Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

copy dynamic import chunks to functions dirs #174

Merged
merged 1 commit into from
Mar 2, 2021

Conversation

lindsaylevine
Copy link
Contributor

Fixes #121

@lindsaylevine lindsaylevine added the type: bug code to address defects in shipped code label Mar 1, 2021
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

@lindsaylevine, this looks good as a fix for the issue.

You can discard my comments if you feel they are not relevant

// Copy page
const nextPageCopyPath = join(functionDirectory, "nextPage.js");
const nextPageCopyPath = join(functionDirectory, "nextPage", "index.js");
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason behind this change is to organize all the page files in the same directory, or is it also required for the fix to work?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is because the chunks are imported relative to a parent dir (e.g. ../[chunk]) 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, what jason said :( the lambda generated by next (that we previous renamed to nextPage.js to pair with next_whatever_the_page_name_is.js) is searching for the chunks one level up at ../ 💀

const { NEXT_DIST_DIR } = require("../config");

// Check if there are dynamic import chunks and copy to the necessary function dir
const copyDynamicImportChunks = (functionPath) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean we're copying all chunks to all functions?

I was also worried users can control the chunks configuration until I found this

Copy link
Contributor

Choose a reason for hiding this comment

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

if we're copying all chunks, we might hit size limits for particularly inefficient sites. I think 50MB is the cap, so if people are doing terrible things like including all of lodash/moment/etc. we might see issues opened down the road

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it does. i think it should be okay for now and can definitely revisit later if issues arise from this implementation. reading the lambdas for the chunk names should be an "if absolutely necessary" approach imo 😂

const { NEXT_DIST_DIR } = require("../config");

// Check if there are dynamic import chunks and copy to the necessary function dir
const copyDynamicImportChunks = (functionPath) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

if we're copying all chunks, we might hit size limits for particularly inefficient sites. I think 50MB is the cap, so if people are doing terrible things like including all of lodash/moment/etc. we might see issues opened down the road

// Copy page
const nextPageCopyPath = join(functionDirectory, "nextPage.js");
const nextPageCopyPath = join(functionDirectory, "nextPage", "index.js");
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is because the chunks are imported relative to a parent dir (e.g. ../[chunk]) 😕

@@ -47,8 +48,11 @@ const setupNetlifyFunctionForPage = ({
});
});

// Copy any dynamic import chunks
copyDynamicImportChunks(functionDirectory);
Copy link
Contributor

Choose a reason for hiding this comment

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

I love how you contained this so we can drop it easily if/when Next fixes this upstream ❤️

@lindsaylevine lindsaylevine force-pushed the ll/est-dynamic-imports branch from 0aacd11 to acb37ef Compare March 2, 2021 04:50
@lindsaylevine lindsaylevine merged commit 8515dd7 into main Mar 2, 2021
@lindsaylevine lindsaylevine deleted the ll/est-dynamic-imports branch March 2, 2021 05:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Next dynamic loading breaks with experimental-serverless-trace
3 participants