chore(document): gate auto-capture debug tooling to dev + preview only#675
Conversation
🔍 Semgrep Security Scan Results✅ No security findings detected by |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
| export const isDebugEnabled = (): boolean => | ||
| typeof __SMILE_DEBUG__ !== 'undefined' && __SMILE_DEBUG__ === true; |
There was a problem hiding this comment.
Suggestion: Since __SMILE_DEBUG__ is replaced at build time by JSON.stringify(debugEnabled) (which produces the literal true or false), the typeof guard will never trigger at runtime in a properly bundled build — the code becomes typeof true !== 'undefined' && true === true. However, in test runners (Jest/Vitest without the define), __SMILE_DEBUG__ remains an undeclared identifier and typeof __SMILE_DEBUG__ correctly prevents a ReferenceError. This is fine, but wrapping it in a function means it's re-evaluated on every call. Since the value is a compile-time constant, exporting a const directly would allow bundlers to tree-shake dead branches more effectively. [general, importance: 5]
| export const isDebugEnabled = (): boolean => | |
| typeof __SMILE_DEBUG__ !== 'undefined' && __SMILE_DEBUG__ === true; | |
| export const isDebugEnabled: boolean = | |
| typeof __SMILE_DEBUG__ !== 'undefined' && __SMILE_DEBUG__ === true; |
There was a problem hiding this comment.
Pull request overview
This PR gates the document auto-capture debug tooling (TuningPanel, ROI overlay, verbose detection logs) behind a build-time __SMILE_DEBUG__ flag so it’s enabled only for dev + preview builds and intended to be omitted from production bundles.
Changes:
- Add
__SMILE_DEBUG__build-time define inpackages/web-componentsVite config (dev on by default; preview viaSMILE_DEBUG_BUILD=true; production defaults off). - Introduce a shared
isDebugEnabled()helper and route both the UI debug toggle and detection telemetry gating through it. - Ensure preview deploys and local
dev-mobile.shbuilds opt into debug tooling viaSMILE_DEBUG_BUILD=true.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| previews/scripts/dev-mobile.sh | Sets SMILE_DEBUG_BUILD=true when building web-components for local mobile preview tunneling. |
| packages/web-components/vite.config.ts | Injects __SMILE_DEBUG__ via Vite define based on mode/env. |
| packages/web-components/lib/components/document/src/document-auto-capture/utils/debug.ts | Adds isDebugEnabled() utility wrapping the build-time flag. |
| packages/web-components/lib/components/document/src/document-auto-capture/hooks/useCardDetection.ts | Switches debug telemetry gating from URL params to the build-time debug flag. |
| packages/web-components/lib/components/document/src/document-auto-capture/DocumentAutoCapture.tsx | Replaces hardcoded showDebug = true with build-time-gated debug enablement. |
| .github/workflows/deploy-preview.yml | Enables debug tooling in preview bundles by setting SMILE_DEBUG_BUILD: 'true' for the web-components build step. |
| // Debug UI (tuning panel + ROI overlay) is compiled in for dev + preview only | ||
| // (see utils/debug.ts / __SMILE_DEBUG__); production builds strip it. | ||
| const showDebug = isDebugEnabled(); |
| // Internal debug flag: emit verbose detection telemetry only in dev + preview | ||
| // builds (compiled-in via __SMILE_DEBUG__; off in production). Same switch that | ||
| // gates the tuning panel. Evaluated once at module load. | ||
| const IS_DEBUG_MODE = isDebugEnabled(); |
|
This branch has been deployed to s3 / cloudfront. ✅ Preview URL for Smart Camera Web: ✅ Preview URL for Embed: ✅ Preview URL for Web Client (Sandbox): ✅ Preview URL for Web Client (Production): |
The TuningPanel, ROI overlay and verbose detection logs were exposed in every environment (DocumentAutoCapture hardcoded `showDebug = true`), so end users would see them in production. Gate them so `?debug` only works in dev + preview: - `utils/debug.ts#isDebugEnabled()` requires BOTH a build-time gate and the `?debug` URL param. The build gate `__SMILE_DEBUG__` is injected by the web-components Vite `define`: true for non-production vite modes (vite dev + Storybook) or when `SMILE_DEBUG_BUILD=true`; production / npm-publish builds compile it to false (fail-safe), so `?debug` is inert in production. - `isDebugEnabled()` is the single source of truth — replaces the hardcoded `showDebug` and the standalone `?debug` check in `IS_DEBUG_MODE`. - deploy-preview.yml sets `SMILE_DEBUG_BUILD=true` on the web-components build; dev-mobile.sh sets it for the locally-built embed. Prod deploy/publish unchanged. - The embed's `?debug` forwarding into the iframe (embed/src/js/script.js) is retained — it's what carries the opt-in into the capture component. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
f8d9dd7 to
d751a99
Compare
…uilds The build gate already disabled the panel in production, but the TuningPanel code still shipped in the bundle (gated off at runtime). Guard the TuningPanel render sites with the bare `__SMILE_DEBUG__` build-time literal (declared in lib/types.d.ts) instead of only the runtime `showDebug` call, so the bundler constant-folds the dead branch and drops the TuningPanel import entirely in production. `showDebug` still applies the runtime `?debug` opt-in in dev/preview. Verified: clean production build contains 0 bundles with the panel code; the SMILE_DEBUG_BUILD=true (preview) build keeps it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
User description
What
The document auto-capture debug tooling (live
TuningPanel, ROI overlay, verbose detection logs) was exposed in every environment —DocumentAutoCapturehardcodedshowDebug = true, so end users would see it in production. This gates it behind a build-time flag so it appears only in dev + preview and is compiled out of production.How
__SMILE_DEBUG__build-time flag injected by the web-components Vitedefine:truefor non-production vite modes (vite dev+ Storybook) or whenSMILE_DEBUG_BUILD=true; production / npm-publish builds (vite build, no flag) compile it out (fail-safe default).utils/debug.ts#isDebugEnabled()is the single source of truth — replaces the hardcodedshowDebugand the?debugURL check inIS_DEBUG_MODE. (A URL param can't drive this: the component runs inside the embed iframe, so a parent-page?debugnever reaches it.)deploy-preview.ymlsetsSMILE_DEBUG_BUILD=trueon the web-components build;dev-mobile.shsets it for the locally-built embed. Prod deploy / publish unchanged.Verification
SMILE_DEBUG_BUILD=true) produce different bundles;__SMILE_DEBUG__is fully replaced in the emitted.js(present only in sourcemaps).tsc --noEmit+eslintclean on changed files.Base
Targets
feat/mobile-capture-adaptive-cannyso the diff is only this change (it's branched off that work). When #673 merges, this will retarget todocument-capture-new-flow.🤖 Generated with Claude Code
PR Type
Enhancement
Description
Gate debug tooling behind build-time
__SMILE_DEBUG__flagStrip TuningPanel/ROI overlay from production builds
Enable debug in dev, Storybook, and preview deploys only
Replace hardcoded
showDebug = trueand URL-param checkDiagram Walkthrough
File Walkthrough
debug.ts
Add build-time debug flag utilitypackages/web-components/lib/components/document/src/document-auto-capture/utils/debug.ts
isDebugEnabled()function__SMILE_DEBUG__constant withtypeofguarduseCardDetection.ts
Replace URL-param debug check with build flagpackages/web-components/lib/components/document/src/document-auto-capture/hooks/useCardDetection.ts
IS_DEBUG_MODEwithisDebugEnabled()callwindow.location.searchparsing logicisDebugEnabledfrom the new debug utilityDocumentAutoCapture.tsx
Use build-time debug flag for showDebugpackages/web-components/lib/components/document/src/document-auto-capture/DocumentAutoCapture.tsx
showDebug = truewithisDebugEnabled()callisDebugEnabledutility fromutils/debugvite.config.ts
Inject __SMILE_DEBUG__ build-time definepackages/web-components/vite.config.ts
debugEnabledvariable: true for non-production mode or whenSMILE_DEBUG_BUILD=true__SMILE_DEBUG__intodefineconfig with the computed booleandeploy-preview.yml
Enable debug build for preview deploys.github/workflows/deploy-preview.yml
SMILE_DEBUG_BUILD: 'true'env variable to the web-componentsbuild step
dev-mobile.sh
Enable debug build in local dev-mobile scriptpreviews/scripts/dev-mobile.sh
SMILE_DEBUG_BUILD=true