-
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
( 'core/edit-site' ).getEditedPostId()
returns a number instead of a string
#53230
Comments
For additional context, the |
Regarding 6.3 release cycle.: The typeof is still "string' in WordPress 6.3 RC 2. It doesn't seem that the PR causing the type change made it into the WordPress release. |
3 issues related yet linked to this regression |
I think the postID should be a number, not a string, so we should update the docs to reflect that. |
That may not necessarily be true for templates though (which are currently strings):
It's a bit unfortunate that postID is overloaded to be multiple potential types in this environment, but to be accurate the type would still need to be |
We'll see how to approach this best. Given that the PR only casts to number if the value looks like a number, it doesn't look like something we should rush to revert or unfix - particularly since the PR did not land in the core releases. The problem we're trying to fix is caching mismatches because of the inconsistency in the type of post id. As I've argued in #52120 I think casting the type to fix caching is a bad solution, and that we should instead cache API responses with, as @jsnajdr suggested, some serialized form of the request, not with one particular multitype prop. If we approach caching correctly #52338 should be reverted and #52120 be closed. On the other hand @jsnajdr and Felix approved #52120 which may cause the same problem for Woo, right? So maybe that is worth testing and getting some feedback in place for #52120. As far as the problem itself - post ID being Let's see what @getdave has to add in terms of how to continue best. |
I agree with @draganescu that the issue here really is that for templates on the REST API we (historically) decided to make it's ID a string-based slug. I believe that we should have instead used another field altered the way we consume the endpoint to handle looking up templates by slug. However, that's now in the past and I don't think we can alter the REST response of something that is in Core already. I'm looking at the PR referenced here and I didn't actually change the selector. But, what I did do was set data in the store and the selector doesn't enforce the return type to match what it specifies. That's the source of the bug.
This seems entirely reasonable. The selector should return the correct type or we should amend the selector. However, it's extremely confusing that an ID can be a number or a string slug. Again, this is a historical problem.
If we can do this then it seems to make sense. Cast the type on the REST API. However, if we look at the Posts endpoint as an example the type of Next Steps
|
Here is the revert PR for review #53419 |
It would be very helpfull if getEditedPostId() would return the same id of the wp_template_part as within the wp_posts table is used. I would also expect that getEditedPostContext() would return the edited content of my template part but it's returning undefined.
returns |
Description
#52338 (shipped with Gutenberg 16.3.0) converts the postId into a number and, after that sets in the redux store the number (source code). According to the JSDoc
getEditedPostId
should return astring | undefined
type. (source code).In WooCommerce blocks, we rely on this return type (source code), so the code isn't ready to work with a number type. This introduces a regression in WooCommerce Blocks plugin. I suspect that other plugins could have the same issue.
Step-by-step reproduction instructions
window.wp.data.select( 'core/edit-site' ).getEditedPostId()
Screenshots, screen recording, code snippet
Screen.Capture.on.2023-08-01.at.14-57-34.mp4
Screen.Capture.on.2023-08-01.at.14-59-13.mp4
Environment info
No response
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
The text was updated successfully, but these errors were encountered: