Commit Graph

1383 Commits

Author SHA1 Message Date
Masen Furer
7b43b923b8
bump to 0.4.4 (#2833) 2024-03-11 13:00:13 -07:00
Masen Furer
94e750a5f1
[REF-2157] Allow rx.download to resolve rx.get_upload_url links (#2813) 2024-03-11 12:29:34 -07:00
hjpr
4413cb4038
Allow access to position from HighLevelSelect (#2829) 2024-03-11 12:27:38 -07:00
benedikt-bartscher
8a3c9383fb
improve event handler state references (#2818) 2024-03-11 12:18:18 -07:00
Masen Furer
c809107d09
[REF-2158] Enable state when on_load or event_triggers are set. (#2815)
* [REF-2158] Enable state when `on_load` or event_triggers are set.

Basically all events in a reflex app require the backend to be up, even the
built-in server side events round trip to the backend and require "state" even
if no user-defined state classes are declared.

test_app_state_determination: checking that state is enabled at the right time

* Clear out DECORATED_PAGES when initializing a new app
2024-03-08 17:34:09 -08:00
Martin Xu
bf297e2f5b
[REF-2141] Custom component command improvements (#2807)
* add custom component command improvements

* fix test

* fix regex to include both single/double quotes
2024-03-07 20:42:22 -08:00
benedikt-bartscher
f5b7eca9c7
add support for sqlalchemy AssociationProxys (#2809)
* add support for sqlalchemy AssociationProxys

* python 3.8 compatibility
2024-03-07 15:19:35 -08: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
benedikt-bartscher
8903ebb8b0
add webdriver option arguments via env (#2783)
* add webdriver option arguments via env

* forgot to split the args
2024-03-06 17:13:40 -08:00
Masen Furer
ecb4dbaea9
[REF-2098] Allow overlay Close components to have on_click handlers (#2793)
* [REF-2098] Allow overlay Close components to have on_click handlers

The child of the Radix *Close components are passed `asChild`, meaning they are
treated as the direct child of the Close itself. This causes the `on_click`
handler attached to such an element to override the default `on_click` behavior
of the Close, which is to close the overlay, thus breaking the desired behavior
of the Close component.

When creating a Close component, if the child has an `on_click` handler, then
internally wrap it in a `Flex` so that the `Flex` gets the `asChild` treatment,
and both the default on_click and the child's on_click are both fired.

Bonus fix: pass `asChild` when constructing the `DrawerClose` to avoid a
<button> in <button> warning in the browser console, because the Drawer does
NOT pass `asChild` to the Close by default.

* Move Trigger logic to RadixThemesTriggerComponent base class

Apply trigger logic to Trigger, Close, Cancel, and Accept components; including
hover_card and dropdown_menu.
2024-03-06 17:09:46 -08:00
Nikhil Rao
c61419a761
Unwrap images in rx.markdown (#2789) 2024-03-06 16:03:33 -08:00
Masen Furer
77d551f781
[REF-1994] ThemePanel: clear chakra-ui-color-mode key when using theme panel (#2799)
The ThemePanel fights with the ThemeProvider when the user color preference key differs from the `appearance` prop specified in the theme. To avoid issues when using the ThemePanel (in development), clear out the user color preference before loading the page and before unloading the page (to ensure it does not freeze on reload).

Clearing the user preference isn't ideal production behavior, but typically the
ThemePanel is only used during development for trying out different styles, and
having it not freeze the app is better dev behavior.

Fix #2650
2024-03-06 15:32:08 -08:00
Masen Furer
03aa28320a
Perf improvements (part 1) (#2779)
* types: remove runtime imports from `is_generic_alias`

Reduce try/except contexts for better performance.

* _decode_var optimizations:

* compile the regex once at module scope
* fast path string scan for REFLEX_VAR_OPENING_TAG before doing more complex logic

* Avoid repeated `hasattr` check in `is_union`

`is_union` gets called a lot, and the hasattr check can be resolved at import
time for better performance.
2024-03-06 10:42:20 -08:00
Carlos Llatser
2125701c2d
Fix encoding of the .gitignore file on Windows (#2797) 2024-03-06 09:40:55 -08:00
Thomas Brandého
1b207eb444
fix template (#2787) 2024-03-05 16:10:44 -08:00
Masen Furer
c79719f7be
Expose on_drop event trigger for rx.upload component. (#2766)
* Expose `on_drop` event trigger for rx.upload component.

If `on_drop` is provided, it should be an EventSpec accepting the special
rx.upload_files() arg.

When `on_drop` is provided, it will be called immediately when files are
selected. The default functionality of saving a file list to be uploaded later
will not be available.

* update pyi file

* Undeprecate explicit EventChain
2024-03-05 12:07:36 -08:00
Masen Furer
75b63cbc25
[REF-2087] Better rx.progress styling integration with radix themes (#2762)
* [REF-2087] Better rx.progress styling integration with radix themes

Support the `radius` prop on `ProgressRoot`, via data-radius and CSS tokens

Support the `color_scheme` on `ProgressIndicator`, via data-accent-color and CSS token

Move high-level `Progress` to a real `Component` subclass to get better pyi hinting

Allow overriding the background color of the `ProgressIndicator` via low-level api

Remove `value` and `max` props from `ProgressRoot` (these only apply to `ProgressIndicator`)

* Progress: do not pass `value` or `max` to ProgressRoot

* progress: use background_color instead of background-color
2024-03-05 12:07:20 -08:00
Masen Furer
e4c32e3edf
Include app.Dockerfile for deploying to container hosting platform (#2784) 2024-03-05 09:28:32 -08:00
Masen Furer
fc190c8c8f
app_module_for_backend: wait for _compile in prod mode (#2760)
* Expose reflex.utils.exec.is_prod_mode

Formalize runtime checking of the app's `--env` parameter.

* app_module_for_backend: wait for _compile in prod mode

Prod mode uses separate worker processes that fork from the main process.

If the app is not fully compiled when the fork occurs, any further changes to
the app (like mounting the _upload endpoint) will not be reflected in the
workers. This is not a performance hit because compile is skipped anyway
for backend processes and hot reload is not in the picture for prod mode.

* remove _is_dev_mode and replace it with calls to is_prod_mode()

_is_dev_mode was a private function in the compiler, but now that utils.exec
exposes is_prod_mode, we should use that throughout for consistency
2024-03-04 16:50:31 -08:00
Martin Xu
02bedca32e
bump up httpx to >= 0.25.1 (Add support for Python 3.12) (#2782) 2024-03-04 16:38:55 -08:00
Masen Furer
e8faec708e
docker-example overhaul (#2690)
* docker-example overhaul

Update docker-example with a more realistic multi-compose deployment, and
also a more simplistic single-image deploy.

* Use `uv` for faster bootstrapping
* Separate simple and production-ready docker files
* Split compose.yaml into 3 parts
  * Persist sqlite db and tls keys
  * Include postgres and redis
  * Include Adminer and redis-commander for adminstration
  * Suppose upload persistence
* Update documentation
* Update Caddyfile for compatibility with new Upload API

* Simple Dockerfile: keep `reflex export --frontend-only`

Pre-pack the resulting image with npm dependencies to reduce startup time

* Simplify simple docker file to just use pip
2024-03-04 16:21:37 -08:00
Masen Furer
ebd84b39f8
Bump to 0.4.3 (#2780) 2024-03-04 14:49:52 -08:00
Masen Furer
4f12d2e269
Fix infinite recursion when a substate named "state" has a computed var (#2778)
* test_potentially_dirty_substates: when a state named State should be computed

Catch a regression introduced in 0.4.3a1

* _potentially_dirty_substates: qualify substate name

When looking up substate classes, ensure the qualified name is used to avoid
issues with same-named substates.
2024-03-04 13:13:08 -08:00
Masen Furer
9327bfaa71
Mark Upload.is_used when calling get_upload_url (#2765) 2024-03-03 19:47:17 -08:00
Pablo GS
bbb9253985
Solved Nodejs prerequisite check (#2767) 2024-03-03 19:47:05 -08:00
macmoritz
9e0452beb0
pass lang and custom_attrs from app to html root (#2697)
* pass lang and custom_attrs from app to html root

* fix some pre-commit errors and try adding lang

* fix tests

* really fix test

* cleanup with @benedikt-bartscher

* fix props and tests

* use str instead of var

* change typing of html_custom_attrs to not allow Vars
2024-03-03 13:51:20 -08:00
Martin Xu
5cb1f2007c
remove pipdeptree as reflex dep (#2763) 2024-03-03 09:55:21 -08:00
Frank Bold Society
ab6ebfc1a8
Update CSS padding in accordion.py (#2759)
Typo in default padding for AccordionContent.

"15px, 20px" lead to invalid CSS.

"15px 20px" is correct.
2024-03-01 12:32:44 -08:00
Yummy-Yums
7725c48fb7
Reconnection Logic (#2743)
* reconnection logic

* prettier state.js

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-02-29 16:21:35 -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
wassaf shahzad
0a18eaa28b
DRAFT PR - Added code for computed backend vars (#2540)
* added code for computed backend vars

* fixed formatting issues

* fix small bug

* fixes ruff issue

* fixed black issue

* augment test for backend computed var

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-02-29 13:00:41 -08:00
Thomas Brandého
cc678e8648
add pulser for connection + adjust condition for connnection_modal (#2676)
* add pulser for connection + adjust condition for connnection_modal

* update style for connection pulser

* rename connectError to connectErrors

* resolve update bug of connectErrors

* fix pulse definition

* rollback pulse definition

* Define WifiOffPulse icon as its own component

Attach the pulse keyframes and imports to the icon itself so that the code gets
properly included in stateful_components.js when it is used.

* limit number of errors in memory

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-02-29 19:01:12 +01:00
Thomas Brandého
bea9eb4349
fix drawer on_open_change event (#2755) 2024-02-29 18:04:59 +01:00
Martin Xu
4f9cdd6472
Add support for custom components starter (#2314) 2024-02-28 15:25:26 -08:00
benedikt-bartscher
c465b94016
add some backend var state inheritance tests (#2685) 2024-02-28 15:11:14 -08:00
benedikt-bartscher
e70c149752
call default_factorys on State.reset (#2749) 2024-02-28 14:55:22 -08:00
Thomas Brandého
3bcd0672e5
update templates radix sidebar (#2705) 2024-02-28 14:52:24 -08:00
benedikt-bartscher
2d56441a28
fix black+ruff (#2750) 2024-02-28 14:51:50 -08:00
Amir Molavi
842c7e6882
Add config to rx.plotly component (#2745) 2024-02-28 12:44:33 -08:00
Thomas Brandého
2062c1dd05
fix initial value for color_mode (#2741)
* fix initial value for color_mode

* better fix
2024-02-28 03:31:38 +01:00
Elijah Ahianyo
7ec7f031a3
Only alert users of reflex upgrade once per project (#2731) 2024-02-27 17:12:21 -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
Carlos Llatser
bf07315cb4
Add header tag for exporting its corresponding component (#2732) 2024-02-27 09:58:31 -08:00
Thomas Brandého
467fb794da
fix telemetry for init event (#2736) 2024-02-27 18:53:57 +01:00
Chris Davis
39175f5812
Update sidebar template README.md (#2735) 2024-02-27 09:50:26 -08:00
Masen Furer
fc874e2ece
Avoid frontend errors with getRefValue (#2691) 2024-02-26 19:38:02 -08:00
Masen Furer
350a051a45
[REF-1741] Disallow routes with /api prefix (#2711) 2024-02-26 19:34:51 -08:00
Thomas Brandého
0464a7723e
remove chakra from markdown component_map (#2709) 2024-02-26 19:34:22 -08:00