Commit Graph

100 Commits

Author SHA1 Message Date
Nikhil Rao
7903a1020d
Clean up config and app API (#3197) 2024-05-02 18:15:28 -07:00
Angelina Sheyko
4b6a7ff8e3
Fixed unused kwargs in reflex.App (#3170) 2024-04-29 13:53:27 -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
Ihor
415ce5557c
fix: args issue in __init__ of App class (#3140) (#3141) 2024-04-22 15:43:16 -07:00
benedikt-bartscher
0a1ff38920
separate DECORATED_PAGES per reflex app (#3102) 2024-04-22 11:32:31 -07:00
Masen Furer
6ca5f48ae7
[REF-2587] Ignore top-level theme appearance (#3119)
* pyi_generator: ignore `app.py` and single files

When running pyi_generator in pre-commit, it passes individual changed files on
the command line as targets, and these were not being properly excluded
according to the EXCLUDED_FILES list.

Add app.py to the EXCLUDED_FILES list so it does not get regenerated
automatically.

* [REF-2587] Ignore top-level theme appearance

From the Radix docs, it is not recommended to actually set `appearance`, but
instead use next-themes to set and switch the appearance dynamically.

Because Reflex already compiles the top-level theme into the next-themes
ThemeProvider, we can blank out the appearance prop after compiling contexts.js
to avoid a mismatch between the selected app appearance and the appearance in
the rx.theme when displaying overlay components.

Fix #2992
2024-04-19 14:43:45 -07:00
Masen Furer
1a11941577
[REF-2392] Expose next.config.js transpilePackages key (#3006) 2024-04-11 13:50:42 -07:00
Martin Xu
5274f04b66
[REF-2296] Rename recursive functions (#2999) 2024-04-04 09:26:31 -07:00
Thomas Brandého
bf0ebb8d09
Lendemor/improve coverage (#2988)
* add more tests

* add tests to raise coverage

* more tests, bump coverage to 73

* fix up icon_button test

* fix darglint for app.py

* fix utcnow usage warning

* set threshold to 72

* fix timestamp

* fix unit tests for linux-redis

* removed commented code and put a TODO
2024-04-04 14:31:43 +02:00
Elijah Ahianyo
d43a85bab2
Unpack component tuples in a fragment (#2985) 2024-04-03 10:44:04 -07:00
Malte Klemm
86526cba51
[REF-2127] Loosen requirements (#2796)
* Remove upper bounds of most dependencies.

Also adds a import try except block for pydantic.v1 and relocks.

Keep black and ruff to not mess to much with current formatting

Make pyright see the right import as long as constraint still lock pydantiv v1

Down pin pytest-asyncio again due to known issue

Fix upload handler with latest versions of fastapi

Change comment

* Add changed lockfile

* Set max versions for deps

* Revert app.pyi

---------

Co-authored-by: Malte Klemm <malte.klemm@blueyonder.com>
Co-authored-by: Nikhil Rao <nikhil@reflex.dev>
2024-03-29 09:26:53 -07:00
Masen Furer
7debd3dbb9
When __REFLEX_SKIP_COMPILE == "yes" allow telemetry to fail (#2881)
* When __REFLEX_SKIP_COMPILE == "yes" allow telemetry to fail

Allow running `--backend-only` without a .web directory

* When re-initializing a pre-project_hash project, do not blow up on KeyError
2024-03-19 14:30:55 -07:00
Masen Furer
ee1ff7f93f
[REF-2122] Opt-in multiprocess compile (#2838)
* Revert "Revert "Revert "Revert "use process pool to compile faster (#2377)" (#2434)" (#2497)" (#2595)"

This reverts commit 6b6eea4d7d.

* Adjust number of operations for more correct progress bar

* app: recognize REFLEX_COMPILE_PROCESSES and REFLEX_COMPILE_THREADS

Control whether multiprocessing is used and the number of processes or threads
that should be used.

This will allow users to opt-in to the new, potentially hazardous,
multiprocessing mode, which results in much faster compiles, but has already
been reverted 4 times. Lets leave the code in this time, but use the thread
pool executor by default.

Limiting the number of threads or processes to 1 can also aid in debugging
issues that arise during compile time.

* Allow REFLEX_COMPILE_PROCESSES=0 to trigger multiprocessing with auto workers
2024-03-15 17:29:52 -07:00
Masen Furer
432fcd4a5b
Account for imports of @rx.memo components for frontend package installation (#2863)
* CustomComponent ignores the annotation type in favor of the passed value

Do not require rx.memo wrapped functions to have 100% correct annotations.

* test_custom_component_get_imports: test imports from wrapped custom components

* Account for imports of custom components for frontend installation

Create new ImportVar that only install the package to avoid rendering the
imports in the page that contains the custom component itself.

* Handle Imports that should never be installed

* Fix up double negative logic

* Perf Optimization: use the imports we already calculate during compile

Instead of augmenting _get_imports with a weird, slow, recursive crawl and
dictionary reconstruction, just use the imports that we compile into the
components.js file to install frontend packages needed by the custom
components.

Same effect, but adds essentially zero overhead to the compilation.
2024-03-15 09:59:59 -07:00
Masen Furer
fb2c3606d9
Get client_ip from asgi.scope (#2808)
* Get `client_ip` from `asgi.scope`

It seems like REMOTE_ADDR is always 127.0.0.1, which is not super useful when
trying to figure out where the websocket connection is originating from.

Of course this isn't a silver bullet because most-likely the WS will be passed
through a reverse proxy anyway... in that case, the client IP is likely in the
headers under `x_forwarded_for`

* client_ip: fallback to REMOTE_ADDR
2024-03-14 10:03:30 -07:00
Thomas Brandého
e5fc5f9a83
better default title for seo (also remove default description) (#2844)
* better default title for seo (also remove default description)
2024-03-13 11:18:54 -07:00
Masen Furer
eb18ce90d5
[REF-2172] Add DECORATED_PAGES before compiling in thread (#2841) 2024-03-12 10:28:37 -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
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
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
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
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
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
Masen Furer
421bfa034a
Apply app theme color_mode/appearance as next-themes default (#2654)
* Apply app theme color_mode/appearance as next-themes default

* compiler: blacken
2024-02-22 10:14:38 -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
Nikhil Rao
4ad238c42c
Update deprecation version to 0.5.0 (#2642) 2024-02-16 11:23:15 -08:00
Nikhil Rao
7240f8ee6f
Handle component namespaces in global styles (#2630) 2024-02-15 16:03:10 -08:00
jackie-pc
6b6eea4d7d
Revert "Revert "Revert "use process pool to compile faster (#2377)" (#2434)" (#2497)" (#2595) 2024-02-13 12:16:35 -08:00
Masen Furer
b5f06991a9
Change names to get_upload_dir and get_upload_url (#2587)
These shorter names are more concise and easier to type without losing
significant information.
2024-02-13 11:09:48 -08:00
Masen Furer
10e8bd010c
Upload Workflow Refactor (#2309)
* upload with StaticFiles

* always create uploaded files folder

* just use /_upload to serve uploaded files

* Upload: update pyi file

* app.py: only mount Upload StaticFiles if the upload component is used
2024-02-12 12:21:56 -08:00
Masen Furer
6d33156d15
Move is_used to Upload component rather than UploadFilesProvider (#2514) 2024-02-01 17:57:43 -08:00
jackie-pc
80dce21ac0
Revert "Revert "use process pool to compile faster (#2377)" (#2434)" (#2497) 2024-01-31 11:38:28 -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
0b1b8ee639
auto enable /_upload endpoint only if Upload component is used (#2430) 2024-01-23 12:20:06 -08:00
Nikhil Rao
f513f4c089
Revert "use process pool to compile faster (#2377)" (#2434) 2024-01-22 12:56:07 -08:00
Nikhil Rao
2abecbdb9c
Remove default radix theme (#2403) 2024-01-18 15:25:23 -08:00
jackie-pc
2c270585ab
Skip frontend packages install if previously done (#2400) 2024-01-16 17:52:28 -08:00
jackie-pc
a8756cb0f8
use process pool to compile faster (#2377) 2024-01-12 14:22:18 -08:00
Masen Furer
87844c3f7d
Enable real app AppHarness tests to not specify state= (#2358) 2024-01-05 17:47:31 -08:00
Elijah Ahianyo
abfc099779
rx.match component (#2318)
* initial commit

* add more tests

* refactor match jinja template

* add docstrings

* cleanup

* possible fix for pyright

* fix conflicts

* fix conflicts again

* comments

* fixed bug from review

* fix tests

* address PR comment

* fix tests

* type error improvement

* formatting

* darglint fix

* more tests

* stringify switch condition and cases as js doesnt support complex types(lists and dicts) in switch cases.

* Update reflex/vars.py

Co-authored-by: Masen Furer <m_github@0x26.net>

* change usages

* Precommit fix

---------

Co-authored-by: Alek Petuskey <alek@pynecone.io>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Alek Petuskey <alekpetuskey@aleks-mbp.lan>
2024-01-04 09:48:18 -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
Thomas Brandého
527fa4bc3f
Add slider, progress, and form primitives (#2306) 2023-12-21 10:32:40 -08:00
Nikhil Rao
93c97383d9
Refactor chakra components into separate folder (#2315) 2023-12-21 09:52:08 -08:00
Nikhil Rao
cfb9d44e0c
Apply default theme to apps (#2320) 2023-12-20 15:17:49 -08:00
jackie-pc
7388617b72
apps should no longer call "app.compile()" (#2291) 2023-12-18 16:06:21 -08:00
Nikhil Rao
96f68cb94d
Implement accordion component (#2262)
* Implement accordion component

* Fix literal annotation

* Use style prop instead of css

* Move accordion to primitives folder

* Add pyi file

* Fix pyright

* Add apply_theme method

* Fix apply_theme

* Use apply_theme method

* Fix lint
2023-12-08 21:20:30 -08:00
Thomas Brandého
1109f8f508
deprecate state arg in App() (#2237) 2023-12-01 09:50:40 -08:00
Elijah Ahianyo
e3ee98098a
RED-1052/rx.State as Base State (#2146) 2023-11-29 09:43:33 -08:00
Masen Furer
3deb2cec93
code_block responds to color mode by default (#2228) 2023-11-28 13:24:38 -08:00
Masen Furer
0c55723df4
[REF-1158] Move chakra-only deps to chakra lib (#2171) 2023-11-28 00:04:07 -08:00