diff --git a/src/component/error_handling.ts b/src/component/error_handling.ts index 9774b2f7..d61a6d8c 100644 --- a/src/component/error_handling.ts +++ b/src/component/error_handling.ts @@ -16,10 +16,6 @@ function _handleError(node: ComponentNode | null, error: any, isFirstRound = fal const errorHandlers = nodeErrorHandlers.get(node); if (errorHandlers) { - if (isFirstRound && fiber) { - fiber.root.counter--; - } - let stopped = false; // execute in the opposite order for (let i = errorHandlers.length - 1; i >= 0; i--) { @@ -33,6 +29,9 @@ function _handleError(node: ComponentNode | null, error: any, isFirstRound = fal } if (stopped) { + if (isFirstRound && fiber) { + fiber.root.counter--; + } return true; } } diff --git a/tests/components/__snapshots__/error_handling.test.ts.snap b/tests/components/__snapshots__/error_handling.test.ts.snap index ddf47998..c1e86958 100644 --- a/tests/components/__snapshots__/error_handling.test.ts.snap +++ b/tests/components/__snapshots__/error_handling.test.ts.snap @@ -705,6 +705,81 @@ exports[`can catch errors catchError in catchError 3`] = ` }" `; +exports[`can catch errors catching error, rethrow, render parent -- a main component loop implementation 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + let { prepareList, capture, withKey } = helpers; + + function slot3(ctx, node, key = \\"\\") { + let Comp5 = ctx['cp'].Comp; + return toggler(Comp5, component(Comp5, {}, key + \`__4\`, node, ctx)); + } + + return function template(ctx, node, key = \\"\\") { + ctx = Object.create(ctx); + const [k_block1, v_block1, l_block1, c_block1] = prepareList(Object.values(ctx['state'].cps)); + for (let i1 = 0; i1 < l_block1; i1++) { + ctx[\`cp\`] = v_block1[i1]; + let key1 = ctx['cp'].id; + const v1 = ctx['cp']; + const ctx2 = capture(ctx); + c_block1[i1] = withKey(component(\`ErrorHandler\`, {onError: ()=>this.cleanUp(v1.id),slots: {'default': {__render: slot3, __ctx: ctx2}}}, key + \`__6__\${key1}\`, node, ctx), key1); + } + return list(c_block1); + } +}" +`; + +exports[`can catch errors catching error, rethrow, render parent -- a main component loop implementation 2`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + let { callSlot } = helpers; + + return function template(ctx, node, key = \\"\\") { + return callSlot(ctx, node, key, 'default', false, {}); + } +}" +`; + +exports[`can catch errors catching error, rethrow, render parent -- a main component loop implementation 3`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + return function template(ctx, node, key = \\"\\") { + return component(\`ErrorComponent\`, {}, key + \`__1\`, node, ctx); + } +}" +`; + +exports[`can catch errors catching error, rethrow, render parent -- a main component loop implementation 4`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + let block1 = createBlock(\`
\`); + + return function template(ctx, node, key = \\"\\") { + return block1(); + } +}" +`; + +exports[`can catch errors catching error, rethrow, render parent -- a main component loop implementation 5`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + let block1 = createBlock(\`