-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
docs: per-environment state in plugins #20239
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
Maybe skipping
Currently, Rolldown does not share state between Rust and JS. We haven't investigated around that topic yet. I guess it'll take some time. |
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
In that case, the One issue when there is no reset is that old modules state are kept around when the deleting a file for example. At the end, all these cases are the same as they have always been for plugin state even taking environments out of the picture (just with client, and state defined in the plugin, it is the same case). We never documented how that should work so far, so maybe we should keep things in the same way and don't document this either for now. |
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 go without perEnvironmentState
for now. I think we’ll have a clearer picture of watch mode in the near future.
Description
Adds a section about per-environment state handling in plugins. We didn't have a reference to
perEnvironmentStartEndDuringDev: true
without this section.This was already document under future breaking changes here https://vite.dev/changes/shared-plugins-during-build.html, including the
perEnvironmentState
helper.I didn't include the
perEnvironmentState
helper in the guide because I'm unsure if we should be promoting it. The explicitMap<Environment, State>
may be better and less magical. The helper currently takes ainit
function to create the state of each environment, but a reset should also be added tobuildStart
for build watch mode leading to the state being inited twice (just a detail, but still)A note, during build watch, this plugin counts how many modules have been re-transformed. We use this pattern in our internal plugins, but for many use cases it could break if the whole state is busted on
buildStart
and only some modules get re-transformed and people expect the whole state to be there. In the case of keeping state per module, I don't know if we have a good answer that is compatible with watch mode.Maybe we shouldn't promote per environment state at all and instead have users return
meta
info in hooks. This documents what we have been doing internally and how the ecosystem also did things even without environments so probably it is fine to have it (same issue between state and build watch mode could happen only for the client). Long term, @sapphi-red maybe this is something to review for rolldown-vite and how state in plugins would be shared between Rust and JS, how it interacts with build watch mode, and the future full-bundle mode too.