Commit Graph

587 Commits

Author SHA1 Message Date
Masen Furer
736b2a6ea9
Handle rx.State subclasses defined in function (#4129)
* Handle rx.State subclasses defined in function

* create a new container module: `reflex.istate.dynamic` to save references to
  dynamically generated substates.
* for substates with `<locals>` in the name, copy these to the container module
  and update the name to avoid duplication.
* add test for "poor man" ComponentState

Fix #4128

* test_state: disable local def handling for dupe-detection test

* Track the original module and name for type hint evaluation

Also use the original name when checking for the "mangled name" pattern when
doing undeclared Var assignment checking.
2024-10-11 16:51:10 -07:00
Thomas Brandého
6f586c8b8f
let users pick state manager mode (#4041) 2024-10-10 12:22:35 -07:00
Khaleel Al-Adhami
8ec3cf6157
remove dictify from state dict (#4141) 2024-10-10 12:18:18 -07:00
abulvenz
87648af3ee
fix: Determine var type from value. (#4143) 2024-10-09 17:33:34 -07:00
Khaleel Al-Adhami
91ab8ac574
Remove wrong event handlers (#4136)
* remove wrong target value

* add keyboard event

* simplify empty ones

* remove events from text_area

* empty tuples are empty bruh

* dangit darglint
2024-10-09 13:25:41 -07:00
Masen Furer
876426c581
test_dynamic_routes: log on_loads and poll for 60 seconds on order (#4089)
Assert on `list(...order)` so the error message prints actual value instead of
MutableProxy's repr.

Not sure if this fixes it...
2024-10-08 09:14:35 -07:00
Khaleel Al-Adhami
af83161fed
reset backend vars in state.reset() (#4087) 2024-10-07 15:04:01 -07:00
Thomas Brandého
0e99ce91c1
update ruff to latest version (#4081)
* update ruff to latest version

* fix pyi
2024-10-07 23:52:36 +02:00
Thomas Brandého
59dd54c049
add workflow to check dependencies on release branch (#4050)
* add workflow to check dependencies on release branch

* rename action to follow convention of other actions

* update workflow

* bump poetry version

* relock deps

* update check to ignore pyright and ruff

* oops, you saw nothing

* split dep check in two job

* fix frontend dep check

* fix stuff

* hmm yeah

* nope nope nope

* sigh

* bump js versions for some packages

* fix some warnings in tests

* fix tests

* try some options

* try to set asyncio policy

* debug dep check

* fix attempt for backend dep

* clean up output for backend check

* run bun outdated on reflex-web to catch most of the packages

* fix python version

* fix python version

* add missing env

* fix bun command

* fix workdir of frontend check

* update packages version

* up-pin plotly.js version

* add debug ouput

* clean frontend dep check output

* fix output

* fix async tests for redis

* relock poetry.lock

* Non-async functions do not need pytest_asyncio.fixture

* test_state: close StateManagerRedis connection in test to avoid warning

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-10-07 20:57:02 +02:00
Masen Furer
edd17208c0
Reduce pickle size (#4063)
* Only serialize base vars
* Never serialize router/router_data in substates
* Hash the schema to reduce serialized size
* lru_cache the schema to avoid recomputing it
2024-10-07 09:34:36 -07:00
Masen Furer
5c0518053d
Get default for backend var defined in mixin (#4060)
* Get default for backend var defined in mixin

If the backend var is defined in a mixin class, it won't appear in
`cls.__dict__`, but the value is still retrievable via `getattr` on `cls`.
Prefer to use the actual defined default before using
`Var.get_default_value()`.

If `Var.get_default_value()` fails, set the default to `None` such that the
backend var still gets recognized as a backend var when it is used on `self`.

----

Update test_component_state to include backend vars

Extra coverage for backend vars with and without defaults, defined in a
ComponentState/mixin class.

* fix integration test
2024-10-07 09:33:44 -07:00
Masen Furer
aa69234b76
Optimize StateManagerDisk (#4056)
* Simplify StateManagerDisk implementation

* Act more like the memory state manager and only track the root state in self.states
* .load_state always loads a single state or returns None
* .populate_states is the new entry point in loading from disk and it only occurs
  when the root state is not known
* much fast

* StateManagerDisk now acts much more like StateManagerMemory

Treat StateManagerDisk like StateManagerMemory for AppHarness

* Handle root_state deserialized from disk

In this case, we need to initialize the whole state tree, so any non-persistent
states will still get default values, whereas on-disk states will overwrite the
defaults.

* Cache root_state under client_token for StateManagerMemory compatibility

Mainly this just makes it easier for us to write tests that work against either
Disk or Memory state managers.
2024-10-07 09:33:16 -07:00
Khaleel Al-Adhami
73e8a4e0ab
support eventspec/eventchain in var operations (#4038) 2024-10-03 15:33:51 -07:00
Masen Furer
a66e0f2e11
[ENG-3870] rx.call_script with f-string var produces incorrect code (#4039)
* Add additional test cases for rx.call_script

Include internal vars inside an f-string to be properly rendered on the backend
and frontend.

* [ENG-3870] rx.call_script with f-string var produces incorrect code

Avoid casting javascript code with embedded Var as LiteralStringVar

There are two cases that need to be handled:

1. The javascript code contains Vars with VarData, these can only be evaluated
   in the component context, since they may use hooks. Vars with VarData cannot be
   used from the backend. In this case, we cast the given code as a raw js
   expression and include the extracted VarData.

2. The javascript code has no VarData. In this case, we pass the code as the
   raw js expression and cast to a python str to get a js literal string to eval.

* use VarData.__bool__ instead of `is None`
2024-10-03 14:18:53 -07:00
Khaleel Al-Adhami
56709a210b
add of_type to _evaluate (#4051)
* add of_type to _evaluate

* get it right pyright
2024-10-03 13:01:19 -07:00
Elijah Ahianyo
4b3d056212
[ENG-3476] Setting State Vars that are not defined should raise an error (#4007) 2024-10-03 10:35:34 -07:00
Thomas Brandého
3f51943162
use pathlib as much as possible (#3967)
* use pathlib as much as possible

* fixstuff

* break locally to unbreak in CI 🤷

* add type on env

* debug attempt 1

* debugged

* oops, there is the actual fix

* fix 3.9 compat
2024-10-03 17:50:39 +02:00
ChinoUkaegbu
bd71c8e6c9
feat: Add support for missing SVGs (#3962) 2024-10-01 09:24:26 -07:00
Khaleel Al-Adhami
62021b0b40
implement _evaluate in state (#4018)
* implement _evaluate in state

* add warning

* use typing_extension

* add integration test
2024-09-27 16:58:20 -07:00
Masen Furer
9ca5d4a095
Track backend-only vars that are declared without a default value (#4016)
* 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
2024-09-27 12:04:43 -07:00
Khaleel Al-Adhami
0ab161c119
remove format_state and override behavior for bare (#3979)
* 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
2024-09-26 16:00:28 -07:00
LeoH
60276cf1ff
EventFnArgMismatch fix to support defaults args (#4004)
* 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>
2024-09-26 13:56:53 -07:00
Khaleel Al-Adhami
54c7b5a261
disable prose by default for rx.html (#4001)
* disable prose by default for rx.html

* remove styled

* put that on one line
2024-09-26 13:47:05 -07:00
Thomas Brandého
130bcf96ca
default on_submit in form set to prevent_default (#4005)
* default submit forms set to prevent_default

* fix tests
2024-09-26 11:56:59 -07:00
Thomas Brandého
3f538865b5
reorganize all tests in a single top folder (#3981)
* 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
2024-09-26 01:22:52 +02:00
Khaleel Al-Adhami
74d1c47ce2
allow classname to be state vars (#3991)
* 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
2024-09-25 09:57:29 -07:00
Khaleel Al-Adhami
5e738fd62b
don't camel case keys of dicts in style (#3982)
* don't camel case keys of dicts in style

* change tests to fit the code 😎

* respect objectvars as true dicts
2024-09-24 17:38:49 -07:00
Thomas Brandého
4e4d36a867
re add removed method with better behaviour and tests (#3986) 2024-09-24 23:29:56 +02:00
Andrew Davies
2c4310d9ff
Use tailwind typography plugin by default (#3593)
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2024-09-23 18:18:05 -07:00
Masen Furer
2883e541a9
Bring back py3.9 support with a deprecation warning. (#3976)
* 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
2024-09-23 18:15:16 -07:00
Khaleel Al-Adhami
47c9938d95
use is true for bool var (#3973) 2024-09-23 16:36:58 -07:00
Thomas Brandého
61332fdba1
add some more tests (#3965) 2024-09-22 14:44:44 -07:00
Thomas Brandého
fe1833c5e1
bump python>=3.10 for 0.6.0 (#3956) 2024-09-20 09:52:29 -07:00
Masen Furer
bca49d3537
Component as Var type (#3732)
* [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>
2024-09-19 19:06:53 -07:00
Thomas Brandého
cf69964cd6
add some unit tests for coverage (#3947)
* add some unit tests for coverage

* add test for page decorator

* bump coverage threshold

* check content
2024-09-18 23:44:59 +02:00
Thomas Brandého
44a89b2e87
fix unionize recursion (#3948)
* fix unionize recursion

* merging

---------

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2024-09-18 22:50:54 +02:00
Khaleel Al-Adhami
91b50d713e
add special handling for infinity and nan (#3943)
* add special handling for infinity and nan

* use custom exception

* add test for inf and nan
2024-09-18 13:10:32 -07:00
Khaleel Al-Adhami
a8734d7392
add few test cases for bool (#3949)
* 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>
2024-09-18 13:10:18 -07:00
Khaleel Al-Adhami
a57095ffe8
use serializer for state update and rework serializers (#3934)
* use serializer for state update and rework serializers

* format
2024-09-16 16:36:01 -07:00
Khaleel Al-Adhami
8328a622a2
Fix string color (#3922) 2024-09-16 11:12:51 -07:00
Khaleel Al-Adhami
085b761f6b
replace old var system with immutable one (#3916)
* 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>
2024-09-13 16:01:52 -07:00
Khaleel Al-Adhami
8f937f0417
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>
2024-09-13 12:53:30 -07:00
Elijah Ahianyo
625c5302dd
[REF-3562][REF-3563] Replace chakra usage (#3872) 2024-09-12 10:46:42 -07:00
benedikt-bartscher
5dcf554bd4
cleanup dead test code (#3909) 2024-09-11 11:15:49 -07:00
benedikt-bartscher
63bf1b8817
Dynamic route vars silently shadow all other vars (#3805)
* 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>
2024-09-11 09:43:18 -07:00
abulvenz
95631ffdba
Fix type propagation in ToStringOperation (#3895)
* 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>
2024-09-11 09:35:19 -07:00
benedikt-bartscher
d672c643b3
Forbid Computed var shadowing (#3843) 2024-09-10 12:09:35 -07:00
Khaleel Al-Adhami
a5c73ad8e5
Use old serializer system in LiteralVar (#3875)
* 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>
2024-09-10 11:43:37 -07:00
benedikt-bartscher
99ffbc8c39
fix var dependency dicts (#3842) 2024-09-08 18:35:47 -07:00
benedikt-bartscher
477e1dece9
mixin computed vars should only be applied to highest level state (#3833) 2024-09-08 18:26:52 -07:00
Samarth Bhadane
59047303c9
/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
2024-09-03 18:34:03 -07:00
Khaleel Al-Adhami
c07a983f05
add var_operation and move some operations to the new style (#3841)
* 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
2024-09-03 11:39:05 -07:00
Khaleel Al-Adhami
629850162a
implement disk state manager (#3826)
* 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
2024-08-30 17:26:10 -07:00
Masen Furer
356deb5457
[REF-3589] raise EventHandlerArgMismatch when event handler args don't match spec (#3853)
* 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
2024-08-29 16:05:15 -07:00
Elijah Ahianyo
e6080a7707
[REF-3568][REF-3569]Remove deprecations (#3852)
* Remove deprecations

* remove prop conversion

* fix tests

* fix slight issue

* fix darglint
2024-08-29 15:46:18 -07:00
benedikt-bartscher
dd6feff13f
Get attribute access type fix (#3803)
* add failing test

* catch unhandled NotImplementedError
2024-08-29 09:45:24 -07:00
Khaleel Al-Adhami
ea15b184c0
fully migrate vars into new system (#3743)
* 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>
2024-08-26 13:28:18 -07:00
Elijah Ahianyo
1f3779f40e
[REF-3536][REF-3537][REF-3541] Move chakra components into its repo(reflex-chakra) (#3798) 2024-08-19 13:41:31 -07:00
Elijah Ahianyo
4190a79835
[REF-3334] Validate Toast Props (#3793) 2024-08-15 09:30:32 -07:00
Khaleel Al-Adhami
ad14f38329
add type hinting to existing types (#3729)
* add type hinting to existing types

* dang it darglint

* i cannot
2024-07-31 12:01:17 -07:00
benedikt-bartscher
129adc941a
add test for initial state dict (#3727) 2024-07-31 11:37:53 -07:00
Khaleel Al-Adhami
1c400043c6
[REF-3328] Implement __getitem__ for ArrayVar (#3705)
* 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>
2024-07-30 15:38:32 -07:00
Masen Furer
06833f6d8d
[REF-3203] Find a DOM event-like object in addEvents (#3706) 2024-07-29 17:17:51 -07:00
Khaleel Al-Adhami
ede5cd1f2c
[REF-3321] implement var operation decorator (#3698)
* 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 🥺
2024-07-25 09:34:14 -07:00
Masen Furer
0845d2ee76
[REF-3184] [REF-3339] Background task locking improvements (#3696)
* [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
2024-07-23 15:28:38 -07:00
Thomas Brandého
b9927b6f49
notifying frontend about backend error looks better (#3491) 2024-07-23 13:58:15 -07:00
Khaleel Al-Adhami
ea016314b0
[REF-3227] implement more literal vars (#3687)
* 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
2024-07-22 12:45:23 -07:00
Khaleel Al-Adhami
458cbfac59
[REF-3228] implement LiteralStringVar and format/retrieval mechanism (#3669)
* 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
2024-07-17 17:01:27 -07:00
Masen Furer
0ed895cde7
debounce: pass through key and special_props (#3655)
These fields on the base Component were not being carried onto the
DebounceInput component (to be passed to the child).

Discovered while testing #3653
2024-07-12 13:27:19 -07:00
Khaleel Al-Adhami
d4d077818c
[REF-3225] implement __format__ for immutable vars (#3617)
* 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
2024-07-11 11:19:38 -07:00
benedikt-bartscher
3039b54a75
add module prefix to generated state names (#3214)
* 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>
2024-07-11 11:13:57 -07:00
Jishnu N
690b719437
[REF-3160] fix rx.Var._replace raise TypeError on invalid kwargs (#3625)
* 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
2024-07-09 11:19:29 -07:00
benedikt-bartscher
d621115f9b
add Bare SQLAlchemy mutation tracking, improve typing (#3628) 2024-07-09 11:13:28 -07:00
Maxim Vlah
772a3ef893
Catch unhandled errors on both frontend and backend (#3572) 2024-07-08 19:26:11 -07:00
benedikt-bartscher
6d3321284c
fix sqla python_type issues, add tests (#3613) 2024-07-08 19:21:08 -07:00
benedikt-bartscher
b7651e214b
add computed backend vars (#3573)
* 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
2024-06-28 17:01:07 -07:00
benedikt-bartscher
bcc7a61452
improve backend var determination (#3587)
* cleanup reserved backend var check

* cleanup backend var determination mess

* add tests for hidden and class methods
2024-06-28 14:07:39 -07:00
benedikt-bartscher
a6bdaf1bbe
fix var dependency over properties (#3588) 2024-06-28 12:48:28 -07:00
benedikt-bartscher
33d7ec1f04
copy backend vars from mixins (#3580)
* copy backend vars from mixins

* fix and improve backend var mixin test
2024-06-28 10:42:41 -07:00
benedikt-bartscher
a7e4594fdc
Deprecate cached var (#3582)
* deprecate cached_var partial

* migrate cached_var to var(cache=True)

* fix darglint (typo)
2024-06-28 10:14:55 -07:00
benedikt-bartscher
44d27f9e4c
do not validate non-cached var deps (#3576)
* do not validate non-cached var deps

* further improve Exceptions for misconfigured var deps
2024-06-27 17:00:55 -07:00
benedikt-bartscher
8e66c9b3c7
classvars should not be backend vars (#3578)
* classvars should not be backend vars

* cleanup RESERVED_BACKEND_VAR_NAMES
2024-06-27 16:03:36 -07:00
Elijah Ahianyo
31bd75ff39
[REF-3185][REF-3180]Dont escape backticks in JS string interpolation (#3566)
* 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
2024-06-26 13:23:07 -07:00
benedikt-bartscher
9d71bcbbb5
bare sqlalchemy session + tests (#3522)
* 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
2024-06-25 15:29:01 +02:00
benedikt-bartscher
41efe12e9a
Validate ComputedVar dependencies, add tests (#3527) 2024-06-24 16:11:42 -07:00
Elijah Ahianyo
f037df0977
[REF-3056] Config knob for redis StateManager expiration times (#3523) 2024-06-24 16:03:30 -07:00
Thomas Brandého
0d39237b3c
upgrade to latest ruff (#3497)
* 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
2024-06-19 12:32:13 +02:00
Thomas Brandého
ed05f57fc9
Make .web configurable with REFLEX_WEB_WORKDIR (#3462) 2024-06-17 16:17:00 -04:00
Elijah Ahianyo
69e4bbc301
[REF-2830] server side events and stateless components should not require not require a backend (#3475)
* `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>
2024-06-14 09:48:53 -07:00
Thomas Brandého
462b023019
use add_imports everywhere (#3448) 2024-06-12 09:26:45 -07:00
Elijah Ahianyo
8c8156f3aa
[REF-3016] Allow special characters in upload ID (#3449) 2024-06-12 09:21:21 -07:00
Alexander Morgan
ad3134413b
Make better/less use of dict.keys() calls (#3455) 2024-06-07 14:28:44 -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
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
b04e3a6ce9
[REF-1356] Track changes applied to Base subclass via helper method. (#2242) 2024-05-31 14:58:58 -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
abulvenz
6c6eaaa55f
External assets (#3220) 2024-05-28 09:39:25 -07:00
abulvenz
7c2056e960
feat: Optionally comparing fields in Var.contains, e.g. on rx.Base based types. (#3375)
* 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.
2024-05-24 17:16:26 -07:00
Nikhil Rao
ec72448b8b
Catch more errors in frontend/backend (#3346) 2024-05-20 16:55:41 -07:00
benedikt-bartscher
656914edef
fix rx.cond with ComputedVars and use union type (#3336) 2024-05-19 12:14:46 -07:00
Masen Furer
bc6f0f70cb
Support replacing route on redirect (#3072)
* 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
2024-05-16 13:21:40 -07:00
Thomas Brandého
47043ae787
throw error for componentstate in foreach (#3243) 2024-05-15 17:59:23 -07:00
Masen Furer
c5f32db756
[REF-2787] add_hooks supports Var-wrapped hooks (#3248)
* [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
2024-05-15 14:59:45 -07:00
Masen Furer
3715462eb4
Allow Component.add_style to return a regular dict (#3264)
* 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
2024-05-10 20:25:04 -07:00
Masen Furer
d767dc5fc7
[REF-2802] Foreach should respect modifications to children (#3263)
* 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
2024-05-09 15:04:26 -07:00
Nikhil Rao
940afb2c92
Remove deprecations for 0.5.0 (#3222) 2024-05-07 08:55:42 -07:00
Masen Furer
83371d51d3
[REF-2658] Alembic should use batch mode for autogenerate (#3223) 2024-05-06 18:34:55 -07:00
Thomas Brandého
57476966f3
add_style api (#3202) 2024-05-06 16:59:11 -07:00
Elijah Ahianyo
0838e5ac6a
[REF-2676][REF-2751] Windows Skip ARM devices on bun install + Telemetry (#3212) 2024-05-06 09:50:05 -07:00
Elijah Ahianyo
9c7dbdbc72
[REF-2643] Throw Errors for duplicate Routes (#3155) 2024-05-03 12:15:40 -07:00
Nikhil Rao
7903a1020d
Clean up config and app API (#3197) 2024-05-02 18:15:28 -07:00
Masen Furer
c636c91c9c
[REF-2273] Implement .setvar special EventHandler (#3163)
* 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
2024-05-01 17:13:55 -07:00
benedikt-bartscher
9ead091fec
Improved get_attribute_access_type tests (#3180)
* test get_attribute_access_type against attrs

* add union and hybrid_property tests
2024-05-01 17:13:23 -07:00
khhan0130
be93b1280c
Update CodeBlock class to accept rx.color in custom_style (#3168) 2024-05-01 14:48:33 -07:00
Masen Furer
19d8f6c752
[REF-2523] Implement new public Component API (#3203) 2024-05-01 14:46:27 -07:00
benedikt-bartscher
e31b458a69
allow optional props with None default value (#3179) 2024-05-01 13:33:38 -07:00
Masen Furer
b7e85ecec4
[REF-2574] Default width for Stack (+children) and default padding for container (#3104) 2024-04-30 13:15:57 -07:00
Masen Furer
3564df7620
Implement throttle and debounce as event actions (#3091) 2024-04-26 17:28:51 -07:00
benedikt-bartscher
c2017b295e
Improved get_attribute_access_type (#3156) 2024-04-26 17:28:30 -07:00
Masen Furer
0a8aaea599
[REF-2682] Foreach over dict uses Tuple arg value (#3160)
* 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
2024-04-25 09:10:55 -07:00
Thomas Brandého
ac36bfc6ea
Radix 3.0 (#3159) 2024-04-25 08:33:29 -07:00
Ogidi Ifechukwu
ce2bd2286e
Refactor upload component and add styled upload component (#3035) 2024-04-24 13:45:22 -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
Elijah Ahianyo
8e4d6a4781
[REF-2636]Improve Error message for unsupported event trigger (#3147)
* Improve Error message for unsupported event trigger

* typo fix

* fix ci

* add tests

* Update reflex/components/component.py

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

* fix typo

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-04-23 14:36:26 -07:00
Martin Xu
c567334c92
allow set in var.contains (#3113)
* allow set in var.contains

* fix UT
2024-04-18 20:00:18 -07:00
Masen Furer
fc0be257a3
Fix annotated EventHandler (#3076) 2024-04-11 15:34:00 -07:00
Elijah Ahianyo
04ab2b9a71
[REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
Masen Furer
1a11941577
[REF-2392] Expose next.config.js transpilePackages key (#3006) 2024-04-11 13:50:42 -07:00
Masen Furer
d7abcd45de
Force pydantic v1 for sqlmodel compatibility (#3026) 2024-04-11 13:42:30 -07:00
wassaf shahzad
9073a2781b
added serializer for enums (#3058) 2024-04-09 21:13:43 -07:00
Elijah Ahianyo
fdc944e002
Literal Error Formatting (#3037) 2024-04-08 11:29:40 -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
Thomas Brandého
34ee07ecd1
use dict instead of set to store hooks (#2995) 2024-04-03 17:13:42 -07:00
Elijah Ahianyo
d43a85bab2
Unpack component tuples in a fragment (#2985) 2024-04-03 10:44:04 -07:00
Aman Salwan
0e221f0984
Logic for removing the 'None' property along with its corresponding test case. (#2969) 2024-04-02 11:37:05 -07:00
Martin Xu
6d400eddc9
Revert "[REF-2269] Add add_imports API for component class (#2937)" (#2978)
This reverts commit 8edd1dfdc9.
2024-04-01 15:57:03 -07:00
Thomas Brandého
0af4770180
generate pyi files when building/publishing 3rd party component (#2945)
* 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>
2024-03-29 09:54:21 -07:00
Masen Furer
55b0fb36e8
[REF-2219] Avoid refetching states that are already cached (#2953)
* 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
2024-03-29 09:42:25 -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
5510eaf820
[REF-2265] ComponentState: scaffold for copying State per Component instance (#2923)
* [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
2024-03-29 09:22:25 -07:00
Martin Xu
f372402ee4
[REF-2272] Support declaring EventHandlers directly in component (#2952) 2024-03-29 06:26:07 -07:00
Martin Xu
68c56a9811
[REF-2168] Add share options to custom component commands (#2883)
* 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>
2024-03-28 15:13:37 -07:00
Martin Xu
8edd1dfdc9
[REF-2269] Add add_imports API for component class (#2937) 2024-03-28 11:03:26 -07:00
Thomas Brandého
1810288007
remove inheritance from Flex for list components (#2936) 2024-03-28 10:58:36 -07:00
Masen Furer
b788890696
[REF-2089] Use dill instead of cloudpickle for serialization (#2922)
* 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
2024-03-27 13:47:33 -07:00
Thomas Brandého
f19a6a8c8d
use radix box instead of chakra one for responsive elements (#2921) 2024-03-25 15:16:48 -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
Thomas Brandého
92db402539
telemetry refactor + unit tests (#2786) 2024-03-13 12:38:54 -07:00