Skip to content

Intermittently unable to start writing content when creating a new page in the Site Editor #76310

Closed

Description

@annezazu

Description

Intermittently, when creating a new page from the Site Editor, I'm unable to start to add content and am not able to select the content block. This doesn't happen consistently but I can eventually replicate it consistently so I'm unsure what's breaking down.

I cannot replicate this in WP 7.0 beta 3 but I can in the latest of GB!

Step-by-step reproduction instructions

  1. Go to Appearance > Editor
  2. Add a page
  3. Try to type content. If it works, keep going back to add a new page until you see you are unable to do so.

Screenshots, screen recording, code snippet

intermittently.unable.to.select.type.to.text.mov

Environment info

  • WP 6.9.1
  • GB Version 22.6.0
  • Chrome

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    [Type] Bug
    [Feature] Site Editor
    on Mar 9, 2026
  2. annezazu commented on Mar 9, 2026

    @annezazu
    ContributorAuthor

    I also can't replicate in Gutenberg nightly! Trying to track down what likely fixed this using AI and my own brain looking through recent PRs but can't quite find the cause. I'm going to leave this open to be extra safe to see if someone else might have more information to ensure this was properly fixed.

  3. tyxla commented on Mar 11, 2026

    @tyxla
    Member

    I wonder if #76314 (which is part of the React 19 upgrade prep) resolved this.

    Previously we had a hack where with a custom _load() call we manually signalled that the iframe document was ready, and this was potentially unreliable - if the timing was off (e.g., the iframe loaded before React attached the _load hack, or during the DOM manipulations), the iframe's contentDocument was not set, meaning the writing flow and typing observer refs could not be attached to the body. If my gut feeling is correct and this was the cause, as a result, users couldn't click into or type in the content area. And if that was the reason, then there's a chance #76314 fixed it.

    cc @jsnajdr for thoughts and confirmation

  4. jsnajdr commented on Mar 11, 2026

    @jsnajdr
    Member

    @tyxla Yes, it seems likely that the issue got accidentally fixed with #76314. It was merged in the last 24 hours, and the fact that the issue is no longer reproducible in nightly (trunk) supports this hypothesis.

    If you can't type, a failure to mount the useWritingFlow or useTypingObserver hooks is a likely cause. And the loading changes in #76314 are very directly related to this. That PR generally tries to do the load "correctly" and to remove the complexity and the quirks that have accumulated there over time.

  5. tyxla commented on Mar 11, 2026

    @tyxla
    Member

    @jsnajdr thanks for looking - can we confirm with certainty so we know if we can close this one?

  6. jsnajdr commented on Mar 11, 2026

    @jsnajdr
    Member

    So far I haven't been able to reproduce this. Trying different environments, Playground... The best course of action will probably be wait for a few days, even weeks, and see if we see other cases.

  7. jsnajdr commented on Mar 11, 2026

    @jsnajdr
    Member

    Ha! Just managed to reproduce it. There's one crucial step: you need to be in the template-locked rendering mode, i.e., have "Show Template" checked in the preview menu:

    Image

    Let me now investigate what is going on.

  8. jsnajdr commented on Mar 11, 2026

    @jsnajdr
    Member

    When this issue happens, the block elements are inert, and the content blocks are missing from the list view:

    Image

    The correct scenario is that the blocks are clickable and the list view contains them:

    Image

    @youknowriad @ellatrix Do you have any idea what might be going on here? Right after creating a page, in template-locked mode, how could the content blocks get into bad state? Inert + hidden from list view?

  9. youknowriad commented on Mar 12, 2026

    @youknowriad
    Contributor

    In "template locked" there's an extra component rendered in EditorProvider that is supposed to lock what's outside PostContent (update block editing mode if I recall properly), So my guess is that it could be related to that.

    I've said it before but these non declarative editing mode actions were a mistake in the first place and can result in race conditions when used in multiple places. For instance one possibility here is that the new changes to "pattern insertion" (simple editing) could conflict with the "template-locked" behavior as probably both impact that "editing mode"... So the more we move into declarative configuration for blocks and avoid these actions the better to avoid this kind of issues.

  10. jsnajdr commented on Mar 12, 2026

    @jsnajdr
    Member

    Another thing that happens intermittently is that the core/post-content block doesn't create the default paragraph block that should be the template content when there are no inner blocks. On the following screenshot, notice that the "Content" block doesn't have the expand arrow. The previous screenshots in comments above do have it.

    Image

    This insertion should happen in useInnerBlockTemplateSync. That leads me to an idea that maybe this bug is related to @youknowriad's recent work on selection restoration. That touched the inner block sync code a lot.

  11. jsnajdr commented on Mar 13, 2026

    @jsnajdr
    Member

    It's now almost certain that this is a regression caused by #75458. The optimization of resetting controlled blocks has an edge case that is buggy. I'll post a patch soon, once I understand Claude's very technical description of it 🙂

  12. jsnajdr commented on Mar 16, 2026

    @jsnajdr
    Member

    After the refactors related to "selection restoration on page navigation" in PRs like #75458, the core/block-editor state tree can get into inconsistent states. I identified two:

    First: when on the /page?postId=123 page in Site Editor, a page is displayed in read-only mode, where blockEditingModes for the root block is disabled, and therefore also all the child blocks have a derivedBlockEditingModes = 'disabled' record.

    Then "Add New Page" creates a new page, and does RESET_BLOCKS with the same page template, but different content. After this reset, blockEditingModes for a core/post-content block is contentOnly, as it should be. But there is a stale derivedBlockEditingModes record that says disabled. And the getBlockEditingMode looks at the derived state first. That's why you can't edit the new page content. The withDerivedBlockEditingModes reduces was supposed to clear the derivedBlockEditingModes record, but it didn't. That's one bug.

    Second: on the navigation from one page to another, RESET_BLOCKS can trigger another inconsistent state. Where the core/post-content block has controlledInnerBlocks: true and a controlled|| record in tree, but that controlled tree is not present in order and parents. It's not "connected" to the parent tree. Then different ways of querying the blocks gives different results. Looking at state.blocks.order tells you there are no child blocks, but calling getBlocks( 'foo' ), which looks at state.blocks.tree[ 'controlled||foo' ], tells you there are child blocks. That causes the issue I describe above where the default paragraph block is not created. The useInnerBlockTemplateSync hook doesn't apply the template because it thinks the core/post-content block already has content.

    I believe both these bugs are pre-existing and that #75458 and friends merely uncovered them. Before, the controlled subtrees were scrapped and recreated on each RESET_BLOCKS, so errors didn't have an opportunity to accumulate. But now the state is preserved, and the preservation is not 100% solid.

    I'll continue working on fixes. The code is super-complicated and while AI helps tremendously, it doesn't do the entire job.

  13. annezazu commented on Mar 16, 2026

    @annezazu
    ContributorAuthor

    Proactively adding this to the 7.0 board as my understanding is that we’ll need to do some backports related to this. Please correct and remove if that’s incorrect.

  14. 2 remaining items

  15. jsnajdr commented on Mar 16, 2026

    @jsnajdr
    Member

    Actually, it looks that @talldan fixed this issue in #76305 and that the #76529 fix is not necessary.

    Before #76305, the RESET_BLOCKS action cleared all the blockEditingModes except the '' => 'disabled' one. And DisableNonPageContentBlocks did not reconstruct the contentOnly modes for the post content block. Only for the template parts. That's why the content remained read-only.

    After #76305 I see that all the modes are now reconstructed and the post content is editable once again. However, it looks like a somewhat random effect to me. In #76305 the memoization of the getPostBlocksByName selector was removed. That's why the result now changes more often and triggers the set/unsetBlockEditingMode effects.

    I'd say that the root cause is still that RESET_BLOCKS clears the blockEditingModes, but only partially. Maybe we should preserve the block editing modes on reset, just like we now do for controlledInnerBlocks?

  16. talldan commented on Mar 17, 2026

    @talldan
    Contributor

    @jsnajdr #76421 reintroduces memoization of that selector (but in a way that should work correctly). Removing it entirely caused a warning, so it was probably not the best idea.

    Then "Add New Page" creates a new page, and does RESET_BLOCKS with the same page template, but different content. After this reset, blockEditingModes for a core/post-content block is contentOnly, as it should be. But there is a stale derivedBlockEditingModes record that says disabled. And the getBlockEditingMode looks at the derived state first. That's why you can't edit the new page content. The withDerivedBlockEditingModes reduces was supposed to clear the derivedBlockEditingModes record, but it didn't. That's one bug.

    The derived state should update whenever explicit block editing modes are set or unset:

    case 'SET_BLOCK_EDITING_MODE':
    case 'UNSET_BLOCK_EDITING_MODE':
    case 'SET_HAS_CONTROLLED_INNER_BLOCKS': {
    const updatedBlock = getBlockTreeBlock(
    nextState,
    action.clientId
    );
    // The block might have been removed in which case it'll be
    // handled by the `REMOVE_BLOCKS` action.
    if ( ! updatedBlock ) {
    break;
    }
    const nextDerivedBlockEditingModes =
    getDerivedBlockEditingModesUpdates( {
    prevState: state,
    nextState,
    removedClientIds: [ action.clientId ],
    addedBlocks: [ updatedBlock ],
    } );
    if ( nextDerivedBlockEditingModes ) {
    return {
    ...nextState,
    derivedBlockEditingModes:
    nextDerivedBlockEditingModes ??
    state.derivedBlockEditingModes,
    };
    }
    break;
    }

    And usually a derived mode is avoided when there's an explicit mode:

    // If the block already has an explicit block editing mode set,
    // don't override it.
    if ( state.blockEditingModes.has( clientId ) ) {
    return;
    }

    There's one situation where that doesn't happen (when a user clicks 'Edit pattern' on an unsynced pattern to initiate spotlight mode editing), the derived modes then override the explicit modes which is why the getBlockEditingModes selector is required to return any derived modes first.

    It's interesting that it can end up with the situation you describe. It's possible there's a missing scenario in which the derived modes should update. I think this code can be prone to bugs, so I've been trying to explore ways to make the derived modes update more reactively rather than needing to track every relevant store action.

    Second: on the navigation from one page to another, RESET_BLOCKS can trigger another inconsistent state. Where the core/post-content block has controlledInnerBlocks: true and a controlled|| record in tree, but that controlled tree is not present in order and parents. It's not "connected" to the parent tree. Then different ways of querying the blocks gives different results. Looking at state.blocks.order tells you there are no child blocks, but calling getBlocks( 'foo' ), which looks at state.blocks.tree[ 'controlled||foo' ], tells you there are child blocks. That causes the issue I describe above where the default paragraph block is not created. The useInnerBlockTemplateSync hook doesn't apply the template because it thinks the core/post-content block already has content.

    What you described here is essentially the cause of the bug that #76305 fixes. getPostBlocksByName was previously memoized using getBlocks, but the problem is getBlocks doesn't return controlled block descendants, those are stored in seperate controlled||foo keys in the blocks.tree. It means that getPostBlocksByName often returned stale results for controlled inner blocks. #76421 now updates the memoization to more precisely use the selectors that are called in the getPostBlocksByName body. I'm not sure if the incorrect memoization could also have been the cause of OPs bug too, I'd have to go back and debug it.

  17. jsnajdr commented on Mar 17, 2026

    @jsnajdr
    Member

    It's interesting that it can end up with the situation you describe. It's possible there's a missing scenario in which the derived modes should update.

    I found the cause of this in #76529. And I originally described the situation incorrectly. For the core/post-content block, there are not two entries, one in blockEditingModes: contentOnly and another in derivedBlockEditingModes: disabled, but just the derived one with disabled value. That makes the post-content block read-only.

    It's caused by the RESET_BLOCK action. On reset, the blockEditingModes reducer carries over only the '' => 'disabled' record, and removes all others, i.e., all the contentOnly records. That makes the entire tree read-only. And then it all depends on DisableNonPageContentBlocks which either reconstructs the contentOnly records or not.

    The derivedBlockEditingModes are always updated correctly, I'm not currently aware of any bug there.

    What you described here is essentially the cause of the bug that #76305 fixes. getPostBlocksByName was previously memoized using getBlocks, but the problem is getBlocks doesn't return controlled block descendants

    Nice to hear that you encountered the same bug, where getBlocks returns a bad result. getBlocks does return controlled descendants, the selector code is like:

    function getBlocks( state, rootClientId ) {
      if ( state.controlledInnerBlocks[ rootClientId ] ) {
        return state.blocks.tree[ 'controlled||' + rootClientId ];
      } else {
        return state.blocks.tree[ rootClientId ];
      }
    }

    But the bug is that sometimes the tree is in inconsistent state: the controlled blocks are there, but are not part of the state.block.order and state.blocks.parents structures. Then getBlockOrder( rootId ) will return empty list, because it looks at order, and getBlocks( rootId ) returns non-empty list, because it looks at tree.

    At this moment I still don't 100% understand why this is happening, and would like to improve that today.

  18. moved this to 🏗️ In Progress in WordPress 7.0 Editor Taskson Mar 17, 2026
  19. jsnajdr commented on Mar 17, 2026

    @jsnajdr
    Member

    At this moment I still don't 100% understand why this is happening, and would like to improve that today.

    I managed to reproduce this bug in an isolated unit test: #76591.

  20. talldan commented on Mar 18, 2026

    @talldan
    Contributor

    But the bug is that sometimes the tree is in inconsistent state: the controlled blocks are there, but are not part of the state.block.order and state.blocks.parents structures. Then getBlockOrder( rootId ) will return empty list, because it looks at order, and getBlocks( rootId ) returns non-empty list, because it looks at tree.

    I think @youknowriad wrote most of the block tree code, so might have some input. I had noticed before that controlled blocks are double stored in the block.tree with both regular and controlled|| keys, but the child blocks only exist on the controlled|| key, and I think the attributes only exist on the regular key. I can't recall if there was some reason for that. An optimization or back compat perhaps.

    edit: I recall now. The controlled blocks come from a different source, so that's why they're stored using separate keys. The attributes of a controlled block on the other hand are still serialized to the parent source. I think the separation makes sense, but it does mean there are some quirks to how things are stored. The main principle seems to be keeping a clear boundary to avoid the possibility of serializing any controlled inner blocks to the parent source.


    Another edit:

    getBlocks does return controlled descendants, the selector code is like

    I should clarify, the issue with the selector memoization is that getBlocks was being called like this - select( blockEditorStore ).getBlocks(). In this case rootClientId is undefined, which defaults to '' (the block editor's root block list). This tree doesn't contain any controlled block descendants, only explicitly querying for a controlled block client id will cause the selector to add the controlled|| prefix and return a controlled block's descendants.

  21. jsnajdr commented on Mar 18, 2026

    @jsnajdr
    Member

    I had noticed before that controlled blocks are double stored in the block.tree with both regular and controlled|| keys, but the child blocks only exist on the controlled|| key, and I think the attributes only exist on the regular key. I can't recall if there was some reason for that. An optimization or back compat perhaps.

    The original design was that the child blocks can be either uncontrolled and controlled, and there can be both types of children at the same time. It's like having two branches, and the hasControlledInnerBlocks flag check out one branch or the other, non-destructively.

    Today, however, setHasControlledInnerBlocks always resets the "previous" children to empty. We probably have opportunities to simplify.

  22. jsnajdr commented on Mar 18, 2026

    @jsnajdr
    Member

    In "template locked" there's an extra component rendered in EditorProvider that is supposed to lock what's outside PostContent (update block editing mode if I recall properly). [...] I've said it before but these non declarative editing mode actions were a mistake in the first place and can result in race conditions when used in multiple places.

    @youknowriad The extra component is DisableNonPageContentBlocks and I think it would be very beneficial if its functionality was moved to the core/block-editor reducer. Maybe as another higher-order reducer wrapper.

    The component has selectors and efffects that watch changes in the block tree, and if the right condition is triggered, does set/unsetBlockEditingMode on matching blocks. The reducer could do this job much better, faster and with no room for race conditions. If you and @talldan agree, this could be another nice PR that reduces the block state complexity a lot.

  23. talldan commented on Mar 19, 2026

    @talldan
    Contributor

    The component has selectors and efffects that watch changes in the block tree, and if the right condition is triggered, does set/unsetBlockEditingMode on matching blocks. The reducer could do this job much better, faster and with no room for race conditions. If you and @talldan agree, this could be another nice PR that reduces the block state complexity a lot.

    @youknowriad and I had some discussions about doing that in the past. The tricky part is that the DisableNonPageContentBlocks is in the editor package, and it's for a WordPress feature. I think we considered passing the block names as an editor setting as a way to solve that.

    I've also wanted to explore the possibility that any block that has a binding to the edited post can be edited in this view (so blocks bound to other post properties or meta). Essentially post content, title and featured image are like blocks with bindings anyway. I think that would be better than a hard-coded list of block names.

  24. tyxla commented on Mar 20, 2026

    @tyxla
    Member

    Now that #76591 has landed, can this be closed? Does anything remain to be done there, @jsnajdr?

  25. jsnajdr commented on Mar 23, 2026

    @jsnajdr
    Member

    Does anything remain to be done there

    There's also #76529 where I finished the final version a moment ago. That fixes the actual original issue where inner blocks were read-only after a reset.

    After this, the issue can be closed.

  26. jsnajdr commented on Mar 25, 2026

    @jsnajdr
    Member

    Now after #76529 is merged and backported, I consider this bug fixed 🙂 All the problems I was aware of got fixed.

  27. moved this from 🏗️ In Progress to ✅ Done in WordPress 7.0 Editor Taskson Mar 25, 2026
  28. tyxla commented on Mar 25, 2026

    @tyxla
    Member

    Thank you Jarda 🙌

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

    [Feature] Site Editor[Type] Bug

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions