-
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
Post Template: fix incorrect offset query #56440
Conversation
Size Change: +161 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Flaky tests detected in 7a50eca. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6959968424
|
274c890
to
03a2ad3
Compare
03a2ad3
to
7a50eca
Compare
@@ -123,7 +123,7 @@ export default function PostTemplateEdit( { | |||
slug: templateSlug.replace( 'category-', '' ), | |||
} ); | |||
const query = { | |||
offset: perPage ? perPage + offset : 0, | |||
offset: perPage ? offset || 0 : 0, |
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.
|| 0
ensures that the value of the offset
property is always a number. Without this code, when you empty the offset field, the value of the offset property will be an empty string and the spinner will remain visible.
cebed4473f14039f76d2867aceb4c8d3.mp4
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.
Per page doesn't affect the calculation, so offset: offset || 0
would be enough.
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.
Good point, I updated 👍
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 catching this and the fix! 🚀
I've left a small comment and will pre approve.
@@ -123,7 +123,7 @@ export default function PostTemplateEdit( { | |||
slug: templateSlug.replace( 'category-', '' ), | |||
} ); | |||
const query = { | |||
offset: perPage ? perPage + offset : 0, | |||
offset: perPage ? offset || 0 : 0, |
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.
Per page doesn't affect the calculation, so offset: offset || 0
would be enough.
* Post Template: fix incorrect offset query * Remove unnecessary code
Fixes #56439
Related to: #56034
What?
This PR fixes an issue where the Post Template block's offset query would have an incorrect value when using the Query Loop block in the editor.
Why?
This offset value was originally calculated using the following formula.
In a post template block, my understanding is that the
page
variable should always be1
. In other words, the originaloffset
value should have been calculated as follows.Later, in #56034, this calculation formula was changed as follows.
As a result, the
perPage
value is always added to the offset value, and I suspect that it will deviate from the front end query offset.How?
Maintain the original calculation formula.
Testing Instructions
Screenshots or screencast
6d733bc191817fffd12ebbecc0cb759f.mp4