Skip to content

Navigate to entity record crash editor #64814

Closed

Description

@Tropicalista

Description

I have a custom post type which I wanna use as a pattern.

If I try something like this, the editor crashes.

	const handleEditForm = () => {
		onNavigateToEntityRecord( {
			postId: ref,
			postType: 'formello',
		} );
	};

The error is:

Uncaught TypeError: Cannot read properties of null (reading 'ownerDocument')
    at apply (rich-text.js?ver=9988fecf32c29c7254e1:2492:18)
    at applyRecord (rich-text.js?ver=9988fecf32c29c7254e1:3709:5)
    at applyFromProps (rich-text.js?ver=9988fecf32c29c7254e1:3806:5)
    at rich-text.js?ver=9988fecf32c29c7254e1:3813:7
    at commitHookEffectListMount (react-dom.development.js:23184:26)
    at commitLayoutEffectOnFiber (react-dom.development.js:23302:17)
    at commitLayoutMountEffects_complete (react-dom.development.js:24722:9)
    at commitLayoutEffects_begin (react-dom.development.js:24708:7)
    at commitLayoutEffects (react-dom.development.js:24646:3)
    at commitRootImpl (react-dom.development.js:26857:5)

Step-by-step reproduction instructions

  1. Create a custom post type (ex. Doc)
  2. Create a new post of custom post type (New doc)
  3. Create a simple block that mimic what patterns do and add function mentioned above
  4. Editor crashes

Screenshots, screen recording, code snippet

No response

Environment info

  • WP 6.6

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

