@@ -15,7 +15,7 @@ import {
15
15
Signal ,
16
16
type ReadonlySignal ,
17
17
} from "@preact/signals-core" ;
18
- import { Effect , ReactOwner , ReactDispatcher } from "./internal" ;
18
+ import { Effect , ReactDispatcher } from "./internal" ;
19
19
20
20
export { signal , computed , batch , effect , Signal , type ReadonlySignal } ;
21
21
@@ -55,7 +55,7 @@ function createPropUpdater(props: any, prop: string, signal: Signal) {
55
55
*/
56
56
57
57
let finishUpdate : ( ( ) => void ) | undefined ;
58
- const updaterForComponent = new WeakMap < ReactOwner , Effect > ( ) ;
58
+ const updaterForComponent = new WeakMap < ( ) => void , Effect > ( ) ;
59
59
60
60
function setCurrentUpdater ( updater ?: Effect ) {
61
61
// end tracking for the current update:
@@ -95,19 +95,6 @@ Object.defineProperties(Signal.prototype, {
95
95
ref : { configurable : true , value : null } ,
96
96
} ) ;
97
97
98
- // Track the current owner (roughly equiv to current vnode)
99
- let lastOwner : ReactOwner | undefined ;
100
- let currentOwner : ReactOwner | null = null ;
101
- Object . defineProperty ( internals . ReactCurrentOwner , "current" , {
102
- get ( ) {
103
- return currentOwner ;
104
- } ,
105
- set ( owner ) {
106
- currentOwner = owner ;
107
- if ( currentOwner ) lastOwner = currentOwner ;
108
- } ,
109
- } ) ;
110
-
111
98
// Track the current dispatcher (roughly equiv to current component impl)
112
99
let lock = false ;
113
100
const UPDATE = ( ) => ( { } ) ;
@@ -119,17 +106,17 @@ Object.defineProperty(internals.ReactCurrentDispatcher, "current", {
119
106
set ( api ) {
120
107
currentDispatcher = api ;
121
108
if ( lock ) return ;
122
- if ( lastOwner && api && ! isInvalidHookAccessor ( api ) ) {
109
+ if ( api && ! isInvalidHookAccessor ( api ) ) {
123
110
// prevent re-injecting useReducer when the Dispatcher
124
111
// context changes to run the reducer callback:
125
112
lock = true ;
126
113
const rerender = api . useReducer ( UPDATE , { } ) [ 1 ] ;
127
114
lock = false ;
128
115
129
- let updater = updaterForComponent . get ( lastOwner ) ;
116
+ let updater = updaterForComponent . get ( rerender ) ;
130
117
if ( ! updater ) {
131
118
updater = createUpdater ( rerender ) ;
132
- updaterForComponent . set ( lastOwner , updater ) ;
119
+ updaterForComponent . set ( rerender , updater ) ;
133
120
} else {
134
121
updater . _callback = rerender ;
135
122
}
@@ -148,8 +135,7 @@ function isInvalidHookAccessor(api: ReactDispatcher) {
148
135
if ( cached !== undefined ) return cached ;
149
136
// we only want the real implementation, not the warning ones
150
137
const invalid =
151
- api . useCallback . length < 2 ||
152
- / w a r n I n v a l i d H o o k A c c e s s / . test ( api . useCallback as any ) ;
138
+ api . useCallback . length < 2 || / I n v a l i d / . test ( api . useCallback as any ) ;
153
139
invalidHookAccessors . set ( api , invalid ) ;
154
140
return invalid ;
155
141
}
0 commit comments