Skip to content

[alpha.5] #4 — Route Lazy Loading #116

Description

@SisyphusZheng

Parent

#114 — v0.41.0-alpha.5: SPA Mode + Deno Desktop Proof

What to build

At build time, the Vite plugin (@openelement/adapter-vite) scans the routes/ directory and generates a client router manifest that maps route paths to lazy-loaded component imports. This enables route-level code splitting in SPA mode — only the current route's code is loaded on first page, and navigation triggers lazy-loading of the target route.

Build-time manifest generation:

  • Plugin scans routes/**/*.tsx during vite build
  • Generates a manifest like { '/': () => import('./routes/index.tsx'), '/products': () => import('./routes/products.tsx') }
  • Injects the manifest into the client bundle

Runtime behavior:

  • Router uses the manifest to resolve route → component mapping
  • First navigation to a route triggers import() (code split point)
  • Subsequent navigations to the same route reuse the cached module
  • Loading state between navigation (lazy-loading a route for the first time shows a loading indicator or renders nothing until resolved)

Manual escape hatch:

  • defineRoute({ path: '/admin', lazy: () => import('./routes/admin.tsx') }) supported but unnecessary for file-system routes

Acceptance criteria

  • deno task build generates a route manifest from routes/*.tsx files
  • Router reads the manifest and lazy-loads routes on first access
  • First page load only includes the current route's code in the bundle
  • Navigation to a new route triggers import() for the target route
  • Repeated navigation to the same route reuses the cached module (no re-import)
  • defineRoute({ lazy: () => import(...) }) manual override works
  • Tests cover: manifest generation, lazy load on navigate, cache reuse, manual override

Blocked by

None — can start immediately (parallel with #115)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions