-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Fix empty modify on JSON save or edit #2816
Conversation
|
@@ -179,7 +179,7 @@ function Tokens({ isActive }: { isActive: boolean }) { | |||
// because of specific logic requirements | |||
setError(null); | |||
dispatch.tokenState.setStringTokens(getStringTokens()); | |||
}, [tokens, activeTokenSet, tokenFormat, tokenType, dispatch.tokenState, getStringTokens]); | |||
}, [tokens, activeTokenSet, tokenFormat, tokenType, dispatch.tokenState]); // getStringTokens removed to fix bug around first paste/edit (useEffect was being triggered) |
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.
From my testing, on the first edit of stringTokens
, getStringTokens
was changing, triggering this useEffect
to run with a race condition, wiping the initial change/paste.
This should fix it, but additional testing would be nice :)
if (typeof payload?.$extensions?.['studio.tokens'] !== 'undefined') { | ||
studioTokensExtension = Object.keys(payload?.$extensions?.['studio.tokens']).reduce((accExt, k) => { | ||
const extension = (payload?.$extensions?.['studio.tokens'] || {})[k]; | ||
if (extension && Object.values(extension).length > 0) { |
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.
This should look through every value of the studio.tokens
extension, and if an object with no values is found (i.e. modify: {}
), it should filter it out (avoid adding it to the accumulator object).
✅ Tested by copy pasting the JSON, and it works! 🤔 This might not be in scope for the fix, but now that there's the With your branch locally:
😫 This also adds an empty modify object My hunch is that the remapping action is adding it somewhere, maybe? renameTokenModifyObject.mp4 |
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.
This is a great candidate to write some unit tests 🤓
…a-plugin into fix/2805-empty-modify
…a-plugin into fix/2805-empty-modify
Why does this PR exist?
Closes #2805
What does this pull request do?
validateStudioTokensExtensions
util function to strip emptystudio.tokens
extensions such asmodify
.useEffect
dependency ongetStringTokens
.Testing this change
To reproduce
For existing tokens with empty
modify
:Edit Token
, then save.modify
should be stripped.Additional Notes (if any)
A migration step would be nice to automatically strip empty extension objects when the plugin is opened/upgraded, but this would probably be better left for a future migration system with strong testing/error catching.