Skip to content

fix: avoid externalising node:async_hooks for the browser#16231

Open
teemingc wants to merge 7 commits into
version-3from
fix-async-hooks-externalise
Open

fix: avoid externalising node:async_hooks for the browser#16231
teemingc wants to merge 7 commits into
version-3from
fix-async-hooks-externalise

Conversation

@teemingc

@teemingc teemingc commented Jul 3, 2026

Copy link
Copy Markdown
Member

Accidentally introduced in #16198 because our shared exports now transitively imports a file that should only run on the server. Can be reproduced by building any of our test apps that import from @sveltejs/kit and you'll see an "externalized for browser" warning for the client build.

This PR marks the als import call as pure so it can be treeshaken correctly from the client code but we remove the pure annotation for server builds to keep it. Not proud of how hacky this is and am open to alternatives.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 3, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from d5480d5:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/d5480d538218ce40da2a85e7c94bb566249e10a0

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16231

@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d5480d5

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@@ -1,4 +1,3 @@
/** @import { ReadableSpan } from '@opentelemetry/sdk-trace-node' */

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unused

Comment thread packages/kit/test/apps/basics/test/server.test.js Outdated
@teemingc teemingc requested a review from dummdidumm July 3, 2026 10:36
@svelte-docs-bot

Copy link
Copy Markdown

Comment thread packages/kit/test/apps/basics/test/server.test.js Outdated
@teemingc teemingc marked this pull request as draft July 3, 2026 12:08
@teemingc teemingc marked this pull request as ready for review July 3, 2026 15:58
@dummdidumm

Copy link
Copy Markdown
Member

Would wrapping the dynamic import with if (!BROWSER) { ... } from esm-env work, too?

@teemingc

teemingc commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Would wrapping the dynamic import with if (!BROWSER) { ... } from esm-env work, too?

Tried that but unfortunately it doesn't work 😞 it might in the future? Rolldown still has some treeshaking issues so it's not on par with Rollup

@dummdidumm

Copy link
Copy Markdown
Member

Another idea (not sure if it's better): Make @sveltejs/kit/internal return a different file on the server/browser, i.e. on the browser it returns a noop basically for try_get_request_store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants