* Track backend-only vars that are declared without a default value
Without this provision, declared backend vars can be accidentally shared among
all states if a mutable value is assigned to the class attribute.
* add test case for no default backend var
* remove format_state and override behavior for bare
* pass the test cases
* only do one level of dicting dataclasses
* remove dict and replace list with set
* delete unnecessary serialize calls
* remove serialize for mutable proxy
* dang it darglint
* EventFnArgMismatch fix to support defaults args
* fixing type hint and docstring raises
* enforce stronger type checking
* unwrap var annotations :(
---------
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
* lift node version restraint to allow more recent version if already installed
* add node test for latest version
* change python version
* use purple for debug logs
* update workflow
* add playwright dev dependency
* update workflow
* change test
* oops
* improve test
* update test
* fix tests
* mv units tests to a subfolder
* reorganize tests
* fix install
* update test_state
* revert node changes and only keep new tests organization
* move integration tests in tests/integration
* fix integration workflow
* fix dockerfile workflow
* fix dockerfile workflow 2
* fix shared_state
* allow classname to be state vars
* simplify join with all literal string vars
* add test case and avoid concat var operation if it's not necessary
* remove silly print statement
* simplify case where there's no var
* don't automatically do class name str to literal var
* Revert "ruff formatting to unbreak `main` CI (#3964)"
This reverts commit f9be184b86.
* Revert "bump python>=3.10 for 0.6.0 (#3956)"
This reverts commit fe1833c5e1.
* drop python3.8 support
* relock dependencies
* Raise warning when < py310 is used
* Move python version check to reflex version check function
Avoid spammy deprecation warnings by only emitting warning once per project,
per reflex version, per reinit.
* Remove other references to python3.8
* [WiP] Support UI components returned from a computed var
* Get rid of nasty react hooks warning
* include @babel/standalone in the base to avoid CDN
* put window variables behind an object
* use jsx
* implement the thing
* cleanup dead test code (#3909)
* override dict in propsbase to use camelCase (#3910)
* override dict in propsbase to use camelCase
* fix underscore in dict
* dang it darglint
* [REF-3562][REF-3563] Replace chakra usage (#3872)
* [ENG-3717] [flexgen] Initialize app from refactored code (#3918)
* Remove Pydantic from some classes (#3907)
* half of the way there
* add dataclass support
* Forbid Computed var shadowing (#3843)
* get it right pyright
* fix unit tests
* rip out more pydantic
* fix weird issues with merge_imports
* add missing docstring
* make special props a list instead of a set
* fix moment pyi
* actually ignore the runtime error
* it's ruff out there
---------
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
* Merging
* fixss
* fix field_name
* always import react
* move func to file
* do some weird things
* it's really ruff out there
* add docs
* how does this work
* dang it darglint
* fix the silly
* don't remove computed guy
* silly goose, don't ignore var types :D
* update code
* put f string on one line
* make it deprecated instead of outright killing it
* i hate it
* add imports from react
* assert it has evalReactComponent
* do things ig
* move get field to global context
* ooops
---------
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
* add few test cases for bool
* use parametrize
* use a tuple of strings
Co-authored-by: Masen Furer <m_github@0x26.net>
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* delete most references to varr
* [REF-3562][REF-3563] Replace chakra usage (#3872)
* only one mention of var
* delete vars.py why not
* remove reflex.vars
* rename immutable var to var
* rename ivars to vars
* add vars back smh
* ruff
* no more create_safe
* reorder deprecated
* remove raises
* remove all Var.create
* move to new api
* fix unit tests
* fix pyi hopefully
* sort literals
* fix event handler issues
* update poetry
* fix silly issues i'm very silly
* add var_operation_return
* rename immutable to not immutable
* add str type
* it's ruff out there
---------
Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
* half of the way there
* add dataclass support
* Forbid Computed var shadowing (#3843)
* get it right pyright
* fix unit tests
* rip out more pydantic
* fix weird issues with merge_imports
* add missing docstring
* make special props a list instead of a set
* fix moment pyi
* actually ignore the runtime error
* it's ruff out there
---------
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
* fix dynamic route vars silently shadow all other vars
* add test
* fix: allow multiple dynamic routes with the same arg
* add test for multiple dynamic args with the same name
* avoid side-effects with DynamicState tests
* fix dynamic route integration test which shadowed a var
* fix darglint
* refactor to DynamicRouteVar
* old typing stuff again
* from typing_extensions import Self
try to keep typing backward compatible with older releases we support
* Raise a specific exception when encountering dynamic route arg shadowing
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* fix: Adding type propagation to ToStringOperation.
* fix: Better naming.
* fix: Added test that fails without the fix.
* Update reflex/ivars/base.py
Co-authored-by: Masen Furer <m_github@0x26.net>
* Retain mutability inside `async with self` block (#3884)
When emitting a state update, restore `_self_mutable` to the value it had
previously so that `yield` in the middle of `async with self` does not result
in an immutable StateProxy.
Fix#3869
* Include child imports in markdown component_map (#3883)
If a component in the markdown component_map contains children components, use
`_get_all_imports` to recursively enumerate them.
Fix#3880
* [REF-3570] Remove deprecated REDIS_URL syntax (#3892)
* fix: Instead of researching the type after dropping it, preserve it.
* Apply suggestions from code review
Co-authored-by: Masen Furer <m_github@0x26.net>
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* use serializer system
* add checks for unsupported operands
* and and or are now supported
* format
* remove unnecessary call to JSON
* put base before rest
* fix failing testcase
* add hinting to get static analysis to complain
* damn
* big changes
* get typeguard from extensions
* please darglint
* dangit darglint
* remove one from vars
* add without data and use it in plotly
* DARGLINT
* change format for special props
* add pyi
* delete instances of Var.create
* modify client state to work
* fixed so much
* remove every Var.create
* delete all basevar stuff
* checkpoint
* fix pyi
* get older python to work
* dangit darglint
* add simple fix to last failing testcase
* remove var name unwrapped and put client state on immutable var
* fix older python
* fox event issues
* change forms pyi
* make test less strict
* use rx state directly
* add typeignore to page_id
* implement foreach
* delete .web states folder silly
* update reflex chakra
* fix issue when on mount or on unmount is not set
* nuke Var
* run pyi
* import immutablevar in critical location
* delete unwrap vars
* bring back array ref
* fix style props in app
* /health endpoint for K8 Liveness and Readiness probes (#3855)
* Added API Endpoint
* Added API Endpoint
* Added Unit Tests
* Added Unit Tests
* main
* Apply suggestions from Code Review
* Fix Ruff Formatting
* Update Socket Events
* Async Functions
* Update find_replace (#3886)
* [REF-3592]Promote `rx.progress` from radix themes (#3878)
* Promote `rx.progress` from radix themes
* fix pyi
* add warning when accessing `rx._x.progress`
* Use correct flexgen backend URL (#3891)
* Remove demo template (#3888)
* gitignore .web (#3885)
* update overflowY in AUTO_HEIGHT_JS from hidden to scroll (#3882)
* Retain mutability inside `async with self` block (#3884)
When emitting a state update, restore `_self_mutable` to the value it had
previously so that `yield` in the middle of `async with self` does not result
in an immutable StateProxy.
Fix#3869
* Include child imports in markdown component_map (#3883)
If a component in the markdown component_map contains children components, use
`_get_all_imports` to recursively enumerate them.
Fix#3880
* [REF-3570] Remove deprecated REDIS_URL syntax (#3892)
* mixin computed vars should only be applied to highest level state (#3833)
* improve state hierarchy validation, drop old testing special case (#3894)
* fix var dependency dicts (#3842)
* Adding array to array pluck operation. (#3868)
* fix initial state without cv fallback (#3670)
* add fragment to foreach (#3877)
* Update docker-example (#3324)
* /health endpoint for K8 Liveness and Readiness probes (#3855)
* Added API Endpoint
* Added API Endpoint
* Added Unit Tests
* Added Unit Tests
* main
* Apply suggestions from Code Review
* Fix Ruff Formatting
* Update Socket Events
* Async Functions
* /health endpoint for K8 Liveness and Readiness probes (#3855)
* Added API Endpoint
* Added API Endpoint
* Added Unit Tests
* Added Unit Tests
* main
* Apply suggestions from Code Review
* Fix Ruff Formatting
* Update Socket Events
* Async Functions
* Merge branch 'main' into use-old-serializer-in-literalvar
* [REF-3570] Remove deprecated REDIS_URL syntax (#3892)
* /health endpoint for K8 Liveness and Readiness probes (#3855)
* Added API Endpoint
* Added API Endpoint
* Added Unit Tests
* Added Unit Tests
* main
* Apply suggestions from Code Review
* Fix Ruff Formatting
* Update Socket Events
* Async Functions
* [REF-3570] Remove deprecated REDIS_URL syntax (#3892)
* remove extra var
Co-authored-by: Masen Furer <m_github@0x26.net>
* resolve typo
* write better doc for var.create
* return var value when we know it's literal var
* fix unit test
* less bloat for ToOperations
* simplify ImmutableComputedVar.__get__ (#3902)
* simplify ImmutableComputedVar.__get__
* ruff it
---------
Co-authored-by: Samarth Bhadane <samarthbhadane119@gmail.com>
Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
Co-authored-by: Vishnu Deva <vishnu.deva12@gmail.com>
Co-authored-by: abulvenz <a.eismann@senbax.de>
* add var_operations and move some operations to the new style
* change bound style
* can't assume int anymore
* slice is not hashable (how did this work bef)
* convert to int explicitly
* move the rest of the operations to new style
* fix bool guess type
* forgot to precommit dangit
* add type ignore to bool for now
* implement disk state manager
* put states inside of a folder
* return root state all the time
* factor out code
* add docs for token expiration
* cache states directory
* call absolute on web directory
* change dir to app path when testing the backend
* remove accidental 🥒
* test disk for now
* modify schema
* only serialize specific stuff
* fix issue in types
* what is a kilometer
* create folder if it doesn't exist in write
* this code hates me
* check if the file isn't empty
* add try except clause
* add check for directory again
* test_component: improve valid/invalid event trigger tests
Add test cases for event triggers defined as annotations.
Add additional cases around lambda returning different values.
Improve assertions for invalid tests (each line needs its own `pytest.raises`).
More invalid test cases.
* [REF-3589] raise EventHandlerArgMismatch when event handler args don't match spec
Improve error message for common issue.
Previously when the event handler arguments didn't match the spec, the
traceback resulted in:
```
OSError: could not get source code
```
Now this problem is traceable as a distinct error condition and users are
empowered to debug their code and reference the documentation (to be updated)
for further information.
* raise EventFnArgMismatch when lambda args don't match event trigger spec
Improve error message for another common issue encountered in the reflex framework.
Previous error message was
```
TypeError: index.<locals>.<lambda>() takes 0 positional arguments but 1 was given
```
* Fix up lambda test cases
* call_event_fn: adjust number of args for bound methods
* fully migrate vars into new system
* i hate rufffff (no i don't)
* fix silly pright issues (except colormode and state)
* remove all instances of Var.create
* create immutable callable var and get rid of more base vars
* implement hash for all functions
* get reflex-web to compile
* get it to compile reflex-web successfully
* fix tests
* fix pyi
* use override from typing_extension
* put plotly inside of a catch
* dicts are unusable sadly
* fix silly mistake
* overload equals to special case immutable var
* improve test_cond
* solve more CI issues, down to 94 failures
* down to 20 errors
* down to 13 errors
* pass all testcases
* fix pyright issues
* reorder things
* use get origin more
* use fixed_type logic
* various optimizations
* go back to passing test cases
* use less boilerplate
* remove unnecessary print message
* remove weird comment
* add test for html issue
* add type ignore
* fix another silly issue
* override get all var data for var operations call
* make integration tests pass
* fix immutable call var
* better logic for finding parent class
* use even better logic for finding state wrt computedvar
* only choose the ones that are defined in the same module
* small dict to large dict
* [REF-3591] Remove chakra-related files from immutable vars PR (#3821)
* Add comments to html metadata component (#3731)
* fix: add verification for path /404 (#3723)
Co-authored-by: coolstorm <manas.gupta@fampay.in>
* Use the new state name when setting `is_hydrated` to false (#3738)
* Use `._is_mutable()` to account for parent state proxy (#3739)
When a parent state proxy is set, also allow child StateProxy._self_mutable to
override the parent's `_is_mutable()`.
* bump to 0.5.9 (#3746)
* add message when installing requirements.txt is needed for chosen template during init (#3750)
* #3752 bugfix add domain for XAxis (#3764)
* fix appharness app_source typing (#3777)
* fix import clash between connectionToaster and hooks.useState (#3749)
* use different registry when in china, fixes#3700 (#3702)
* do not reload compilation if using local app in AppHarness (#3790)
* do not reload if using local app
* Update reflex/testing.py
Co-authored-by: Masen Furer <m_github@0x26.net>
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* Bump memory on relevant actions (#3781)
Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>
* [REF-3334] Validate Toast Props (#3793)
* [REF-3536][REF-3537][REF-3541] Move chakra components into its repo(reflex-chakra) (#3798)
* fix get_uuid_string_var (#3795)
* minor State cleanup (#3768)
* Fix code wrap in markdown (#3755)
---------
Co-authored-by: Alek Petuskey <alek@pynecone.io>
Co-authored-by: Manas Gupta <53006261+Manas1820@users.noreply.github.com>
Co-authored-by: coolstorm <manas.gupta@fampay.in>
Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>
Co-authored-by: Shubhankar Dimri <dimrishubhi@gmail.com>
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>
Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
* pyproject.toml: bump to 0.6.0a1
* pyproject.toml: depend on reflex-chakra>=0.6.0a
New Var system support in reflex-chakra 0.6.0a1
* poetry.lock: relock dependencies
* integration: bump listening timeout to 1200 seconds
* integration: bump listening timeout to 1800 seconds
* Use cached_var_no_lock to avoid ImmutableVar deadlocks (#3835)
* Use cached_var_no_lock to avoid ImmutableVar deadlocks
ImmutableVar subclasses will always return the same value for a _var_name or
_get_all_var_data so there is no need to use a per-class lock to protect a
cached attribute on an instance, and doing so actually is observed to cause
deadlocks when a particular _cached_var_name creates new LiteralVar instances
and attempts to serialize them.
* remove unused module global
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Alek Petuskey <alek@pynecone.io>
Co-authored-by: Manas Gupta <53006261+Manas1820@users.noreply.github.com>
Co-authored-by: coolstorm <manas.gupta@fampay.in>
Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>
Co-authored-by: Shubhankar Dimri <dimrishubhi@gmail.com>
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>
Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
* half of the way there
* implement __getitem__ for array
* add some tests
* add fixes to pyright
* fix default factory
* implement array operations
* format code
* fix pyright issue
* give up
* add object operations
* add test for merge
* pyright 🥺
* use str isntead of _var_name
Co-authored-by: Masen Furer <m_github@0x26.net>
* wrong var_type
* make to much nicer
* add subclass checking
* enhance types
* use builtin list type
* improve typing even more
* i'm awaiting october
* use even better typing
* add hash, json, and guess type method
* fix pyright issues
* add a test and fix lots of errors
* fix pyright once again
* add type inference to list
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* implement var operation decorator
* use older syntax
* use cast and older syntax
* use something even simpler
* add some tests
* use old union tactics
* that's not how you do things
* implement arithmetic operations while we're at it
* add test
* even more operations
* can't use __bool__
* thanos snap
* forgot ruff
* use default factory
* dang it darglint
* i know i should have done that but
* convert values into literalvars
* make test pass
* use older union tactics
* add test to string var
* pright why do you hate me 🥺
* [REF-3184] Raise exception when encountering nested `async with self` blocks
Avoid deadlock when the background task already holds the mutation lock for a
given state.
* [REF-3339] get_state from background task links to StateProxy
When calling `get_state` from a background task, the resulting state instance
is wrapped in a StateProxy that is bound to the original StateProxy and shares
the same async context, lock, and mutability flag.
* If StateProxy has a _self_parent_state_proxy, retrieve the correct substate
* test_state fixup
* implement more literal vars
* fix super issue
* pyright has a bug i think
* oh we changed that
* fix docs
* literalize vars recursively
* do what masen told me :D
* use dynamic keys
* forgot .create
* adjust _var_value
* dang it darglint
* add test for serializing literal vars into js exprs
* fix silly mistake
* add handling for var and none
* use create safe
* is none bruh
* implement function vars and do various modification
* fix None issue
* clear a lot of creates that did nothing
* add tests to function vars
* added simple fix smh
* use fconcat to make an even more complicated test
* implement LiteralStringVar and format/retrieval mechanism
* use create safe
* add cached properties to ConcatVarOperation
* fix caches
* also include self
* fix inconsistencies in typings
* use default factory not default
* add missing docstring
* experiment with immutable var data
* solve pydantic issues
* add sorted function
* missing docs
* forgot ellipses
* give up on frozen
* dang it darglint
* fix string serialization bugs and remove unused code
* add returns statement
* whitespace moment
* add simple test for string concat
* export ConcatVarOperation
* implement format for immutable vars
* add some basic test
* make reference only after formatting
* win over pyright
* hopefully now pyright doesn't hate me
* forgot some _var_data
* i don't know how imports work
* use f_string var and remove assignments from pyi file
* override post_init to not break immutability
* add create_safe and test for it
* add module prefix to state names
* fix state names in test_app
* update state names in test_state
* fix state names in test_var
* fix state name in test_component
* fix state names in test_format
* fix state names in test_foreach
* fix state names in test_cond
* fix state names in test_datatable
* fix state names in test_colors
* fix state names in test_script
* fix state names in test_match
* fix state name in event1 fixture
* fix pyright and darglint
* fix state names in state_tree
* fix state names in redis only test
* fix state names in test_client_storage
* fix state name in js template
* add `get_state_name` and `get_full_state_name` helpers for `AppHarness`
* fix state names in test_dynamic_routes
* use new state name helpers in test_client_storage
* fix state names in test_event_actions
* fix state names in test_event_chain
* fix state names in test_upload
* fix state name in test_login_flow
* fix state names in test_input
* fix state names in test_form_submit
* ruff
* validate state module names
* wtf is going on here?
* remove comments leftover from refactoring
* adjust new test_add_style_embedded_vars
* fix state name in state.js
* fix integration/test_client_state.py
new SessionStorage feature was added with more full state names that need to be formatted in
* fix pre-commit issues in test_client_storage.py
* adjust test_computed_vars
* adjust safe-guards
* fix redis tests with new exception state
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* fix: unexpected kwargs raise type error, on _replace
* add: docstring for _replace, test for invalid kwargs replace
* add: parametrize var for replace test
* fix: computed_var _replace with invalid kwargs
* add computed backend vars
* finish computed backend vars, add tests
* fix token for AppHarness with redis state manager
* fix timing issues
* add unit tests for computed backend vars
* automagically mark cvs with _ prefix as backend var
* fully migrate backend computed vars
* rename is_backend_variable to is_backend_base_variable
* add integration test for implicit backend cv, adjust comments
* replace expensive backend var check at runtime
* keep stuff together
* simplify backend var check method, consistent naming, improve test typing
* fix: do not convert properties to cvs
* add test for property
* fix cached_properties with _ prefix in state cls
* Dont escape backticks in JS string interpolation
* add unit tests
* Fix darglint
* add a note to re-visit after new Var API is implemented
* tests should have a good meaning
* add bare sqlalchemy session, Closes#3512
* expose sqla_session at module level, add tests, improve typing
* fix table name
* add model_registry fixture, improve typing
* did not meant to push this
* add docstring to model_registry
* do not expose sqla_session in reflex namespace
* upgrade to latest ruff
* try to fix dep review
* try to fix dep review (2)
* upgrade black
* upgrade black (2)
* update allowed dependencies
* update allowed dependencies (2)
* update allowed dependencies (3)
* wait between interim and final in yield test
* remove previous commit, increase delay between yield
* forgot to save on the time.sleep(1) removal
* fix integration (maybe?)
* fix pyi?
* what even is going on
* what is realityi?
* test another fix for app harness
* try to wait even longer?
* force uvloop to be optional
* downpin fastapi < 0.111, remove changes to test
* `rx.color_mode.icon`, `rx.color_mode.button` and `rx.color_mode.switch` should not require a backend`
* remove print statement
* unit tests and precommit fix
* add unit tests
* change logic to check if event handlers actually contain state. Also delay websocket object check in state.js so server side events can get executed for stateless apps
* make sure events are not queued for server side events particularly ones that call queueEvents(clear_local_storage, clear_cookies, remove_local_storage, remove_cookies) when the app is stateless(no ws)
* fix unit tests
* fix broken unit tests in test_app
* modify socket check in processEvent to only return if socket exists and theres any event in the queue that requires state
* Apply suggestions from code review
make queueEvent call async
Co-authored-by: Masen Furer <m_github@0x26.net>
* await queueEventIfSocketExists
* Revert "await queueEventIfSocketExists"
This reverts commit 9ef8070b87.
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* wip type transforming serializers
* old python sucks
* typing fixups
* Expose the `to` parameter on `rx.serializer` for type conversion
Serializers can also return a tuple of `(serialized_value, type)`, if both ways
are specified, then the returned value MUST match the `to` parameter.
When initializing a new rx.Var, if `_var_is_string` is not specified and the serializer returns a `str` type, then mark `_var_is_string=True` to indicate that the Var should be treated like a string literal.
Include datetime, color, types, and paths as "serializing to str" type.
Avoid other changes at this point to reduce fallout from this change:
Notably, the `serialize_str` function does NOT cast to `str`, which
would cause existing code to treat all Var initialized with a str as a
str literal even though this was NOT the default before.
Update test cases to accomodate these changes.
* Raise deprecation warning for rx.Var.create with string literal
In the future, we will treat strings as string literals in the JS code. To get
a Var that is not treated like a string, pass _var_is_string=False.
This will allow our serializers to automatically identify cast string literals
with less special cases (and the special cases need to be explicitly
identified).
* Add test case for mismatched serialized types
* fix old python
* Remove serializer returning a tuple feature
Simplify the logic; instead of making a wrapper function that returns
a tuple, just save the type conversions in a separate global.
* Reset the LRU cache when adding new serializers
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* test_tailwind: include custom stylesheet
* [REF-3004] Use relative path to stylesheet for postcss-import compat
postcss-import balls all of the CSS up into a single file, which happens at
compile time. So, replace the `@/` with `../public` so the import paths can be
resolved relative to the `styles` directory.
* test_compiler: fix compile_stylesheets expectations
* Use constants.Dirs.PUBLIC instead of "public"
* init fix
* Update reflex/components/plotly/plotly.py
Co-authored-by: Masen Furer <m_github@0x26.net>
* plotly: treat `data` as a `dict`-type Var in _render
this allows the data to be passed directly as a figure or from a state var
* removed width height prop as they are no longer needed
* updated
* reverted some of the changes
* fixed unit tests
* regen pyi
---------
Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Hongyu Yao <hongyuyao@Hongyus-MacBook-Pro-3.local>
* Improve import times
* add lazy loading to rx.el
* add lazy loading to reflex core components
* minor refactor
* Get imports working with reflex web
* get imports to work with all reflex examples
* refactor to define imports only in the root.
* lint
* deadcode remove
* update poetry deps
* unit tests fix
* app_harness fix
* app_harness fix
* pyi file generate
* pyi file generate
* sort pyi order
* fix pyi
* fix docker ci
* rework pyi-generator
* generate pyi for __init__ files
* test pyright
* test pyright ci
* partial pyright fix
* more pyright fix
* pyright fix
* fix pyi_generator
* add rx.serializer and others
* add future annotation import which fixes container CI, then also load recharts lazily
* add new pyi files
* pyright fix
* minor fixes for reflex-web and flexdown
* forward references for py38
* ruff fix
* pyi fix
* unit tests fix
* reduce coverage to 68%
* reduce coverage to 67%
* reduce coverage to 66%as a workaround to coverage's rounding issue
* reduce coverage to 66%as a workaround to coverage's rounding issue
* exclude lazy_loader dependency review checks.
* its lazy-loader
* Add docstrings and regenerate pyi files
* add link
* address Pr comments
* CI fix
* partially address PR comments.
* edit docstrings and fix integration tests
* fix typo in docstring
* pyi fix
* feat: Optionally comparing fields, e.g. on rx.Base based types.
* feat: Minimally invasive change.
Leave the current implementation as is. Added test.
* fix: Supporting old-school python versions.
* fix: Adding masenf's suggestions to use var instead of string.
* Support replacing route on redirect
Support next/router `.replace` interface to change page without creating a
history entry.
* test_event: include test cases for new "replace" kwarg
* [REF-2787] add_hooks supports Var-wrapped hooks
* Fix VarData definition in .pyi file to allow removal of type ignore comments
* Var.create and Var.create_safe accept _var_data parameter
* Replace instances where a set of imports was being passed to VarData
* Update code throughout reduce use of `._replace` to add VarData
* Fixup: user hooks _var_data.imports will never be iterable, just a single ImportDict
* Allow `Component.add_style` to return a regular dict
It's more convenient to allow returning a regular dict without having to import
and wrap the value in `rx.style.Style`.
If the dict contains any Var or encoded VarData f-strings, these will be picked
up when the plain dicts are passed to Style.update().
Because Style.update already merges VarData, there is no reason to explicitly
merge it again in this function; this change keeps the merging logic inside the
Style class.
* Test for Style.update with existing Style with _var_data and kwargs
Should retain the _var_data from the original Style instance
* style: Avoid losing VarData in Style.update
If a Style class with _var_data is passed to `Style.update` along with kwargs,
then the _var_data was lost in the double-splat dictionary expansion.
Instead, only apply the kwargs to an existing or new Style instance to retain
_var_data and properly convert values.
* add_style return annotation is Dict[str, Any]
* nit: use lowercase dict in annotation
* Unit tests for add_style and component styles with foreach
The styles should be correctly applied for components that are rendered as part
of a foreach.
* [REF-2802] Foreach should respect modifications to children
Components are mutable, and there is logic that depends on walking through the
component tree and making modifications to components along the way. These
modifications _must_ be respected by foreach for consistency.
Modifications necessary to fix the bug:
* Change the hash function in `_render` to get a hash over the render_fn's
`__code__` object. This way we get a stable hash without having to call the
render function with bogus values.
* Call the render function once during `create` and save the result as a child
of the Foreach component (tree walks will modify this instance).
* Directly render the original (and possibly modified) child component instead
of calling the render_fn again and creating a new component instance at
render time.
Additional changes because they're nice:
* Deprecate passing `**props` to `rx.foreach`. No one should have been
doing this anyway, because it just does not work in any reasonable way.
* Raise `ForeachVarError` when the iterable type is Any
* Raise `ForeachRenderError` when the render function does not take 1 or 2 args.
* Link to the foreach component docs when either of those errors are hit.
* Change the `iterable` arg in `create` to accept `Var[Iterable] | Iterable`
for better typing support (and remove some type: ignore comments)
* Simplify `_render` and `render` methods -- remove unused and potentially
confusing code.
* Fixup: `to_bytes` requires `byteorder` arg before py3.11
* Allow EventHandler args to be partially applied
When an EventHandler is called with an incomplete set of args it creates a
partial EventSpec. This change allows Component._create_event_chain to apply
remaining args from an args_spec to an existing EventSpec to make it
functional.
Instead of requiring the use of `lambda` functions to pass arguments to an
EventHandler, they can now be passed directly and any remaining args defined in
the event trigger will be applied after those.
* [REF-2273] Implement `.setvar` special EventHandler
All State subclasses will now have a special `setvar` EventHandler which
appears in the autocomplete drop down, passes static analysis, and canbe used
to set State Vars in response to event triggers.
Before:
rx.input(value=State.a, on_change=State.set_a)
After:
rx.input(value=State.a, on_change=State.setvar("a"))
This reduces the "magic" because `setvar` is statically defined on all State
subclasses.
* Catch invalid Var names and types at compile time
* Add test cases for State.setvar
* Use a proper redis-compatible token
* test_foreach: assert on arg _var_type
* [REF-2682] Foreach over dict uses Tuple arg value
When iterating over a Var with _var_type dict, the resulting arg value
_var_type should be Tuple[key, value] so it can be correctly used with other
var operations.
Fix#3157
* Correct _var_type for iteration over Tuple of multiple types
The arg value when iterating over a tuple could be any of the possible values
mentioned in the annotation.
When only one type is used, the Union collapses to the base type, at least in py3.11
* Add comments
* 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
* build pyi files when building/publishing 3rd party
* fix typo in workflow
* add future annotation
* add tests to pass coverage check
* add more unit tests
* omit pyi_generator from test coverage
* change black from dev deps to direct deps
* remake all pyi
* format pyi if black is present, return as if otherwise
* fix requested changes
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* Add test_get_state_from_sibling_not_cached
A better unit test to catch issues with refetching parent states
and calculating the wrong parent state names to fetch.
* _determine_missing_parent_states: correctly generate state names
Prepend only the previous state name to the current relative_parent_state_name
instead of joining all of the previous state names together.
* [REF-2219] Avoid refetching states that are already cached
The already cached states may have unsaved changes which can be wiped out if
they are refetched from redis in the middle of handling an event.
If the root state already knows about one of the potentially missing states,
then use the instance that is already cached.
Fix#2851
* 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>
* [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
* add command to share custom component info for gallery
* cleanup
* tested
* Update custom_components.py
Co-authored-by: Masen Furer <m_github@0x26.net>
* reorder the questions
* ask user to verify info before publishing
* remove questions already captured in pyproject.toml
* no need to cache form inputs since not many questions
* tested
* cleanup
* delete test
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* Use dill instead of cloudpickle for serialization
* smaller size pickles
* support dynamically defined states
* avoid issues with unpickleable globals
* pyproject: add dill, remove cloudpickle
* poetry.lock: relock dependencies
* Dynamically convert EventHandler to functools.partial
Instead of converting the functions up front and assigning them to the
instance, unbox the function from the EventHandler when it is requested via
__getattribute__. This reduces the size of the per-instance pickle, because
event handler bodies do not need to be included.
* Improve checking for cython_function_or_method
Because pydantic can be installed without cython, only use the workaround in
the case where the BaseModel.validate function is NOT a FunctionType,
indicating it's a cython function.
* Serialize all State subclasses by reference
* 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.
* [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
* 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>
* 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.
* 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
* 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>
* 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
* initial values for computed vars draft
* add tests, add computed_var overloads
* fix darglint
* pass initial to substates when calling dict
* add tests for for child states
* format black
* allow None as initial value
* rename runtime_only to raises_at_runtime
* cleanup unused arguments of ComputedVars
* refactor cached_var to be partial of computed_var
* test_state: augment modify_state test for writing MutableProxy
If the object contains a MutableProxy inside of it, then we get a pickling
error.
* Implement __reduce_ex__ for MutableProxy
Pass through `__reduce_ex__` onto the wrapped instance to strip it off when
cloudpickling to redis.
* base: get_value actually works with a str key
Unless the key isn't a field on the model, then it falls back to the previous
behavior of just returning the given key as is... why does it do this? I don't
know.
* 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
* Component: translate underscore suffix for props supported by chakra
type_ becomes type
min_ becomes min
max_ becomes max
id_ becomes id
The deprecation warning is only displayed when the underscore suffix prop is
passed and the non-underscore suffix prop is defined on the given component.
* Rename type_ to type in accordion and scroll_area
All of the new radix components avoid the underscore suffix names where
possible.
* Update deprecation warning wording
* Refactor for readability
* Do not raise deprecation warning for `id_`
id is kind of a special prop because it exists on all components
* Add test case for deprecating underscore suffix props
* 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
* pyi_generator: always ignore files starting with `tests`
* Move CodeBlock out of chakra namespace
* Expose additional names in the top-level namespace
* code pyi fixup
* expose input and quote at the top-level
* add text_field to top-level namespace (maybe)
* fixup chakra code.pyi
* Remove `text_field` from top level namespace
* Remove top-level big C Cond
* fixup top level pyi
* use redis-py url syntax for redis_url
* port is optional
* Add StateManagerRedis.close method
The close helper method always calls `close_connection_pool=True` so that all
outstanding redis operations can be stopped before changing event loops.
---------
Co-authored-by: Masen Furer <m_github@0x26.net>