Skip to content

Commit bd6bc67

Browse files
authored
adding explicit proxy:true, to fix default charm list in new CTS check (#1575)
* adding explicit proxy:true, to fix default charm list in new CTS check * Revert "Revert "without CTS, our types allow invalid handler (#1551)" (#1568)" This reverts commit bc970a5.
1 parent 4f68791 commit bd6bc67

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
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);

packages/static/assets/recipes/charm-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const CharmsListOutputSchema = {
4444

4545
const visit = handler<{}, { charm: any }>((_, state) => {
4646
return navigateTo(state.charm);
47-
});
47+
}, { proxy: true });
4848

4949

5050
const removeCharm = handler({}, {

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)