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

Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -1,12 +1,65 @@
import { tracked } from '@ember/-internals/metal';
import { template } from '@ember/template-compiler/runtime';
import { RenderingTestCase, defineSimpleModifier, moduleFor } from 'internal-test-helpers';
import { RenderingTestCase, defineSimpleModifier, moduleFor, runTask } from 'internal-test-helpers';
import GlimmerishComponent from '../../utils/glimmerish-component';
import { on } from '@ember/modifier/on';
import { fn } from '@ember/helper';

moduleFor(
'Strict Mode - Runtime Template Compiler (implicit)',
class extends RenderingTestCase {
async '@test can have in-scope tracked data'(assert: Assert) {
class State {
@tracked str = `hello there`;

get component() {
assert.step('get component');

let getStr = () => {
assert.step('getStr()');
return this.str;
};

hide(getStr);

return template(`{{ (getStr) }}`, {
eval() {
return eval(arguments[0]);
},
});
}
}

let state = new State();

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

this.assertHTML('hello there');
this.assertStableRerender();
assert.verifySteps([
// for every value in the component, for eevry node traversed in the compiler
'eval', // precompileJSON -> ... ElementNode -> ... -> lexicalScope -> isScope('state', ...)
'eval', // "..."
'eval', // "..."
'eval', // creating the templateFactory
'get component',
'getStr()',
]);

runTask(() => (state.str += '!'));

this.assertHTML('hello there!');
this.assertStableRerender();
assert.verifySteps(['getStr()']);
}

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