reactpy v2.0.0b2
Pre-release
Pre-release
Summary
Welcome to the first public beta release of ReactPy v2, which brings ReactPy Standalone Mode, and ReactPy ASGI Middleware! That's right, ReactPy is now fully compatible with all ASGI frameworks!
You can give this version a try by typing pip install reactpy --pre
.
Here is a quick demo of the new ReactPy Standalone mode:
# FILENAME: example.py
from reactpy import component, html
from reactpy import ReactPy
@component
def ExampleComponent():
return html.div("Hello World")
app = ReactPy(ExampleComponent)
# Now you can run `uvicorn example:app --reload` to start ReactPy!
Here is a quick demo of the new ReactPy Middleware mode (using Starlette for demonstration purposes):
# FILENAME: example.py
from starlette.applications import Starlette
from starlette.routing import Route
from starlette.templating import Jinja2Templates
from reactpy import ReactPyMiddleware
# You will need to follow your framework's guidelines on installing Jinja extensions
# When our new Jinja extension is installed, the `{% component "example.path" %}` tag will be available in any Jinja template.
# The template tag currently accepts a single argument, which is the dotted path to the component.
# For example {% component "my_package.ExampleComponent" %}
templates = Jinja2Templates(
directory="templates",
extensions=["reactpy.jinja.ReactPyTemplateTag"],
)
async def homepage(request):
return templates.TemplateResponse(request, "index.html")
app = ReactPyMiddleware(
Starlette(routes=[Route("/", homepage)]),
# Register components with ReactPy to allow them to be used as a root component in your templates
root_components=["my_package.ExampleComponent"],
)
# Now you can run `uvicorn example:app --reload` to start ReactPy!
Changelog
Added
- Added
reactpy.executors.asgi.ReactPy
that can be used to run ReactPy in standalone mode via ASGI. - Added
reactpy.executors.asgi.ReactPyPyodide
that can be used to run ReactPy in standalone mode via ASGI, but rendered entirely client-sided. - Added
reactpy.executors.asgi.ReactPyMiddleware
that can be used to utilize ReactPy within any ASGI compatible framework. - Added
reactpy.templatetags.Jinja
that can be used alongsideReactPyMiddleware
to embed several ReactPy components into your existing application. This includes the following template tags:{% component %}
,{% pyscript_component %}
, and{% pyscript_setup %}
. - Added
reactpy.pyscript_component
that can be used to embed ReactPy components into your existing application. - Added
uvicorn
andjinja
installation extras (for examplepip install reactpy[jinja]
). - Added support for Python 3.12 and 3.13.
- Added
reactpy.use_async_effect
hook. - Added
shutdown_timeout
parameter to thereactpy.use_async_effect
hook. reactpy.html
will now automatically flatten lists recursively (ex.reactpy.html(["child1", ["child2"]])
)- Added
reactpy.Vdom
primitive interface for creating VDOM dictionaries. - Added type hints to
reactpy.html
attributes. - Added support for nested components in web modules
- Added support for inline JavaScript as event handlers or other attributes that expect a callable via
reactpy.types.InlineJavaScript
Changed
- Substitute client-side usage of
react
withpreact
. - Script elements no longer support behaving like effects. They now strictly behave like plain HTML script elements.
- The
reactpy.html
module has been modified to allow for auto-creation of any HTML nodes. For example, you can create a<data-table>
element by callinghtml.data_table()
. - Change
set_state
comparison method to check equality with==
more consistently. - Add support for rendering
@component
children withinvdom_to_html
. - Renamed the
use_location
hook'ssearch
attribute toquery_string
. - Renamed the
use_location
hook'spathname
attribute topath
. - Renamed
reactpy.config.REACTPY_DEBUG_MODE
toreactpy.config.REACTPY_DEBUG
. @reactpy/client
now exportsReact
andReactDOM
.- ReactPy no longer auto-converts
snake_case
props tocamelCase
. It is now the responsibility of the user to ensure that props are in the correct format. reactpy.utils.reactpy_to_string
will now retain the user's original casing fordata-*
andaria-*
attributes.reactpy.utils.string_to_reactpy
has been upgraded to handle more complex scenarios without causing ReactJS rendering errors.reactpy.core.vdom._CustomVdomDictConstructor
has been moved toreactpy.types.CustomVdomConstructor
.reactpy.core.vdom._EllipsisRepr
has been moved toreactpy.types.EllipsisRepr
.reactpy.types.VdomDictConstructor
has been renamed toreactpy.types.VdomConstructor
.
Removed
- Removed the ability to import
reactpy.html.*
elements directly. You must now callhtml.*
to access the elements. - Removed
reactpy.sample
module. - Removed
reactpy.svg
module. Contents previously withinreactpy.svg.*
can now be accessed viahtml.svg.*
. - Removed
reactpy.html._
function. Usehtml.fragment
instead. - Removed
reactpy.run
. See the documentation for the new method to run ReactPy applications. - Removed
reactpy.backend.*
. See the documentation for the new method to run ReactPy applications. - Removed
reactpy.core.types
module. Usereactpy.types
instead. - Removed
reactpy.utils.html_to_vdom
. Usereactpy.utils.string_to_reactpy
instead. - Removed
reactpy.utils.vdom_to_html
. Usereactpy.utils.reactpy_to_string
instead. - All backend related installation extras (such as
pip install reactpy[starlette]
) have been removed. - Removed deprecated function
module_from_template
. - Removed support for Python 3.9.
- Removed support for async functions within
reactpy.use_effect
hook. Usereactpy.use_async_effect
instead. - Removed
reactpy.vdom
. Usereactpy.Vdom
instead. - Removed
reactpy.core.make_vdom_constructor
. Usereactpy.Vdom
instead. - Removed
reactpy.core.custom_vdom_constructor
. Usereactpy.Vdom
instead.
Fixed
- Fixed a bug where script elements would not render to the DOM as plain text.
- Fixed a bug where the
key
property provided via server-side ReactPy code was failing to propagate to the front-end JavaScript component. - Fixed a bug where
RuntimeError("Hook stack is in an invalid state")
errors would be provided when using a webserver that reuses threads.