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

decline() vs not accept() #10

Open
rictic opened this issue May 25, 2020 · 1 comment
Open

decline() vs not accept() #10

rictic opened this issue May 25, 2020 · 1 comment

Comments

@rictic
Copy link

rictic commented May 25, 2020

Calling import.meta.hot.decline() clearly indicates that a change to the module should result in a full page reload.

What about a file that doesn't call any APIs on import.meta.hot?

Because HMR usually requires cooperation of the module to work, it seems like a module should by default behave as though it called import.meta.hot.decline(), so that changes to it result in a full page refresh.

@FredKSchott
Copy link
Owner

FredKSchott commented May 25, 2020

So what I've learned since starting this: the trickiest part of HMR is event bubbling. If a file changes, an "update" event is kicked off that starts to bubble up your import graph. If the changed file itself has an accept handler, then great! That handler gets called, and the update is complete.

If the changed file doesn't have an accept handler, then that update event bubbles up to all of changed files dependents. And so on up the import graph until every update event as been accepted, or one event has bubbled up past a root node (no imports) unhandled, in which case a full page reload is triggered.

decline() is a way to tell the HMR client: if I ever get hit with an update event (due to this file changing or an event bubbling up to this file) then stop with the bubbling logic and just reload the whole page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants