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

fix: server islands regression in bundling #11702

Closed
wants to merge 3 commits into from

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Aug 14, 2024

Changes

Closes #11700

I changed the condition that adds the server entrypoint to the rollup inputs, to only so when the server islands are enabled.

Testing

I will create a preview release and ask the user to test it.

The CI should pass

Docs

N/A

Copy link

changeset-bot bot commented Aug 14, 2024

🦋 Changeset detected

Latest commit: 07c4e8e

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 14, 2024
@ematipico
Copy link
Member Author

!preview server-island-regression

Copy link
Contributor

Snapshots have been released for the following packages:

  • astro@experimental--server-island-regression
  • @astrojs/db@experimental--server-island-regression
  • create-astro@experimental--server-island-regression
  • @astrojs/upgrade@experimental--server-island-regression
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--server-island-regression tag
🦋  warn ----------------------------------------------------------------------
🦋  info npm info astro
🦋  info npm info @astrojs/prism
🦋  info npm info @astrojs/rss
🦋  info npm info create-astro
🦋  info npm info @astrojs/db
🦋  info npm info @astrojs/alpinejs
🦋  info npm info @astrojs/lit
🦋  info npm info @astrojs/markdoc
🦋  info npm info @astrojs/mdx
🦋  info npm info @astrojs/node
🦋  info npm info @astrojs/partytown
🦋  info npm info @astrojs/preact
🦋  info npm info @astrojs/react
🦋  info npm info @astrojs/sitemap
🦋  info npm info @astrojs/solid-js
🦋  info npm info @astrojs/svelte
🦋  info npm info @astrojs/tailwind
🦋  info npm info @astrojs/vercel
🦋  info npm info @astrojs/vue
🦋  info npm info @astrojs/web-vitals
🦋  info npm info @astrojs/internal-helpers
🦋  info npm info @astrojs/markdown-remark
🦋  info npm info @astrojs/studio
🦋  info npm info @astrojs/telemetry
🦋  info npm info @astrojs/underscore-redirects
🦋  info npm info @astrojs/upgrade
🦋  info astro is being published because our local version (0.0.0-server-island-regression-20240814104839) has not been published on npm
🦋  warn @astrojs/prism is not being published because version 3.1.0 is already published on npm
🦋  warn @astrojs/rss is not being published because version 4.0.7 is already published on npm
🦋  info create-astro is being published because our local version (0.0.0-server-island-regression-20240814104839) has not been published on npm
🦋  info @astrojs/db is being published because our local version (0.0.0-server-island-regression-20240814104839) has not been published on npm
🦋  warn @astrojs/alpinejs is not being published because version 0.4.0 is already published on npm
🦋  warn @astrojs/lit is not being published because version 4.3.0 is already published on npm
🦋  warn @astrojs/markdoc is not being published because version 0.11.3 is already published on npm
🦋  warn @astrojs/mdx is not being published because version 3.1.3 is already published on npm
🦋  warn @astrojs/node is not being published because version 8.3.3 is already published on npm
🦋  warn @astrojs/partytown is not being published because version 2.1.1 is already published on npm
🦋  warn @astrojs/preact is not being published because version 3.5.1 is already published on npm
🦋  warn @astrojs/react is not being published because version 3.6.2 is already published on npm
🦋  warn @astrojs/sitemap is not being published because version 3.1.6 is already published on npm
🦋  warn @astrojs/solid-js is not being published because version 4.4.1 is already published on npm
🦋  warn @astrojs/svelte is not being published because version 5.7.0 is already published on npm
🦋  warn @astrojs/tailwind is not being published because version 5.1.0 is already published on npm
🦋  warn @astrojs/vercel is not being published because version 7.7.2 is already published on npm
🦋  warn @astrojs/vue is not being published because version 4.5.0 is already published on npm
🦋  warn @astrojs/web-vitals is not being published because version 1.0.0 is already published on npm
🦋  warn @astrojs/internal-helpers is not being published because version 0.4.1 is already published on npm
🦋  warn @astrojs/markdown-remark is not being published because version 5.2.0 is already published on npm
🦋  warn @astrojs/studio is not being published because version 0.1.1 is already published on npm
🦋  warn @astrojs/telemetry is not being published because version 3.1.0 is already published on npm
🦋  warn @astrojs/underscore-redirects is not being published because version 0.3.4 is already published on npm
🦋  info @astrojs/upgrade is being published because our local version (0.0.0-server-island-regression-20240814104839) has not been published on npm
🦋  info Publishing "astro" at "0.0.0-server-island-regression-20240814104839"
🦋  info Publishing "create-astro" at "0.0.0-server-island-regression-20240814104839"
🦋  info Publishing "@astrojs/db" at "0.0.0-server-island-regression-20240814104839"
🦋  info Publishing "@astrojs/upgrade" at "0.0.0-server-island-regression-20240814104839"
🦋  success packages published successfully:
🦋  astro@0.0.0-server-island-regression-20240814104839
🦋  create-astro@0.0.0-server-island-regression-20240814104839
🦋  @astrojs/db@0.0.0-server-island-regression-20240814104839
🦋  @astrojs/upgrade@0.0.0-server-island-regression-20240814104839
🦋  Creating git tags...
🦋  New tag:  astro@0.0.0-server-island-regression-20240814104839
🦋  New tag:  create-astro@0.0.0-server-island-regression-20240814104839
🦋  New tag:  @astrojs/db@0.0.0-server-island-regression-20240814104839
🦋  New tag:  @astrojs/upgrade@0.0.0-server-island-regression-20240814104839
Build Log

