Skip to content

chore: faster builds with Vite 8 hook filters - #15439

Merged
teemingc merged 18 commits into
version-3from
vite-filters
Mar 1, 2026
Merged

chore: faster builds with Vite 8 hook filters#15439
teemingc merged 18 commits into
version-3from
vite-filters

Conversation

@benmccann

@benmccann benmccann commented Feb 26, 2026

Copy link
Copy Markdown
Member

closes #13756

This PR is going to be hard to look at because of all the indentation changes, but basically I moved some if statements in our Vite plugin hooks to a filter methods to be faster. The changes themselves are pretty straightforward if you ignore the spacing changes. There was only one where it was a little gnarly to convert the if to a regex. I put a comment on that regex explaining what it's supposed to do

@changeset-bot

changeset-bot Bot commented Feb 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0bcc952

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 3 packages
Name Type
@sveltejs/package Major
@sveltejs/kit Major
@sveltejs/enhanced-img Major

Click here to learn what changesets are, and how to add one.

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

@svelte-docs-bot

Copy link
Copy Markdown

Comment thread packages/kit/src/exports/vite/index.js Outdated
@benmccann
benmccann force-pushed the vite-filters branch 2 times, most recently from 0343bfb to 4648332 Compare February 26, 2026 22:01
Comment thread packages/kit/src/exports/vite/index.js Outdated
@benmccann benmccann added this to the 3.0 milestone Feb 27, 2026
@benmccann benmccann added the vite label Feb 27, 2026
Comment thread packages/kit/src/exports/vite/index.js Outdated

@teemingc teemingc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! I added a few more filters, used non-capturing groups where possible, refactored to use Vite's prefixRegex helper and left one comment about the server file regex

Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Comment thread packages/kit/src/exports/vite/index.js Outdated
Comment thread packages/kit/src/exports/vite/index.js Outdated
This reverts commit 3e9f3b8.
This reverts commit da9faf6.
@teemingc
teemingc merged commit 23782eb into version-3 Mar 1, 2026
20 checks passed
@teemingc
teemingc deleted the vite-filters branch March 1, 2026 17:18
Rich-Harris pushed a commit that referenced this pull request Jul 17, 2026
Addresses part of #15461

`vite-plugin-sveltekit-guard` builds its `import_map` in every
environment, but the map is only read in the `load` hook, which bails
for non-client consumers before touching it. On the svelte.dev build
that makes 69% of the guard's `resolveId` calls (3,987 of 5,778) dead
work, and the guard was the top entry in dominikg's `PLUGIN_TIMINGS`
report in #13756. This adds the same consumer bail to `resolveId`.

The error chains from #14155 are unaffected because the client
environment collects its own edges. Measured on the svelte.dev build
with `3.0.0-next.6` and vite `8.0.16` (details in
#15461 (comment)),
ssr-side hook time drops from ~296s cumulative to 23ms, the build
succeeds, and a planted two-hop `$lib/server` violation still fails with
the full chain. There is no new test because the behavior is meant to be
unobservable and the exact chain assertions already exist in
`test/apps/dev-only` (dev) and `test/build-errors/server-only.spec.js`
(build), both green with this change.

History for reviewers. #15439 added hook filters everywhere except this
hook, which is blocked on vitejs/vite#21956. #15543 proposed this skip
plus a node_modules importer skip and was closed pending kit 3. The ssr
half was not fixed by kit 3. The node_modules half is not implemented
here because it is unsafe, a library can legitimately import
`$app/server` and its violation chain has to walk node_modules edges.

---

### Please don't delete this checklist! Before submitting the PR, please
make sure you do the following:
- [x] 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
- [x] This message body should clearly illustrate what problems it
solves.
- [x] Ideally, include a test that fails without this PR but passes with
it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint` and `pnpm check`

### Changesets
- [x] 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

- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs
without this option may be closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants