feat: add react-compiler
export condition
#177
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The React Compiler were struggling to understand the flow of
<PortableText>
:react-portabletext/src/react-portable-text.tsx
Lines 42 to 67 in 11fbc8a
And it got different results for its
useMemo
deps arrays that were used to memorenderNode
, and thus opted out from optimizing it.Here's a diff of what happens if you add
react-compiler
without refactoring anything, and with the changes in this PR: https://npmdiff.dev/%40portabletext%2Freact/3.0.18-canary.0/3.1.0-canary.2/package/dist/index.compiled.js/What I like about the implementation on
main
is that if thecomponents
andonMissingComponent
props were stable, then a changingvalue
prop didn't result ingetNodeRenderer
andmergeComponents
being called more than once. I wanted to preserve this behaviour, while also changing the code so that the compiler understands it and can auto memoize it further.By splitting the work into two separate components we preserve the previous memoization, while adding a few new benefits:
<PortableText>
is now wrapped inmemo
it can opt-out of looping a possibly very deep recursive tree ofrenderNode
if parent components rerender but the props given to<PortableText>
haven't changed.