Skip to content

Conversation

@dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Sep 17, 2025

Instead of using manualChunks which turns out to cause some weird chunking bugs, we instead use a virtual module which we force to be loaded at the very end after all other modules have been discovered. By that time we have collected all remote function files and can generated a record of hash->import. Vite will then do the proper chunking without further interference by us. Thanks @bluwy for the tip!

Fixes #14444 and possibly #14430 and #14519

Putting this into draft because while working on this I discovered that remote functions in node_modules are not loaded at dev time - but this is not new to this PR, it's failing on main, too. Investigating. Also fixes a bug in dev mode where remote functions might not be transformed if Vite decides to append a query parameter (we checked if the file ends with .remote.js/ts but they could end with .remote.js/ts?v=123)


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

Instead of using manualChunks which turns out to cause some weird chunking bugs, we instead use a virtual module which we force to be loaded at the very end after all other modules have been discovered. By that time we have collected all remote function files and can generated a record of hash->import. Vite will then do the proper chunking without further interference by us.

Fixes #14444 and possibly #14430
@changeset-bot
Copy link

changeset-bot bot commented Sep 17, 2025

🦋 Changeset detected

Latest commit: 42ae134

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 Patch

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

@dummdidumm dummdidumm marked this pull request as ready for review September 30, 2025 21:13
@dummdidumm dummdidumm marked this pull request as draft October 1, 2025 14:55
Comment on lines +672 to +674
// On the client the id may have a query string appended, e.g. ?v=1234
// so we need to remove it before checking the extension
const normalized_id = id.split('?')[0];
Copy link
Member

Choose a reason for hiding this comment

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

what are the conditions in which this happens? i can't seem to reproduce it. it would be nice to get HMR working with remote functions though, is this involved in that?

Copy link
Member

Choose a reason for hiding this comment

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

given that #14571 is merged, we should probably close this PR — the main reason I haven't done so is this outstanding question. I'm 99% sure the id won't have a cachebusting parameter here (it's included in the request, but is stripped out by the time we get here AFAICT) but I'll leave it open until we resolve this

Copy link
Member Author

@dummdidumm dummdidumm Oct 2, 2025

Choose a reason for hiding this comment

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

I extracted this into #14578. I can very reliably reproduce this with https://github.com/dummdidumm/sveltekit-remote-functions-node_modules. We're also using the normalization (which includes the query stripping) in other places so pretty sure past us had problems in this area, too. This is unrelated to hmr.

Copy link
Member

Choose a reason for hiding this comment

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

oh, weird — I do see it happening there, though not when I actually edit the file. Very curious about under what circumstances the parameter gets passed through. I wonder if it's actually a Vite bug or something

Anyway, I'll merge that other PR which means I think we can close this?

Comment on lines -978 to -979
> [!NOTE] `form` does not accept a schema since you are always passed a `FormData` object. You are free to parse and validate this as you see fit.
Copy link
Member

Choose a reason for hiding this comment

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

updated this on main

@dummdidumm dummdidumm closed this Oct 2, 2025
@dummdidumm dummdidumm deleted the remote-fn-lazy-rework branch October 2, 2025 19:48
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.

remote function build issues sveltekit @ 2.39.0 and up (tested up to and including 2.42.0)

3 participants