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

Inconsistent spacing between two copies of same code #6117

Open
ezfe opened this issue Mar 23, 2021 · 9 comments
Open

Inconsistent spacing between two copies of same code #6117

ezfe opened this issue Mar 23, 2021 · 9 comments
Labels

Comments

@ezfe
Copy link

ezfe commented Mar 23, 2021

Describe the bug

Spaces are added to the Svelte output causing the rendered text not to appear as expected (for example, looping over and outputting characters in a string).

To Reproduce

REPL: https://svelte.dev/repl/86aa94c8350845e794b27ea9f75624e9?version=3.35.0

<script>
	let name = 'Hello world';
</script>

{#each name as character}
	<span>
		{#if character == "l"}
			A
		{:else}
			B
		{/if}
	</span>
{/each}

{#each name as character}
	<span>
		{#if character == "l"}
			A
		{:else}
			B
		{/if}
	</span>
{/each}

Screen Shot 2021-03-22 at 11 22 35 PM

Expected behavior
There should be no spaces in the output.

  • Your browser and the version: (e.x. Chrome 52.1, Firefox 48.0, IE 10)

Safari 14.1
Edge 89.0.774.57

  • Your operating system: (e.x. OS X 10, Ubuntu Linux 19.10, Windows XP, etc)

macOS 11

  • Svelte version (Please check you can reproduce the issue with the latest release!)

Svelte 3.35.0

  • Whether your project uses Webpack or Rollup

Rollup, reproduced with Repl

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of Svelte entirely?

This bug is blocking a secondary feature of my website. I am building a preview of formatted text, and need to be able to loop over text and show each one in its own <span>. Only spaces in the source text should appear in the HTML.

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Mar 23, 2021

Curiously this only happens in the very last block. If you repeat it more than two times it's always the last block. And if you add anything after the each block the space disappears. I hope this helps.

No spaces because of the "x" at the end:

<script>
	let name = 'Hello world';
</script>

{#each name as character}
	<span>
		{#if character == "l"}
			A
		{:else}
			B
		{/if}
	</span>
{/each}

{#each name as character}
	<span>
		{#if character == "l"}
			A
		{:else}
			B
		{/if}
	</span>
{/each}

{#each name as character}
	<span>
		{#if character == "l"}
			A
		{:else}
			B
		{/if}
	</span>
{/each}

x

@ezfe
Copy link
Author

ezfe commented Mar 23, 2021

Yea, I actually noticed that after filing but forgot to come back and add it in. It's super variable, (if of course not actually random).

@stalkerg
Copy link
Contributor

Also, we still have these issues #4731 and #189

@stalkerg
Copy link
Contributor

heh this space exists but not working inside Svelte runtime tests

@ezfe
Copy link
Author

ezfe commented Mar 26, 2021

I found a REPL that actually identifies the same issue: https://svelte.dev/repl/b6c71bf8825f46028793d804facf5e08?version=3.5.1

@stalkerg
Copy link
Contributor

@ezfe I think is different issue

@stalkerg
Copy link
Contributor

ok, I know why it's happens

@stalkerg
Copy link
Contributor

because the first \n (actually something more) between two Fragments (each) we can remove, but the last \n have no obvious reasons to remove.
This part in compiler a little tricky... basically here we can see some inconsistency between the parser and internal compiler AST.
I will try to find way to solve it.

@stale
Copy link

stale bot commented Jun 26, 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 Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 27, 2021
@dummdidumm dummdidumm added bug and removed temp-stale labels Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants