Skip to content

Commit

Permalink
Fix unowned roots having owner in dev (#1456)
Browse files Browse the repository at this point in the history
* Fix unowned roots having owner in dev

* add changeset

Co-authored-by: Ryan Carniato <[email protected]>
  • Loading branch information
thetarnav and ryansolid authored Jan 3, 2023
1 parent c4ac14c commit 1384496
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-ducks-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

Fix unowned roots having owner in dev
9 changes: 5 additions & 4 deletions packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ export function createRoot<T>(fn: RootFunction<T>, detachedOwner?: Owner): T {
const listener = Listener,
owner = Owner,
unowned = fn.length === 0,
root: Owner =
unowned && !"_SOLID_DEV_"
? UNOWNED
: { owned: null, cleanups: null, context: null, owner: detachedOwner || owner },
root: Owner = unowned
? "_SOLID_DEV_"
? { owned: null, cleanups: null, context: null, owner: null }
: UNOWNED
: { owned: null, cleanups: null, context: null, owner: detachedOwner || owner },
updateFn = unowned
? "_SOLID_DEV_"
? () =>
Expand Down
19 changes: 17 additions & 2 deletions packages/solid/test/signals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
createContext,
useContext,
getOwner,
runWithOwner,
runWithOwner
} from "../src";

import "./MessageChannel";
Expand Down Expand Up @@ -305,7 +305,6 @@ describe("Effect grouping of signals", () => {
try {
setA(1);
throw new Error("test");
setB(1);
} catch (e) {
error = e as Error;
}
Expand Down Expand Up @@ -660,6 +659,22 @@ describe("create and use context", () => {
});
});

describe("createRoot", () => {
test("roots with dispose function unused are unowned", () => {
createRoot(_ => {
const root1 = getOwner()!;
createRoot(_ => {
const root2 = getOwner()!;
createRoot(() => {
const root3 = getOwner()!;
expect(root2.owner).toBe(root1);
expect(root3.owner).toBe(null);
});
});
});
});
});

describe("runWithOwner", () => {
test("Top level owner execute and disposal", () => {
let effectRun = false;
Expand Down

0 comments on commit 1384496

Please sign in to comment.