-
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
Update image block save to only save align none class #56449
Conversation
Size Change: +6.82 kB (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
Flaky tests detected in fe091f1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7117243983
|
Interesting, this change does break something it appears that now there is an |
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 went deeper than I expected for a one line change.
As far as I can tell, the { align: 'none' }
attribute only ever came from the shortcode transform for the image block. (Or, technically, someone could have manually entered it in the code view.) Surprisingly, the regex from raw HTML for the attribute didn't even include it despite the alignnone
class being used in TwentyThirteen & TwentyTwenty default themes. Not sure if that's a bug, but if it is, it's been around for more than 6 years and is probably considered functionality by someone at this point [ref].
gutenberg/packages/block-library/src/image/transforms.js
Lines 221 to 226 in 66078c4
align: { | |
type: 'string', | |
shortcode: ( { named: { align = 'alignnone' } } ) => { | |
return align.replace( 'align', '' ); | |
}, | |
}, |
Because of this code, any align*
class has been considered valid, not just the ones supported by the block supports and alignnone
. If we really want to maintain the old behavior, we can't change this line. As we've seen, this doesn't cause the classes to be doubled up, so I think it's okay. But it's probably worthwhile adding a comment as to why.
We could also just consider everything other than |
I think this is fair. |
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 added a comment for future devs to know why alignnone
is handled here, but not the other align classes.
Follow up from #55954 to update the save function of the image block to no longer set the align class on render.
That was an oversight of the original PR. #55954 did work - not ending up with duplicate classes - because of implementation consistency :) the name of the class set by the support is the same as the one set by the save function and it would just be replaced.
This should be a benign change, but @youknowriad 's observation about the complexity of this block is something to keep an eye on.