Skip to content

Releases: reflex-dev/reflex

v0.6.8

10 Jan 17:27
fea0ceb
Compare
Choose a tag to compare

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.

  • Move _create_event_chain to EventChain.create by @masenf in #4557

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)
  • BaseState.get_var_value helper to get a value from a Var by @masenf in #4553

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.

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.

Performance

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 resolve rx.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

Documentation

Other Changes

New Contributors

Full Changelog: v0.6.7...v0.6.8

v0.6.7

17 Dec 18:11
61caf14
Compare
Choose a tag to compare

Deprecations

  • app.add_custom_404_page is deprecated -- use app.add_page(..., route="/404") instead.
  • external prop of rx.redirect is renamed to is_external for consistency.

New Features

async_db_url and rx.asession

Builtin support for async database operations using sqlmodel. Proper usage requires the following:

  1. Install greenlet for sqlalchemy to use async operations.
  2. Install an appropriate async-capable database driver (aiosqlite, pyscopg)
  3. Set ASYNC_DB_URL in the environment that references the async db driver. This should point to the same database as specified in DB_URL, which should still be set for handling alembic migrations and for use in computed vars, etc.
  4. 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.

  • Reuse the sqlalchemy engine once it's created by @masenf in #4493

Linting

Performance

Miscellaneous

Bug Fixes

Documentation

Version Bumps

Other Changes

New Contributors

Full Changelog: v0.6.6.post3...v0.6.7

v0.6.6.post3

10 Dec 03:04
49caf9d
Compare
Choose a tag to compare

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

05 Dec 09:21
7c81dca
Compare
Choose a tag to compare

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

05 Dec 07:27
dc99778
Compare
Choose a tag to compare

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

03 Dec 05:00
0c81922
Compare
Choose a tag to compare

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.

Builtin support for existing pydantic v1 and v2 models

State vars can now be typed as pydantic models, with support for modification tracking.

  • [ENG-3953] Support pydantic BaseModel (v1 and v2) as state var by @masenf in #4338

rx.asset promoted to non-experimental

TBD: docs for new API

Improvements

Streamlined reflex init workflow

Other Improvements

Bug Fixes

Version Bumps

Other Changes

New Contributors

Full Changelog: v0.6.5...v0.6.6

v0.6.5

12 Nov 21:50
3e9f346
Compare
Choose a tag to compare

Known Issues

  • #4384 Setting the default appearance prop in rx.theme is no longer working

Breaking Changes

  • rx.App is now a dataclass that does not accept additional kwargs. Any unrecognized kwargs passed to rx.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 regular dict

New Features

New rx.get_state interface

  • expose rx.get_state() to get instance of state from anywhere by @Lendemor in #3959

Support custom bunfig.toml

New Hosting Service CLI

Improvements

Better Typing Support

Experimental Shiki Code Block Features

Refactor Environment Variable Handling

Other Improvements

Bug Fixes

Documentation

Version Bumps

Other Changes

New Contributors

Full Changelog: v0.6.4...v0.6.5

v0.6.4

29 Oct 23:45
e471dc1
Compare
Choose a tag to compare

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

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
)

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",
)

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",
        ),
    )

Improvements

Better Type Hinting for Built in Components

Other Improvements

Bug Fixes

Version Bumps

Other Changes

Full Changelog: v0.6.3.post1...v0.6.4

v0.6.3.post1

23 Oct 23:17
9308caa
Compare
Choose a tag to compare

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

v0.6.3

18 Oct 16:23
addf633
Compare
Choose a tag to compare

New Features

Correct handling of aria and data props

Any props passed to a component with aria_ or data_ prefix will be applied directly to the component (previously, these were misinterpreted as style props).

Reflex Code

rx.icon_button("save", aria_label="Save Changes", data_test="arbitrary data")

Generated Output

<button ... aria-label="Save Changes" data-test="arbitrary data"><svg>...</svg></button>

Improvements

Static typing of events and vars

New (optional) rx.Field, rx.field and @rx.event decorators allow pyright and other static type checkers to better understand how event handlers and state vars are handled in reflex, allowing most static type checking to pass without # type: ignore comments.

import reflex as rx


class MyState(rx.State):
    v: rx.Field[int] = rx.field(42)

    @rx.event
    def set_v(self, v: str):
        try:
            self.v = int(v)
        except ValueError:
            pass


def index() -> rx.Component:
    return rx.vstack(
        rx.heading(MyState.v),
        rx.input(
            value=MyState.v,
            on_change=MyState.set_v,
            type="number",
        ),
    )


app = rx.App()
app.add_page(index)
  • [ENG-3749] type safe vars by @adhami3310 in #4066
  • add type hinting to events by @adhami3310 in #4145
    • Fix runtime error on python 3.11.0 (#4197)
    • fix pyi for untyped event handlers (#4186)
    • Arbitrary arg access two levels deep for untyped handler (#4180)

Other Improvements

  • Optimize StateManagerDisk by @masenf in #4056
  • Reduce pickle size by @masenf in #4063
  • fail safely when pickling by @adhami3310 in #4085
  • First use environment variable as npm registry by @ruhz3 in #4082
  • let users pick state manager mode by @Lendemor in #4041
    • disk is memory is disk (#4185)
    • When REDIS_URL is set, use redis, regardless of config preference. (#4196)
  • Allow setting a different invocation function for EventChain by @masenf in #4160

Bug Fixes

Version Bumps

Documentation

Other Changes

New Contributors

Read more