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(hmr): call hotUpdate hook with file create/delete #16249

Merged
merged 3 commits into from
Mar 29, 2024

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Mar 24, 2024

Description

The import.meta.glob plugin was using server._importGlobMap. If the handleHotUpdate hook runs on file create/delete, that variable can be moved inside the plugin by using that hook.

This PR is mostly a refactor but it changes two behaviors.

  1. When creating/deleting a HTML file, Vite now reloads the page if the page is opened. (e.g. when opening /foo.html and foo.html is created or deleted, a reload will happen)
  2. If a plugin has _runHandleHotUpdateOnCreateAndDelete: true, handleHMRUpdate hook will be called for create/delete events. HmrContext type now has type: 'create' | 'delete' | 'update'. I added the new property to keep backward compatibility, but maybe we can just call it for all plugins.

Additional context


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, especially the Pull Request Guidelines.
  • 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).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Mar 24, 2024
Copy link

stackblitz bot commented Mar 24, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev
Copy link
Member

This is great! I needed to modify server._importGlobMap as part of #16003, and broke VitePress when doing so. See this comment. They need to rework this code in VitePress, maybe telling us what public API they need that forced them to use the internal. So I didn't yet touched this part in the Environment API PR. Once/if we move forward with it, this cache should depend on the environment (starting to think we should offer a environment.cache so it is easier for plugins to have environment-specific state). And we would move from handleHotUpdate to hotUpdate, so we have an opportunity to change the hook without any breaking consideration. If we are going to merge this PR in 5.3, maybe we could leave handleHotUpdate as is, and focus on the new hotUpdate hook directly?
In that case, maybe you could rebase this PR against the feat/environment-api branch?

@sapphi-red
Copy link
Member Author

sapphi-red commented Mar 27, 2024

They need to rework this code in VitePress, maybe telling us what public API they need that forced them to use the internal.

It seems they want handleHotUpdate to be called when a file is created/deleted (vuejs/vitepress#3706).

I'll make a new PR without the last commit (1bbaa6f) and cherry-pick the last commit on top of feat/environment-api branch. I think the commits other than the last one is fine to merge before the Environment API PR. That would avoid the Environment API PR getting larger.

@sapphi-red sapphi-red force-pushed the refactor/hmr-handle branch from 1bbaa6f to f1ecdb4 Compare March 29, 2024 04:42
@sapphi-red sapphi-red changed the base branch from main to feat/environment-api March 29, 2024 04:42
@sapphi-red sapphi-red changed the title feat(hmr): move import.meta.glob related code to plugin refactor(hmr): move import.meta.glob related code to plugin Mar 29, 2024
@sapphi-red sapphi-red changed the title refactor(hmr): move import.meta.glob related code to plugin feat(hmr): call hotUpdate hook with file create/delete Mar 29, 2024
@sapphi-red sapphi-red marked this pull request as ready for review March 29, 2024 04:43
@sapphi-red sapphi-red changed the title feat(hmr): call hotUpdate hook with file create/delete feat(hmr): call hotUpdate hook with file create/delete Mar 29, 2024
@sapphi-red
Copy link
Member Author

The test failure is same with #16129

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for rebasing the PR!

@patak-dev patak-dev merged commit 3d37ac1 into vitejs:feat/environment-api Mar 29, 2024
2 of 6 checks passed
@sapphi-red sapphi-red deleted the refactor/hmr-handle branch March 29, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants