Skip to content

Commit 05fde77

Browse files
cleanup
1 parent c99b450 commit 05fde77

2 files changed

Lines changed: 24 additions & 44 deletions

File tree

reflex/minify.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,18 @@ class MinifyConfig(TypedDict):
3535

3636

3737
def _get_minify_json_path() -> Path:
38-
"""Get the path to the minify.json file.
39-
40-
Returns:
41-
Path to minify.json in the current working directory.
42-
"""
38+
"""Return the path to ``minify.json`` in the current working directory."""
4339
return Path.cwd() / MINIFY_JSON
4440

4541

4642
def _load_minify_config_uncached() -> MinifyConfig | None:
47-
"""Load minify configuration from minify.json.
43+
"""Load and validate ``minify.json`` from disk.
4844
4945
Returns:
50-
The parsed configuration, or None if file doesn't exist.
46+
The parsed config, or ``None`` if the file is absent.
5147
5248
Raises:
53-
ValueError: If the file exists but has an invalid format.
49+
ValueError: If the file exists but is malformed.
5450
"""
5551
path = _get_minify_json_path()
5652
if not path.exists():
@@ -196,13 +192,9 @@ class MinifyNameResolver:
196192

197193
@classmethod
198194
def from_disk(cls) -> MinifyNameResolver:
199-
"""Build a resolver from the current ``minify.json`` and env vars.
195+
"""Build a resolver from ``minify.json`` (uncached) and env vars.
200196
201-
Bypasses the lru_cache on :func:`get_minify_config` so the snapshot
202-
reflects the cwd at install time. A malformed config becomes
203-
``config=None`` (graceful degradation — the app still runs without
204-
minification) and a warning is logged once per install so the user
205-
notices.
197+
Malformed configs degrade gracefully to ``config=None`` with a warning.
206198
207199
Returns:
208200
A configured resolver.
@@ -224,7 +216,7 @@ def from_disk(cls) -> MinifyNameResolver:
224216
)
225217

226218
def _is_minify_allowed(self, state_cls: type[BaseState], enabled: bool) -> bool:
227-
"""Whether minification applies to ``state_cls`` for the given mode.
219+
"""Whether ``state_cls`` is eligible for minification under the given mode.
228220
229221
Args:
230222
state_cls: The state class being resolved.
@@ -289,10 +281,9 @@ def _is_framework_state(state_cls: type[BaseState]) -> bool:
289281
def install_minify_resolver() -> None:
290282
"""Install a fresh :class:`MinifyNameResolver` into the active context.
291283
292-
Must run before any state class is registered:
293-
:func:`reflex_base.vars.base.VarData.from_state` captures the state's
294-
full name at Var-creation time, so a later install would leave dangling
295-
references in the generated frontend.
284+
Must run before any state class registers — :func:`VarData.from_state`
285+
captures the state's full name at Var-creation time, so a later install
286+
leaves dangling references in the generated frontend.
296287
"""
297288
from reflex_base.registry import RegistrationContext
298289

@@ -301,22 +292,20 @@ def install_minify_resolver() -> None:
301292

302293

303294
def ensure_minify_resolver_for_active_context() -> None:
304-
"""Install a :class:`MinifyNameResolver` for the active context if needed.
295+
"""Install a :class:`MinifyNameResolver` if one isn't already in place.
305296
306-
Idempotent in the steady state — safe to wire into hot paths
307-
(e.g. :func:`reflex.utils.prerequisites.get_app`, which can be re-entered
308-
at runtime from a different cwd than the one that loaded the config).
309-
Re-installs only when something on disk could have changed: a config
310-
appearing where there wasn't one, or a non-minify resolver in the slot.
297+
Idempotent — safe to wire into hot paths like
298+
:func:`reflex.utils.prerequisites.get_app`. Re-installs only when on-disk
299+
state could have changed (config appearing, or non-minify resolver).
311300
"""
312301
from reflex_base.registry import RegistrationContext
313302

314303
ctx = RegistrationContext.ensure_context()
315304
if isinstance(ctx.name_resolver, MinifyNameResolver):
316305
if ctx.name_resolver.config is not None:
317-
return # already loaded with a config — no work to do
306+
return
318307
if not _get_minify_json_path().exists():
319-
return # no config and none on disk; nothing changed
308+
return
320309
ctx.set_name_resolver(MinifyNameResolver.from_disk())
321310

322311

reflex/state.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ def __init_subclass__(cls, mixin: bool = False, **kwargs):
494494

495495
super().__init_subclass__(**kwargs)
496496

497-
# Mixin states are not initialized
498497
if cls._mixin:
499498
return
500499

@@ -1004,11 +1003,9 @@ def get_class_substate(
10041003
10051004
Args:
10061005
path: The path to the substate.
1007-
_skip_self: Internal recursion flag — leave at the default. Only
1008-
the root call strips a leading segment that matches
1009-
``cls.get_name()``; recursion passes ``False`` so a child
1010-
that shares a minified name with its parent (``"a.b.b"``)
1011-
still resolves to the child.
1006+
_skip_self: Internal recursion flag; leave at the default. Allows
1007+
``"a.b.b"`` to resolve to a child that shares its parent's
1008+
minified name.
10121009
10131010
Returns:
10141011
The class substate.
@@ -1538,11 +1535,9 @@ def get_substate(self, path: Sequence[str], _skip_self: bool = True) -> BaseStat
15381535
15391536
Args:
15401537
path: The path to the substate.
1541-
_skip_self: Internal recursion flag — leave at the default. Only
1542-
the root call strips a leading segment that matches
1543-
``self.get_name()``; recursion passes ``False`` so a child
1544-
that shares a minified name with its parent (``"a.b.b"``)
1545-
still resolves to the child.
1538+
_skip_self: Internal recursion flag; leave at the default. Allows
1539+
``"a.b.b"`` to resolve to a child that shares its parent's
1540+
minified name.
15461541
15471542
Returns:
15481543
The substate.
@@ -2334,9 +2329,7 @@ def handle_frontend_exception(
23342329
class UpdateVarsInternalState(State):
23352330
"""Substate for handling internal state var updates."""
23362331

2337-
# ``__init_subclass__`` replaces the method below with an ``EventHandler``
2338-
# instance on the class. Splitting via ``TYPE_CHECKING`` lets callers
2339-
# (e.g. ``format_event_handler``) see the post-rewrite type.
2332+
# See ``FrontendEventExceptionState`` for why this is split.
23402333
if TYPE_CHECKING:
23412334
update_vars_internal: EventHandler
23422335
else:
@@ -2368,9 +2361,7 @@ class OnLoadInternalState(State):
23682361
This is a separate substate to avoid deserializing the entire state tree for every page navigation.
23692362
"""
23702363

2371-
# ``__init_subclass__`` replaces the method below with an ``EventHandler``
2372-
# instance on the class. Splitting via ``TYPE_CHECKING`` lets callers
2373-
# (e.g. ``format_event_handler``) see the post-rewrite type.
2364+
# See ``FrontendEventExceptionState`` for why this is split.
23742365
if TYPE_CHECKING:
23752366
on_load_internal: EventHandler
23762367

0 commit comments

Comments
 (0)