-
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
Using customClassName: false produces a weird bug #20874
Comments
Note: I just checked with latest Gutenberg plugin version, 7.7.1, and this issue seems to be fixed there. So, this should be just about backporting the fix to WP 5.4 before it's too late. |
@jorgefilipecosta It would be good to identify if there's a fix that needs backporting here. Maybe the SlotFill refactor fixed this issue? |
I verified the issue is present in WordPress 5.4 RC and happens even with the default blocks (e.g: paragraph and shortcode block). The issue is not present in the Gutenberg plugin because it was fixed by #19242. |
Looking specifically at the changes of 6447a09 and comparing to how it was fixed via #19242, I believe the issue stems from this remark in the pull request:
You can see in 6447a09 that |
I was able to confirm that it's the lack of an updating context value which prevents the rendering from occurring as expected in the changes introduced with 6447a09. I did so by isolating a small subset of the effective fix from #19242, applied to the previous implementation of diff --git a/packages/components/src/slot-fill/context.js b/packages/components/src/slot-fill/context.js
index b4229c71f..094d47821 100644
--- a/packages/components/src/slot-fill/context.js
+++ b/packages/components/src/slot-fill/context.js
@@ -31,11 +31,12 @@ class SlotFillProvider extends Component {
this.getFills = this.getFills.bind( this );
this.hasFills = this.hasFills.bind( this );
this.subscribe = this.subscribe.bind( this );
+ this.updateContext = this.updateContext.bind( this );
this.slots = {};
this.fills = {};
this.listeners = [];
- this.contextValue = {
+ const contextValue = {
registerSlot: this.registerSlot,
unregisterSlot: this.unregisterSlot,
registerFill: this.registerFill,
@@ -45,6 +46,11 @@ class SlotFillProvider extends Component {
hasFills: this.hasFills,
subscribe: this.subscribe,
};
+ this.state = { contextValue };
+ }
+
+ updateContext() {
+ this.setState( { contextValue: { ...this.state.contextValue } } );
}
registerSlot( name, slot ) {
@@ -63,6 +69,7 @@ class SlotFillProvider extends Component {
if ( previousSlot ) {
previousSlot.forceUpdate();
}
+ this.updateContext();
}
registerFill( name, instance ) {
@@ -71,6 +78,7 @@ class SlotFillProvider extends Component {
instance,
];
this.forceUpdateSlot( name );
+ this.updateContext();
}
unregisterSlot( name, instance ) {
@@ -83,6 +91,7 @@ class SlotFillProvider extends Component {
delete this.slots[ name ];
this.triggerListeners();
+ this.updateContext();
}
unregisterFill( name, instance ) {
@@ -92,6 +101,7 @@ class SlotFillProvider extends Component {
);
this.resetFillOccurrence( name );
this.forceUpdateSlot( name );
+ this.updateContext();
}
getSlot( name ) {
@@ -139,7 +149,7 @@ class SlotFillProvider extends Component {
render() {
return (
- <Provider value={ this.contextValue }>
+ <Provider value={ this.state.contextValue }>
{ this.props.children }
</Provider>
); This mimics the memoization behavior implemented in #19242 via the new As I see it, options for WordPress 5.4 could be one of the following:
(cc @diegohaz) |
This is the only option I would go against as I'm not sure how this would impact the current code that relies on forced updates. If all tests pass though, maybe it's not a problem. I also think that It's not supported by React Native. So, even if we migrate every |
The patch in #20874 (comment) seemed to work okay when applied to the
I suppose it could be an issue that somewhere, as a result of the context updating, a component triggers to register or unregister a slot or fill (thus causing an infinite loop). In any case, it's alarming enough to me to want to avoid it. @diegohaz For this issue specifically, could you imagine any subset of changes from #19242 we could use for a fix? Or you think it should be cherry-picked in its entirety? Is your commentary on |
I think the safest option for now is to cherry-pick #19242 entirely. Regarding |
The refactor was cherry-picked so we can close this issue. |
Describe the bug
In WP 5.4-RC2, if a block uses
a weird bug occurs in relationship with another block that displays Advanced panel: if you click on a block without Advanced and immediately on a block with that panel, the panel will be missing from the block where it should be, and shown on the block where it shouldn't be (and corrupted - without controls inside).
This was not happening on WP 5.3.
To reproduce
Steps to reproduce the behavior:
customClassName: false
and 1 withcustomClassName: true
Expected behavior
Advanced panel shows by default, does not show on a block with
customClassName: false
, and works properly. This worked properly on WP 5.3.Desktop (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: