reflex 0.8.15a0__py3-none-any.whl → 0.8.15a2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of reflex might be problematic. Click here for more details.
- reflex/.templates/web/utils/state.js +68 -8
- reflex/__init__.py +11 -6
- reflex/__init__.pyi +9 -2
- reflex/app.py +5 -5
- reflex/base.py +8 -11
- reflex/components/field.py +3 -1
- reflex/components/markdown/markdown.py +101 -27
- reflex/constants/base.py +5 -0
- reflex/constants/installer.py +2 -2
- reflex/event.py +3 -0
- reflex/istate/manager/__init__.py +120 -0
- reflex/istate/manager/disk.py +210 -0
- reflex/istate/manager/memory.py +76 -0
- reflex/istate/{manager.py → manager/redis.py} +5 -372
- reflex/model.py +5 -1
- reflex/state.py +14 -9
- reflex/testing.py +4 -8
- reflex/utils/codespaces.py +30 -1
- reflex/utils/compat.py +49 -1
- reflex/utils/misc.py +2 -1
- reflex/utils/monitoring.py +1 -2
- reflex/utils/prerequisites.py +17 -3
- reflex/utils/processes.py +3 -1
- reflex/utils/redir.py +21 -37
- reflex/utils/templates.py +4 -4
- reflex/utils/types.py +9 -1
- reflex/vars/base.py +106 -25
- reflex/vars/color.py +28 -8
- reflex/vars/datetime.py +6 -2
- reflex/vars/dep_tracking.py +2 -2
- reflex/vars/number.py +26 -0
- reflex/vars/object.py +23 -6
- reflex/vars/sequence.py +32 -1
- {reflex-0.8.15a0.dist-info → reflex-0.8.15a2.dist-info}/METADATA +4 -3
- {reflex-0.8.15a0.dist-info → reflex-0.8.15a2.dist-info}/RECORD +38 -35
- {reflex-0.8.15a0.dist-info → reflex-0.8.15a2.dist-info}/WHEEL +0 -0
- {reflex-0.8.15a0.dist-info → reflex-0.8.15a2.dist-info}/entry_points.txt +0 -0
- {reflex-0.8.15a0.dist-info → reflex-0.8.15a2.dist-info}/licenses/LICENSE +0 -0
|
@@ -529,6 +529,14 @@ export const connect = async (
|
|
|
529
529
|
navigate,
|
|
530
530
|
params,
|
|
531
531
|
) => {
|
|
532
|
+
// Socket already allocated, just reconnect it if needed.
|
|
533
|
+
if (socket.current) {
|
|
534
|
+
if (!socket.current.connected) {
|
|
535
|
+
socket.current.reconnect();
|
|
536
|
+
}
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
532
540
|
// Get backend URL object from the endpoint.
|
|
533
541
|
const endpoint = getBackendURL(EVENTURL);
|
|
534
542
|
const on_hydrated_queue = [];
|
|
@@ -540,7 +548,9 @@ export const connect = async (
|
|
|
540
548
|
protocols: [reflexEnvironment.version],
|
|
541
549
|
autoUnref: false,
|
|
542
550
|
query: { token: getToken() },
|
|
551
|
+
reconnection: false, // Reconnection will be handled manually.
|
|
543
552
|
});
|
|
553
|
+
socket.current.wait_connect = !socket.current.connected;
|
|
544
554
|
// Ensure undefined fields in events are sent as null instead of removed
|
|
545
555
|
socket.current.io.encoder.replacer = (k, v) => (v === undefined ? null : v);
|
|
546
556
|
socket.current.io.decoder.tryParse = (str) => {
|
|
@@ -550,6 +560,18 @@ export const connect = async (
|
|
|
550
560
|
return false;
|
|
551
561
|
}
|
|
552
562
|
};
|
|
563
|
+
// Set up a reconnect helper function
|
|
564
|
+
socket.current.reconnect = () => {
|
|
565
|
+
if (
|
|
566
|
+
socket.current &&
|
|
567
|
+
!socket.current.connected &&
|
|
568
|
+
!socket.current.wait_connect
|
|
569
|
+
) {
|
|
570
|
+
socket.current.wait_connect = true;
|
|
571
|
+
socket.current.io.opts.query = { token: getToken() }; // Update token for reconnect.
|
|
572
|
+
socket.current.connect();
|
|
573
|
+
}
|
|
574
|
+
};
|
|
553
575
|
|
|
554
576
|
function checkVisibility() {
|
|
555
577
|
if (document.visibilityState === "visible") {
|
|
@@ -565,7 +587,7 @@ export const connect = async (
|
|
|
565
587
|
);
|
|
566
588
|
} else if (!socket.current.connected) {
|
|
567
589
|
console.log("Socket is disconnected, attempting to reconnect ");
|
|
568
|
-
socket.current.
|
|
590
|
+
socket.current.reconnect();
|
|
569
591
|
} else {
|
|
570
592
|
console.log("Socket is reconnected ");
|
|
571
593
|
}
|
|
@@ -588,6 +610,7 @@ export const connect = async (
|
|
|
588
610
|
|
|
589
611
|
// Once the socket is open, hydrate the page.
|
|
590
612
|
socket.current.on("connect", async () => {
|
|
613
|
+
socket.current.wait_connect = false;
|
|
591
614
|
setConnectErrors([]);
|
|
592
615
|
window.addEventListener("pagehide", pagehideHandler);
|
|
593
616
|
window.addEventListener("beforeunload", disconnectTrigger);
|
|
@@ -599,16 +622,33 @@ export const connect = async (
|
|
|
599
622
|
});
|
|
600
623
|
|
|
601
624
|
socket.current.on("connect_error", (error) => {
|
|
602
|
-
|
|
625
|
+
socket.current.wait_connect = false;
|
|
626
|
+
let n_connect_errors = 0;
|
|
627
|
+
setConnectErrors((connectErrors) => {
|
|
628
|
+
const new_errors = [...connectErrors.slice(-9), error];
|
|
629
|
+
n_connect_errors = new_errors.length;
|
|
630
|
+
return new_errors;
|
|
631
|
+
});
|
|
632
|
+
window.setTimeout(() => {
|
|
633
|
+
if (socket.current && !socket.current.connected) {
|
|
634
|
+
socket.current.reconnect();
|
|
635
|
+
}
|
|
636
|
+
}, 200 * n_connect_errors); // Incremental backoff
|
|
603
637
|
});
|
|
604
638
|
|
|
605
639
|
// When the socket disconnects reset the event_processing flag
|
|
606
|
-
socket.current.on("disconnect", () => {
|
|
607
|
-
socket.current =
|
|
640
|
+
socket.current.on("disconnect", (reason, details) => {
|
|
641
|
+
socket.current.wait_connect = false;
|
|
642
|
+
const try_reconnect =
|
|
643
|
+
reason !== "io server disconnect" && reason !== "io client disconnect";
|
|
608
644
|
event_processing = false;
|
|
609
645
|
window.removeEventListener("unload", disconnectTrigger);
|
|
610
646
|
window.removeEventListener("beforeunload", disconnectTrigger);
|
|
611
647
|
window.removeEventListener("pagehide", pagehideHandler);
|
|
648
|
+
if (try_reconnect) {
|
|
649
|
+
// Attempt to reconnect transient non-intentional disconnects.
|
|
650
|
+
socket.current.reconnect();
|
|
651
|
+
}
|
|
612
652
|
});
|
|
613
653
|
|
|
614
654
|
// On each received message, queue the updates and events.
|
|
@@ -785,6 +825,7 @@ export const useEventLoop = (
|
|
|
785
825
|
const [searchParams] = useSearchParams();
|
|
786
826
|
const [connectErrors, setConnectErrors] = useState([]);
|
|
787
827
|
const params = useRef(paramsR);
|
|
828
|
+
const mounted = useRef(false);
|
|
788
829
|
|
|
789
830
|
useEffect(() => {
|
|
790
831
|
const { "*": splat, ...remainingParams } = paramsR;
|
|
@@ -796,11 +837,16 @@ export const useEventLoop = (
|
|
|
796
837
|
}, [paramsR]);
|
|
797
838
|
|
|
798
839
|
const ensureSocketConnected = useCallback(async () => {
|
|
840
|
+
if (!mounted.current) {
|
|
841
|
+
// During hot reload, some components may still have a reference to
|
|
842
|
+
// addEvents, so avoid reconnecting the socket of an unmounted event loop.
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
799
845
|
// only use websockets if state is present and backend is not disabled (reflex cloud).
|
|
800
846
|
if (
|
|
801
847
|
Object.keys(initialState).length > 1 &&
|
|
802
848
|
!isBackendDisabled() &&
|
|
803
|
-
!socket.current
|
|
849
|
+
!socket.current?.connected
|
|
804
850
|
) {
|
|
805
851
|
// Initialize the websocket connection.
|
|
806
852
|
await connect(
|
|
@@ -813,13 +859,23 @@ export const useEventLoop = (
|
|
|
813
859
|
() => params.current,
|
|
814
860
|
);
|
|
815
861
|
}
|
|
816
|
-
}, [
|
|
862
|
+
}, [
|
|
863
|
+
socket,
|
|
864
|
+
dispatch,
|
|
865
|
+
setConnectErrors,
|
|
866
|
+
client_storage,
|
|
867
|
+
navigate,
|
|
868
|
+
params,
|
|
869
|
+
mounted,
|
|
870
|
+
]);
|
|
817
871
|
|
|
818
872
|
// Function to add new events to the event queue.
|
|
819
873
|
const addEvents = useCallback((events, args, event_actions) => {
|
|
820
874
|
const _events = events.filter((e) => e !== undefined && e !== null);
|
|
821
|
-
|
|
822
|
-
|
|
875
|
+
if (!event_actions?.temporal) {
|
|
876
|
+
// Reconnect socket if needed for non-temporal events.
|
|
877
|
+
ensureSocketConnected();
|
|
878
|
+
}
|
|
823
879
|
|
|
824
880
|
if (!(args instanceof Array)) {
|
|
825
881
|
args = [args];
|
|
@@ -914,12 +970,16 @@ export const useEventLoop = (
|
|
|
914
970
|
// Handle socket connect/disconnect.
|
|
915
971
|
useEffect(() => {
|
|
916
972
|
// Initialize the websocket connection.
|
|
973
|
+
mounted.current = true;
|
|
917
974
|
ensureSocketConnected();
|
|
918
975
|
|
|
919
976
|
// Cleanup function.
|
|
920
977
|
return () => {
|
|
978
|
+
mounted.current = false;
|
|
921
979
|
if (socket.current) {
|
|
922
980
|
socket.current.disconnect();
|
|
981
|
+
socket.current.off();
|
|
982
|
+
socket.current = null;
|
|
923
983
|
}
|
|
924
984
|
};
|
|
925
985
|
}, []);
|
reflex/__init__.py
CHANGED
|
@@ -84,13 +84,18 @@ In the example above, you will be able to do `rx.list`
|
|
|
84
84
|
|
|
85
85
|
from __future__ import annotations
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
import sys
|
|
88
|
+
|
|
89
|
+
from reflex.utils import lazy_loader
|
|
90
|
+
|
|
91
|
+
if sys.version_info < (3, 11):
|
|
92
|
+
from reflex.utils import console
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
console.warn(
|
|
95
|
+
"Reflex support for Python 3.10 is deprecated and will be removed in a future release. Please upgrade to Python 3.11 or higher for continued support."
|
|
96
|
+
)
|
|
97
|
+
del console
|
|
98
|
+
del sys
|
|
94
99
|
|
|
95
100
|
RADIX_THEMES_MAPPING: dict = {
|
|
96
101
|
"components.radix.themes.base": ["color_mode", "theme", "theme_panel"],
|
reflex/__init__.pyi
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# This file was generated by `reflex/utils/pyi_generator.py`!
|
|
4
4
|
# ------------------------------------------------------
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import sys
|
|
7
7
|
|
|
8
8
|
from . import (
|
|
9
9
|
admin,
|
|
@@ -160,7 +160,14 @@ from .utils.misc import run_in_thread
|
|
|
160
160
|
from .utils.serializers import serializer
|
|
161
161
|
from .vars import Field, Var, field
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
if sys.version_info < (3, 11):
|
|
164
|
+
from reflex.utils import console
|
|
165
|
+
|
|
166
|
+
console.warn(
|
|
167
|
+
"Reflex support for Python 3.10 is deprecated and will be removed in a future release. Please upgrade to Python 3.11 or higher for continued support."
|
|
168
|
+
)
|
|
169
|
+
del console
|
|
170
|
+
del sys
|
|
164
171
|
RADIX_THEMES_MAPPING: dict
|
|
165
172
|
RADIX_THEMES_COMPONENTS_MAPPING: dict
|
|
166
173
|
RADIX_THEMES_LAYOUT_MAPPING: dict
|
reflex/app.py
CHANGED
|
@@ -1781,16 +1781,16 @@ async def process(
|
|
|
1781
1781
|
name=f"reflex_emit_reload|{event.name}|{time.time()}|{event.token}",
|
|
1782
1782
|
)
|
|
1783
1783
|
return
|
|
1784
|
+
router_data[constants.RouteVar.PATH] = "/" + (
|
|
1785
|
+
app.router(path) or "404"
|
|
1786
|
+
if (path := router_data.get(constants.RouteVar.PATH))
|
|
1787
|
+
else "404"
|
|
1788
|
+
).removeprefix("/")
|
|
1784
1789
|
# re-assign only when the value is different
|
|
1785
1790
|
if state.router_data != router_data:
|
|
1786
1791
|
# assignment will recurse into substates and force recalculation of
|
|
1787
1792
|
# dependent ComputedVar (dynamic route variables)
|
|
1788
1793
|
state.router_data = router_data
|
|
1789
|
-
router_data[constants.RouteVar.PATH] = "/" + (
|
|
1790
|
-
app.router(path) or "404"
|
|
1791
|
-
if (path := router_data.get(constants.RouteVar.PATH))
|
|
1792
|
-
else "404"
|
|
1793
|
-
).removeprefix("/")
|
|
1794
1794
|
state.router = RouterData.from_router_data(router_data)
|
|
1795
1795
|
|
|
1796
1796
|
# Preprocess the event.
|
reflex/base.py
CHANGED
|
@@ -5,7 +5,9 @@ from importlib.util import find_spec
|
|
|
5
5
|
if find_spec("pydantic") and find_spec("pydantic.v1"):
|
|
6
6
|
from pydantic.v1 import BaseModel
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
from reflex.utils.compat import ModelMetaclassLazyAnnotations
|
|
9
|
+
|
|
10
|
+
class Base(BaseModel, metaclass=ModelMetaclassLazyAnnotations):
|
|
9
11
|
"""The base class subclassed by all Reflex classes.
|
|
10
12
|
|
|
11
13
|
This class wraps Pydantic and provides common methods such as
|
|
@@ -22,22 +24,17 @@ if find_spec("pydantic") and find_spec("pydantic.v1"):
|
|
|
22
24
|
use_enum_values = True
|
|
23
25
|
extra = "allow"
|
|
24
26
|
|
|
25
|
-
def
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
Args:
|
|
29
|
-
*args: Positional arguments.
|
|
30
|
-
**kwargs: Keyword arguments.
|
|
31
|
-
"""
|
|
27
|
+
def __init_subclass__(cls):
|
|
28
|
+
"""Warn that rx.Base is deprecated."""
|
|
32
29
|
from reflex.utils import console
|
|
33
30
|
|
|
34
31
|
console.deprecate(
|
|
35
32
|
feature_name="rx.Base",
|
|
36
|
-
reason="You can subclass from `pydantic.BaseModel` directly instead or use dataclasses if possible.",
|
|
37
|
-
deprecation_version="0.8.
|
|
33
|
+
reason=f"{cls!r} is subclassing rx.Base. You can subclass from `pydantic.BaseModel` directly instead or use dataclasses if possible.",
|
|
34
|
+
deprecation_version="0.8.15",
|
|
38
35
|
removal_version="0.9.0",
|
|
39
36
|
)
|
|
40
|
-
super().
|
|
37
|
+
super().__init_subclass__()
|
|
41
38
|
|
|
42
39
|
def json(self) -> str:
|
|
43
40
|
"""Convert the object to a json string.
|
reflex/components/field.py
CHANGED
|
@@ -7,6 +7,7 @@ from dataclasses import _MISSING_TYPE, MISSING
|
|
|
7
7
|
from typing import Annotated, Any, Generic, TypeVar, get_origin
|
|
8
8
|
|
|
9
9
|
from reflex.utils import types
|
|
10
|
+
from reflex.utils.compat import annotations_from_namespace
|
|
10
11
|
|
|
11
12
|
FIELD_TYPE = TypeVar("FIELD_TYPE")
|
|
12
13
|
|
|
@@ -117,7 +118,8 @@ class FieldBasedMeta(type):
|
|
|
117
118
|
cls, namespace: dict[str, Any], name: str
|
|
118
119
|
) -> dict[str, Any]:
|
|
119
120
|
return types.resolve_annotations(
|
|
120
|
-
namespace
|
|
121
|
+
annotations_from_namespace(namespace),
|
|
122
|
+
namespace["__module__"],
|
|
121
123
|
)
|
|
122
124
|
|
|
123
125
|
@classmethod
|
|
@@ -38,6 +38,84 @@ _REHYPE_PLUGINS = LiteralVar.create([_REHYPE_KATEX, _REHYPE_RAW])
|
|
|
38
38
|
NO_PROPS_TAGS = ("ul", "ol", "li")
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
def _h1(value: object):
|
|
42
|
+
from reflex.components.radix.themes.typography.heading import Heading
|
|
43
|
+
|
|
44
|
+
return Heading.create(value, as_="h1", size="6", margin_y="0.5em")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _h2(value: object):
|
|
48
|
+
from reflex.components.radix.themes.typography.heading import Heading
|
|
49
|
+
|
|
50
|
+
return Heading.create(value, as_="h2", size="5", margin_y="0.5em")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _h3(value: object):
|
|
54
|
+
from reflex.components.radix.themes.typography.heading import Heading
|
|
55
|
+
|
|
56
|
+
return Heading.create(value, as_="h3", size="4", margin_y="0.5em")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _h4(value: object):
|
|
60
|
+
from reflex.components.radix.themes.typography.heading import Heading
|
|
61
|
+
|
|
62
|
+
return Heading.create(value, as_="h4", size="3", margin_y="0.5em")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _h5(value: object):
|
|
66
|
+
from reflex.components.radix.themes.typography.heading import Heading
|
|
67
|
+
|
|
68
|
+
return Heading.create(value, as_="h5", size="2", margin_y="0.5em")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _h6(value: object):
|
|
72
|
+
from reflex.components.radix.themes.typography.heading import Heading
|
|
73
|
+
|
|
74
|
+
return Heading.create(value, as_="h6", size="1", margin_y="0.5em")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _p(value: object):
|
|
78
|
+
from reflex.components.radix.themes.typography.text import Text
|
|
79
|
+
|
|
80
|
+
return Text.create(value, margin_y="1em")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _ul(value: object):
|
|
84
|
+
from reflex.components.radix.themes.layout.list import UnorderedList
|
|
85
|
+
|
|
86
|
+
return UnorderedList.create(value, margin_y="1em")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _ol(value: object):
|
|
90
|
+
from reflex.components.radix.themes.layout.list import OrderedList
|
|
91
|
+
|
|
92
|
+
return OrderedList.create(value, margin_y="1em")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _li(value: object):
|
|
96
|
+
from reflex.components.radix.themes.layout.list import ListItem
|
|
97
|
+
|
|
98
|
+
return ListItem.create(value, margin_y="0.5em")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _a(value: object):
|
|
102
|
+
from reflex.components.radix.themes.typography.link import Link
|
|
103
|
+
|
|
104
|
+
return Link.create(value)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _code(value: object):
|
|
108
|
+
from reflex.components.radix.themes.typography.code import Code
|
|
109
|
+
|
|
110
|
+
return Code.create(value)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _codeblock(value: object, **props):
|
|
114
|
+
from reflex.components.datadisplay.code import CodeBlock
|
|
115
|
+
|
|
116
|
+
return CodeBlock.create(value, margin_y="1em", wrap_long_lines=True, **props)
|
|
117
|
+
|
|
118
|
+
|
|
41
119
|
# Component Mapping
|
|
42
120
|
@lru_cache
|
|
43
121
|
def get_base_component_map() -> dict[str, Callable]:
|
|
@@ -46,33 +124,20 @@ def get_base_component_map() -> dict[str, Callable]:
|
|
|
46
124
|
Returns:
|
|
47
125
|
The base component map.
|
|
48
126
|
"""
|
|
49
|
-
from reflex.components.datadisplay.code import CodeBlock
|
|
50
|
-
from reflex.components.radix.themes.layout.list import (
|
|
51
|
-
ListItem,
|
|
52
|
-
OrderedList,
|
|
53
|
-
UnorderedList,
|
|
54
|
-
)
|
|
55
|
-
from reflex.components.radix.themes.typography.code import Code
|
|
56
|
-
from reflex.components.radix.themes.typography.heading import Heading
|
|
57
|
-
from reflex.components.radix.themes.typography.link import Link
|
|
58
|
-
from reflex.components.radix.themes.typography.text import Text
|
|
59
|
-
|
|
60
127
|
return {
|
|
61
|
-
"h1":
|
|
62
|
-
"h2":
|
|
63
|
-
"h3":
|
|
64
|
-
"h4":
|
|
65
|
-
"h5":
|
|
66
|
-
"h6":
|
|
67
|
-
"p":
|
|
68
|
-
"ul":
|
|
69
|
-
"ol":
|
|
70
|
-
"li":
|
|
71
|
-
"a":
|
|
72
|
-
"code":
|
|
73
|
-
"codeblock":
|
|
74
|
-
value, margin_y="1em", wrap_long_lines=True, **props
|
|
75
|
-
),
|
|
128
|
+
"h1": _h1,
|
|
129
|
+
"h2": _h2,
|
|
130
|
+
"h3": _h3,
|
|
131
|
+
"h4": _h4,
|
|
132
|
+
"h5": _h5,
|
|
133
|
+
"h6": _h6,
|
|
134
|
+
"p": _p,
|
|
135
|
+
"ul": _ul,
|
|
136
|
+
"ol": _ol,
|
|
137
|
+
"li": _li,
|
|
138
|
+
"a": _a,
|
|
139
|
+
"code": _code,
|
|
140
|
+
"codeblock": _codeblock,
|
|
76
141
|
}
|
|
77
142
|
|
|
78
143
|
|
|
@@ -413,7 +478,16 @@ let {_LANGUAGE!s} = match ? match[1] : '';
|
|
|
413
478
|
@staticmethod
|
|
414
479
|
def _component_map_hash(component_map: dict) -> str:
|
|
415
480
|
inp = str(
|
|
416
|
-
{
|
|
481
|
+
{
|
|
482
|
+
tag: (
|
|
483
|
+
f"{component.__module__}.{component.__qualname__}"
|
|
484
|
+
if (
|
|
485
|
+
"<" not in component.__name__
|
|
486
|
+
) # simple way to check against lambdas
|
|
487
|
+
else component(_MOCK_ARG)
|
|
488
|
+
)
|
|
489
|
+
for tag, component in component_map.items()
|
|
490
|
+
}
|
|
417
491
|
).encode()
|
|
418
492
|
return md5(inp).hexdigest()
|
|
419
493
|
|
reflex/constants/base.py
CHANGED
|
@@ -134,6 +134,11 @@ class Templates(SimpleNamespace):
|
|
|
134
134
|
# The reflex.build frontend host
|
|
135
135
|
REFLEX_BUILD_FRONTEND = "https://build.reflex.dev"
|
|
136
136
|
|
|
137
|
+
# The reflex.build frontend with referrer
|
|
138
|
+
REFLEX_BUILD_FRONTEND_WITH_REFERRER = (
|
|
139
|
+
f"{REFLEX_BUILD_FRONTEND}/?utm_source=reflex_cli"
|
|
140
|
+
)
|
|
141
|
+
|
|
137
142
|
class Dirs(SimpleNamespace):
|
|
138
143
|
"""Folders used by the template system of Reflex."""
|
|
139
144
|
|
reflex/constants/installer.py
CHANGED
|
@@ -143,11 +143,11 @@ class PackageJson(SimpleNamespace):
|
|
|
143
143
|
"postcss-import": "16.1.1",
|
|
144
144
|
"@react-router/dev": _react_router_version,
|
|
145
145
|
"@react-router/fs-routes": _react_router_version,
|
|
146
|
-
"vite": "npm:rolldown-vite@7.1.
|
|
146
|
+
"vite": "npm:rolldown-vite@7.1.16",
|
|
147
147
|
}
|
|
148
148
|
OVERRIDES = {
|
|
149
149
|
# This should always match the `react` version in DEPENDENCIES for recharts compatibility.
|
|
150
150
|
"react-is": _react_version,
|
|
151
151
|
"cookie": "1.0.2",
|
|
152
|
-
"vite": "npm:rolldown-vite@7.1.
|
|
152
|
+
"vite": "npm:rolldown-vite@7.1.16",
|
|
153
153
|
}
|
reflex/event.py
CHANGED
|
@@ -1866,6 +1866,9 @@ def fix_events(
|
|
|
1866
1866
|
# Fix the events created by the handler.
|
|
1867
1867
|
out = []
|
|
1868
1868
|
for e in events:
|
|
1869
|
+
if callable(e) and getattr(e, "__name__", "") == "<lambda>":
|
|
1870
|
+
# A lambda was returned, assume the user wants to call it with no args.
|
|
1871
|
+
e = e()
|
|
1869
1872
|
if isinstance(e, Event):
|
|
1870
1873
|
# If the event is already an event, append it to the list.
|
|
1871
1874
|
out.append(e)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""State manager for managing client states."""
|
|
2
|
+
|
|
3
|
+
import contextlib
|
|
4
|
+
import dataclasses
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from collections.abc import AsyncIterator
|
|
7
|
+
|
|
8
|
+
from reflex import constants
|
|
9
|
+
from reflex.config import get_config
|
|
10
|
+
from reflex.state import BaseState
|
|
11
|
+
from reflex.utils import console, prerequisites
|
|
12
|
+
from reflex.utils.exceptions import InvalidStateManagerModeError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclasses.dataclass
|
|
16
|
+
class StateManager(ABC):
|
|
17
|
+
"""A class to manage many client states."""
|
|
18
|
+
|
|
19
|
+
# The state class to use.
|
|
20
|
+
state: type[BaseState]
|
|
21
|
+
|
|
22
|
+
@classmethod
|
|
23
|
+
def create(cls, state: type[BaseState]):
|
|
24
|
+
"""Create a new state manager.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
state: The state class to use.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
InvalidStateManagerModeError: If the state manager mode is invalid.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
The state manager (either disk, memory or redis).
|
|
34
|
+
"""
|
|
35
|
+
config = get_config()
|
|
36
|
+
if prerequisites.parse_redis_url() is not None:
|
|
37
|
+
config.state_manager_mode = constants.StateManagerMode.REDIS
|
|
38
|
+
if config.state_manager_mode == constants.StateManagerMode.MEMORY:
|
|
39
|
+
from reflex.istate.manager.memory import StateManagerMemory
|
|
40
|
+
|
|
41
|
+
return StateManagerMemory(state=state)
|
|
42
|
+
if config.state_manager_mode == constants.StateManagerMode.DISK:
|
|
43
|
+
from reflex.istate.manager.disk import StateManagerDisk
|
|
44
|
+
|
|
45
|
+
return StateManagerDisk(state=state)
|
|
46
|
+
if config.state_manager_mode == constants.StateManagerMode.REDIS:
|
|
47
|
+
redis = prerequisites.get_redis()
|
|
48
|
+
if redis is not None:
|
|
49
|
+
from reflex.istate.manager.redis import StateManagerRedis
|
|
50
|
+
|
|
51
|
+
# make sure expiration values are obtained only from the config object on creation
|
|
52
|
+
return StateManagerRedis(
|
|
53
|
+
state=state,
|
|
54
|
+
redis=redis,
|
|
55
|
+
token_expiration=config.redis_token_expiration,
|
|
56
|
+
lock_expiration=config.redis_lock_expiration,
|
|
57
|
+
lock_warning_threshold=config.redis_lock_warning_threshold,
|
|
58
|
+
)
|
|
59
|
+
msg = f"Expected one of: DISK, MEMORY, REDIS, got {config.state_manager_mode}"
|
|
60
|
+
raise InvalidStateManagerModeError(msg)
|
|
61
|
+
|
|
62
|
+
@abstractmethod
|
|
63
|
+
async def get_state(self, token: str) -> BaseState:
|
|
64
|
+
"""Get the state for a token.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
token: The token to get the state for.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
The state for the token.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
@abstractmethod
|
|
74
|
+
async def set_state(self, token: str, state: BaseState):
|
|
75
|
+
"""Set the state for a token.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
token: The token to set the state for.
|
|
79
|
+
state: The state to set.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
@abstractmethod
|
|
83
|
+
@contextlib.asynccontextmanager
|
|
84
|
+
async def modify_state(self, token: str) -> AsyncIterator[BaseState]:
|
|
85
|
+
"""Modify the state for a token while holding exclusive lock.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
token: The token to modify the state for.
|
|
89
|
+
|
|
90
|
+
Yields:
|
|
91
|
+
The state for the token.
|
|
92
|
+
"""
|
|
93
|
+
yield self.state()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _default_token_expiration() -> int:
|
|
97
|
+
"""Get the default token expiration time.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
The default token expiration time.
|
|
101
|
+
"""
|
|
102
|
+
return get_config().redis_token_expiration
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def reset_disk_state_manager():
|
|
106
|
+
"""Reset the disk state manager."""
|
|
107
|
+
console.debug("Resetting disk state manager.")
|
|
108
|
+
states_directory = prerequisites.get_states_dir()
|
|
109
|
+
if states_directory.exists():
|
|
110
|
+
for path in states_directory.iterdir():
|
|
111
|
+
path.unlink()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def get_state_manager() -> StateManager:
|
|
115
|
+
"""Get the state manager for the app that is currently running.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
The state manager.
|
|
119
|
+
"""
|
|
120
|
+
return prerequisites.get_and_validate_app().app.state_manager
|