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: safely executes form state conditions, validations, and default values #10275

Merged
merged 8 commits into from
Jan 2, 2025

Conversation

jacobsfletch
Copy link
Member

@jacobsfletch jacobsfletch commented Dec 31, 2024

Whenever form state fails, like when field conditions, validations, or default value functions throw errors, blocks and array rows are stuck within an infinite loading state. Examples of this might be when accessing properties of undefined within these functions, etc. Although these errors are logged to the server console, the UI is be misleading, where the user often waits for the request to resolve rather than understanding that an underlying API error has occurred. Now, we safely execute these functions within a try...catch block and handle their failures accordingly. On the client, form state will resolve as expected using the default return values for these functions.

@jacobsfletch jacobsfletch changed the title fix(ui): logs and toasts server function errors fix(ui): logs and displays server function errors Dec 31, 2024
@jacobsfletch jacobsfletch enabled auto-merge (squash) December 31, 2024 05:05
@jmikrut
Copy link
Member

jmikrut commented Dec 31, 2024

I wonder if instead of throwing an error, which will likely mean nothing to end-users of the admin panel, we should just wrap any custom user code in a try / catch and then log the error in console. Validations with errors return false, with a helpful message, and conditions simply return false on error. Default values return undefined.

This might be a better path forward here. We should make it so the form state itself is returned in as many cases as possible.

What do you think?

@jacobsfletch jacobsfletch requested a review from denolfe as a code owner January 2, 2025 15:03
@jacobsfletch jacobsfletch changed the title fix(ui): logs and displays server function errors fix(ui): safely handles field conditions and validations Jan 2, 2025
@jacobsfletch jacobsfletch changed the title fix(ui): safely handles field conditions and validations fix(ui): safely handles field conditions, validations, and default values Jan 2, 2025
@jacobsfletch jacobsfletch changed the title fix(ui): safely handles field conditions, validations, and default values fix: safely executes form state conditions, validations, and default values Jan 2, 2025
@jacobsfletch jacobsfletch merged commit 7928eca into main Jan 2, 2025
82 checks passed
@jacobsfletch jacobsfletch deleted the fix/toast-form-state-errors branch January 2, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants