Skip to content

Commit 9a02db4

Browse files
authored
Sync Preact build config with reactpy-django (#1296)
2 parents 6930fc2 + 1e7d5d2 commit 9a02db4

25 files changed

+105
-188
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/bun.lockb

-45.5 KB
Binary file not shown.

src/js/eslint.config.mjs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,25 @@
1-
import react from "eslint-plugin-react";
2-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
1+
import { default as eslint } from "@eslint/js";
32
import globals from "globals";
4-
import tsParser from "@typescript-eslint/parser";
5-
import path from "node:path";
6-
import { fileURLToPath } from "node:url";
7-
import js from "@eslint/js";
8-
import { FlatCompat } from "@eslint/eslintrc";
9-
10-
const __filename = fileURLToPath(import.meta.url);
11-
const __dirname = path.dirname(__filename);
12-
const compat = new FlatCompat({
13-
baseDirectory: __dirname,
14-
recommendedConfig: js.configs.recommended,
15-
allConfig: js.configs.all,
16-
});
3+
import tseslint from "typescript-eslint";
174

185
export default [
19-
...compat.extends(
20-
"eslint:recommended",
21-
"plugin:react/recommended",
22-
"plugin:@typescript-eslint/recommended",
23-
),
24-
{
25-
ignores: ["**/node_modules/", "**/dist/"],
26-
},
6+
eslint.configs.recommended,
7+
...tseslint.configs.recommended,
8+
{ ignores: ["**/node_modules/", "**/dist/"] },
279
{
28-
plugins: {
29-
react,
30-
"@typescript-eslint": typescriptEslint,
31-
},
32-
3310
languageOptions: {
3411
globals: {
3512
...globals.browser,
3613
...globals.node,
3714
},
38-
39-
parser: tsParser,
4015
ecmaVersion: "latest",
4116
sourceType: "module",
4217
},
43-
44-
settings: {
45-
react: {
46-
version: "detect",
47-
},
48-
},
49-
5018
rules: {
5119
"@typescript-eslint/ban-ts-comment": "off",
5220
"@typescript-eslint/no-explicit-any": "off",
5321
"@typescript-eslint/no-non-null-assertion": "off",
5422
"@typescript-eslint/no-empty-function": "off",
55-
"react/prop-types": "off",
5623
},
5724
},
5825
];

src/js/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
{
22
"devDependencies": {
3-
"@eslint/eslintrc": "^3.2.0",
4-
"@eslint/js": "^9.18.0",
5-
"@typescript-eslint/eslint-plugin": "^8.21.0",
6-
"@typescript-eslint/parser": "^8.21.0",
3+
"@eslint/js": "^9.29.0",
4+
"bun-types": "^1.2.16",
75
"eslint": "^9.18.0",
8-
"eslint-plugin-react": "^7.37.4",
96
"globals": "^15.14.0",
10-
"prettier": "^3.4.2"
7+
"prettier": "^3.4.2",
8+
"typescript-eslint": "^8.34.0"
119
},
1210
"license": "MIT",
1311
"scripts": {
14-
"lint": "prettier --check . && eslint",
15-
"format": "prettier --write . && eslint --fix"
12+
"format": "prettier --write . && eslint --fix",
13+
"lint": "prettier --check . && eslint"
1614
}
1715
}
420 Bytes
Binary file not shown.

src/js/packages/@reactpy/app/eslint.config.mjs

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

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"name": "@reactpy/app",
3-
"description": "ReactPy's client-side entry point. This is strictly for internal use and is not designed to be distributed.",
4-
"license": "MIT",
52
"dependencies": {
63
"@reactpy/client": "file:../client",
74
"event-to-object": "file:../../event-to-object",
85
"preact": "^10.25.4"
96
},
7+
"description": "ReactPy's client-side entry point. This is strictly for internal use and is not designed to be distributed.",
108
"devDependencies": {
11-
"typescript": "^5.7.3",
129
"@pyscript/core": "^0.6",
13-
"morphdom": "^2"
10+
"morphdom": "^2",
11+
"typescript": "^5.8.3"
1412
},
13+
"license": "MIT",
14+
"name": "@reactpy/app",
1515
"scripts": {
1616
"build": "bun build \"src/index.ts\" --outdir=\"../../../../reactpy/static/\" --minify --sourcemap=\"linked\"",
1717
"checkTypes": "tsc --noEmit"

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
{
-1.79 KB
Binary file not shown.
Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
{
2-
"name": "@reactpy/client",
3-
"version": "1.0.0",
4-
"description": "A client for ReactPy implemented in React",
52
"author": "Ryan Morshead",
6-
"license": "MIT",
7-
"repository": {
8-
"type": "git",
9-
"url": "https://github.com/reactive-python/reactpy"
3+
"dependencies": {
4+
"json-pointer": "^0.6.2",
5+
"preact": "^10.26.9"
6+
},
7+
"description": "A client for ReactPy implemented in React",
8+
"devDependencies": {
9+
"@types/json-pointer": "^1.0.34",
10+
"typescript": "^5.8.3"
1011
},
1112
"keywords": [
1213
"react",
1314
"reactive",
1415
"python",
1516
"reactpy"
1617
],
17-
"type": "module",
18+
"license": "MIT",
1819
"main": "dist/index.js",
19-
"dependencies": {
20-
"json-pointer": "^0.6.2",
21-
"preact": "^10.25.4"
22-
},
23-
"devDependencies": {
24-
"@types/json-pointer": "^1.0.34",
25-
"@types/react": "^17.0",
26-
"@types/react-dom": "^17.0",
27-
"typescript": "^5.7.3"
28-
},
20+
"name": "@reactpy/client",
2921
"peerDependencies": {
3022
"event-to-object": "<1.0.0"
3123
},
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/reactive-python/reactpy"
27+
},
3228
"scripts": {
3329
"build": "tsc -b",
3430
"checkTypes": "tsc --noEmit"
35-
}
31+
},
32+
"type": "module",
33+
"version": "1.0.0"
3634
}

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, type JSX } 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
{
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)