Skip to content

🐛 Fix Copilot findings: console noop, GA4 tracker, safety check scope#4308

Merged
clubanderson merged 1 commit intomainfrom
fix/copilot-review-fixes
Apr 2, 2026
Merged

🐛 Fix Copilot findings: console noop, GA4 tracker, safety check scope#4308
clubanderson merged 1 commit intomainfrom
fix/copilot-review-fixes

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

@clubanderson clubanderson commented Apr 2, 2026

  • Fix comment in web/src/main.tsx – remove literal "mockServiceWorker.js" from comment to prevent safety check false positive
  • Add trackDuration prop to PageViewTracker in web/src/App.tsx – pass false in LightweightShell so landing pages only emit GA4 page_view, not ksc_dashboard_viewed duration events
  • Narrow MSW detection regex in web/scripts/check-vendor-safety.mjs – match JS string literal "/mockServiceWorker.js" instead of bare substring to avoid false positives from comments
  • npm run build passes – all 5 post-build safety checks pass
  • npm run lint – only pre-existing errors, no new issues introduced

- Replace 'undefined' with no-op arrow functions in vite.config.ts
  console stripping to prevent `undefined()` crashes in vendor code
- Add PageViewTracker to LightweightShell so public landing pages
  (FromLens, FromHeadlamp, etc.) emit GA4 page_view events
- Expand post-build safety check to scan ALL .js files for void 0(
  corruption, not just vendor-prefixed chunks
- Move mockServiceWorker.js URL into dynamically-imported MSW chunk
  so the literal string stays out of the index bundle

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Copilot AI review requested due to automatic review settings April 2, 2026 19:13
@kubestellar-prow kubestellar-prow bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Apr 2, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 2, 2026

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit 1bb2a29
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69cebfd94e69870008138bf9
😎 Deploy Preview https://deploy-preview-4308.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses build/runtime safety and analytics coverage in the web console by preventing production console-stripping crashes, ensuring GA4 pageview tracking on public landing pages, and tightening post-build bundle safety checks (including MSW leakage detection).

Changes:

  • Updated Vite production define console stubs to use no-op functions instead of undefined to avoid undefined() runtime crashes.
  • Added PageViewTracker to LightweightShell so GA4 page_view events fire for public/landing routes.
  • Refined the post-build safety script: clearer naming/messages, broader JS scanning, and MSW leak detection based on mockServiceWorker.js string presence in the index chunk; moved MSW SW URL into the dynamically imported MSW module.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
web/vite.config.ts Switches production console stripping from undefined to a no-op function to prevent runtime crashes from replaced calls.
web/src/mocks/browser.ts Introduces startMocking() and moves the service worker URL string into the MSW dynamic chunk.
web/src/main.tsx Switches demo-mode MSW startup to call startMocking() from the dynamic import.
web/src/App.tsx Ensures PageViewTracker runs for landing pages by placing it in LightweightShell.
web/scripts/check-vendor-safety.mjs Clarifies define-corruption scanning scope and changes MSW leak detection heuristic to search for mockServiceWorker.js.

Comment on lines +411 to 420
/** Lightweight shell for standalone pages that don't need the full dashboard provider stack.
* Includes PageViewTracker so GA4 page_view events fire for landing pages too. */
function LightweightShell({ children }: { children: React.ReactNode }) {
return (
<BrandingProvider>
<ThemeProvider>
<AppErrorBoundary>
<ChunkErrorBoundary>
<PageViewTracker />
<Suspense fallback={<LoadingFallback />}>
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

PageViewTracker also emits the custom duration event (emitDashboardViewed) based on the current pathname. Putting it on public landing pages means those routes (e.g. /from-lens, /welcome) will be reported as ksc_dashboard_viewed dashboards via pathToDashboardId, which seems inconsistent with the event’s intent ("dashboard" duration). Consider either disabling duration tracking in LightweightShell (page_view only) or updating pathToDashboardId/flushDuration to only map real dashboard routes.

Copilot uses AI. Check for mistakes.
},
})
// Import and start MSW via the dynamically-imported chunk so the
// mockServiceWorker.js URL string never appears in the index bundle.
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The new safety-check heuristic looks for the literal substring "mockServiceWorker.js" in the built index chunk. This file currently includes that exact substring in a source comment, which could still end up in the index bundle depending on minifier/comment preservation and trigger a false failure. Recommend rewording the comment to avoid the literal string (or otherwise ensure it cannot be emitted into the bundle).

