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

Identifier xxx has already been declared #5247

Closed
Rich-Harris opened this issue Aug 7, 2020 · 1 comment · Fixed by #5251
Closed

Identifier xxx has already been declared #5247

Rich-Harris opened this issue Aug 7, 2020 · 1 comment · Fixed by #5251
Labels

Comments

@Rich-Harris
Copy link
Member

Describe the bug
If a reactive declaration is an assignment, Svelte automatically replaces $: with let in SSR mode if the variable on the left hand side hasn't been declared. It does this even if the left hand side is a member expression:

<script>
  $: user = {};
  $: user.name = 'world';
</script>

<h1>Hello {user.name}!</h1>
const App = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
  let user = {};
  let user.name = "world";
  return `<h1>Hello ${escape(user.name)}!</h1>`;
});

To Reproduce
https://svelte.dev/repl/b8f185ca9b104f4c8d08f2e5846cfaf0?version=3.24.1

Expected behavior
Only the $: user = ... declaration should have a let prepended.

Severity
Can be worked around (e.g. $: true && (user.name = 'world');) but it's a bit annoying. Relatively infrequent occurrence though.

@Conduitry
Copy link
Member

In 3.25.0, the SSR output for this situation now only declares the variable once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants