fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state#7588
Conversation
…nsaved changes state
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where the code widget incorrectly triggers the onChange callback when initializing the language value from props, causing the CMS to show "unsaved changes" status when loading a document with a saved language setting.
- Added state tracking to identify initial language initialization
- Modified the language change handler to ignore the initial language setting
- Prevented false positive unsaved changes state on document load
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| this.setState({ isLangInitialized: true }); | ||
|
|
||
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); |
There was a problem hiding this comment.
Setting isLangInitialized to true should be done after the language change is processed, not before. If handleChangeCodeMirrorProps throws an error, the flag will be incorrectly set to true even though initialization didn't complete successfully.
| this.setState({ isLangInitialized: true }); | |
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); | |
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); | |
| this.setState({ isLangInitialized: true }); |
There was a problem hiding this comment.
I disagree with this, the ordering here is intentional for graceful failure; if for some reason handleChangeCodeMirrorProps errors we would rather falsely report changes when there are none than potentially ignore actual changes that have been made.
|
@dlford please check if Copilot makes sense here. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nsaved changes state (decaporg#7588) * fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state * 7588: apply copilot nitpick Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Martin Jagodic <jagodicmartin1@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
fixes #7431
Summary
The code widget executes the
onChangecallback anytimelangis changed, including when initializing the value fromprops. This causes the CMS to act as if there are unsaved changes any time a document is loaded with a saved language in the code widget.Test plan
Using the below config and index, create a new blog post and add a code component, set the language and save. Reload the page, you should see the "changes saved" message in the top left of the CMS instead of "unsaved changes".
config.ymlindex.htmlChecklist
Please add a
xinside each checkbox: