Skip to content

Commit da11736

Browse files
authored
Merge pull request #7368 from QwikDev/v2-fix-backrefs-serialization
fix: signals back refs serialization
2 parents 1c2df76 + ed9d343 commit da11736

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

.changeset/seven-pumpkins-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/core': patch
3+
---
4+
5+
fix: infinity serialization loop

packages/qwik/src/core/shared/shared-serialization.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ export const createSerializationContext = (
835835
discoveredValues.push(v);
836836
}
837837
if (obj.$effects$) {
838-
discoveredValues.push(...obj.$effects$);
838+
discoveredValues.push(obj.$effects$);
839839
}
840840
// WrappedSignal uses syncQrl which has no captured refs
841841
if (obj instanceof WrappedSignal) {
@@ -847,6 +847,7 @@ export const createSerializationContext = (
847847
discoveredValues.push(obj.$hostElement$);
848848
}
849849
} else if (obj instanceof ComputedSignal) {
850+
discoverEffectBackRefs(obj[_EFFECT_BACK_REF], discoveredValues);
850851
discoveredValues.push(obj.$computeQrl$);
851852
}
852853
} else if (obj instanceof Task) {
@@ -944,18 +945,7 @@ const discoverEffectBackRefs = (
944945
discoveredValues: unknown[]
945946
) => {
946947
if (effectsBackRefs) {
947-
// We need serialize effect subscriptions with back refs
948-
let hasBackRefs = false;
949-
for (const [, effect] of effectsBackRefs) {
950-
const backRefs = effect[EffectSubscriptionProp.BACK_REF];
951-
if (backRefs) {
952-
hasBackRefs = true;
953-
break;
954-
}
955-
}
956-
if (hasBackRefs) {
957-
discoveredValues.push(effectsBackRefs);
958-
}
948+
discoveredValues.push(effectsBackRefs);
959949
}
960950
};
961951

packages/qwik/src/core/signal/signal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import type { OnRenderFn } from '../shared/component.public';
3232
import { _EFFECT_BACK_REF, NEEDS_COMPUTATION } from './flags';
3333
import { QError, qError } from '../shared/error/error';
3434
import { isDomContainer } from '../client/dom-container';
35-
import type { BackRef } from './signal-cleanup';
35+
import { type BackRef } from './signal-cleanup';
3636
import { getSubscriber } from './subscriber';
3737

3838
const DEBUG = false;
@@ -328,7 +328,7 @@ export const triggerEffects = (
328328
*
329329
* The value is available synchronously, but the computation is done lazily.
330330
*/
331-
export class ComputedSignal<T> extends Signal<T> {
331+
export class ComputedSignal<T> extends Signal<T> implements BackRef {
332332
/**
333333
* The compute function is stored here.
334334
*
@@ -340,6 +340,7 @@ export class ComputedSignal<T> extends Signal<T> {
340340
// we need the old value to know if effects need running after computation
341341
$invalid$: boolean = true;
342342
$forceRunEffects$: boolean = false;
343+
[_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | null = null;
343344

344345
constructor(container: Container | null, fn: QRLInternal<() => T>) {
345346
// The value is used for comparison when signals trigger, which can only happen

0 commit comments

Comments
 (0)