* 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