Skip to content

can not pass $store into child component as props in ssr, its get TypeError : can not read property of undefined #4651

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

Closed
jadeja-rajdeep opened this issue Apr 8, 2020 · 2 comments

Comments

@jadeja-rajdeep
Copy link

Describe the bug
store.js

import { writable } from 'svelte/store';
export const activeRoute = writable({});

Router.svelte

import { activeRoute } from './../store.js';
//some function here which is updated the store $activeRoute
<Route currentRoute={$activeRoute } />

Route.svelte

<script>
	export let currentRoute = {};
</script>
{#if currentRoute.layout.viewed == false}
	<svelte:component this={currentRoute.layout.layout} currentRoute={{ ...currentRoute, layout:{layout:currentRoute.layout.layout,viewed:true}}}/>
{:else if currentRoute.component.viewed == false}
	<svelte:component this={currentRoute.component.component} currentRoute={{ ...currentRoute, component:{layout:currentRoute.component.component,viewed:true}}}/>
{/if}

in the browser mode single page application working fine as exptected
but when we try to run the same app which is build / compiled for ssr support its fail at
{#if currentRoute.layout.viewed == false}

for the solution for this i changed the code in Router.svelte
Router.svelte

import { activeRoute } from './../store.js';
//some function here which is updated the store $activeRoute
const unsubscribe = activeRoute.subscribe(value => {
    currentRoute = value;
});
<Route currentRoute={currentRoute} />

and instead of $activeRoute now i am passing currentRoute


so i dont know its error or we cant not use direct $store into as prop but think to just report in case.

thanks

@Conduitry
Copy link
Member

This sounds like it might be a duplicate of #3636.

@jadeja-rajdeep
Copy link
Author

okay thanks if you think its duplicate then you can close this

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

2 participants