sliftutils 1.2.12 → 1.2.14

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.
@@ -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 = "hotReload:getHash";
6
+ const HOT_RELOAD_HASH_STORAGE_KEY = "sliftHotReloadBuildHash";
7
7
 
8
8
  export async function enableHotReloading(config?: {
9
9
  port?: number;
@@ -79,18 +79,9 @@ 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
- chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
85
- if (message && message.type === HOT_RELOAD_HASH_MESSAGE) {
86
- sendResponse({ hash: currentHash });
87
- return; // synchronous response
88
- }
89
- return undefined;
90
- });
91
-
92
82
  watchPortHotReload(port, () => { /* unused — hash callback drives reloads */ }, (hash) => {
93
83
  if (!hash) return;
84
+ chrome.storage.local.set({ [HOT_RELOAD_HASH_STORAGE_KEY]: hash });
94
85
  if (currentHash === undefined) {
95
86
  currentHash = hash;
96
87
  console.log(`[Hot Reload] Initial build hash: ${hash}`);
@@ -109,12 +100,9 @@ function chromeExtensionContentScriptHotReload() {
109
100
 
110
101
  setInterval(() => {
111
102
  try {
112
- chrome.runtime.sendMessage({ type: HOT_RELOAD_HASH_MESSAGE }, (response) => {
113
- if (chrome.runtime.lastError) {
114
- // Background may be reloading try again on the next tick.
115
- return;
116
- }
117
- let hash: string | undefined = response?.hash;
103
+ chrome.storage.local.get(HOT_RELOAD_HASH_STORAGE_KEY, (result) => {
104
+ if (chrome.runtime.lastError) return;
105
+ let hash: string | undefined = result?.[HOT_RELOAD_HASH_STORAGE_KEY];
118
106
  if (!hash) return;
119
107
  if (lastHash === undefined) {
120
108
  lastHash = hash;
@@ -127,7 +115,7 @@ function chromeExtensionContentScriptHotReload() {
127
115
  }
128
116
  });
129
117
  } catch (error) {
130
- // Ignore — extension context can be transiently invalidated during reload.
118
+ // Extension context can be transiently invalidated during reload.
131
119
  }
132
120
  }, CONTENT_SCRIPT_POLL_INTERVAL_MS);
133
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [