Skip to content

Commit

Permalink
fix wrapping of object with null prototype (#2286)
Browse files Browse the repository at this point in the history
* fix wrapping object with null prototype

* Create yellow-rings-report.md

---------

Co-authored-by: Ryan Carniato <[email protected]>
  • Loading branch information
MrFoxPro and ryansolid authored Sep 23, 2024
1 parent 9697c94 commit 94929af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-rings-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

fix wrapping of object with `null` prototype
1 change: 1 addition & 0 deletions packages/solid/store/src/mutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function wrap<T extends StoreNode>(value: T): T {

const proto = Object.getPrototypeOf(value);
const isClass =
proto !== null &&
value !== null &&
typeof value === "object" &&
!Array.isArray(value) &&
Expand Down
5 changes: 5 additions & 0 deletions packages/solid/store/test/mutable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { createRoot, createSignal, createMemo, batch, createEffect } from "../..
import { Accessor, Setter } from "../../types";
import { createMutable, unwrap, $RAW } from "../src";

test("Object.create(null) is allowed", () => {
const user = createMutable(Object.assign(Object.create(null), { name: "John" }));
expect(user.name).toBe("John");
});

describe("State Mutability", () => {
test("Setting a property", () => {
const user = createMutable({ name: "John" });
Expand Down

0 comments on commit 94929af

Please sign in to comment.