Skip to content

Commit cef6091

Browse files
Merge pull request #215 from jmeistrich/remove-owner
2 parents d930658 + 515ff33 commit cef6091

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

packages/react/src/index.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Signal,
1616
type ReadonlySignal,
1717
} from "@preact/signals-core";
18-
import { Effect, ReactOwner, ReactDispatcher } from "./internal";
18+
import { Effect, ReactDispatcher } from "./internal";
1919

2020
export { signal, computed, batch, effect, Signal, type ReadonlySignal };
2121

@@ -55,7 +55,7 @@ function createPropUpdater(props: any, prop: string, signal: Signal) {
5555
*/
5656

5757
let finishUpdate: (() => void) | undefined;
58-
const updaterForComponent = new WeakMap<ReactOwner, Effect>();
58+
const updaterForComponent = new WeakMap<() => void, Effect>();
5959

6060
function setCurrentUpdater(updater?: Effect) {
6161
// end tracking for the current update:
@@ -95,19 +95,6 @@ Object.defineProperties(Signal.prototype, {
9595
ref: { configurable: true, value: null },
9696
});
9797

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-
11198
// Track the current dispatcher (roughly equiv to current component impl)
11299
let lock = false;
113100
const UPDATE = () => ({});
@@ -119,17 +106,17 @@ Object.defineProperty(internals.ReactCurrentDispatcher, "current", {
119106
set(api) {
120107
currentDispatcher = api;
121108
if (lock) return;
122-
if (lastOwner && api && !isInvalidHookAccessor(api)) {
109+
if (api && !isInvalidHookAccessor(api)) {
123110
// prevent re-injecting useReducer when the Dispatcher
124111
// context changes to run the reducer callback:
125112
lock = true;
126113
const rerender = api.useReducer(UPDATE, {})[1];
127114
lock = false;
128115

129-
let updater = updaterForComponent.get(lastOwner);
116+
let updater = updaterForComponent.get(rerender);
130117
if (!updater) {
131118
updater = createUpdater(rerender);
132-
updaterForComponent.set(lastOwner, updater);
119+
updaterForComponent.set(rerender, updater);
133120
} else {
134121
updater._callback = rerender;
135122
}
@@ -148,8 +135,7 @@ function isInvalidHookAccessor(api: ReactDispatcher) {
148135
if (cached !== undefined) return cached;
149136
// we only want the real implementation, not the warning ones
150137
const invalid =
151-
api.useCallback.length < 2 ||
152-
/warnInvalidHookAccess/.test(api.useCallback as any);
138+
api.useCallback.length < 2 || /Invalid/.test(api.useCallback as any);
153139
invalidHookAccessors.set(api, invalid);
154140
return invalid;
155141
}

packages/react/src/internal.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ export interface Effect {
77
_dispose(): void;
88
}
99

10-
export interface ReactOwner {
11-
_: never;
12-
}
13-
1410
export interface ReactDispatcher {
1511
useCallback(): unknown;
1612
}

0 commit comments

Comments
 (0)