mirror of
https://github.com/discourse/discourse.git
synced 2025-06-09 06:18:14 +08:00
FIX: Lost outer context in #each
block in hbr (#28461)
Regressed 3.5 years ago in e80332a2bcc5b9c56e4fd2937ecbc3b3dfff941c :P
This commit is contained in:
@ -44,8 +44,8 @@ export function registerRawHelpers(hbs, handlebarsClass, owner) {
|
|||||||
}
|
}
|
||||||
let list = get(this, contextName);
|
let list = get(this, contextName);
|
||||||
let output = [];
|
let output = [];
|
||||||
|
let innerContext = { ...options.contexts[0] };
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
let innerContext = {};
|
|
||||||
innerContext[localName] = list[i];
|
innerContext[localName] = list[i];
|
||||||
output.push(options.fn(innerContext));
|
output.push(options.fn(innerContext));
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import RenderGlimmerContainer from "discourse/components/render-glimmer-containe
|
|||||||
import raw from "discourse/helpers/raw";
|
import raw from "discourse/helpers/raw";
|
||||||
import rawRenderGlimmer from "discourse/lib/raw-render-glimmer";
|
import rawRenderGlimmer from "discourse/lib/raw-render-glimmer";
|
||||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||||
|
import { compile } from "discourse-common/lib/raw-handlebars";
|
||||||
import {
|
import {
|
||||||
addRawTemplate,
|
addRawTemplate,
|
||||||
removeRawTemplate,
|
removeRawTemplate,
|
||||||
@ -104,4 +105,20 @@ module("Integration | Helper | raw", function (hooks) {
|
|||||||
|
|
||||||
assert.dom("span.bar").hasText(/^baz$/);
|
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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user