Sfoglia il codice sorgente

[REF-2587] Ignore top-level theme appearance (#3119)

* pyi_generator: ignore `app.py` and single files

When running pyi_generator in pre-commit, it passes individual changed files on
the command line as targets, and these were not being properly excluded
according to the EXCLUDED_FILES list.

Add app.py to the EXCLUDED_FILES list so it does not get regenerated
automatically.

* [REF-2587] Ignore top-level theme appearance

From the Radix docs, it is not recommended to actually set `appearance`, but
instead use next-themes to set and switch the appearance dynamically.

Because Reflex already compiles the top-level theme into the next-themes
ThemeProvider, we can blank out the appearance prop after compiling contexts.js
to avoid a mismatch between the selected app appearance and the appearance in
the rx.theme when displaying overlay components.

Fix #2992
Masen Furer 1 anno fa
parent
commit
6ca5f48ae7
2 ha cambiato i file con 9 aggiunte e 1 eliminazioni
  1. 3 0
      reflex/app.py
  2. 6 1
      reflex/utils/pyi_generator.py

+ 3 - 0
reflex/app.py

@@ -839,6 +839,9 @@ class App(Base):
         compile_results.append(
             compiler.compile_contexts(self.state, self.theme),
         )
+        # Fix #2992 by removing the top-level appearance prop
+        if self.theme is not None:
+            self.theme.appearance = None
 
         app_root = self._app_root(app_wrappers=app_wrappers)
 

+ 6 - 1
reflex/utils/pyi_generator.py

@@ -34,6 +34,7 @@ PWD = Path(".").resolve()
 
 EXCLUDED_FILES = [
     "__init__.py",
+    "app.py",
     "component.py",
     "bare.py",
     "foreach.py",
@@ -795,7 +796,11 @@ class PyiGenerator:
         file_targets = []
         for target in targets:
             target_path = Path(target)
-            if target_path.is_file() and target_path.suffix == ".py":
+            if (
+                target_path.is_file()
+                and target_path.suffix == ".py"
+                and target_path.name not in EXCLUDED_FILES
+            ):
                 file_targets.append(target_path)
                 continue
             if not target_path.is_dir():