GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stash the component stack on the thrown value and reuse by gnoff · Pull Request #25790 · react/react

Conversation

@gnoff

@gnoff gnoff commented Dec 2, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

ErrorBoundaries are currently not fully composable. The reason is if you decide your boundary cannot handle a particular error and rethrow it to higher boundary the React runtime does not understand that this throw is a forward and it recreates the component stack from the Boundary position. This loses fidelity and is especially bad if the boundary is limited it what it handles and high up in the component tree.

This implementation uses a WeakMap to store component stacks for values that are objects. If an error is rethrown from an ErrorBoundary the stack will be pulled from the map if it exists. This doesn't work for thrown primitives but this is uncommon and stashing the stack on the primitive also wouldn't work

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

eps1lon reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@facebook-github-bot facebook-github-bot added the CLA Signed label Dec 2, 2022
@gnoff
gnoff requested a review from sebmarkbage December 2, 2022 22:24
@sizebot

sizebot commented Dec 2, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Comparing: f0534ae...d1d6184

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 +0.14% 154.40 kB 154.61 kB +0.11% 49.00 kB 49.05 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.13% 156.32 kB 156.53 kB +0.13% 49.65 kB 49.71 kB
facebook-www/ReactDOM-prod.classic.js +0.07% 533.40 kB 533.79 kB +0.13% 94.99 kB 95.12 kB
facebook-www/ReactDOM-prod.modern.js +0.07% 518.50 kB 518.89 kB +0.15% 92.80 kB 92.94 kB
facebook-www/ReactDOMForked-prod.classic.js +0.07% 533.40 kB 533.79 kB +0.13% 94.99 kB 95.12 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-test-renderer/umd/react-test-renderer.production.min.js +0.23% 100.44 kB 100.67 kB +0.31% 31.16 kB 31.26 kB
oss-stable/react-test-renderer/umd/react-test-renderer.production.min.js +0.23% 100.46 kB 100.69 kB +0.30% 31.16 kB 31.26 kB
oss-experimental/react-test-renderer/umd/react-test-renderer.production.min.js +0.23% 100.52 kB 100.75 kB +0.30% 31.19 kB 31.28 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.production.min.js +0.23% 100.20 kB 100.43 kB +0.22% 30.74 kB 30.81 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.production.min.js +0.23% 100.22 kB 100.45 kB +0.21% 30.74 kB 30.81 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.production.min.js +0.23% 100.28 kB 100.51 kB +0.21% 30.78 kB 30.84 kB
oss-stable-semver/react-art/cjs/react-art.production.min.js +0.23% 92.33 kB 92.54 kB +0.19% 28.43 kB 28.49 kB
oss-stable/react-art/cjs/react-art.production.min.js +0.23% 92.35 kB 92.56 kB +0.19% 28.43 kB 28.49 kB
oss-experimental/react-art/cjs/react-art.production.min.js +0.22% 93.77 kB 93.98 kB +0.19% 28.87 kB 28.92 kB

