-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state #7588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a617264
61a853e
560417f
7c30c68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -77,6 +77,7 @@ export default class CodeControl extends React.Component { | |||||||||||||
|
|
||||||||||||||
| state = { | ||||||||||||||
| isActive: false, | ||||||||||||||
| isLangInitialized: false, | ||||||||||||||
| unknownLang: null, | ||||||||||||||
| lang: '', | ||||||||||||||
| keyMap: localStorage.getItem(settingsPersistKeys['keyMap']) || 'default', | ||||||||||||||
|
|
@@ -124,7 +125,15 @@ export default class CodeControl extends React.Component { | |||||||||||||
| const keys = ['lang', 'theme', 'keyMap']; | ||||||||||||||
| const changedProps = getChangedProps(prevState, this.state, keys); | ||||||||||||||
| if (changedProps) { | ||||||||||||||
| this.handleChangeCodeMirrorProps(changedProps); | ||||||||||||||
| // Check if this is the initial setting of the language prop | ||||||||||||||
| const shouldIgnoreLangChange = | ||||||||||||||
| this.state.isLangInitialized === false && | ||||||||||||||
| !!changedProps?.lang && | ||||||||||||||
| Object.keys(changedProps).length === 1; | ||||||||||||||
|
|
||||||||||||||
| this.setState({ isLangInitialized: true }); | ||||||||||||||
|
|
||||||||||||||
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); | ||||||||||||||
|
Comment on lines
+134
to
+136
|
||||||||||||||
| this.setState({ isLangInitialized: true }); | |
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); | |
| this.handleChangeCodeMirrorProps(changedProps, shouldIgnoreLangChange); | |
| this.setState({ isLangInitialized: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Uh oh!
There was an error while loading. Please reload this page.