fix: resolve custom tool input schema persistence race condition#5885
fix: resolve custom tool input schema persistence race condition#5885DiveshK007 wants to merge 2 commits intoFlowiseAI:mainfrom
Conversation
MUI DataGrid defers state updates when a cell is still in edit mode. Clicking Save without blurring caused stale schema state to be serialized, making edits appear to revert. Force-commit pending cell edits before save, stabilize row identity, and serialize schema using the latest state.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the reliability of custom tool input schema persistence. By proactively handling MUI DataGrid's asynchronous state updates and ensuring data integrity through stable row identification and robust validation, it prevents data loss and inconsistent behavior when users edit and save tool schemas. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves a race condition with custom tool input schema persistence by force-committing pending edits from the MUI DataGrid before saving. The use of a ref to hold the latest state, stabilizing row identities with UUIDs, and adding pre-save validation are all excellent improvements. My only feedback is a suggestion to refactor some duplicated code to enhance maintainability.
| await commitPendingEdits() | ||
| const schemaError = getSchemaValidationError() | ||
| if (schemaError) { | ||
| enqueueSnackbar({ | ||
| message: schemaError, | ||
| options: { | ||
| key: new Date().getTime() + Math.random(), | ||
| variant: 'error', | ||
| persist: true, | ||
| action: (key) => ( | ||
| <Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}> | ||
| <IconX /> | ||
| </Button> | ||
| ) | ||
| } | ||
| }) | ||
| return | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
Pull request overview
Fixes a race where MUI DataGrid edits weren’t committed before persisting a custom tool’s input schema, leading to stale schema serialization when users click Save without blurring the edited cell.
Changes:
- Adds a DataGrid
apiRefand acommitPendingEdits()step to force-commit in-progress cell edits prior to saving/exporting. - Switches schema row identity to UUIDs and introduces schema (de)serialization helpers (
formatSchemaRows,serializeSchema) with normalization. - Adds schema validation on save (empty property + duplicate property names).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/ui/src/views/tools/ToolDialog.jsx | Forces edit commit before save/export, stabilizes row IDs, serializes schema from “latest” state, and validates schema. |
| packages/ui/src/views/tools/PasteJSONDialog.jsx | Generates UUID row IDs for pasted schema and normalizes/cleans pasted properties. |
| packages/ui/src/ui-component/grid/Grid.jsx | Extends shared Grid wrapper to accept and pass through MUI DataGrid apiRef. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Ref that always mirrors the latest toolSchema state. | ||
| // Needed because MUI DataGrid's processRowUpdate → onRowUpdate uses setTimeout, | ||
| // so React state may not yet reflect the latest edit when Save is clicked. | ||
| const toolSchemaRef = useRef(toolSchema) | ||
| useEffect(() => { | ||
| toolSchemaRef.current = toolSchema | ||
| }, [toolSchema]) |
There was a problem hiding this comment.
toolSchemaRef is kept in sync via useEffect, which runs after paint. Because serializeSchema()/getSchemaValidationError() read from the ref, there’s still a window where the UI has rendered the latest toolSchema but the ref hasn’t been updated yet, so a fast click on Save/Save As Template could serialize stale schema. Consider syncing this ref in a useLayoutEffect, or updating toolSchemaRef.current inside every setToolSchema call (not just onRowUpdate) so it is always current before any save handler runs.
| const commitPendingEdits = async () => { | ||
| try { | ||
| const editRowsModel = gridApiRef.current?.state?.editRows | ||
| if (editRowsModel) { | ||
| for (const rowId of Object.keys(editRowsModel)) { | ||
| for (const field of Object.keys(editRowsModel[rowId])) { | ||
| try { | ||
| gridApiRef.current.stopCellEditMode({ id: rowId, field }) | ||
| } catch (_) { |
There was a problem hiding this comment.
commitPendingEdits reads gridApiRef.current.state.editRows, which is an internal DataGrid state shape and can change across @mui/x-data-grid versions. Prefer a public apiRef method/selector (if available in 6.8.0) to get the current edit model, or encapsulate this behind a small helper with a comment tying it to the specific MUI version to reduce upgrade risk.
Fixes #5761
MUI DataGrid defers state updates when a cell is still in edit mode. Clicking Save without blurring caused stale schema state to be serialized, making edits appear to revert.
Force-commit pending cell edits before save, stabilize row identity, and serialize schema using the latest state.