diff --git a/src/component/fiber.ts b/src/component/fiber.ts index ee76c01f..07150a91 100644 --- a/src/component/fiber.ts +++ b/src/component/fiber.ts @@ -355,7 +355,14 @@ export class Fiber { this.root.counter = 0; this.root.error = error; scheduler.flush(); - root.destroy(); + // at this point, the state of the application is corrupted and we could + // have a lot of issues or crashes. So we destroy the application in a try + // catch and swallow these errors because the fiber is already in error, + // and this is the actual issue that needs to be solved, not those followup + // errors. + try { + root.destroy(); + } catch (e) {} } } } diff --git a/tests/component/error_handling.test.ts b/tests/component/error_handling.test.ts index 666da5a3..1af4e9b9 100644 --- a/tests/component/error_handling.test.ts +++ b/tests/component/error_handling.test.ts @@ -586,4 +586,25 @@ describe("component error handling (catchError)", () => { await mount(Parent, { target: fixture }); expect(fixture.innerHTML).toBe("
Error
"); }); + + test("errors in mounted and in willUnmount", async () => { + expect.assertions(1); + class Example extends Component { + static template = xml`
`; + val; + mounted() { + throw new Error("Error in mounted"); + this.val = { foo: "bar" }; + } + willUnmount() { + console.log(this.val.foo); + } + } + + try { + await mount(Example, { target: fixture }); + } catch (e) { + expect(e.message).toBe("Error in mounted"); + } + }); });