fix: exclude /debug/* route group from production build#263
Open
dobby-coder[bot] wants to merge 2 commits into
Open
fix: exclude /debug/* route group from production build#263dobby-coder[bot] wants to merge 2 commits into
dobby-coder[bot] wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
/debug/*route group holds developer-only fixtures (QR sandbox, upload/download flow mocks, etc.). They were guarded only by a runtimedevredirect insrc/routes/(app)/debug/+layout.svelte, so the page components were still compiled into the production bundle:console.log('QR test page loaded. PostGuard instance:', pg)ran on production clients that navigated to/debug/qrbefore the async redirect resolved.How
Added an
excludeDebugRoutesInProductionVite plugin invite.config.ts. Duringvite build(and only then), it replaces the source of every(app)/debug/**/+page.sveltewith 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.vite devnothing is touched, so the debug pages remain fully usable while developing.+layout.svelteredirect 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:build/output and asserts none of a curated set of debug-only markers (headings, console.log text, mock data, hardcoded PKG URL) appear./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