You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Block] CoverAffects the Cover Block - used to display content laid over a background image[Feature] Nested / Inner BlocksAnything related to the experience of nested/inner blocks inside a larger container, like Group or P[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release
Describe the bug
when inserting a new Cover, changing the paragraph to heading using "/" break it
related: #16959
possibly related: #16851 To reproduce
Steps to reproduce the behavior:
create a new cover block
set a background
in the paragraph field, write / to insert a heading
it breaks
Expected behavior
Paragraph should turn into Heading block
Screenshots
Desktop (please complete the following information):
Narrowed down the problem to block-list/block & hooks/align
no block is being passed the moment of transfer, so props is empty (no attributes, block name..)
testing on Gutenberg 5.8.0 (version just prior to the version #15038 was merged on) showed no problem, so I'm assuming it's a regression.
I think this comment has something to do with it
So apparently, withSelect is being called with the old clientId. It looks like this is the zombie children bug for me. Is it possible that errors are not caught properly with the useSelect refactoring?
Apparently, this regression happened in the same release that introduced useSelect too.
Ohhh! I think It might be because the error is not triggered in withSelect directly but it's triggered in another Higher-order component withFilters that is based on the result of the withSelect. (Makes me wonder if we should trigger an error explicitly in withSelect if there's no block. Seems like a hacky fix though :)
We need the error to be thrown inside mapSelect for the failsafe to work. I would just refactor the mapSelect of this component to check that it's not running with stale props.
@epiqueras can you demonstrate how can this be done? I've already tried throwing an error inside mapSelect callback inside the withSelect but it resulted in the same problem, useSelect would catch that error & throw it again.
specifically, you can catch the block inside applyWithSelect@block-list/blockif it's defined or not
Where is the error coming from? withSelect or withFilter? useSelect returns the previous result if mapSelect fails so also keep that in mind with what you're trying.
while doing some basic debugging with @youknowriad we found that it's in withSelect, no error is triggered since it's returning the previous block clientID (so if you try to transform a paragraph to heading, withSelect will try to get you the paragraph block clientID, even though the store has the heading block, this triggers no error in withSelect since there is no check right now, the error only surface down in withFilter when another components need to use the new block
doing a manual check inside withSelect like this will just surface the error earlier but would still fail & break the component
if ( !block) throw new Error( 'no block' );
if you have a minute or two maybe you can give it a try so if it persists
I'm personally a bit concerned about this and why we're not capable of providing a solution that works out of the box without touching the component itself.
The "least bad" solution I see is to have a HoC between withSelect and withFilters that just renders nothing if the block is not available.
I still haven't fully dug into the issue yet so I'm just going by comments so far. But I did want to raise these points:
It's not clear to me yet what exactly is the source of the error. The cause is clear but not what is triggering that cause.
To fix this specific issue, what @youknowriad proposes sounds like a path forward.
However, I'm wary that this may be surfacing a larger flaw either in withSelect or withFilter that could surface elsewhere... so even if the quick fix is implemented, we'd should still investigate whether either of these hocs needs a closer look (or "gotchas" documented to prevent future occurrences).
I'll try and see if I can debug this further sometime today but for now just thought I'd give my two cents :)
The original withSelect impelementation might have some edge cases where this triggered but it was largely solved (granted it's not async mode compatible). The fact that this works the commit before useSelect is introduced is telling.
You're right that we don't have too much choice here. We could:
add those guidelines somewhere
Apply the fix @nerrad suggested for this particular component. (Let's comment why it was added)
In an ideal world, React would provide an API for us to fix this. Not sure if they're considering it but I'm pretty sure we're not the only ones having that need.
In an ideal world, React would provide an API for us to fix this. Not sure if they're considering it but I'm pretty sure we're not the only ones having that need.
The Redux connect HOC solves it, because every wrapped component replaces its subtree's store with a clone that runs its subscriptions after its parent. They also suggest that if you can't get around the error by modifying your selecting functions, you could just wrap the component in connect so that the subscription hierarchy can kick in. We could do something similar in our registry implementation by leveraging their low level Subscription component, which implements this hierarchical callback firing.
Hi @senadir, @youknowriad, @epiqueras
I created a hot module replacement (hmr) package for block development. Versions 7.4.0+ of Gutenberg break my hmr package.
The way my hmr package works is if a block's code changes on save, then I unregister ( unregisterBlockType ) the changed block and then immediately register ( registerBlockType ) the block with the updated code.
I'm getting the error in the screenshot below. This error lead me to the BlockListBlock, who's comments below lead me to here. I'm not sure if this is highlighting the same issue, but I was curious as to your thoughts?
// block is sometimes not mounted at the right time, causing it be undefined
// see issue for more info https://github.com/WordPress/gutenberg/issues/17013
This is something else. A render is taking place between the time you unregister and register the new block. We need to guard against that or overwrite the block without unregistering it first.
[Block] CoverAffects the Cover Block - used to display content laid over a background image[Feature] Nested / Inner BlocksAnything related to the experience of nested/inner blocks inside a larger container, like Group or P[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release
Activity
senadir commentedon Aug 12, 2019
Narrowed down the problem to block-list/block & hooks/align
no block is being passed the moment of transfer, so props is empty (no attributes, block name..)
gutenberg/packages/block-editor/src/hooks/align.js
Lines 142 to 145 in cd6f74c
testing on Gutenberg 5.8.0 (version just prior to the version #15038 was merged on) showed no problem, so I'm assuming it's a regression.
I think this comment has something to do with it
gutenberg/packages/block-editor/src/components/block-list/block.js
Lines 641 to 644 in cd6f74c
cc @youknowriad
youknowriad commentedon Aug 13, 2019
So apparently,
withSelectis being called with the oldclientId. It looks like this is the zombie children bug for me. Is it possible that errors are not caught properly with theuseSelectrefactoring?Apparently, this regression happened in the same release that introduced
useSelecttoo.cc @epiqueras @nerrad
youknowriad commentedon Aug 13, 2019
Ohhh! I think It might be because the error is not triggered in
withSelectdirectly but it's triggered in another Higher-order componentwithFiltersthat is based on the result of thewithSelect. (Makes me wonder if we should trigger an error explicitly inwithSelectif there's no block. Seems like a hacky fix though :)senadir commentedon Aug 13, 2019
useSelectwill just throw the error again at you with a stackgutenberg/packages/data/src/components/use-select/index.js
Lines 92 to 110 in cd6f74c
epiqueras commentedon Aug 13, 2019
We need the error to be thrown inside
mapSelectfor the failsafe to work. I would just refactor themapSelectof this component to check that it's not running with stale props.senadir commentedon Aug 14, 2019
@epiqueras can you demonstrate how can this be done? I've already tried throwing an error inside
mapSelectcallback inside thewithSelectbut it resulted in the same problem,useSelectwould catch that error & throw it again.specifically, you can catch the
blockinsideapplyWithSelect@block-list/blockif it's defined or notepiqueras commentedon Aug 14, 2019
Where is the error coming from?
withSelectorwithFilter?useSelectreturns the previous result ifmapSelectfails so also keep that in mind with what you're trying.senadir commentedon Aug 14, 2019
while doing some basic debugging with @youknowriad we found that it's in
withSelect, no error is triggered since it's returning the previous block clientID (so if you try to transform a paragraph to heading,withSelectwill try to get you the paragraph block clientID, even though the store has the heading block, this triggers no error inwithSelectsince there is no check right now, the error only surface down inwithFilterwhen another components need to use the new blockdoing a manual check inside
withSelectlike this will just surface the error earlier but would still fail & break the componentif you have a minute or two maybe you can give it a try so if it persists
epiqueras commentedon Aug 14, 2019
Can we change it so that
withFilterdoesn't fail and waits for the new client ID in a subsequent render?youknowriad commentedon Aug 14, 2019
I'm personally a bit concerned about this and why we're not capable of providing a solution that works out of the box without touching the component itself.
The "least bad" solution I see is to have a HoC between withSelect and withFilters that just renders nothing if the block is not available.
nerrad commentedon Aug 14, 2019
I still haven't fully dug into the issue yet so I'm just going by comments so far. But I did want to raise these points:
I'll try and see if I can debug this further sometime today but for now just thought I'd give my two cents :)
8 remaining items
youknowriad commentedon Aug 14, 2019
The original
withSelectimpelementation might have some edge cases where this triggered but it was largely solved (granted it's not async mode compatible). The fact that this works the commit beforeuseSelectis introduced is telling.epiqueras commentedon Aug 14, 2019
Yes, but what do you propose for now? I think we should just refactor this component to follow the
react-reduxhook guidelines.senadir commentedon Aug 14, 2019
since this problem was only introduced in innerBlocks, we can start with it for now
youknowriad commentedon Aug 15, 2019
You're right that we don't have too much choice here. We could:
In an ideal world, React would provide an API for us to fix this. Not sure if they're considering it but I'm pretty sure we're not the only ones having that need.
epiqueras commentedon Aug 15, 2019
Let's do both.
The Redux
connectHOC solves it, because every wrapped component replaces its subtree's store with a clone that runs its subscriptions after its parent. They also suggest that if you can't get around the error by modifying your selecting functions, you could just wrap the component inconnectso that the subscription hierarchy can kick in. We could do something similar in our registry implementation by leveraging their low levelSubscriptioncomponent, which implements this hierarchical callback firing.youknowriad commentedon Aug 19, 2019
Anyone willing to push the fix above?
senadir commentedon Aug 19, 2019
Darren's Fix?
youknowriad commentedon Aug 19, 2019
yes
ellatrix commentedon Jan 11, 2020
Any further ideas for a proper fix?
epiqueras commentedon Jan 11, 2020
senadir commentedon Jan 11, 2020
@epiqueras Will there be any side effects to that?
epiqueras commentedon Jan 11, 2020
leeshadle commentedon Feb 13, 2020
Hi @senadir, @youknowriad, @epiqueras
I created a hot module replacement (hmr) package for block development. Versions 7.4.0+ of Gutenberg break my hmr package.
The way my hmr package works is if a block's code changes on save, then I unregister ( unregisterBlockType ) the changed block and then immediately register ( registerBlockType ) the block with the updated code.
I'm getting the error in the screenshot below. This error lead me to the BlockListBlock, who's comments below lead me to here. I'm not sure if this is highlighting the same issue, but I was curious as to your thoughts?
epiqueras commentedon Feb 13, 2020
This is something else. A render is taking place between the time you unregister and register the new block. We need to guard against that or overwrite the block without unregistering it first.