enhancement: Enable immediate JSON synchronization with validation in JSON Editor #7213
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.