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

SSR: writable store set in component does not update $store variable #3636

Closed
btakita opened this issue Sep 29, 2019 · 4 comments
Closed

SSR: writable store set in component does not update $store variable #3636

btakita opened this issue Sep 29, 2019 · 4 comments
Assignees
Labels

Comments

@btakita
Copy link
Contributor

btakita commented Sep 29, 2019

Here is the repro. https://svelte.dev/repl/e8ab45ee0a1e44ff8da3d09a427e201d?version=3.12.1

You have to look at the SSR output to see the issue, since the repl does not render SSR.

Notice that $name is defined before name.set('Joe') & is not updated afterwards. This causes the SSR to render the state from the previous request.

/* App.svelte generated by Svelte v3.12.1 */
import {
	create_ssr_component,
	escape,
	get_store_value
} from "svelte/internal";
import { writable, get } from "svelte/store"

const App = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
	let $name;

	const name = writable('Peter'); $name = get_store_value(name)

	$name = get_store_value(name);

	name.set('Joe')
	console.debug($name)
	console.debug(get(name))

	return `<h1>Hello ${escape($name)}!</h1>`;
});

export default App;
@btakita
Copy link
Contributor Author

btakita commented Sep 29, 2019

It looks like $name is hoisted in SSR, causing the issue. Not sure when this was introduced.

<script>
	import { writable, get } from 'svelte/store'
	const name = writable('Peter')
	$: name.set('Joe')
	$: console.debug($name)
	$: console.debug(get(name))
</script>

<h1>Hello {$name}!</h1>

@Conduitry
Copy link
Member

This looks like a similar issue to #3582 but I'm not sure whether they're the same.

@btakita
Copy link
Contributor Author

btakita commented Oct 24, 2019

They look similar but the behavior is different. #3582 is an undeclared variable while this issue is the store convenience variable ($name) is not updated after name.set.

@Conduitry
Copy link
Member

This is finally fixed in 3.31.2 as part of a more sweeping change to how store autosubscriptions are handled in SSR code. See the generated code for https://svelte.dev/repl/e8ab45ee0a1e44ff8da3d09a427e201d?version=3.31.2

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

2 participants