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

Bad code generated for self-referencing reactive value #2386

Closed
Rich-Harris opened this issue Apr 9, 2019 · 0 comments
Closed

Bad code generated for self-referencing reactive value #2386

Rich-Harris opened this issue Apr 9, 2019 · 0 comments

Comments

@Rich-Harris
Copy link
Member

REPL. This works for DOM code, as the let happens outside the update function:

<script>
	let number = 0;
	
	// this generates bad code in SSR mode
	$: max = Math.max(number, max || 0);
</script>

<style>
	input {
		width: 100%;
	}
</style>

<input type=range bind:value={number}>
<p>{number} / {max}</p>

In SSR mode, this code gets generated, resulting in a TDZ:

let max = Math.max(number, max || 0);

We could fix it straightforwardly enough by doing this instead:

let max; max = Math.max(number, max || 0);

Perhaps we should just do it in these rare cases though.

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

No branches or pull requests

1 participant