dillon1000/react

Commit

Fork the "empty" prepareStackTrace case for Server builds (#31427)

We don't actually want the source mapped version of `.stack` from errors
because that would cause us to not be able to associate it with a source
map in the UIs that need it. The strategy in browsers is more correct
where the display is responsible for source maps.

That's why we disable any custom `prepareStackTrace` like the ones added
by `source-map`. We reset it to `undefined`.

However, when running node with `--enable-source-maps` the default for
`prepareStackTrace` which is a V8 feature (but may exist elsewhere too
like Bun) is a source mapped version of the stack. In those environments
we need to reset it to a default implementation that doesn't apply
source maps.

We already did this in Flight using the `ReactFlightStackConfigV8.js`
config. However, we need this more generally in the
`shared/ReactComponentStackFrame` implementation.

We could always set it to the default implementation instead of
`undefined` but that's unnecessary code in browser builds and it might
lead to slightly different results. For safety and code size, this PR
does it with a fork instead.

All builds specific to `node` or `edge` (or `markup` which is a server
feature) gets the default implementation where as everything else (e.g.
browsers) get `undefined` since it's expected that this is not source
mapped. We don't have to do anything about the equivalent in React
DevTools since React DevTools doesn't run on the server.
Browse files
Changed paths10 files
First-parent comparison
M packages/react-server/src/ReactFlightStackConfigV8.js ModifiedA packages/shared/DefaultPrepareStackTrace.js AddedA packages/shared/DefaultPrepareStackTraceV8.js AddedM packages/shared/ReactComponentStackFrame.js ModifiedM packages/shared/ReactOwnerStackFrames.js ModifiedA packages/shared/forks/DefaultPrepareStackTrace.dom-edge.js AddedA packages/shared/forks/DefaultPrepareStackTrace.dom-node.js AddedA packages/shared/forks/DefaultPrepareStackTrace.markup.js AddedM scripts/rollup/forks.js ModifiedM scripts/shared/inlinedHostConfigs.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…