@shopify/theme-hot-reload
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -86,38 +86,2 @@ (function hotReloadScript() { | ||
const oseActions = { | ||
startDataReload: async (signal) => { | ||
if (!isOSE) | ||
return null; | ||
// Force OSE to show the loading state | ||
window.dispatchEvent(new Event('pagehide')); | ||
return fetch(window.location.href, { | ||
// Note: enable these properties when we have access to replace_templates | ||
// method: 'POST', | ||
// body: storefrontReplaceTemplatesParams(data.replaceTemplates), | ||
// This is required to get the OnlineStoreEditorData script: | ||
headers: { Accept: 'text/html' }, | ||
signal, | ||
}) | ||
.then((response) => response.text()) | ||
.catch((error) => { | ||
logError('Error fetching full page reload for section settings', error); | ||
return null; | ||
}); | ||
}, | ||
finishDataReload: async (oseDataPromise) => { | ||
if (!isOSE) | ||
return null; | ||
const refreshedHtml = await oseDataPromise; | ||
const newOSEData = new DOMParser() | ||
.parseFromString(refreshedHtml ?? '', 'text/html') | ||
.querySelector('#OnlineStoreEditorData')?.textContent; | ||
if (newOSEData) { | ||
const oseDataElement = document.querySelector('#OnlineStoreEditorData'); | ||
if (oseDataElement && newOSEData !== oseDataElement.textContent) { | ||
oseDataElement.textContent = newOSEData; | ||
logInfo('OSE data updated'); | ||
} | ||
} | ||
// OSE reads the new data after the page is loaded | ||
window.dispatchEvent(new Event('load')); | ||
}, | ||
sendEvent: (payload) => { | ||
@@ -135,5 +99,2 @@ if (!isOSE) | ||
const controller = new AbortController(); | ||
const oseDataPromise = isOSE | ||
? oseActions.startDataReload(controller.signal) | ||
: null; | ||
await Promise.all(elements.map(async (element) => { | ||
@@ -153,5 +114,2 @@ const sectionId = element.id.replace(/^shopify-section-/, ''); | ||
}); | ||
if (oseDataPromise) { | ||
await oseActions.finishDataReload(oseDataPromise); | ||
} | ||
}; | ||
@@ -326,2 +284,1 @@ const refreshAppEmbedBlock = async (data, block) => { | ||
})(); | ||
export {}; |
@@ -9,3 +9,3 @@ { | ||
"license": "MIT", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"engines": { | ||
@@ -27,3 +27,3 @@ "node": ">=22", | ||
"scripts": { | ||
"build": "tsc", | ||
"build": "rm -rf dist && tsc", | ||
"format": "prettier --write .", | ||
@@ -30,0 +30,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
2
14170
308