Skip to content

Variables are not recognized inside string interpolation if <style> is part of the string #2104

@sserdyuk

Description

@sserdyuk

Describe the bug

I needed to dynamically define CSS variables based on the config, and I used string interpolation to construct an HTML fragment and insert it at svelte:head. While it works, it confuses the VS Code plugin. First, the branding variable is marked as unused, second there's no type information during interpolation. After some experiments, I found that <style> in the string is what triggering the issue.

image

Reproduction

<script lang="ts">
  const config = { branding: { primaryColor: '#012345' } },
    branding = config?.branding;

  const cssString = `<style>:root {--primary-color: ${branding?.primaryColor ?? '#ABCDEF'};}</style>`;
</script>

<svelte:head>
  {@html cssString}
</svelte:head>

Expected behaviour

I was expecting that string interpolation works regardless the content of the string.

System Info

  • OS: [e.g. Windows]
  • IDE: [e.g. VSCode, Atom]

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions