Skip to content

Commit 1ae4fe2

Browse files
committed
fix falsey context lookup
1 parent 25d84f3 commit 1ae4fe2

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

packages/solid/src/reactive/signal.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { JSX } from "../jsx";
66

77
export const equalFn = <T>(a: T, b: T) => a === b;
88
export const $PROXY = Symbol("solid-proxy");
9-
export const $DEVCOMP = Symbol('solid-dev-component');
9+
export const $DEVCOMP = Symbol("solid-dev-component");
1010
const signalOptions = { equals: equalFn };
1111
let ERROR: symbol | null = null;
1212
let runEffects = runQueue;
@@ -324,17 +324,23 @@ export function createEffect<Next, Init = Next>(
324324
*/
325325
export function createReaction(onInvalidate: () => void, options?: EffectOptions) {
326326
let fn: (() => void) | undefined;
327-
const c = createComputation(() => {
328-
fn ? fn() : untrack(onInvalidate);
329-
fn = undefined;
330-
}, undefined, false, 0, "_SOLID_DEV_" ? options : undefined),
327+
const c = createComputation(
328+
() => {
329+
fn ? fn() : untrack(onInvalidate);
330+
fn = undefined;
331+
},
332+
undefined,
333+
false,
334+
0,
335+
"_SOLID_DEV_" ? options : undefined
336+
),
331337
s = SuspenseContext && lookup(Owner, SuspenseContext.id);
332338
if (s) c.suspense = s;
333339
c.user = true;
334340
return (tracking: () => void) => {
335341
fn = tracking;
336342
updateComputation(c);
337-
}
343+
};
338344
}
339345

340346
interface Memo<Prev, Next = Prev> extends SignalState<Next>, Computation<Next> {
@@ -971,10 +977,11 @@ export function resumeEffects(e: Computation<any>[]) {
971977
// Dev
972978
export function devComponent<T>(Comp: (props: T) => JSX.Element, props: T) {
973979
const c: Partial<Memo<JSX.Element, JSX.Element>> = createComputation<JSX.Element, JSX.Element>(
974-
() => untrack(() => {
975-
Object.assign(Comp, {[$DEVCOMP]: true});
976-
return Comp(props);
977-
}),
980+
() =>
981+
untrack(() => {
982+
Object.assign(Comp, { [$DEVCOMP]: true });
983+
return Comp(props);
984+
}),
978985
undefined,
979986
true
980987
);
@@ -1564,7 +1571,10 @@ function handleError(err: any) {
15641571

15651572
function lookup(owner: Owner | null, key: symbol | string): any {
15661573
return (
1567-
owner && ((owner.context && owner.context[key]) || (owner.owner && lookup(owner.owner, key)))
1574+
owner &&
1575+
((owner.context && owner.context[key] !== undefined)
1576+
? owner.context[key]
1577+
: owner.owner && lookup(owner.owner, key))
15681578
);
15691579
}
15701580

packages/solid/src/server/reactive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ export function runWithOwner(o: Owner, fn: () => any) {
166166

167167
export function lookup(owner: Owner | null, key: symbol | string): any {
168168
return (
169-
owner && ((owner.context && owner.context[key]) || (owner.owner && lookup(owner.owner, key)))
169+
owner &&
170+
((owner.context && owner.context[key] !== undefined)
171+
? owner.context[key]
172+
: owner.owner && lookup(owner.owner, key))
170173
);
171174
}
172175

0 commit comments

Comments
 (0)