* `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>
1. Updated recharts version to the newest - recharts.py
2. Added `legend_type` back for cartesian class, it was currently commented out - cartesian.py
3. Added `vertical_points` and `horizontal_points` to CartesianGrid class - cartesian.py
4. Added `ticks` `tick` `tick_count` `tick_line` `tick_size` `min_tick_gap`props to Axis class - cartesian.py
5. Refactored `on_click` `on_mouse_down` `on_mouse_up` `on_mouse_move` `on_mouse_out` `on_mouse_enter` `on_mouse_leave` event triggers of `Axis` class using Masen's new method - cartesian.py
6. Added `on_animation_begin` and `on_animation_end` event trigger to `Bar(Cartesian)` class - cartesian.py
7. Added `id` `is_animation_active` `animation_begin` `animation_duration` `animation_easing` `unit` `min_point_size` `name` prop to `Bar(Cartesian)` class - cartesian.py.
8. Added `unit` `name` props to `Area(Cartesian)` class - cartesian.py
9. Added `unit` `name` props to `Line(Cartesian)` class - cartesian.py
10. Added `id` `is_animation_active` `animation_begin` `animation_duration` `animation_easing` props to `Scatter(Recharts)` class - cartesian.py
11. Refactored eventtriggers for `Scatter(Recharts)` class using Masen's new method - cartesian.py
12. Change the var type of stack_id in `Area(Cartesian)` class to be string and int, it used to be only a string. - cartesian.py
13. Added `name_key` prop and `on_animation_start` and `on_animation_end` prop to `Funnul(Recharts)` class cartesian.py
14. Added `on_mouse_down` `on_mouse_up` `on_mouse_over` `on_mouse_out` event triggers to `PieChart(ChartBase)` and also refactored using Masen's new method - Charts.py
15. Refaactored event triggers for referenceDot(Reference) class using Masen's new method. - Cartesian.py
16. Refactored event triggers for ChartBase(RechartsCharts) class using Masen's new method. - Cartesian.py
17. Refactored event triggers for Piechart(ChartBase) class using Masen's new method, Added `on_mouse_down` `on_mouse_up` `on_mouse_over` `on_mouse_out` event triggers - Cartesian.py
Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan>
In pydantic 1.10.16 (hopefully the last version), they added the `pydantic.v1`
namespace to make transitioning to the v2 package easier without changing code.
However, Reflex was depending on pydantic v1 NOT having `pydantic.v1` to skip
patching names from `v1` into the top level `pydantic` (normally we do this to
force sqlmodel to use v1, even when the v2 package is installed).
Unbreak CI
* Override _var_is_string when handling str literals
Maintain the pre 0.5.4 behavior when dealing with string literal
props, without displaying the deprecation warning.
Wait, isn't it weird to pass `_var_is_string=False` when the type is actually a str??
Yes, yes it is. However this is currently needed to avoid raising the
DeprecationWarning internally. These str-type vars with
_var_is_string set to false are handled by
`reflex.utils.format.format_prop`, but setting them to be
_var_is_string=True causes them to get quoted twice, which is not
what we want.
Var operations refactor will take care of cleaning this up, but for
now, we will go with the hack.
* Ignore type checks
Since I'm using an `isinstance` check now, the type checker thinks that `value`
could possibly be a string (instead of Any), which raises typing errors that
have to be ignored (they were ignored before implicitly due to being Any-typed)
* Make client_state work without global refs (local only)
* client_state: if the default is str, mark _var_is_string=True
Ensure that a string default is not rendered literally
* add `to_int` as a Var operation
* Allow an event handler lambda to return a Var in some cases
If an lambda is passed to an event trigger and it returns a single Var, then
treat it like the Var was directly passed for the event trigger.
This allows ClientState.set_var to be used within a lambda.
* test_connection_banner: Improve assertions
* Actually assert on the presence or absense of the connection banner
* Update XPATH selector to find the connection toast
* Add event handling while backend down to verify queue functionality
* Bring backend down while an event is running to ensure queue does not get
blocked (#3404)
* state.js: set event_processing = false when websocket connects
In case an event was pending when the websocket went down, allow further events
to be processed when it comes back up.
Fix#3404
* test_connection_banner: wait for token indicating backend is connected
* test_connection_banner: increase delay time
make the time window longer in which the backend can go down and get stuck in
event_processing=true for better test reliability
* Ensure the redis connection is reset in new backend thread
Redis has an event loop affinity and needs to be attached to the event loop
that the thread is running.
* Reset event_processing on disconnect
* if the socket never comes back up, it still allows client-side events to be
processed
* on_mount events may start running before the socket is up, so resetting the
flag on connect may break event determinism (test_event_chain.py)
* 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>
* Addresses an issue with pydantic v2 models as Vars
It looks like there's an issue with state vars
which are pydantic v2 models... Here's a
reproducible test case:
```python
import reflex as rx
from pydantic import BaseModel
from reflex.utils.serializers import serializer
class User(BaseModel):
has_image: bool = False
@serializer
def serialize_user(user: User) -> dict:
return user.dict()
class State(rx.State):
user: User = None
def index() -> rx.Component:
return rx.container(
rx.cond(State.user,
rx.text(State.user.has_image),
rx.text("No user"))
)
app = rx.App()
app.add_page(index)
```
This app works only with pydantic <2 installed:
```bash
reflex-test $ reflex run
...
AttributeError: 'FieldInfo' object has no attribute 'outer_type_'
reflex-test $ pip install pydantic==1.10.15
─────────────────────────────────── Starting Reflex App ───────────────────────────────────
Compiling: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 13/13 0:00:00
─────────────────────────────────────── App Running ───────────────────────────────────────
App running at: http://localhost:3000
```
Looks like this is caused by `outer_type_` no
[longer existing][1] in pydantic v2. I'm guessing
this was introduced back in [v0.4.6][2].
1: https://github.com/pydantic/pydantic/discussions/7217
2: 86526cba51
This change explicitly ignores pydantic v2 models in
`get_attribute_access_type`, rather than trying to treat
them as v1 models.
* ruff formatting
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* [REF-2977] [REF-2982] Merge layout prop and automatic darkmode
* Expose `template` prop in rx.plotly
* Set default `template` to a color_mode_cond that responds to dark mode
* Merge user-provided `layout` and `template` props into the serialized
plot data
* pyi_generator: avoid affecting the HTML Template component
* Raise warning when importing rx.plotly without plotly installed
* Remove PlotlyLib component and consolidate imports [fixup]
* 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"
* include resize and radius props to the text area component
* run scripts/make_pyi.py for text_area
* pre-commit fixup
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
* pyi_generator: do not generate kwargs for event trigger props
event triggers are handled separately
* Implement event handlers for Plotly
* py38 compat: from __future__ import annotations
* 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