Skip to content
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): split up head & page component loading #36545

Merged
merged 2 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,19 @@ const createComponentUrls = componentChunkName =>

export class ProdLoader extends BaseLoader {
constructor(asyncRequires, matchPaths, pageData) {
const loadComponent = chunkName => {
if (!asyncRequires.components[chunkName]) {
const loadComponent = (chunkName, exportType = `components`) => {
if (!global.hasPartialHydration) {
Copy link
Contributor

@pieh pieh Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is global.hasPartialHydration being set somewhere? I don't see it anywhere in existing code in master (yet)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be available with partialHydration #36485

exportType = `components`
}

if (!asyncRequires[exportType][chunkName]) {
throw new Error(
`We couldn't find the correct component chunk with the name ${chunkName}`
`We couldn't find the correct component chunk with the name "${chunkName}"`
)
}

return (
asyncRequires.components[chunkName]()
asyncRequires[exportType][chunkName]()
// loader will handle the case when component is error
.catch(err => err)
)
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby/src/bootstrap/requires-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ const preferDefault = m => (m && m.default) || m
// Create file with async requires of components/json files.
let asyncRequires = ``

if (process.env.gatsby_executing_command === `develop`) {
if (
process.env.gatsby_executing_command === `develop` ||
(_CFLAGS_.GATSBY_MAJOR === `5` && process.env.GATSBY_PARTIAL_HYDRATION)
) {
asyncRequires = `exports.components = {\n${components
.map((c: IGatsbyPageComponent): string => {
// we need a relative import path to keep contenthash the same if directory changes
Expand Down