Mutable compilation state for an entire compile run.
| 752 | |
| 753 | @dataclasses.dataclass(slots=True, kw_only=True) |
| 754 | class CompileContext(BaseContext): |
| 755 | """Mutable compilation state for an entire compile run.""" |
| 756 | |
| 757 | app: App | None = None |
| 758 | pages: Sequence[PageDefinition] |
| 759 | hooks: CompilerHooks = dataclasses.field(default_factory=CompilerHooks) |
| 760 | compiled_pages: dict[str, PageContext] = dataclasses.field(default_factory=dict) |
| 761 | all_imports: ParsedImportDict = dataclasses.field(default_factory=dict) |
| 762 | app_wrap_components: dict[tuple[int, str], Component] = dataclasses.field( |
| 763 | default_factory=dict |
| 764 | ) |
| 765 | stateful_routes: dict[str, None] = dataclasses.field(default_factory=dict) |
| 766 | # Auto-memoize wrapper tags seen during the tree walk (populated by |
| 767 | # ``MemoizeStatefulPlugin``). |
| 768 | memoize_wrappers: dict[str, None] = dataclasses.field(default_factory=dict) |
| 769 | # Compiler-generated memo definitions for auto-memoized stateful wrappers. |
| 770 | # Keyed by ``(tag, source_module)`` so identical-rendering subtrees from |
| 771 | # different user modules each get their own entry and emit into the right |
| 772 | # mirrored memo file. Stored as ``Any`` to avoid an import cycle with |
| 773 | # ``reflex_base.components.memo``. |
| 774 | auto_memo_components: dict[tuple[str, str | None], Any] = dataclasses.field( |
| 775 | default_factory=dict |
| 776 | ) |
| 777 | |
| 778 | def compile( |
| 779 | self, |
| 780 | *, |
| 781 | evaluate_progress: Callable[[], None] | None = None, |
| 782 | render_progress: Callable[[], None] | None = None, |
| 783 | **kwargs: Any, |
| 784 | ) -> dict[str, PageContext]: |
| 785 | """Compile all configured pages through the plugin pipeline. |
| 786 | |
| 787 | Args: |
| 788 | evaluate_progress: Callback invoked after each page evaluation. |
| 789 | render_progress: Callback invoked after each page render. |
| 790 | kwargs: Additional compiler-specific context. |
| 791 | |
| 792 | Returns: |
| 793 | The compiled page contexts keyed by route. |
| 794 | """ |
| 795 | from reflex.compiler import compiler |
| 796 | from reflex.state import all_base_state_classes |
| 797 | |
| 798 | self.ensure_context_attached() |
| 799 | self.compiled_pages.clear() |
| 800 | self.all_imports.clear() |
| 801 | self.app_wrap_components.clear() |
| 802 | self.stateful_routes.clear() |
| 803 | self.memoize_wrappers.clear() |
| 804 | self.auto_memo_components.clear() |
| 805 | |
| 806 | for page in self.pages: |
| 807 | page_fn = page.component |
| 808 | n_states_before = len(all_base_state_classes) |
| 809 | page_ctx = self.hooks.eval_page( |
| 810 | page_fn, |
| 811 | page=page, |
no outgoing calls