@@ -35,22 +35,18 @@ class MinifyConfig(TypedDict):
3535
3636
3737def _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
4642def _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:
289281def 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
303294def 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
0 commit comments