Skip to content

Commit 78c8f1a

Browse files
authored
v2.0.0b4 (#1311)
- Improve type hints on `reactjs_component_from_*` - Remove `jsonpointer` dependency - `use_effect` will now generate an exception if attempting to use an async function. Use `use_async_effect` instead. - Add warning within `event-to-object` if providing a non-object value. Non-objects will now be passed through as-is. - Prevent `@reactpy/client` from attempting to convert non-object types. - Remove deprecated `Stop` exception type - Remove deprecated `hotswap` function - Remove top-level export of `reactpy.Layout`. Use `reactpy.core.layout.Layout` instead. - Remove top-level export of `reactpy.Event`. Use `reactpy.types.Event` instead.
1 parent ea40d18 commit 78c8f1a

File tree

23 files changed

+242
-162
lines changed

23 files changed

+242
-162
lines changed

docs/source/about/changelog.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Unreleased
5757
- :pull:`1196` - Rewrite the ``event-to-object`` package to be more robust at handling properties on events.
5858

5959
**Deprecated**
60+
6061
-:pull:`1307` - ``reactpy.web.export`` is deprecated. Use ``reactpy.web.reactjs_component_from_*`` instead.
6162
-:pull:`1307` - ``reactpy.web.module_from_file`` is deprecated. Use ``reactpy.web.reactjs_component_from_file`` instead.
6263
-:pull:`1307` - ``reactpy.web.module_from_url`` is deprecated. Use ``reactpy.web.reactjs_component_from_url`` instead.
@@ -81,6 +82,10 @@ Unreleased
8182
- :pull:`1281` - Removed ``reactpy.vdom``. Use ``reactpy.Vdom`` instead.
8283
- :pull:`1281` - Removed ``reactpy.core.make_vdom_constructor``. Use ``reactpy.Vdom`` instead.
8384
- :pull:`1281` - Removed ``reactpy.core.custom_vdom_constructor``. Use ``reactpy.Vdom`` instead.
85+
- :pull:`1311` - Removed ``reactpy.core.serve.Stop`` type due to extended deprecation.
86+
- :pull:`1311` - Removed ``reactpy.Layout`` top-level export. Use ``reactpy.core.layout.Layout`` instead.
87+
- :pull:`1311` - Removed ``reactpy.widgets.hotswap`` due to extended deprecation.
88+
8489

8590
**Fixed**
8691

@@ -288,7 +293,7 @@ v0.43.0
288293

289294
**Deprecated**
290295

291-
- :pull:`870` - ``ComponentType.should_render()``. This method was implemented based on
296+
- :pull:`870` - ``ComponentType.()``. This method was implemented based on
292297
reading the React/Preact source code. As it turns out though it seems like it's mostly
293298
a vestige from the fact that both these libraries still support class-based
294299
components. The ability for components to not render also caused several bugs.

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ features = ["all"]
9898
python = ["3.10", "3.11", "3.12", "3.13"]
9999

100100
[tool.pytest.ini_options]
101-
addopts = """\
102-
--strict-config
103-
--strict-markers
104-
"""
101+
addopts = ["--strict-config", "--strict-markers"]
105102
filterwarnings = """
106103
ignore::DeprecationWarning:uvicorn.*
107104
ignore::DeprecationWarning:websockets.*

src/build_scripts/copy_dir.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# dependencies = []
44
# ///
55

6-
# ruff: noqa: INP001
76
import logging
87
import shutil
98
import sys

src/js/packages/@reactpy/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
"checkTypes": "tsc --noEmit"
3232
},
3333
"type": "module",
34-
"version": "1.0.0"
34+
"version": "1.0.1"
3535
}

src/js/packages/@reactpy/client/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class ReactPyClient
6969
url: this.urls.componentUrl,
7070
readyPromise: this.ready,
7171
...props.reconnectOptions,
72-
onMessage: (event) => this.handleIncoming(JSON.parse(event.data)),
72+
onMessage: async ({ data }) => this.handleIncoming(JSON.parse(data)),
7373
});
7474
}
7575

src/js/packages/@reactpy/client/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from "./vdom";
66
export * from "./websocket";
77
export { default as React } from "preact/compat";
88
export { default as ReactDOM } from "preact/compat";
9+
export * as preact from "preact";

src/js/packages/@reactpy/client/src/vdom.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactPyClientInterface } from "./types";
2-
import serializeEvent from "event-to-object";
2+
import eventToObject from "event-to-object";
33
import type {
44
ReactPyVdom,
55
ReactPyVdomImportSource,
@@ -212,7 +212,13 @@ function createEventHandler(
212212
if (stopPropagation) {
213213
event.stopPropagation();
214214
}
215-
return serializeEvent(event);
215+
216+
// Convert JavaScript objects to plain JSON, if needed
217+
if (typeof event === "object") {
218+
return eventToObject(event);
219+
} else {
220+
return event;
221+
}
216222
});
217223
client.sendMessage({ type: "layout-event", data, target });
218224
};

src/js/packages/event-to-object/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
"checkTypes": "tsc --noEmit"
3232
},
3333
"type": "module",
34-
"version": "1.0.0"
34+
"version": "1.0.1"
3535
}

src/js/packages/event-to-object/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ export default function convert(
77
classObject: { [key: string]: any },
88
maxDepth: number = 10,
99
): object {
10-
const visited = new WeakSet<any>();
11-
visited.add(classObject);
10+
// Immediately return `classObject` if given an unexpected (non-object) input
11+
if (!classObject || typeof classObject !== "object") {
12+
console.warn(
13+
"eventToObject: Expected an object input, received:",
14+
classObject,
15+
);
16+
return classObject;
17+
}
1218

1319
// Begin conversion
20+
const visited = new WeakSet<any>();
21+
visited.add(classObject);
1422
const convertedObj: { [key: string]: any } = {};
1523
for (const key in classObject) {
1624
// Skip keys that cannot be converted

src/js/packages/event-to-object/tests/event-to-object.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,10 @@ test("handles recursive HTML node structures", () => {
670670
expect(converted.children[0].parentNode).toBeUndefined();
671671
}
672672
});
673+
674+
test("pass-through on unexpected non-object inputs", () => {
675+
expect(convert(null as any)).toEqual(null);
676+
expect(convert(undefined as any)).toEqual(undefined);
677+
expect(convert(42 as any)).toEqual(42);
678+
expect(convert("test" as any)).toEqual("test");
679+
});

0 commit comments

Comments
 (0)