-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigate to entity record crash editor #64814
Comments
@Tropicalista, can you provide code for a simple block that mimics the Patterns (Reusable) block? The issue might be with it. |
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. |
This is solved with Gutenberg 19.4.0 |
This come out again with wp 6.7 RC 1.
|
@Tropicalista, the issue is fixed in Gutenberg 19.4 but not in WP 6.7 RC1. Is that correct? |
Yes it's correct. Can this be related? |
I tested it with the following steps and I think I was able to reproduce it.
Interestingly, this issue does not occur in the
It is still unclear whether this is a plugin issue or a Gutenberg issue. 77987f469265bcfce0e12a0eac1dd11e.mp4 |
@Tropicalista I tested this issue again with minimal code and am unable to reproduce the issue in 6.7 RC1. The following code creates a custom post called "Book" and tests navigating to the post via a block. DetailsPHP: add_action(
'init',
function () {
register_post_type(
'book',
array(
'public' => true,
'label' => 'Books',
'show_in_rest' => true,
)
);
}
); JavaScript: wp.blocks.registerBlockType( 'test/navigate-entity-test', {
apiVersion: 3,
title: 'Navigate Entity Test',
edit: () => {
const { onNavigateToEntityRecord } = wp.data
.select( 'core/block-editor' )
.getSettings();
return wp.element.createElement(
'div',
wp.blockEditor.useBlockProps(),
wp.element.createElement(
'button',
{
onClick: () => {
onNavigateToEntityRecord( {
postId: 8, // Replace with the actual post ID
postType: 'book',
} );
},
},
'Navigate to Custom Post Type (Books) entity'
)
);
},
} ); 304896d44987cad810d2895b78f4fb78.mp4Is your code attempting to access a variable or element that may be undefined? |
Moving this back to "In Discussion" on the 6.7 project board for the time being. |
I think I found the problem. This code works. But of course it will not display the children
IT will crash if I change the code to something like this:
Do you have any idea of what should I do to prevent this error? Is it a bug or is my code worng? |
I'm still not sure if this is a problem with Gutenberg itself.
|
@t-hamano I have uploaded a demo repo that you can test here: Link to repo: https://github.com/Tropicalista/navigate-to-entity/tree/master
To be clear, if I use the code you shared before, without a children block, it works. The code of the block is very simple and you can see it here: https://github.com/Tropicalista/navigate-to-entity/blob/master/src/edit.js |
@Tropicalista Thanks for the detailed info. I was able to track down the PR related to this issue. To get straight to the point, I believe this is a Gutenberg issue and should be fixed in WP 6.7. Step-by-step reproduction instructionsFirst, I would like to explain again how to test this issue:
Screenshots, screen recording, code snippet26e6776611982fd8665e9eb405a6dc89.mp4When was this issue resolved and when did it reoccur?
So it looks like a regression that occurred during the WP 6.7 cycle. @SantosGuillamot @gziolo Do you know anything about this issue? |
Can be this line? |
I performed some debugging at these are my findings.
Removing the logic as follows doesn't fix the issue: diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js
index 50d0261006..623cb847be 100644
--- a/packages/editor/src/components/provider/index.js
+++ b/packages/editor/src/components/provider/index.js
@@ -173,17 +173,13 @@ export const ExperimentalEditorProvider = withRegistryProvider(
getRenderingMode,
__unstableIsEditorReady,
} = select( editorStore );
- const { getEntitiesConfig } = select( coreStore );
return {
editorSettings: getEditorSettings(),
isReady: __unstableIsEditorReady(),
mode: getRenderingMode(),
selection: getEditorSelection(),
- postTypeEntities:
- post.type === 'wp_template'
- ? getEntitiesConfig( 'postType' )
- : null,
+ postTypeEntities: null,
};
},
[ post.type ] Adding an additional call for diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js
index 50d0261006..dba4e86178 100644
--- a/packages/editor/src/components/provider/index.js
+++ b/packages/editor/src/components/provider/index.js
@@ -173,8 +173,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
getRenderingMode,
__unstableIsEditorReady,
} = select( editorStore );
- const { getEntitiesConfig } = select( coreStore );
-
+ const { getEntitiesConfig, getPostTypes } =
+ select( coreStore );
+ getPostTypes( { per_page: -1 } );
return {
editorSettings: getEditorSettings(),
isReady: __unstableIsEditorReady(), It means that the plugins shared above depend on some internal implementation of the post editor, which was never guaranteed in WordPress core. To me, it feels like the missing part is populating the list of all available post types for this functionality to be fully functional. |
I have similar observations after testing it. I don't think it is a bug caused by the mentioned pull request, but it was potentially covering the original issue. From my triaging, it definitely seems it is a problem caused because the postType is not available yet when doing the navigation. To simplify the testing I was running this code directly in the console: wp.data.select('core/block-editor').getSettings().onNavigateToEntityRecord( { postId: 16, postType: 'book' } ) Running just that code triggers the error. However, if just before that I run the following: wp.data.select('core').getPostType('book'); It navigates as expected. I'm wondering if this should be handled automatically by the core function and make it wait until the postType is available. I've seen we are already calling that function here. Maybe we can reuse that logic somehow. The rendering logic seems to happen in that file. |
I also ran a test with WordPress 6.6 and installed the Formello plugin (highlighted here). The same issue has existed for quite some time. I agree with @SantosGuillamot that the potential fix should be applied on the |
With Gutenberg version 16.3 and up, this it's working. Why not backport? |
The backport to 6.7 which "regressed" this fixed a performance issue so I'm not sure a simple backport is possible. We need a more tailored fix (as suggested above). |
I'm still seeing the problem with Gutenberg Some potential solutions I see to the original issue:
We could include a call to With Gutenberg version 16.3 and up, this it's working. Why not backport?
isPostTypeLoaded: !! getPostType( currentPostType ), I have tested it, and it seems to "work" as a quick solution. However, I believe we should try to go one step back.
|
Update: I have a PoC PR in #66709. Would this gutenberg/packages/block-library/src/navigation/edit/use-convert-classic-menu-to-block-menu.js Lines 33 to 45 in 7c7c206
Something like: const onNavigateToEntityRecord = useCallback(
async ( params ) => {
await registry
.resolveSelect( coreStore )
.getPostType( params.postType );
dispatch( {
type: 'push',
post: { postId: params.postId, postType: params.postType },
// Save the current rendering mode so we can restore it when navigating back.
previousRenderingMode: getRenderingMode(),
} );
setRenderingMode( defaultRenderingMode );
},
[ registry, getRenderingMode, setRenderingMode, defaultRenderingMode ]
); In my testing this fixes the Issue reported when using that Plugin. |
I believe something like that could work and it seems to solved the issue in my testing 🙂 |
Let's work on refining #66709. It's currently targetting |
In Gutenberg 19.4, this issue was resolved, but it has reappeared in version 19.6.1. Please investigate. |
@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 |
@getdave You are right. I thought that this was merged because issue title says 6.7. |
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? |
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. |
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. |
This is a bug caused by const { ref } = useRichText();
return (
<PostTypeSupportCheck supportKeys="title">
<h1 ref={ ref } />
<PostTypeSupportCheck />
); When navigating from a post of type The I tried to fix this by setting This all also explains why @getdave's fix in #66709 involves calling The bug can also be fixed by wrapping all post title logic inside |
Cherry-picked to 6.7 branch for a 6.7.2 release. |
Description
I have a custom post type which I wanna use as a pattern.
If I try something like this, the editor crashes.
The error is:
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
The text was updated successfully, but these errors were encountered: