Introducing a new way to review your PRs.

Read the announcement

walterlow / freecut

FreeCut is a professional-grade video editor that runs entirely in your browser. Professional video editing, zero installation. Create stunning videos with multi-track editing, keyframe animations, real-time preview, and high-quality exports.

View on GitHub

19 documents · Updated Oct 30, 2026

docs / application-shell-and-routing

Application shell and routing

FreeCut's application shell starts the browser app, prepares the user-selected workspace, and places the right top-level surface behind the router. It keeps public pages easy to open while protecting project and editor pages with storage access and recovery paths.

Application bootstrap

The application bootstrap turns the static HTML entry point into a running React app. It clears production service-worker state during development, waits for translations, then mounts the shell that owns the router and global recovery UI.

Startup sequence

The startup path separates browser preparation from app rendering. This prevents an old production cache from controlling a development session and ensures that the first rendered page has its language resources ready.

flowchart TD
    A[index.html] --> B[src/bootstrap.ts]
    B -->|development cleanup| C{Production service worker present?}
    C -->|yes| D[Unregister worker and clear app-shell cache]
    C -->|no| E[Load main entry]
    D --> E
    E --> F[Wait for i18n]
    F --> G[Render App]
    G --> H[ErrorBoundary]
    H --> I[WorkspaceGate]
    I --> J[RouterProvider]

The shell also installs global browser safeguards and event listeners. It keeps browser zoom from changing the editor view, makes a toast host available on demand, and records uncaught errors for diagnosis without changing the route flow.

References: index.html• L1-23 src/bootstrap.ts• L1-36 src/main.tsx• L1-14 src/main.tsx• L233-240 src/app.tsx• L26-93

Route structure

TanStack Router maps the URL to a small set of public, project, editor, documentation, and release-note surfaces. The root route supplies the outlet; each child route owns the page or loader needed for that URL.

Route families

The route tree gives the application a clear progression from discovery to project work. The /projects/:projectId path is a compatibility entry that sends project settings links to the editor rather than opening a separate settings page.

Route familyPurposeWorkspace access
/Public landing page with product overview and entry linksNot required
/projectsProject library, import, trash, and workspace controlsRequired
/projects/newProject creation formRequired
/projects/:projectIdRedirect from a project URL to its editorRequired
/editor/:projectIdEditor entry point for one projectRequired
/docs and /docs/:slugDocumentation overview and article pagesNot required
/changelogRelease historyNot required

The editor route checks that the requested project exists and passes only the project details needed to start the editor. The editor view is loaded separately, so opening an editor URL can validate the project before the larger editing surface is ready.

References: src/…/__root.tsx• L1-5 src/routeTree.gen.ts• L11-62 src/…/index.lazy.tsx• L1-14 src/…/index.lazy.tsx• L1-43 src/…/$projectId.tsx• L1-39 src/…/$projectId.lazy.tsx• L1-13 src/…/$projectId.tsx• L1-12

Project entry flow

Project creation and project import converge on the same editor URL. This keeps the project library responsible for choosing or creating a project while the editor remains responsible for editing it.

flowchart LR
    A[/projects/] -->|New project| B[/projects/new]
    B -->|Create succeeds| C[/editor/:projectId]
    A -->|Import bundle| C
    D[/projects/:projectId] -->|Redirect| C
    C -->|Back with save or discard| A

The project library refreshes its data when the route loads, and it keeps a populated list visible during later mutations. The editor asks for confirmation before leaving when its timeline has unsaved changes.

References: src/…/index.lazy.tsx• L41-43 src/…/index.lazy.tsx• L92-95 src/…/index.lazy.tsx• L157-201 src/…/new.tsx• L18-28 src/…/new.tsx• L36-56 src/…/toolbar.tsx• L131-136 src/…/unsaved-changes-dialog.tsx• L37-54

Workspace gating

A storage workspace is the user-selected folder that holds FreeCut project data and related files. WorkspaceGate sits outside RouterProvider so protected route loaders never run before the folder is active and usable.

Protected route access

The gate checks the current pathname outside the router. It lets public pages render while it checks the saved folder in the background, but it blocks /projects* and /editor* until read/write access is ready.

sequenceDiagram
    participant User
    participant Gate as WorkspaceGate
    participant DB as Handle record store
    participant Folder as User folder
    participant Router

    Gate->>DB: Read active workspace handle
    alt No saved handle
        Gate-->>User: Show choose-folder surface
        User->>Folder: Pick folder and grant access
        Gate->>DB: Save active handle
    else Saved handle
        Gate->>Folder: Check permission
        alt Permission granted
            Gate->>Folder: Prepare workspace
        else Permission missing
            Gate-->>User: Show reconnect surface
        end
    end
    Gate->>Router: Render protected route

When access is granted, the gate activates the folder, prepares its FreeCut workspace, and starts cleanup work after the first render. If access is lost during a session, it returns to the reconnect state instead of allowing storage actions to fail without guidance.

References: src/app.tsx• L70-91 src/…/workspace-gate.tsx• L37-80 src/…/workspace-gate.tsx• L82-127 src/…/use-pathname.ts• L1-63 src/…/handles-db.ts• L113-180

Workspace controls

The project page exposes the active folder and known folders through WorkspaceIndicator. A user can add, switch, or forget a known folder; changes reload the app so the same gate runs again with one clear active workspace.

The gate also distinguishes unsupported browsers, a first-time folder choice, and a lost permission. The unsupported path points to the workspace guide, while the other states provide a folder action that matches the recovery needed.

References: src/…/workspace-indicator.tsx• L1-13 src/…/workspace-indicator.tsx• L77-128 src/…/workspace-gate-splash.tsx• L19-117 src/…/index.lazy.tsx• L263-320

Error and preload recovery

FreeCut uses separate recovery layers for render errors, route-load errors, and stale or failed lazy-module loads. Each layer keeps the user on a useful path and avoids treating an expected missing project or a short network fault as an unrelated application failure.

Route error recovery

The router owns errors raised before a route component mounts. Its error screen turns a missing project into a direct path back to the project library, explains known storage permission failures in plain language, and offers retry, reload, folder change, or copyable diagnostic details as appropriate.

React render errors use the app-level ErrorBoundary instead. It allows a retry without a full navigation and offers a page reload for an app-wide failure. Development builds can show the error stack, while the normal screen stays focused on recovery.

References: src/app.tsx• L11-18 src/…/route-error.tsx• L40-109 src/…/route-error.tsx• L112-197 src/…/route-error-cause.ts• L9-53 src/…/error-boundary.tsx• L21-87

Update and preload recovery

A failed lazy-module load can mean either that a new deployment removed an old file or that the network failed for a short time. Production checks the live app-shell signature before showing an update prompt, so a temporary fetch failure stays retryable rather than looking like a new release.

When an update is accepted, the shell offers to save the current project before reload. Development preload recovery follows the same save-first rule and reports a save failure without navigating away from the editor.

References: src/main.tsx• L35-119 src/main.tsx• L121-191 src/main.tsx• L242-267 src/…/vite-preload-recovery.ts• L1-20 src/…/vite-preload-recovery.test.ts• L5-34

Progressive web app installation

FreeCut can be installed as a progressive web app (PWA), which is a web app that the browser can open as a standalone application. The manifest defines the installed app identity, start URL, display mode, colors, categories, icons, and a product screenshot.

Installation prompt

The shell listens for the browser's install event and shows an install prompt only when the app is not already running in an installed display mode. A dismissal is remembered for seven days, and an accepted install or later app-installed event clears that delay.

The prompt is mounted at app level, so it can appear over public or project surfaces without becoming part of a route. It does not create an install path when the browser has not supplied an install offer.

References: index.html• L4-13 public/manifest.webmanifest• L1-41 src/…/pwa-install-prompt.tsx• L1-27 src/…/pwa-install-prompt.tsx• L28-88 src/…/pwa-install-prompt.tsx• L90-128

Offline shell and service-worker updates

In production, the service worker caches the app shell and selected same-origin assets. Navigation uses the network first and falls back to the cached document when the network is unavailable; other cacheable assets use a stale-while-revalidate pattern.

The shell watches for a waiting service worker and asks the user before activation. It also checks the entry-script signature on a timer and when the page becomes visible. Accepted updates activate the waiting worker or reload the current location with a cache-busting path.

References: public/sw.js• L1-18 public/sw.js• L20-72 public/sw.js• L74-130 src/main.tsx• L193-231 src/main.tsx• L274-295

