Skip to content

feat: allow adapter Vite plugins to be either pre or post - #16711

Merged
teemingc merged 4 commits into
version-3from
adapter-plugins-pre-post
Aug 10, 2026
Merged

feat: allow adapter Vite plugins to be either pre or post#16711
teemingc merged 4 commits into
version-3from
adapter-plugins-pre-post

Conversation

@ottomated

@ottomated ottomated commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

part of #16705


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:.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 10, 2026

Copy link
Copy Markdown

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

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

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

@ottomated
ottomated requested a review from teemingc August 10, 2026 16:39
@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d54f92a

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 Major

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

@svelte-docs-bot

Copy link
Copy Markdown

Comment thread packages/kit/src/exports/public.d.ts
Comment thread .changeset/strict-bees-arrive.md Outdated
vercel Bot and others added 2 commits August 10, 2026 17:00
… required, but the runtime treats them as optional, forcing adapter authors to always specify both.

This commit fixes the issue reported at packages/kit/src/exports/public.d.ts:75

## Bug

The new adapter `vite.plugins` option was typed with both sub-properties required:

```ts
vite?: {
  plugins?: {
    pre: Plugin[];   // required
    post: Plugin[];  // required
  };
};
```

However, the runtime in `packages/kit/src/exports/vite/index.js` (lines ~2059 and ~2070) consumes them with optional chaining and filters out falsy values:

```js
return /** @type {Plugin[]} */ (
  [
    svelte_config.kit.adapter?.vite?.plugins?.pre,
    // ...SvelteKit's own plugins...
    svelte_config.kit.adapter?.vite?.plugins?.post
  ].filter(Boolean)
);
```

Because of `?.` plus `.filter(Boolean)`, either `pre` or `post` being `undefined` is fully tolerated at runtime.

### Trigger

An adapter author who only wants to inject pre-plugins writes:

```ts
vite: { plugins: { pre: [myPlugin] } }
```

This is a valid, working configuration at runtime, but TypeScript reports an error because `post` is declared required (`Property 'post' is missing`). The author is forced to add `post: []` (and vice versa) purely to satisfy the types — an ergonomic regression from the previous `plugins?: Plugin[]` shape.

## Fix

Marked both `pre` and `post` as optional in the two generated/source type definitions so the types match the runtime's optional handling:

- `packages/kit/src/exports/public.d.ts`
- `packages/kit/types/index.d.ts`

```ts
plugins?: {
  pre?: Plugin[];
  post?: Plugin[];
};
```

The docs example (`documentation/docs/25-build-and-deploy/99-writing-adapters.md`) still shows both `pre: []` and `post: []`, which remains valid as an illustrative example now that each is individually optional.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: teemingc <chewteeming01@gmail.com>

@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.

Thanks!

@teemingc
teemingc merged commit 919dd9d into version-3 Aug 10, 2026
4 of 5 checks passed
@teemingc
teemingc deleted the adapter-plugins-pre-post branch August 10, 2026 17:01
Rich-Harris pushed a commit that referenced this pull request Aug 10, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/kit@3.0.0-next.18

### Major Changes

- breaking: separate adapter Vite plugins into `pre` and `post`
([#16711](#16711))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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