fix: properly track query instances inside and outside of reactive contexts#15353
fix: properly track query instances inside and outside of reactive contexts#15353dummdidumm wants to merge 10 commits intomainfrom
Conversation
…ntexts This switches the approach we take to tracking the query/prerender instances across invocations. Instead of having a "are you in a reactive context"-counter, we use a WeakRef instead to keep a weak reference to the instance we create. This a) simplifies the code and b) allows people to create instances outside of reactive contexts, and have them share the same instance with other queries later invoked inside tracking contexts. Practically speaking this avoids surprises where your instance, created outside a reactive context, is not getting any updates from mutation refreshes. Fixes #14559
🦋 Changeset detectedLatest commit: 97aaf8e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| /** | ||
| * Use this to iterate the query_map. Will clean up dereferenced resources as a side effect. | ||
| */ | ||
| export function get_query_array() { |
There was a problem hiding this comment.
would it be worth having this be a generator function so that it doesn't have to populate an intermediate array? tradeoff being it's probably slower but with lower memory usage?
There was a problem hiding this comment.
I doubt that it matters. I would guess we talk about a thousand entries at most
|
I really worry about the non-determinism of this (as well as the big 'Avoid where possible' heading on MDN). I think it's really weird if the behaviour of something like this... <script lang="ts">
import { now } from './test.remote';
async function onclick() {
console.log(await now());
}
</script>
<button {onclick}>click me</button>...has the potential to differ between browsers or devices or whatever. I don't have the answer to #14559 off the top of my head — possibly something about warning if a remote function is created/read in an unowned derived — but unfortunately I don't think this is it. |
This switches the approach we take to tracking the query/prerender instances across invocations. Instead of having a "are you in a reactive context"-counter, we use a WeakRef instead to keep a weak reference to the instance we create. This a) simplifies the code and b) allows people to create instances outside of reactive contexts, and have them share the same instance with other queries later invoked inside tracking contexts. Practically speaking this avoids surprises where your instance, created outside a reactive context, is not getting any updates from mutation refreshes. Fixes #14559