Skip to content

fix(deploy): stable /sandbox/ URL that never 404s - #913

Closed
rubyycheung wants to merge 1 commit into
mainfrom
navi/fix/stable-sandbox-url
Closed

rubyycheung wants to merge 1 commit into
mainfrom
navi/fix/stable-sandbox-url

Conversation

@rubyycheung

Copy link
Copy Markdown
Contributor

Problem

Sandbox URLs like /<hash>/sandbox/ break when the cleanup job removes old hash directories. Shared links go permanently dead.

Solution

Build sandbox with basePath=/sandbox (fixed) instead of basePath=/<hash>/sandbox (dynamic).

Stable URL: .../sandbox/ — always serves the latest, never gets cleaned up, no 404 during rebuilds (GitHub Pages serves the old version until the new one lands).

Hash-versioned URL: .../\<hash\>/sandbox/ — still created via cp + sed rewrite for PR previews and pinned references. These are ephemeral by nature.

Changes

  • SANDBOX_BASE_PATH → /sandbox (was /<hash>/sandbox)
  • Hash copy created by copying the stable build and rewriting /sandbox/ → /<hash>/sandbox/ in HTML/JS/JSON/txt files
  • Landing page sandbox link points to sandbox/index.html directly instead of resolving via latest file
  • Removed unused REPO_NAME/REPO_OWNER variables

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 27, 2026
@github-actions

github-actions Bot commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 11.2KB 17.7KB 2.7KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: request changes

The core idea is right — build with basePath=/sandbox, deploy to /sandbox/

