Skip to content

Conversation

Archmonger
Copy link
Contributor

@Archmonger Archmonger commented Jul 18, 2023

Issues

Solution

Create a ReactPy ASGI application and middleware.

Features of the ASGI application/middleware

  • Gain compatibility with every ASGI framework.
  • Allows ReactPy to be "self contained" if needed (run within any ASGI webserver without a backend).

For example, this is the interface for ReactPy's standalone mode:

from reactpy import component, html
from reactpy.asgi.standalone import ReactPy

@component
def Example():
    return html.div("Hello World")

app = ReactPy(Example)
# Now you can run `uvicorn example:app --reload` to start ReactPy!

Major Changes

  • ReactPy class has been created as the standalone API for ReactPy.
  • ReactPyMiddleware has been created as the version of ReactPy that can wrap other ASGI web frameworks.
  • Added a template tag to use alongside our middleware.
  • @reactpy/client has been rewritten to be more modular. This also helps in preparation for template tags.
  • reactpy.backends.* is removed.

Checklist

Please update this checklist as you complete each item:

  • Tests have been developed for bug fixes or new functionality.
  • The changelog has been updated, if necessary.
  • Documentation has been updated, if necessary.
  • GitHub Issues closed by this PR have been linked.

By submitting this pull request I agree that all contributions comply with this project's open source license(s).

@Archmonger
Copy link
Contributor Author

Archmonger commented Jul 18, 2023

The more I develop this, the more I realize it's unwise to finish this PR until the following issues are closed

This PR is in a 90% finished state, but I will hold off on finishing it for now and refocus on template tags.

@Archmonger Archmonger added the flag-blocked Currently cannot be resolved. label Jul 18, 2023
@Archmonger Archmonger changed the title ASGI Middleware ReactPy ASGI Application & Middleware Jul 18, 2023
@Archmonger
Copy link
Contributor Author

Archmonger commented Jul 20, 2023

@rmorshea I will implement things using starlette for static files now, but ideally I don't want a web framework to be a dependency for us.

I would feel more comfortable using whitenoise as it's a static-file focused library that doesn't have extra stuff. However, this relies on this PR getting merged:

@Archmonger
Copy link
Contributor Author

Archmonger commented Aug 27, 2023

Note to self:
It seems logical to mandate that ReactPy standalone's root component must be a html.html node. By forcing the user to template the whole page, this would eliminate the need for a janky Options(head=...) parameter.

html.html(
    {"lang": "en"},
    html.head(
        ...,
    ),
    html.body(
        ...,
    ),
)

It also seems logical to have ReactPyStandalone and ReactPyMiddleware to be discrete classes.

EDIT: Not realistic since the root object needs to be a component, not VDOM.

@Archmonger Archmonger changed the base branch from main to develop January 31, 2025 23:18
@Archmonger Archmonger marked this pull request as ready for review January 31, 2025 23:20
@Archmonger Archmonger merged commit d906dc8 into reactive-python:develop Feb 1, 2025
17 checks passed
@Archmonger Archmonger deleted the asgi-middleware branch February 1, 2025 02:02
@Archmonger Archmonger mentioned this pull request Feb 23, 2025
4 tasks
Archmonger added a commit that referenced this pull request May 31, 2025
- `ReactPy` class has been created as the standalone API for ReactPy.
- `ReactPyMiddleware` has been created as the version of ReactPy that can wrap other ASGI web frameworks.
- Added a template tag to use alongside our middleware.
- `@reactpy/client` has been rewritten to be more modular.
- `reactpy.backends.*` is removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-major Warrents a major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReactPy ASGI App and Middleware Modify SimpleReactPyClient to not use pre-defined endpoints Improve Reconnecting WS Configurability
1 participant