Skip to content

Plugin cannot process a component containing <style> in string or even comment #507

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

Closed
samijaber opened this issue Apr 25, 2022 · 1 comment

Comments

@samijaber
Copy link

Describe the bug

I was initially trying to build this component and ran into errors:

<script>
$: injectedStyles = () => `//some logic here`

$: injectedStyleScript = () => {
  return `<style>${injectedStyles()}</style>`;
};
</script>
    
{@html injectedStyleScript()}

After some more testing, I realized that the mere presence of the <style> string within <script>, even if in a string (or a comment!!) causes the vite-plugin-svelte plugin to crash with the following error:

Reproduction

<script>
	// export const value = '<style>test</style>';
</script>

<div>test</div>

Logs
Please include browser console and server logs around the time this bug occurred.

Error while preprocessing {filePath}.svelte - {filePath}:1:1: Unknown word
CssSyntaxError: Error while preprocessing {filePath}.svelte - {filePath}.svelte:1:1: Unknown word
    at Input.error (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/postcss/lib/input.js:148:16)
    at Parser.unknownWord (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/postcss/lib/parser.js:540:22)
    at Parser.other (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/postcss/lib/parser.js:164:12)
    at Parser.parse (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/postcss/lib/parser.js:72:16)
    at parse (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/postcss/lib/parse.js:11:12)
    at new LazyResult (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/postcss/lib/lazy-result.js:133:16)
    at Processor.process (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/postcss/lib/processor.js:28:14)
    at transformer (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/svelte-preprocess/dist/transformers/globalStyle.js:56:72)
    at transform (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/svelte-preprocess/dist/autoProcess.js:37:12)
    at async style (/Users/samijaber/code/work/builder/examples/svelte/sveltekit/node_modules/svelte-preprocess/dist/autoProcess.js:191:33)

To Reproduce
To help us help you, if you've found a bug please consider the following:

Expected behavior
This should be valid Svelte code as it works fine in the Svelte REPL

Information about your project:

System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 164.56 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/.asdf/installs/nodejs/16.14.0/bin/node
    Yarn: 3.2.0 - ~/.asdf/installs/nodejs/16.14.0/bin/yarn
    npm: 8.3.1 - ~/.asdf/plugins/nodejs/shims/npm
    Watchman: 2022.02.28.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 100.1.37.116
    Chrome: 100.0.4896.127
    Firefox: 97.0.1
    Safari: 15.2
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.34
    @sveltejs/kit: next => 1.0.0-next.311
    svelte: ^3.46.0 => 3.47.0
@bluwy
Copy link
Member

bluwy commented Apr 26, 2022

Similar to sveltejs/vite-plugin-svelte#315, it's an issue in Svelte sveltejs/svelte#5292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants