sliftutils 1.2.12 → 1.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builders/hotReload.ts +4 -6
- package/package.json +1 -1
package/builders/hotReload.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { isInBrowser, isInChromeExtension, isInChromeExtensionBackground, isInCh
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_WATCH_PORT = 9876;
|
|
5
5
|
const CONTENT_SCRIPT_POLL_INTERVAL_MS = 1000;
|
|
6
|
-
const HOT_RELOAD_HASH_MESSAGE = "
|
|
6
|
+
const HOT_RELOAD_HASH_MESSAGE = "sliftHotReload:getHash";
|
|
7
7
|
|
|
8
8
|
export async function enableHotReloading(config?: {
|
|
9
9
|
port?: number;
|
|
@@ -79,12 +79,10 @@ function watchPortHotReload(port = DEFAULT_WATCH_PORT, onReload: () => void, onH
|
|
|
79
79
|
function chromeExtensionBackgroundHotReload(port = DEFAULT_WATCH_PORT) {
|
|
80
80
|
let currentHash: string | undefined;
|
|
81
81
|
|
|
82
|
-
// Content scripts poll the background for the latest build hash and reload
|
|
83
|
-
// themselves when it changes.
|
|
84
82
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
85
83
|
if (message && message.type === HOT_RELOAD_HASH_MESSAGE) {
|
|
86
84
|
sendResponse({ hash: currentHash });
|
|
87
|
-
return;
|
|
85
|
+
return true;
|
|
88
86
|
}
|
|
89
87
|
return undefined;
|
|
90
88
|
});
|
|
@@ -111,7 +109,7 @@ function chromeExtensionContentScriptHotReload() {
|
|
|
111
109
|
try {
|
|
112
110
|
chrome.runtime.sendMessage({ type: HOT_RELOAD_HASH_MESSAGE }, (response) => {
|
|
113
111
|
if (chrome.runtime.lastError) {
|
|
114
|
-
|
|
112
|
+
console.warn("[Hot Reload] sendMessage error:", chrome.runtime.lastError.message);
|
|
115
113
|
return;
|
|
116
114
|
}
|
|
117
115
|
let hash: string | undefined = response?.hash;
|
|
@@ -127,7 +125,7 @@ function chromeExtensionContentScriptHotReload() {
|
|
|
127
125
|
}
|
|
128
126
|
});
|
|
129
127
|
} catch (error) {
|
|
130
|
-
//
|
|
128
|
+
// Extension context can be transiently invalidated during reload.
|
|
131
129
|
}
|
|
132
130
|
}, CONTENT_SCRIPT_POLL_INTERVAL_MS);
|
|
133
131
|
}
|