@@ -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
145146export function getContextOwner ( ) {
147+ Owner && ( Owner . noRecycle = true ) ;
146148 return Owner ;
147149}
148150
149151export 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 {
197200class 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
382386function 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