feat: add "worker" exports condition #14779
Merged
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
workercondition for entrypoints that exports dual browser/non-browser files, so thatworkerresolves 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
browserornodeconditions, it's more likely forbrowserto 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 preferbrowserwas made before that.However, using the
browsercondition in Svelte seem to interfere with the runtime lifecycle, and causes runtime issues (linked issue above). Using the non-browsercondition (usuallydefaultin the exports) works. This PR adds theworkercondition to route to thedefaultfile.Additional info: about why `worker` condition is used
The
workercondition 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 testand lint the project withpnpm lintI also tested this change in Astro and it fixes the issue.