Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/solid/store/src/modifiers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setProperty, unwrap, isWrappable, StoreNode, $RAW } from "./store.js";
import { $PROXY, $TRACK } from "solid-js";
import { setProperty, unwrap, isWrappable, StoreNode, $RAW, $NODE, $HAS } from "./store.js";

const $ROOT = Symbol("store-root");

Expand Down Expand Up @@ -144,6 +145,14 @@ const setterTraps: ProxyHandler<StoreNode> = {
get(target, property): any {
if (property === $RAW) return target;
const value = target[property];
if (
property === $PROXY ||
property === $TRACK ||
property === $NODE ||
property === $HAS ||
property === "__proto__"
)
return value;
let proxy;
return isWrappable(value)
? producers.get(value) ||
Expand Down
27 changes: 27 additions & 0 deletions packages/solid/store/test/modifiers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,33 @@ describe("setState with produce", () => {
expect(state[1].done).toBe(true);
expect(state[2].title).toBe("Go Home");
});

test("Leaked draft proxy returned from getter does not violate proxy invariant (#2668)", () => {
let leaked: any;
const [state, setState] = createStore<{ items: number[]; readonly probe: number[] }>({
items: [],
get probe() {
// touch items so it's tracked, then return leaked draft
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.items;
return leaked;
}
});
expect(() => {
setState(
produce(draft => {
leaked = draft.items;
// Reading probe through the store proxy returns the leaked draft.
// Previously this triggered a "TypeError: 'get' on proxy: property
// 'Symbol(solid-proxy)' is a read-only and non-configurable data
// property on the proxy target but the proxy did not return its
// actual value" because setterTraps.get wrapped the $PROXY value.
state.probe;
})
);
}).not.toThrow();
expect(Array.isArray(state.items)).toBe(true);
});
});

describe("modifyMutable with reconcile", () => {
Expand Down
Loading