-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(ui): significantly more predictable autosave form state #13460
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
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
if ('value' in action) { | ||
for (const [path, field] of Object.entries(newState)) { | ||
if (path !== action.path && 'isModified' in field) { | ||
delete newState[path].isModified |
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.
Note: this is not ideal, but works for now. An alternate approach would be to store the lastModifiedPath
on the form context itself. That would remove this loop. The problem is we don't have access to that context from within the field reducer.
🚀 This is included in version v3.52.0 |
Continuation of #13416 and #13438.
Persists local state in a much more predictable way when autosave is enabled. Instead of comparing values to determine if a field was modified, we manage an
isModified
flag in local form state. Referential comparison was an inherent problem to begin with, as form state can include JSON, etc., and it would be expensive to deeply compare values.This PR also ensures computed values aren't overwritten during autosave. Right now it is possible to enter into race conditions where the incoming form state from the server overrides any local changes that were made while the initial request was still processing.
This is especially noticeable within JSON fields, etc. which are formatted on the server. This, by default, makes them have computed values.
Here's an example:
Before:
before.mov
After:
after.mp4