-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Mobile - Columns block - Fix transforming into a Group block crash #54035
Conversation
…hat's nested in a container block like Group. By avoid accessing the width value outside of the isSelected and adding a fallback value.
Size Change: 0 B Total Size: 1.51 MB ℹ️ View Unchanged
|
Flaky tests detected in 7069a35. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6027262663
|
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.
LGTM 🎊 ! Awesome work @geriux 🎖️ !
NOTE: I noticed that one of the CI jobs failed but seems unrelated to these changes. Probably re-running it would make it pass.
const { width: columnWidth } = contentStyle[ clientId ] || {}; | ||
const isFullWidth = columnWidth === screenWidth; |
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.
The value passed as contentStyle
is contentWidths
, which is calculated in:
gutenberg/packages/block-library/src/columns/edit.native.js
Lines 147 to 157 in 1ae7d9f
const contentWidths = useMemo( | |
() => | |
getContentWidths( | |
columnsInRow, | |
width, | |
columnCount, | |
innerWidths, | |
globalStyles | |
), | |
[ width, columnsInRow, columnCount, innerWidths, globalStyles ] | |
); |
I checked the parameters passed in getContentWidths
when transforming the block to a Group block, and noticed that columnCount
is 0 in the first render after the transformation. In the second render, the column count is set to back the proper value and populates contentWidths
with the expected data. Seems that upon transformation there's an initial state that doesn't have the columns parameter ready. That said, this approach makes sense and will definitely address the crash.
@@ -133,7 +133,7 @@ function ColumnEdit( { | |||
); | |||
} | |||
return null; | |||
}, [ contentStyle[ clientId ], screenWidth, isSelected, hasChildren ] ); | |||
}, [ contentStyle, clientId, screenWidth, isSelected, hasChildren ] ); |
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.
The value passed as contentStyle
(i.e. contentWidths
) is memoized here:
gutenberg/packages/block-library/src/columns/edit.native.js
Lines 147 to 157 in 1ae7d9f
const contentWidths = useMemo( | |
() => | |
getContentWidths( | |
columnsInRow, | |
width, | |
columnCount, | |
innerWidths, | |
globalStyles | |
), | |
[ width, columnsInRow, columnCount, innerWidths, globalStyles ] | |
); |
contentStyle={ contentWidths } |
Hence, using this new dependency list won't produce extra renders.
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.
Yup! Since it's still a dependency I left it to also avoid the ESLint warning, although it can be disabled it's best to leave it.
@geriux I forgot to mention that it would be great to add an entry to the |
…ow its imported from the helpers instead of the initializedEditor
Thanks for the reminder! I've added a changelog entry for this change. |
Fixes wordpress-mobile/gutenberg-mobile#6100
Related PRs:
What?
This PR fixes a crash when transforming a nested Columns block into a Group block.
By checking the error it was happening around:
Checking the breadcrumbs shows the last UI change before the crash:
Why?
To fix some crashes in production related to transforming Columns blocks into Group blocks.
How?
By moving part of the logic of
renderAppender
within theisSelected
if condition and also by adding a default value tocontentStyle
in case ofundefined
values.Testing Instructions
Precondition: Use the following HTML code:
Transform block...
Group
Screenshots or screencast
ColumnsBefore.mov
ColumnsAfter.mov