Skip to content

Fix: metadata add modal sends empty value due to stale closure - #15229

Merged
wangq8 merged 5 commits into
infiniflow:mainfrom
nickmopen:fix/metadata-edit-empty-updates
Jun 22, 2026
Merged

wangq8 merged 5 commits into
infiniflow:mainfrom
nickmopen:fix/metadata-edit-empty-updates

Conversation

@nickmopen

Copy link
Copy Markdown
Contributor

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> 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.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

nickmopen added 2 commits May 26, 2026 05:19
…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.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 26, 2026
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1d49664f-f2de-49d4-893f-0eb0e7822ad8

📥 Commits

Reviewing files that changed from the base of the PR and between 36d6f42 and 12ccb22.

📒 Files selected for processing (2)
  • web/src/pages/dataset/components/metedata/hooks/tests/use-manage-values-modal.test.ts
  • web/src/pages/dataset/components/metedata/hooks/use-manage-values-modal.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/pages/dataset/components/metedata/hooks/use-manage-values-modal.ts
  • web/src/pages/dataset/components/metedata/hooks/tests/use-manage-values-modal.test.ts

📝 Walkthrough

Walkthrough

Updates useManageValues: handleSave now aborts when any valueError.field exists and uses current tempValues for add-mode saves. Adds an extensive Jest regression suite for add/edit/delete, duplicate detection, valueType switching, blur/save timing, and add-row behavior. No public API changes.

Changes

Metadata Save State Race Condition

Layer / File(s) Summary
handleSave guard and tempValues use
web/src/pages/dataset/components/metedata/hooks/use-manage-values-modal.ts
handleSave now returns early if valueError.field is set; when isAddValueMode it passes tempValues to addUpdateValue and the useCallback deps were updated to include tempValues and remove type.
Comprehensive useManageValues test suite
web/src/pages/dataset/components/metedata/hooks/tests/use-manage-values-modal.test.ts
Adds react-i18next mock, makeProps helper, and tests covering add/save timing, duplicate field/value guards across modes, edit-mode blur/update behavior, delete/clear handlers, valueType changes, and add-row deduplication.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped through blur and save,
Kept tempValues brave and brave.
No more empty updates in queue,
Fields and values stick like dew.
A tiny test parade — hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the core fix: addressing a stale closure bug in the metadata add modal that caused empty values to be sent.
Description check ✅ Passed The description covers all required sections including problem statement, type of change, and root cause analysis with detailed technical explanation.
Linked Issues check ✅ Passed The PR directly addresses issue #15139 by fixing the stale closure bug causing empty updates arrays, adding regression tests, and ensuring typed values are sent instead of pre-blur empty strings.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the identified metadata modal bug: the hook implementation fix and comprehensive regression test suite for the specific issue.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nickmopen

Copy link
Copy Markdown
Contributor Author

@dosu

@dosubot

dosubot Bot commented May 26, 2026

Copy link
Copy Markdown

This PR looks correct. The fix addresses a classic React stale closure bug where handleSave closed over metaData.values (which only syncs on blur), so a Confirm click that races the blur would queue the pre-blur empty string ['']. Reading from tempValues instead captures the real-time typed input regardless of whether blur has fired .

The dependency array update (adding tempValues) is also correct to keep the hook semantics sound, and the regression test properly validates the "Confirm without blur" path .

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about ragflow Share Dosu with your team

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.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 26, 2026
@nickmopen

Copy link
Copy Markdown
Contributor Author

@dcc123456 , Can you review this when you have a moment?

@nickmopen

Copy link
Copy Markdown
Contributor Author

@wangq8 , Could you take a look at this, please?

@nickmopen

Copy link
Copy Markdown
Contributor Author

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.
@nickmopen

Copy link
Copy Markdown
Contributor Author

Updated!

@nickmopen
nickmopen requested a review from dcc123456 June 18, 2026 03:42
@nickmopen

Copy link
Copy Markdown
Contributor Author

@dcc123456 , pls let me know if you have any other feedback.

@wangq8
wangq8 merged commit 329e09f into infiniflow:main Jun 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question]: Cannot add metadata via UI: Request payload sends empty "updates: []" despite "Success" message (v0.25.4)

3 participants