Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test for deduped props of elements in fragments #30526

Closed

Conversation

eps1lon
Copy link
Collaborator

@eps1lon eps1lon commented Jul 30, 2024

Summary

We're adding null as a placeholder until the referenced props resolve in waitForReference. But when the props resolve, we only replace the value in the parent object which is a tuple. However, by that time we have already created the element by de-referencing the props from tuple in parseModelTuple.

How did you test this change?

  • $ yarn test --watch packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js -t "should handle deduped props of elements in fragments"
    TypeError: Cannot read properties of null (reading 'itemProp')
    
       3085 |
       3086 |   // Global opt out of hoisting for anything in SVG Namespace or anything with an itemProp inside an itemScope
     > 3087 |   if (hostContextProd === HostContextNamespaceSvg || props.itemProp != null) {
            |                                                            ^
       3088 |     if (__DEV__) {
       3089 |       if (
       3090 |         outsideHostContainerContext &&
    
       at isHostHoistableType (packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js:3087:60)

Copy link

vercel bot commented Jul 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2024 1:03pm

@react-sizebot
Copy link

Comparing: bea5a2b...7d93d2a

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 501.29 kB 501.29 kB = 89.95 kB 89.95 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB +0.05% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 508.41 kB 508.41 kB = 91.12 kB 91.12 kB
facebook-www/ReactDOM-prod.classic.js = 596.31 kB 596.31 kB = 105.76 kB 105.76 kB
facebook-www/ReactDOM-prod.modern.js = 572.61 kB 572.61 kB = 101.96 kB 101.96 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against e26781e

function Server() {
return (
<FooClient track={shared}>
<React.Fragment>{shared}</React.Fragment>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't hit this particular case without the Fragment though the Fragment isn't relevant. It just helps us trigger the case where deduped props of elements are resolved.

unstubbable added a commit to unstubbable/react that referenced this pull request Jul 30, 2024
When an element is used multiple times as shown in facebook#30526, its props
might be deduped. When resolving the reference to the deduped props, we
were only updating the React element tuple, which at this point has
already been parsed into a React element object, using `null` as
placeholder props. Therefore, updating the element tuple doesn't help
much, and we need to make sure that the element object's props are
updated as well.

This is a similar fix as facebook#28669, see the code lines above, and thus
feels similarly hacky. Maybe there's a better way to fix this? @eps1lon
was mentioning offline that solving [this
TODO](https://github.com/facebook/react/blob/33e54fa252b9dbe7553ef42a2287c3dbbd4f035d/packages/react-client/src/ReactFlightClient.js#L1327)
would probably fix it properly, since we wouldn't need to deal with
stale tuples then. But that's a way heavier lift.
unstubbable added a commit to unstubbable/react that referenced this pull request Jul 30, 2024
When an element is used multiple times as shown in facebook#30526, its props
might be deduped. When resolving the reference to the deduped props, we
were only updating the React element tuple, which at this point has
already been parsed into a React element object, using `null` as
placeholder props. Therefore, updating the element tuple doesn't help
much, and we need to make sure that the element object's props are
updated as well.

This is a similar fix as facebook#28669, see the code lines above, and thus
feels similarly hacky. Maybe there's a better way to fix this? @eps1lon
was mentioning offline that solving [this
TODO](https://github.com/facebook/react/blob/33e54fa252b9dbe7553ef42a2287c3dbbd4f035d/packages/react-client/src/ReactFlightClient.js#L1327)
would probably fix it properly, since we wouldn't need to deal with
stale tuples then. But that's a way heavier lift.
@eps1lon
Copy link
Collaborator Author

eps1lon commented Jul 30, 2024

Closing in favor of #30528

@eps1lon eps1lon closed this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants