Skip to content

Remove microtask in runtime compiler #20909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ import { fn } from '@ember/helper';
moduleFor(
'Strict Mode - Runtime Template Compiler (implicit)',
class extends RenderingTestCase {
async '@test can immediately render a runtime-compiled template'() {
class State {
get component() {
return template(`hello there`);
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
let state = new State();

await this.renderComponentModule(() => {
return template('<state.component />', {
eval() {
return eval(arguments[0]);
},
});
});

this.assertHTML('hello there');
this.assertStableRerender();
}

async '@test Can use a component in scope'() {
await this.renderComponentModule(() => {
let Foo = template('Hello, world!', {
Expand Down
8 changes: 3 additions & 5 deletions packages/@ember/template-compiler/lib/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,10 @@ export function template(
const normalizedOptions = compileOptions(options);
const component = normalizedOptions.component ?? templateOnly();

queueMicrotask(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: for @NullVoxPopuli

Potential use case:

  • forward references (like functions)

const source = glimmerPrecompile(templateString, normalizedOptions);
const template = templateFactory(evaluate(`(${source})`) as SerializedTemplateWithLazyBlock);
const source = glimmerPrecompile(templateString, normalizedOptions);
const template = templateFactory(evaluate(`(${source})`) as SerializedTemplateWithLazyBlock);

setComponentTemplate(template, component);
});
setComponentTemplate(template, component);

return component;
}
Expand Down
Loading