Skip to content

Commit

Permalink
add bubbled esm-hmr property
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Oct 6, 2020
1 parent 6136a0f commit e07758e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions snowpack/assets/hmr-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function createHotContext(fullUrl) {
}

/** Called when a new module is loaded, to pass the updated module to the "active" module */
async function runModuleAccept(id) {
async function runModuleAccept({url: id, bubbled}) {
const state = REGISTERED_MODULES[id];
if (!state) {
return false;
Expand All @@ -125,7 +125,7 @@ async function runModuleAccept(id) {
import(id + `?mtime=${updateID}`),
...deps.map((d) => import(d + `?mtime=${updateID}`)),
]);
acceptCallback({module, deps: depModules});
acceptCallback({module, bubbled, deps: depModules});
}
return true;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ socket.addEventListener('message', ({data: _data}) => {
}
if (data.type === 'update') {
log('message: update', data);
runModuleAccept(data.url)
runModuleAccept(data)
.then((ok) => {
if (ok) {
clearErrorOverlay();
Expand Down
5 changes: 3 additions & 2 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,12 @@ export async function startServer(commandOptions: CommandOptions) {
if (visited.has(url)) {
return;
}
visited.add(url);
const node = hmrEngine.getEntry(url);
const isBubbled = visited.size > 0;
if (node && node.isHmrEnabled) {
hmrEngine.broadcastMessage({type: 'update', url});
hmrEngine.broadcastMessage({type: 'update', url, bubbled: isBubbled});
}
visited.add(url);
if (node && node.isHmrAccepted) {
// Found a boundary, no bubbling needed
} else if (node && node.dependents.size > 0) {
Expand Down
2 changes: 1 addition & 1 deletion snowpack/src/hmr-server-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Dependency {

type HMRMessage =
| {type: 'reload'}
| {type: 'update'; url: string}
| {type: 'update'; url: string; bubbled: boolean;}
| {
type: 'error';
title: string;
Expand Down

0 comments on commit e07758e

Please sign in to comment.