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

feat: add error boundary for form input components #6869

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Jun 6, 2024

Description

While debugging issues in React 19, as well as React Compiler, I've frequently encountered crashes that takes down the Structure Tool completely:
image

It's difficult to track down exactly what's causing it, the same is true when handling user reports of crashes, in Next v14 and v15 embedded studios in particular.
This PR adds an error boundary for input components, which narrows down the crash to the input level:
image

In the image above only some of the Portable Text Editor inputs are crashing, significantly helping with narrowing down the cause. Fixes for the errors seen here will be done in follow up PRs.

What to review

Does the language strings and the UI make sense?

Testing

It's easiest to test on the compiled studio deployment, as it crashes early on race condition issues, instead of requiring tricky race condition reproduction steps: https://test-compiled-studio-git-add-input-error-boundary.sanity.build/test/structure/input-standard;portable-text;pt_allTheBellsAndWhistles;7455ba88-75d5-4a77-94a4-91738fa670c5

Notes for release

Form input components now have their own error boundaries, limiting crashes to a field level on a document form, instead of taking down the entire Structure Tool.

@stipsan stipsan requested a review from a team as a code owner June 6, 2024 19:35
@stipsan stipsan requested review from cngonzalez and removed request for a team June 6, 2024 19:35
Copy link

vercel bot commented Jun 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2024 0:42am
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2024 0:42am
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2024 0:42am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2024 0:42am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2024 0:42am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jun 7, 2024 0:42am

@stipsan stipsan enabled auto-merge June 6, 2024 19:35
Copy link
Contributor

github-actions bot commented Jun 6, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented Jun 6, 2024

Component Testing Report Updated Jun 7, 2024 12:47 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 41s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 7s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 27s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 33s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 39s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 21s 20 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 9s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 8s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 21s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 16s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 31s 12 0 0

* when there are no errors.
* @internal
*/
function ErrorCard(props: {error: unknown; onRetry: () => void}) {
Copy link
Member

Choose a reason for hiding this comment

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

The unknown type here and the stack and message params become a little confusing for me here, but I understand if it's more difficult to more strictly type things here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It follows the precedence in StudioErrorBoundary, as well as the convention of the stricter TS rule that enforces:

try {
  doSomething()
} catch(error: unknown) {
 // `error` is never guaranteed to be a subclass of `Error` and can be anything, `unknown` forces you to deal with every eventuality
}

Which is also why the isRecord asserters are used further down

Copy link
Member

Choose a reason for hiding this comment

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

ahh, of course! apologies for not checking that

Merged via the queue into next with commit 23c42ae Jun 7, 2024
45 checks passed
@stipsan stipsan deleted the add-input-error-boundary branch June 7, 2024 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants