Skip to content

Commit bdea164

Browse files
committed
Sync Preact build config with reactpy-django
1 parent 6930fc2 commit bdea164

File tree

16 files changed

+54
-59
lines changed

16 files changed

+54
-59
lines changed

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"proseWrap": "never",
3+
"trailingComma": "all"
4+
}

src/js/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/js/packages/@reactpy/app/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"extends": "../../../tsconfig.json",
32
"compilerOptions": {
3+
"composite": true,
44
"outDir": "dist",
5-
"rootDir": "src",
6-
"composite": true
5+
"rootDir": "src"
76
},
7+
"extends": "../../../tsconfig.json",
88
"include": ["src"],
99
"references": [
1010
{
0 Bytes
Binary file not shown.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"main": "dist/index.js",
1919
"dependencies": {
2020
"json-pointer": "^0.6.2",
21-
"preact": "^10.25.4"
21+
"preact": "^10.26.9"
2222
},
2323
"devDependencies": {
2424
"@types/json-pointer": "^1.0.34",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logger from "./logger";
2-
import {
2+
import type {
33
ReactPyClientInterface,
44
ReactPyModule,
55
GenericReactPyClientProps,

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import { set as setJsonPointer } from "json-pointer";
2-
import React, {
3-
ChangeEvent,
4-
createContext,
5-
createElement,
6-
Fragment,
7-
MutableRefObject,
8-
useContext,
9-
useEffect,
10-
useRef,
11-
useState,
12-
} from "preact/compat";
13-
import {
2+
import type { ChangeEvent, MutableRefObject } from "preact/compat";
3+
import { createContext, createElement, Fragment } from "preact";
4+
import { useContext, useEffect, useRef, useState } from "preact/hooks";
5+
import type {
146
ImportSourceBinding,
157
ReactPyComponent,
168
ReactPyVdom,
@@ -67,7 +59,7 @@ export function Element({ model }: { model: ReactPyVdom }): JSX.Element | null {
6759
}
6860

6961
function StandardElement({ model }: { model: ReactPyVdom }) {
70-
const client = React.useContext(ClientContext);
62+
const client = useContext(ClientContext);
7163
// Use createElement here to avoid warning about variable numbers of children not
7264
// having keys. Warning about this must now be the responsibility of the client
7365
// providing the models instead of the client rendering them.
@@ -83,10 +75,10 @@ function StandardElement({ model }: { model: ReactPyVdom }) {
8375
function UserInputElement({ model }: { model: ReactPyVdom }): JSX.Element {
8476
const client = useContext(ClientContext);
8577
const props = createAttributes(model, client);
86-
const [value, setValue] = React.useState(props.value);
78+
const [value, setValue] = useState(props.value);
8779

8880
// honor changes to value from the client via props
89-
React.useEffect(() => setValue(props.value), [props.value]);
81+
useEffect(() => setValue(props.value), [props.value]);
9082

9183
const givenOnChange = props.onChange;
9284
if (typeof givenOnChange === "function") {
@@ -116,7 +108,7 @@ function UserInputElement({ model }: { model: ReactPyVdom }): JSX.Element {
116108
function ScriptElement({ model }: { model: ReactPyVdom }) {
117109
const ref = useRef<HTMLDivElement | null>(null);
118110

119-
React.useEffect(() => {
111+
useEffect(() => {
120112
// Don't run if the parent element is missing
121113
if (!ref.current) {
122114
return;
@@ -181,10 +173,10 @@ function useImportSource(model: ReactPyVdom): MutableRefObject<any> {
181173
const vdomImportSource = model.importSource;
182174
const vdomImportSourceJsonString = JSON.stringify(vdomImportSource);
183175
const mountPoint = useRef<HTMLElement>(null);
184-
const client = React.useContext(ClientContext);
176+
const client = useContext(ClientContext);
185177
const [binding, setBinding] = useState<ImportSourceBinding | null>(null);
186178

187-
React.useEffect(() => {
179+
useEffect(() => {
188180
let unmounted = false;
189181

190182
if (vdomImportSource) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { default as React, default as ReactDOM } from "preact/compat";
1+
import { render } from "preact";
22
import { ReactPyClient } from "./client";
33
import { Layout } from "./components";
4-
import { MountProps } from "./types";
4+
import type { MountProps } from "./types";
55

66
export function mountReactPy(props: MountProps) {
77
// WebSocket route for component rendering
@@ -36,6 +36,5 @@ export function mountReactPy(props: MountProps) {
3636
});
3737

3838
// Start rendering the component
39-
// eslint-disable-next-line react/no-deprecated
40-
ReactDOM.render(<Layout client={client} />, props.mountElement);
39+
render(<Layout client={client} />, props.mountElement);
4140
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentType } from "react";
1+
import type { ComponentType } from "preact";
22

33
// #### CONNECTION TYPES ####
44

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React from "react";
2-
import { ReactPyClientInterface } from "./types";
1+
import type { ReactPyClientInterface } from "./types";
32
import serializeEvent from "event-to-object";
4-
import {
3+
import type {
54
ReactPyVdom,
65
ReactPyVdomImportSource,
76
ReactPyVdomEventHandler,
@@ -112,7 +111,7 @@ function getComponentFromModule(
112111
/* Gets the component with the provided name from the provided module.
113112
114113
Built specifically to work on inifinitely deep nested components.
115-
For example, component "My.Nested.Component" is accessed from
114+
For example, component "My.Nested.Component" is accessed from
116115
ModuleA like so: ModuleA["My"]["Nested"]["Component"].
117116
*/
118117
const componentParts: string[] = componentName.split(".");
@@ -206,17 +205,14 @@ function createEventHandler(
206205
): [string, () => void] {
207206
const eventHandler = function (...args: any[]) {
208207
const data = Array.from(args).map((value) => {
209-
if (!(typeof value === "object" && value.nativeEvent)) {
210-
return value;
211-
}
212-
const event = value as React.SyntheticEvent<any>;
208+
const event = value as Event;
213209
if (preventDefault) {
214210
event.preventDefault();
215211
}
216212
if (stopPropagation) {
217213
event.stopPropagation();
218214
}
219-
return serializeEvent(event.nativeEvent);
215+
return serializeEvent(event);
220216
});
221217
client.sendMessage({ type: "layout-event", data, target });
222218
};
@@ -228,7 +224,7 @@ function createInlineJavaScript(
228224
name: string,
229225
inlineJavaScript: string,
230226
): [string, () => void] {
231-
/* Function that will execute the string-like InlineJavaScript
227+
/* Function that will execute the string-like InlineJavaScript
232228
via eval in the most appropriate way */
233229
const wrappedExecutable = function (...args: any[]) {
234230
function handleExecution(...args: any[]) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CreateReconnectingWebSocketProps } from "./types";
1+
import type { CreateReconnectingWebSocketProps } from "./types";
22
import log from "./logger";
33

44
export function createReconnectingWebSocket(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"extends": "../../../tsconfig.json",
32
"compilerOptions": {
3+
"composite": true,
44
"outDir": "dist",
5-
"rootDir": "src",
6-
"composite": true
5+
"rootDir": "src"
76
},
7+
"extends": "../../../tsconfig.json",
88
"include": ["src"],
99
"references": [
1010
{
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"extends": "../../tsconfig.json",
32
"compilerOptions": {
3+
"composite": true,
44
"outDir": "dist",
5-
"rootDir": "src",
6-
"composite": true
5+
"rootDir": "src"
76
},
7+
"extends": "../../tsconfig.json",
88
"include": ["src"]
99
}

src/js/tsconfig.json

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
{
22
"compilerOptions": {
3-
"allowJs": false,
3+
"allowJs": true,
44
"allowSyntheticDefaultImports": true,
55
"declaration": true,
66
"declarationMap": true,
77
"esModuleInterop": true,
88
"forceConsistentCasingInFileNames": true,
99
"isolatedModules": true,
10-
"jsx": "react",
11-
"lib": ["DOM", "DOM.Iterable", "esnext"],
12-
"module": "esnext",
13-
"moduleResolution": "node",
10+
"jsx": "react-jsx",
11+
"jsxImportSource": "preact",
12+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
13+
"module": "Preserve",
14+
"moduleDetection": "force",
15+
"moduleResolution": "bundler",
1416
"noEmitOnError": true,
1517
"noUnusedLocals": true,
18+
"paths": {
19+
"react": ["./node_modules/preact/compat/"],
20+
"react-dom": ["./node_modules/preact/compat/"],
21+
"react-dom/*": ["./node_modules/preact/compat/*"],
22+
"react/jsx-runtime": ["./node_modules/preact/jsx-runtime"]
23+
},
1624
"resolveJsonModule": true,
17-
"skipLibCheck": false,
25+
"skipLibCheck": true,
1826
"sourceMap": true,
1927
"strict": true,
20-
"target": "esnext"
28+
"target": "ESNext",
29+
"verbatimModuleSyntax": true
2130
}
2231
}

src/reactpy/executors/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def vdom_head_to_html(head: VdomDict) -> str:
4343
if isinstance(head, dict) and head.get("tagName") == "head":
4444
return reactpy_to_string(head)
4545

46-
raise ValueError(
47-
"Invalid head element! Element must be either `html.head` or a string."
48-
)
46+
raise ValueError("Head element must be constructed with `html.head`.")
4947

5048

5149
def process_settings(settings: ReactPyConfig) -> None:

tests/test_asgi/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def test_invalid_vdom_head():
8-
with pytest.raises(ValueError, match="Invalid head element!*"):
8+
with pytest.raises(ValueError):
99
utils.vdom_head_to_html({"tagName": "invalid"})
1010

1111

0 commit comments

Comments
 (0)