Skip to content

Commit 833e0a3

Browse files
committed
Prevent node recycling when referenced for context
1 parent f0e870f commit 833e0a3

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "solid-js",
33
"description": "A declarative JavaScript library for building user interfaces.",
4-
"version": "0.7.1",
4+
"version": "0.7.2",
55
"author": "Ryan Carniato",
66
"license": "MIT",
77
"repository": {

src/signals.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: Co
7171
},
7272
root = disposer === null ? UNOWNED : getCandidateNode(),
7373
result: T;
74-
root.owner = detachedOwner || Owner;
74+
let potentialOwner = detachedOwner || Owner;
75+
root !== potentialOwner && (root.owner = potentialOwner);
7576
Owner = root;
7677

7778
try {
@@ -143,12 +144,14 @@ export function useContext(context: Context) {
143144
}
144145

145146
export function getContextOwner() {
147+
Owner && (Owner.noRecycle = true);
146148
return Owner;
147149
}
148150

149151
export function setContext(key: symbol | string, value: any) {
150152
if (Owner === null) return console.warn("Context keys cannot be set without a root or parent");
151153
const context = Owner.context || (Owner.context = {});
154+
Owner.noRecycle = true;
152155
context[key] = value;
153156
}
154157

@@ -197,7 +200,6 @@ export class DataNode {
197200
class ComputationNode {
198201
fn: ((v: any) => any) | null;
199202
value: any;
200-
context: any;
201203
age: number;
202204
state: number;
203205
source1: null | Log;
@@ -206,6 +208,8 @@ class ComputationNode {
206208
sourceslots: null | number[];
207209
log: Log | null;
208210
owner: any;
211+
context: any;
212+
noRecycle?: boolean;
209213
owned: ComputationNode[] | null;
210214
cleanups: (((final: boolean) => void)[]) | null;
211215

@@ -381,11 +385,12 @@ function getCandidateNode() {
381385

382386
function recycleOrClaimNode<T>(node: ComputationNode, fn: (v: T | undefined) => T, value: T, orphan: boolean) {
383387
var _owner = orphan || Owner === null || Owner === UNOWNED ? null : Owner,
384-
recycle = node.source1 === null && (node.owned === null && node.cleanups === null || _owner !== null),
388+
recycle = !node.noRecycle && node.source1 === null && (node.owned === null && node.cleanups === null || _owner !== null),
385389
i: number;
386390

387391
if (recycle) {
388392
LastNode = node;
393+
node.owner = null;
389394

390395
if (_owner !== null) {
391396
if (node.owned !== null) {

0 commit comments

Comments
 (0)