-
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
(RichText)(Workaround)(17.1.x) Fallback to a string arg in collapseWhiteSpace()
if value
is not a string
#56570
(RichText)(Workaround)(17.1.x) Fallback to a string arg in collapseWhiteSpace()
if value
is not a string
#56570
Conversation
Size Change: +5 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
…id TypeErorrs See the comments in this changeset for more info on why this was needed.
9c732af
to
2bb1c16
Compare
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.
Seems ok and makes sense considering the stack trace of the bug this is fixing and the commit bisected to, but I'm not the most well-versed in all the details of React stuff.
Yeah, I don't like changing the argument's value either. I think your suggestion of a more localized fix makes sense. Done in 0eecb37. This is really a laser-focused fix based on the stacktrace of the unhandled exception that prevents the block from rendering, but I haven't seen any other failures due to the |
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 looks safer, targeting just what seems to have changed to cause the bug. 👍
@@ -71,7 +71,9 @@ export function useRichText( { | |||
function setRecordFromProps() { | |||
_value.current = value; | |||
record.current = create( { | |||
html: preserveWhiteSpace ? value : collapseWhiteSpace( value ), | |||
html: preserveWhiteSpace | |||
? value |
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 tested the scenario with presrveWhiteSpace
= true
and it doesn't crash, so the problem seems limited to the collapseWhiteSpace
call.
collapseWhiteSpace()
if value
is not a string
…hiteSpace()` if `value` is not a string (#56570) * (RichText)(Fix)(Workaround) Make sure value is always a string to avoid TypeErorrs See the comments in this changeset for more info on why this was needed. * Use a more localized fix that does not change the argument
…hiteSpace()` if `value` is not a string (#56570) * (RichText)(Fix)(Workaround) Make sure value is always a string to avoid TypeErorrs See the comments in this changeset for more info on why this was needed. * Use a more localized fix that does not change the argument
What?
Add a safeguard type-check that sets the
value
to''
if it's not a string in theRichText
component.A better solution would be to figure out why
null
is being passed there, but this seems to be a feasible temporary workaround if we don't get to the real culprit.Why?
The issue that led to this fix was found in the
Multi-Line Text Field block, provided by Jetpack. The block is completely broken in 17.1.2 and (current)
trunk`.How?
By passing an empty string to the
collapseWhiteSpace
ifvalue
is not a string.Testing Instructions
Multi-Line Text Field
;This block has encountered an error and cannot be previewed.
is rendered;Multi-Line Text Field
block to the page and notice how it render and works correctly now.Testing Instructions for Keyboard
Screenshots or screencast