Top-level navigation surfaces

Top-level navigation connects the public product story, project work, and supporting information without making those surfaces depend on editor state. Public headers provide paths to the home page, project library, docs, changelog, community, and source repository.

Public surfaces

The landing page is the main discovery surface. Its calls to action lead to projects, documentation, and release notes, while external actions lead to the community and source repository.

The docs shell keeps the same orientation across the docs overview and each article. It provides home and project links, searchable page navigation, and previous or next article links. An unknown article slug stays inside the docs shell and gives the reader a way back to the docs overview.

References: src/…/index.tsx• L200-272 src/…/index.tsx• L381-431 src/…/index.lazy.tsx• L1-14 src/…/docs-shell.tsx• L50-77 src/…/docs-shell.tsx• L80-147 src/…/$slug.tsx• L10-35

Project navigation

The project library is the handoff point between storage-backed project management and editing. Its header exposes the active storage workspace, import, and new-project actions; the editor toolbar provides the return path and protects it with an unsaved-change choice.

This boundary keeps route navigation aligned with data safety. A user can leave by saving or discarding, while a reload caused by an accepted app update also attempts to save the current project first.

References: src/…/index.lazy.tsx• L252-320 src/…/toolbar.tsx• L131-186 src/…/unsaved-changes-dialog.tsx• L37-54 src/main.tsx• L35-49 src/main.tsx• L91-109

Change checklist

When these files or sections are changed, remember to consider these:

  • Update the generated route tree when a route file or route path changes. The router's typed route map and lazy editor entry depend on that generated contract.
  • Keep the protected pathname rule aligned with every route that reads or writes the workspace. A new storage-backed route can otherwise run before the workspace root is ready.
  • Keep the route error classification aligned with errors thrown by loaders and storage calls. A changed error name can remove the useful retry, project-library, or folder-switch path.
  • Keep app-update save behavior aligned with the current-project URL parser. A route change can cause an accepted update to reload without saving the open project.
  • Keep the service-worker app-shell list aligned with the manifest and deployed static assets. A missing shell asset can break install or offline startup.
  • Keep documentation route lookup and the docs page module list aligned when publishing a new article. The URL can exist while the docs shell still reports the page as unknown.

Important failure modes

TriggerConsequenceGuard
A project or editor route is added without adding it to the workspace protection ruleA loader can read storage before a workspace root is activeTreat every storage-backed pathname as protected in WorkspaceGate
A saved folder handle loses permissionProject or editor routes cannot read the selected folderThe gate checks permission and shows reconnect actions; mid-session loss returns to that state
An editor URL points to a deleted projectThe router shows a generic failure unless the missing-project error stays classifiedPreserve ProjectNotFoundError and its project-library recovery path
A lazy chunk fails during a short network faultThe user may see no new-version prompt and must retry the routeKeep transient preload failures separate from verified app-shell changes
An accepted update reloads while the current project is dirtyRecent editor changes can be lostSave the current project before the update reload and stop if save fails
A production service worker serves an old shell after deploymentRoute code and shell assets can disagreeVersion the shell cache and activate waiting workers only through the update flow

Key files

FileWhy to read it
index.htmlShows the browser entry point, manifest link, and root mount element.
src/bootstrap.tsShows development cleanup before the main application starts.
src/main.tsxShows translation-gated mounting, update checks, service-worker registration, and save-before-reload behavior.
src/app.tsxShows the application shell order: error boundary, workspace gate, router, global UI, and PWA prompt.
src/routeTree.gen.tsShows the complete typed route map and the lazy editor route.
src/…/error-boundary.tsxShows app, feature, and component recovery for render errors.
src/…/workspace-gate.tsxShows which URLs need a workspace and how folder access controls route rendering.
src/…/route-error.tsxShows route-level recovery choices for missing projects and storage failures.
src/…/pwa-install-prompt.tsxShows the browser install offer and dismissal behavior.
public/sw.jsShows app-shell caching, offline navigation fallback, and asset update behavior.
src/…/docs-shell.tsxShows the shared docs navigation and article layout.
src/…/index.lazy.tsxShows the docs overview route inside the shared docs shell.
src/…/index.lazy.tsxShows the project-library entry surface and its handoff to create, import, and editor routes.