react-live
react-live copied to clipboard
feat(SSR): add support for initial SSR render
Fixes #321 (more details in this issue)
This PR adds support for in "initial sync render". With that, we do support SSR again.
- A new property to skip that behavior was added:
skipInitialRender. - For performance reasons we run the initial render once and omit the second from inside useEffect – else the code render would have to render twice.
There may be ways to write less code, or to combine transpileSync and transpileAsync – but when I did that, it got less readable and feels bloated. Anyway, maybe someone else want have a try?
Test plan
- Added some tests to verify that initial render.
- I needed to remove
"resetMocks": true,jest config in thepackage.jsonso mocking ofgenerateElementwas possible, but use the original at the same time. - Most of the
LiveProvider.test.jstest where giving false positives, as thereturn waitAsyncnever got called. - In order to actually make
useEffectwork (called) – I changed the jsdom renderer to@testing-library/react.
@jpdriver could you review this PR? Or anybody else? 🙏🏻