Skip to content

Commit

Permalink
fix(core): handle deref returning null on RefactiveNode. (#50992)
Browse files Browse the repository at this point in the history
On Safari <16.1 there is a bug where `deref` can return `null`.

Fixes #50989

PR Close #50992
  • Loading branch information
JeanMeche authored and dylhunn committed Jul 11, 2023
1 parent 29aaded commit 5d6ec03
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/signals/src/graph.ts
Expand Up @@ -149,7 +149,9 @@ export abstract class ReactiveNode {
for (const [producerId, edge] of this.producers) {
const producer = edge.producerNode.deref();

if (producer === undefined || edge.atTrackingVersion !== this.trackingVersion) {
// On Safari < 16.1 deref can return null, we need to check for null also.
// See https://github.com/WebKit/WebKit/commit/44c15ba58912faab38b534fef909dd9e13e095e0
if (producer == null || edge.atTrackingVersion !== this.trackingVersion) {
// This dependency edge is stale, so remove it.
this.producers.delete(producerId);
producer?.consumers.delete(this.id);
Expand Down Expand Up @@ -177,7 +179,10 @@ export abstract class ReactiveNode {
try {
for (const [consumerId, edge] of this.consumers) {
const consumer = edge.consumerNode.deref();
if (consumer === undefined || consumer.trackingVersion !== edge.atTrackingVersion) {

// On Safari < 16.1 deref can return null, we need to check for null also.
// See https://github.com/WebKit/WebKit/commit/44c15ba58912faab38b534fef909dd9e13e095e0
if (consumer == null || consumer.trackingVersion !== edge.atTrackingVersion) {
this.consumers.delete(consumerId);
consumer?.producers.delete(this.id);
continue;
Expand Down

0 comments on commit 5d6ec03

Please sign in to comment.