Skip to content

Conversation

@JadedBlueEyes
Copy link

(copying from the first commit message)

Vite includes a feature that allows importing a module's URL to then later dynamically load it. In development mode, you can use this to get the import path for a module on the server, and return it to the client to load.
Unfortunately, in release mode this doesn't work because the client build and the server build are two different runs. This adds a Vite plugin that stubs out these imports in the server build, and adds the imported path as an entrypoint to the client build, allowing the same effect. See the end-to-end test for a demonstration.

The case I developed this for is glob/dynamic imports where some of the possible imports should not be listed in the client code unless the server instructs the client where to find it. This helps protect unlisted & unreleased posts on my blog, for example.

It could also be useful when a glob could import a very large number of possible modules, such that including the import map would be a performance concern. I'm sure that other people will find cases for it too.

I haven't included documentation here, I'm not quite sure where it would best fit for now. I would also like to add a way to preload dependencies of the import, but as is it's no worse than my existing situation for that. The way I've structured this means it could be put behind a config option pretty easily too, if needed.


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.

Vite includes a feature that allows importing a module's
URL to then later dynamically load it. In development
mode, you can use this to get the import path for a module
on the server, and return it to the client to load.
Unfortunately, in release mode this doesn't work because
the client build and the server build are two different
runs. This adds a Vite plugin that stubs out these imports
in the server build, and adds the imported path as an
entrypoint to the client build, allowing the same effect.
See the end-to-end test for a demonstration

The case I developed this for is glob/dynamic imports where
some of the possible imports should not be listed in the
client code unless the server instructs the client where
to find it. This helps protect unlisted & unreleased posts
on my blog.

It could also be useful when a glob could import a very
large number of possible modules, such that including the
import map would be a performance concern. I'm sure that
other people will find cases for it too.

I haven't included documentation here, I'm not quite sure
where it would best fit for now. I would also like to
add a way to preload dependencies of the import, but as is
it's no worse than my existing situation for that.
The way I've structured this means it could be put behind a
config option pretty easily too, if needed.
Oops, I forgot to do this in the last commit.
@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2026

🦋 Changeset detected

Latest commit: 91a7639

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 Minor

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

@JadedBlueEyes
Copy link
Author

Just noticed this is already behind main 😅 Let me know if you need a rebase/squash.

@JadedBlueEyes
Copy link
Author

Looks like the test fail is a flake

@JadedBlueEyes JadedBlueEyes marked this pull request as draft January 23, 2026 23:50
@JadedBlueEyes
Copy link
Author

Drafted because I have some local tests failing in dev mode, but not release mode, so something is up with that handling.

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.

1 participant