{"action":"created","issue":{"url":"https://api.github.com/repos/sveltejs/sapper/issues/917","repository_url":"https://api.github.com/repos/sveltejs/sapper","labels_url":"https://api.github.com/repos/sveltejs/sapper/issues/917/labels{/name}","comments_url":"https://api.github.com/repos/sveltejs/sapper/issues/917/comments","events_url":"https://api.github.com/repos/sveltejs/sapper/issues/917/events","html_url":"https://github.com/sveltejs/sapper/issues/917","id":499997768,"node_id":"MDU6SXNzdWU0OTk5OTc3Njg=","number":917,"title":"SSR does not use correct value from layout store which is updated within a route","user":{"login":"bikeshedder","id":1112569,"node_id":"MDQ6VXNlcjExMTI1Njk=","avatar_url":"https://avatars0.githubusercontent.com/u/1112569?v=4","gravatar_id":"","url":"https://api.github.com/users/bikeshedder","html_url":"https://github.com/bikeshedder","followers_url":"https://api.github.com/users/bikeshedder/followers","following_url":"https://api.github.com/users/bikeshedder/following{/other_user}","gists_url":"https://api.github.com/users/bikeshedder/gists{/gist_id}","starred_url":"https://api.github.com/users/bikeshedder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bikeshedder/subscriptions","organizations_url":"https://api.github.com/users/bikeshedder/orgs","repos_url":"https://api.github.com/users/bikeshedder/repos","events_url":"https://api.github.com/users/bikeshedder/events{/privacy}","received_events_url":"https://api.github.com/users/bikeshedder/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2019-09-30T00:43:28Z","updated_at":"2019-09-30T10:47:25Z","closed_at":null,"author_association":"NONE","body":"**Describe the bug**\r\nWhen updating a layout store from within a route the store is rendered with the wrong value during SSR.\r\n\r\n**To Reproduce**\r\nhttps://github.com/bikeshedder/sapper-store-bug\r\n\r\n**Expected behavior**\r\nThe SSR should produce the following output:\r\n```\r\n_layout.svelte :: foo = borat\r\n_layout.svelet :: bar = borat\r\n```\r\nInstead `$foo` and `$bar` are both rendered as `undefined`:\r\n```\r\n_layout.svelte :: foo = undefined\r\n_layout.svelet :: bar = undefined\r\n```\r\nOnce the page is rerendered inside the browser the proper values appear:\r\n\r\n**Severity**\r\nIt's very annoying as this essentially means SSR is broken for anything but data loaded and displayed inside the route or its children. Any data that is passed to the parent component/layout via context+store doesn't work with SSR."},"comment":{"url":"https://api.github.com/repos/sveltejs/sapper/issues/comments/536507984","html_url":"https://github.com/sveltejs/sapper/issues/917#issuecomment-536507984","issue_url":"https://api.github.com/repos/sveltejs/sapper/issues/917","id":536507984,"node_id":"MDEyOklzc3VlQ29tbWVudDUzNjUwNzk4NA==","user":{"login":"bikeshedder","id":1112569,"node_id":"MDQ6VXNlcjExMTI1Njk=","avatar_url":"https://avatars0.githubusercontent.com/u/1112569?v=4","gravatar_id":"","url":"https://api.github.com/users/bikeshedder","html_url":"https://github.com/bikeshedder","followers_url":"https://api.github.com/users/bikeshedder/followers","following_url":"https://api.github.com/users/bikeshedder/following{/other_user}","gists_url":"https://api.github.com/users/bikeshedder/gists{/gist_id}","starred_url":"https://api.github.com/users/bikeshedder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bikeshedder/subscriptions","organizations_url":"https://api.github.com/users/bikeshedder/orgs","repos_url":"https://api.github.com/users/bikeshedder/repos","events_url":"https://api.github.com/users/bikeshedder/events{/privacy}","received_events_url":"https://api.github.com/users/bikeshedder/received_events","type":"User","site_admin":false},"created_at":"2019-09-30T10:47:25Z","updated_at":"2019-09-30T10:47:25Z","author_association":"NONE","body":"I just added another example which updates a global store from within the `preload` function:\r\nhttps://github.com/bikeshedder/sapper-store-bug/commit/61d39c4805ecbd90398e85798739473f28381f7c\r\n\r\nThis also illustrates two problems with this implementation:\r\n\r\n1. Custom stores are not hydrated on the client side. This causes the SSR to render the correct thing but the client store is empty and upon rerendering inside the browser the value vanishes.\r\n2. As it is now a global state it's very easy to leak possibly sensible data to other users which shouldn't be able to access them. Just `curl http://localhost:3000/foo` and then `curl http://localhost:3000/` to see `foo` still being stored inside the store.\r\n\r\nThe first one can be solved by calling `name3.set(name)` inside the component initializer. While being ugly as it needs to be done for every single component it's a possible workaround. The second one is rather serious and illustrates quite nicely that global state should better not be used to solve this problem."}}
{"actor":{"display_login":"bikeshedder"}}