Have useMergeRefs return a callback that mimics a ref#29188
Have useMergeRefs return a callback that mimics a ref#29188
Conversation
|
Size Change: +13 B (0%) Total Size: 1.38 MB
ℹ️ View Unchanged
|
Addison-Stavlo
left a comment
There was a problem hiding this comment.
Tested this out and it definitely fixes the slash inserter issues (including the site editor issue #29262). The link popover for buttons seems more consistent as well. Unfortunately I am unable to repro the original issue noted for the cover block focal point, but everything seems to be working well!
The fix seems reasonable to me, but I will defer to @ellatrix and @youknowriad since they have been working in this area and may have other insights or ideas.
|
After rebasing the gallery refactor PR drag and drop was broken due to the issue of the ref property being a function rather than an object with property of current ref. I think this is because in this case the block wrapper is acting as the outer block wrapper and the innerBlocks parent, so the outer wrapper blockProps ref is overriding the innerBlocks ref that the drag and drop provides is expecting. Applying this patch that the gallery refactor branch appears to fix the issue. |
| if ( value ) { | ||
| refsToUpdate = currentRefs.current; | ||
| // Makes this callback mimic a ref | ||
| rootCallback.current = value; |
There was a problem hiding this comment.
It seems this PR might be fixing the consequence and not the root of the issue. Where is the .current value being used in useBlockProps?
There was a problem hiding this comment.
Nowhere within useBlockProps. From what I can tell the root of the issue is a breaking change in #28917 (comment), this just patches so the previous expectation can be met. This same type of patch could probably be done from within useBlockProps instead if that is better in any way. I don't have a problem with the breaking change, but just figured it might be nice to avoid it if possible since third-party blocks could break.
There was a problem hiding this comment.
Indeed, I'd like to understand how impactful is the breaking change in other code aside Core code. For me, code relying on the fact that "ref" is an object is a code that need to be fixed anyway (core or third-party), so depending on the impact, I might be ok with this breaking change.
Since #28917 was merged, the
refproperty of the object returned byuseBlockPropsis a function instead of a ref. This PR lets the function returned fromuseMergeRefsmimic a ref by having acurrentproperty referencing thecurrentproperty of the appropriate ref.This seems to work well enough and tests aren't failing but it looks possible and may be preferable to do this in
useBlockPropsinstead ofuseMergeRefs.How has this been tested?
Verifying instances of breakage are fixed ;P
Screenshots detailing some breakage/fixage
I've posted three examples but there could be more.
Popover for slash inserter (first reported #28917 (comment))
Cover block focal point adjustment (only on repeated backgrounds)
Popover for Button block link
Types of changes
Bug fix #29262
Checklist: