-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block versioning: Introduce a migration function #3673
Changes from 1 commit
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 |
---|---|---|
|
@@ -147,10 +147,16 @@ export function getAttributesFromDeprecatedVersion( blockType, innerHTML, attrib | |
...omit( blockType, [ 'attributes', 'save', 'supports' ] ), // Parsing/Serialization properties | ||
...blockType.deprecated[ i ], | ||
}; | ||
const deprecatedBlockAttributes = getBlockAttributes( deprecatedBlockType, innerHTML, attributes ); | ||
const isValid = isValidBlock( innerHTML, deprecatedBlockType, deprecatedBlockAttributes ); | ||
if ( isValid ) { | ||
return deprecatedBlockAttributes; | ||
|
||
try { | ||
const deprecatedBlockAttributes = getBlockAttributes( deprecatedBlockType, innerHTML, attributes ); | ||
const migratedBlockAttributes = deprecatedBlockType.migrate ? deprecatedBlockType.migrate( deprecatedBlockAttributes ) : deprecatedBlockAttributes; | ||
const isValid = isValidBlock( innerHTML, deprecatedBlockType, deprecatedBlockAttributes ); | ||
if ( isValid ) { | ||
return migratedBlockAttributes; | ||
} | ||
} catch ( error ) { | ||
// ignore error, it means this deprecated version is invalid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasoning here is that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the error being thrown? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no error nowhere. The idea is that
On an invalid block, this could throw an error since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think even the parsing could produce errors in theory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I feel a bit uneasy about the fact that we anticipate that this will occur 😬 |
||
} | ||
} | ||
} | ||
|
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 could use some more comments explaining the process.