withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.98k stars 2.43k forks source link

4.11 not pruning `satori` build chunks, increasing build sizes #11377

Closed NuroDev closed 2 months ago

NuroDev commented 3 months ago

Astro Info

Astro                    v4.11.3
Node                     v20.11.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/preact

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The other week I got a regular pull request from dependabot to bump some dependencies for my personal website but I noticed CI was failing.

After looking into it a bit more it seemed that the bump of astro from 4.10.2 to 4.11.* was increasing the total size of the _worker.js for Cloudflare just over the limit of what Cloudflare allows (I have not does any optimisation on my end so chances are there are a few things I could be doing better anyway to make this a non-issue).

After digging into it a bit more I found the cause: The final dist/ output is no longer omitting / pruning satori (Which I use to generate OpenGraph image) from the _worker.js/chunks directory.

What's the expected result?

I mentioned this in the Astro Discord & @alexanderniebuhr mentioned that:

It is expected that build size increases, but it shouldn't increase too much.

So ideally either it would be good for the output to be the same size as the previous 4.10.2 version or at least only slightly larger.

[!NOTE]
I have attached a reproduction repo below rather than a StackBlitz project because Stackblitz web containers do not support / have enabled .node addon loading.

Cannot load native addon because loading addons is disabled: /home/projects/github-ar9x5l/node_modules/@resvg/resvg-> js-linux-x64-musl/resvgjs.linux-x64-musl.node

Link to Minimal Reproducible Example

https://github.com/nurodev/astro-4.11-build-size-increase

Participation

alexanderniebuhr commented 3 months ago

FYI for others coming here during triage, I still need to figure out if this belongs here because of the prerendering changes or the adapters repo, cause we should fix it inside the adapter.

NuroDev commented 3 months ago

I did do a quick test as well using the Node.js adapter & it showed that the dist/server/ bundle also increased in size but only by ~4kb (More inline with the version bump increase in size) so it could be something specific to the Cloudflare adapter as the impact there seems way more impactful & like the Node.js adapter is actually "cleaning up" correctly.

bluwy commented 3 months ago

I think this belongs in core. Looks like it's because of https://github.com/withastro/astro/pull/11245#discussion_r1636593458 which I was mistaken of reverting it. I'll make a fix for this.