-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
preserveWhitespace does not behave according to the docs or the docs are vague rather #4337
Comments
One of the points of confusion I see is here are competing optimizations. In the case above, the I will mention that putting the example html: <span>
<span>a</span>
<span>b</span>
</span> in a plain html page and rendering it actually results in 5 nodes |
Would it help if the docs instead said "rather than collapsed to a single space where possible"? |
If I understand correctly that happens at runtime? While I believe the whitespace should and can be handled at compile time, regardless of how (
you could also say Svelte behaves unexpected or is less predictable or more non-standard. The Browser does it one way, other Frameworks (e.g. React using JSX) do it a second, predictable way (no whitespace at all) and Svelte has its own (third) way.
I don't think this can be solved with words. Maybe the compiler options should be accompanied by examples? I'm also not sure if this is purely a "docs" things. What is the benefit of how Svelte does it? I'm still looking for a workaround that let's me keep using prettier (I don't want to cramp multiple |
Is anyone aware of a workaround? I'd really appreciate it. It doesn't look like we're getting Example rendering a colored URL query string. This makes it obvious that I cannot control the whitespace as a user. It is impossible for me to cramp everything in a single line. I cannot set <span class="query-string">
{#each pairs as [key, value], index}
{#if index === 0}
<span>?</span>
{/if}
<span class="key">{key}</span>
{#if value}
<span>=</span>
<span class="value">{value}</span>
{/if}
{#if index < pairs.length - 1}
<span>&</span>
{/if}
{:else}
<span>{search}</span>
{/each}
</span>
|
Describe the bug
I'm aware of #189 (didn't read the whole thing) and #2258
Docs say
"optimised by Svelte" is vague and not well-defined. Naive as I am I was expecting all whitespace between elements to be removed by svelte. But they are not.
To Reproduce
Paste into REPL:
Output
Expected behavior
Output
The same example in React (JSX) behaves that way https://jsfiddle.net/pc5ozm1r/
Information about your Svelte project:
Your browser and the version: Chrome 79.0.3945.130, Firefox 72.0.1
Your operating system: Ubuntu 19.10
Svelte version: REPL
Whether your project uses Webpack or Rollup; Irrelevant, reproduces in REPL
Severity
It's more annoying than super sever. I'd have to resort to old hacks such as using
font-size:0
on the wrapper to get rid of the whitespace, which would introduce all kinds of dependencies (suddenly my component would care about the context it is used in). I'd be more than happy with a non-awkward workaround.Additional context
There is a long history of issues with whitespace between elements and there is currently still no clean solution https://stackoverflow.com/questions/2628050/ignore-whitespace-in-html
I was using React a while ago and forgot that problem even existed.
The text was updated successfully, but these errors were encountered: