Repository navigation
Fix: metadata add modal sends empty value due to stale closure - #15229
Conversation
…iflow#15139) The "+ Add" flow in the Set/Edit Metadata modal posted updates with an empty value, so backend saves were silent no-ops and the document's "X fields" count stayed at 0 despite a "Success" toast. The value <Input> updates `tempValues` synchronously per keystroke but only writes through to `metaData.values` on blur (via `handleValueBlur`). When the user clicks the nested modal's Confirm button without first blurring, the click handler races the blur and `handleSave` closes over the pre-blur `metaData.values` — still the initial ['']. `addUpdateValue` then queues an empty-string update; the auto-fire save sends it, and after `resetOperations()` the outer Save button posts updates: []. Read from `tempValues` instead so the queued update carries the typed value. Regression test in tests/use-manage-values-modal.test.ts asserts that handleSave passes the typed value (not the pre-blur empty string) to addUpdateValue in the add-new code path.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughUpdates useManageValues: ChangesMetadata Save State Race Condition
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This PR looks correct. The fix addresses a classic React stale closure bug where The dependency array update (adding To reply, just mention @dosu. Docs are dead. Just use Dosu. |
Previously handleSave only bailed on a duplicate field error when type === MetadataType.Setting. The same warning is shown to users in the UpdateSingle / Manage / SingleFileSetting modes, but submission went through anyway. Apply the guard uniformly so the UI's warning state actually blocks save in every mode. Expand the regression test file to cover the duplicate-field guard across all modes, edit-existing flows, the duplicate-value guard, delete and clear behaviors, valueType changes, and the add-row path.
|
@dcc123456 , Can you review this when you have a moment? |
|
@wangq8 , Could you take a look at this, please? |
|
Weekly follow-up. |
Reviewer noted the type === MetadataType.Setting condition on the field-error guard cannot be removed. Restore it so only Setting mode hard-blocks save on a duplicate field name; UpdateSingle/Manage still surface the warning but proceed, matching prior behavior. Re-add type to the callback deps and update the two guard tests to assert the Setting-only semantics.
|
Updated! |
|
@dcc123456 , pls let me know if you have any other feedback. |
What problem does this PR solve?
Closes #15139.
The "+ Add" flow in the Set/Edit Metadata modal posted updates with an empty value, so backend saves were silent no-ops and the document's "X fields" count stayed at 0 despite a "Success" toast.
The value
<Input>updatestempValuessynchronously per keystroke but only writes through tometaData.valueson blur (viahandleValueBlur). When the user clicks the nested modal's Confirm button without first blurring, the click handler races the blur andhandleSavecloses over the pre-blurmetaData.values— still the initial[''].addUpdateValuethen queues an empty-string update; the auto-fire save sends it, and afterresetOperations()the outer Save button postsupdates: [].Read from
tempValuesinstead so the queued update carries the typed value.Regression test in
tests/use-manage-values-modal.test.tsasserts thathandleSavepasses the typed value (not the pre-blur empty string) toaddUpdateValuein the add-new code path.Type of change