react-live icon indicating copy to clipboard operation
react-live copied to clipboard

feat(SSR): add support for initial SSR render

Open tujoworker opened this issue 3 years ago • 1 comments

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 the package.json so mocking of generateElement was possible, but use the original at the same time.
  • Most of the LiveProvider.test.js test where giving false positives, as the return waitAsync never got called.
  • In order to actually make useEffect work (called) – I changed the jsdom renderer to @testing-library/react.

tujoworker avatar May 25 '22 14:05 tujoworker

@jpdriver could you review this PR? Or anybody else? 🙏🏻

tujoworker avatar Oct 08 '22 03:10 tujoworker