Skip to content

Releases: reflex-dev/reflex

v0.5.2

30 May 23:59
f9c008a
Compare
Choose a tag to compare

New Features

Lifespan Tasks

A lifespan task is either a coroutine which runs while the backend server is running and is cancelled when the server stops, or it can be an asynccontextmanager in which case it will run at server startup until yield is called, then it will resume as the server is shutting down. In either case, the task is started and stopped during hot reload.

Any keyword arguments passed to app.register_lifespan_task will be passed to the coroutine/contextmanager. If the coroutine takes a parameter called app, this will be an instance of the underlying FastAPI object.

Sample Code
import asyncio
from contextlib import asynccontextmanager


def fake_answer_to_everything_ml_model(x: float):
    return x * 42


ml_models = {}


@asynccontextmanager
async def setup_model(app: FastAPI):
    # Load the ML model
    ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model
    yield
    # Clean up the ML models and release the resources
    ml_models.clear()


async def long_running_task(foo, bar):
    print(f"Starting {foo} {bar} task")
    some_api = SomeApi(foo)
    try:
        while True:
            updates = some_api.poll_for_updates()
            other_api.push_changes(updates, bar)
            await asyncio.sleep(5)  # add some polling delay to avoid running too often
    except asyncio.CancelledError:
        some_api.close()  # clean up the API if needed
        print("Task was stopped")


app = rx.App()
app.register_lifespan_task(setup_model)
app.register_lifespan_task(long_running_task, foo=42, bar=os.environ["BAR_PARAM"])

Improvements

Bug Fixes

Readme Updates

Other Changes

New Contributors

Full Changelog: https://github.com/reflex-dev/reflex/compare/v0.5.1..v0.5.2

v0.5.1

22 May 00:20
4cfa0e3
Compare
Choose a tag to compare

New Features

  • Connection Error modal is now a dismissable toast by @Lendemor in #3242
  • rx._x.client_state: react useState Var integration for frontend and backend by @masenf in #3269
    • Work in progress, API subject to change
  • Support replacing route on redirect by @masenf in #3072

Improvements

Bugfixes

Dependencies

Other Changes

  • [REF-2776] enable telemetry for frontend package download subprocess by @martinxu9 in #3270
  • [REF-2774] Add ReflexError and subclasses, send in telemetry by @martinxu9 in #3271
  • [REF-2774] Send runtime error in telemetry by @martinxu9 in #3276
  • Automatically label bug report issues with bug tag by @ericwb in #3288
  • [REF-2803]Add imports benchmarks by @ElijahAhianyo in #3272
  • Mirgrate from pip to uv by @ericwb in #3285
  • Adds dependency review action to verify allowed licensed dependencies by @ericwb in #3306

New Contributors

Full Changelog: v0.5.0.post1...v0.5.1

v0.5.0.post1

15 May 01:52
25c1406
Compare
Choose a tag to compare

Escape Hatch to avoid Bun on Windows

