News for hackers. Stuff that matters.
Re:React v18.0 by tunesmith on Tuesday March 29, 2022 @12:36PM (#30844841)
We've heard rumblings that react18 implies the need for major changes in legacy projects. For instance, jest testing suites apparently need to move away from enzyme?

Also, is there something about MUI and react18 that makes styled-components more of a pain? Not sure where I heard that.

Re:React v18.0 by tshaddox on Tuesday March 29, 2022 @01:07PM (#30845392)
Regarding styled-components and many similar CSS-in-JS libraries, I don't think there are any breaking changes currently with React 18, but it does seem like the writing is on the wall that React intends to not support libraries that inject styles into <style> tags, or at least has some specific rules these libraries need to follow to avoid performance problems. See this discussion: https://github.com/reactwg/react-18/discussions/110
Re:React v18.0 by danabramov on Tuesday March 29, 2022 @02:32PM (#30846580)
I wouldn't say we're planning to not support them. They work with React 18. If they move to useInsertionEffect they'll avoid major performance issues.

The writing on the wall is more that we wouldn't encourage this mechanism over time because we find that <link> + inline styles have much better performance tradeoffs. Often, it's possible to implement a very similar API but statically extractable. That's great and we encourage that. But we wouldn't add a runtime helper like css() into React because we don't think this pattern scales well. Of course, we can't stop people from using it though.

Re:React v18.0 by tunesmith on Tuesday March 29, 2022 @05:52PM (#30848859)
I'm wondering how switching from a css-in-js library to <link> + inline styles would impact CLS. With css-in-js we have some built-in CLS protection in that I think it blocks the JS until the CSS is present, by definition. At the least, it sounds like <link> + inline styles would take more analysis effort to determine what the critical css is for any component.
Re:React v18.0 by madeofpalk on Tuesday March 29, 2022 @07:57PM (#30849890)
CSS-in-JS and external <link> style sheets are not mutually exclusive.

There are a few toolkits out there that let you write component-oriented CSS-in-JS, but during build will extract everything to static external style sheets.

Re:React v18.0 by tunesmith on Tuesday March 29, 2022 @03:53PM (#30847528)
Thanks Dan - can you or anyone else point to something that details those performance tradeoffs in more detail? I think some of it has to do with css render-blocking when it's part of the JS.
Re:React v18.0 by danabramov on Tuesday March 29, 2022 @04:01PM (#30847632)
"When to Insert <style> on The Client" in https://github.com/reactwg/react-18/discussions/110 describes some of the issues. Does this help?
Re:React v18.0 by tunesmith on Tuesday March 29, 2022 @04:46PM (#30848149)
Yes, thanks - after reading it more in depth. :) The "Future" section especially. I don't relish rewriting a legacy codebase that relies heavily upon css-in-js, hopefully the libraries will add compatibility.
Re:React v18.0 by acemarke on Tuesday March 29, 2022 @12:48PM (#30845061)
Enzyme has been lagging in support for React features for several years now, so yes, I would expect it would not correctly support React 18 right away. (Note that both Enzyme and React Testing Library are independent of what test runner you're using - Jest, Mocha, etc).
Re:React v18.0 by rkuykendall-com on Tuesday March 29, 2022 @01:17PM (#30845536)
> I would expect it would not correctly support React 18 right away

It's worse than you know, Enzyme will never support React 18, and it will likely never officially (or fully) support React 17. It's a completely dead project.

Re:React v18.0 by vosper on Tuesday March 29, 2022 @02:02PM (#30846192)
This right here. Enzyme’s dead, barring some major change, and people need to move off it.

https://dev.to/wojtekmaj/enzyme-is-dead-now-what-ekl

(Honestly I’m a bit surprised some big company hasn’t taken over Enzyme development - there most be teams facing hundreds ,or thousands, of hours on test rewriting)

Re:React v18.0 by rimunroe on Tuesday March 29, 2022 @03:52PM (#30847520)
Last I checked it still doesn't even fully support React 16
Re:React v18.0 by acdlite on Tuesday March 29, 2022 @01:37PM (#30845839)
Not sure what Enzyme's plans are, since I know they depend on some React internals.

However, we've worked closely with the React Testing Library maintainers, and that's the solution I'd recommend for React tests going forward. We're fans of RTL because it encourages you to write tests "end-2-end"-like tests that resemble real-world scenarios and are resilient to implementation changes.

Re:React v18.0 by RussianCow on Tuesday March 29, 2022 @03:21PM (#30847167)
That's a shame, because there are plenty of use cases where testing a shallow render makes much more sense than fully rendering the component—for example, when you're wrapping a third-party library and simply need to test that the correct props are being passed, instead of testing the library's functionality.
Re:React v18.0 by danabramov on Tuesday March 29, 2022 @04:02PM (#30847637)
Usually you can do this by mocking that specific library out at the module level. E.g. Jest has functionality for this.
Re:React v18.0 by RussianCow on Wednesday March 30, 2022 @01:39AM (#30851811)
Sure, but using Enzyme has been easier and far less brittle in my experience by being less reliant on hacky, library-specific mocking techniques. (Then again, I suppose you could argue that Enzyme is itself a giant hack, but it worked very well for me in the past.)