@waffle-os/runtime 0.0.151 → 0.0.152

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.
@@ -219,10 +219,25 @@ export function createPreviewServiceWorker(options: PreviewServiceWorkerOptions)
219
219
  };
220
220
  }
221
221
 
222
- /** Await activation even when the registering page is outside the worker's scope. */
222
+ /**
223
+ * Await activation even when the registering page is outside the worker's scope.
224
+ *
225
+ * A worker in the registration's active slot is already activating or activated, and fetches it
226
+ * handles wait for its activation, so it needs no wait. Only an installing or waiting worker is
227
+ * watched. WebKit can resolve `register()` in a second page that registered at the same moment with
228
+ * the active worker's state still reading "installing", and never sends that object another
229
+ * `statechange`; waiting on it would hang forever. A "redundant" state is still a failure: the spec
230
+ * queues that state update before it clears the active slot, so the two can briefly disagree.
231
+ */
223
232
  export function activated(registration: ServiceWorkerRegistration): Promise<void> {
224
- const worker = registration.installing ?? registration.waiting ?? registration.active;
225
- if (!worker) return Promise.reject(new Error("service worker registration has no worker"));
233
+ const worker = registration.installing ?? registration.waiting;
234
+ if (!worker) {
235
+ const active = registration.active;
236
+ if (!active) return Promise.reject(new Error("service worker registration has no worker"));
237
+ if (active.state === "redundant")
238
+ return Promise.reject(new Error("service worker became redundant before activation"));
239
+ return Promise.resolve();
240
+ }
226
241
  return new Promise((resolve, reject) => {
227
242
  const check = () => {
228
243
  if (worker.state !== "activated" && worker.state !== "redundant") return;
@@ -177,9 +177,15 @@ export function createPreviewServiceWorker(options) {
177
177
  };
178
178
  }
179
179
  export function activated(registration) {
180
- const worker = registration.installing ?? registration.waiting ?? registration.active;
181
- if (!worker)
182
- return Promise.reject(new Error("service worker registration has no worker"));
180
+ const worker = registration.installing ?? registration.waiting;
181
+ if (!worker) {
182
+ const active = registration.active;
183
+ if (!active)
184
+ return Promise.reject(new Error("service worker registration has no worker"));
185
+ if (active.state === "redundant")
186
+ return Promise.reject(new Error("service worker became redundant before activation"));
187
+ return Promise.resolve();
188
+ }
183
189
  return new Promise((resolve, reject) => {
184
190
  const check = () => {
185
191
  if (worker.state !== "activated" && worker.state !== "redundant")