@sigil-dev/runtime 0.9.16 → 0.9.17

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/index.test.ts CHANGED
@@ -2001,6 +2001,32 @@ describe("collectEffects", () => {
2001
2001
  expect(ran).toEqual(["second", "first"]);
2002
2002
  });
2003
2003
 
2004
+ test("an effect that throws doesn't stop the others", () => {
2005
+ const ran: string[] = [];
2006
+ const { flush } = collectEffects(() => {
2007
+ createEffect(() => {
2008
+ throw new Error("boom");
2009
+ });
2010
+ createEffect(() => void ran.push("after"));
2011
+ });
2012
+ const original = globalThis.queueMicrotask;
2013
+ const reported: unknown[] = [];
2014
+ globalThis.queueMicrotask = (fn: () => void) => {
2015
+ try {
2016
+ fn();
2017
+ } catch (e) {
2018
+ reported.push(e);
2019
+ }
2020
+ };
2021
+ try {
2022
+ flush();
2023
+ } finally {
2024
+ globalThis.queueMicrotask = original;
2025
+ }
2026
+ expect(ran).toEqual(["after"]);
2027
+ expect(String(reported[0])).toContain("boom");
2028
+ });
2029
+
2004
2030
  test("effects outside it run straight away again", () => {
2005
2031
  collectEffects(() => {});
2006
2032
  let ran = 0;
package/index.ts CHANGED
@@ -461,8 +461,18 @@ export function collectEffects<T>(fn: () => T): {
461
461
  }
462
462
  return {
463
463
  value,
464
+ // one effect that throws must not stop the rest (or the page swap the
465
+ // flush runs in); the error is still reported, as an uncaught one
464
466
  flush: () => {
465
- for (const run of queue.splice(0)) run();
467
+ for (const run of queue.splice(0)) {
468
+ try {
469
+ run();
470
+ } catch (e) {
471
+ queueMicrotask(() => {
472
+ throw e;
473
+ });
474
+ }
475
+ }
466
476
  },
467
477
  };
468
478
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@sigil-dev/runtime",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.9.16",
5
+ "version": "0.9.17",
6
6
  "description": "Runtime for the Sigil framework",
7
7
  "private": false,
8
8
  "devDependencies": {
package/test-preload.ts CHANGED
@@ -7,3 +7,5 @@ const window = new Window();
7
7
  (globalThis as any).Node = window.Node;
8
8
  (globalThis as any).HTMLElement = window.HTMLElement;
9
9
  (globalThis as any).Comment = window.Comment;
10
+ // events the tests dispatch must be the DOM's own: happy-dom refuses Bun's
11
+ (globalThis as any).Event = window.Event;