Skip to content

Silence "No scopable elements found in template" via attribute #1221

@techniq

Description

@techniq

Describe the problem

In an upcoming LayerChart PR that removes Tailwind and leverages pure CSS via <style> blocks, I encounter a lot of the following warnings:

No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS.

Click to view warnings
2:09:03 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Voronoi.svelte:179:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:03 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Axis.svelte:553:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:03 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Rule.svelte:252:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Grid.svelte:281:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Highlight.svelte:572:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Labels.svelte:211:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/AnnotationLine.svelte:156:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/AnnotationPoint.svelte:141:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/AnnotationRange.svelte:161:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Calendar.svelte:168:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/MonthPath.svelte:91:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Hull.svelte:139:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/AnnotationPoint.svelte:141:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/AnnotationRange.svelte:161:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Axis.svelte:553:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/AnnotationLine.svelte:156:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Calendar.svelte:168:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:04 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Grid.svelte:281:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:05 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Highlight.svelte:572:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:05 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Hull.svelte:139:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:05 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Labels.svelte:211:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:05 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Rule.svelte:252:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:05 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/Voronoi.svelte:179:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.
2:09:05 PM [vite-plugin-svelte] /Users/techniq/Documents/Development/open-source/layerchart/packages/layerchart/dist/components/MonthPath.svelte:91:1 No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles.

This is due to needing to use :global(...) to target inner component classes and the class itself does not have any DOM itself (ex. Grid).

The use of :global() is also needed to enable LayerChart to apply classes to Canvas primitives (such as Rect, Circle, etc).

As far as I can tell there is no way to disable this warning through the use of an attribute or annotation on <style> (IIRC older versions of Svelte 3 had a <style global> attribute).

Describe the proposed solution

Add a way to annotation a <style> block to silence the vite-plugin-svelte-css-no-scopable-elements warning

Alternatives considered

While we could tell the user to add the following to svelte.config.js to silence the warning, this isn't a great experience.

const config = {
  onwarn: (warning, handler) => {
    if (warning.code === 'vite-plugin-svelte-css-no-scopable-elements') return;
      handler(warning);
    }
};

We could also move all of these classes to a separate layerchart.css or separate *.css per component (ex. grid.css) but I very much enjoy keeping the styles co-located with the component (and would end up needing to create over 70 new files) 😞

Is there something available that I'm overlooking to make this experience better for development and users? If not, is there something we could add to allow a library to control this setting? Lastly, should these warnings even be shown when the package is imported? I actually only see this warning when running one of the examples and was surprised it doesn't show up in svelte-check.

Thanks!

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttriageAwaiting triage by a project member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions