-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Post Template: Add default value for offset
#47308
Conversation
Size Change: +174 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
I think it would be simpler to just add 0
as a default value here and it would align with front end handling here.
What do you think?
offset
and perPage
offset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@ntsekouras The reason I implemented this is that I felt that simply adding default values would not prevent non-numeric, illegal values from entering the query. However, this problem can occur with other query parameters as well, so it would have been better not to put in too much complexity 😅 |
Closes: #45867
What?
This PR
normalizes the values ofadds default value foroffset
andperPage
query parametersoffset
of the Post Template block in the editor.Why?
Query parameters in the Post Template block are inherited from the Query block. Then, within the query to be built, the
offset
property is calculated in the following part:gutenberg/packages/block-library/src/post-template/edit.js
Lines 123 to 124 in 2499646
This formula works correctly when the block is generated from a variation placeholder since all variations of the query block have an
offset
value.However, if a query block with the innerBlock is created as a variation, the placeholder is skipped and the content is rendered directly. As a result, if no offset is defined,
NaN
is generated by the following formula:This will generate an incorrect request URL, as reported in #45867.
How?
I have rewritten the logic that generates these two values to be nearly identical to what PHP renders on the front end:Just adds default value for offset.
gutenberg/lib/compat/wordpress-6.1/blocks.php
Lines 190 to 206 in 2499646
As a result, if incorrect values are injected, these values are normalized and the incorrect request URL will not generated.
Testing Instructions
Use the following code to generate query variations with invalid parameters.
Insert this variation.
Before: An invalid request URL will be generated and the content will not be rendered.