Skip to content
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 strips prefix space #4731

Closed
bwbroersma opened this issue Apr 27, 2020 · 4 comments · Fixed by #6990
Closed

preserveWhitespace strips prefix space #4731

bwbroersma opened this issue Apr 27, 2020 · 4 comments · Fixed by #6990
Labels
compiler Changes relating to the compiler

Comments

@bwbroersma
Copy link
Contributor

Describe the bug
The compiler option preserveWhitespace: true strips prefix space:

<h1> Hello {name}!</h1>

To Reproduce
See this repo. With minimal changes from the svelte/template. This is my output with missing prefix space.

Expected behavior
Keep the prefix whitespace in the SSR.

Information about your Svelte project:
svelte-3.21.0 & rollup.

@bwbroersma
Copy link
Contributor Author

bwbroersma commented Apr 28, 2020

I'm trying to make near-byte-perfect SSR output because we might be involved in the Creative Commons static site generator of the Licenses (the deeds and legalcode). Because this is quite a project (with many languages), I wanted to verify the Svelte (Sapper) output with the current situation (both compared to the code live and in the repo).

Because both comments and whitespace is not working like expected: whitespace is stripped in this case:

<div>
    <div>
        <p> Some text </p>
    </div>
</div>

to

<div><div><p>Some text </p></div>

however, there is a 'trick':

<div><!---->
    <div><!---->
        <p><!----> Some text </p>
    </div><!---->
</div>

this will the desired output:

<div>
    <div>
        <p> Some text </p>
    </div>
</div>

and it is what I'm currently doing in a PoC to get the compare working.

The main function involved in stripping whitespace is remove_whitespace_children not checking preserveWhitespace.

This ssr trim function is involved in stripping leading & trailing whitespace in a component, without checking preserveWhitespace.

I also had issues with tags like select and option which are in elements_without_text meaning all spaces are skipped, also without checking preserveWhitespace.

I think the option preserveWhitespace should preserve all whitespace: newlines, prefix spaces, spaces in select tags, etc.
I would love to hear some feedback how people are thinking about this.

@stale
Copy link

stale bot commented Dec 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Dec 24, 2021
@frederikhors
Copy link

Can we please disable this stupid bot?

dummdidumm pushed a commit that referenced this issue Feb 2, 2022
Fixes #6437
Fixes #4731
Closes #4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
@Conduitry
Copy link
Member

This should be fixed in 3.46.4.

himanshiLt pushed a commit to himanshiLt/svelte that referenced this issue Mar 3, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Mar 14, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Apr 21, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Apr 21, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
nevilm-lt pushed a commit to nevilm-lt/svelte that referenced this issue Apr 22, 2022
…tejs#6990)

Fixes sveltejs#6437
Fixes sveltejs#4731
Closes sveltejs#4737

Whitespace is now untouched inside <pre> tag and other tags if preserveWhitespace is true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Changes relating to the compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants