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
Site Editor: Fix deprecation console error in top toolbar #55678
Conversation
Size Change: -3 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
@@ -191,7 +191,7 @@ export default function HeaderEditMode( { setListViewToggleElement } ) { | |||
> | |||
{ hasDefaultEditorCanvasView && ( | |||
<NavigableToolbar | |||
as={ motion.div } | |||
render={ <motion.div /> } |
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 don't know if the as
prop was part of the public API of the NavigableToolbar
component. But if it was, we should probably re-implement that within NavigableToolbar
.
Something like this may work:
const Component = props.as;
const render = Component ? <Component /> : undefined;
<Toolbar render={ render } />
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.
Thanks for the review!
It appears that the as
prop in the NavigableToolbar
component is not defined and is simply received as a remainder of the defined props. In this case, I thought it would be better not to re-implement internally from as
prop to render
prop, but what do you think?
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.
There's a few things happening here:
Toolbar
technically never supported theas
prop: thefalse
here in fact marks the component as non polymorphic- But since the component internally used to spread the props to the underlying reakit component, passing the
as
prop worked (even if technically not supported) Toolbar
was recently refactored fromreakit
toariakit
, which introduced the deprecation warning for theas
prop
So, technically Toolbar
doesn't support neither as
nor render
. On top of that, looking at the implementation of NavigableToolbar
, depending on the isAccessibleToolbar
prop, it could also render a NavigableMenu
, which would ignore the as
prop completely.
It just seems to me that the best choice here is to find a different way to animate the header without passing the as
prop (or render
prop) to Toolbar
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.
Maybe the other way around?
const MotionNavigableToolbar = motion( NavigableToolbar );
// ...
<MotionNavigableToolbar>
Ref: https://www.framer.com/motion/component/#custom-components
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.
yeah we could try that
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.
Thank you for your ideas. I have tried various implementations based on the documentation, but so far nothing has worked. The editor crashes with an error logged in the browser console, or the animation doesn't work.
const MotionNavigableToolbar = motion( NavigableToolbar );
// ...
<MotionNavigableToolbar
...
/>
const MotionNavigableToolbar = motion( 'NavigableToolbar' );
// ...
<MotionNavigableToolbar
...
/>
const MotionNavigableToolbar = motion( 'navigable-toolbar' );
// ...
<MotionNavigableToolbar
...
/>
const Component = forwardRef( ( props, ref ) => (
<NavigableToolbar ref={ ref } { ...props } />
) );
const MotionNavigableToolbar = motion( Component );
// ...
<MotionNavigableToolbar
...
/>
const Component = forwardRef( ( { children, ...props }, ref ) => (
<NavigableToolbar { ...props } ref={ ref }>
{ children }
</NavigableToolbar>
) );
const MotionNavigableToolbar = motion( Component );
// ...
<MotionNavigableToolbar
...
/>
I'll try to find another approach.
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.
How about wrapping NavigableToolbar
in a motion.div
?
Or simply adding the animation via SCSS ?
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.
How about wrapping
NavigableToolbar
in amotion.div
?
In the end, I did this approach. The layout and animations should remain the same.
Flaky tests detected in b0889c1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6715616142
|
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.
Tested this and the animation looks as in trunk
.
Thank you everyone for your review. I found out that this component was refactored in #55770, causing a conflict. So I merged the latest trunk and made similar changes. There are a lot of differences in this PR diff, but I simply wrapped it in I have confirmed that it is working as before, so I would like to merge it as soon as it passes the tests. |
Yup, using the "hide whitespace" option when reviewing the code diff helps a lot to reduce the noise. Code-wise this LTGM, I'll let other folks confirm that the animation behaves as expected. |
Thank you, I didn't know this method until now 😅 |
I didn't know about that either. That's super handy! |
What?
This PR fixes a browser warning error that is logged when opening the editor canvas in the Site Editor.
e370345309f15367d49226c1f3b3bfee.mp4
Why?
According to my research, I found that this error occurred in the
HeaderEditMode
component. Inside this component, theas
property is used on theNavigableToolbar
. And this component is internally renderingAriakit.Toolbar
. As the console message indicates, I expected that we should use therender
property instead of theas
property.How?
I simply changed theWrapas
property to therender
property.NavigableToolbar
in amotion.div
.Testing Instructions
Screenshots or screencast
22debb53902e0352562fc32b09d35bd7.mp4