sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7.01k stars 435 forks source link

Updates to the session store cause the page store subscription to fire. #1754

Open AaronDDM opened 3 years ago

AaronDDM commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

Logs N/A

To Reproduce https://github.com/AaronDDM/sapper-store-update-bug/blob/main/src/routes/index.svelte

    import { stores } from "@sapper/app";
    const { session, page } = stores();
    page.subscribe((p) => {
        console.debug('[page.subscribe] called');
    })
    setTimeout(() => {
        session.update((s) => {
            console.debug('[session.update] called');
            return {...s}
        })
    })

Actual: Console logs:

[session.update] called
[page.subscribe] called
[page.subscribe] called

Expected behaviour Console logs:

[session.update] called
[page.subscribe] called

Severity This has caused unexpected behaviour for us, but via some local caching of state we can avoid having our page.subscribe() code from being unnecessarily be called. It's not super urgent, but I think it should be fixed as soon as convenient.