The current state on main (from #758) is silently broken: /sandbox/ is a copy of a build with basePath=/<hash>/sandbox, so every asset path in the HTML points to /<hash>/sandbox/_next/.... It works by accident because the hash dir exists, but it's parasitically coupled to it.

Building with basePath=/sandbox and deploying to /sandbox/ fixes this properly. No downtime risk — Next.js uses content-hashed filenames, so old chunks stay around (keep_files: true), old index.html references old chunk names (still present), new index.html references new chunk names (added in the same commit). GitHub Pages serves old content until rebuild completes, then atomically switches.

Drop the hash-versioned sandbox copy + sed rewrite

The sed -i "s|/sandbox/|/${SHORT_HASH}/sandbox/|g" rewrite is unsafe for Next.js static export. Next.js bakes basePath into:

  • RSC payload JSON (e.g. "p":"/sandbox" in inline <script> tags)
  • Webpack chunk-loading runtime logic
  • Client-side router prefetch URLs
  • _next/data/ JSON files

A global sed on *.html *.js *.json *.txt will catch some of these but will break others — especially the RSC data embedded in HTML. And if any JS has /sandbox/ as a substring in a different context, sed corrupts that too.

The hash-versioned sandbox doesn't serve a real purpose anyway — PR previews have their own workflow, and "pinned references" to a sandbox that gets cleaned up aren't actually pinned. Recommendation: drop deploy/${SHORT_HASH}/sandbox/ entirely. That saves ~69 files per hash dir and removes the fragile sed step.

Cleanup workflow needs attention (separate PR)

The cleanup workflow (cleanup-previews.yml) only targets 7-char hex directories. The stable /storybook/ and /sandbox/ dirs are invisible to it. With keep_files: true, old content-hashed chunks accumulate indefinitely:

  • storybook/assets/: 2,656 files (vs ~192 per single build — 14x bloat)
  • sandbox/_next/: 49 files today, will grow the same way

This is the real deploy speed / gh-pages bloat issue. The deploy workflow should either:

  1. Delete stable dirs before copying new builds (add a gh-pages checkout + cleanup step before peaceiris)
  2. Or add /storybook/ and /sandbox/ cleanup to the cleanup workflow

Either way, that's a follow-up — not this PR's scope.

Split out BuildStatus component

The BuildStatus.tsx component (375 lines) is nice but orthogonal to the deploy fix. The fetch('./build-status.json') also uses a relative URL that resolves differently depending on the path context. Should be a separate PR.

Summary of requested changes

  1. ✅ Keep SANDBOX_BASE_PATH: /sandbox and deploy to /sandbox/ — this is correct
  2. ❌ Remove the sed-rewritten deploy/${SHORT_HASH}/sandbox/ copy — fragile and unnecessary
  3. ❌ Remove the build-status.json generation step and BuildStatus.tsx — separate PR
  4. ✅ Landing page sandbox/index.html direct link — good
  5. ✅ Removing dynamic sandbox link resolution from JS — good

@cixzhang

Copy link
Copy Markdown
Contributor

Follow-up from the review — I've been working on a broader fix that supersedes most of this PR. The changes are on branch navi/fix/deploy-cleanup (couldn't push from sandbox due to workflow scope on the token — you'll need to push it or I can push from a CLI node).

What the branch does (3 files changed)

1. deploy.yml — switch to keep_files: false

The root cause of the gh-pages bloat: keep_files: true means peaceiris/actions-gh-pages never deletes anything. It clones gh-pages, skips git rm, copies your deploy/ dir on top, and pushes. Old content-hashed chunks accumulate forever.

Current state: storybook/ has 2,656 files (vs ~192 per build — 14x bloat from accumulated stale chunks).

Fix: keep_files: false gives us a clean slate each deploy. To preserve PR previews and reports, the workflow clones gh-pages first and copies /pr/ and /reports/ into the fresh deploy/ dir before publishing.

Also: sandbox builds with basePath=/sandbox (stable, self-contained). Landing page links directly to storybook/index.html and sandbox/index.html — no more JS fetch("latest") resolution, no dependency on hash dirs.

2. ci.yml — PR previews at /pr/<number>/

Instead of /<commit-hash>/, PR previews deploy to /pr/<number>/. This is:

  • Easier to identify — you know which PR a dir belongs to without API calls
  • Easier to clean up — match PR number against open PRs list
  • Stable per-PR — same URL across force-pushes (just gets overwritten)
  • No namespace collision with main deploys

3. cleanup-previews.yml — simplified

  • Delete /pr/<number>/ dirs for closed/merged PRs
  • Delete all legacy 7-char hex directories (one-time migration)
  • Stop deleting /sandbox/ — the current cleanup was nuking it daily! (it was in the stale root-level items list from the old format, confirmed in the most recent cleanup run log: DELETE root/sandbox (stale root-level file))

What this means for #913

This branch covers:

  • ✅ basePath=/sandbox stable URL
  • ✅ Landing page direct links
  • ✅ No hash-versioned sandbox copy (and no sed rewrite)
  • ✅ Cleanup workflow fix

What's left from #913 that isn't covered:

  • The BuildStatus.tsx component (recommend splitting to its own PR)

Suggest closing this PR and opening a fresh one from navi/fix/deploy-cleanup (after pushing it). Or rebasing this branch onto those changes and keeping just the BuildStatus addition.

Build sandbox with basePath=/sandbox instead of /<hash>/sandbox so the
stable /sandbox/ path always serves the latest version. GitHub Pages
keeps serving the old build until the new one lands, so there's no 404
window during deploys. The cleanup job only targets 7-char hex dirs,
so /sandbox/ is never removed.

- SANDBOX_BASE_PATH: /sandbox (was /<hash>/sandbox)
- Landing page sandbox link points to sandbox/index.html directly
- Removed hash-based sandbox copy from deploy (hash dirs are storybook-only)
- Removed unused REPO_NAME/REPO_OWNER variables
@rubyycheung

Copy link
Copy Markdown
Contributor Author

Closing because of #916

rubyycheung added a commit that referenced this pull request Mar 27, 2026
Bell icon in the top nav with a popover showing:
- Current deployed build hash
- In-progress GitHub Actions workflows (with spinner + workflow link)
- Last 10 merged PRs with title, hash, PR number, and time ago

When a build is running, a small accent-colored dot appears on the bell.

Uses the public GitHub API (unauthenticated, 60 req/hr) — fetches on
mount and via manual refresh button.

Split from #913 per review feedback.
@cixzhang
cixzhang deleted the navi/fix/stable-sandbox-url branch April 9, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants