-
Notifications
You must be signed in to change notification settings - Fork 10.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
fix(wordpress): ensure all file links are rewritten #31652
fix(wordpress): ensure all file links are rewritten #31652
Conversation
- in the case of either having a small `schema.perPage` setting or many many referenced resources on a single page only the first page of links were properly rewritten - now we ensure that all pages are fully processed until we resolve the promise fixes gatsbyjs#31646
anyone home? |
Hey, thank you for creating the PR, and sorry for taking so long to get to you. I'll test the reproduction and come back to you! |
Any news? we need this fix quite urgently |
@wardpeet any updates? |
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, sorry for keeping you waiting. The function is a bit weird here so I had a hard time wrapping my head around it.
I think we're going to need to revert this. It looks like it's causing the process to freeze now in tests on another branch since I pulled master (with these changes) into that branch. If I manually undo these changes it stops freezing the process |
Looks like the tests were failing here too when this was merged 🤔 weird that the gatsbybot merged this when it wasn't green |
This reverts commit f970600.
fwiw the solution here wont work because it will only ever resolve for a single request now that resolve is in that if statement but we need it to resolve for every request since it resolving there is part of what adds those nodes to Gatsby.
|
Well the initial problem was that it resolved too soon in case there were more than one pages. Imho it's correct to only resolve once all pages have been fetched. @TylerBarnes could you add a test case that shows the problem. I would be happy to fix it once I know what the problem is. |
@rburgst I don't think we need to add another test case for it since the integration tests caught this. The problem was the tests didn't run for your PR originally for some reason and then when "merge on green" was added the WP integration tests weren't marked as required so the PR merged with them failing. You can run them by running My guess is your code breaks when there's only 1 page. Somehow the condition you added never gets tripped and the promise never resolves so we wait indefinitely. I think not creating a new promise for each page and doing it as you had it originally could potentially result in subtle race conditions. For example you have 2 pages, the first page takes 2 seconds to finish (for some reason) and the second page takes 1 second. Here, we will resolve the nodes for the second page before the first page finishes. And this could get trickier the more pages there are. |
Sorry to interject, but does this I wonder relate to the bug I raised: #32350 around having low perPage schema settings? |
@rforster-dev potentially yes. We should probably run a build in our integration tests with perPage set low since there are multiple places throughout the codebase that that setting effects and for a lot of sites that setting is needed for the build to succeed. |
@TylerBarnes I checked out the last commit before the revert (79b7b04) and ran the int tests. The only difference is that the test {
"id": "cG9zdDoxMTgzMQ==",
"slug": "11828",
"__typename": "WpBlockEditorPreview"
}, I could not find any failed tests where the promise was not resolved. This is the query I ran via
With the PR I get the following result (31 results): {
"data": {
"allWpContentNode": {
"totalCount": 31,
"nodes": [
{
"id": "cG9zdDoxMTgzMQ==",
"slug": "11828",
"__typename": "WpBlockEditorPreview"
},
{
"id": "cG9zdDo3NzQ4",
"slug": "1002-4312x2868",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo3NzYw",
"slug": "10-2500x1667",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMTgyOA==",
"slug": "featured-image-too-big",
"__typename": "WpPage"
},
{
"id": "cG9zdDo3ODY4",
"slug": "beautiful_slug",
"__typename": "WpPage"
},
{
"id": "cG9zdDoxNg==",
"slug": "activity",
"__typename": "WpPage"
},
{
"id": "cG9zdDoy",
"slug": "sample-page",
"__typename": "WpPage"
},
{
"id": "cG9zdDozNjI=",
"slug": "84-1000x1000",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo3NzUy",
"slug": "1003-1181x1772",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo3NzU2",
"slug": "1001-5616x3744",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDox",
"slug": "hello-world",
"__typename": "WpPost"
},
{
"id": "cG9zdDo3NjQ2",
"slug": "acf-field-test",
"__typename": "WpPage"
},
{
"id": "cG9zdDoxMDQ=",
"slug": "wordpress-logotype-standard",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDM=",
"slug": "zoltan-tasi-482489-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDE=",
"slug": "jordan-steranka-504707-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDI=",
"slug": "kristopher-roller-110203-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo5Ng==",
"slug": "brandon-siu-608784-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMjU=",
"slug": "gutenberg-layout-element-blocks",
"__typename": "WpPost"
},
{
"id": "cG9zdDoxMjI=",
"slug": "gutenberg-formatting-blocks",
"__typename": "WpPost"
},
{
"id": "cG9zdDoxMjg=",
"slug": "gutenberg-columns",
"__typename": "WpPost"
},
{
"id": "cG9zdDoxMzM1",
"slug": "english-page",
"__typename": "WpTranslationFilterTest"
},
{
"id": "cG9zdDoxMzEx",
"slug": "french-page",
"__typename": "WpTranslationFilterTest"
},
{
"id": "cG9zdDoxMTY3",
"slug": "11",
"__typename": "WpTypeLimitTest"
},
{
"id": "cG9zdDoxMDYyMQ==",
"slug": "mattmullenweg-interview",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDYyNw==",
"slug": "giphy",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo5NA==",
"slug": "gutenberg-common-blocks",
"__typename": "WpPost"
},
{
"id": "cG9zdDo3NzQw",
"slug": "file-sample_1mb",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQ1Mw==",
"slug": "sample-mov-file",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQ0OQ==",
"slug": "sample-mp4-file",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQ0NQ==",
"slug": "sample-2",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQzOQ==",
"slug": "sample",
"__typename": "WpMediaItem"
}
]
}
},
"extensions": {}
} without it I get the following result (30 nodes) {
"data": {
"allWpContentNode": {
"totalCount": 30,
"nodes": [
{
"id": "cG9zdDo3NzQ4",
"slug": "1002-4312x2868",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo3NzYw",
"slug": "10-2500x1667",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMTgyOA==",
"slug": "featured-image-too-big",
"__typename": "WpPage"
},
{
"id": "cG9zdDo3ODY4",
"slug": "beautiful_slug",
"__typename": "WpPage"
},
{
"id": "cG9zdDoxNg==",
"slug": "activity",
"__typename": "WpPage"
},
{
"id": "cG9zdDoy",
"slug": "sample-page",
"__typename": "WpPage"
},
{
"id": "cG9zdDozNjI=",
"slug": "84-1000x1000",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo3NzUy",
"slug": "1003-1181x1772",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo3NzU2",
"slug": "1001-5616x3744",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDox",
"slug": "hello-world",
"__typename": "WpPost"
},
{
"id": "cG9zdDo3NjQ2",
"slug": "acf-field-test",
"__typename": "WpPage"
},
{
"id": "cG9zdDoxMDQ=",
"slug": "wordpress-logotype-standard",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDM=",
"slug": "zoltan-tasi-482489-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDE=",
"slug": "jordan-steranka-504707-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDI=",
"slug": "kristopher-roller-110203-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo5Ng==",
"slug": "brandon-siu-608784-unsplash",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMjU=",
"slug": "gutenberg-layout-element-blocks",
"__typename": "WpPost"
},
{
"id": "cG9zdDoxMjI=",
"slug": "gutenberg-formatting-blocks",
"__typename": "WpPost"
},
{
"id": "cG9zdDoxMjg=",
"slug": "gutenberg-columns",
"__typename": "WpPost"
},
{
"id": "cG9zdDoxMzM1",
"slug": "english-page",
"__typename": "WpTranslationFilterTest"
},
{
"id": "cG9zdDoxMzEx",
"slug": "french-page",
"__typename": "WpTranslationFilterTest"
},
{
"id": "cG9zdDoxMTY3",
"slug": "11",
"__typename": "WpTypeLimitTest"
},
{
"id": "cG9zdDoxMDYyMQ==",
"slug": "mattmullenweg-interview",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDYyNw==",
"slug": "giphy",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDo5NA==",
"slug": "gutenberg-common-blocks",
"__typename": "WpPost"
},
{
"id": "cG9zdDo3NzQw",
"slug": "file-sample_1mb",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQ1Mw==",
"slug": "sample-mov-file",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQ0OQ==",
"slug": "sample-mp4-file",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQ0NQ==",
"slug": "sample-2",
"__typename": "WpMediaItem"
},
{
"id": "cG9zdDoxMDQzOQ==",
"slug": "sample",
"__typename": "WpMediaItem"
}
]
}
},
"extensions": {}
} |
There were some changes to the int tests related to media items so you likely need to pull master into your branch. The other thing is I think promises will sometimes resolve and sometimes not since it'll be a race condition. So there might be some cases where the tests still pass 🤔 |
That's why I checked out 79b7b04. I couldn't see a problem there other than the extra node. If you can point me to a commit that would be better suited I would be grateful. At any rate I will try and replicate the problem with this commit in the meantime. |
@rburgst you should be able to create a branch from your latest commit in this PR and then merge latest master into it 👍 |
@TylerBarnes I did exactly this and now the tests succeed without error. I am not sure what to do. Could it be that this fix interacted with a different bug which was fixed in the meantime? |
- in the case of either having a small `schema.perPage` setting or many many referenced resources on a single page only the first page of links were properly rewritten - now we ensure that all pages are fully processed until we resolve the promise - this is a recommit of gatsbyjs#31652 fixes gatsbyjs#31646
@TylerBarnes since I cannot replicate any problem, I have rebased the changes and created a new PR: #32679 |
@TylerBarnes note that I tweaked the PR more like you suggested by creating individual per page promises and using |
- in the case of either having a small `schema.perPage` setting or many many referenced resources on a single page only the first page of links were properly rewritten - now we ensure that all pages are fully processed until we resolve the promise - this is an improved recommit of gatsbyjs#31652 fixes gatsbyjs#31646
* fix(wordpress): ensure all file links are rewritten - in the case of either having a small `schema.perPage` setting or many many referenced resources on a single page only the first page of links were properly rewritten - now we ensure that all pages are fully processed until we resolve the promise - this is an improved recommit of #31652 fixes #31646 Co-authored-by: gatsbybot <[email protected]> Co-authored-by: Tyler Barnes <[email protected]>
Description
Ensure that all file links are properly resolved even in cases where it spans multiple graphql queries.
Documentation
schema.perPage
settingor many many referenced resources on a single page only the first
page of links were properly rewritten
promise
Related Issues
Fixes #31646