Skip to content

feat(router,website): base-path support for subpath deployments - #114

Draft
stefvw93 wants to merge 5 commits into
mainfrom
feat/site-base-path
Draft

feat(router,website): base-path support for subpath deployments#114
stefvw93 wants to merge 5 commits into
mainfrom
feat/site-base-path

Conversation

@stefvw93

@stefvw93 stefvw93 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Problem

The GitHub Pages deploy works, but the site is broken at stefvw93.github.io/weft/: every asset and internal link is root-absolute (/assets/…, /docs/…), so JS/CSS fetch from stefvw93.github.io/assets/… → 404, and hard links escape the subpath.

Approach

Route patterns keep their literal strings (segment-string type inference stays intact); the base is handled at the URL boundaries instead.

@weftui/router — new base option (spec: packages/router/src/base.specs.md):

  • RouterLive({ base }): strips the base on location reads (seed, popstate), prefixes it on History writes, and the link interceptor matches/navigates on the stripped href — same-origin hrefs outside the base fall through to the browser.
  • RouterServer.render({ url, base }): strips before matching; URLs outside the base render the 404 page.
  • Canonical invariant: match.url, navigate targets, and everything stored in the router stay base-less. No behavior change when base is omitted.

Website (spec: website/prerender.specs.md, "Subpath deployment"):

  • SITE_BASE env → Vite base in both configs; src/lib/site-base.ts exposes the normalized SITE_BASE + withBase().
  • All app-rendered internal hrefs go through withBase (docs-shell nav/prev-next/home, landing page, 404 page, markdown links via render-hast).
  • Prerender renders SITE_BASE + path but writes base-less output files — the artifact root is the base.
  • Build tasks declare env: ["SITE_BASE"]: vp tasks run in a clean environment, so this is required both to pass the variable through and to fingerprint the task cache (a base change was silently reusing stale root-base bundles — including the CI-restored task cache).

CI: the Deploy Website build step sets SITE_BASE=/weft/.

Validation

  • vp run check clean; vp run test 597/597 (new: router base helpers + RouterLive/interceptor/server-render base cases, site-base tests); vp run test:browser 36/36.
  • E2e: SITE_BASE=/weft/ vp run build:static, served under a /weft/ prefix — all pages 200, entry JS + CSS 200 at /weft/assets/…, zero stray non-base hrefs, 404.html correct.
  • Regression: build without SITE_BASE is root-absolute as before (cache correctly invalidates both directions).

After merge: release → deploy runs with the base baked in; site at stefvw93.github.io/weft/ becomes fully functional. If a custom domain is added later, deleting the SITE_BASE env line reverts to root serving.

🤖 Generated with Claude Code

stefvw93 and others added 2 commits July 2, 2026 22:27
The Pages project site serves at stefvw93.github.io/weft/, but the static
build emitted root-absolute asset and link URLs, so JS/CSS 404'd and every
internal link escaped the subpath.

Router (@weftui/router): new `base` option on RouterLive and
RouterServer.render. URLs inside the router stay canonical (base-less) —
the base is stripped/prefixed only at the boundaries: location reads,
History writes, the link click interceptor, and the server render URL.
Hrefs outside the base fall through to the browser.

Website: SITE_BASE env drives Vite `base` in both configs;
src/lib/site-base.ts exposes the normalized base and withBase(), applied
to every app-rendered internal href (nav, prev/next, home, 404, markdown
links via render-hast). Prerender renders base-prefixed URLs into
base-less output files (the artifact root is the base). The build tasks
declare `env: ["SITE_BASE"]` — vp tasks run in a clean environment, so
this both passes the variable through and fingerprints the cache.

CI: the Pages deploy build sets SITE_BASE=/weft/.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
# Conflicts:
#	graphify-out/.graphify_labels.json
#	graphify-out/GRAPH_REPORT.md
#	graphify-out/graph.html
#	graphify-out/graph.json
#	graphify-out/manifest.json
#	packages/router/src/client/router-live.test.ts
#	website/src/entry-client.ts
#	website/src/layouts/docs-shell.ts
@stefvw93
stefvw93 marked this pull request as draft July 4, 2026 19:53
stefvw93 added 3 commits July 4, 2026 21:53
# Conflicts:
#	graphify-out/.graphify_labels.json
#	graphify-out/GRAPH_REPORT.md
#	graphify-out/graph.html
#	graphify-out/graph.json
#	graphify-out/manifest.json
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