> root@0.0.0 build /home/runner/work/astro/astro
> turbo run build --filter=astro --filter=create-astro --filter="@astrojs/*" --filter="@benchmark/*"

• Packages in scope: @astrojs/alpinejs, @astrojs/cloudflare, @astrojs/db, @astrojs/internal-helpers, @astrojs/lit, @astrojs/markdoc, @astrojs/markdown-remark, @astrojs/mdx, @astrojs/netlify, @astrojs/node, @astrojs/partytown, @astrojs/preact, @astrojs/prism, @astrojs/react, @astrojs/rss, @astrojs/sitemap, @astrojs/solid-js, @astrojs/studio, @astrojs/svelte, @astrojs/tailwind, @astrojs/telemetry, @astrojs/underscore-redirects, @astrojs/upgrade, @astrojs/vercel, @astrojs/vue, @astrojs/web-vitals, @benchmark/timer, astro, create-astro
• Running build in 29 packages
• Remote caching enabled
::group::@astrojs/upgrade:build
cache miss, executing d1689bc541aad9c2

> @astrojs/upgrade@0.0.0-server-island-regression-20240814104839 build /home/runner/work/astro/astro/packages/upgrade
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::@astrojs/prism:build
cache miss, executing 6a68a49c1f511ddf

> @astrojs/prism@3.1.0 build /home/runner/work/astro/astro/packages/astro-prism
> astro-scripts build "src/**/*.ts" && tsc -p ./tsconfig.json

::endgroup::
::group::@astrojs/internal-helpers:build
cache miss, executing 086c7539f6921f02

> @astrojs/internal-helpers@0.4.1 build /home/runner/work/astro/astro/packages/internal-helpers
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json


> @astrojs/internal-helpers@0.4.1 postbuild /home/runner/work/astro/astro/packages/internal-helpers
> astro-scripts copy "src/**/*.js"

::endgroup::
::group::@astrojs/telemetry:build
cache miss, executing dd95b014cc068edd

> @astrojs/telemetry@3.1.0 build /home/runner/work/astro/astro/packages/telemetry
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::create-astro:build
cache miss, executing 79028e0e01f42a0e

> create-astro@0.0.0-server-island-regression-20240814104839 build /home/runner/work/astro/astro/packages/create-astro
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::@astrojs/markdown-remark:build
cache miss, executing 5ddcf3e2b6c4b11e

> @astrojs/markdown-remark@5.2.0 build /home/runner/work/astro/astro/packages/markdown/remark
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json


> @astrojs/markdown-remark@5.2.0 postbuild /home/runner/work/astro/astro/packages/markdown/remark
> astro-scripts copy "src/**/*.js"

