Skip to content
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(server): invalidate module with hmr #10333

Merged
merged 5 commits into from
Oct 14, 2022
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Oct 3, 2022

Description

Fix #6871

New API: server.reloadModule that invalidates a module with hmr, unlike moduleGraph.invalidateModule

Additional context

Question:

  1. Would the API name be confusing?
  2. Is the first parameter ok? e.g. a string vs a ModuleNode

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy added feat: hmr p3-significant High priority enhancement (priority) labels Oct 3, 2022
@patak-dev
Copy link
Member

Would the API name be confusing?

I think that it may be confusing that server.invalidateModule and moduleGraph.invalidateModule has the same name but they have different side effects.

Is the first parameter ok? e.g. a string vs a ModuleNode

We should probably follow the current convention in the module graph and pass a module instead.

What about server.reloadModule(module, ...)? IMO it more clearly states that it will trigger a Hot Module Reload for the module, and not only invalidate it.

@bluwy
Copy link
Member Author

bluwy commented Oct 10, 2022

reloadModule sounds nice! I updated to use that.

We should probably follow the current convention in the module graph and pass a module instead.

I also updated to a ModuleNode. I initially didn't went with it since the API would tie to the moduleGraph. And to keep it consistent with ssrLoadModule. But I feel like ModuleNode would be more futureproof too so it might be fine.

@rosskevin
Copy link

This PR would make my i18next resources HMR desperately easy (if I have the correct understanding). Invalidating my virtual module should cause all the relative i18next resource to refresh. Aside from this, it looks like a detailed mess (outside of the vite ecosystem) to invalidate old resources and load new.

@patak-dev patak-dev merged commit 8328011 into main Oct 14, 2022
@patak-dev patak-dev deleted the feat-server-invalidate branch October 14, 2022 09:02
@patak-dev
Copy link
Member

Thanks for your feedback @rosskevin, it's very helpful to know real use cases for PRs 🙏🏼
This feature will be included in Vite 3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p3-significant High priority enhancement (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Reload virtual module on demand
3 participants