Skip to content

Cannot insert Heading component into Cover #17013

Closed

Description

@senadir

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:

  1. create a new cover block
  2. set a background
  3. in the paragraph field, write / to insert a heading
  4. it breaks

Expected behavior
Paragraph should turn into Heading block

Screenshots
ezgif com-optimize (1)

Desktop (please complete the following information):

  • OS: OSX
  • Browser: Chrome
  • Version: Latest

Additional context

  • Gutenberg on master

Activity

  1. added
    [Type] Bug
    [Feature] Nested / Inner Blocks
    [Block] Cover
    [Type] Regression
    on Aug 12, 2019
  2. senadir commented on Aug 12, 2019

    @senadir
    ContributorAuthor

    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..)

    export const insideSelectWithDataAlign = ( BlockListBlock ) => (
    ( props ) => {
    const { name, attributes, hasWideEnabled } = props;
    const { align } = attributes;

    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
    // The fallback to `{}` is a temporary fix.
    // This function should never be called when a block is not present in the state.
    // It happens now because the order in withSelect rendering is not correct.
    const { name, attributes, isValid } = block || {};

    cc @youknowriad

  3. youknowriad commented on Aug 13, 2019

    @youknowriad
    Contributor

    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.

    cc @epiqueras @nerrad

  4. youknowriad commented on Aug 13, 2019

    @youknowriad
    Contributor

    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 :)

  5. senadir commented on Aug 13, 2019

    @senadir
    ContributorAuthor

    useSelect will just throw the error again at you with a stack

    try {
    if ( latestMapSelect.current !== mapSelect || latestMapOutputError.current ) {
    mapOutput = mapSelect( registry.select, registry );
    } else {
    mapOutput = latestMapOutput.current;
    }
    } catch ( error ) {
    let errorMessage = `An error occurred while running 'mapSelect': ${
    error.message
    }`;
    if ( latestMapOutputError.current ) {
    errorMessage += `\nThe error may be correlated with this previous error:\n`;
    errorMessage += `${ latestMapOutputError.current.stack }\n\n`;
    errorMessage += 'Original stack trace:';
    throw new Error( errorMessage );
    }
    }

  6. epiqueras commented on Aug 13, 2019

    @epiqueras
    Contributor

    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.

  7. senadir commented on Aug 14, 2019

    @senadir
    ContributorAuthor

    @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

  8. epiqueras commented on Aug 14, 2019

    @epiqueras
    Contributor

    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.

  9. senadir commented on Aug 14, 2019

    @senadir
    ContributorAuthor

    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

  10. epiqueras commented on Aug 14, 2019

    @epiqueras
    Contributor

    Can we change it so that withFilter doesn't fail and waits for the new client ID in a subsequent render?

  11. youknowriad commented on Aug 14, 2019

    @youknowriad
    Contributor

    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.

  12. nerrad commented on Aug 14, 2019

    @nerrad
    Contributor

    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 :)

  13. 8 remaining items

  14. youknowriad commented on Aug 14, 2019

    @youknowriad
    Contributor

    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.

  15. epiqueras commented on Aug 14, 2019

    @epiqueras
    Contributor

    The fact that this works the commit before useSelect is introduced is telling.

    Yes, but what do you propose for now? I think we should just refactor this component to follow the react-redux hook guidelines.

  16. senadir commented on Aug 14, 2019

    @senadir
    ContributorAuthor

    since this problem was only introduced in innerBlocks, we can start with it for now

  17. youknowriad commented on Aug 15, 2019

    @youknowriad
    Contributor

    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.

  18. epiqueras commented on Aug 15, 2019

    @epiqueras
    Contributor

    Let's do both.

    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.

  19. youknowriad commented on Aug 19, 2019

    @youknowriad
    Contributor

    Anyone willing to push the fix above?

  20. senadir commented on Aug 19, 2019

    @senadir
    ContributorAuthor

    Darren's Fix?

  21. youknowriad commented on Aug 19, 2019

    @youknowriad
    Contributor

    yes

  22. ellatrix commented on Jan 11, 2020

    @ellatrix
    Member

    Any further ideas for a proper fix?

  23. epiqueras commented on Jan 11, 2020

    @epiqueras
    Contributor
  24. senadir commented on Jan 11, 2020

    @senadir
    ContributorAuthor

    @epiqueras Will there be any side effects to that?

  25. epiqueras commented on Jan 11, 2020

    @epiqueras
    Contributor
  26. leeshadle commented on Feb 13, 2020

    @leeshadle

    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
    

    Screen Shot 2020-02-12 at 10 47 30 PM

  27. epiqueras commented on Feb 13, 2020

    @epiqueras
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Cover[Feature] Nested / Inner Blocks[Type] Bug[Type] Regression

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions