diff --git a/.changeset/smart-islands-learn.md b/.changeset/smart-islands-learn.md new file mode 100644 index 0000000000..42b684f856 --- /dev/null +++ b/.changeset/smart-islands-learn.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme': patch +--- + +Fix hot reload on sections diff --git a/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.test.ts b/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.test.ts index 7f3aaf14b1..52e7cc1662 100644 --- a/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.test.ts +++ b/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.test.ts @@ -128,7 +128,7 @@ describe('hot-reload server', () => { const hotReloadEventsLengthBeforeChange = hotReloadEvents.length // Since the JSON file was removed, the section file is not referenced anymore: await triggerFileEvent('change', testSectionFileKey) - expect(hotReloadEvents).toHaveLength(hotReloadEventsLengthBeforeChange) + expect(hotReloadEvents.at(-1)).toMatch(`data: {"type":"full","key":"${testSectionFileKey}"}`) await nextTick() // -- Updates section groups: diff --git a/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.ts b/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.ts index c0ab692cd7..f97757ae2a 100644 --- a/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.ts +++ b/packages/theme/src/cli/utilities/theme-environment/hot-reload/server.ts @@ -301,6 +301,8 @@ function hotReloadSections(key: string, ctx: DevServerContext) { if (sectionsToUpdate.size > 0) { emitHotReloadEvent({type: 'section', key, names: [...sectionsToUpdate]}) + } else { + emitHotReloadEvent({type: 'full', key}) } }