Suggested change
// mockServiceWorker.js URL string never appears in the index bundle.
// mock worker script URL string never appears in the index bundle.

Copilot uses AI. Check for mistakes.
Comment on lines +99 to 107
// Detect MSW being statically bundled. If `mockServiceWorker.js` appears as
// a static string in the index chunk (not behind a dynamic import), MSW's
// service worker registration could fire unconditionally, intercepting real
// API calls. A proper dynamic import keeps the reference in a separate chunk.
const hasMswStaticRef = indexContent.includes('mockServiceWorker.js')
if (hasMswStaticRef) {
fail(
`MSW identifiers (${leaked.join(', ')}) found statically in ${indexChunk}. ` +
`'mockServiceWorker.js' found as a static string in ${indexChunk}. ` +
`MSW must be behind a dynamic import() so it only loads in demo mode.`,
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

Check 3 now fails if the index chunk contains the substring "mockServiceWorker.js" anywhere, which can produce false positives (e.g., the string appearing in comments, error messages, or unrelated text). Since this check runs post-build and can block CI, consider narrowing the match to a more specific pattern (like the serviceWorker url assignment / quoted string with leading '/') or stripping comments before scanning.

Copilot uses AI. Check for mistakes.
@clubanderson
Copy link
Copy Markdown
Collaborator Author

🔄 Auto-Applying Copilot Code Review

Copilot code review found 1 code suggestion(s) and 2 general comment(s).

@copilot Please apply all of the following code review suggestions:

  • web/src/main.tsx (line 66): // mock worker script URL string never appears in the index bundle.

Also address these general comments:

  • web/src/App.tsx (line 420): PageViewTracker also emits the custom duration event (emitDashboardViewed) based on the current pathname. Putting it on
  • web/scripts/check-vendor-safety.mjs (line 107): Check 3 now fails if the index chunk contains the substring "mockServiceWorker.js" anywhere, which can produce false pos

Push all fixes in a single commit. Run cd web && npm run build && npm run lint before committing.


Auto-generated by copilot-review-apply workflow.

@clubanderson
Copy link
Copy Markdown
Collaborator Author

/lgtm
/approve

@kubestellar-prow
Copy link
Copy Markdown
Contributor

@clubanderson: you cannot LGTM your own PR.

Details

In response to this:

/lgtm
/approve

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clubanderson

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 2, 2026
@clubanderson clubanderson merged commit 1e1f0eb into main Apr 2, 2026
27 of 29 checks passed
@kubestellar-prow kubestellar-prow bot deleted the fix/copilot-review-fixes branch April 2, 2026 19:21
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

🔄 Auto-Applying Copilot Code Review

Copilot code review found 1 code suggestion(s) and 2 general comment(s)....

All three review suggestions have been implemented and verified (build passes, all 5 safety checks pass):

1. web/src/main.tsx line 66 — Removed literal mockServiceWorker.js from comment:

-    // mockServiceWorker.js URL string never appears in the index bundle.
+    // mock worker script URL string never appears in the index bundle.

2. web/src/App.tsx — Added trackDuration prop to PageViewTracker (default true), passes false in LightweightShell so landing pages only emit GA4 page_view events without the ksc_dashboard_viewed duration event:

-function PageViewTracker() {
+function PageViewTracker({ trackDuration = true }: { trackDuration?: boolean } = {}) {
   ...
   const flushDuration = () => {
+    if (!trackDuration) return
     ...
   }
 
-<PageViewTracker />   // in LightweightShell
+<PageViewTracker trackDuration={false} />

3. web/scripts/check-vendor-safety.mjs line 103 — Narrowed MSW detection to match only JS string literals (avoids false positives from comments):

-const hasMswStaticRef = indexContent.includes('mockServiceWorker.js')
+const hasMswStaticRef = /["']\/mockServiceWorker\.js["']/.test(indexContent)

Note: The original PR branch fix/copilot-review-fixes was already merged when this review was posted, and the repo's branch creation rules are preventing the push. The changes (commit 24acfa3a) are ready — a new PR or manual merge from this branch will be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants