reflex 0.3.2__py3-none-any.whl → 0.3.3a1__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.

Files changed (48) hide show
  1. reflex/.templates/jinja/web/pages/custom_component.js.jinja2 +20 -3
  2. reflex/.templates/web/next.config.js +1 -0
  3. reflex/.templates/web/utils/helpers/range.js +43 -0
  4. reflex/.templates/web/utils/state.js +10 -6
  5. reflex/__init__.py +312 -40
  6. reflex/__init__.pyi +477 -0
  7. reflex/compiler/compiler.py +3 -0
  8. reflex/components/__init__.py +138 -138
  9. reflex/components/component.py +29 -22
  10. reflex/components/datadisplay/__init__.py +3 -1
  11. reflex/components/datadisplay/code.py +388 -14
  12. reflex/components/datadisplay/code.pyi +1146 -10
  13. reflex/components/forms/button.py +3 -0
  14. reflex/components/forms/checkbox.py +3 -0
  15. reflex/components/forms/form.py +90 -27
  16. reflex/components/forms/input.py +3 -0
  17. reflex/components/forms/numberinput.py +3 -0
  18. reflex/components/forms/pininput.py +77 -21
  19. reflex/components/forms/radio.py +3 -0
  20. reflex/components/forms/rangeslider.py +3 -0
  21. reflex/components/forms/select.py +3 -0
  22. reflex/components/forms/slider.py +3 -0
  23. reflex/components/forms/switch.py +3 -0
  24. reflex/components/forms/textarea.py +3 -0
  25. reflex/components/libs/chakra.py +2 -0
  26. reflex/components/libs/chakra.pyi +323 -24
  27. reflex/components/tags/tag.py +3 -2
  28. reflex/components/typography/markdown.py +10 -0
  29. reflex/constants/installer.py +4 -4
  30. reflex/event.py +4 -0
  31. reflex/page.py +3 -4
  32. reflex/page.pyi +17 -0
  33. reflex/reflex.py +3 -0
  34. reflex/state.py +31 -12
  35. reflex/testing.py +1 -1
  36. reflex/utils/build.py +24 -19
  37. reflex/utils/console.py +5 -1
  38. reflex/utils/format.py +26 -9
  39. reflex/utils/prerequisites.py +27 -28
  40. reflex/utils/processes.py +5 -4
  41. reflex/vars.py +80 -12
  42. reflex/vars.pyi +7 -0
  43. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/METADATA +3 -2
  44. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/RECORD +47 -45
  45. reflex/.templates/web/styles/code/prism.js +0 -1015
  46. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/LICENSE +0 -0
  47. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/WHEEL +0 -0
  48. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/entry_points.txt +0 -0
@@ -1,14 +1,330 @@
1
- """Stub file for chakra.py"""
1
+ """Stub file for reflex/components/libs/chakra.py"""
2
2
  # ------------------- DO NOT EDIT ----------------------
3
3
  # This file was generated by `scripts/pyi_generator.py`!
4
4
  # ------------------------------------------------------
5
5
 
6
- from typing import Literal, Optional, Union, overload
7
- from reflex.components.component import Component
6
+ from typing import Optional, Literal, Any, overload, List, Union, Dict
8
7
  from reflex.vars import Var, BaseVar, ComputedVar
9
- from reflex.event import EventHandler, EventChain, EventSpec
8
+ from reflex.event import EventChain, EventHandler, EventSpec
9
+ from reflex.style import Style
10
+ from typing import List, Literal
11
+ from reflex.components.component import Component
12
+ from reflex.utils import imports
13
+ from reflex.vars import ImportVar, Var
14
+
15
+ class ChakraComponent(Component):
16
+ ...
17
+
18
+ @overload
19
+ @classmethod
20
+ def create( # type: ignore
21
+ cls,
22
+ *children,
23
+ style: Optional[Style] = None,
24
+ key: Optional[Any] = None,
25
+ id: Optional[Any] = None,
26
+ class_name: Optional[Any] = None,
27
+ autofocus: Optional[bool] = None,
28
+ custom_attrs: Optional[Dict[str, str]] = None,
29
+ on_blur: Optional[
30
+ Union[EventHandler, EventSpec, List, function, BaseVar]
31
+ ] = None,
32
+ on_click: Optional[
33
+ Union[EventHandler, EventSpec, List, function, BaseVar]
34
+ ] = None,
35
+ on_context_menu: Optional[
36
+ Union[EventHandler, EventSpec, List, function, BaseVar]
37
+ ] = None,
38
+ on_double_click: Optional[
39
+ Union[EventHandler, EventSpec, List, function, BaseVar]
40
+ ] = None,
41
+ on_focus: Optional[
42
+ Union[EventHandler, EventSpec, List, function, BaseVar]
43
+ ] = None,
44
+ on_mount: Optional[
45
+ Union[EventHandler, EventSpec, List, function, BaseVar]
46
+ ] = None,
47
+ on_mouse_down: Optional[
48
+ Union[EventHandler, EventSpec, List, function, BaseVar]
49
+ ] = None,
50
+ on_mouse_enter: Optional[
51
+ Union[EventHandler, EventSpec, List, function, BaseVar]
52
+ ] = None,
53
+ on_mouse_leave: Optional[
54
+ Union[EventHandler, EventSpec, List, function, BaseVar]
55
+ ] = None,
56
+ on_mouse_move: Optional[
57
+ Union[EventHandler, EventSpec, List, function, BaseVar]
58
+ ] = None,
59
+ on_mouse_out: Optional[
60
+ Union[EventHandler, EventSpec, List, function, BaseVar]
61
+ ] = None,
62
+ on_mouse_over: Optional[
63
+ Union[EventHandler, EventSpec, List, function, BaseVar]
64
+ ] = None,
65
+ on_mouse_up: Optional[
66
+ Union[EventHandler, EventSpec, List, function, BaseVar]
67
+ ] = None,
68
+ on_scroll: Optional[
69
+ Union[EventHandler, EventSpec, List, function, BaseVar]
70
+ ] = None,
71
+ on_unmount: Optional[
72
+ Union[EventHandler, EventSpec, List, function, BaseVar]
73
+ ] = None,
74
+ **props
75
+ ) -> "ChakraComponent":
76
+ """Create the component.
77
+
78
+ Args:
79
+ *children: The children of the component.
80
+ style: The style of the component.
81
+ key: A unique key for the component.
82
+ id: The id for the component.
83
+ class_name: The class name for the component.
84
+ autofocus: Whether the component should take the focus once the page is loaded
85
+ custom_attrs: custom attribute
86
+ **props: The props of the component.
87
+
88
+ Returns:
89
+ The component.
90
+
91
+ Raises:
92
+ TypeError: If an invalid child is passed.
93
+ """
94
+ ...
95
+
96
+ class Global(Component):
97
+ ...
98
+
99
+ @overload
100
+ @classmethod
101
+ def create( # type: ignore
102
+ cls,
103
+ *children,
104
+ styles: Optional[Union[Var[str], str]] = None,
105
+ style: Optional[Style] = None,
106
+ key: Optional[Any] = None,
107
+ id: Optional[Any] = None,
108
+ class_name: Optional[Any] = None,
109
+ autofocus: Optional[bool] = None,
110
+ custom_attrs: Optional[Dict[str, str]] = None,
111
+ on_blur: Optional[
112
+ Union[EventHandler, EventSpec, List, function, BaseVar]
113
+ ] = None,
114
+ on_click: Optional[
115
+ Union[EventHandler, EventSpec, List, function, BaseVar]
116
+ ] = None,
117
+ on_context_menu: Optional[
118
+ Union[EventHandler, EventSpec, List, function, BaseVar]
119
+ ] = None,
120
+ on_double_click: Optional[
121
+ Union[EventHandler, EventSpec, List, function, BaseVar]
122
+ ] = None,
123
+ on_focus: Optional[
124
+ Union[EventHandler, EventSpec, List, function, BaseVar]
125
+ ] = None,
126
+ on_mount: Optional[
127
+ Union[EventHandler, EventSpec, List, function, BaseVar]
128
+ ] = None,
129
+ on_mouse_down: Optional[
130
+ Union[EventHandler, EventSpec, List, function, BaseVar]
131
+ ] = None,
132
+ on_mouse_enter: Optional[
133
+ Union[EventHandler, EventSpec, List, function, BaseVar]
134
+ ] = None,
135
+ on_mouse_leave: Optional[
136
+ Union[EventHandler, EventSpec, List, function, BaseVar]
137
+ ] = None,
138
+ on_mouse_move: Optional[
139
+ Union[EventHandler, EventSpec, List, function, BaseVar]
140
+ ] = None,
141
+ on_mouse_out: Optional[
142
+ Union[EventHandler, EventSpec, List, function, BaseVar]
143
+ ] = None,
144
+ on_mouse_over: Optional[
145
+ Union[EventHandler, EventSpec, List, function, BaseVar]
146
+ ] = None,
147
+ on_mouse_up: Optional[
148
+ Union[EventHandler, EventSpec, List, function, BaseVar]
149
+ ] = None,
150
+ on_scroll: Optional[
151
+ Union[EventHandler, EventSpec, List, function, BaseVar]
152
+ ] = None,
153
+ on_unmount: Optional[
154
+ Union[EventHandler, EventSpec, List, function, BaseVar]
155
+ ] = None,
156
+ **props
157
+ ) -> "Global":
158
+ """Create the component.
159
+
160
+ Args:
161
+ *children: The children of the component.
162
+ style: The style of the component.
163
+ key: A unique key for the component.
164
+ id: The id for the component.
165
+ class_name: The class name for the component.
166
+ autofocus: Whether the component should take the focus once the page is loaded
167
+ custom_attrs: custom attribute
168
+ **props: The props of the component.
169
+
170
+ Returns:
171
+ The component.
172
+
173
+ Raises:
174
+ TypeError: If an invalid child is passed.
175
+ """
176
+ ...
177
+
178
+ class ChakraProvider(ChakraComponent):
179
+ @overload
180
+ @classmethod
181
+ def create( # type: ignore
182
+ cls,
183
+ *children,
184
+ theme: Optional[Union[Var[str], str]] = None,
185
+ style: Optional[Style] = None,
186
+ key: Optional[Any] = None,
187
+ id: Optional[Any] = None,
188
+ class_name: Optional[Any] = None,
189
+ autofocus: Optional[bool] = None,
190
+ custom_attrs: Optional[Dict[str, str]] = None,
191
+ on_blur: Optional[
192
+ Union[EventHandler, EventSpec, List, function, BaseVar]
193
+ ] = None,
194
+ on_click: Optional[
195
+ Union[EventHandler, EventSpec, List, function, BaseVar]
196
+ ] = None,
197
+ on_context_menu: Optional[
198
+ Union[EventHandler, EventSpec, List, function, BaseVar]
199
+ ] = None,
200
+ on_double_click: Optional[
201
+ Union[EventHandler, EventSpec, List, function, BaseVar]
202
+ ] = None,
203
+ on_focus: Optional[
204
+ Union[EventHandler, EventSpec, List, function, BaseVar]
205
+ ] = None,
206
+ on_mount: Optional[
207
+ Union[EventHandler, EventSpec, List, function, BaseVar]
208
+ ] = None,
209
+ on_mouse_down: Optional[
210
+ Union[EventHandler, EventSpec, List, function, BaseVar]
211
+ ] = None,
212
+ on_mouse_enter: Optional[
213
+ Union[EventHandler, EventSpec, List, function, BaseVar]
214
+ ] = None,
215
+ on_mouse_leave: Optional[
216
+ Union[EventHandler, EventSpec, List, function, BaseVar]
217
+ ] = None,
218
+ on_mouse_move: Optional[
219
+ Union[EventHandler, EventSpec, List, function, BaseVar]
220
+ ] = None,
221
+ on_mouse_out: Optional[
222
+ Union[EventHandler, EventSpec, List, function, BaseVar]
223
+ ] = None,
224
+ on_mouse_over: Optional[
225
+ Union[EventHandler, EventSpec, List, function, BaseVar]
226
+ ] = None,
227
+ on_mouse_up: Optional[
228
+ Union[EventHandler, EventSpec, List, function, BaseVar]
229
+ ] = None,
230
+ on_scroll: Optional[
231
+ Union[EventHandler, EventSpec, List, function, BaseVar]
232
+ ] = None,
233
+ on_unmount: Optional[
234
+ Union[EventHandler, EventSpec, List, function, BaseVar]
235
+ ] = None,
236
+ **props
237
+ ) -> "ChakraProvider":
238
+ """Create a new ChakraProvider component.
239
+
240
+ Returns:
241
+ A new ChakraProvider component.
242
+ """
243
+ ...
244
+
245
+ class ChakraColorModeProvider(Component):
246
+ ...
247
+
248
+ @overload
249
+ @classmethod
250
+ def create( # type: ignore
251
+ cls,
252
+ *children,
253
+ style: Optional[Style] = None,
254
+ key: Optional[Any] = None,
255
+ id: Optional[Any] = None,
256
+ class_name: Optional[Any] = None,
257
+ autofocus: Optional[bool] = None,
258
+ custom_attrs: Optional[Dict[str, str]] = None,
259
+ on_blur: Optional[
260
+ Union[EventHandler, EventSpec, List, function, BaseVar]
261
+ ] = None,
262
+ on_click: Optional[
263
+ Union[EventHandler, EventSpec, List, function, BaseVar]
264
+ ] = None,
265
+ on_context_menu: Optional[
266
+ Union[EventHandler, EventSpec, List, function, BaseVar]
267
+ ] = None,
268
+ on_double_click: Optional[
269
+ Union[EventHandler, EventSpec, List, function, BaseVar]
270
+ ] = None,
271
+ on_focus: Optional[
272
+ Union[EventHandler, EventSpec, List, function, BaseVar]
273
+ ] = None,
274
+ on_mount: Optional[
275
+ Union[EventHandler, EventSpec, List, function, BaseVar]
276
+ ] = None,
277
+ on_mouse_down: Optional[
278
+ Union[EventHandler, EventSpec, List, function, BaseVar]
279
+ ] = None,
280
+ on_mouse_enter: Optional[
281
+ Union[EventHandler, EventSpec, List, function, BaseVar]
282
+ ] = None,
283
+ on_mouse_leave: Optional[
284
+ Union[EventHandler, EventSpec, List, function, BaseVar]
285
+ ] = None,
286
+ on_mouse_move: Optional[
287
+ Union[EventHandler, EventSpec, List, function, BaseVar]
288
+ ] = None,
289
+ on_mouse_out: Optional[
290
+ Union[EventHandler, EventSpec, List, function, BaseVar]
291
+ ] = None,
292
+ on_mouse_over: Optional[
293
+ Union[EventHandler, EventSpec, List, function, BaseVar]
294
+ ] = None,
295
+ on_mouse_up: Optional[
296
+ Union[EventHandler, EventSpec, List, function, BaseVar]
297
+ ] = None,
298
+ on_scroll: Optional[
299
+ Union[EventHandler, EventSpec, List, function, BaseVar]
300
+ ] = None,
301
+ on_unmount: Optional[
302
+ Union[EventHandler, EventSpec, List, function, BaseVar]
303
+ ] = None,
304
+ **props
305
+ ) -> "ChakraColorModeProvider":
306
+ """Create the component.
307
+
308
+ Args:
309
+ *children: The children of the component.
310
+ style: The style of the component.
311
+ key: A unique key for the component.
312
+ id: The id for the component.
313
+ class_name: The class name for the component.
314
+ autofocus: Whether the component should take the focus once the page is loaded
315
+ custom_attrs: custom attribute
316
+ **props: The props of the component.
317
+
318
+ Returns:
319
+ The component.
320
+
321
+ Raises:
322
+ TypeError: If an invalid child is passed.
323
+ """
324
+ ...
10
325
 
11
326
  LiteralColorScheme = Literal[
327
+ "none",
12
328
  "gray",
13
329
  "red",
14
330
  "orange",
@@ -32,6 +348,7 @@ LiteralColorScheme = Literal[
32
348
  LiteralVariant = Literal["solid", "subtle", "outline"]
33
349
  LiteralDividerVariant = Literal["solid", "dashed"]
34
350
  LiteralTheme = Literal["light", "dark"]
351
+
35
352
  LiteralTagColorScheme = Literal[
36
353
  "gray",
37
354
  "red",
@@ -94,8 +411,8 @@ LiteralCardVariant = Literal["outline", "filled", "elevated", "unstyled"]
94
411
  LiteralStackDirection = Literal["row", "column"]
95
412
  LiteralImageLoading = Literal["eager", "lazy"]
96
413
  LiteralTagSize = Literal["sm", "md", "lg"]
97
- LiteralSpinnerSize = Literal[Literal[LiteralTagSize], "xs"]
98
- LiteralAvatarSize = Literal[Literal[LiteralTagSize], "xs", "2xl", "full", "2xs"]
414
+ LiteralSpinnerSize = Literal[Literal[LiteralTagSize], "xs", "xl"]
415
+ LiteralAvatarSize = Literal[Literal[LiteralTagSize], "xl", "xs", "2xl", "full", "2xs"]
99
416
  LiteralButtonSize = Literal["sm", "md", "lg", "xs"]
100
417
  # Applies to AlertDialog and Modal
101
418
  LiteralAlertDialogSize = Literal[
@@ -108,21 +425,3 @@ LiteralMenuOption = Literal["checkbox", "radio"]
108
425
  LiteralPopOverTrigger = Literal["click", "hover"]
109
426
 
110
427
  LiteralHeadingSize = Literal["lg", "md", "sm", "xs", "xl", "2xl", "3xl", "4xl"]
111
-
112
- class ChakraComponent(Component):
113
- @overload
114
- @classmethod
115
- def create(cls, *children, on_blur: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_click: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_context_menu: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_double_click: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_focus: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mount: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mouse_down: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mouse_enter: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mouse_leave: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mouse_move: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mouse_out: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mouse_over: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_mouse_up: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_scroll: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, on_unmount: Optional[Union[EventHandler, EventSpec, List, function, BaseVar]] = None, **props) -> "ChakraComponent": # type: ignore
116
- """Create the component.
117
-
118
- Args:
119
- *children: The children of the component.
120
- **props: The props of the component.
121
-
122
- Returns:
123
- The component.
124
-
125
- Raises:
126
- TypeError: If an invalid child is passed.
127
- """
128
- ...
@@ -83,8 +83,9 @@ class Tag(Base):
83
83
  The tag with the props removed.
84
84
  """
85
85
  for name in args:
86
- if name in self.props:
87
- del self.props[name]
86
+ prop_name = format.to_camel_case(name)
87
+ if prop_name in self.props:
88
+ del self.props[prop_name]
88
89
  return self
89
90
 
90
91
  @staticmethod
@@ -240,6 +240,16 @@ class Markdown(Component):
240
240
  ] = f"""{{({{inline, className, {_CHILDREN._var_name}, {_PROPS._var_name}}}) => {{
241
241
  const match = (className || '').match(/language-(?<lang>.*)/);
242
242
  const language = match ? match[1] : '';
243
+ if (language) {{
244
+ (async () => {{
245
+ try {{
246
+ const module = await import(`react-syntax-highlighter/dist/cjs/languages/prism/${{language}}`);
247
+ SyntaxHighlighter.registerLanguage(language, module.default);
248
+ }} catch (error) {{
249
+ console.error(`Error importing language module for ${{language}}:`, error);
250
+ }}
251
+ }})();
252
+ }}
243
253
  return inline ? (
244
254
  {self.format_component("code")}
245
255
  ) : (
@@ -95,8 +95,8 @@ class PackageJson(SimpleNamespace):
95
95
  """The commands to define in package.json."""
96
96
 
97
97
  DEV = "next dev"
98
- EXPORT = "next build && next export -o _static"
99
- EXPORT_SITEMAP = "next build && next-sitemap && next export -o _static"
98
+ EXPORT = "next build"
99
+ EXPORT_SITEMAP = "next build && next-sitemap"
100
100
  PROD = "next start"
101
101
 
102
102
  PATH = os.path.join(Dirs.WEB, "package.json")
@@ -106,7 +106,7 @@ class PackageJson(SimpleNamespace):
106
106
  "focus-visible": "5.2.0",
107
107
  "framer-motion": "10.16.4",
108
108
  "json5": "2.2.3",
109
- "next": "13.5.4",
109
+ "next": "14.0.1",
110
110
  "next-sitemap": "4.1.8",
111
111
  "next-themes": "0.2.0",
112
112
  "react": "18.2.0",
@@ -116,5 +116,5 @@ class PackageJson(SimpleNamespace):
116
116
  }
117
117
  DEV_DEPENDENCIES = {
118
118
  "autoprefixer": "10.4.14",
119
- "postcss": "8.4.24",
119
+ "postcss": "8.4.31",
120
120
  }
reflex/event.py CHANGED
@@ -270,6 +270,10 @@ class FileUpload(Base):
270
270
  pass
271
271
 
272
272
 
273
+ # Alias for rx.upload_files
274
+ upload_files = FileUpload
275
+
276
+
273
277
  # Special server-side events.
274
278
  def server_side(name: str, sig: inspect.Signature, **kwargs) -> EventSpec:
275
279
  """A server-side event.
reflex/page.py CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from reflex.components.component import Component
6
- from reflex.event import EventHandler
5
+ from typing import Any
7
6
 
8
7
  DECORATED_PAGES = []
9
8
 
@@ -14,8 +13,8 @@ def page(
14
13
  image: str | None = None,
15
14
  description: str | None = None,
16
15
  meta: str | None = None,
17
- script_tags: list[Component] | None = None,
18
- on_load: EventHandler | list[EventHandler] | None = None,
16
+ script_tags: list[Any] | None = None,
17
+ on_load: Any | list[Any] | None = None,
19
18
  ):
20
19
  """Decorate a function as a page.
21
20
 
reflex/page.pyi ADDED
@@ -0,0 +1,17 @@
1
+ """The page decorator and associated variables and functions."""
2
+
3
+ from reflex.components.component import Component
4
+ from reflex.event import EventHandler
5
+
6
+ DECORATED_PAGES: list
7
+
8
+ def page(
9
+ route: str | None = None,
10
+ title: str | None = None,
11
+ image: str | None = None,
12
+ description: str | None = None,
13
+ meta: str | None = None,
14
+ script_tags: list[Component] | None = None,
15
+ on_load: EventHandler | list[EventHandler] | None = None,
16
+ ): ...
17
+ def get_decorated_pages() -> list[dict]: ...
reflex/reflex.py CHANGED
@@ -184,6 +184,7 @@ def _run(
184
184
  console.rule("[bold]Starting Reflex App")
185
185
 
186
186
  if frontend:
187
+ prerequisites.update_next_config()
187
188
  # Get the app module.
188
189
  prerequisites.get_app()
189
190
 
@@ -337,6 +338,8 @@ def export(
337
338
  console.rule("[bold]Compiling production app and preparing for export.")
338
339
 
339
340
  if frontend:
341
+ # Update some parameters for export
342
+ prerequisites.update_next_config(export=True)
340
343
  # Ensure module can be imported and app.compile() is called.
341
344
  prerequisites.get_app()
342
345
  # Set up .web directory and install frontend dependencies.
reflex/state.py CHANGED
@@ -43,9 +43,11 @@ from reflex.event import (
43
43
  )
44
44
  from reflex.utils import console, format, prerequisites, types
45
45
  from reflex.utils.exceptions import ImmutableStateError, LockExpiredError
46
+ from reflex.utils.serializers import SerializedType, serialize, serializer
46
47
  from reflex.vars import BaseVar, ComputedVar, Var
47
48
 
48
49
  Delta = Dict[str, Any]
50
+ var = ComputedVar
49
51
 
50
52
 
51
53
  class HeaderData(Base):
@@ -1900,7 +1902,7 @@ class MutableProxy(wrapt.ObjectProxy):
1900
1902
  """
1901
1903
  return self._wrap_recursive(wrapped(*args, **kwargs))
1902
1904
 
1903
- def __getattribute__(self, __name: str) -> Any:
1905
+ def __getattr__(self, __name: str) -> Any:
1904
1906
  """Get the attribute on the proxied object and return a proxy if mutable.
1905
1907
 
1906
1908
  Args:
@@ -1909,26 +1911,24 @@ class MutableProxy(wrapt.ObjectProxy):
1909
1911
  Returns:
1910
1912
  The attribute value.
1911
1913
  """
1912
- value = super().__getattribute__(__name)
1914
+ value = super().__getattr__(__name)
1913
1915
 
1914
1916
  if callable(value):
1915
- if __name in super().__getattribute__("__mark_dirty_attrs__"):
1917
+ if __name in self.__mark_dirty_attrs__:
1916
1918
  # Wrap special callables, like "append", which should mark state dirty.
1917
- value = wrapt.FunctionWrapper(
1918
- value,
1919
- super().__getattribute__("_mark_dirty"),
1920
- )
1919
+ value = wrapt.FunctionWrapper(value, self._mark_dirty)
1921
1920
 
1922
- if __name in super().__getattribute__("__wrap_mutable_attrs__"):
1921
+ if __name in self.__wrap_mutable_attrs__:
1923
1922
  # Wrap methods that may return mutable objects tied to the state.
1924
1923
  value = wrapt.FunctionWrapper(
1925
1924
  value,
1926
- super().__getattribute__("_wrap_recursive_decorator"),
1925
+ self._wrap_recursive_decorator,
1927
1926
  )
1928
1927
 
1929
- if isinstance(
1930
- value, super().__getattribute__("__mutable_types__")
1931
- ) and __name not in ("__wrapped__", "_self_state"):
1928
+ if isinstance(value, self.__mutable_types__) and __name not in (
1929
+ "__wrapped__",
1930
+ "_self_state",
1931
+ ):
1932
1932
  # Recursively wrap mutable attribute values retrieved through this proxy.
1933
1933
  return self._wrap_recursive(value)
1934
1934
 
@@ -2018,6 +2018,25 @@ class MutableProxy(wrapt.ObjectProxy):
2018
2018
  return copy.deepcopy(self.__wrapped__, memo=memo)
2019
2019
 
2020
2020
 
2021
+ @serializer
2022
+ def serialize_mutable_proxy(mp: MutableProxy) -> SerializedType:
2023
+ """Serialize the wrapped value of a MutableProxy.
2024
+
2025
+ Args:
2026
+ mp: The MutableProxy to serialize.
2027
+
2028
+ Returns:
2029
+ The serialized wrapped object.
2030
+
2031
+ Raises:
2032
+ ValueError: when the wrapped object is not serializable.
2033
+ """
2034
+ value = serialize(mp.__wrapped__)
2035
+ if value is None:
2036
+ raise ValueError(f"Cannot serialize {type(mp.__wrapped__)}")
2037
+ return value
2038
+
2039
+
2021
2040
  class ImmutableMutableProxy(MutableProxy):
2022
2041
  """A proxy for a mutable object that tracks changes.
2023
2042
 
reflex/testing.py CHANGED
@@ -677,7 +677,7 @@ class AppHarnessProd(AppHarness):
677
677
  frontend_server: Optional[Subdir404TCPServer] = None
678
678
 
679
679
  def _run_frontend(self):
680
- web_root = self.app_path / reflex.constants.Dirs.WEB / "_static"
680
+ web_root = self.app_path / reflex.constants.Dirs.WEB_STATIC
681
681
  error_page_map = {
682
682
  404: web_root / "404.html",
683
683
  }
reflex/utils/build.py CHANGED
@@ -35,21 +35,25 @@ def set_os_env(**kwargs):
35
35
  os.environ[key.upper()] = value
36
36
 
37
37
 
38
- def generate_sitemap_config(deploy_url: str):
38
+ def generate_sitemap_config(deploy_url: str, export=False):
39
39
  """Generate the sitemap config file.
40
40
 
41
41
  Args:
42
42
  deploy_url: The URL of the deployed app.
43
+ export: If the sitemap are generated for an export.
43
44
  """
44
45
  # Import here to avoid circular imports.
45
46
  from reflex.compiler import templates
46
47
 
47
- config = json.dumps(
48
- {
49
- "siteUrl": deploy_url,
50
- "generateRobotsTxt": True,
51
- }
52
- )
48
+ config = {
49
+ "siteUrl": deploy_url,
50
+ "generateRobotsTxt": True,
51
+ }
52
+
53
+ if export:
54
+ config["outDir"] = constants.Dirs.STATIC
55
+
56
+ config = json.dumps(config)
53
57
 
54
58
  with open(constants.Next.SITEMAP_CONFIG_FILE, "w") as f:
55
59
  f.write(templates.SITEMAP_CONFIG(config=config))
@@ -115,7 +119,7 @@ def _zip(
115
119
 
116
120
  with progress, zipfile.ZipFile(target, "w", zipfile.ZIP_DEFLATED) as zipf:
117
121
  for file in files_to_zip:
118
- console.debug(f"{target}: {file}")
122
+ console.debug(f"{target}: {file}", progress=progress)
119
123
  progress.advance(task)
120
124
  zipf.write(file, os.path.relpath(file, root_dir))
121
125
 
@@ -145,22 +149,23 @@ def export(
145
149
  command = "export"
146
150
 
147
151
  if frontend:
148
- # Generate a sitemap if a deploy URL is provided.
149
- if deploy_url is not None:
150
- generate_sitemap_config(deploy_url)
151
- command = "export-sitemap"
152
-
153
152
  checkpoints = [
154
153
  "Linting and checking ",
155
- "Compiled successfully",
154
+ "Creating an optimized production build",
156
155
  "Route (pages)",
156
+ "prerendered as static HTML",
157
157
  "Collecting page data",
158
- "automatically rendered as static HTML",
159
- 'Copying "static build" directory',
160
- 'Copying "public" directory',
161
158
  "Finalizing page optimization",
162
- "Export successful",
159
+ "Collecting build traces",
163
160
  ]
161
+
162
+ # Generate a sitemap if a deploy URL is provided.
163
+ if deploy_url is not None:
164
+ generate_sitemap_config(deploy_url, export=zip)
165
+ command = "export-sitemap"
166
+
167
+ checkpoints.extend(["Loading next-sitemap", "Generation completed"])
168
+
164
169
  # Start the subprocess with the progress bar.
165
170
  process = processes.new_process(
166
171
  [prerequisites.get_package_manager(), "run", command],
@@ -181,7 +186,7 @@ def export(
181
186
  target=os.path.join(
182
187
  zip_dest_dir, constants.ComponentName.FRONTEND.zip()
183
188
  ),
184
- root_dir=".web/_static",
189
+ root_dir=constants.Dirs.WEB_STATIC,
185
190
  files_to_exclude=files_to_exclude,
186
191
  exclude_venv_dirs=False,
187
192
  )