Skip to content

Commit ba899d6

Browse files
committed
functional standalone app and static apps, broken dispatcher
1 parent d1fe8c7 commit ba899d6

File tree

14 files changed

+552
-431
lines changed

14 files changed

+552
-431
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies = [
3737
"colorlog >=6",
3838
"asgiref >=3",
3939
"lxml >=4",
40+
"servestatic >= 3.0.0",
4041
]
4142
dynamic = ["version"]
4243
urls.Changelog = "https://reactpy.dev/docs/about/changelog.html"
@@ -69,7 +70,7 @@ commands = [
6970
'bun run --cwd "src/js/packages/@reactpy/client" build',
7071
'bun install --cwd "src/js/packages/@reactpy/app"',
7172
'bun run --cwd "src/js/packages/@reactpy/app" build',
72-
'python "src/build_scripts/copy_dir.py" "src/js/packages/@reactpy/app/dist" "src/reactpy/static"',
73+
'python "src/build_scripts/copy_dir.py" "src/js/packages/@reactpy/app/dist" "src/reactpy/static" ".*\.js(\.map)?$"',
7374
]
7475
artifacts = []
7576

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"typescript": "^5.7.3"
1212
},
1313
"scripts": {
14-
"build": "bun build \"src/index.html\" --outdir=\"dist\" --minify --sourcemap=\"linked\" --experimental-html --public-path=\"reactpy/static/\"",
14+
"build": "bun build \"src/index.ts\" --outdir=\"dist\" --minify --sourcemap=\"linked\"",
1515
"checkTypes": "tsc --noEmit"
1616
}
1717
}

src/js/packages/@reactpy/app/src/index.html

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { mount } from "@reactpy/client";
1+
export { mountReactPy } from "@reactpy/client";

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { ReactPyClient } from "./client";
33
import { Layout } from "./components";
44
import { MountProps } from "./types";
55

6-
export function mount(props: MountProps) {
6+
export function mountReactPy(props: MountProps) {
77
// WebSocket route for component rendering
88
const wsProtocol = `ws${window.location.protocol === "https:" ? "s" : ""}:`;
9-
let wsOrigin = `${wsProtocol}//${window.location.host}`;
10-
let componentUrl = new URL(`${wsOrigin}/${props.componentPath}`);
9+
const wsOrigin = `${wsProtocol}//${window.location.host}`;
10+
const componentUrl = new URL(`${wsOrigin}/${props.pathPrefix}/`);
1111

1212
// Embed the initial HTTP path into the WebSocket URL
1313
componentUrl.searchParams.append("http_pathname", window.location.pathname);
@@ -20,10 +20,10 @@ export function mount(props: MountProps) {
2020
urls: {
2121
componentUrl: componentUrl,
2222
query: document.location.search,
23-
jsModules: `${window.location.origin}/${props.jsModulesPath}`,
23+
jsModules: `${window.location.origin}/${props.pathPrefix}/modules/`,
2424
},
2525
reconnectOptions: {
26-
startInterval: props.reconnectStartInterval || 750,
26+
interval: props.reconnectInterval || 750,
2727
maxInterval: props.reconnectMaxInterval || 60000,
2828
backoffMultiplier: props.reconnectBackoffMultiplier || 1.25,
2929
maxRetries: props.reconnectMaxRetries || 150,

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ComponentType } from "react";
33
// #### CONNECTION TYPES ####
44

55
export type ReconnectOptions = {
6-
startInterval: number;
6+
interval: number;
77
maxInterval: number;
88
maxRetries: number;
99
backoffMultiplier: number;
@@ -15,7 +15,7 @@ export type CreateReconnectingWebSocketProps = {
1515
onMessage: (message: MessageEvent<any>) => void;
1616
onOpen?: () => void;
1717
onClose?: () => void;
18-
startInterval: number;
18+
interval: number;
1919
maxInterval: number;
2020
maxRetries: number;
2121
backoffMultiplier: number;
@@ -35,9 +35,8 @@ export type GenericReactPyClientProps = {
3535

3636
export type MountProps = {
3737
mountElement: HTMLElement;
38-
componentPath: string;
39-
jsModulesPath: string;
40-
reconnectStartInterval?: number;
38+
pathPrefix: string;
39+
reconnectInterval?: number;
4140
reconnectMaxInterval?: number;
4241
reconnectMaxRetries?: number;
4342
reconnectBackoffMultiplier?: number;

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import log from "./logger";
44
export function createReconnectingWebSocket(
55
props: CreateReconnectingWebSocketProps,
66
) {
7-
const { startInterval, maxInterval, maxRetries, backoffMultiplier } = props;
7+
const { interval, maxInterval, maxRetries, backoffMultiplier } = props;
88
let retries = 0;
9-
let interval = startInterval;
9+
let currentInterval = interval;
1010
let everConnected = false;
1111
const closed = false;
1212
const socket: { current?: WebSocket } = {};
@@ -18,8 +18,8 @@ export function createReconnectingWebSocket(
1818
socket.current = new WebSocket(props.url);
1919
socket.current.onopen = () => {
2020
everConnected = true;
21-
log.info("ReactPy connected!");
22-
interval = startInterval;
21+
log.info("Connected!");
22+
currentInterval = interval;
2323
retries = 0;
2424
if (props.onOpen) {
2525
props.onOpen();
@@ -31,26 +31,28 @@ export function createReconnectingWebSocket(
3131
props.onClose();
3232
}
3333
if (!everConnected) {
34-
log.info("ReactPy failed to connect!");
34+
log.info("Failed to connect!");
3535
return;
3636
}
37-
log.info("ReactPy disconnected!");
37+
log.info("Disconnected!");
3838
if (retries >= maxRetries) {
39-
log.info("ReactPy connection max retries exhausted!");
39+
log.info("Connection max retries exhausted!");
4040
return;
4141
}
4242
log.info(
43-
`ReactPy reconnecting in ${(interval / 1000).toPrecision(4)} seconds...`,
43+
`Reconnecting in ${(currentInterval / 1000).toPrecision(4)} seconds...`,
44+
);
45+
setTimeout(connect, currentInterval);
46+
currentInterval = nextInterval(
47+
currentInterval,
48+
backoffMultiplier,
49+
maxInterval,
4450
);
45-
setTimeout(connect, interval);
46-
interval = nextInterval(interval, backoffMultiplier, maxInterval);
4751
retries++;
4852
};
4953
};
5054

51-
props.readyPromise
52-
.then(() => log.info("Starting ReactPy client..."))
53-
.then(connect);
55+
props.readyPromise.then(() => log.info("Starting client...")).then(connect);
5456

5557
return socket;
5658
}

0 commit comments

Comments
 (0)