Skip to content

Commit 87bf8d5

Browse files
fix(signals): narrow the merge trap's table state so the package typechecks
The inlined read trap kept `view.table` (number | Map | null) in one binding through the branch that reaches `table.get`, so `pnpm build` in signals exited 2 while rollup still emitted JS. Read the state once and give the table its own binding. Co-authored-by: Cursor <[email protected]>
1 parent 24943f1 commit 87bf8d5

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎packages/signals/src/store/utils.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,11 @@ const mergeTraps: ProxyHandler<MergeView> = {
831831
// few plain objects read once per key on the server — the walk is the
832832
// whole read. A leaf that is not plain hands the walk to `mergeGet`,
833833
// which starts over (a plain leaf walked twice is two `in` checks).
834-
let table = view.table;
835-
if (typeof table !== "object") {
836-
if (table + 1 < READS_FOR_TABLE) {
837-
view.table = table + 1;
834+
const state = view.table;
835+
let table: Map<PropertyKey, any> | undefined;
836+
if (typeof state !== "object") {
837+
if (state + 1 < READS_FOR_TABLE) {
838+
view.table = state + 1;
838839
const f = view.sources,
839840
k = view.kinds;
840841
for (let i = f.length - 1; i >= 0; i--) {
@@ -848,7 +849,8 @@ const mergeTraps: ProxyHandler<MergeView> = {
848849
}
849850
table = mergeTable(view);
850851
if (table === undefined) return mergeGet(view, property);
851-
} else if (table === null) return mergeGet(view, property);
852+
} else if (state === null) return mergeGet(view, property);
853+
else table = state;
852854
const leaf = table.get(property);
853855
return leaf === undefined ? undefined : leaf[property];
854856
},

0 commit comments

Comments
 (0)