Repository navigation
fix(deploy): stable /sandbox/ URL that never 404s - #913
rubyycheung wants to merge 1 commit into
Conversation
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
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:
- Delete stable dirs before copying new builds (add a gh-pages checkout + cleanup step before peaceiris)
- 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
- ✅ Keep
SANDBOX_BASE_PATH: /sandboxand deploy to/sandbox/— this is correct - ❌ Remove the sed-rewritten
deploy/${SHORT_HASH}/sandbox/copy — fragile and unnecessary - ❌ Remove the
build-status.jsongeneration step andBuildStatus.tsx— separate PR - ✅ Landing page
sandbox/index.htmldirect link — good - ✅ Removing dynamic sandbox link resolution from JS — good
|
Follow-up from the review — I've been working on a broader fix that supersedes most of this PR. The changes are on branch What the branch does (3 files changed)1.
|
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
bddc663 to
f570120
Compare
|
Closing because of #916 |
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.
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 ofbasePath=/<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 viacp+sedrewrite for PR previews and pinned references. These are ephemeral by nature.Changes
SANDBOX_BASE_PATH→/sandbox(was/<hash>/sandbox)/sandbox/→/<hash>/sandbox/in HTML/JS/JSON/txt filessandbox/index.htmldirectly instead of resolving vialatestfileREPO_NAME/REPO_OWNERvariables