Commit Graph

92 Commits

Author SHA1 Message Date
Masen Furer
3564df7620
Implement throttle and debounce as event actions (#3091) 2024-04-26 17:28:51 -07:00
Masen Furer
74eaab5e19
Integration testing: Firefox compatibility (#3162)
* Integration testing: Firefox compatibility

* test_client_side_storage: ruff format
2024-04-26 13:44:08 -07:00
Thomas Brandého
ac36bfc6ea
Radix 3.0 (#3159) 2024-04-25 08:33:29 -07:00
Ogidi Ifechukwu
ce2bd2286e
Refactor upload component and add styled upload component (#3035) 2024-04-24 13:45:22 -07:00
Jirka Borovec
4d567b7ec1
ruff-format: unify Black with Ruff v0.1 (#2837)
* ruff-format: unify Black with Ruff

* ruff lint.

* v0.1.0

* run precommit

* hand fixing

* fix `not isinstance(...)`

Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>

* rev isinstance(...) with noqa

* exclude = ["*.pyi"]

* apply precommit

* apply format

* revert pyi

* fixing

* Fix or

Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>

* Update reflex/components/datadisplay/code.pyi

* Apply suggestions from code review

Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>

* Update tests/components/core/test_colors.py

* Update reflex/app.py

* Update reflex/app.py

* Update benchmarks/test_benchmark_compile_pages.py

* Update benchmarks/test_benchmark_compile_pages.py

* Update benchmarks/test_benchmark_compile_pages.py

---------

Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>
2024-04-23 14:40:06 -07:00
Martin Xu
7d36610cae
Support reflex app creation from templates from github (#2490) 2024-04-04 15:31:34 -07:00
Masen Furer
5510eaf820
[REF-2265] ComponentState: scaffold for copying State per Component instance (#2923)
* [REF-2265] ComponentState: scaffold for copying State per Component instance

Define a base ComponentState which can be used to easily create copies of the
given State definition (Vars and EventHandlers) that are tied to a particular
instance of a Component (returned by get_component)

* Define `State` field on `Component` for typing compatibility.

This is an Optional field of Type[State] and is populated by ComponentState.

* Add integration/test_component_state.py

Create two independent counters and increment them separately

* Add unit test for ComponentState
2024-03-29 09:22:25 -07:00
benedikt-bartscher
f27eae7655
fix AppHarness reloading (#2916)
* move AppHarness tests to module scope

* fix AppHarness reloading

* add test

* docstrings and formatting

* fix benchmarks not reloading state module
2024-03-26 11:09:46 -07:00
Masen Furer
e3db9adc70
Fix py3.8 integration test_var_operations.py (#2858)
A newly added test was not py3.8 compatible and is breaking CI runs
2024-03-13 17:45:27 -07:00
Elijah Ahianyo
a06b570e3a
Benchmark with app harness (#2774) 2024-03-13 15:59:55 -07:00
Masen Furer
036afa951a
Make @rx.memo work with state vars passed as props (#2810)
* Make @rx.memo work with state vars passed as props

Seems like this was a regression from the StatefulComponent refactor, because
trying to pass a state Var to a CustomComponent gave undefined, likely due to
`_get_vars` not accounting for `self.props` in CustomComponents.

With this change, it works.

Integration test added to `test_var_operations.py`

* Allow CustomComponent props to be Component

Avoid calling `.json()` on all Base types because the Var serializer already
does that, but this way, more specific types (like Component) can be serialized
differently.

When the type is Component, attach a VarData with the imports and hooks to when
the Var is rendered, it also carries the correct imports/hooks and does not
throw frontend errors.
2024-03-13 13:41:17 -07:00
Masen Furer
eb18ce90d5
[REF-2172] Add DECORATED_PAGES before compiling in thread (#2841) 2024-03-12 10:28:37 -07:00
benedikt-bartscher
19a5cdd408
Track state usage (#2441)
* rebase

* pass include_children kwarg in radix FormRoot

* respect include_children

* ruff fixes

* readd statemanager init, run pyi gen

* minor performance imporovements, fix for state changes

* fix pyi and pyright

* pass include_children for chakra

* remove old state detection

* add test for unused states in stateless app

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-03-07 14:25:55 -08:00
Masen Furer
5d647a498f
[REF-1368] Move common form functionality to rx.el.forms (#2801)
* [REF-1368] Move common form functionality to rx.el.forms

Allow plain HTML Form element to have magic on_submit event handler.

* Chakra and Radix forms inherit `on_submit` functionality from rx.el.form

Consolidate logic in the basic HTML form and use it in both Radix and Chakra
form wrappers.

* from __future__ import annotations for py38
2024-03-07 13:17:54 -08:00
Tom Gotsman
93fc269860
initial attempt at writing test for urls (#2689)
* initial attempt at writing test for urls

* turn it into a pytest test

* fix precommit and add wrong url to make sure test work

* fix darglint error and fix url set error

* black error

* add to test .md files in reflex as well

* update to fix masen comment

* black formatting

* Fix trailing slash in reflex/state.py

---------

Co-authored-by: Tom Gotsman <tomgotsman@Toms-MacBook-Pro.local>
Co-authored-by: Tom Gotsman <tomgotsman@toms-mbp.lan>
Co-authored-by: Masen Furer <m_github@0x26.net>
2024-02-29 13:45:57 -08:00
benedikt-bartscher
c465b94016
add some backend var state inheritance tests (#2685) 2024-02-28 15:11:14 -08:00
Masen Furer
3c3c331856
[REF-2101] Support default_value and default_checked on rx.el.input (#2739) 2024-02-27 16:57:37 -08:00
Masen Furer
deae662e2a
[REF-1988] API to Get instance of Arbitrary State class (#2678)
* WiP get_state

* Refactor get_state fast path

Rudimentary protection for state instance access from a background task
(StateProxy)

* retain dirty substate marking per `_mark_dirty` call to avoid test changes

* Find common ancestor by part instead of by character

Fix StateProxy for substates and parent_state attributes (have to handle in
__getattr__, not property)

Fix type annotation for `get_state`

* test_state: workflow test for `get_state` functionality

* Do not reset _always_dirty_substates when adding vars

Reset the substate tracking only when the class is instantiated.

* test_state_tree: test substate access in a larger state tree

Ensure that `get_state` returns the proper "branch" of the state tree depending
on what substate is requested.

* test_format: fixup broken tests from adding substates of TestState

* Fix flaky integration tests with more polling

* AppHarness: reset _always_dirty_substates on rx.State

* RuntimeError unless State is instantiated with _reflex_internal_init=True

Avoid user errors trying to directly instantiate State classes

* Helper functions for _substate_key and _split_substate_key

Unify the implementation of generating and decoding the token + state name
format used for redis state sharding.

* StateManagerRedis: use create_task in get_state and set_state

read and write substates concurrently (allow redis to shine)

* test_state_inheritance: use polling cuz life too short for flaky tests

kthnxbai ❤️

* Move _is_testing_env to reflex.utils.exec.is_testing_env

Reuse the code in app.py

* Break up `BaseState.get_state` and friends into separate methods

* Add test case for pre-fetching cached var dependency

* Move on_load_internal and update_vars_internal to substates

Avoid loading the entire state tree to process these common internal events. If
the state tree is very large, this allow page navigation to occur more quickly.

Pre-fetch substates that contain cached vars, as they may need to be recomputed
if certain vars change.

* Do not copy ROUTER_DATA into all substates.

This is a waste of time and memory, and can be handled via a special case in
__getattribute__

* Track whether State instance _was_touched

Avoid wasting time serializing states that have no modifications

* Do not persist states in `StateManagerRedis.get_state`

Wait until the state is actually modified, and then persist it as part of `set_state`.

Factor out common logic into helper methods for readability and to reduce
duplication of common logic.

To avoid having to recursively call `get_state`, which would require persisting
the instance and then getting it again, some of the initialization logic
regarding parent_state and substates is duplicated when creating a new
instance. This is for performance reasons.

* Remove stray print()

* context.js.jinja2: fix check for empty local storage / cookie vars

* Add comments for onLoadInternalEvent and initialEvents

* nit: typo

* split _get_was_touched into _update_was_touched

Improve clarity in cases where _get_was_touched was being called for its side
effects only.

* Remove extraneous information from incorrect State instantiation error

* Update missing redis exception message
2024-02-27 13:02:08 -08:00
Krys
278183b526
fix image serializing - REF-1889 (#2550)
* fix image serializing

* If get_format_mimetype does not work, look up format in Image.MIME

Throw a warning if the image format does not have an associated MIME type and
ultimately fallback to image/png and let the browser figure it out.

* test_media: end to end serialization of PIL images

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-02-22 08:13:19 -08:00
Masen Furer
789d50e0e4
test_input: replace sleep with _poll_for (#2677)
Reduce test flakiness and improve runtime in optimal case
2024-02-21 20:12:31 -08:00
Masen Furer
756bf9b0f4
[REF-1885] Shard Substates when serializing to Redis (#2574)
* Move sharding internal to StateManager

Avoid leaking sharding implementation details all over the State class and
breaking the API

* WiP StateManager based sharding

* Copy the state __dict__ when serializing to avoid breaking the instance

* State tests need to pass the correct substate token for redis

* state: when getting parent_state, set top_level=False

ensure that we don't end up with a broken tree

* test_app: get tests passing with redis by passing the correct token

refactor upload tests to suck less

* test_client_storage: look up substate key

* state.py: pass static checks

* test_dynamic_routes: working with redis state shard

* Update the remaining AppHarness tests to pass {token}_{state.get_full_name()}

* test_app: pass all tokens with state suffix

* StateManagerRedis: clean up commentary
2024-02-21 01:50:25 -08:00
abulvenz
980834605b
feat: Synchronizing localStorage between tabs using browser events (#2533)
* feat: Synchronizing localStorage between tabs using browser events

* test_client_storage: Test sync'd local storage vars

* update_vars_internal: generic handler to apply var changes to state tree

Apply fully qualified var names to each substate they are associated with. This
allows consistent updates to arbitrary state vars without having to know their
"setter" arguments, in case the user has overwritted the `set_x` name.

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-02-20 15:14:55 -08:00
Masen Furer
279e9bfa28
[REF-1993] link: respect is_external prop and other attributes on A tag (#2651)
* link: respect `is_external` prop and other attributes on A tag

Instead of passing all props to NextLink by default, only pass props that
NextLink understands, placing the remaining props on the Radix link

Add a test case to avoid regression of `is_external` behavior.

* Link is a MemoizationLeaf

Because Link is often rendered with NextLink as_child, and NextLink breaks if
the href is stateful outside of a Link, ensure that any stateful child of Link
gets memoized together.
2024-02-19 15:43:27 -08:00
Masen Furer
4206afeb7b
[REF-1958] Remove shadowed radix css props (#2590)
* style: shorthand replacements need camelCase

Avoid warning on terminal and in browser console from using kebab-case CSS
props with emotion.

* _rename_props only replace prop name once

In case the value also contains the prop name, we don't want to replace it
multiple times.

* pyi_generator: ignore _rename_props in create signature

* Avoid shadowing CSS prop `display` and `gap`

Replace usages of `gap` with `spacing` to retain Radix sizing number system,
while allowing users to specify a responsive `gap` using CSS units.

Remove `display` props from radix components, allowing `display` to accept
responsive lists.

* checkbox: apply `gap` to `flex` if provided

* Remove _rename_props from .create signatures

* Fix spacing prop in blank template

* Fixup tests after changing style shorthand to return camelCase
2024-02-13 10:06:28 -08:00
Nikhil Rao
f05d5ba7ba
Rename components in top level namespace (#2589) 2024-02-12 21:35:49 -08:00
Masen Furer
2b7e7450f8
Merge remote-tracking branch 'origin/main' into reflex-0.4.0 2024-02-12 12:22:50 -08:00
Masen Furer
3df4eac33d
test_call_script: update poll ending condition to avoid race (#2583) 2024-02-12 12:21:30 -08:00
Masen Furer
58b5e2f5bd
Merge remote-tracking branch 'origin/main' into reflex-0.4.0 2024-02-09 19:38:35 -08:00
Masen Furer
fe2778379d
Fix race condition in test_client_storage (#2568) 2024-02-09 16:15:07 -08:00
Masen Furer
ae20644a82
Merge remote-tracking branch 'origin/main' into reflex-0.4.0 2024-02-08 10:17:34 -08:00
benedikt-bartscher
eabbbea171
fix EventHandlers and ComputedVars inherited by mixin classes (#2534)
* wip event handlers for state mixins

* fix computed vars, prepare event handler tests

* fix computed vars and event handlers inherited by mixins

* Base is not a mixin

* improve state inheritance tests

* wait for alerts to appear

* poll_for_content to fix flaky ci tests
2024-02-07 14:48:39 -08:00
Nikhil Rao
05d1be2182
Move core components to radix namespace (#2506) 2024-02-02 14:26:46 -08:00
jackie-pc
032017df3a
simple pytest benchmark for measuring event <=> state update round trip time (#2489) 2024-01-30 15:55:55 -08:00
Masen Furer
bece5bdb44
[REF-1632] Apply rx.App styles to Radix Themes root div (#2481) 2024-01-29 16:58:05 -08:00
benedikt-bartscher
5cc1ecfe4a
fix SmartDisplay visible parameter (#2451) 2024-01-24 17:41:16 -08:00
benedikt-bartscher
6401dc6a7f
extend state inheritance tests with non-computed vars (#2425) 2024-01-23 12:20:34 -08:00
benedikt-bartscher
ae1a6e1acc
inherit computed vars from state mixins (#2351) 2024-01-12 14:22:38 -08:00
Masen Furer
accaf6dc52
[REF-1365] Radix + Tailwind Compatibility (and allow tailwind to be completely disabled) (#2246) 2023-12-28 00:14:04 -08:00
jackie-pc
7388617b72
apps should no longer call "app.compile()" (#2291) 2023-12-18 16:06:21 -08:00
Masen Furer
e52267477c
[REF-1417] Convert underscore-prefixed style props to pseudo selector (#2266) 2023-12-11 13:37:57 -08:00
Alek Petuskey
7164b91d7b
Implement Radix Themes (#2236) 2023-12-06 16:47:03 -08:00
Masen Furer
0bbae2d3d5
[REF-1404] router_data not updated when processing events (#2255) 2023-12-04 16:45:22 -08:00
Masen Furer
a2d5bbc133
[reflex-web tweaks] Do not memoize children of InputGroup (#2230) 2023-11-30 09:48:28 -08:00
Elijah Ahianyo
e3ee98098a
RED-1052/rx.State as Base State (#2146) 2023-11-29 09:43:33 -08:00
Masen Furer
527437cf23
[REF-144] Add context in each component to prevent rerenders (#2198) 2023-11-27 16:05:59 -08:00
Masen Furer
1603144c7d
[REF-889] useContext per substate (#2149) 2023-11-21 11:52:06 -08:00
Masen Furer
7eccc6d988
[REF-723+] Upload with progress and cancellation (#1899) 2023-11-16 15:46:13 -08:00
Masen Furer
9480f76a27
reflex_init_in_docker_test: export both frontend and backend (#2182) 2023-11-16 14:21:54 -08:00
Masen Furer
5e6520cb5d
Support Form controls via name attribute (no ID or ref) (#2012) 2023-11-10 12:58:59 -08:00
Alek Petuskey
dd982c5ace
Add benchmarking tests (#2143) 2023-11-08 17:41:08 -08:00