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

fix(5019): imported stores can be identified as reactive store subscr… #5022

Merged
merged 4 commits into from
Jun 23, 2020
Merged

fix(5019): imported stores can be identified as reactive store subscr… #5022

merged 4 commits into from
Jun 23, 2020

Conversation

skippednote
Copy link
Contributor

This PR address the issue #5019.
The way stores are filtered it is expected variable to be hoistable.
https://github.com/sveltejs/svelte/blob/master/src/compiler/compile/render_dom/index.ts#L320

const reactive_store_subscriptions = reactive_stores
    .filter(store => {
        const variable = component.var_lookup.get(store.name.slice(1));
        return !variable || variable.hoistable;
    })
    .map(({ name }) => b`
        ${component.compile_options.dev && b`@validate_store(${name.slice(1)}, '${name.slice(1)}');`}
        @component_subscribe($$self, ${name.slice(1)}, $$value => $$invalidate(${renderer.context_lookup.get(name).index}, ${name} = $$value));
    `);

Since imports are by their nature hoistable, I have explicitly set that.

@Conduitry Conduitry marked this pull request as draft June 15, 2020 17:34
@Conduitry
Copy link
Member

It looks like this marks every instance variable as hoistable, not just the imports - and this is also breaking many tests.

@skippednote
Copy link
Contributor Author

Thank you @Conduitry for the feedback.
I've taken a different route now, I've marked imported stores as hoistable specifically. All the existing tests seem to be passing now.

@skippednote skippednote marked this pull request as ready for review June 16, 2020 03:36
@Conduitry
Copy link
Member

I think there's another field on the variable object that ought to be able to tell us whether something is a store in a more direct fashion. I think it might be .subscribable?

Can you also add a test for this in test/runtime/samples?

@skippednote
Copy link
Contributor Author

@Conduitry Thanks for the feedback. Instead of check the variable name I'm checking if it is subscribable. I have added a test as suggested.

@Conduitry Conduitry merged commit 0e2bc35 into sveltejs:master Jun 23, 2020
taylorzane pushed a commit to taylorzane/svelte that referenced this pull request Dec 17, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants