Skip to content

Commit 8f7d5bb

Browse files
Merge branch 'main' into nvp/check-void-mAlex-usecase
2 parents 57a2c73 + 7b7bb60 commit 8f7d5bb

2 files changed

Lines changed: 50 additions & 5 deletions

File tree

packages/@ember/-internals/glimmer/tests/integration/components/render-component-test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,50 @@ moduleFor(
657657
this.renderComponent(Root, {
658658
expect: [`<div id="a">a:Hi: THEREa:Hi: THERE</div><br>`, '', ''].join('\n'),
659659
});
660+
run(() => destroy(this));
661+
662+
assertHTML('');
663+
}
664+
665+
async '@test async rendering multiple times to adjacent elements'() {
666+
let Child = defComponent(`Hi`, { scope: {} });
667+
let get = (id: string) => this.element.querySelector(id);
668+
let promises: Promise<unknown>[] = [];
669+
670+
function render(Comp: GlimmerishComponent, id: string, owner: Owner) {
671+
let promise = (async () => {
672+
await Promise.resolve();
673+
let element = get(`#${id}`);
674+
675+
renderComponent(Comp, {
676+
into: element!,
677+
owner,
678+
});
679+
})();
680+
681+
promises.push(promise);
682+
683+
return;
684+
}
685+
let A = defComponent('a:<Child />', { scope: { Child } });
686+
let B = defComponent('b:<Child />', { scope: { Child } });
687+
let Root = defComponent(
688+
[
689+
`<div id="a"></div><br>`,
690+
`<div id="b"></div>`,
691+
`{{render A 'a' owner}}`,
692+
`{{render B 'b' owner}}`,
693+
].join('\n'),
694+
{ scope: { render, A, B, owner: this.owner } }
695+
);
696+
697+
this.renderComponent(Root, {
698+
expect: [`<div id="a"></div><br>`, `<div id="b"></div>`, ``, ``].join('\n'),
699+
});
700+
701+
await Promise.all(promises);
702+
703+
assertHTML([`<div id="a">a:Hi</div><br>`, `<div id="b">b:Hi</div>`, ``, ``].join('\n'));
660704

661705
run(() => destroy(this));
662706

packages/@glimmer/opcode-compiler/lib/compilable-template.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
HandleResult,
1010
HighLevelOp,
1111
LayoutWithContext,
12-
Nullable,
1312
SerializedBlock,
1413
SerializedInlineBlock,
1514
Statement,
@@ -37,7 +36,7 @@ class CompilableTemplateImpl<S extends SymbolTable> implements CompilableTemplat
3736
}
3837
}
3938

40-
compiled: Nullable<HandleResult> = null;
39+
compiled: WeakMap<EvaluationContext, HandleResult> = new WeakMap();
4140

4241
constructor(
4342
readonly statements: WireFormat.Statement[],
@@ -70,14 +69,16 @@ function maybeCompile(
7069
compilable: CompilableTemplateImpl<SymbolTable>,
7170
context: EvaluationContext
7271
): HandleResult {
73-
if (compilable.compiled !== null) return compilable.compiled;
72+
if (compilable.compiled.has(context)) {
73+
return compilable.compiled.get(context) as HandleResult;
74+
}
7475

75-
compilable.compiled = PLACEHOLDER_HANDLE;
76+
compilable.compiled.set(context, PLACEHOLDER_HANDLE);
7677

7778
let { statements, meta } = compilable;
7879

7980
let result = compileStatements(statements, meta, context);
80-
compilable.compiled = result;
81+
compilable.compiled.set(context, result);
8182

8283
return result;
8384
}

0 commit comments

Comments
 (0)