reflex 0.8.8a2__py3-none-any.whl → 0.8.9a1__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/app.py +15 -5
- reflex/compiler/templates.py +19 -3
- reflex/compiler/utils.py +7 -4
- reflex/components/component.py +64 -34
- reflex/components/el/elements/media.py +518 -0
- reflex/components/lucide/icon.py +3 -0
- reflex/components/radix/primitives/drawer.pyi +4 -0
- reflex/config.py +1 -1
- reflex/constants/installer.py +4 -4
- reflex/environment.py +8 -3
- reflex/istate/data.py +15 -0
- reflex/plugins/sitemap.py +3 -6
- reflex/reflex.py +8 -2
- reflex/state.py +46 -6
- reflex/testing.py +1 -1
- reflex/utils/console.py +67 -7
- reflex/utils/frontend_skeleton.py +6 -1
- reflex/utils/imports.py +1 -1
- reflex/utils/prerequisites.py +3 -1
- reflex/utils/pyi_generator.py +2 -2
- reflex/utils/serializers.py +4 -4
- reflex/utils/types.py +7 -10
- reflex/vars/base.py +24 -17
- reflex/vars/object.py +4 -2
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a1.dist-info}/METADATA +1 -1
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a1.dist-info}/RECORD +29 -29
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a1.dist-info}/WHEEL +0 -0
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a1.dist-info}/entry_points.txt +0 -0
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a1.dist-info}/licenses/LICENSE +0 -0
reflex/app.py
CHANGED
|
@@ -1100,12 +1100,18 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1100
1100
|
for substate in state.class_subclasses:
|
|
1101
1101
|
self._validate_var_dependencies(substate)
|
|
1102
1102
|
|
|
1103
|
-
def _compile(
|
|
1103
|
+
def _compile(
|
|
1104
|
+
self,
|
|
1105
|
+
prerender_routes: bool = False,
|
|
1106
|
+
dry_run: bool = False,
|
|
1107
|
+
use_rich: bool = True,
|
|
1108
|
+
):
|
|
1104
1109
|
"""Compile the app and output it to the pages folder.
|
|
1105
1110
|
|
|
1106
1111
|
Args:
|
|
1107
1112
|
prerender_routes: Whether to prerender the routes.
|
|
1108
1113
|
dry_run: Whether to compile the app without saving it.
|
|
1114
|
+
use_rich: Whether to use rich progress bars.
|
|
1109
1115
|
|
|
1110
1116
|
Raises:
|
|
1111
1117
|
ReflexRuntimeError: When any page uses state, but no rx.State subclass is defined.
|
|
@@ -1171,10 +1177,14 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1171
1177
|
return
|
|
1172
1178
|
|
|
1173
1179
|
# Create a progress bar.
|
|
1174
|
-
progress =
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1180
|
+
progress = (
|
|
1181
|
+
Progress(
|
|
1182
|
+
*Progress.get_default_columns()[:-1],
|
|
1183
|
+
MofNCompleteColumn(),
|
|
1184
|
+
TimeElapsedColumn(),
|
|
1185
|
+
)
|
|
1186
|
+
if use_rich
|
|
1187
|
+
else console.PoorProgress()
|
|
1178
1188
|
)
|
|
1179
1189
|
|
|
1180
1190
|
# try to be somewhat accurate - but still not 100%
|
reflex/compiler/templates.py
CHANGED
|
@@ -362,7 +362,7 @@ export const UploadFilesContext = createContext(null);
|
|
|
362
362
|
export const DispatchContext = createContext(null);
|
|
363
363
|
export const StateContexts = {{{state_contexts_str}}};
|
|
364
364
|
export const EventLoopContext = createContext(null);
|
|
365
|
-
export const clientStorage = {"{}" if client_storage is None else
|
|
365
|
+
export const clientStorage = {"{}" if client_storage is None else json.dumps(client_storage)}
|
|
366
366
|
|
|
367
367
|
{state_str}
|
|
368
368
|
|
|
@@ -502,11 +502,13 @@ def package_json_template(
|
|
|
502
502
|
)
|
|
503
503
|
|
|
504
504
|
|
|
505
|
-
def vite_config_template(base: str):
|
|
505
|
+
def vite_config_template(base: str, hmr: bool, force_full_reload: bool):
|
|
506
506
|
"""Template for vite.config.js.
|
|
507
507
|
|
|
508
508
|
Args:
|
|
509
509
|
base: The base path for the Vite config.
|
|
510
|
+
hmr: Whether to enable hot module replacement.
|
|
511
|
+
force_full_reload: Whether to force a full reload on changes.
|
|
510
512
|
|
|
511
513
|
Returns:
|
|
512
514
|
Rendered vite.config.js content as string.
|
|
@@ -537,12 +539,25 @@ function alwaysUseReactDomServerNode() {{
|
|
|
537
539
|
}};
|
|
538
540
|
}}
|
|
539
541
|
|
|
542
|
+
function fullReload() {{
|
|
543
|
+
return {{
|
|
544
|
+
name: "full-reload",
|
|
545
|
+
enforce: "pre",
|
|
546
|
+
handleHotUpdate({{ server }}) {{
|
|
547
|
+
server.ws.send({{
|
|
548
|
+
type: "full-reload",
|
|
549
|
+
}});
|
|
550
|
+
return [];
|
|
551
|
+
}}
|
|
552
|
+
}};
|
|
553
|
+
}}
|
|
554
|
+
|
|
540
555
|
export default defineConfig((config) => ({{
|
|
541
556
|
plugins: [
|
|
542
557
|
alwaysUseReactDomServerNode(),
|
|
543
558
|
reactRouter(),
|
|
544
559
|
safariCacheBustPlugin(),
|
|
545
|
-
],
|
|
560
|
+
].concat({"[fullReload()]" if force_full_reload else "[]"}),
|
|
546
561
|
build: {{
|
|
547
562
|
assetsDir: "{base}assets".slice(1),
|
|
548
563
|
rollupOptions: {{
|
|
@@ -564,6 +579,7 @@ export default defineConfig((config) => ({{
|
|
|
564
579
|
}},
|
|
565
580
|
server: {{
|
|
566
581
|
port: process.env.PORT,
|
|
582
|
+
hmr: {"true" if hmr else "false"},
|
|
567
583
|
watch: {{
|
|
568
584
|
ignored: [
|
|
569
585
|
"**/.web/backend/**",
|
reflex/compiler/utils.py
CHANGED
|
@@ -220,10 +220,13 @@ def compile_state(state: type[BaseState]) -> dict:
|
|
|
220
220
|
|
|
221
221
|
def _compile_client_storage_field(
|
|
222
222
|
field: Field,
|
|
223
|
-
) ->
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
]
|
|
223
|
+
) -> (
|
|
224
|
+
tuple[
|
|
225
|
+
type[Cookie] | type[LocalStorage] | type[SessionStorage],
|
|
226
|
+
dict[str, Any],
|
|
227
|
+
]
|
|
228
|
+
| tuple[None, None]
|
|
229
|
+
):
|
|
227
230
|
"""Compile the given cookie, local_storage or session_storage field.
|
|
228
231
|
|
|
229
232
|
Args:
|
reflex/components/component.py
CHANGED
|
@@ -419,7 +419,6 @@ def evaluate_style_namespaces(style: ComponentStyle) -> dict:
|
|
|
419
419
|
|
|
420
420
|
# Map from component to styling.
|
|
421
421
|
ComponentStyle = dict[str | type[BaseComponent] | Callable | ComponentNamespace, Any]
|
|
422
|
-
ComponentChild = types.PrimitiveType | Var | BaseComponent
|
|
423
422
|
ComponentChildTypes = (*types.PrimitiveTypes, Var, BaseComponent, type(None))
|
|
424
423
|
|
|
425
424
|
|
|
@@ -480,7 +479,21 @@ def _components_from(
|
|
|
480
479
|
return ()
|
|
481
480
|
|
|
482
481
|
|
|
483
|
-
def
|
|
482
|
+
def _hash_str(value: str) -> str:
|
|
483
|
+
return md5(f'"{value}"'.encode(), usedforsecurity=False).hexdigest()
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _hash_sequence(value: Sequence) -> str:
|
|
487
|
+
return _hash_str(str([_deterministic_hash(v) for v in value]))
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def _hash_dict(value: dict) -> str:
|
|
491
|
+
return _hash_sequence(
|
|
492
|
+
sorted([(k, _deterministic_hash(v)) for k, v in value.items()])
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def _deterministic_hash(value: object) -> str:
|
|
484
497
|
"""Hash a rendered dictionary.
|
|
485
498
|
|
|
486
499
|
Args:
|
|
@@ -492,37 +505,28 @@ def _deterministic_hash(value: object) -> int:
|
|
|
492
505
|
Raises:
|
|
493
506
|
TypeError: If the value is not hashable.
|
|
494
507
|
"""
|
|
495
|
-
if
|
|
496
|
-
#
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if isinstance(value, Var):
|
|
500
|
-
return _deterministic_hash((value._js_expr, value._get_all_var_data()))
|
|
501
|
-
if isinstance(value, VarData):
|
|
502
|
-
return _deterministic_hash(dataclasses.asdict(value))
|
|
503
|
-
if isinstance(value, dict):
|
|
504
|
-
# Sort the dictionary to ensure consistent hashing.
|
|
505
|
-
return _deterministic_hash(
|
|
506
|
-
tuple(sorted((k, _deterministic_hash(v)) for k, v in value.items()))
|
|
507
|
-
)
|
|
508
|
-
if isinstance(value, int):
|
|
508
|
+
if value is None:
|
|
509
|
+
# Hash None as a special case.
|
|
510
|
+
return "None"
|
|
511
|
+
if isinstance(value, (int, float, enum.Enum)):
|
|
509
512
|
# Hash numbers and booleans directly.
|
|
510
|
-
return
|
|
511
|
-
if isinstance(value, float):
|
|
512
|
-
return _deterministic_hash(str(value))
|
|
513
|
+
return str(value)
|
|
513
514
|
if isinstance(value, str):
|
|
514
|
-
return
|
|
515
|
+
return _hash_str(value)
|
|
516
|
+
if isinstance(value, dict):
|
|
517
|
+
return _hash_dict(value)
|
|
515
518
|
if isinstance(value, (tuple, list)):
|
|
516
519
|
# Hash tuples by hashing each element.
|
|
517
|
-
return
|
|
518
|
-
|
|
520
|
+
return _hash_sequence(value)
|
|
521
|
+
if isinstance(value, Var):
|
|
522
|
+
return _hash_str(
|
|
523
|
+
str((value._js_expr, _deterministic_hash(value._get_all_var_data())))
|
|
519
524
|
)
|
|
520
|
-
if isinstance(value,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
return _deterministic_hash("None")
|
|
525
|
+
if isinstance(value, VarData):
|
|
526
|
+
return _hash_dict(dataclasses.asdict(value))
|
|
527
|
+
if isinstance(value, BaseComponent):
|
|
528
|
+
# If the value is a component, hash its rendered code.
|
|
529
|
+
return _hash_dict(value.render())
|
|
526
530
|
|
|
527
531
|
msg = (
|
|
528
532
|
f"Cannot hash value `{value}` of type `{type(value).__name__}`. "
|
|
@@ -1038,9 +1042,13 @@ class Component(BaseComponent, ABC):
|
|
|
1038
1042
|
name
|
|
1039
1043
|
for name in cls.get_fields()
|
|
1040
1044
|
if name in cls.get_props()
|
|
1041
|
-
and
|
|
1042
|
-
types.value_inside_optional(
|
|
1045
|
+
and isinstance(
|
|
1046
|
+
field_type := types.value_inside_optional(
|
|
1047
|
+
types.get_field_type(cls, name)
|
|
1048
|
+
),
|
|
1049
|
+
type,
|
|
1043
1050
|
)
|
|
1051
|
+
and issubclass(field_type, Component)
|
|
1044
1052
|
}
|
|
1045
1053
|
|
|
1046
1054
|
def _get_components_in_props(self) -> Sequence[BaseComponent]:
|
|
@@ -1508,8 +1516,9 @@ class Component(BaseComponent, ABC):
|
|
|
1508
1516
|
Returns:
|
|
1509
1517
|
A sequence of parent classes that define the method (differently than the base).
|
|
1510
1518
|
"""
|
|
1519
|
+
current_class_method = getattr(Component, method, None)
|
|
1511
1520
|
seen_methods = (
|
|
1512
|
-
{
|
|
1521
|
+
{current_class_method} if current_class_method is not None else set()
|
|
1513
1522
|
)
|
|
1514
1523
|
clzs: list[type[Component]] = []
|
|
1515
1524
|
for clz in cls.mro():
|
|
@@ -1807,7 +1816,7 @@ class Component(BaseComponent, ABC):
|
|
|
1807
1816
|
|
|
1808
1817
|
# Add the hook code from add_hooks for each parent class (this is reversed to preserve
|
|
1809
1818
|
# the order of the hooks in the final output)
|
|
1810
|
-
for clz in reversed(
|
|
1819
|
+
for clz in reversed(self._iter_parent_classes_with_method("add_hooks")):
|
|
1811
1820
|
for hook in clz.add_hooks(self):
|
|
1812
1821
|
if isinstance(hook, Var):
|
|
1813
1822
|
extract_var_hooks(hook)
|
|
@@ -2190,6 +2199,9 @@ def _register_custom_component(
|
|
|
2190
2199
|
Args:
|
|
2191
2200
|
component_fn: The function that creates the component.
|
|
2192
2201
|
|
|
2202
|
+
Returns:
|
|
2203
|
+
The custom component.
|
|
2204
|
+
|
|
2193
2205
|
Raises:
|
|
2194
2206
|
TypeError: If the tag name cannot be determined.
|
|
2195
2207
|
"""
|
|
@@ -2214,6 +2226,7 @@ def _register_custom_component(
|
|
|
2214
2226
|
msg = f"Could not determine the tag name for {component_fn!r}"
|
|
2215
2227
|
raise TypeError(msg)
|
|
2216
2228
|
CUSTOM_COMPONENTS[dummy_component.tag] = dummy_component
|
|
2229
|
+
return dummy_component
|
|
2217
2230
|
|
|
2218
2231
|
|
|
2219
2232
|
def custom_component(
|
|
@@ -2237,7 +2250,24 @@ def custom_component(
|
|
|
2237
2250
|
)
|
|
2238
2251
|
|
|
2239
2252
|
# Register this component so it can be compiled.
|
|
2240
|
-
_register_custom_component(component_fn)
|
|
2253
|
+
dummy_component = _register_custom_component(component_fn)
|
|
2254
|
+
if tag := dummy_component.tag:
|
|
2255
|
+
object.__setattr__(
|
|
2256
|
+
wrapper,
|
|
2257
|
+
"_as_var",
|
|
2258
|
+
lambda: Var(
|
|
2259
|
+
tag,
|
|
2260
|
+
_var_type=type[Component],
|
|
2261
|
+
_var_data=VarData(
|
|
2262
|
+
imports={
|
|
2263
|
+
f"$/{constants.Dirs.UTILS}/components": [ImportVar(tag=tag)],
|
|
2264
|
+
"@emotion/react": [
|
|
2265
|
+
ImportVar(tag="jsx"),
|
|
2266
|
+
],
|
|
2267
|
+
}
|
|
2268
|
+
),
|
|
2269
|
+
),
|
|
2270
|
+
)
|
|
2241
2271
|
|
|
2242
2272
|
return wrapper
|
|
2243
2273
|
|
|
@@ -2457,7 +2487,7 @@ class StatefulComponent(BaseComponent):
|
|
|
2457
2487
|
return None
|
|
2458
2488
|
|
|
2459
2489
|
# Compute the hash based on the rendered code.
|
|
2460
|
-
code_hash = _deterministic_hash(rendered_code)
|
|
2490
|
+
code_hash = _hash_str(_deterministic_hash(rendered_code))
|
|
2461
2491
|
|
|
2462
2492
|
# Format the tag name including the hash.
|
|
2463
2493
|
return format.format_state_name(
|