Commit Graph

1603 Commits

Author SHA1 Message Date
Thomas Brandého
463f7829d4
swap all use of get_event_triggers to rx.EventHandler props (#3458) 2024-06-12 11:11:29 -07:00
Thomas Brandého
462b023019
use add_imports everywhere (#3448) 2024-06-12 09:26:45 -07:00
Carlos
991f6e0183
[REF-3012] Add defs, lineargradient and stop html elements (#3467) 2024-06-12 09:21:36 -07:00
Elijah Ahianyo
8c8156f3aa
[REF-3016] Allow special characters in upload ID (#3449) 2024-06-12 09:21:21 -07:00
Masen Furer
c3c06a1fcb
compat: do not patch pydantic if the installed version starts with "1." (#3482)
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
2024-06-11 19:16:35 -07:00
Masen Furer
bd799a2680
Override _var_is_string when handling str literals (#3473)
* 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)
2024-06-11 13:18:34 -07:00
Masen Furer
66f0a49b75
Pass _var_is_string parameter to Var.create (#3470) 2024-06-10 14:32:32 -07:00
Tom Gotsman
ccf617ba85
small update to fix radial bar chart (#3468)
* small update to fix radial bar chart

* update add data prop to radar

---------

Co-authored-by: Tom Gotsman <tomgotsman@toms-mbp.lan>
2024-06-10 14:03:47 -07:00
Tom Gotsman
cc0f0bcc22
Fix recharts errors part 1 (#3450) 2024-06-07 17:30:09 -07:00
Alexander Morgan
ad3134413b
Make better/less use of dict.keys() calls (#3455) 2024-06-07 14:28:44 -07:00
Masen Furer
bb44d51f2f
[REF-2879] Make client_state work without global refs (local only) (#3379)
* 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.
2024-06-07 13:29:52 -07:00
Masen Furer
e138d9dfd0
state.js: set event_processing = false when websocket connects (#3443)
* 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)
2024-06-07 13:29:25 -07:00
Thomas Brandého
c04ed58d2e
default color_mode is now system color (#3457) 2024-06-07 09:56:07 -07:00
benedikt-bartscher
e42d4ed9ef
[REF-3009] type transforming serializers (#3227)
* 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>
2024-06-07 09:50:10 -07:00
Elliot Kroo
168501d58a
Address an issue with pydantic v2 models as Vars (#3396)
* 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>
2024-06-07 09:47:54 -07:00
HongyuHansonYao
4e990d2716
Recharts supporting radix color, add event triggers (#3430)
Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan>
2024-06-07 09:47:12 -07:00
Masen Furer
6e719d4c83
[REF-2977] [REF-2982] Merge layout prop and automatic darkmode (#3442)
* [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]
2024-06-07 09:42:50 -07:00
Masen Furer
fb173908db
Only run pyi_generator on files in reflex/components or reflex/__init__.py (#3452) 2024-06-06 21:31:17 -07:00
Devon Stewart
39d9a9f8eb
[bug] Avoid deleting endpoint port when running on Replit (#3447)
* "if codespace_name" repeated, no-op

* Special-case replit.dev

* Codifying a ruff future
2024-06-06 14:00:00 -07:00
benedikt-bartscher
f672391618
Webdriver ArgOptions improvements (#3429)
* allow to pass custom selenium ArgOptions to webdriver

* allow to pass capabilities to auto generated driver options
2024-06-06 13:59:41 -07:00
Thomas Brandého
3579513964
fix warning about props (#3451) 2024-06-06 13:45:22 -07:00
Thomas Brandého
e1244b4ea6
promote toast to main namespace (#3422) 2024-06-06 10:38:35 -07:00
Thomas Brandého
4b955d3831
clean up hooks and update component to use add_hooks (#3439) 2024-06-06 10:26:04 -07:00
Elijah Ahianyo
44ad9a7311
[REF-2956] Fail When Backend port or frontend port is explicitly provided and the port is in use (#3432) 2024-06-05 11:46:00 -07:00
Milo Chen
bbd320b3ce
fix: correct zh_tw and zh_cn README for hyperlink issues (#3440)
* fix: correct zh_tw and zh_cn README for hyperlink issues

* Update docs/zh/zh_cn/README.md

Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>

* Update docs/zh/zh_tw/README.md

Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>

---------

Co-authored-by: Thomas Brandého <thomas.brandeho@gmail.com>
2024-06-05 19:11:20 +02:00
Masen Furer
765f349f02
[REF-3004] Use relative path to stylesheet for postcss-import compat (#3435)
* 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"
2024-06-05 10:02:05 -07:00
Masen Furer
447fe56833
bump version to 0.5.3 (#3446) 2024-06-05 10:01:17 -07:00
Masen Furer
096ecf3113
[REF-3006] Inline code rendered in rx.markdown has extra trailing space (#3426)
Avoid replacing newlines with whitespaces... these show up in the rendered
output 😱

Fix #3425
2024-06-05 16:55:02 +02:00
Elijah Ahianyo
6420fb1252
[REF-3010] Circular Imports Fix (#3433) 2024-06-04 11:50:02 -07:00
Elijah Ahianyo
a3cbfefb22
[REF-2602] Do not suppress import errors in rxconfig (#3434) 2024-06-04 11:48:52 -07:00
HongyuHansonYao
1c29bff998
Set use resize handler default to true (#3424)
* init

* empty commit

* set true

* set true

* set true

---------

Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan>
2024-06-03 12:42:22 -07:00
Milo Chen
6c1af838cf
PR zh/zh_tw readme update for relex 0.5.2 (#3415) 2024-06-03 10:29:58 -07:00
Carlos
7a12fe2c5e
include resize and radius props to the text area component (#3383)
* 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>
2024-05-31 17:45:59 -07:00
Masen Furer
b04e3a6ce9
[REF-1356] Track changes applied to Base subclass via helper method. (#2242) 2024-05-31 14:58:58 -07:00
Masen Furer
5995b32f5f
[REF-2978] Ignore Redis config_set for AWS ElastiCache (#3401) 2024-05-31 14:58:25 -07:00
Masen Furer
16fc3936a4
[REF-2202] Implement event handlers for Plotly (#3397)
* 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
2024-05-31 13:04:19 -07:00
HongyuHansonYao
d9e718d7bd
Layout property not pushed through on rx.plotly (#3394)
* 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>
2024-05-31 11:48:43 -07:00
Elijah Ahianyo
34bf25071a
[REF-2821]Improve Dynamic Imports (#3345)
* 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
2024-05-31 16:43:10 +00:00
Jishnu N
83d99889ec
refactor: radix section default size (#3406) 2024-05-30 20:52:01 -07:00
Masen Furer
2f1a68c975
pyproject.toml: bump to 0.5.2 (#3408) 2024-05-30 16:58:23 -07:00
Elijah Ahianyo
1a833d6b25
Recommend Running with REFLEX_USE_NPM=1 if npm run fails after installing packages with bun. (#3399) 2024-05-30 15:57:15 -07:00
Tom Gotsman
5652310840
update image for readme (#3395)
* update image for readme

* update based on Nikhil's comment

---------

Co-authored-by: Tom Gotsman <tomgotsman@toms-mbp.lan>
2024-05-30 12:23:56 -07:00
Kelechi Ebiri
d99c40a763
Add domain prop for the PolarRadiusAxis component (#3349) 2024-05-30 09:14:50 -07:00
Sagar Hedaoo
7f054fda9d
Updated in/readme.md with current readme (#3333) 2024-05-30 09:14:02 -07:00
Thomas Brandého
c7064b9a24
add config knob for react_strict_mode. default to True. also cleanup unused code (#3389) 2024-05-29 11:49:04 -07:00
Elijah Ahianyo
4b939caa7f
[REF-2895]Benchmarks getting skipped on merge (#3369) 2024-05-29 09:28:41 -07:00
benedikt-bartscher
93de407007
Explicit deps and interval for computed vars (#3231) 2024-05-28 12:27:27 -07:00
Masen Furer
ac1c660bf0
Radix Themes + Tailwind Harmony (#3355) 2024-05-28 12:21:28 -07:00
Thomas Brandého
33f71c6eef
add mapping between client_token and socket id (#3388) 2024-05-28 10:53:26 -07:00
abulvenz
6c6eaaa55f
External assets (#3220) 2024-05-28 09:39:25 -07:00