question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Variable's in-template usage not detected

See original GitHub issue

In the following scenario, the CurrentYear variable doesn’t get picked up.

<i18n>
{
    "en": {
        "copyrightNotice": "{currentYear} (...)"
    }
}
</i18n>

<template>
    <span>
        {{ $t("copyrightNotice", { currentYear: CurrentYear }) }}
    </span>
</template>

<script setup lang="ts">
import { computed, useContext } from "@nuxtjs/composition-api";

const { $moment } = useContext();
const CurrentYear = computed(() => $moment().year());
</script>

It does work though when variable is present in the following way:

<template>
    <span>
        {{ CurrentYear }}
    </span>
</template>

Is there some background optimisation in place detecting unused variables and ignoring them? If so, unfortunately this is a case when it appears to fail.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
DamianGlowalacommented, Feb 22, 2022

Definitely, I will share a reproduction as soon as I get meaningful results. I was overconfident with the above snippets - when I attempted to reproduce the problem myself in a blank project, I couldn’t do that in any way. Turns out to be more tricky than I thought. Whenever I have some spare time, I will try to replicate my current project step-by-step and see which bit of code (or library) triggers the bug. Very bizarre. I am intrigued what makes it skip the variable so I will keep digging!

1reaction
xiaoxiangmoecommented, Feb 22, 2022

@DamianGlowala I’m trying to rewrite parseSFC logic. It will take some time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why template local variables are not usable ... - Stack Overflow
My goal is to focus an element that will be created. Solution given by Mark Rajcok: make a directive with an afterViewInit that...
Read more >
clion does not see usages of data variable for template class
This is small example, I have a template class which declared in ". h" file, and the implementation of its function is in...
Read more >
'recursive loop detected in template string' error with variables ...
I've found a weird bug with ansible playbooks (or maybe my code/setup). When I use a tasks playbook using an include, the variables...
Read more >
Typing $ to create or list template variables does not work - Jira
The problem isn't creating new variables. It's the inability to use/insert that variable in the rest of the page. Andrew W.
Read more >
Troubleshooting email template error messages – Klaviyo
This error message means one or more of your variables contains a filter that has been applied incorrectly. Compare your filters to those...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found