These exceptions only apply to Windows native platform (not WSL)

  • [REF-2814]Throw Warning for Projects Created in OneDrive on Windows (#3304)
    • Skip bun when project path contains "onedrive"
    • Skip bun when REFLEX_USE_NPM=1 (environment variable)

Full Changelog: v0.5.0...v0.5.0.post1

v0.5.0

14 May 00:56
52e0507
Compare
Choose a tag to compare

Breaking Changes

Radix Themes 3.0

  • rx.badge now has size="3" available, and sizes "2" and "1" have been adjusted accordingly
  • rx.input.root and rx.input.input are deprecated. Just use rx.input as the root. It accepts rx.input.slot as a child.
    • [REF-2789] Graceful deprecation of rx.input.root and rx.input.input #3249

Previously Deprecated Features Removed

  • get_asset_path removed
  • passing state to rx.App
  • passing script_tags to rx.App.add_page
  • passing custom_styles to rx.markdown (use component_map instead)
  • rx.State getters removed (use self.router instead)
    • get_token
    • get_sid
    • get_headers
    • get_client_ip
    • get_current_page
    • get_query_params
    • get_cookies

Remove deprecations for 0.5.0 by @picklelo in #3222

New Features

Radix Themes 3.0

  • rx.spinner - new component for indeterminate loading
  • rx.skeleton - new component for placeholder loading
  • loading prop available for
    • rx.button
    • rx.icon_button
    • rx.spinner and rx.skeleton -- use loading=State.is_loading instead of using rx.cond
  • rx.data_list - new component for showing key value pairs
  • rx._x.progress - experimental radix themes progress component, supports duration for indeterminate progress.

Radix 3.0 by @Lendemor in #3159

New Public API for wrapping Components

To make wrapping components easier and less error prone, the following functions should be overridden when wrapping components:

  • add_style - return an rx.style.Style for default component styles
  • add_imports - return a dictionary of {"library-name@0.5.0": {"tag1", "tag2", "tag3"}} of required imports -- it will automatically be merged with the other component imports.
  • add_hooks - return a list of javascript snippets that will go inside the component function -- it will be deduped automatically with any other hooks
  • add_custom_code - return a list of javascript snippets that will go inside the module for each page the component is included in.

With these new methods, Reflex will internally call them for each parent class your component inherits from, so there is no need to call super().add_* or do any merging yourself.

State.setvar(var_name, value)

A less magic version of the automatic State.set_x setter functions which accept the var_name as a string.

  • [REF-2273] Implement .setvar special EventHandler by @masenf in #3163

Experimental Toast Component

def try_some_toast():
    return rx.fragment(
        rx.button("πŸ₯‚", on_click=rx._x.toast.info("Cheers"), variant="outline"),
        rx._x.toast.provider(),
    )

Generic .throttle and .debounce for all Event types

class ThrottleState(rx.State):
    last_event: datetime.datetime = datetime.datetime.now()

    def handle_mouse_move(self):
        self.last_event = datetime.datetime.now()

def throttle_example():
    return rx.box(
        ThrottleState.last_event,
        background_color=rx.color("red", 7),
        width="500px",
        height="500px",
        on_mouse_move=ThrottleState.handle_mouse_move.throttle(500),  # one event every 500ms
    )
  • Implement throttle and debounce as event actions by @masenf in #3091

rx.container new prop stack_children_full_width

For a nice streamlit-like wide layout, use the following snippet:

def index():
    return rx.container(
        rx.vstack(content()),
        stack_children_full_width=True,
    )

This will cause all vstack/hstack children and most stack child components to have width="100%" automatically, which provides a nice aesthetic for many apps without applying CSS to individual components.

  • [REF-2574] Default width for Stack (+children) and default padding for container by @masenf in #3104

Improvements

Unify on ruff-format

  • ruff-format: unify Black with Ruff v0.1 by @Borda in #2837
  • sync ruff version in pyproject.toml with the precommit one by @Lendemor in #3150

Error Messages

  • [REF-2636]Improve Error message for unsupported event trigger by @ElijahAhianyo in #3147
  • prevent shadowing by @Lendemor in #3221
    • Better error when a computed var has the same name as an existing state var.
  • [REF-2643]Throw Errors for duplicate Routes by @ElijahAhianyo in #3155
  • [REF-2622]Throw warning for incompatible uvicorn version on windows by @ElijahAhianyo in #3246

rx.color_mode changes

  • rx.color_mode.button now has built in positioning prop for floating button
    • IconButton for color_mode with nice default and a position props to control it by @Lendemor in #3165

Default style for rx.upload

Use Alembic Batch Mode for reflex db makemigrations

This improves compatibility with the default sqlite database when re-typing columns.

  • [REF-2658] Alembic should use batch mode for autogenerate by @masenf in #3223

README

Miscellaneous

Bugfixes

  • [REF-2587] Ignore top-level theme appearance by @masenf in #3119
    • avoids "flickering" when the top-level appearance differs from user selected mode
  • [REF-2619] Re-init when the template is out of date by @masenf in #3121
  • Fixed app name validation by @Snaipergelka in #3146
  • extend rx.input allowed types by @Lendemor in #3149
  • [REF-2682] Foreach over dict uses Tuple arg value by @masenf in #3160
    • Improve nested foreach when dict has complex values
  • Update CodeBlock class to accept rx.color in custom_style by @khhan0130 in #3168
  • Windows --frontend-only fix ctrl + c by @ElijahAhianyo in #3181
  • [REF-2676][REF-2751]Windows Skip ARM devices on bun install + Telemetry by @ElijahAhianyo in #3212
  • icon_button: Icon size should be specified as int pixels, not str by @masenf in #3247
  • copy background task marker by @benedikt-bartscher in #3255
    • Can now define background tasks in a state mixin
  • Dynamic NoSSRComponent properly renders in prod mode when using State/event handlers

Dependencies

Other Changes

Read more

v0.4.9

23 Apr 16:57
1e6d31a
Compare
Choose a tag to compare

New Features

Improvements

Bug Fixes

  • [REF-2586] Pass child event_trigger through DebounceInput by @masenf in #3092
    • on_key_down / on_key_up work with controlled inputs
  • [REF-2589] Use errors='replace' with subprocess by @masenf in #3096
    • Avoid UnicodeDecodeError on windows
  • [REF-2587] Ignore top-level theme appearance (#3119)

Experimental

Other Changes

Full Changelog: v0.4.8...v0.4.9

v0.4.8.post1

20 Apr 04:02
75fee92
Compare
Choose a tag to compare

Pin react-focus-lock to 2.11.13 #3123

v0.4.8

15 Apr 22:15
64805d3
Compare
Choose a tag to compare

New Features

new transpile_packages field in rx.Component

For packages on npm which are not exported as modules, these can now be transpiled by Next.JS and used directly.

  • [REF-2392] Expose next.config.js transpilePackages key by @masenf in #3006

Improvements

Use bun as a package manager on windows

Much faster package installation on windows!

x64 only (no x86 or ARM support)

  • [REF-1586] Use bun as a package manager on windows by @masenf in #2359

Upload with no files selected still calls event handler

Note: you need to specify a default value for your files parameter to take advantage of this change.

  • Fix For When user selects Empty files using File Upload by @Yummy-Yums in #3051

Enum types are now serialized to their value

Automatic tuple unpacking also works for Component children

Bug Fixes

Experimental

Other Changes

New Contributors

Full Changelog: v0.4.7...v0.4.8

v0.4.7

09 Apr 22:10
bf28dab
Compare
Choose a tag to compare

New Features

New reflex init templates

We've added 4 new base templates to reflex init.

(0) blank (https://blank-template.reflex.run) - A minimal template
(1) dashboard (https://dashboard.reflex.run) - A dashboard with tables and graphs
(2) chat (https://chat.reflex.run) - A ChatGPT clone
(3) sidebar (https://sidebar-template.reflex.run) - A template with a sidebar to navigate pages

You can also specify the template directly

reflex init --template chat

Use any Reflex app on Github as an initial template

reflex init now also supports passing in any Github url as a template. Currently the Reflex app must be in the root of the Github directory (meaning the rxconfig.py should be in the root.

reflex init --template https://github.com/reflex-dev/reflex-chat
  • Support reflex app creation from templates from github by @martinxu9 in #2490

reflex run will automatically init the app when required

Previously when updating versions of Reflex or cloning an existing Reflex app, you would have to run reflex init before you can reflex run. From 0.4.7, reflex init is only required the very first time you create an app. If you are missing a .web folder or there's a new version of Reflex, reflex run and reflex export will automatically init the app for you.

rx.logo() component to display the Reflex logo

Show Built with Reflex logo.

rx.logo()

Reflex Experimental Namespace

We've introduced a new rx._x namespace where we will be putting experimental features for early testers before they go into general release. This will help us make sure new features have time to mature with real users before we make them public

Improvements

None can be passed in as a component prop and it will be skipped

  • Logic for removing the 'None' property along with its corresponding test cases by @AmanSal1 in #2969

Leaving a trailing comma on a reflex component won't throw an error anymore as we unpack the tuple

Bug Fixes

Misc

New Contributors

Full Changelog: v0.4.6...v0.4.7

v0.4.6

01 Apr 23:49
5c8d5e5
Compare
Choose a tag to compare

Known Issues

  • Unhandled runtime error when navigating between pages in a stateless app.

This Release was Airdropped from 30000' over Nevada πŸͺ‚

IMG_2840

Breaking Changes

Use dill instead of cloudpickle

In reflex-0.4.6, existing states persisted in redis are not compatible. Redis should be cleared and existing states/sessions discarded after upgrading.

  • [REF-2089] Use dill instead of cloudpickle for serialization by @masenf in #2922

New Features

reflex component share CLI

Simplify sharing of custom 3rd party components to the Reflex Component Gallery.

  • [REF-2168] Add share options to custom component commands by @martinxu9 in #2883

rx.ComponentState

An easy way to define per-component State.

import reflex as rx

class CounterButton(rx.ComponentState):
    count: int

    def increment(self):
        self.count += 1

    def decrement(self):
        self.count -= 1

    @classmethod
    def get_component(cls, *children, **props):
        return rx.button(
            f"Counter {cls.count}",
            on_click=cls.increment,
            on_context_menu=cls.decrement.prevent_default,
        )

counter_button = CounterButton.create

@rx.page()
def index():
    return rx.vstack(
        *[counter_button() for _ in range(10)]
    )

app = rx.App()
  • [REF-2265] ComponentState: scaffold for copying State per Component instance by @masenf in #2923

Automatically Select Next Available Port

When the configured port is not available, automatically select the next sequential port until one is available

Expanding Textarea

New props on rx.el.textarea and rx.text_area allow the field to expand to match content and submit the form when Enter is pressed (shift+enter to create a new line)

  • textarea: expose auto_height and enter_key_submit props by @masenf in #2884

rx.scroll_to event

Scroll the viewpoint to show a given element by ID.

Improvements

Simplify Component Wrapping API

[REF-2272] Support declaring EventHandlers directly in component by @martinxu9 in #2952

Props typed as rx.EventHandler can be used to define event triggers without overriding get_event_triggers method. The argument of the type specifies the JS to Python mapping: on_click: rx.EventTrigger[lambda e: [e]].

generate pyi files when building/publishing 3rd party component by @Lendemor in #2945

Third-party components will now have .pyi files generated for them to improve IDE completion, similar to the built in Reflex components.

Updated Lucide Icons

The latest icons available on https://lucide.dev are now usable in Reflex. Some icon names have changed, these will print a deprecation warning pointing to the new name. The old names will be removed in 0.5.0.

Loosen Requirement Pins

Reflex is now compatible with a wider range of dependencies. Notably, it can be used with packages that depend on Pydantic v2 (although the framework itself is still using v1).

Note: due to a regression in recent uvicorn versions, that dep will remain pinned as it was in 0.4.5.

Avoid content flicker when using State.is_hydrated

is_hydrated is set to False immediately when a navigation event starts, and is set back to True after all on_load events have executed. This avoids content flickering into view before a loading spinner is displayed when the spinner is conditional on the value of State.is_hydrated.

Additionally, the WiFi off connection error pulser is only displayed when connection errors are detected (before it was displayed whenever the page was not hydrated).

  • Set is_hydrated=False at route onChangeStart by @masenf in #2949

Miscellaneous

  • [REF-1982] state: Warn if redis state is "too big" by @masenf in #2868
  • use radix box instead of chakra one for responsive elements by @Lendemor in #2921
  • [REF-2229]Dedupe deprecation warnings by @ElijahAhianyo in #2871
  • fix hook order to use ref inside user hooks by @Lendemor in #2906
    • Ensure user-defined hooks can always access refs
  • [REF-2302] When a Var points to a model, prefer access to model fields. by @masenf in #2893

Bug Fixes

  • [REF-2117]:rx.color_mode_cond to work in f-strings by @ElijahAhianyo in #2775
  • Default to None if bun/fnm version is Invalid by @ElijahAhianyo in #2940
  • remove inheritance from Flex for list components by @Lendemor in #2936
    • Fix markdown rendering of lists
  • parse_args_spec: resolve annotations with typing.get_type_hints by @masenf in #2849
  • [REF-2219] Avoid refetching states that are already cached by @masenf in #2953
    • Fix issue affecting Cookie/LocalStorage values when substates contained computed vars
  • [REF-2306] Include twine in dependencies on pyproject.toml by @martinxu9 in #2895

Other Changes

New Contributors

Full Changelog: v0.4.5...v0.4.6

v0.4.5

20 Mar 20:04
ab7b856
Compare
Choose a tag to compare

New Features

Support SQLAlchemy Models Directly

Experimental Multi-process Compilation

Pass REFLEX_COMPILE_PROCESSES=0 to opt-in to multiprocess compile, which significantly improves compilation speed of large apps (Mac and Linux only).

  • [REF-2122] Opt-in multiprocess compile by @masenf in #2838

Improvements

Bug Fixes

  • [REF-2172] Add DECORATED_PAGES before compiling in thread by @masenf in #2841
    • Fix known regression with py3.8 and py3.9
  • Remove width prop from rx.select by @picklelo in #2835
    • HighLevelSelect: pass flex_shrink prop to SelectTrigger by @masenf in #2876
  • Get client_ip from asgi.scope by @masenf in #2808
    • router.session.client_ip more likely to be correct now
  • convert text inside list_item to span and set icon display to inline by @Lendemor in #2860

Other Changes

  • [REF-2086] Avoid "Warning: The path to the Node binary could not be found. by @masenf in #2803
  • telemetry refactor + unit tests by @Lendemor in #2786
    • When __REFLEX_SKIP_COMPILE == "yes" allow telemetry to fail by @masenf in #2881
  • Custom Component Request Template by @Alek99 in #2853
  • Benchmark with app harness by @ElijahAhianyo in #2774
  • Fix py3.8 integration test_var_operations.py by @masenf in #2858
  • Account for imports of @rx.memo components for frontend package installation by @masenf in #2863
  • [REF-2216] Warn if windows is used with py312 by @masenf in #2856
  • Separate get_hooks and get_hooks_internal for stable output by @masenf in #2710
  • [REF-2219] vars: set _was_touched when updating cached vars by @masenf in #2886

New Contributors

Full Changelog: v0.4.4...v0.4.5