From ba5219509e20ab6429f1d3a3af5dc2d9bcb6e5f4 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 3 Feb 2025 03:29:04 -0800 Subject: [PATCH 01/18] Sync with reactpy core repo --- .github/workflows/test-python.yml | 2 +- .gitignore | 3 ++- docs/src/about/contributing.md | 2 +- pyproject.toml | 2 +- src/js/src/client.ts | 10 +++++----- src/js/src/types.ts | 1 - src/reactpy_django/checks.py | 6 +++--- src/reactpy_django/forms/components.py | 2 +- src/reactpy_django/javascript_components.py | 2 +- src/reactpy_django/templates/reactpy/component.html | 2 +- tests/test_app/__init__.py | 9 ++++++++- 11 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 0a7ae35a..85d40160 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -76,5 +76,5 @@ jobs: python-version: 3.x - name: Install Python Dependencies run: pip install --upgrade pip hatch uv - - name: Check Python formatting + - name: Run Python type checker run: hatch run python:type_check diff --git a/.gitignore b/.gitignore index e3cbc599..e675e09a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # ReactPy-Django Build Artifacts -src/reactpy_django/static/reactpy_django/client.js +src/reactpy_django/static/reactpy_django/index.js +src/reactpy_django/static/reactpy_django/index.js.map src/reactpy_django/static/reactpy_django/pyscript src/reactpy_django/static/reactpy_django/morphdom diff --git a/docs/src/about/contributing.md b/docs/src/about/contributing.md index b78a9508..06499c3e 100644 --- a/docs/src/about/contributing.md +++ b/docs/src/about/contributing.md @@ -50,7 +50,7 @@ By utilizing `hatch`, the following commands are available to manage the develop The `hatch test` command is a wrapper for `pytest`. Hatch "intercepts" a handful of arguments, which can be previewed by typing `hatch test --help`. - Any additional arguments in the `test` command are directly passed on to pytest. See the [pytest documentation](https://docs.pytest.org/en/stable/reference/reference.html#command-line-flags) for what additional arguments are available. + Any additional arguments in the `test` command are provided directly to pytest. See the [pytest documentation](https://docs.pytest.org/en/stable/reference/reference.html#command-line-flags) for what additional arguments are available. ### Linting and Formatting diff --git a/pyproject.toml b/pyproject.toml index 2354e3a5..8b8c50f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,7 @@ installer = "uv" [[tool.hatch.build.hooks.build-scripts.scripts]] commands = [ "bun install --cwd src/js", - "bun build src/js/src/index.ts --outfile src/reactpy_django/static/reactpy_django/client.js --minify", + 'bun build src/js/src/index.ts --outdir="src/reactpy_django/static/reactpy_django/" --minify --sourcemap=linked', 'cd src/build_scripts && python copy_dir.py "src/js/node_modules/@pyscript/core/dist" "src/reactpy_django/static/reactpy_django/pyscript"', 'cd src/build_scripts && python copy_dir.py "src/js/node_modules/morphdom/dist" "src/reactpy_django/static/reactpy_django/morphdom"', ] diff --git a/src/js/src/client.ts b/src/js/src/client.ts index a856fb3a..1f506f56 100644 --- a/src/js/src/client.ts +++ b/src/js/src/client.ts @@ -19,11 +19,14 @@ export class ReactPyDjangoClient constructor(props: ReactPyDjangoClientProps) { super(); this.urls = props.urls; + this.mountElement = props.mountElement; + this.prerenderElement = props.prerenderElement; + this.offlineElement = props.offlineElement; this.socket = createReconnectingWebSocket({ - readyPromise: this.ready, url: this.urls.componentUrl, - onMessage: async ({ data }) => this.handleIncoming(JSON.parse(data)), + readyPromise: this.ready, ...props.reconnectOptions, + onMessage: async ({ data }) => this.handleIncoming(JSON.parse(data)), onClose: () => { // If offlineElement exists, show it and hide the mountElement/prerenderElement if (this.prerenderElement) { @@ -43,9 +46,6 @@ export class ReactPyDjangoClient } }, }); - this.mountElement = props.mountElement; - this.prerenderElement = props.prerenderElement; - this.offlineElement = props.offlineElement; } sendMessage(message: any): void { diff --git a/src/js/src/types.ts b/src/js/src/types.ts index 1f0e2b23..e3be73d7 100644 --- a/src/js/src/types.ts +++ b/src/js/src/types.ts @@ -7,7 +7,6 @@ export type ReconnectOptions = { export type ReactPyUrls = { componentUrl: URL; - query: string; jsModules: string; }; diff --git a/src/reactpy_django/checks.py b/src/reactpy_django/checks.py index 32f38768..88001c77 100644 --- a/src/reactpy_django/checks.py +++ b/src/reactpy_django/checks.py @@ -62,11 +62,11 @@ def reactpy_warnings(app_configs, **kwargs): ) ) - # Check if reactpy_django/client.js is available - if not find("reactpy_django/client.js"): + # Check if reactpy_django/index.js is available + if not find("reactpy_django/index.js"): warnings.append( Warning( - "ReactPy client.js could not be found within Django static files!", + "ReactPy index.js could not be found within Django static files!", hint="Check all static files related Django settings and INSTALLED_APPS.", id="reactpy_django.W004", ) diff --git a/src/reactpy_django/forms/components.py b/src/reactpy_django/forms/components.py index 9aa99497..a10d5c92 100644 --- a/src/reactpy_django/forms/components.py +++ b/src/reactpy_django/forms/components.py @@ -27,7 +27,7 @@ from reactpy.core.types import VdomDict DjangoForm = export( - module_from_file("reactpy-django", file=Path(__file__).parent.parent / "static" / "reactpy_django" / "client.js"), + module_from_file("reactpy-django", file=Path(__file__).parent.parent / "static" / "reactpy_django" / "index.js"), ("DjangoForm"), ) diff --git a/src/reactpy_django/javascript_components.py b/src/reactpy_django/javascript_components.py index eb4fa035..80072211 100644 --- a/src/reactpy_django/javascript_components.py +++ b/src/reactpy_django/javascript_components.py @@ -5,6 +5,6 @@ from reactpy import web HttpRequest = web.export( - web.module_from_file("reactpy-django", file=Path(__file__).parent / "static" / "reactpy_django" / "client.js"), + web.module_from_file("reactpy-django", file=Path(__file__).parent / "static" / "reactpy_django" / "index.js"), ("HttpRequest"), ) diff --git a/src/reactpy_django/templates/reactpy/component.html b/src/reactpy_django/templates/reactpy/component.html index 7e3746f5..b7c9d705 100644 --- a/src/reactpy_django/templates/reactpy/component.html +++ b/src/reactpy_django/templates/reactpy/component.html @@ -10,7 +10,7 @@ {% if reactpy_prerender_html %}
{{reactpy_prerender_html|safe}}
{% endif %} {% if reactpy_offline_html %}{% endif %}