-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Svelte adds whitespace to template literals when dev: false
#2813
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
Comments
dev: false
dev: false
Further to the above, Svelte only generates the incorrect code in dev mode when hydratable is false due to the different code generated. This REPL better illustrates the problem. The rendered code is fine but I copy/ pasted the example output and attached it manually added to illustrate the problem. If you look at the generated code (in the output tab) you can see that the indentation is intact (when it should be flattened). |
I was just pleasantly surprised to see that Svelte is apparently already correctly handling indentation of multi-line template strings in user code. So I guess it's just the code generated for the optimized static innerHTML, which is weird (maybe because it's not getting inserted via a replaceable snippet reference, which happens after |
I was sweeping through the open bugs for ones that might be fixed by the structured codegen PR, and I realized I'm really not sure at all what exactly the bug is here. I'm fiddling with the different REPLs here, and I can't actually see any behavior that looks wrong. Do you have a super simple example that shows this? |
This bug is the extra indentation when Svelte sets the In this REPL if you compare line 60-65 with line 23-27 you can see the difference. If this is what you mean by whitespace then, yeah, that is what I was seeing. |
Fixed by #3539. I'm closing this without writing a test because writing a test sounds annoying to test for (because the HTML comparer in the tests ignores whitespace) and it seems unlikely this would resurface. |
Uh oh!
There was an error while loading. Please reload this page.
When
dev: false
and Svelte generates template literals to set the innerHTML of an element, it seems to be adding whitespace. Specifically it seems to be aligning the template literal to the indentation level of its parent function in the generated code. If this is a nested function then one or more tabs will be added to the beginning of each line.Example input:
Output:
This does not happen when
dev: true
.For the case of code blocks (wrapped in pre tags) this is obviously more of an issue, in some cases it doesn't make much of a difference.
The text was updated successfully, but these errors were encountered: