FIX: Lost outer context in #each block in hbr (#28461)

Regressed 3.5 years ago in e80332a2bc :P
This commit is contained in:
Jarek Radosz 2024-08-21 17:11:36 +02:00 committed by GitHub
parent b69a7ea824
commit cee2605d88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -44,8 +44,8 @@ export function registerRawHelpers(hbs, handlebarsClass, owner) {
}
let list = get(this, contextName);
let output = [];
let innerContext = { ...options.contexts[0] };
for (let i = 0; i < list.length; i++) {
let innerContext = {};
innerContext[localName] = list[i];
output.push(options.fn(innerContext));
}

View File

@ -7,6 +7,7 @@ import RenderGlimmerContainer from "discourse/components/render-glimmer-containe
import raw from "discourse/helpers/raw";
import rawRenderGlimmer from "discourse/lib/raw-render-glimmer";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { compile } from "discourse-common/lib/raw-handlebars";
import {
addRawTemplate,
removeRawTemplate,
@ -104,4 +105,20 @@ module("Integration | Helper | raw", function (hooks) {
assert.dom("span.bar").hasText(/^baz$/);
});
test("#each helper preserves the outer context", async function (assert) {
const template = `
{{#each items as |item|}}
{{string}} {{item}}
{{/each}}
`;
addRawTemplate("raw-test", compile(template));
const items = [1, 2];
await render(<template>
<span>{{raw "raw-test" string="foo" items=items}}</span>
</template>);
assert.dom("span").hasText("foo 1 foo 2");
});
});