dillon1000/react
Commit
Browse files Warn for invalid type in renderer with the correct RSC stack (#30102)
This is all behind the `enableOwnerStacks` flag. This is a follow up to #29088. In that I moved type validation into the renderer since that's the one that knows what types are allowed. However, I only removed it from `React.createElement` and not the JSX which was an oversight. However, I also noticed that for invalid types we don't have the right stack trace for throws because we're not yet inside the JSX element that itself is invalid. We should use its stack for the stack trace. That's the reason it's enough to just use the throw now because we can get a good stack trace from the owner stack. This is fixed by creating a fake Throw Fiber that gets assigned the right stack. Additionally, I noticed that for certain invalid types like the most common one `undefined` we error in Flight so a missing import in RSC leads to a generic error. Instead of erroring on the Flight side we should just let anything that's not a Server Component through to the client and then let the Client renderer determine whether it's a valid type or not. Since we now have owner stacks through the server too, this will still be able to provide a good stack trace on the client that points to the server in that case. <img width="571" alt="Screenshot 2024-06-25 at 6 46 35 PM" src="https://github.com/facebook/react/assets/63648/6812c24f-e274-4e09-b4de-21deda9ea1d4"> To get the best stack you have to expand the little icon and the regular stack is noisy [due to this Chrome bug](https://issues.chromium.org/issues/345248263) which makes it a little harder to find but once that's fixed it might be easier.
Changed paths12 files
First-parent comparisonpackages/react-client/src/__tests__/ReactFlight-test.js ModifiedM packages/react-dom/src/__tests__/ReactComponent-test.js ModifiedM packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js ModifiedM packages/react-dom/src/__tests__/ReactLegacyErrorBoundaries-test.internal.js ModifiedM packages/react-reconciler/src/ReactChildFiber.js ModifiedM packages/react-reconciler/src/ReactFiber.js ModifiedM packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js ModifiedM packages/react-server/src/ReactFlightServer.js ModifiedM packages/react/src/__tests__/ReactElementValidator-test.internal.js ModifiedM packages/react/src/__tests__/ReactJSXElementValidator-test.js ModifiedM packages/react/src/jsx/ReactJSXElement.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…