Skip to content

Commit af1e224

Browse files
committed
Revert "Revert "without CTS, our types allow invalid handler (#1551)" (#1568)"
This reverts commit bc970a5.
1 parent 9c01905 commit af1e224

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

packages/runner/src/builder/module.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,17 @@ export function handler<E, T>(
123123
handler?: (event: E, props: T) => any,
124124
): HandlerFactory<T, E> {
125125
if (typeof eventSchema === "function") {
126-
handler = eventSchema;
127-
eventSchema = stateSchema = undefined;
126+
if (
127+
stateSchema && typeof stateSchema === "object" &&
128+
"proxy" in stateSchema && stateSchema.proxy === true
129+
) {
130+
handler = eventSchema;
131+
eventSchema = stateSchema = undefined;
132+
} else {
133+
throw new Error(
134+
"invalid handler, no schema provided - did you forget to enable CTS?",
135+
);
136+
}
128137
}
129138

130139
const schema: JSONSchema | undefined = eventSchema || stateSchema

packages/runner/test/module.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ describe("module", () => {
100100
props.x = event.clientX;
101101
props.y = event.clientY;
102102
},
103+
{ proxy: true },
103104
);
104105
expect(typeof clickHandler).toBe("function");
105106
expect(isModule(clickHandler)).toBe(true);
@@ -111,6 +112,7 @@ describe("module", () => {
111112
props.x = event.clientX;
112113
props.y = event.clientY;
113114
},
115+
{ proxy: true },
114116
);
115117
const stream = clickHandler({ x: opaqueRef(10), y: opaqueRef(20) });
116118
expect(isOpaqueRef(stream)).toBe(true);
@@ -201,6 +203,7 @@ describe("module", () => {
201203
props.x = event.clientX;
202204
props.y = event.clientY;
203205
},
206+
{ proxy: true },
204207
);
205208
const stream = clickHandler.with({ x: opaqueRef(10), y: opaqueRef(20) });
206209
expect(isOpaqueRef(stream)).toBe(true);

recipes/simpleValue.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <cts-enable />
12
import {
23
Cell,
34
derive,

0 commit comments

Comments
 (0)