Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0dfe999
Add a plugin hook for Vite plugins
FarhanAliRaza Nov 27, 2026
091afa3
Scaffold reflex-components-ui and the rx.ui namespace
FarhanAliRaza Nov 27, 2026
c72d618
Merge PR 4 of the rx.ui plan: Plugin.get_vite_plugins() hook
FarhanAliRaza Nov 27, 2026
d4a909d
Load dynamic-component libraries as chunks of their own
FarhanAliRaza Nov 27, 2026
5dc02bf
Merge PR 1 of the rx.ui plan: load dynamic-component libraries on demand
FarhanAliRaza Nov 27, 2026
7ea1a0f
Format the ESLint config as the repository's formatter does
FarhanAliRaza Nov 27, 2026
f365f87
Merge PR 5 of the rx.ui plan: reflex-components-ui scaffold and rx.ui…
FarhanAliRaza Nov 27, 2026
4ecf2d4
Start a prerendered page's scripts after its first paint
FarhanAliRaza Nov 27, 2026
c05dd41
Document the early click hand-over in the frontend README
FarhanAliRaza Nov 27, 2026
f7e8892
Ship the state runtime and the toaster only to apps that use them
FarhanAliRaza Nov 27, 2026
0bb8a71
Add UIPlugin and rx.ui.box, compiled to a plain div through StyleX
FarhanAliRaza Nov 27, 2026
9ffb744
Merge PR 6 of the rx.ui plan: UIPlugin, StyleX in the build, rx.ui.box
FarhanAliRaza Nov 27, 2026
257e5e0
Remove a duplicated command line from AGENTS.md
FarhanAliRaza Nov 27, 2026
d3b3fc9
Take the early click over right before hydration
FarhanAliRaza Nov 27, 2026
698cb49
Add typed rx.ui styles with lowering and merging
FarhanAliRaza Nov 27, 2026
66d9d3f
Merge PR 8a of the rx.ui plan: typed StyleProps, style lowering and m…
FarhanAliRaza Nov 27, 2026
0cfa6b5
Generate the rx.ui tokens, color scales and themes from Radix Themes
FarhanAliRaza Nov 27, 2026
5b481d2
Merge PR 3 of the rx.ui plan: state runtime and toaster ship only whe…
FarhanAliRaza Nov 27, 2026
035c744
Build the rx.ui test pages with the layer prefix an app uses
FarhanAliRaza Nov 27, 2026
8112e82
Merge PR 7a of the rx.ui plan: tokens, color scales and themes as Sty…
FarhanAliRaza Nov 27, 2026
7ba9da5
Apply the rx.ui theme at the root, add rx.ui.theme and rx.ui.tokens (…
FarhanAliRaza Nov 27, 2026
da98a77
Merge PR 2 of the rx.ui plan: scripts start after first paint on prer…
FarhanAliRaza Nov 27, 2026
c38fb26
Test the rx.ui themes and tokens, and subscribe a bound theme to its …
FarhanAliRaza Nov 27, 2026
795856c
Add the rx.ui parity harness and behaviour contract
FarhanAliRaza Nov 27, 2026
bc1f083
Carry the class of an appearance on a boxless element, and sweep the …
FarhanAliRaza Nov 27, 2026
e9fc4a9
Merge PR 9 of the rx.ui plan: parity harness and behaviour contract
FarhanAliRaza Nov 27, 2026
1fae9d2
Document themes and tokens, regenerate the stubs, and type the tests
FarhanAliRaza Nov 27, 2026
b996372
Read the appearance from the props, and settle the type checks of the…
FarhanAliRaza Nov 27, 2026
aaa0b27
Compile rx.ui styles: merge in Python, emit one StyleX declaration
FarhanAliRaza Nov 27, 2026
93ae32c
Merge PR 8b of the rx.ui plan: style compiler wired into UIComponent,…
FarhanAliRaza Nov 27, 2026
4fa651e
Refuse a Radix theme in UIPlugin, and test selection and a state-boun…
FarhanAliRaza Nov 27, 2026
5127fc7
Type the state-bound page of the shared test app
FarhanAliRaza Nov 27, 2026
b6ccd86
Wait for the hydration commit before the parity harness reads a page
FarhanAliRaza Nov 27, 2026
051ccf1
Merge the style compiler and the parity harness, and join theme class…
FarhanAliRaza Nov 27, 2026
c9dfa02
Merge the parity harness readiness fix: wait for committed hydration
FarhanAliRaza Nov 27, 2026
3b54a6f
Wire color_scheme into UIComponent, and adapt the theme tests to the …
FarhanAliRaza Nov 27, 2026
aab5b83
Test color_scheme and the whole token sweep live on the merged base
FarhanAliRaza Nov 27, 2026
9bf05cc
Document the theme classes without the StyleX runtime, and settle the…
FarhanAliRaza Nov 27, 2026
453dfe1
Merge PR 7b of the rx.ui plan: Theme, rx.ui.theme, rx.ui.tokens, colo…
FarhanAliRaza Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .github/workflows/dispatch_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ on:
description: "reflex-components-sonner"
type: boolean
default: false
reflex_components_ui:
description: "reflex-components-ui"
type: boolean
default: false
reflex_docgen:
description: "reflex-docgen"
type: boolean
Expand Down Expand Up @@ -207,6 +211,7 @@ jobs:
${{ inputs.reflex_components_react_player && 'reflex-components-react-player' || '' }}
${{ inputs.reflex_components_recharts && 'reflex-components-recharts' || '' }}
${{ inputs.reflex_components_sonner && 'reflex-components-sonner' || '' }}
${{ inputs.reflex_components_ui && 'reflex-components-ui' || '' }}
${{ inputs.reflex_docgen && 'reflex-docgen' || '' }}
${{ inputs.reflex_hosting_cli && 'reflex-hosting-cli' || '' }}
${{ inputs.reflex_otel && 'reflex-otel' || '' }}
Expand Down
80 changes: 79 additions & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,83 @@ jobs:
- name: Run Playwright integration tests
env:
REFLEX_REDIS_URL: ${{ matrix.state_manager == 'redis' && 'redis://localhost:6379' || '' }}
run: uv run pytest tests/integration/tests_playwright --reruns 3 -rs -v --maxfail=5 --splits 2 --group ${{ matrix.split_index }}
# The rx.ui parity harness has jobs of its own below: it compares
# pixels, which a rerun must not paper over.
run: uv run pytest tests/integration/tests_playwright --ignore=tests/integration/tests_playwright/test_ui_parity.py --reruns 3 -rs -v --maxfail=5 --splits 2 --group ${{ matrix.split_index }}

# The look of every rx.ui component against the Radix one it replaces:
# pixels, computed styles and accessibility tree, cell by cell.
ui-parity:
needs: changes
if: needs.changes.outputs.run == 'true'
timeout-minutes: 30
runs-on: ubuntu-22.04
env:
UI_PARITY_REPORT: ui-parity-report
# The build and every matrix together, in seconds: the run fails above.
UI_PARITY_BUDGET_SECONDS: "900"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-tags: true
fetch-depth: 0
persist-credentials: false
- uses: ./.github/actions/setup_build_env
with:
python-version: "3.14"
run-uv-sync: true
- name: Install Playwright Chromium
run: uv run playwright install chromium --only-shell
- name: Compare every matrix with Radix Themes
run: uv run pytest tests/integration/tests_playwright/test_ui_parity.py -k "not test_contract" -rs -v
- name: Report the run time
if: always()
run: |
if [ -f "$UI_PARITY_REPORT/timings.json" ]; then
{
echo '### rx.ui parity run time'
echo '```json'
cat "$UI_PARITY_REPORT/timings.json"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload the report
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ui-parity-report
path: ui-parity-report
if-no-files-found: warn

# The behaviour contract of every rx.ui component, and of the Radix one it
# replaces, in each browser engine.
ui-contracts:
needs: changes
if: needs.changes.outputs.run == 'true'
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
engine: [chromium, firefox, webkit]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-tags: true
fetch-depth: 0
persist-credentials: false
- uses: ./.github/actions/setup_build_env
with:
python-version: "3.14"
run-uv-sync: true
- name: Install Playwright ${{ matrix.engine }}
env:
ENGINE: ${{ matrix.engine }}
run: uv run playwright install --with-deps "$ENGINE"
- name: Run every contract in ${{ matrix.engine }}
env:
ENGINE: ${{ matrix.engine }}
run: uv run pytest tests/integration/tests_playwright/test_ui_parity.py --browser "$ENGINE" -k test_contract -rs -v

bun-only-startup:
needs: changes
Expand Down Expand Up @@ -413,6 +489,8 @@ jobs:
reflex-docs-macos,
app-harness,
app-harness-playwright,
ui-parity,
ui-contracts,
bun-only-startup,
]
if: always()
Expand Down
30 changes: 29 additions & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,34 @@ jobs:
if-no-files-found: error
retention-days: 7

ui-js-checks:
# Checks the javascript reflex-components-ui embeds: its lint rules (no
# components, no barrels, StyleX), the type check, the generated files and
# the tests.
needs: changes
if: needs.changes.outputs.run == 'true'
timeout-minutes: 10
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/reflex-components-ui/js
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 22
cache: npm
cache-dependency-path: packages/reflex-components-ui/js/package-lock.json
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm run generate:check
# The tests of the tokens and themes read computed styles in a browser.
- run: npx playwright install --with-deps --only-shell chromium
- run: npm test

unit-tests-macos:
timeout-minutes: 30
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down Expand Up @@ -224,7 +252,7 @@ jobs:
# jobs above directly does not survive: check names follow the matrix and the
# display names, and a job that a filter skips must not block the merge.
unit-tests-gate:
needs: [changes, unit-tests, js-unit-tests, unit-tests-macos]
needs: [changes, unit-tests, js-unit-tests, ui-js-checks, unit-tests-macos]
if: always()
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ reflex.db
.env.*
node_modules
package-lock.json
# ...except the frontend package, which CI installs with `npm ci`.
# ...except the javascript packages, which CI installs with `npm ci`.
!packages/reflex-frontend/package-lock.json
!packages/reflex-components-ui/js/package-lock.json
*.pyi
.pre-commit-config.yaml
.claude/.worktrees
Expand Down
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ uv run reflex-release sync # regenerate th
uv run python scripts/make_pyi.py # regenerate .pyi stubs
uv run pre-commit run --all-files # all pre-commit hooks
npm --prefix packages/reflex-frontend ci && npm --prefix packages/reflex-frontend run check # frontend package: lint, type-check (JSDoc) and unit tests
npm --prefix packages/reflex-components-ui/js ci && npm --prefix packages/reflex-components-ui/js run check # rx.ui javascript: lint, type-check (JSDoc), generated files and unit tests
uv run python scripts/ui_parity.py [component] # rx.ui parity harness: look and behaviour against the Radix components, in Chromium (--all-engines adds Firefox and WebKit)
```

## Layout
Expand Down
68 changes: 68 additions & 0 deletions docs/api-reference/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ class Plugin:
"""Get paths to stylesheets required by the plugin."""
return []

def get_vite_plugins(self, **context) -> Sequence[VitePluginEntry]:
"""Get Vite plugins to add to the generated vite.config.js."""
return []

def register_route(self, **context) -> None:
"""Contribute pages before the app's first compilation."""
pass
Expand Down Expand Up @@ -295,6 +299,70 @@ during collection, while the framework owns the final batch commit. The public
API but are intentionally not dispatched during a staged plugin batch, so an
override cannot make the batch commit partially.

### Adding Vite Plugins

Reflex generates the app's `vite.config.js` and rewrites it on every compile. A
plugin adds a Vite plugin to it by overriding `get_vite_plugins`, which returns
`VitePluginEntry` objects. Each entry carries JavaScript source: the import
statements it needs, and the expression to place in the `plugins` array.

```python
from reflex.plugins import Plugin, VitePluginEntry


class InspectPlugin(Plugin):
def get_frontend_development_dependencies(self, **context):
return ["vite-plugin-inspect"]

def get_vite_plugins(self, **context):
return [
VitePluginEntry(
imports=['import inspect from "vite-plugin-inspect"'],
call="inspect({ build: true })",
)
]
```

This renders as:

```javascript
import inspect from "vite-plugin-inspect";

export default defineConfig((config) => ({
plugins: [
alwaysUseReactDomServerNode(),
inspect({ build: true }),
reactRouter(),
// ...
],
}));
```

- `imports` is a sequence of import statements, one per string, with or without
the closing semicolon. An entry may need several. A statement that several
entries share is written once, so two plugins can import the same name from
the same package; importing one name from two different modules is a syntax
error in the generated file.
- `call` is any JavaScript expression: usually a call, possibly spanning
several lines. It may evaluate to one Vite plugin or to an array of them.
- Module specifiers resolve from `.web`. Import an npm package by name, and a
file the plugin writes with `get_static_assets` by its relative path, such as
`"./my-vite-plugin.js"`.
- Entries are placed ahead of `reactRouter()` (and after React Compiler, when
`react_compiler` is enabled), in the order of the plugins in `rxconfig.py`
and then in the order each plugin returns them. Vite's own `enforce: "pre"`
and `enforce: "post"` still apply within that order.
- A Vite plugin only runs at build time, so declare its npm packages in
`get_frontend_development_dependencies`. Packages returned from
`get_frontend_dependencies` are also bundled into the app.

A malformed entry stops the compile with an `InvalidVitePluginError` that names
the plugin and the entry, for example:

```text
InspectPlugin.get_vite_plugins() returned an invalid entry: entry 0 has 'vite-plugin-inspect' in imports, which is not an import statement.
```

### Looking Up Configured Plugins

Use `rx.plugins.get_plugin(PluginType)` when runtime behavior needs the plugin
Expand Down
3 changes: 2 additions & 1 deletion docs/app/.github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ jobs:
--upgrade-package reflex-components-radix \
--upgrade-package reflex-components-react-player \
--upgrade-package reflex-components-recharts \
--upgrade-package reflex-components-sonner
--upgrade-package reflex-components-sonner \
--upgrade-package reflex-components-ui

- name: Install custom reflex version (if specified)
if: github.event.inputs.reflex_dep
Expand Down
8 changes: 7 additions & 1 deletion docs/library/overlay/toast.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,11 @@ Using the `rx.toast` function require to have a toast provider in your app.
`rx.toast.provider` is a component that provides a context for displaying toasts. It should be placed at the root of your app.

```md alert warning
# In most case you will not need to include this component directly, as it is already included in `rx.app` as the `overlay_component` for displaying connections errors.
# In most case you will not need to include this component directly, as `rx.App` puts one at the root of the app.
```

The toaster is only bundled with an app that sends a toast: a page that calls `rx.toast`, an event handler that refers to it, or an `on_load` toast. An app with state that sends none shows connection errors, and any toast the compiler could not foresee, as plain notices. To bundle the toaster in every case, or to configure it, pass one to the app:

```python
app = rx.App(toaster=rx.toast.provider(position="top-center"))
```
1 change: 1 addition & 0 deletions examples/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ reflex_components_radix.msg = "Examples import Reflex only as `import reflex as
reflex_components_react_player.msg = "Examples import Reflex only as `import reflex as rx`."
reflex_components_recharts.msg = "Examples import Reflex only as `import reflex as rx`."
reflex_components_sonner.msg = "Examples import Reflex only as `import reflex as rx`."
reflex_components_ui.msg = "Examples import Reflex only as `import reflex as rx`."
reflex_docgen.msg = "Examples import Reflex only as `import reflex as rx`."
reflex_otel.msg = "Examples import Reflex only as `import reflex as rx`."
reflex_release.msg = "Examples import Reflex only as `import reflex as rx`."
Expand Down
1 change: 1 addition & 0 deletions news/+lazy-dynamic-libraries.performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Apps that render no dynamic component (a component held in state) no longer build or ship the libraries registered for them, and apps that do fetch each library on first use instead of on every page. Libraries an app registers itself with `rx.bundle_library` always stay loadable through `window.__reflex_load`.
1 change: 1 addition & 0 deletions news/+rx-ui-extra.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the `ui` extra. `pip install 'reflex[ui]'` installs `reflex-components-ui`, a pre-release package of components that compile to plain HTML and static CSS, and exposes it as `rx.ui`. Without the extra, `rx.ui` raises an error that says what to install. The package has no components yet.
3 changes: 3 additions & 0 deletions news/+state-runtime-on-demand.performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
An app without state no longer bundles Socket.io, the cookie library or the code that connects to the backend, and no app bundles the toaster unless it sends a toast: a static page ships about 28 kB less gzipped JavaScript, and an app with state that sends no toast about 8 kB less.

The toaster is bundled when a toast call is compiled into a page, when an event handler refers to `rx.toast`, or when `rx.App` is given a `toaster`. A toast the compiler could not foresee, and a connection error, show as a plain notice in an app with state; pass `toaster=rx.toast.provider()` to `rx.App` to always bundle the toaster.
1 change: 1 addition & 0 deletions news/+ui-plugin.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `rx.plugins.UIPlugin`, which compiles the styles of the `rx.ui` components. It comes with the `ui` extra: `pip install 'reflex[ui]'`.
1 change: 1 addition & 0 deletions news/+vite-plugin-hook.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Plugins can add Vite plugins to the app's `vite.config.js` through the new `Plugin.get_vite_plugins()` hook, which returns `rx.plugins.VitePluginEntry` objects. A malformed entry stops the compile with an error naming the plugin. See [Adding Vite Plugins](https://reflex.dev/docs/api-reference/plugins/#adding-vite-plugins).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`frontend_lazy_bundled_libraries` now defaults to `True`: `window.__reflex` holds React and the Reflex runtime, and gains each other registered library only once it has been loaded. Custom scripts that read a library from `window.__reflex` must first `await window.__reflex_load(["<library>"])`, or the app can set `frontend_lazy_bundled_libraries=False` to keep importing every registered library up front. Dynamic components and `rx.bundle_library` need no change.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop shipping whole libraries to every page for dynamic components. A library registered for dynamic components (such as `@radix-ui/themes`, or one passed to `rx.bundle_library`) is now built as a chunk of its own and fetched the first time a dynamic component needs it, so pages only load the parts of it they use. A blank app's JavaScript drops from about 240 KB to 171 KB gzipped.
1 change: 1 addition & 0 deletions packages/reflex-base/news/+pyi-overwrite-types.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A component class can set `_pyi_overwrite_types` and `_pyi_imports` to give a prop a narrower annotation in its generated `.pyi` stub.
1 change: 1 addition & 0 deletions packages/reflex-base/news/+pyi-ui-subpackage.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The stub generator resolves the `ui` component subpackage to `reflex-components-ui`.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `reflex_base.components.dynamic.is_rendering_dynamic_component()`, which a component can call while it renders to learn that its code will be evaluated in the browser at runtime and skip what depends on the frontend build.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prerendered pages show up sooner: a production page no longer preloads its scripts ahead of the stylesheet it needs to paint, and starts them once it has painted. On a blank app, mobile Lighthouse LCP drops from about 2.9 s to 1.2 s (simulated slow 4G). Hydration starts later by the same design, and the window `load` event no longer waits for it. A click that comes before the page is hydrated starts the scripts right away and is dispatched again once its handler is attached; so does a hidden tab or a browser without paint timing, and a page that paints nothing starts them after one second. Dev mode and pages rendered in the browser are unchanged.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The connection to the backend moved out of `utils/state.js` into `utils/socket.js`, which only the compiled context of an app with state imports, so an app without state bundles neither it nor Socket.io and the cookie library. Every name `$/utils/state` exported is still exported from there.
11 changes: 11 additions & 0 deletions packages/reflex-base/news/+vite-plugin-hook.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
A plugin can add Vite plugins to the generated `vite.config.js` by overriding `Plugin.get_vite_plugins()`, instead of rewriting the file in `pre_compile`. Each `VitePluginEntry` gives the import statements it needs and the expression placed in the `plugins` array, ahead of `reactRouter()`:

```python
def get_vite_plugins(self, **context):
return [
VitePluginEntry(
imports=['import inspect from "vite-plugin-inspect"'],
call="inspect({ build: true })",
)
]
```
Loading
Loading