-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block Bindings: Error handling for external sources. #72585
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
Conversation
|
Size Change: +10 B (0%) Total Size: 2.45 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 6c0b82c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18748167847
|
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.
Pull Request Overview
This PR adds error handling to prevent crashes in the block bindings UI when external sources throw JavaScript errors. The changes wrap critical operations in try-catch blocks to gracefully handle and skip problematic sources.
Key changes:
- Wraps
getValuescalls in try-catch blocks to prevent UI crashes from external source errors - Wraps
editorUIandgetFieldsListfunction calls in try-catch blocks - Filters out items that fail validation, ensuring only valid sources appear in the UI
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Adding a modal boundary requires a new |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@cbravobernal, could you provide a test browser snippet for this change? I'm not sure about DX for this change. I wonder if it's better to let the block error boundary catch the error. Also, warnings won't be displayed in production builds, which can delay user error reporting. |
|
Btw, React docs has somewhat related note and links to an interesting article - https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary:~:text=You%20don%E2%80%99t%20need%20to%20wrap%20every%20component%20into%20a%20separate%20Error%20Boundary.. |
There you have some screen shares @Mamaduka : Without boundary: without_boundary.mp4With the boundary (the source just don't appear) with_boundary.mp4The modal would still crash with the block error system, as I think is a better DX, cause is not crashing the rest of sources. Fot modal_crash.mp4Sorry for the late answer. |
6c0b82c to
5c90755
Compare
5c90755 to
aa806bd
Compare
ockham
left a comment
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.
Sorry for the late review. TBH I'm not entirely sure about this one.
On the one hand, it's good to prevent the UI from crashing. OTOH, we'd lose any kind of visibility what the error is (which makes e.g. development of a source more difficult). Maybe we should at least log the error in the console?
The error, as is a JS one, is indeed being logged on console. |
Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org> Co-authored-by: ockham <bernhard-reiter@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
|
I just cherry-picked this PR to the wp/6.9 branch to get it included in the next release: 03b913f |
Changes can be found at https://github.com/WordPress/gutenberg/commits/wp/6.9/. - [Block Bindings: Add unit test coverage for `core/post-data` source](WordPress/gutenberg#73055) - [Block Bindings: Error handling for external sources.](WordPress/gutenberg#72585) - [Notes: Collapse note on blur](WordPress/gutenberg#73158) - [Border-radius values triggers unintended px conversion](WordPress/gutenberg#73324) - [Fix navigation tag entity binding](WordPress/gutenberg#73255) - [DataViews: ensure primary actions are not wrapped in the list layout](WordPress/gutenberg#73345) - [Fix: Fit Text may overflow into the padding area.](WordPress/gutenberg#73327) - [Merge "Icon Size" and "Icon size" translation strings](WordPress/gutenberg#73325) - [Notes: Improve delete confirm message for replies](WordPress/gutenberg#73173) - [Fix: Custom font size taking over fit text.](WordPress/gutenberg#73241) - [Fix a11y of descriptions and alerts for "Invalid" Nav Items](WordPress/gutenberg#73177) - [Stretchy text: Hide variations in Block Inspector (hack)](WordPress/gutenberg#73238) - [Update button label from "Add new note" to "Add new reply"](WordPress/gutenberg#73189) - [Notes: Fix first note creation with pinned sidebar](WordPress/gutenberg#73164) Developed in #10528. See https://make.wordpress.org/core/handbook/about/release-cycle/block-editor-release-process-for-major-releases/#package-updates-and-core-patches. Fixes #64267. Props priethor. git-svn-id: https://develop.svn.wordpress.org/trunk@61262 602fd350-edb4-49c9-b593-d223f7449a82
Changes can be found at https://github.com/WordPress/gutenberg/commits/wp/6.9/. - [Block Bindings: Add unit test coverage for `core/post-data` source](WordPress/gutenberg#73055) - [Block Bindings: Error handling for external sources.](WordPress/gutenberg#72585) - [Notes: Collapse note on blur](WordPress/gutenberg#73158) - [Border-radius values triggers unintended px conversion](WordPress/gutenberg#73324) - [Fix navigation tag entity binding](WordPress/gutenberg#73255) - [DataViews: ensure primary actions are not wrapped in the list layout](WordPress/gutenberg#73345) - [Fix: Fit Text may overflow into the padding area.](WordPress/gutenberg#73327) - [Merge "Icon Size" and "Icon size" translation strings](WordPress/gutenberg#73325) - [Notes: Improve delete confirm message for replies](WordPress/gutenberg#73173) - [Fix: Custom font size taking over fit text.](WordPress/gutenberg#73241) - [Fix a11y of descriptions and alerts for "Invalid" Nav Items](WordPress/gutenberg#73177) - [Stretchy text: Hide variations in Block Inspector (hack)](WordPress/gutenberg#73238) - [Update button label from "Add new note" to "Add new reply"](WordPress/gutenberg#73189) - [Notes: Fix first note creation with pinned sidebar](WordPress/gutenberg#73164) Developed in WordPress/wordpress-develop#10528. See https://make.wordpress.org/core/handbook/about/release-cycle/block-editor-release-process-for-major-releases/#package-updates-and-core-patches. Fixes #64267. Props priethor. Built from https://develop.svn.wordpress.org/trunk@61262 git-svn-id: http://core.svn.wordpress.org/trunk@60574 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Changes can be found at https://github.com/WordPress/gutenberg/commits/wp/6.9/. - [Block Bindings: Add unit test coverage for `core/post-data` source](WordPress/gutenberg#73055) - [Block Bindings: Error handling for external sources.](WordPress/gutenberg#72585) - [Notes: Collapse note on blur](WordPress/gutenberg#73158) - [Border-radius values triggers unintended px conversion](WordPress/gutenberg#73324) - [Fix navigation tag entity binding](WordPress/gutenberg#73255) - [DataViews: ensure primary actions are not wrapped in the list layout](WordPress/gutenberg#73345) - [Fix: Fit Text may overflow into the padding area.](WordPress/gutenberg#73327) - [Merge "Icon Size" and "Icon size" translation strings](WordPress/gutenberg#73325) - [Notes: Improve delete confirm message for replies](WordPress/gutenberg#73173) - [Fix: Custom font size taking over fit text.](WordPress/gutenberg#73241) - [Fix a11y of descriptions and alerts for "Invalid" Nav Items](WordPress/gutenberg#73177) - [Stretchy text: Hide variations in Block Inspector (hack)](WordPress/gutenberg#73238) - [Update button label from "Add new note" to "Add new reply"](WordPress/gutenberg#73189) - [Notes: Fix first note creation with pinned sidebar](WordPress/gutenberg#73164) Developed in WordPress/wordpress-develop#10528. See https://make.wordpress.org/core/handbook/about/release-cycle/block-editor-release-process-for-major-releases/#package-updates-and-core-patches. Fixes #64267. Props priethor. Built from https://develop.svn.wordpress.org/trunk@61262 git-svn-id: https://core.svn.wordpress.org/trunk@60574 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Changes can be found at https://github.com/WordPress/gutenberg/commits/wp/6.9/. [Block Bindings: Add unit test coverage for core/post-data source](WordPress/gutenberg#73055) [Block Bindings: Error handling for external sources.](WordPress/gutenberg#72585) [Notes: Collapse note on blur](WordPress/gutenberg#73158) [Border-radius values triggers unintended px conversion](WordPress/gutenberg#73324) [Fix navigation tag entity binding](WordPress/gutenberg#73255) [DataViews: ensure primary actions are not wrapped in the list layout](WordPress/gutenberg#73345) [Fix: Fit Text may overflow into the padding area.](WordPress/gutenberg#73327) [Merge "Icon Size" and "Icon size" translation strings](WordPress/gutenberg#73325) [Notes: Improve delete confirm message for replies](WordPress/gutenberg#73173) [Fix: Custom font size taking over fit text.](WordPress/gutenberg#73241) [Fix a11y of descriptions and alerts for "Invalid" Nav Items](WordPress/gutenberg#73177) [Stretchy text: Hide variations in Block Inspector (hack)](WordPress/gutenberg#73238) [Update button label from "Add new note" to "Add new reply"](WordPress/gutenberg#73189) [Notes: Fix first note creation with pinned sidebar](WordPress/gutenberg#73164) Developed in #10528. See https://make.wordpress.org/core/handbook/about/release-cycle/block-editor-release-process-for-major-releases/#package-updates-and-core-patches. Reviewed by davidbaumwald. Merges [61262] to the 6.9 branch. Props priethor, ellatrix. See #64267. git-svn-id: https://develop.svn.wordpress.org/branches/6.9@61263 602fd350-edb4-49c9-b593-d223f7449a82
Changes can be found at https://github.com/WordPress/gutenberg/commits/wp/6.9/. [Block Bindings: Add unit test coverage for core/post-data source](WordPress/gutenberg#73055) [Block Bindings: Error handling for external sources.](WordPress/gutenberg#72585) [Notes: Collapse note on blur](WordPress/gutenberg#73158) [Border-radius values triggers unintended px conversion](WordPress/gutenberg#73324) [Fix navigation tag entity binding](WordPress/gutenberg#73255) [DataViews: ensure primary actions are not wrapped in the list layout](WordPress/gutenberg#73345) [Fix: Fit Text may overflow into the padding area.](WordPress/gutenberg#73327) [Merge "Icon Size" and "Icon size" translation strings](WordPress/gutenberg#73325) [Notes: Improve delete confirm message for replies](WordPress/gutenberg#73173) [Fix: Custom font size taking over fit text.](WordPress/gutenberg#73241) [Fix a11y of descriptions and alerts for "Invalid" Nav Items](WordPress/gutenberg#73177) [Stretchy text: Hide variations in Block Inspector (hack)](WordPress/gutenberg#73238) [Update button label from "Add new note" to "Add new reply"](WordPress/gutenberg#73189) [Notes: Fix first note creation with pinned sidebar](WordPress/gutenberg#73164) Developed in WordPress/wordpress-develop#10528. See https://make.wordpress.org/core/handbook/about/release-cycle/block-editor-release-process-for-major-releases/#package-updates-and-core-patches. Reviewed by davidbaumwald. Merges [61262] to the 6.9 branch. Props priethor, ellatrix. See #64267. Built from https://develop.svn.wordpress.org/branches/6.9@61263 git-svn-id: http://core.svn.wordpress.org/branches/6.9@60575 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What?
Closes #72569
We don't need to add any warning, the error will appear on block render and will be logged on the console.
The block boundary will do the work. We just let the dropdown list to appear.
Why?
If an external source contains any error on JS, it may crash the block bindings UI.
How?
By try-catching the
getValuesfunction.Testing Instructions
Create a custom source that triggers an error on
getValues.Check that source is not shown on the UI.
Without the PR
The UI crashes on the dropdown render.
without_pr.mp4
After the PR
The block crashes on dropdown item selection ( if you choose an error source item )
with_pr.mp4