-
Notifications
You must be signed in to change notification settings - Fork 201
Fix hot-reload early trigger #1458
Changes from 7 commits
50944d3
5ccc3c2
4d31fa2
77d1d8c
9d00034
637350c
581113d
a4ff5c3
d3f197e
8af899c
d5a6217
f2d34e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,27 @@ | |
|
||
connect(); | ||
|
||
let nonDynamicFileChanged = false; | ||
function handleUpdate(message) { | ||
var data = JSON.parse(message.data); | ||
|
||
// Assume only one file is modified at a time | ||
var modified = data.modified[0]; | ||
if(data.modified) { | ||
data.modified.forEach(file => { | ||
tommypepsi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (isCssFile(file)) { | ||
reloadCssFile(file) | ||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should also include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you mention that it makes me realize that sections are probably not served locally since shopify needs to parse the liquid. Considering that I think we should wait for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did more tests with the sections and indeed the sections are hot reloading too fast for the file upload. I noticed two things with the hot-reload of the sections:
Locally I managed to fix and make it work with the json templates! But somehow I'm having a new problem. The first time you make a change after loading the page the hot reload for sections seems to be happening too fast even if you wait for the "uploadComplete" message. But subsequent change seems to be ok. My guess is that even if you get the "uploadComplete" message it doesn't mean that shopify has finished parsing the file or maybe it's a cache thing. (Though I'm really not sure why the problem would only happen on the first change after the page load) For now I've added only the change for the .js files. Not sure if I should add my changes for the sections, it's mostly working except for this weird bug. I'll wait for your opinion on that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a special Proxy that does a trick to make sure Liquid files are updated faster in the backend. It passes the body of the templates with the request, so the backend doesn't have to wait for the file to be updated: https://github.com/Shopify/shopify-cli/blob/main/lib/shopify_cli/theme/dev_server/proxy.rb#L126. This should take care of the section templates, and we shouldn't have to wait for them to be updated. You are correct that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If everything makes sense for you I think this PR could move forward like this and the sections hot-reload part could be handled in a separate PR. Currently the sections triggers most of the time a full refresh and the full refresh seems slow enough that we don't see the problem I was talking about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a couple of tests with the proxy and the "replace_templates" form param that is passed to the proxy doesn't seem to help. The request always returns the section with the previous changes so it's always a change behind. (Is it possible that this has been removed from the backend since it is not documented and that we are seing a lot of changes lately with OS 2.0?) If I wait for the uploadComplete message it seems to work most of the time though. The only thing is that it doesn't work the first time after a manual refresh the page, changes after that work as intended. For some reason this only happens when you manually refresh, when the hot reload does the refresh it works as intended somehow. Edit: now that I think about it the fact that the proxy trick doesn't work anymore might be the main reason why my changes are needed. My changes would still fix some small cases but the biggest pain point comes from liquid files not updating fast enough which is not supposed to be the case with the proxy trick. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Aaaah! Indeed it shouldn't be the case. The Is this issue only affecting a particular set of Liquid files, or every change you make to any Liquid files has this delay in being updated? I just tested, and it works for me, so the issue is likely be somewhere else. Can you reproduce with the environment variable |
||
} else if (isSectionFile(file)) { | ||
reloadSection(file); | ||
} else { | ||
nonDynamicFileChanged = true; | ||
} | ||
}); | ||
} | ||
|
||
if (isCssFile(modified)) { | ||
reloadCssFile(modified) | ||
} else if (isSectionFile(modified)) { | ||
reloadSection(modified); | ||
} else { | ||
console.log(`[HotReload] Refreshing entire page`); | ||
if(nonDynamicFileChanged) { | ||
console.log(`[HotReload] Refreshing entire page, waiting for file uploads`); | ||
} | ||
|
||
if(nonDynamicFileChanged && data.uploadComplete) { | ||
window.location.reload(); | ||
} | ||
} | ||
|
@@ -80,7 +89,7 @@ | |
|
||
console.log(`[HotReload] Reloaded ${this.name} section`); | ||
} else { | ||
window.location.reload() | ||
nonDynamicFileChanged = true; | ||
|
||
console.log(`[HotReload] Hot-reloading not supported, fully reloading ${this.name} section`); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be inside the
if
? Or else it will never be reseted tofalse
.EDIT: However, I think because the page is reloaded it might not be a problem. But still I would move inside the
if
to make this clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is once it switches to true it needs to stay true until we receive the "uploadComplete" message.
While we are waiting for files upload other files can still get modified so we don't want it to be set to false because a file that needs a full refresh has changed before so we still need to wait for the upload to complete.
This is why I have set it outside the function. I've also put it outside of the function because the code to reload a section seems to assume that some stores might not support the section rendering api so we need to set the
nonDynamicFileChanged
to true from outside thehandleUpdate
function (But I feel like this is not relevant anymore, I think all store have access to it now).