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

Add test case for hydration warning suppression #24436

Closed
wants to merge 2 commits into from

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Apr 25, 2022

In #24404 a test case was added for supressing hydration warnings if a preceding component suspends. The test case showed that hydration warnings would still emit after resolution but it did not include a test case for when the resolution led to a complete hydration without errors. This commit adds the additional test case demonstrating that no warnings or Errors are observed if hydration completes successfully after suspended component resolution

In facebook#24404 a test case was added for supressing hydration warnings if a preceding component suspends. The test case showed that hydration warnings would still emit after resolution but it did not include a test case for when the resolution led to a complete hydration without errors. This commit adds the additional test case demonstrating that no warnings or Errors are observed if hydration completes successfully after suspended component resolution
@sizebot
Copy link

sizebot commented Apr 25, 2022

Comparing: bd4784c...06b7825

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.min.js = 131.56 kB 131.56 kB = 42.11 kB 42.11 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 136.83 kB 136.83 kB = 43.69 kB 43.69 kB
facebook-www/ReactDOM-prod.classic.js = 441.15 kB 441.15 kB = 80.48 kB 80.48 kB
facebook-www/ReactDOM-prod.modern.js = 426.40 kB 426.40 kB = 78.28 kB 78.28 kB
facebook-www/ReactDOMForked-prod.classic.js = 441.15 kB 441.15 kB = 80.48 kB 80.48 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 06b7825

@xiel
Copy link

xiel commented Apr 26, 2022

Mh weird that the test is not failing? But I still see errors here:
https://codesandbox.io/s/relaxed-northcutt-8jewmg?file=/package.json (06b7825)

@gaearon
Copy link
Collaborator

gaearon commented Apr 26, 2022

Yes, I'm also concerned the test doesn't fail since the behavior on main is not supposed to fix it yet

@gnoff
Copy link
Collaborator Author

gnoff commented Apr 26, 2022

@xiel I'm having trouble forking your sandbox for some reason. it tells me it cannot install the react versions in package.json becuase they are missing form the registry but clearly they are not because you are using them. I'm not sandbox expert, got any idea why a simple fork shouldn't work

(plus @gaearon) As for the difference in behavior between test and this sandbox I believe there is something causing the root to complete even though the app is still suspended so the mismatch errors which were queued end up being logged.

The test case (as constructed) does not commit the root when the boundary is in fallback and so the queued errors get dropped. The unmerged change in #24427 would suppress these. I don't think the test is wrong per se but perhaps there is another test that needs to recreate the conditions observed in this sandbox which I don't yet know how to do. will look more into it when I touch base with @acdlite later this week

@gnoff
Copy link
Collaborator Author

gnoff commented Apr 28, 2022

Closing to combine with #24427

@gnoff gnoff closed this Apr 28, 2022
@gnoff
Copy link
Collaborator Author

gnoff commented Apr 28, 2022

@xiel the reason those errors are showing up has to do with how React makes dev-time errors "uncaught" for debugging purposes. When you run in dev mode and there is an error rendering a component a thing called invokeGuardedCallback is used to re-run your function in a dom event dispatch that is "uncaught" so the debugger can pause there. Unfortunately the default behavior in most browsers for these errors is to also have them logged to the console. So while we were suppressing the errors through normal program control flow (hence the tests worked) in a browser context they leak as uncaught still.

We're going to change this over in #24427

The other issue your sandbox demonstrates is a rapid retry of the suspense boundary leading to a flood of errors. This is a separate issue I'll tackle next but essentially work is getting scheduled on the suspended component on each mousemove but it should instead wait if we're blocked on that boundary.

@gnoff
Copy link
Collaborator Author

gnoff commented Apr 28, 2022

@xiel and here is a modified codesandbox showing the errors are gone but the over-eager render retries still present: https://codesandbox.io/s/trusting-buck-2j21to?file=/src/index.js

@gaearon
Copy link
Collaborator

gaearon commented Apr 28, 2022

Unfortunately the default behavior in most browsers for these errors is to also have them logged to the console.

To be clear, I think that’s the reason why we have these invokeGuardedCallback wrappers at all. That is, they are explicitly for that purpose — to get the browser to report the error as uncaught despite us actually catching it. But yeah, in this case we wouldn’t want that.

@gnoff
Copy link
Collaborator Author

gnoff commented Apr 29, 2022

To be clear, I think that’s the reason why we have these invokeGuardedCallback wrappers at all. That is, they are explicitly for that purpose — to get the browser to report the error as uncaught despite us actually catching it. But yeah, in this case we wouldn’t want that.

Yeah I think I was looking at it myopically and thinking it was about breaking on uncaught exceptions. makes sense that you would also want to surface in console when you don't necessarily know you need to be debugging. appreciate the callout

@gnoff gnoff deleted the hydration-warn-test-case branch April 29, 2022 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants