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 — Re-throw errors thrown by the renderer at the root in the complete ph… · react/react@4d9f850

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • react-noop-renderer/src
      • createReactNoop.js
    • react-reconciler/src
      • ReactFiberWorkLoop.js
      • __tests__
        • ReactIncrementalErrorHandling-test.internal.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-noop-renderer/src/createReactNoop.js‎

Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/createReactNoop.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
533533
newChildren: Array<Instance | TextInstance>,
534534
): void {
535535
container.pendingChildren = newChildren;
536+
if (
537+
newChildren.length === 1 &&
538+
newChildren[0].text === 'Error when completing root'
539+
) {
540+
// Trigger an error for testing purposes
541+
throw Error('Error when completing root');
542+
}
536543
},
537544

538545
replaceContainerChildren(
Collapse file

‎packages/react-reconciler/src/ReactFiberWorkLoop.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,13 @@ function handleError(root, thrownValue) {
12851285
// boundary.
12861286
workInProgressRootExitStatus = RootFatalErrored;
12871287
workInProgressRootFatalError = thrownValue;
1288+
// Set `workInProgress` to null. This represents advancing to the next
1289+
// sibling, or the parent if there are no siblings. But since the root
1290+
// has no siblings nor a parent, we set it to null. Usually this is
1291+
// handled by `completeUnitOfWork` or `unwindWork`, but since we're
1292+
// interntionally not calling those, we need set it here.
1293+
// TODO: Consider calling `unwindWork` to pop the contexts.
1294+
workInProgress = null;
12881295
return null;
12891296
}
12901297

Collapse file

‎packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,4 +1658,16 @@ describe('ReactIncrementalErrorHandling', () => {
16581658
'Please update the following components: Provider',
16591659
]);
16601660
});
1661+
1662+
if (global.__PERSISTENT__) {
1663+
it('regression test: should fatal if error is thrown at the root', () => {
1664+
const root = ReactNoop.createRoot();
1665+
root.render('Error when completing root');
1666+
expect(Scheduler).toFlushAndThrow('Error when completing root');
1667+
1668+
const blockingRoot = ReactNoop.createBlockingRoot();
1669+
blockingRoot.render('Error when completing root');
1670+
expect(Scheduler).toFlushAndThrow('Error when completing root');
1671+
});
1672+
}
16611673
});

0 commit comments

Comments
0 (0)
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.