-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: rework lazily remote function files discovery #14456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 detectedLatest commit: 42ae134 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| // 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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
| > [!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. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated this on main
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/tsbut 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:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.