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

fix: Errors thrown during a grid update are not caught #2188

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ export type GridState = {
// Whether we're stuck to the bottom or the right
isStuckToBottom: boolean;
isStuckToRight: boolean;

/**
* Errors thrown during a render animation frame.
* These are not caught by the grid panel,
* so we need to throw them in componentDidUpdate
*/
renderError?: unknown;
};

/**
Expand Down Expand Up @@ -497,6 +504,13 @@ class Grid extends PureComponent<GridProps, GridState> {
}

componentDidUpdate(prevProps: GridProps, prevState: GridState): void {
const { renderError } = this.state;

// Render errors mean we can't recover
if (renderError != null) {
throw renderError;
}

const changedProps = getChangedKeys(prevProps, this.props);
const changedState = getChangedKeys(prevState, this.state);
// We don't need to bother re-checking any of the metrics if only the children have changed
Expand Down Expand Up @@ -811,7 +825,12 @@ class Grid extends PureComponent<GridProps, GridState> {
this.animationFrame = requestAnimationFrame(() => {
this.animationFrame = null;

this.updateCanvas();
try {
this.updateCanvas();
} catch (e) {
// Errors thrown from the animation frame are uncaught by the grid panel
this.setState({ renderError: e });
}
});
}

Expand Down
Loading