Activity

  1. Mamaduka commented on Aug 28, 2024

    @Mamaduka
    Member

    @Tropicalista, can you provide code for a simple block that mimics the Patterns (Reusable) block? The issue might be with it.

  2. github-actions commented on Sep 26, 2024

    @github-actions

    Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

  3. added
    [Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.
    on Sep 26, 2024
  4. removed
    [Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.
    on Sep 27, 2024
  5. Tropicalista commented on Oct 10, 2024

    @Tropicalista
    Author

    This is solved with Gutenberg 19.4.0

  6. Tropicalista commented on Oct 23, 2024

    @Tropicalista
    Author

    This come out again with wp 6.7 RC 1.

    The above error occurred in the <ForwardRef(PostTitle)> component:
    
        at PostTitle (http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:20825:53)
        at div
        at div
        at WritingFlow (http://localhost:10005/wp-includes/js/dist/block-editor.js?ver=ba158b1bfcaf2bda05b0:43957:3)
        at div
        at BlockTools (http://localhost:10005/wp-includes/js/dist/block-editor.js?ver=ba158b1bfcaf2bda05b0:58576:3)
        at ExperimentalBlockCanvas (http://localhost:10005/wp-includes/js/dist/block-editor.js?ver=ba158b1bfcaf2bda05b0:59136:3)
        at div
        at Resizable (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:62986:28)
        at UnforwardedResizableBox (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:64031:3)
        at ResizableEditor (http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:27050:3)
        at div
        at VisualEditor (http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:27266:3)
        at SlotComponent (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:33416:5)
        at Slot
        at UnforwardedSlot (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:33976:5)
        at EditCanvasContainerSlotSlot
        at div
        at http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:9868:3
        at div
        at div
        at div
        at InterfaceSkeleton (http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:9958:3)
        at EditorInterface (http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:27596:3)
        at BlockRefsProvider (http://localhost:10005/wp-includes/js/dist/block-editor.js?ver=ba158b1bfcaf2bda05b0:27719:3)
        at Provider (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:33991:3)
        at http://localhost:10005/wp-includes/js/dist/block-editor.js?ver=ba158b1bfcaf2bda05b0:36995:5
        at http://localhost:10005/wp-includes/js/dist/block-editor.js?ver=ba158b1bfcaf2bda05b0:36539:3
        at BlockContextProvider (http://localhost:10005/wp-includes/js/dist/block-editor.js?ver=ba158b1bfcaf2bda05b0:37058:3)
        at EntityProvider (http://localhost:10005/wp-includes/js/dist/core-data.js?ver=c8526dfd5ea638e51031:6994:3)
        at EntityProvider (http://localhost:10005/wp-includes/js/dist/core-data.js?ver=c8526dfd5ea638e51031:6994:3)
        at http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:24561:3
        at http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:21964:3
        at Editor (http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:29324:3)
        at div
        at ErrorBoundary (http://localhost:10005/wp-includes/js/dist/editor.js?ver=f84c1fcefdc6332efbd1:11688:5)
        at SlotFillProvider (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:33829:3)
        at provider_SlotFillProvider (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:33927:3)
        at Provider (http://localhost:10005/wp-includes/js/dist/components.js?ver=75e0765bccdbc4da087e:33991:3)
        at Layout (http://localhost:10005/wp-includes/js/dist/edit-post.js?ver=9567d2bb2ad838a6bbda:3116:11)
    
    React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
    
  7. Mamaduka commented on Oct 23, 2024

    @Mamaduka
    Member

    @Tropicalista, the issue is fixed in Gutenberg 19.4 but not in WP 6.7 RC1. Is that correct?

  8. Tropicalista commented on Oct 23, 2024

    @Tropicalista
    Author

    Yes it's correct. Can this be related?

  9. 24 remaining items

  10. Tropicalista commented on Nov 7, 2024

    @Tropicalista
    Author

    The fix is still not working on site editor.

    Simply copy the two demo from a post and try to insert in template in site editor.

    Try in playground: Navifate to entity

  11. getdave commented on Nov 14, 2024

    @getdave
    Contributor

    The fix is still not working on site editor.

    @Tropicalista I don't think your Playground is using the Gutenberg PR which fixes the Issue?

    Try this Playground which activates the Gutenberg PR.

    Here's a screencapture of me showing it working:

    Screen.Capture.on.2024-11-14.at.15-32-59.mp4
  12. Tropicalista commented on Nov 14, 2024

    @Tropicalista
    Author

    @getdave You are right.

    I thought that this was merged because issue title says 6.7.

  13. Mamaduka commented on Nov 14, 2024

    @Mamaduka
    Member

    Has anyone figured out why the bug affects a third-party plugin but not the core Patterns block?

    While #66709 is a good hotfix, it's still a compromise. There should be no need to pre-select data before navigation; the editor should do it for consumers as needed (after navigation).

    @youknowriad, @jsnajdr, what do you think?

  14. youknowriad commented on Nov 14, 2024

    @youknowriad
    Contributor

    The reason is probably because patterns are loaded on every editor, so the post type is already there. But I agree that we need to solve the root issue. (Wait for the post type at the moment that we need it) instead of adding a fetch call in the onNavigate callback because that's probably just one way to trigger the issue.

  15. getdave commented on Nov 18, 2024

    @getdave
    Contributor

    I would be happy to close #66709. I don't like changing from sync to async in that PR and as you say the editor should be able to request the entities on demand when it navigates rather than having to have them ready in advance.

  16. jsnajdr commented on Nov 18, 2024

    @jsnajdr
    Member

    This is a bug caused by useRichText returning a ref that is used on an element that is rendered conditionally. The Post Title component does this:

    const { ref } = useRichText();
    return (
      <PostTypeSupportCheck supportKeys="title">
        <h1 ref={ ref } />
      <PostTypeSupportCheck />
    );

    When navigating from a post of type post to a post of type book, the PostTypeSupportCheck briefly unmounts the h1 element because it internally fetches the post type for book. Only after the post type is loaded does it support title again.

    The useRichText logic, namely the applyFromProps calls, get very confused when the ref is reset to null. Then a useLayoutEffect that calls applyFromProps has no element to work with.

    I tried to fix this by setting didMountRef.current = false when the element unmounts. This fixes the crash, but it introduces another bug: the post title is not updated. When navigation from the "post" post to "book" post, the UI still shows the "post" title. Maybe @ellatrix can help here.

    This all also explains why @getdave's fix in #66709 involves calling getPostType. By preloading the post type, it avoids unmounting the h1 in PostTypeSupportCheck.

    The bug can also be fixed by wrapping all post title logic inside PostTypeSupportCheck, including the useRichText call. But that works around a bug in useRichText that would still remain there.

  17. cbravobernal commented on Nov 22, 2024

    @cbravobernal
    Contributor

    Cherry-picked to 6.7 branch for a 6.7.2 release.

  18. moved this from 📥 Todo to ✅ Done in WordPress 6.7.x Editor Taskson Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions