Releases: reflex-dev/reflex
v0.7.0
Breaking Changes
Python 3.9 support is no longer supported.
Computed Vars are now cache=True
by default
Explicitly set cache=False
on Computed Vars that should be updated after every
event, which was the previous default behavior.
The dependency tracking analysis for Computed Vars has been improved to support
async Computed Vars, so there is a possibility for unanticipated behavior change
around tracking dependencies. Please report any bugs encountered in this area.
Previously "CallableVar" shims need to be explicitly called
rx.upload_file
->rx.upload_file()
rx.selected_files
->rx.selected_files()
rx.clear_selected_files
->rx.clear_selected_files()
rx.set_color_mode
->rx.set_color_mode()
Deprecation Removals
Usage of these features prior to 0.7.0 printed a deprecation warning, now they will result in an error.
-
rx.chakra
is removed, useimport reflex_chakra as rc
instead. -
rx.background
is removed, userx.event(background=True)
instead. -
rx.Component._create_event_chain
is removed, userx.EventChain.create
instead. -
external
prop forrx.redirect
is removed. -
Unannotated event handler arguments will now raise
MissingAnnotationError
. -
Many internal exceptions were renamed to add a trailing
Error
suffix if that was missing. -
rx._x.asset
is removed, userx.asset
instead. -
Passing a
str
argument torx.utils.console.set_log_level
will now raiseTypeError
. -
Removals from
rx.utils.exec
:is_frontend_only
->rx.config.environment.REFLEX_FRONTEND_ONLY.get()
is_backend_only
->rx.config.environment.REFLEX_BACKEND_ONLY.get()
should_skip_compile
->rx.config.environment.REFLEX_SKIP_COMPILE.get()
-
rx.utils.format.format_event_chain
is removed, usestr(rx.Var.create(chain))
instead. -
_var_is_local
and_var_is_string
removed fromrx.Var.create
. -
Computed Vars without a return type annotation will raise
UntypedComputedVarError
. -
removing deprecated features for 0.7.0 and removing py3.9 support by @Lendemor in #4586
rx.App
fields for internal use now have a _
prefix
New Features
reflex rename
A new command to rename an app.
- [ENG-1796]
reflex rename
- B by @ElijahAhianyo in #4668
rx.var
now supports async
functions
An rx.var
computed var can now wrap an async function, which can access
arbitrary state via get_state
and var values via get_var_value
.
Dependency tracking across states is supported, but there may be edge cases in
the new implementation that prevent depedencies from being automatically
identified. You can pass explicit dependencies to the deps
argument, and can
add dependencies at runtime via cls.computed_vars[var_name].add_dependency
.
For best results, pass a globally imported state class to get_state
and assign
the return value to a local variable in the function.
"Built with Reflex" badge
To raise awareness of Reflex, a sticky "Built with Reflex" badge is added to the
lower right corner of each page.
For subscribers of Reflex Cloud, this badge can be disabled by setting
show_built_with_reflex=False
in rxconfig.py
or SHOW_BUILT_WITH_REFLEX=0
in
the environment.
For more information see: https://reflex.dev/docs/hosting/reflex-branding/
- Add a sticky Built with Reflex badge by @Lendemor in #4584
- Sticky tweaks: only show in prod mode by @masenf in #4789
Improvements
Support For Dynamic Icon name
Previously the recommendation was to use rx.match
to map icons, because the
icon name itself could not be a Var.
With rx.dynamic_icon
, the name can now be a Var, but performance may be
affected by dynamic loading.
Support for Specifying Custom App Module
A new config knob is added to rxconfig.py
, to load the app from a module other than the default.
config = rx.Config(
app_name="my_app",
app_module_import="some_package.my_actual_app_module",
)
The app module should be importable by name with the current PYTHONPATH
/ sys.path
, and contain an app
attribute.
- [ENG-4134]Allow specifying custom app module in rxconfig by @ElijahAhianyo in #4556
Display Warning for Frontend/Backend Version Mismatch
When the frontend and backend versions do not match, a warning is displayed in the console.
- check frontend version on connect by @adhami3310 in #4611
- return websocket protocol when asked by @adhami3310 in #4683
- fix subprotocol for granian by @adhami3310 in #4698
Typing
- improve type support for .get_state by @adhami3310 in #4623
- cast return_expr to Var all the time by @adhami3310 in #4649
- make object var handle all mapping instead of just dict by @adhami3310 in #4602
- add more type annotations through the code by @Lendemor in #4401
- improve var create typing by @adhami3310 in #4701
- improve var base typing by @adhami3310 in #4718
- improve rx.Field ObjectVar typing for sqlalchemy and dataclasses by @benedikt-bartscher in #4728
- Add ComputedVar overloads for BASE_TYPE, SQLA_TYPE, and DATACLASS_TYPE by @masenf in #4777
- Ensure EventCallback exposes EventActionsMixin properties by @masenf in #4772
- make computed var generic over mapping by @adhami3310 in #4762
- remove base_state from event types by @adhami3310 in #4740
Recharts
- [ENG-4406] cell component wrapper by @LineIndent in #4670
- Fix recharts min width/height by @adhami3310 in #4672
- pie chart type annotation fix by @LineIndent in #4681
Avoid Leaked Websocket connections
- disable react strict mode for event loop by @adhami3310 in #4720
Miscellaneous
- make that one line better by @adhami3310 in #4610
- EventChain.create accepts arbitrary kwargs by @masenf in #4609
- Skip saving page components when skipping compile output by @masenf in #4653
- Allow deploy with project name and app id by @ElijahAhianyo in #4550
- Remove token check in reflex deploy by @ElijahAhianyo in #4640
- [ENG-4444] move states out of .web by @adhami3310 in #4689
- improve error message for failed compile_state by @adhami3310 in #4702
- assert that .render returns jsonable values by @adhami3310 in #4708
- fix tag render to be recursive by @adhami3310 in #4714
- Handle python
range
passed to rx.Var.create by @masenf in #4716 - var_data fixes with hooks values by @adhami3310 in #4717
- implement a global var cache by @adhami3310 in #4691
- add evaluate time to the progress counter by @adhami3310 in #4722
- better computed var static deps by @benedikt-bartscher in #4729
- provide plotly subpackages by @adhami3310 in #4776
- Copy/update assets on compile by @masenf in #4765
- use getattr when given str in getitem by @adhami3310 in #4761
- Resolve custom component version dynamically by @masenf in #4759
setuptools-scm
support for custom component publishing
- throw error if computed var has args by @Lendemor in #4753
- move id to trigger instead of root by @adhami3310 in #4752
Bug Fixes
- [ENG-4351] Add mapping for lucide icons by @masenf in #4622
- small fix for color_mode_button by @Lendemor in #4634
- [ENG-4383] Handle special float values on frontend by @masenf in #4638
- put import at the top of dynamic component evaluation by @adhami3310 in #4632
- fix boolean to boolen comparisons by @adhami3310 in #4620
- don't need node when --backend_only is used by @Lendemor in #4641
- check for dict passed as children for component by @Lendemor in #4656
- attempt to fix usage when volta is installing node by @Lendemor in #4664
- reflex export environment should default to prod by @adhami3310 in #4673
- refactor client state to restore prior API by @adhami3310 in #4674
- Fix setting default color mode in dev mode by @masenf in https://github.co...
v0.6.8
New Features
New API: rx.EventChain.create
This new interface makes it easier to transform EventType
(EventHandler
, EventSpec
, and lambda
- as accepted by component event triggers) into EventChain
to be rendered in hook calls or rx.call_script
/ rx.call_function
invocations.
New API: BaseState.get_var_value
Similar to get_state
, this API provides access to a Var defined in another state. If the value is mutable, changing it will be reflected in the other state. This API is intended for use with ComponentState
implementations that want to "borrow" data from another state.
Show Example Code
from typing import ClassVar
import reflex as rx
class MyState(rx.State):
data: list[dict] = []
class Appender(rx.ComponentState):
_data: ClassVar[rx.Var]
async def add_value(self, form_data: dict):
(await self.get_var_value(self._data)).append(form_data)
@classmethod
def get_component(cls, data: rx.Var[list[dict]]) -> rx.Component:
cls._data = data
return rx.card(
rx.form(
rx.vstack(
rx.input(placeholder="Name", name="name", autofocus=True),
rx.input(placeholder="Email", name="email"),
rx.button("Submit", type="submit"),
),
reset_on_submit=True,
on_submit=cls.add_value,
),
)
appender = Appender.create
def index() -> rx.Component:
return rx.vstack(
rx.foreach(
MyState.data,
lambda d: rx.text(d.to_string()),
),
appender(data=MyState.data),
)
app = rx.App()
app.add_page(index)
Improvements
Add .endswith()
var operation for strings
Simpler API for rx._x.client_state
Use client state vars anywhere in the tree instead of having to include them and use them separately.
- improve client state by @adhami3310 in #4597
Support Recursive UI elements with @rx.memo
See example code in PR. This allows the rendering of trees and other self-referential structures using rx.foreach
.
- fix recursive UI by @adhami3310 in #4599
Performance
- Minor performance improvements for state getattribute and setattr by @benedikt-bartscher in #4543
- improve dynamic route vars, no need to compute deps by @benedikt-bartscher in #4551
Miscellaneous
- fix health check and skip not needed tasks by @Lendemor in #4563
- [ENG-4083] Track internal changes in dataclass instances by @masenf in #4558
- use position in vardata to mark internal hooks by @Lendemor in #4549
- Enable automatic retry on redis errors by @masenf in #4595
Bug Fixes
- Add
expire_on_commit=False
for async sessions by @masenf in #4582 - Do not allow call_function
callback
argument to be added afterwards by @masenf in #4552 - [ENG-2157] [Refix] Allow
rx.download
to resolverx.get_upload_url
by @masenf in #4470 - fixes #4578 - correct the way dim_props created by @KanvaBhatia in #4587
- unbreak link _hover by @masenf in #4537
- [ENG-4255] Code blocks lead to redefined const in web page by @masenf in #4598
Version Bumps
- chore: update sonner (toast) by @JonZeolla in #4572
- Upgrade Lucide to version 0.469.0 by @celsiusnarhwal in #4571
- poetry 2.0.0 compatibility by @masenf in #4593
Documentation
Other Changes
- add codespell to pre-commit by @Lendemor in #4559
- autodetect print/breakpoints by @Lendemor in #4581
- HOS-400: adding support for config by @Kastier1 in #4540
- Add deprecation message for non-cached var by @masenf in #4591
- test_lifespan: stop periodic events by @masenf in #4600
- Use older python versions for macos actions by @masenf in #4601
New Contributors
- @5quinque made their first contribution in #4577
- @JonZeolla made their first contribution in #4572
- @celsiusnarhwal made their first contribution in #4571
- @KanvaBhatia made their first contribution in #4587
Full Changelog: v0.6.7...v0.6.8
v0.6.7
Deprecations
app.add_custom_404_page
is deprecated -- useapp.add_page(..., route="/404")
instead.external
prop ofrx.redirect
is renamed tois_external
for consistency.- Unify
is_external
prop inrx.redirect
andrx.link
by @ElijahAhianyo in #4389
- Unify
New Features
async_db_url
and rx.asession
Builtin support for async database operations using sqlmodel. Proper usage requires the following:
- Install
greenlet
for sqlalchemy to use async operations. - Install an appropriate async-capable database driver (aiosqlite, pyscopg)
- Set
ASYNC_DB_URL
in the environment that references the async db driver. This should point to the same database as specified inDB_URL
, which should still be set for handling alembic migrations and for use in computed vars, etc. - Use
async with rx.asession() as asession
-- await most operations on the asession.
Async DB operations are preferred in event handlers to avoid blocking other users on the server.
Var Operations for datetime
values
[Wrapping React] new deps
and position
fields in VarData
This allows for customization and control of where hooks are rendered relative to other hooks and memoized event handlers. Deps allows for specification of vars that memoized event handlers depend on.
Improvements
More Efficient Database Connection Pooling
Each time rx.session
was used, it was creating a new pool and not reusing connections.
Linting
- enable RUF rules by @Lendemor in #4465
- enable FURB rules by @Lendemor in #4466
- add ERA rules to detect commented out code by @Lendemor in #4472
- enable C4 rule by @Lendemor in #4536
- enable PTH rule by @Lendemor in #4476
- enable PERF rules by @Lendemor in #4469
- style: prefer type() over class by @benedikt-bartscher in #4512
Performance
- minor pickle improvement by @benedikt-bartscher in #4499
- Avoid double JSON encode/decode for socket.io by @masenf in #4449
- simplify redis code, less redis calls by @benedikt-bartscher in #4456
Miscellaneous
- Avoid
set_log_level
foot gun by @masenf in #4422 - [HOS-333] Send a "reload" message to the frontend after state expiry by @masenf in #4442
- enable css props via wrapperStyle for recharts components by @Lendemor in #4447
- add default value for text area by @Lendemor in #4462
- add
__repr__
method to MutableProxy by @benedikt-bartscher in #4506 - [ENG-4135]Default
rx.link
href to#
sounderline
prop works by @ElijahAhianyo in #4509 - raise StateSerializationError if the state cannot be serialized by @benedikt-bartscher in #4453
- disable polling by @benedikt-bartscher in #4441
- deprecate add_custom_404_page by @Lendemor in #4505
- [ENG-4100]Throw warnings when Redis lock is held for more than the allowed threshold by @ElijahAhianyo in #4522
- Wrap Checkbox component in Context Menu (partial fix for #4262) by @vydpnguyen in #4479
- Include step attribute in input by @Joodith in #4073
- improve StateManagerRedis error message by @benedikt-bartscher in #4444
Bug Fixes
- [ENG-4137] Handle generic alias passing inspect.isclass check by @masenf in #4427
- fix mutable default in EventNamespace by @Lendemor in #4420
- fix: state size was not checked for dill by @benedikt-bartscher in #4431
- allow for 'go.Figure | None' annotation in State by @Lendemor in #4426
- rx.upload must include _var_data from props by @masenf in #4463
- fix: multiple mismatched-type-assignment fixes by @benedikt-bartscher in #4482
- fix: migrate is_backend_only (deprecated) to EnvironmentVariables by @benedikt-bartscher in #4495
- Fix REFLEX_COMPILE_PROCESSES=0 by @masenf in #4523
- client_state: create Var from value when pushing from backend by @masenf in #4474
- fix: handle default_factory in get_attribute_access_type by @benedikt-bartscher in #4517
- [ENG-4165] Consider default and default_factory for state vars by @masenf in #4510
- Fix upload cancellation by @masenf in #4527
- [ENG-4153]Use empty string for None values in
rx.input
andrx.el.input
by @ElijahAhianyo in #4521 - [ENG-3583] Respect cors_allowed_origins for backend HTTP requests by @masenf in #4533
Documentation
- Add production-one-port example by @masenf in #4489
- add issues templates by @Lendemor in #4455
- [HOS-466]Fix deploy help text by @ElijahAhianyo in #4508
Version Bumps
Other Changes
- Remove invitation code logic from reflex logoutv2 by @ElijahAhianyo in #4433
- test dynamic route flakiness (can't reproduce locally) by @benedikt-bartscher in #4496
- add test for color mode (initial and toggle) by @Lendemor in #4467
- Support python 3.13 by @Lendemor in #4206
- bump CI runners to
macos-latest
by @masenf in #4526 - raise_console_error during integration tests by @masenf in #4535
New Contributors
- @vydpnguyen made their first contribution in #4479
- @Joodith made their first contribution in #4073
Full Changelog: v0.6.6.post3...v0.6.7
v0.6.6.post3
fix non-interactive flag in deploy command by @Lendemor in #4498
Full Changelog: v0.6.6.post2...v0.6.6.post3
v0.6.6.post2
Fixup stray loginv2
command in help text
This should have been removed in 0.6.6.post1, but it was missed
Bump reflex-hosting-cli
requirement to 0.1.29
Full Changelog: v0.6.6.post1...v0.6.6.post2
v0.6.6.post1
Update CLI for Reflex Cloud hosting
- remove v2 commands (#4478)
- [HOS-373][HOS-372]Logout should not open the browser (#4475)
- [ENG-4149] require login to deploy named templates (#4450)
Full Changelog: v0.6.6...v0.6.6.post1
v0.6.6
New Features
.temporal
event action drops events when backend is not connected
New "performance mode" options
Allow disabling or modifying various guardrails and checks performed by reflex.
- implement performance mode for existing state size check by @benedikt-bartscher in #4392
Builtin support for existing pydantic v1 and v2 models
State vars can now be typed as pydantic models, with support for modification tracking.
rx.asset
promoted to non-experimental
TBD: docs for new API
- rx._x.asset improvements by @benedikt-bartscher in #3624
Improvements
Streamlined reflex init
workflow
- [GTM-836]Rework Init workflow by @ElijahAhianyo in #4377
Other Improvements
- export Color and ImportDict in top-level namespace by @masenf in #4352
- redesign error boundary screen by @adhami3310 in #4329
- add typing to function vars by @adhami3310 in #4372
- Add template name to reflex init success msg by @ElijahAhianyo in #4349
- fix: do not allow instantiation of State mixins by @benedikt-bartscher in #4347
- add typed dict type checking by @adhami3310 in #4340
- Add datetime to moment by @Alek99 in #4381
- remove deprecation for drawer events by @Lendemor in #4415
- allow to disable checking for the latest package version via env by @benedikt-bartscher in #4407
- Allow bound method as event handler by @benedikt-bartscher in #4348
- enable css props via wrapperStyle for recharts components by @Lendemor in #4447
Bug Fixes
- fix upload argspec being missing by @adhami3310 in #4335
- Only pass Model.fields when casting event args by @masenf in #4356
- Path change after Astral 0.5.0 update by @1Codev in #4336
- [ENG-4098] Deconfuse key/value of State.get_value / dict / get_delta by @masenf in #4371
- fix noSSRComponent imports by @Lendemor in #4386
- fix: Failed to CreateArtifact by @benedikt-bartscher in #4339
- make list suggestions work in rx.input by @Lendemor in #4391
- Don't skip serialization when Var is callable by @masenf in #4399
- ignore rxconfig not in cwd by @adhami3310 in #4398
- fix appearance broken by #3812 by @Lendemor in #4403
- [ENG-4130] Disable typer/rich integration appropriately by @masenf in #4412
- [HOS-313] state.js: when a routing error occurs, delete it by @masenf in #4410
- fix for event handlers in py3.9 by @Lendemor in #4416
- Handle Var passed to
rx.toast
by @masenf in #4405 - allow for 'go.Figure | None' annotation in State by @Lendemor in #4426
- fix mutable default in EventNamespace by @Lendemor in #4420
- [ENG-4137] Handle generic alias passing inspect.isclass check by @masenf in #4427
- [HOS-333] Send a "reload" message to the frontend after state expiry by @masenf in #4442
- rx.upload must include _var_data from props by @masenf in #4463
Version Bumps
- Bump reflex-hosting-cli dep to 0.1.15 for v2 by @masenf in #4355
- Temporarily downpin @radix-ui/themes <3.1.5 by @masenf in #4370
- require typing_extensions >= 4.6.0 by @masenf in #4373
- update cli version by @Kastier1 in #4394
- [maintenance] bump some packages versions by @Lendemor in #4385
- [ENG-4080]Downgrade syntax highlighter to fix
wrapLongLines
issue by @ElijahAhianyo in #4368 - Simon/hosting cli upgrades by @Kastier1 in #4417
Other Changes
- Update bug_report.md by @Alek99 in #4382
- add debug statement to evaluate page by @adhami3310 in #4396
- Remove invitation code logic from reflex logoutv2 @ElijahAhianyo in #4433
New Contributors
Full Changelog: v0.6.5...v0.6.6
v0.6.5
Known Issues
- #4384 Setting the default
appearance
prop inrx.theme
is no longer working
Breaking Changes
rx.App
is now a dataclass that does not accept additional kwargs. Any unrecognized kwargs passed torx.App
will now raise an exception.- Event handlers that accept annotated
rx.Base
subclasses as arguments will receive an instance of the annotated class instead of a regulardict
New Features
New rx.get_state
interface
Support custom bunfig.toml
New Hosting Service CLI
Improvements
Better Typing Support
- add type validation for state setattr by @adhami3310 in #4265
- handle none case in state setattr by @adhami3310 in #4301
- use better typing for on_load by @adhami3310 in #4274
- [ENG-3943]type check for event handler if spec arg are typed by @Lendemor in #4046
- add noop event by @adhami3310 in #4288
- allow for event handlers to ignore args by @adhami3310 in #4282
- improve typing for non decorated events by @adhami3310 in #4308
- add type hinting for plotly by @adhami3310 in #4279
- unbreak pyi plotly by @adhami3310 in #4320
- improve app_src typing by @benedikt-bartscher in #4324
- change custom attr to accept any by @adhami3310 in #4323
- improve typing for serializer decorator by @benedikt-bartscher in #4317
- [ENG-3793] convert event return types to type hints by @adhami3310 in #4331
Experimental Shiki Code Block Features
- [ENG-3892]Shiki codeblock support decorations by @ElijahAhianyo in #4234
- [ENG-4010]Codeblock cleanup in markdown by @ElijahAhianyo in #4233
Refactor Environment Variable Handling
- More env var cleanup by @benedikt-bartscher in #4248
Other Improvements
- Support
locale
prop inrx.moment
by @masenf in #4229 - delay page until _compile gets called by @adhami3310 in #3812
- fix stateful components on delayed evaluation by @adhami3310 in #4247
- make vardata merge not use classmethod by @adhami3310 in #4245
- port enum env var support from #4248 by @benedikt-bartscher in #4251
- expose staticPageGenerationTimeout by @adhami3310 in #4266
- rx.event(background=True) by @adhami3310 in #4263
- components as literal vars by @adhami3310 in #4223
- generate docs for event handlers by @adhami3310 in #4277
- improve page title default by @adhami3310 in #4278
- Add option to scroll to bottom by @picklelo in #4276
- [ENG-759] [ENG-1104] patch
json.dumps
to handle__wrapped__
objects by @masenf in #4166- Support direct usage of
MutableProxy
wrapped objects in JSON APIs (OpenAI, httpx, etc)
- Support direct usage of
- improve object var symantics by @adhami3310 in #4290
- add metainfo to keyevent by @adhami3310 in #4287
Bug Fixes
- Include value._get_all_var_data when ClientStateVar.set_value is used by @masenf in #4161
- client_state: fix fault VarData.merge call by @masenf in #4244
- Remove Duplicated 'gray' colour from ColorType by @lb803 in #4249
- Handle props annotated as list/dict of EventHandler by @masenf in #4257
- add existing path subclass for env checks by @adhami3310 in #4260
- [ENG-4012]Fix shiki copy button animation firing off after clicking copy button by @ElijahAhianyo in #4252
- [ENG-4013] Catch more exceptions for dill pickle fallback by @masenf in #4270
- fix typo in dataeditor prop by @adhami3310 in #4281
- Bugfix/leave gitignore as is by @grahamannett in #4291
- Fix wrong hook by @abulvenz in #4295
- fix call_function events sent from backend by @adhami3310 in #4316
- fix imports with alias from $ by @adhami3310 in #4332
- Only pass Model.fields when casting event args by @masenf in #4356
- fix upload argspec being missing by @adhami3310 in #4335
Documentation
- [ENG-4026]change gallery link to Templates by @ElijahAhianyo in #4283
- [GTM-345]Define component props in class for doc discoverability by @ElijahAhianyo in #4183
- Update overlay props by @tgberkeley in #4261
- default props comment for GraphinTooltip by @carlosabadia in #4101
- add toast classname prop by @carlosabadia in #4310
- [GTM-648]Add Missing Table props by @ElijahAhianyo in #4322
Version Bumps
- update nodejs to lts 22 for real this time by @adhami3310 in #4267
- rollback to 14.2.16 until v15 is more stable by @Lendemor in #4297
- bump python packages version by @Lendemor in #4302
- pin marked to correct version by @adhami3310 in #4313
- Bump reflex-hosting-cli dep to 0.1.15 for v2 by @masenf in #4355
- Temporarily downpin @radix-ui/themes <3.1.5 by @masenf in #4370
Other Changes
- convert test_table to use playwright by @Lendemor in #4241
- cleanup dead code by @benedikt-bartscher in #4271
- unbreak ci lighthouse by @adhami3310 in #4273
- resync steps with task advance by @adhami3310 in #4275
- [ENG-3961] move "warn_if_too_large" logic into BaseState by @masenf in #4284
- raise error when get package manager is not found by @adhami3310 in #4289
- better missing system package message by @adhami3310 in #4306
- move check of path to only check name by @adhami3310 in #4299
- special case field in _isinstance by @adhami3310 in #4298
- bypass pydantic runtime validation for state init by @benedikt-bartscher in #4256
- add codeowners by @Kastier1 in #4312
- stop ignoring some lint rules by @Lendemor in #4311
- mark var methods as private by @adhami3310 in #4319
- test_exception_handlers: add test case that triggers ErrorBoundary by @masenf in #4327
New Contributors
- @lb803 made their first contribution in #4249
- @grahamannett made their first contribution in #4291
Full Changelog: v0.6.4...v0.6.5
v0.6.4
New Features
Make Var System Expandable
A new dispatch mechanism for converting python values into Var and LiteralVar subclasses. This allows component authors and downstream applications to better support custom frontend operations on Python values converted to Javascript values
See Example
This example allows for near drop-in support for working with SQLAlchemy DeclarativeBase
models and will likely be included in a future release:
from collections.abc import Mapping, MutableSet, Sequence
from typing import TypeVar
import dataclasses
import sys
import reflex as rx
import sqlalchemy
import sqlalchemy.orm.exc
from sqlalchemy.orm import DeclarativeBase
class DeclarativeBaseVar(rx.vars.ObjectVar, python_types=DeclarativeBase):
pass
@dataclasses.dataclass(
eq=False,
frozen=True,
**{"slots": True} if sys.version_info >= (3, 10) else {},
)
class LiteralDeclarativeBaseVar(rx.vars.LiteralObjectVar, DeclarativeBaseVar):
_var_value: DeclarativeBase | None = None
T = TypeVar("T")
K = TypeVar("K")
V = TypeVar("V")
@rx.serializer
def serialize_Sequence(s: Sequence[T] | MutableSet[T]) -> list[T]:
return list(s)
@rx.serializer
def serialize_Mapping(m: Mapping[K, V]) -> dict[K, V]:
return dict(m)
@rx.serializer
def serialize_DeclarativeBase(obj: DeclarativeBase) -> dict[str, str]:
s = {}
for attr in sqlalchemy.inspect(type(obj)).all_orm_descriptors.keys():
try:
s[attr] = getattr(obj, attr)
except sqlalchemy.orm.exc.DetachedInstanceError:
# This happens when the relationship was never loaded and the session is closed.
continue
return s
- make var system expandable by @adhami3310 in #4175
max-requests
support to gunicorn (fixed memory leak)
This is a new configurable option in the rx.config but also now has default values.
gunicorn_max_requests
- ( gunicorn / uvicorn )max requests per worker
Defaults value - 100
gunicorn_max_requests_jitter
- (gunicorn only) variance in the max request limit. To prevent all workers restarting at same time
Defaults value - 25
What is max_requests
?
max_requests
is a the maximum number of requests a worker can serve before the manager will kill the worker and restart.
Why is this needed?
gunicorn workers don't release memory after a request. This can cause for a workers to hold on to more and more memory over time. Setting this flag means that after serving N requests the worker is killed, thus releasing the memory, and a new worker is spun up.
How to configure
rx.config(
...
gunicorn_max_requests=50
...
)
Experimental Shiki Codeblock
rx._x.code_block(
"""
print("Original text") # [!code --]
print("Replace original with this") # [!code ++]
name = "John Doe" # [!code highlight]
""",
language="python",
theme="dracula",
use_transformers=True,
can_copy=True,
show_line_numbers=True
)
- [ENG-3848][ENG-3861]Shiki Code block Experimental by @ElijahAhianyo in #4030
dotenv
support added
To use this feature, you must install python-dotenv
separately from reflex.
import reflex as rx
config = rx.Config(
app_name="mycoolapp",
env_file=".env",
)
- HOS-93: add support for .env file by @Kastier1 in #4219
- make python-dotenv optional by @Lendemor in #4222
New rx.dynamic
decorator
Unlike normal UI functions, this decorator allows UI code to directly access State instance values, Python-only APIs, and typical for
and if
statements.
See Example
We can implement a simple Reflex fiddle, that evaluates component strings into UI components and render them. This was previously difficult, as all UI had to compile into react code in the .web
folder. This works by dynamically compiling a JavaScript module using in-window react.
import reflex as rx
class State(rx.State):
component_str = "rx.button('login')"
@rx.dynamic
def evaluated_component(state: State):
try:
component = eval(
state.component_str,
{
"rx": rx,
"State": State,
},
)
except Exception as e:
return rx.text(f"Error: {e}")
if not isinstance(component, rx.Component):
return rx.text("Invalid component")
return component
def index():
return (
rx.hstack(
rx.text_area(
value=State.component_str,
on_change=State.set_component_str,
height="100%",
flex="1",
),
rx.card(evaluated_component(), height="100%", flex="1"),
height="100vh",
padding="1rem",
box_size="border-box",
),
)
- implement rx dynamic by @adhami3310 in #4195
Improvements
Better Type Hinting for Built in Components
- add type hinting to error boundary by @adhami3310 in #4182
- add event types to suneditor by @adhami3310 in #4209
- Add type hinting to dataeditor events by @adhami3310 in #4210
- Add on progress typing to react player by @adhami3310 in #4211
- add additional typing for calling events by @adhami3310 in #4218
Other Improvements
- allow setting run mode via env, add helpers to determine it by @benedikt-bartscher in #4168
- Raise TypeError when
ComputedVar.__init__
gets bad kwargs by @masenf in #4199 - move all environment variables to the same place by @adhami3310 in #4192
- add existing path subclass for env checks by @adhami3310 in #4260
- port enum env var support from #4248 by @benedikt-bartscher in #4251
- [ENG-3970] When normal pickle fails, try dill by @masenf in #4239
Bug Fixes
- use larger or equal for node version check by @adhami3310 in #4189
- check for none before returning which by @adhami3310 in #4187
- fix and test bug in config env loading by @benedikt-bartscher in #4205
- fix inverted alembic file check by @adhami3310 in #4238
- fix: async default setters break setvar by @benedikt-bartscher in #4169
- Fix 'enter_key_submit=True' on 'rx.text_area' by carrying custom_code on debounce by @masenf in #4142
- Handle props annotated as list/dict of EventHandler (#4257)
Version Bumps
- upgrade node to latest lts by @adhami3310 in #4191
- versions bump before 0.6.4 by @Lendemor in #4208
- bump ruff to 0.7.0 by @Lendemor in #4213
Other Changes
- pin AppHarness tests to ubuntu-22.04 runner by @masenf in #4173
- Remove demo command by @Alek99 in #4176
- move client storage classes to their own file by @Lendemor in #4216
- use $ syntax by @adhami3310 in #4237
- test for stateless apps by @Lendemor in #3816
Full Changelog: v0.6.3.post1...v0.6.4
v0.6.3.post1
Post-release fix for hot reload issue RuntimeError: Cannot populate parent states
- [ENG-3989] Ensure non-serialized states are present in StateManagerDisk (#4230)
Full Changelog: v0.6.3...v0.6.3.post1