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

{#each} pattern in textarea has inconsistent errors? #7552

Closed
mallsoft opened this issue May 22, 2022 · 3 comments · Fixed by #7862
Closed

{#each} pattern in textarea has inconsistent errors? #7552

mallsoft opened this issue May 22, 2022 · 3 comments · Fixed by #7862

Comments

@mallsoft
Copy link

Describe the bug

I am unsure if this is a unhelpful error message (bad DX) or a bug on something that should work (i think it's the latter).

<textarea>
	{#each fruits as fruit}
		{fruit}
	{/each}
</textarea>

this gives the following error Unexpected character '#'

Compare this to the error you get when:

<textarea readonly bind:value={somevar}>
	foo
</textarea>

A <textarea> can have either a value attribute or (equivalently) child content, but not both

A more helpful message.

Reproduction

<script>
	let fruits = [
		"spagetti",
		"pasta",
		"potato"
	]
</script>

<textarea >
	{#each fruits as fruit}
		{fruit}
	{/each}
</textarea>

SvelteRepl

Logs

No response

System Info

-svelte repl
-firefox
-windows10

Severity

annoyance

@Conduitry
Copy link
Member

This is just an error message that could be better. Textareas can't contain multiple DOM nodes or anything, so I really don't know what your code example would do besides something like <textarea>{fruits.join('\n')}</textarea> which is much more explicit about how the elements of the array should be joined.

@mallsoft
Copy link
Author

I think users might expect an each behave like what you show {fruits.join('\n')} in your example, and that quickly becomes a source of confusion.

Relevant help thread:
https://discord.com/channels/457912077277855764/977876658679853056

I think a descriptive error would probably solve this

@Conduitry
Copy link
Member

The error message should be improved now in 3.51.0.

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

Successfully merging a pull request may close this issue.

2 participants