::endgroup::
::group::astro:build
cache miss, executing 283aec61241102e4

> astro@0.0.0-server-island-regression-20240814104839 build /home/runner/work/astro/astro/packages/astro
> pnpm run prebuild && astro-scripts build "src/**/*.{ts,js}" && tsc && pnpm run postbuild


> astro@0.0.0-server-island-regression-20240814104839 prebuild /home/runner/work/astro/astro/packages/astro
> astro-scripts prebuild --to-string "src/runtime/server/astro-island.ts" "src/runtime/client/{idle,load,media,only,visible}.ts"


> astro@0.0.0-server-island-regression-20240814104839 postbuild /home/runner/work/astro/astro/packages/astro
> astro-scripts copy "src/**/*.astro" && astro-scripts copy "src/**/*.wasm"

::endgroup::
::group::@astrojs/studio:build
cache miss, executing dd64d4f0a3e875d0

> @astrojs/studio@0.1.1 build /home/runner/work/astro/astro/packages/studio
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/alpinejs:build
cache miss, executing 080ba38edc9b2d91

> @astrojs/alpinejs@0.4.0 build /home/runner/work/astro/astro/packages/integrations/alpinejs
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/lit:build
cache miss, executing cb9a36279ede6b4d

> @astrojs/lit@4.3.0 build /home/runner/work/astro/astro/packages/integrations/lit
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/partytown:build
cache miss, executing dd67e3f8525fc29f

> @astrojs/partytown@2.1.1 build /home/runner/work/astro/astro/packages/integrations/partytown
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/react:build
cache miss, executing 75d784c2e0f53787

> @astrojs/react@3.6.2 build /home/runner/work/astro/astro/packages/integrations/react
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/tailwind:build
cache miss, executing 3a4c15bac839993a

> @astrojs/tailwind@5.1.0 build /home/runner/work/astro/astro/packages/integrations/tailwind
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/preact:build
cache miss, executing 57d080f160cda128

> @astrojs/preact@3.5.1 build /home/runner/work/astro/astro/packages/integrations/preact
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/vercel:build
cache miss, executing ebaebb74ec76f1b5

> @astrojs/vercel@7.7.2 build /home/runner/work/astro/astro/packages/integrations/vercel
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/svelte:build
cache miss, executing 5a6008ce4d5804a0

> @astrojs/svelte@5.7.0 build /home/runner/work/astro/astro/packages/integrations/svelte
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/vue:build
cache miss, executing 448d9f04def54f88

> @astrojs/vue@4.5.0 build /home/runner/work/astro/astro/packages/integrations/vue
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/rss:build
cache miss, executing b2c617d385aae87c

> @astrojs/rss@4.0.7 build /home/runner/work/astro/astro/packages/astro-rss
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/underscore-redirects:build
cache miss, executing 7f459caa7ee93d05

> @astrojs/underscore-redirects@0.3.4 build /home/runner/work/astro/astro/packages/underscore-redirects
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json


> @astrojs/underscore-redirects@0.3.4 postbuild /home/runner/work/astro/astro/packages/underscore-redirects
> astro-scripts copy "src/**/*.js"

::endgroup::
::group::@astrojs/solid-js:build
cache miss, executing 5bbead79c1ece8c1

> @astrojs/solid-js@4.4.1 build /home/runner/work/astro/astro/packages/integrations/solid
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@benchmark/timer:build
cache miss, executing 5cad0ee0a1417b04

> @benchmark/timer@0.0.0 build /home/runner/work/astro/astro/benchmark/packages/timer
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/node:build
cache miss, executing 5b162abf17e143c5

> @astrojs/node@8.3.3 build /home/runner/work/astro/astro/packages/integrations/node
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/mdx:build
cache miss, executing 42d652284c9b418e

> @astrojs/mdx@3.1.3 build /home/runner/work/astro/astro/packages/integrations/mdx
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/markdoc:build
cache miss, executing 69d2225e27ea93eb

> @astrojs/markdoc@0.11.3 build /home/runner/work/astro/astro/packages/integrations/markdoc
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/sitemap:build
cache miss, executing c6605ec0d5612663

> @astrojs/sitemap@3.1.6 build /home/runner/work/astro/astro/packages/integrations/sitemap
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/db:build
cache miss, executing 9e59b310e8dcc6df

> @astrojs/db@0.0.0-server-island-regression-20240814104839 build /home/runner/work/astro/astro/packages/db
> astro-scripts build "src/**/*.ts" && tsc && pnpm types:virtual


> @astrojs/db@0.0.0-server-island-regression-20240814104839 types:virtual /home/runner/work/astro/astro/packages/db
> tsc -p ./tsconfig.virtual.json

::endgroup::
::group::@astrojs/web-vitals:build
cache miss, executing f4469508bdfc7118

> @astrojs/web-vitals@1.0.0 build /home/runner/work/astro/astro/packages/integrations/web-vitals
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::

 Tasks:    27 successful, 27 total
Cached:    0 cached, 27 total
  Time:    58.216s 

@@ -37,11 +42,6 @@ function vitePluginSSR(
inputs.add(getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component));
}

const adapterServerEntrypoint = options.settings.adapter?.serverEntrypoint;
if (adapterServerEntrypoint) {
inputs.add(adapterServerEntrypoint);
Copy link
Member Author

Choose a reason for hiding this comment

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

@matthewp what was the reason for adding the entry point to the list of inputs?

If there's a valid reason, I can restore this change, but it has be done in a different way. We would have to create a virtual module

Copy link
Contributor

Choose a reason for hiding this comment

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

So that the adapter will be built to a separate module and get executed as one of the first things. With the addition of using crypto we need the Node adapter to run early because it polyfills in Node 18. Without this the adapter will be inlined into this main module and not execute in time. Here's the scenario:

import 'package-depends-on-crypto';

// Adapter code here
globalThis.crypto = ...

This throws. because an imported dependency executes first. With this change however:

import './adapter.mjs';
import 'package-depends-on-crypto';

This now works, because the adapter bundle is the first thing to execute, allowing it to polyfill anything it needs to.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it just us that uses globalThis.crypto? Could we ponyfill it ourselves at the point of use instead of relying on a global polyfill?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not easily, no, you need to import node:crypto which doesn't work in non-Node environments.

Copy link
Contributor

Choose a reason for hiding this comment

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

Only if globalThis.crypto isn't defined, which it would be on those runtimes

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I follow, globalThis.crypto is defined in ever environment (to my knowledge) other than Node 18. How would you suggest importing it without it causing bugs when Cloudflare / Deno do their bundling?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant externalising it and importing it dynamically if it's undefined. Deno is fine because it supports node:crypto anyway. I don't know enough about how bundling works for Cloudflare to say if it would work.

Copy link
Contributor

Choose a reason for hiding this comment

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

So we understand each other, what you're suggesting is this, right?

if(typeof crypto === 'undefined') {
  await import('node:crypto');
}

I'm pretty sure the bundle step for Cloudflare will complain about this. We could hide it or add an ignore comment or something possibly.

Part of my stubbornness here is that this is a correctness thing, the adapters are supposed to run first in order to polyfill the environment if they need to. In the past there was more of a need to do this as there was less alignment on globals. Today it's not the case as much as crypto is the only thing I'm aware of.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, basically. That makes sense. I think the real fix here is to work out why rollup is unhappy with Netlify's entrypoint being external

@ematipico
Copy link
Member Author

I tested the reproduction against the latest commit, and it builds correctly

@ematipico ematipico force-pushed the fix/server-island-regression branch from db33864 to 07c4e8e Compare August 14, 2024 12:57
@ascorbic
Copy link
Contributor

This will still break server islands on Netlify though, right?

@ematipico
Copy link
Member Author

This will still break server islands on Netlify though, right?

It's fine if server islands break, they are an experimental feature after all. But the initial reproduction didn't use server islands

@matthewp
Copy link
Contributor

Closing in favor of #11709

@matthewp matthewp closed this Aug 14, 2024
@matthewp matthewp deleted the fix/server-island-regression branch August 14, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New build error - Astro 4.13.4
3 participants