Generated by 🚫 dangerJS against d1d6184

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@poteto poteto added the React Core Team Opened by a member of the React Core Team label Dec 7, 2022
sebmarkbage
sebmarkbage reviewed Feb 16, 2024
View reviewed changes
Comment thread packages/react-reconciler/src/ReactCapturedValue.js Outdated
// If the value is an error, call this function immediately after it is thrown
// so the stack is accurate.
let stack;
if (value != null && hasOwnProperty.call(value, '_componentStack')) {

@sebmarkbage sebmarkbage Feb 16, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We probably should use a WeakMap instead to avoid any conflicts on the object.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sebmarkbage
sebmarkbage approved these changes Feb 16, 2024
View reviewed changes

@sebmarkbage sebmarkbage left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

WeakMap and then good to land.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnoff
gnoff force-pushed the retain-error-stacks branch from d1d6184 to 40a2cb9 Compare February 16, 2024 04:25
@react-sizebot

react-sizebot commented Feb 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Comparing: fea900e...3408207

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 +0.10% 176.83 kB 177.01 kB +0.11% 55.11 kB 55.17 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.10% 178.83 kB 179.00 kB +0.09% 55.69 kB 55.74 kB
facebook-www/ReactDOM-prod.classic.js +0.07% 592.18 kB 592.58 kB +0.11% 104.43 kB 104.54 kB
facebook-www/ReactDOM-prod.modern.js +0.07% 575.46 kB 575.87 kB +0.12% 101.43 kB 101.55 kB
test_utils/ReactAllWarnings.js Deleted 66.25 kB 0.00 kB Deleted 16.31 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 66.25 kB 0.00 kB Deleted 16.31 kB 0.00 kB

Generated by 🚫 dangerJS against 3408207

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gnoff
Retain component stacks when rethrowing an error that already generat…
3408207
…ed a component stack
@gnoff
gnoff force-pushed the retain-error-stacks branch from 40a2cb9 to 3408207 Compare February 16, 2024 04:31
gnoff
gnoff commented Feb 16, 2024
View reviewed changes
Comment thread packages/react-reconciler/src/ReactCapturedValue.js
export function createCapturedValue<T>(
value: T,
export function createCapturedValueFromError(
value: Error,

@gnoff gnoff Feb 16, 2024

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

this was already being used on to construct add hoc captured values for the recoverable error pathway. It doesn't need value generality and this helps us avoid type checking the value before deciding if the stack needs to go in the map

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/react-reconciler/src/ReactCapturedValue.js
): CapturedValue<T> {
): CapturedValue<Error> {
if (typeof stack === 'string') {
CapturedStacks.set(value, stack);

@gnoff gnoff Feb 16, 2024

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The way this is used today we don't really need to capture the stack in the map because these errors aren't bubbling up during a render. However it could be used in other ways in the future so to keep it correct I'm stashing the stack here if it is provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnoff
gnoff merged commit a9cc325 into react:main Feb 16, 2024
@gnoff
gnoff deleted the retain-error-stacks branch February 16, 2024 04:44
github-actions Bot pushed a commit that referenced this pull request Feb 16, 2024
@gnoff
stash the component stack on the thrown value and reuse (#25790)
651e755
ErrorBoundaries are currently not fully composable. The reason is if you
decide your boundary cannot handle a particular error and rethrow it to
higher boundary the React runtime does not understand that this throw is
a forward and it recreates the component stack from the Boundary
position. This loses fidelity and is especially bad if the boundary is
limited it what it handles and high up in the component tree.

This implementation uses a WeakMap to store component stacks for values
that are objects. If an error is rethrown from an ErrorBoundary the
stack will be pulled from the map if it exists. This doesn't work for
thrown primitives but this is uncommon and stashing the stack on the
primitive also wouldn't work

DiffTrain build for [a9cc325](a9cc325)
This was referenced Feb 20, 2024
Bump vendored react versions vercel/next.js#62302
Closed
Upgrade vendored react vercel/next.js#62326
Merged
huozhi added a commit to vercel/next.js that referenced this pull request Feb 23, 2024
@huozhi
Upgrade vendored react (#62326)
e5d604f
### React upstream changes

- react/react#28333
- react/react#28334
- react/react#28378
- react/react#28377
- react/react#28376
- react/react#28338
- react/react#28331
- react/react#28336
- react/react#28320
- react/react#28317
- react/react#28375
- react/react#28367
- react/react#28380
- react/react#28368
- react/react#28343
- react/react#28355
- react/react#28374
- react/react#28362
- react/react#28344
- react/react#28339
- react/react#28353
- react/react#28346
- react/react#25790
- react/react#28352
- react/react#28326
- react/react#27688
- react/react#28329
- react/react#28332
- react/react#28340
- react/react#28327
- react/react#28325
- react/react#28324
- react/react#28309
- react/react#28310
- react/react#28307
- react/react#28306
- react/react#28315
- react/react#28318
- react/react#28226
- react/react#28308
- react/react#27563
- react/react#28297
- react/react#28286
- react/react#28284
- react/react#28275
- react/react#28145
- react/react#28301
- react/react#28224
- react/react#28152
- react/react#28296
- react/react#28294
- react/react#28279
- react/react#28273
- react/react#28269
- react/react#28376
- react/react#28338
- react/react#28331
- react/react#28336
- react/react#28320
- react/react#28317
- react/react#28375
- react/react#28367
- react/react#28380
- react/react#28368
- react/react#28343
- react/react#28355
- react/react#28374
- react/react#28362
- react/react#28344
- react/react#28339
- react/react#28353
- react/react#28346
- react/react#25790
- react/react#28352
- react/react#28326
- react/react#27688
- react/react#28329
- react/react#28332
- react/react#28340
- react/react#28327
- react/react#28325
- react/react#28324
- react/react#28309
- react/react#28310
- react/react#28307
- react/react#28306
- react/react#28315
- react/react#28318
- react/react#28226
- react/react#28308
- react/react#27563
- react/react#28297
- react/react#28286
- react/react#28284
- react/react#28275
- react/react#28145
- react/react#28301
- react/react#28224
- react/react#28152
- react/react#28296
- react/react#28294
- react/react#28279
- react/react#28273
- react/react#28269

Closes NEXT-2542


Disable ppr test for strict mode for now, @acdlite will check it and
we'll sync again
@ztanner ztanner mentioned this pull request Mar 19, 2024
(backport) Update React from 60a927d04 to 14898b6a9 vercel/next.js#63442
Closed
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
@gnoff @AndyPengc12
stash the component stack on the thrown value and reuse (react#25790)
68abb8b
ErrorBoundaries are currently not fully composable. The reason is if you
decide your boundary cannot handle a particular error and rethrow it to
higher boundary the React runtime does not understand that this throw is
a forward and it recreates the component stack from the Boundary
position. This loses fidelity and is especially bad if the boundary is
limited it what it handles and high up in the component tree.

This implementation uses a WeakMap to store component stacks for values
that are objects. If an error is rethrown from an ErrorBoundary the
stack will be pulled from the map if it exists. This doesn't work for
thrown primitives but this is uncommon and stashing the stack on the
primitive also wouldn't work
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
@gnoff
stash the component stack on the thrown value and reuse (#25790)
2a45e92
ErrorBoundaries are currently not fully composable. The reason is if you
decide your boundary cannot handle a particular error and rethrow it to
higher boundary the React runtime does not understand that this throw is
a forward and it recreates the component stack from the Boundary
position. This loses fidelity and is especially bad if the boundary is
limited it what it handles and high up in the component tree.

This implementation uses a WeakMap to store component stacks for values
that are objects. If an error is rethrown from an ErrorBoundary the
stack will be pulled from the map if it exists. This doesn't work for
thrown primitives but this is uncommon and stashing the stack on the
primitive also wouldn't work

DiffTrain build for commit a9cc325.
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
@gnoff
stash the component stack on the thrown value and reuse (react#25790)
c8737db
ErrorBoundaries are currently not fully composable. The reason is if you
decide your boundary cannot handle a particular error and rethrow it to
higher boundary the React runtime does not understand that this throw is
a forward and it recreates the component stack from the Boundary
position. This loses fidelity and is especially bad if the boundary is
limited it what it handles and high up in the component tree.

This implementation uses a WeakMap to store component stacks for values
that are objects. If an error is rethrown from an ErrorBoundary the
stack will be pulled from the map if it exists. This doesn't work for
thrown primitives but this is uncommon and stashing the stack on the
primitive also wouldn't work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@sebmarkbage sebmarkbage sebmarkbage approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@gnoff @sizebot @react-sizebot @sebmarkbage @poteto @facebook-github-bot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.