Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Fix hot reload when users update many files "simultaneously" #1830

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h
* [#1807](https://github.com/Shopify/shopify-cli/pull/1807): Fix `--live` parameter, it should not imply `--allow-live` in the `theme push` command
* [#1812](https://github.com/Shopify/shopify-cli/pull/1812): App creation with Rails 7
* [#1821](https://github.com/Shopify/shopify-cli/pull/1821): Fix Shopify hosted fonts to load via the local preview URL
* [#1830](https://github.com/Shopify/shopify-cli/pull/1830): Fix hot reload when users update many files "simultaneously"

## Version 2.7.2
### Fixed
Expand Down
34 changes: 25 additions & 9 deletions lib/shopify_cli/theme/dev_server/hot-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,35 @@

connect();

function isRefreshRequired(files) {
return files.some((file) => !isCssFile(file) && !isSectionFile(file));
}

function refreshFile(file) {
if (isCssFile(file)) {
reloadCssFile(file);
return;
}

if (isSectionFile(file)) {
reloadSection(file);
return;
}
}

function refreshPage() {
console.log('[HotReload] Refreshing entire page');
window.location.reload();
}

function handleUpdate(message) {
var data = JSON.parse(message.data);
var modifiedFiles = data.modified;

// Assume only one file is modified at a time
var modified = data.modified[0];

if (isCssFile(modified)) {
reloadCssFile(modified)
} else if (isSectionFile(modified)) {
reloadSection(modified);
if (isRefreshRequired(modifiedFiles)) {
refreshPage();
} else {
console.log(`[HotReload] Refreshing entire page`);
window.location.reload();
modifiedFiles.forEach(refreshFile);
}
}

Expand Down