diff --git a/src/hooks.ts b/src/hooks.ts index ff259cc8..3eb865b7 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -45,9 +45,8 @@ function extendEnv(currentEnv: Object, extension: Object): Object { */ export function useSubEnv(envExtension: Env) { const node = getCurrent()!; - const newEnv = extendEnv(node.component.env as any, envExtension); node.component.env = extendEnv(node.component.env as any, envExtension); - node.childEnv = newEnv; + useChildSubEnv(envExtension); } export function useChildSubEnv(envExtension: Env) { diff --git a/tests/components/__snapshots__/hooks.test.ts.snap b/tests/components/__snapshots__/hooks.test.ts.snap index d5edf3cb..2f610f5c 100644 --- a/tests/components/__snapshots__/hooks.test.ts.snap +++ b/tests/components/__snapshots__/hooks.test.ts.snap @@ -103,6 +103,37 @@ exports[`hooks mounted callbacks should be called in reverse order from willUnmo }" `; +exports[`hooks parent and child env (with useChildSubEnv then useSubEnv) 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + return function template(ctx, node, key = \\"\\") { + let b2 = text(ctx['env'].val); + let b3 = component(\`Child\`, {}, key + \`__1\`, node, ctx); + return multi([b2, b3]); + } +}" +`; + +exports[`hooks parent and child env (with useChildSubEnv then useSubEnv) 2`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + let block2 = createBlock(\`