Skip to content

Restructure frontend TS files so managers/stores export destructors instead of returning them from their constructors#3919

Merged
Keavon merged 3 commits intomasterfrom
restructure-frontend-arch
Mar 20, 2026
Merged

Restructure frontend TS files so managers/stores export destructors instead of returning them from their constructors#3919
Keavon merged 3 commits intomasterfrom
restructure-frontend-arch

Conversation

@Keavon
Copy link
Member

@Keavon Keavon commented Mar 20, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the frontend architecture by introducing explicit creation and destruction functions for managers and stores, enhancing modularity and HMR compatibility. It also adds a mechanism for the frontend to request a full resend of UI layouts from the backend, addressing potential state loss during HMR. Minor improvements include converting a Rust enum to a macro for better maintainability and adding a new ESLint rule for stricter TypeScript.

Highlights

  • Frontend Architecture Refactor: The frontend managers and stores have been refactored to use explicit createManager/destroyManager and createStore/destroyStore functions, moving away from global currentCleanup/currentArgs variables for HMR. This improves modularity and hot-module replacement (HMR) reliability.
  • Layout Resend Mechanism: A new ResendAllLayouts message and corresponding handler have been added to the Rust backend. This allows the frontend to request a full resend of all UI layouts, which is crucial for restoring UI state after an HMR re-mount.
  • LayoutTarget Macro: The LayoutTarget enum in Rust has been converted into a macro, simplifying its definition and ensuring consistency.
  • ESLint Rule Addition: A new ESLint rule @typescript-eslint/no-non-null-assertion has been added to the frontend configuration, enforcing stricter TypeScript practices.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant architectural changes to the frontend, primarily focusing on improving resource management and Hot Module Replacement (HMR) compatibility. The refactoring shifts from returning manager/store instances with destroy methods to using module-scoped variables and explicit create and destroy functions. This centralizes resource cleanup in Editor.svelte's onDestroy lifecycle hook, which is a cleaner approach for managing subscriptions and event listeners during HMR re-mounts. The addition of ResendAllLayouts in the Rust backend and its invocation in the frontend ensures UI state consistency after HMR. The new define_layout_target! macro in Rust is a good improvement for enum definition maintainability. The ESLint rule addition for non-null assertions enhances type safety. Overall, these changes are well-considered and improve the robustness and maintainability of the application.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 21 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="frontend/src/managers/persistence.ts">

<violation number="1" location="frontend/src/managers/persistence.ts:44">
P2: Create and reuse one module-level `idb.createStore(...)` instead of recreating it in each function/handler.</violation>
</file>

<file name="frontend/src/managers/fonts.ts">

<violation number="1" location="frontend/src/managers/fonts.ts:9">
P2: The module-scoped AbortController is reused after being aborted, so fetches fail after manager teardown/recreation (including HMR).</violation>
</file>

<file name="frontend/src/stores/app-window.ts">

<violation number="1" location="frontend/src/stores/app-window.ts:32">
P2: Overwriting a single global `editorRef` makes store cleanup instance-unsafe; re-creating the store before teardown can leak old frontend message subscriptions.</violation>
</file>

<file name="frontend/src/managers/input.ts">

<violation number="1" location="frontend/src/managers/input.ts:555">
P1: Unconditional `app?.focus()` steals focus on every input event. In the original code, focus was only restored when `!canvasFocused && newInCanvasArea`. This line forces focus to the app container on every pointer move, key press, etc., breaking text inputs, menus, and all non-canvas interactions. Remove this line — the conditional `app?.focus()` inside the `if` block below handles the intended behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@github-actions github-actions bot temporarily deployed to graphite-dev (Preview) March 20, 2026 00:42 Inactive
@Keavon Keavon changed the title Restructure frontend arch Restructure frontend TS files so managers/stores export destructors instead of returning them from their constructors Mar 20, 2026
@github-actions github-actions bot temporarily deployed to graphite-dev (Preview) March 20, 2026 01:15 Inactive
@Keavon Keavon merged commit 2e2c4fe into master Mar 20, 2026
17 of 18 checks passed
@Keavon Keavon deleted the restructure-frontend-arch branch March 20, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant