Releases: reactive-python/reactpy
@reactpy/client v1.0.2
- Fix dependency path for
event-to-object - Re-export React/ReactDOM within the client
- Client will now try to use
reactfrom the user's environment, and will fallback to ReactPy's internal variant if not found. - Move VDOM
keyinto the main props mapping - Allow for all ReactPy and ReactJS components to be arbitrarily inserted into each other
This GitHub release was deleted & re-created to fix the NPM publishing workflow.
reactpy v2.0.0b8
Summary
Welcome to the latest beta release of ReactPy v2, which brings ReactPy Standalone and ReactPy Middleware!
Here is a quick demo of the new ReactPy Standalone:
# FILENAME: example.py
# Install dependencies: pip install reactpy[asgi]==2.0.0b8 uvicorn[standard]
from reactpy import component, html
from reactpy.executors.asgi 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 (using FastAPI for demonstration purposes):
# FILENAME: example.py
# Install dependencies: pip install reactpy[asgi, jinja]==2.0.0b8 uvicorn[standard] starlette
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from reactpy import component, html
from reactpy.executors.asgi import ReactPyMiddleware
# Follow your framework's documentation on installing Jinja extensions. You will need to install
# ReactPy's Jinja extension to use ReactPy's `{% component "example.path" %}` template tag.
fastapi_app = FastAPI()
fastapi_app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates", extensions=["reactpy.templatetags.ReactPyJinja"])
@fastapi_app.get("/", response_class=HTMLResponse)
async def homepage(request: Request):
# Note: Use ReactPy's template tag in any Jinja template to render a component.
return templates.TemplateResponse(request, "index.html")
@component # Note: Component is declared in this file to simplify the demo.
def HelloWorld():
return html.div("Hello, World!")
# Register components with ReactPy to allow them to be used in your templates
app = ReactPyMiddleware(fastapi_app, root_components=["example.HelloWorld"])
# Now you can run `uvicorn example:app --reload` to start ReactPy!<!-- FILENAME: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example Webpage</title>
</head>
<body>
<h1>Welcome to the Example Webpage</h1>
{% component "example.HelloWorld" %}
</body>
</html>Changelog
Added
- Added support for Python 3.12, 3.13, and 3.14.
- Added type hints to
reactpy.htmlattributes. - 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 - Event functions can now call
event.preventDefault()andevent.stopPropagation()methods directly on the event data object, rather than using the@eventdecorator. - Event data now supports accessing properties via dot notation (ex.
event.target.value). - Added
reactpy.types.Eventto provide type hints for the standarddatafunction argument (for exampledef on_click(event: Event): ...). - Added
asgiandjinjainstallation extras (for examplepip install reactpy[asgi, jinja]). - Added
reactpy.executors.asgi.ReactPythat can be used to run ReactPy in standalone mode via ASGI. - Added
reactpy.executors.asgi.ReactPyCsrthat can be used to run ReactPy in standalone mode via ASGI, but rendered entirely client-sided. - Added
reactpy.executors.asgi.ReactPyMiddlewarethat can be used to utilize ReactPy within any ASGI compatible framework. - Added
reactpy.templatetags.ReactPyJinjathat can be used alongsideReactPyMiddlewareto embed several ReactPy components into your existing application. This includes the following template tags:{% component %},{% pyscript_component %}, and{% pyscript_setup %}. - Added
reactpy.pyscript_componentthat can be used to embed ReactPy components into your existing application. - Added
reactpy.use_async_effecthook. - Added
reactpy.Vdomprimitive interface for creating VDOM dictionaries. - Added
reactpy.reactjs.component_from_fileto import ReactJS components from a file. - Added
reactpy.reactjs.component_from_urlto import ReactJS components from a URL. - Added
reactpy.reactjs.component_from_stringto import ReactJS components from a string. - Added
reactpy.reactjs.component_from_npmto import ReactJS components from NPM. - Added
reactpy.has a shorthand alias forreactpy.html.
Changed
- The
keyattribute is now stored withinattributesin the VDOM spec. - Substitute client-side usage of
reactwithpreact. - Script elements no longer support behaving like effects. They now strictly behave like plain HTML scripts.
- The
reactpy.htmlmodule 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_statecomparison method to check equality with==more consistently. - Add support for rendering
@componentchildren withinvdom_to_html. - Renamed the
use_locationhook'ssearchattribute toquery_string. - Renamed the
use_locationhook'spathnameattribute topath. - Renamed
reactpy.config.REACTPY_DEBUG_MODEtoreactpy.config.REACTPY_DEBUG. - ReactPy no longer auto-converts
snake_caseprops tocamelCase. It is now the responsibility of the user to ensure that props are in the correct format. - Rewrite the
event-to-objectpackage to be more robust at handling properties on events. - Custom JS components will now automatically assume you are using ReactJS in the absence of a
bindfunction. - Refactor layout rendering logic to improve readability and maintainability.
@reactpy/clientnow exportsReactandReactDOM.reactpy.htmlwill now automatically flatten lists recursively (ex.reactpy.html(["child1", ["child2"]]))reactpy.utils.reactpy_to_stringwill now retain the user's original casing fordata-*andaria-*attributes.reactpy.utils.string_to_reactpyhas been upgraded to handle more complex scenarios without causing ReactJS rendering errors.reactpy.core.vdom._CustomVdomDictConstructorhas been moved toreactpy.types.CustomVdomConstructor.reactpy.core.vdom._EllipsisReprhas been moved toreactpy.types.EllipsisRepr.reactpy.types.VdomDictConstructorhas been renamed toreactpy.types.VdomConstructor.REACTPY_ASYNC_RENDERINGcan now de-duplicate and cascade renders where necessary.REACTPY_ASYNC_RENDERINGis now defaulted toTruefor up to 40x performance improvements in environments with high concurrency.
Deprecated
reactpy.web.module_from_fileis deprecated. Usereactpy.reactjs.component_from_fileinstead.reactpy.web.module_from_urlis deprecated. Usereactpy.reactjs.component_from_urlinstead.reactpy.web.module_from_stringis deprecated. Usereactpy.reactjs.component_from_stringinstead.reactpy.web.exportis deprecated. Usereactpy.reactjs.component_from_*instead.reactpy.web.*is deprecated. Usereactpy.reactjs.*instead.
Removed
- Removed support for Python 3.9 and 3.10.
- Removed the ability to import
reactpy.html.*elements directly. You must now callhtml.*to access the elements. - Removed backend specific installation extras (such as
pip install reactpy[starlette]). - Removed support for async functions within
reactpy.use_effecthook. Usereactpy.use_async_effectinstead. - Removed deprecated function
module_from_template. - Removed deprecated exception type
reactpy.core.serve.Stop. - Removed deprecated component
reactpy.widgets.hotswap. - Removed
reactpy.samplemodule. - Removed
reactpy.svgmodule. Contents previously withinreactpy.svg.*can now be accessed viareactpy.html.svg.*. - Removed
reactpy.html._function. Usereactpy.html(...)orreactpy.html.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.typesmodule. Usereactpy.typesinstead. - Removed
reactpy.utils.html_to_vdom. Usereactpy.utils.string_to_reactpyinstead. - Removed
reactpy.utils.vdom_to_html. Usereactpy.utils.reactpy_to_stringinstead. - Removed
reactpy.vdom. Usereactpy.Vdominstead. - Removed
reactpy.core.make_vdom_constructor. Usereactpy.Vdominstead. - Removed
reactpy.core.custom_vdom_constructor. Usereactpy.Vdominstead. - Removed
reactpy.Layouttop-level re-export. Usereactpy.core.layout.Layoutinstead. - Removed
reactpy.types.LayoutType. Usereactpy.types.BaseLayoutinstead. - Removed
reactpy.types.ContextProviderType. Usereactpy.types.ContextProviderinstead. - Removed
reactpy.core.hooks._ContextProvider. Usereactpy.types.ContextProviderinstead. - Removed
reactpy.web.utils. Usereactpy.reactjs.utilsinstead.
Fixed
- Fixed a bug where script elements would not render to the DOM as plain text.
- Fixed a bug where the
keyproperty provided within server-side ReactPy code was failing to propagate to the front-end JavaScript components. - Fixed a bug where
RuntimeError("Hook stack is in an invalid state")errors could be generated when using a webserver that reuses threads. - Allow for ReactPy and ReactJS components to be arbitrarily inserted onto the page with any possible hierarchy.
reactpy v2.0.0b7
All changes from v2.0.0b6 with a few additions:
- JavaScript components will now automagically use ReactPy's internal version of ReactJS, even if the user forgot to call
import_reactjswithinhtml.head(...). As a result, this adds a few improvements:- Components from
component_from_npmcan now piggy-back on ReactPy's internal ReactJS export, which can prevent bugs caused by ReactJS version mismatches. - Components from
component_from_fileandcomponent_from_stringno longer need to be compiled/built by the user (withvite,webpack,rollup, etc) if they are restricted to using the following imports:react,react-dom,react-dom/client, andreact/jsx-runtime.
- Components from
- Changes to test suite, fixtures, and tooling to allow pytest to run in parallel mode (via
hatch test --parallel). This reduces test suite runtime from ~150 seconds to ~20 seconds. - Fix bug where ReactJS components from
component_from_npmcould generate aReactDOM.createRoot was called on existing rootwarning. - Move
reactpy.pyscriptcode intoreactpy.executors.pyscript
reactpy v2.0.0b6
All changes from v2.0.0b5 with a few additions:
- Fix
HOOK_STACKerrors - Remove
keyattribute from VDOM spec (Fix #1284) - Add
reactpy.html(...)shorthand notation for HTML fragments. - Add
reactpy.hshorthand alias forreactpy.html. - Add
reactpy.reactjs.component_from_npm - Deprecate
reactpy.web.* - Move
component_from_*functions intoreactpy.reactjs.* - Allow for all ReactPy and ReactJS components to be arbitrarily inserted into each other (Fix #1262)
reactpy v2.0.0b5
All changes from v2.0.0b4 with a few additions:
- Bump minimum Python version to 3.11
- Support Python 3.14
- Better error message if ASGI dependencies are missing
- Removed
reactpy.types.ContextProviderTypetop-level export. Usereactpy.types.ContextProviderinstead. - Removed
reactpy.types.LayoutTypetop-level export. Usereactpy.types.BaseLayoutinstead. - No longer require a package
namewithinreactjs_component_from_* - Remove
pipdependency - Convert
orjsoninto an ASGI only dependency - Fix
@reactpy/client's dependency path forevent-to-object - Fix #1001 (Create a better custom JS interface)
- Fix #624 (Refactor layout rendering)
- Fix #1198 (use_effect's unmount method is not always called with dynamically rendered children)
- Fix #1201 (de-duplicate async renders)
event-to-object v1.0.1
Add warning if user provided input was not a JSON serializable root object. These non-serializable values are now passed through as-is.
@reactpy/client v1.0.1
- Fix error when a user provided JavaScript component transmits event data that isn't JSON structured.
- Re-export
preactwithin top-level module to assist with version synchronization.
reactpy v2.0.0b4
All changes from v2.0.0b3 with a few additions:
- Improve type hints on
reactjs_component_from_* - Remove
jsonpointerdependency use_effectwill now generate an exception if attempting to use an async function. Useuse_async_effectinstead- Remove deprecated
Stopexception type - Remove deprecated
hotswapfunction - Remove top-level export of
reactpy.Layout. Usereactpy.core.layout.Layoutinstead.
event-to-object v1.0.0
Complete re-write to add more robust translation of events to plain JSON objects.
@reactpy/client v1.0.0
Complete re-write to support ReactPy v2.