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

Several chunk files are added to the SSR bundle for every prerendered mardkown files #10552

Closed
1 task
regisphilibert opened this issue Mar 11, 2024 · 9 comments
Closed
1 task
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: content collections Related to the Content Collections feature (scope) pkg: astro Related to the core `astro` package (scope)

Comments

@regisphilibert
Copy link

Astro Info

Astro                    v4.5.0
Node                     v21.1.0
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/netlify v5.1.3
Integrations             none

Describe the Bug

When publishing an Astro project with output set to hybrid, it appears the Netlify adapter will add to the ssr/functions-internal/ssr/chunks directory several files for every markdown files present in the content directory.

It seems only invoking the getCollections method on one collection suffice for all the "content" files to be added to the bundle.

For one advancing-la-crosse.md following files are generated: (I suppose the bigger the content, the more chunks)

  • .netlify/functions-internal/ssr/chunks/advancing-la-crosse_HTeAmckn.mjs
  • .netlify/functions-internal/ssr/chunks/advancing-la-crosse_WrVGU8CN.mjs
  • .netlify/functions-internal/ssr/chunks/advancing-la-crosse_YBMYQhAr.mjs

This happens even though the project only sports one SSR route with no relations to the markdown files.

I'm afraid this could quickly bloat the bundle on big projects and potentially generate the dreaded following error which I'm currently experiencing on some projects. It breaks the build during the deploy state:

Deploy did not succeed with HTTP Error 400: [PUT /deploys/{deploy_id}/functions/{name}][400] uploadDeployFunction default  &{Code:400 Message:Failed to create function on AWS Lambda: invalid parameter for lambda creation: Unzipped size must be smaller than 262144000 bytes}

What's the expected result?

The bundle should only add the chunks needed for the SSR routes to be functionnal.

Link to Minimal Reproducible Example

https://github.com/regisphilibert/astro-issue-repro-ssl-bundle-collections

Participation

  • I am willing to submit a pull request for this issue.
@alexanderniebuhr
Copy link
Member

cc @Skn0tt

@Skn0tt
Copy link
Contributor

Skn0tt commented Mar 25, 2024

I can also see these files being generated, but I'm not aware of anything specific to the Netlify adapter that would cause it. I'm seeing the same behaviour with @astrojs/node adapter, so it looks like this stems from Astro core.

While those files are generated, I don't see them referenced from any other generated file. This also means that Netlify's bundling mechanism won't include them in the Lambda, so they shouldn't lead to any upload failures because of bundle size.

@alexanderniebuhr should we move this ticket into Astro core for investigation?

@alexanderniebuhr alexanderniebuhr transferred this issue from withastro/adapters Mar 25, 2024
@alexanderniebuhr alexanderniebuhr added the needs triage Issue needs to be triaged label Mar 25, 2024
@alexanderniebuhr alexanderniebuhr changed the title Netlify Adapter: Several chunk files are added to the SSR bundle for every prerendered mardkown files Several chunk files are added to the SSR bundle for every prerendered mardkown files Mar 25, 2024
@ematipico ematipico added - P4: important Violate documented behavior or significantly impacts performance (priority) pkg: astro Related to the core `astro` package (scope) feat: content collections Related to the Content Collections feature (scope) and removed needs triage Issue needs to be triaged labels Mar 26, 2024
@ematipico
Copy link
Member

Trying to understand if the issue belongs to content collections or astro code, still, this is concerning.

@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) and removed - P4: important Violate documented behavior or significantly impacts performance (priority) labels Mar 26, 2024
@alexanderniebuhr
Copy link
Member

I think we do face the same issue in Cloudflare v10 now. Maybe it helps debugging (withastro/adapters#218)

@salloom-domani
Copy link

salloom-domani commented May 8, 2024

@alexanderniebuhr In my case I have a file with 21.8 MB that have index name prefix inside the pages folder

[4.0K]  dist/_worker.js/chunks/pages
├── [ 44K]  generic_CYGdUPp9.mjs
├── [ 21M]  index_B5vzoNaZ.mjs
└── [1.6K]  subscribe_Mgs9DD5k.mjs

EDIT: my bad the issue was that I used lots of astro-icon packs and forgot to limit them in prod, hope somebody will benefit of this

@matthewp
Copy link
Contributor

I don't think this is actually a bug. It's a side-effect of the fact that content collections compile to JavaScript. We are not able to "tree shake" unused collections because those APIs are completely dynamic.

We are investigating having CC be backed by a database as an alternative to the JS structure. That may or may not help with this type of issue.

@alexanderniebuhr
Copy link
Member

@matthewp I agree with you. I think the initial issue was, that all the "pages" even if prerendered ended up in the output, due to the prerendering chunk issue. But since we do have a solution for that incoming, I'm not sure if that is still an issue here, or if that this issue is also resolved by that 🤔

@bluwy
Copy link
Member

bluwy commented Jun 17, 2024

I initially thought that #11245 would fix this, but it doesn't as content collection adds all collection entries as Rollup entries:

// Of the cached entries, these ones need to be rebuilt
for (const { type, entry } of entries.buildFromSource) {
const fileURL = encodeURI(joinPaths(opts.settings.config.root.toString(), entry));
const input = fileURLToPath(fileURL);
// Adds `/src/content/blog/post-1.md?astroContentCollectionEntry` as a top-level input
const inputs = [`${input}?${collectionTypeToFlag(type)}`];
if (type === 'content') {
// Content entries also need to include the version with the RENDER flag
inputs.push(`${input}?${CONTENT_RENDER_FLAG}`);
}
newOptions = addRollupInput(newOptions, inputs);
}

Which makes the prerender plugin think that they have other uses, and doesn't mark them for deletion. It's possible to improve this interaction, perhaps easiest if content collection put each in their own non-entry chunk (with manualChunk).

Other than that, what Matthew mention is still true though as long as one non-prerendered pages uses getCollection.

@matthewp matthewp assigned matthewp and ascorbic and unassigned matthewp and ascorbic Jun 17, 2024
@matthewp
Copy link
Contributor

Ok, going to close as I don't think there's anything we can fix about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: content collections Related to the Content Collections feature (scope) pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

No branches or pull requests

8 participants