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

chore: better store subscriptions #12277

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
we never set last_value, this is gibberish
  • Loading branch information
Rich-Harris committed Jul 3, 2024
commit a2069ac4c8efb85635007bcc4ea118a62c8b9b9a
6 changes: 1 addition & 5 deletions packages/svelte/src/internal/client/reactivity/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function store_get(store, store_name, stores) {
if (is_new) {
entry = {
store: null,
last_value: null,
value: mutable_source(UNINITIALIZED),
unsubscribe: noop
};
Expand All @@ -38,10 +37,7 @@ export function store_get(store, store_name, stores) {
entry.unsubscribe = connect_store_to_signal(store, entry.value);
}

const value = get(entry.value);
// This could happen if the store was cleaned up because the component was destroyed and there's a leak on the user side.
// In that case we don't want to fail with a cryptic Symbol error, but rather return the last value we got.
return value === UNINITIALIZED ? entry.last_value : value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was in response to a real bug I investigated at some point. I think the fix was gradually removed over time (there was more logic there before) so that it's unused now. Let me see if I can dig up the PR and related issue to see if something like this is still necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was from https://github.com/sveltejs/svelte-octane/commit/6ebe7118c8fe3f45d0b9787d1e9c92cc7e27d62d, but without any reference - I vaguely remember that it occured while testing the code out on some Svelte site and noticing the bug. But this error can't happen anymore now because back then the source value was set back to UNINITIALIZED which is no longer the case now - so all good.

return get(entry.value);
}

/**
Expand Down
1 change: 0 additions & 1 deletion packages/svelte/src/internal/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export type StoreReferencesContainer = Record<
string,
{
store: Store<any> | null;
last_value: any;
unsubscribe: Function;
value: Source<any>;
}
Expand Down