Skip to content

fix: exclude /debug/* route group from production build#263

Open
dobby-coder[bot] wants to merge 2 commits into
mainfrom
fix/exclude-debug-routes-from-prod-build
Open

fix: exclude /debug/* route group from production build#263
dobby-coder[bot] wants to merge 2 commits into
mainfrom
fix/exclude-debug-routes-from-prod-build

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What

The /debug/* route group holds developer-only fixtures (QR sandbox, upload/download flow mocks, etc.). They were guarded only by a runtime dev redirect in src/routes/(app)/debug/+layout.svelte, so the page components were still compiled into the production bundle:

  • Hundreds of lines of dev-only UI shipped to production users.
  • console.log('QR test page loaded. PostGuard instance:', pg) ran on production clients that navigated to /debug/qr before the async redirect resolved.

How

Added an excludeDebugRoutesInProduction Vite plugin in vite.config.ts. During vite build (and only then), it replaces the source of every (app)/debug/**/+page.svelte with an empty component before the Svelte compiler sees it (enforce: 'pre'), so none of the debug page code — mock data, console.logs, heavy imports — ends up in the output.

  • In vite dev nothing is touched, so the debug pages remain fully usable while developing.
  • The +layout.svelte redirect is kept as a second line of defence for anyone hitting /debug/* in production; its comment now points at the build-time exclusion.

The route path entries still exist in SvelteKit's client router manifest (unavoidable without deleting the directories), but they now resolve to ~160-byte empty stubs instead of the original components.

Test

tests/debug-routes-excluded.test.ts:

  • Scans the entire build/ output and asserts none of a curated set of debug-only markers (headings, console.log text, mock data, hardcoded PKG URL) appear.
  • Navigates to /debug/qr/ in the production preview and asserts no debug UI renders.

Verification

  • npm run build
  • npx playwright test → 6 passed (2 new + 4 existing) ✓
  • npx svelte-check --threshold warning → 0 errors, 0 warnings ✓
  • npm run lint (prettier + eslint) ✓

Closes #218

🤖 Generated with Claude Code

dobby-coder Bot and others added 2 commits June 19, 2026 17:11
The /debug/* routes are developer-only fixtures. They were guarded by a
runtime `dev` redirect in (app)/debug/+layout.svelte only, so the page
components — heavy mock data, sandbox UI, and a console.log that ran before
the redirect resolved — were still compiled into the production bundle.

Add an `excludeDebugRoutesInProduction` Vite plugin that replaces every
debug `+page.svelte` with an empty component during `vite build`, before the
Svelte compiler sees it, so none of that code ships. The pages remain fully
usable under `vite dev`. The layout redirect is kept as a second line of
defence.

Add a test asserting debug-only markers are absent from build/ and that no
debug UI renders in the production build.

Closes #218

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
walk(build/) read every asset (images, fonts, .wasm) as utf8; the debug
markers only ever land in text output, so scanning binaries was wasteful
and never matched. Restrict the walk to .html/.js/.css/.json.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dobby-coder dobby-coder Bot marked this pull request as ready for review June 19, 2026 17:23
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.

/debug/* routes ship to production bundles (runtime redirect only)

0 participants