feat: add "worker" exports condition #14779
Merged
+9
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the
worker
condition for entrypoints that exports dual browser/non-browser files, so thatworker
resolves to the non-browser file.Reason
In Svelte 5, there has been issues using it in Astro and Cloudflare (withastro/adapters#485). The cloudflare integration configures Vite with
ssr.target: 'webworker'
, which also changes the resolve conditions tobrowser
,development|production
, etc.Additional info: about why `browser` condition is used
Usually if a library have either
browser
ornode
conditions, it's more likely forbrowser
to work in those worker-based environments, like Cloudflare's workerd or Vercel edge since they don't support node-based APIs. Though today these environments do have some form of node-based compat APIs, the decision to preferbrowser
was made before that.However, using the
browser
condition in Svelte seem to interfere with the runtime lifecycle, and causes runtime issues (linked issue above). Using the non-browser
condition (usuallydefault
in the exports) works. This PR adds theworker
condition to route to thedefault
file.Additional info: about why `worker` condition is used
The
worker
condition had been the usual way (afaict) to refer to "all edge environments". Otherwise you'd have to manually specifyworkerd
,edge-light
, any specific runtimes etc. It was touched on at vitejs/vite#6401, and supported in Astro (1, 2) and Solid too.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint
I also tested this change in Astro and it fixes the issue.