-
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
feat(gatsby): track static queries by template #25549
Conversation
Your pull request can be previewed in Gatsby Cloud: https://build-77739d43-5d4d-4856-8781-7a79634866a0.staging-previews.gtsb.io |
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.
I added some nits.
packages/gatsby/src/utils/map-pages-to-static-query-hashes.ts this file probably needs some rework in the near future as it's really hard to understand
// test(`are written correctly when using wrapRootElement`, async () => { | ||
// const queries = [titleQuery] | ||
// const pagePath = `/dynamic-import/` | ||
|
||
// const { staticQueryHashes } = await readPageData(publicDir, pagePath) | ||
|
||
// expect(staticQueryHashes.sort()).toEqual(queries.map(hashQuery).sort()) | ||
// }) | ||
|
||
// test(`are written correctly when using wrapPageElement`, async () => { | ||
// const queries = [titleQuery] | ||
// const pagePath = `/dynamic-import/` | ||
|
||
// const { staticQueryHashes } = await readPageData(publicDir, pagePath) | ||
|
||
// expect(staticQueryHashes.sort()).toEqual(queries.map(hashQuery).sort()) | ||
// }) |
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.
shouldn't we enable these?
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.
Could you tell me why we don't enable them?
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.
I've enabled them, or like one of them cause they are redundant.
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.
Why not remove them?
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.
We should remove them. They are indeed redundant.
packages/gatsby/src/redux/reducers/static-queries-by-template.ts
Outdated
Show resolved
Hide resolved
if ( | ||
!isEqual( | ||
state.staticQueriesByTemplate.get(componentPath), | ||
staticQueryHashes.map(String) |
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.
We shouldn't map here, right? We should do it when we save identifiers.
staticQueryHashes.map(String) | |
staticQueryHashes |
compiler.hooks.compilation.tap(`webpack-dep-tree-plugin`, compilation => { | ||
compilation.hooks.seal.tap(`webpack-dep-tree-plugin`, () => { | ||
const state = store.getState() | ||
const mapOfTemplatesToStaticQueryHashes = mapTemplatesToStaticQueryHashes( | ||
state, | ||
compilation | ||
) | ||
|
||
mapOfTemplatesToStaticQueryHashes.forEach( | ||
(staticQueryHashes, componentPath) => { | ||
if ( | ||
!isEqual( | ||
state.staticQueriesByTemplate.get(componentPath), | ||
staticQueryHashes.map(String) | ||
) | ||
) { | ||
store.dispatch({ | ||
type: `ADD_PENDING_TEMPLATE_DATA_WRITE`, | ||
payload: { | ||
componentPath, | ||
}, | ||
}) | ||
store.dispatch({ | ||
type: `SET_STATIC_QUERIES_BY_TEMPLATE`, | ||
payload: { | ||
componentPath, | ||
staticQueryHashes, | ||
}, | ||
}) | ||
} | ||
} | ||
) | ||
}) | ||
}) |
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.
This should be a webpack plugin instead of hacking it inside build-javascript command but this can be done later in the chain :)
@@ -194,9 +185,25 @@ export function mapTemplatesToStaticQueryHashes( | |||
|
|||
mapOfTemplatesToStaticQueryHashes.set( | |||
page.componentPath, | |||
staticQueryHashes.sort() | |||
staticQueryHashes.sort().map(String) |
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.
staticQueryHashes.sort().map(String) | |
staticQueryHashes.sort() |
one small suggestion and if ci is green i'm good with merging |
Heads up: Community folks have confirmed that the recursion fix by @freiksenet works! |
Avoid single char names Sort at traversal time Refactor reduce to forEach Refactor another reduce to forEach Fix type check Add check to prevent circular dependency problem Add integration tests Typecheck Address issues in review
13353af
to
ba7ac69
Compare
Track static queries by template Co-authored-by: Sidhartha Chatterjee <[email protected]>
Description
Re-merging Sid's PR with a fix to detect circular dependency.
Related Issues
#25481 #25493