Skip to content

breaking: nested server-only directories - #15685

Merged
Rich-Harris merged 8 commits into
sveltejs:version-3from
rChaoz:feat/recursive-server-dirs
Jul 2, 2026
Merged

breaking: nested server-only directories#15685
Rich-Harris merged 8 commits into
sveltejs:version-3from
rChaoz:feat/recursive-server-dirs

Conversation

@rChaoz

@rChaoz rChaoz commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

closes #12732

Instead of only considering $lib/server/** as server-only modules, consider $lib/**/server/** instead, see issue above for reasoning.

As per the conversation in #12733, adding this as defaults for v3 (breaking change).


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.

@changeset-bot

changeset-bot Bot commented Apr 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 86e9d45

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

@rChaoz
rChaoz marked this pull request as ready for review April 9, 2026 11:52
@svelte-docs-bot

Copy link
Copy Markdown

Comment thread packages/kit/src/exports/vite/index.js Outdated
@rChaoz
rChaoz force-pushed the feat/recursive-server-dirs branch from 2244f2d to 2f75514 Compare April 9, 2026 12:06
@rChaoz rChaoz changed the title Feat/recursive server dirs feat: recursive $lib server dirs Apr 9, 2026
Comment thread packages/kit/src/exports/vite/index.js
@rChaoz
rChaoz marked this pull request as draft April 9, 2026 12:30
@rChaoz
rChaoz force-pushed the feat/recursive-server-dirs branch from 2f75514 to cd3c44f Compare April 15, 2026 18:32
@rChaoz
rChaoz marked this pull request as ready for review April 15, 2026 18:32
@rChaoz rChaoz changed the title feat: recursive $lib server dirs feat!: recursive $lib server dirs Apr 15, 2026
Comment thread .changeset/lazy-nights-lay.md Outdated

- adding `.server` to the filename, e.g. `secrets.server.js`
- placing them in `$lib/server`, e.g. `$lib/server/secrets.js`
- For single modules, add `.server` to the filename, e.g. `secrets.server.js`. This works for _any_ file in the project directory, including within `$lib` or `$routes`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we automatically create a $routes alias, do we?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I've had one in my projects for so long I forgot it's not native

const import_map = new Map();
const server_only_pattern = /.*\.server\..+/;
// Matches any ID that has .server. in its filename
const server_only_module_pattern = /\.server\.[^/]+$/;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

did we change this from what it was before on purpose?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, for consistency

normalized.startsWith('$lib/server/') ||
(is_internal && server_only_pattern.test(path.basename(id)));
(normalized.startsWith('$lib/') && server_only_directory_pattern.test(id)) ||
(is_internal && server_only_module_pattern.test(id));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was there any reason to change this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reason as above. It also prevents false positives because the hook ID filters no longer match .server in directory names

Comment thread packages/kit/test/apps/dev-only/test/test.js
@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github changed the title feat!: recursive $lib server dirs breaking: nested server-only directories Apr 21, 2026
Co-authored-by: Elliott Johnson <hello@ell.iott.dev>
Comment thread documentation/docs/30-advanced/50-server-only-modules.md Outdated
@teemingc teemingc linked an issue Jun 6, 2026 that may be closed by this pull request
@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 1, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 86e9d45:

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

Open in pkg.svelte.dev: https://pkg.svelte.dev/@sveltejs/kit/c/86e9d45cd4a991e7026cea149b7a08e33b630dcb

Note

This PR is from a fork. A maintainer must approve the fork build on pkg.svelte.dev before the install URLs above will work.

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

thank you!

@Rich-Harris
Rich-Harris merged commit 7c040ba into sveltejs:version-3 Jul 2, 2026
16 of 17 checks passed
Rich-Harris pushed a commit that referenced this pull request Jul 2, 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/adapter-node@6.0.0-next.2

### Major Changes


- breaking: add `kit.paths.origin` config option, remove
`kit.prerender.origin` and the `adapter-node` `ORIGIN` environment
variable ([#16161](#16161))


### Patch Changes

- Updated dependencies
[[`3c434fb`](3c434fb),
[`a9284e8`](a9284e8),
[`3726a7a`](3726a7a),
[`f9d2240`](f9d2240),
[`a9284e8`](a9284e8),
[`7c040ba`](7c040ba),
[`223eaad`](223eaad),
[`223eaad`](223eaad),
[`3b907d4`](3b907d4),
[`fd628a5`](fd628a5),
[`223eaad`](223eaad),
[`6c1d035`](6c1d035),
[`178eac0`](178eac0),
[`c6562a9`](c6562a9),
[`8eca2ab`](8eca2ab),
[`61cf188`](61cf188)]:
  - @sveltejs/kit@3.0.0-next.6
## @sveltejs/kit@3.0.0-next.6

### Major Changes


- breaking: return no content for 204 responses
([#16200](#16200))


- breaking: form action responses now use the HTTP status code returned
from `fail` ([#16200](#16200))


- breaking: nested server-only directories
([#15685](#15685))


- breaking: add `kit.paths.origin` config option, remove
`kit.prerender.origin` and the `adapter-node` `ORIGIN` environment
variable ([#16161](#16161))


- breaking: don't abort navigation when calling `invalidate(All)` during
navigation ([#16188](#16188))


- breaking: allow `handleError` to influence status code
([#16162](#16162))


- breaking: forbid external redirects by default
([#16198](#16198))


### Minor Changes


- feat: use `type: 'module'` for service worker registrations
([#16169](#16169))


- feat: add `dirty()` property to form fields
([#16208](#16208))


- feat: add `cookies.parse` method
([#16203](#16203))


### Patch Changes


- fix: drain unconsumed request bodies so keep-alive connections don't
hang ([#16170](#16170))


- fix: properly handle Date objects in form.fields.set
([#16168](#16168))


- fix: skip clean fields when programmatically validating forms
([#16208](#16208))


- breaking: experimental remote form `validate({ includeUntouched })`
option is now `all`
([#16208](#16208))


- fix: return `undefined` from `fields.branch.issues()` when only
`fields.branch.leaf` has issues
([#16187](#16187))


- feat: add field.touched() helper to remote form fields
([#14692](#14692))
## @sveltejs/adapter-cloudflare@8.0.0-next.1

### Patch Changes


- fix: avoid overriding user's existing `_headers` rules
([#16183](#16183))

- Updated dependencies
[[`3c434fb`](3c434fb),
[`a9284e8`](a9284e8),
[`3726a7a`](3726a7a),
[`f9d2240`](f9d2240),
[`a9284e8`](a9284e8),
[`7c040ba`](7c040ba),
[`223eaad`](223eaad),
[`223eaad`](223eaad),
[`3b907d4`](3b907d4),
[`fd628a5`](fd628a5),
[`223eaad`](223eaad),
[`6c1d035`](6c1d035),
[`178eac0`](178eac0),
[`c6562a9`](c6562a9),
[`8eca2ab`](8eca2ab),
[`61cf188`](61cf188)]:
  - @sveltejs/kit@3.0.0-next.6

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@rChaoz
rChaoz deleted the feat/recursive-server-dirs branch July 2, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to consider lib/**/server/** as server files

4 participants