enhancement: Enable immediate JSON synchronization with validation in JSON Editor#7213
Open
obrobrio2000 wants to merge 1 commit intosurveyjs:masterfrom
Open
enhancement: Enable immediate JSON synchronization with validation in JSON Editor#7213obrobrio2000 wants to merge 1 commit intosurveyjs:masterfrom
obrobrio2000 wants to merge 1 commit intosurveyjs:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements real-time synchronization of the JSON Editor text to fix issues where changes made in the JSON Editor tab weren't immediately available via creator.text. Previously, JSON changes only synchronized when switching away from the tab, causing data loss and preventing immediate saves.
Key changes:
- Enhanced the
textgetter to retrieve current JSON directly from the editor plugin when on the JSON tab - Added a new
syncJsonEditorText()method to force synchronization before critical operations - Set the
isJSONChangedflag immediately when text changes in the editor
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
packages/survey-creator-core/src/components/tabs/json-editor-plugin.ts
Outdated
Show resolved
Hide resolved
… JSON Editor (closes surveyjs#7212) Signed-off-by: Giovanni Magliocchetti <[email protected]>
7bfc5af to
da91a27
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
This PR implements immediate JSON synchronization in the JSON Editor tab while maintaining validation to ensure data integrity. Previously, JSON changes were only saved when switching away from the JSON Editor tab, causing issues with immediate saves and potential data loss during rapid edits.
✨ Changes
Modified Files
packages/survey-creator-core/src/components/tabs/json-editor-plugin.tsKey Changes
Added
Modelimport fromsurvey-coreNew property:
lastSyncedTextcreator.JSONNew method:
syncToCreator()JSON.parse()new Model(surveyDefinition).jsonErrorscreator.JSONif both validations passisJSONChanged = trueonly after successful synconModifiedevent immediately for real-time updatesEnhanced:
processErrors()syncToCreator()if no errors detectedNew method:
hasUnsyncedChanges()deactivate()to handle fast tab switchesEnhanced:
deactivate()false)Enhanced:
onPluginActivate()lastSyncedTextwhen tab is activated🔄 Workflow
New Synchronization Flow
processErrors()validates syntaxsyncToCreator()validates semanticscreator.JSONonModifiedevent for external listenersFast Tab Switch Handling
deactivate()detects unsynced changes✅ Benefits
isJSONChangedset only after successful validation🧪 Testing Recommendations
Manual Testing
Immediate Save Test
Invalid JSON Test
Rapid Edit Test
Fast Tab Switch Test
onModified Event Test
creator.onModifiedAutomated Testing (if applicable)
syncToCreator()with valid JSONsyncToCreator()with invalid syntaxsyncToCreator()with invalid survey semanticshasUnsyncedChanges()returns correct statedeactivate()with unsynced changesdeactivate()with invalid JSON🔍 Breaking Changes
None. This PR maintains backward compatibility:
deactivate()behavior preserved💬 Additional Notes
This implementation follows the validation-first principle emphasized by the SurveyJS team in support tickets. JSON is validated both syntactically (JSON.parse) and semantically (Survey Model jsonErrors) before any synchronization occurs, ensuring that
creator.JSONalways reflects a valid survey state.The solution addresses the core issue while maintaining all safety guarantees that prevent invalid JSON from corrupting the creator state.