-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
feat: experimental Vite Runtime API #12165
Conversation
Could you clarify in the PR description what the benefit would be? Is there a performance improvement, is it primarily to make it easier to support Vitest, etc.? |
Leaving a note here to capture discussion from Discord. This does not currently support Deno because of use of |
@benmccann sorry for slow turnaround, but we got swamped in other work. I'll prioritize |
@benmccann FYI we have improved |
@cyco130 is aware of this work and there were some discussions out of this PR. I hope that we can work together and bring what makes sense of vavite into the table. At minimum, it would be great to have documented here why are we going with the vite-node approach instead at this point. |
If we leave the
|
7c19c08
to
6b796ce
Compare
One piece of feedback about vite-node is that it's not clear how to implement HMR when running the viteNodeServer and the runner in different contexts. The current implementation of HMR in vite-node cli showcases this
|
eecbe97
to
f6239d9
Compare
9ed7e93
to
9ae440a
Compare
41fefa6
to
ca610a6
Compare
f8c39e1
to
68a01aa
Compare
This should be ready for a review. Most of the files are copy-pasted from |
|
||
The "Vite Runtime" is a tool that allows running any code by processing it with Vite plugins first. It is different from `server.ssrLoadModule` because the runtime implementation is decoupled from the server. This allows library and framework authors to implement their own layer of communication between the server and the runtime. | ||
|
||
One of the goals of this feature is to provide a customizable API to process and run the code. Vite provides enough tools to use Vite Runtime out of the box, but users can build upon it if their needs do not align with Vite's built-in implementation. |
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 think it will be helpful to have some links to custom implementations like @sapphi-red's one. At least during the experimental phase as it is a great resource to see the API in action.
We can add these links in another PR though, once https://github.com/sapphi-red/vite-envs/tree/use-vite-runtime is merged into main in vite-envs
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.
Yes, sounds like a good idea.
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.
Amazing work @sheremet-va! As we discussed, let's merge the PR so we can start iterating from here on. We'll release the Vite Runtime API as experimental in Vite 5.1 to let the ecosystem explore how it works for their projects. Breaking changes are expected to be applied in Vite 5.2 as we gather more feedback, so please pin Vite to the 5.1 minor if you are going to use the API.
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've not tested the API design, but mainly looking in its implementation and have some comments on it.
I'm not really sure about the duplicated code in many places. I think we should figure something out to prevent that. Sometimes there are changes to the SSR code, and the duplicated ones can often be missed.
I'm also confused about what the ViteRuntime
means here. Will the runtime code be always processed by Vite (and its plugins)? It looks like you could entirely avoid Vite if you wanted to, some of the API exposed (like requestStub
) seems to imply that. But I'm not sure then if it's actually a Vite runtime.
Overall, my comments are mostly concerning if we were to maintain this new code. It's great that the new runtime stuff are entirely within it's own folder.
I think there was a discussion about the name in Discord. |
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.
Made some comments below about marking the exported APIs with the @experimental
jsdoc. That way it's more explicit and we can remove/rename the types/api in the future. I think we can get away marking all the APIs in vite/runtime
as experimental if we mention that vite/runtime
is experimental entirely instead.
Totally agree 👍🏻
We mention in the documentation that it is an experimental API: https://github.com/vitejs/vite/pull/12165/files#diff-b9b4fba55b51e1129c00cb2309528aa9ea13f7a85f27c0fd4f185ad7326586c7R4 |
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.
Thanks for addressing my comments quickly! I'm ok with merging this for now. As a note to myself, we could improve this in the future with:
- Have
ssrLoadModule
use the Vite runtime under-the-hood. - Create a special Rollup build that keeps the runtime lean when using shared code.
This comment was marked as resolved.
This comment was marked as resolved.
📝 Ran ecosystem CI on
|
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.
Let's merge this PR to gather feedback until Vite 5.2, were it is expected that breaking changes will be applied. Let's continue the discussion here:
Description
This PR adds a modified implementation of ViteNode into the Vite core for further improvements.
Fixes #7887
Additional context
Expectations
Reasons why we want to implement this API in Vite core.
ssrLoadModule
)Public API
Using a helper:
Or using primitives:
The main difference from the old API is that you can have a client in a separate worker thread or even on another machine. This API also doesn't limit how many clients you can have with a single server. You can choose your own way of communicating between the server and the runtime. Example with worker threads (will be released as a separate package):
ViteRuntime
doesn't depend on server code and should be lightweight (so, anything that imports it would be faster than just importing from vite entry which depends on a lot of modules)All primitives used in
createWorkerViteRuntime
andcreateViteRuntime
are exported fromvite/runtime
so they can be consumed in environments that don't support workers/node builtins.Vite only exports
createViteRuntime
for better compatibility with the previousssrLoadModule
implementation. Vite doesn't exposecreateWorkerViteRuntime
, it's shown only as an example - it will be released as a separate package though.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).