Skip to content
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

New rule to lint against referencing let variables in <template> #1897

Closed
chancancode opened this issue Jun 21, 2023 · 1 comment · Fixed by #1939
Closed

New rule to lint against referencing let variables in <template> #1897

chancancode opened this issue Jun 21, 2023 · 1 comment · Fixed by #1939
Labels
Enhancement New Rule Idea for a new lint rule

Comments

@chancancode
Copy link

chancancode commented Jun 21, 2023

// app/components/foo.gjs
let foo = 1;

function increment() {
  foo++;
}

export default <template>{{foo}}</template>;

This does not "work" – it doesn't error, but it will essentially capture and compile in the value of the foo variable at some arbitrary point and never update again. Even if the component is torn down and a new instance is created/rendered, it will probably still hold on to the old value when the template was initially compiled.

So, generally speaking, one should avoid referencing let variables from within <template> and instead prefer to use const bindings to avoid this confusion/foot-gun.

@bmish bmish added Enhancement New Rule Idea for a new lint rule labels Jun 21, 2023
@patricklx
Copy link
Contributor

Should be easy to implement with #1920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New Rule Idea for a new lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants