🐛 URGENT: Fix production crash from bare console.* stripping#4248
🐛 URGENT: Fix production crash from bare console.* stripping#4248clubanderson merged 1 commit intomainfrom
Conversation
PR #4239 added bare `console.log`/`console.debug` to Vite's define config to strip debug calls. But Vite's define does LITERAL text replacement — it replaced `console.log(...)` with `undefined(...)` in vendor/dependency code (Tailwind Merge, etc.), causing `TypeError: (void 0) is not a function` and crashing the entire app on console.kubestellar.io. Fix: Only use `globalThis.console.*` form which is specific enough to match our code but not vendor dependencies. Signed-off-by: Andrew Anderson <andy@clubanderson.com>
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
/lgtm |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
@clubanderson: you cannot LGTM your own PR. DetailsIn response to this:
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. |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
There was a problem hiding this comment.
Pull request overview
Fixes a production outage caused by Vite define doing literal replacements of bare console.*, which impacted vendor bundles and produced runtime TypeError crashes.
Changes:
- Removes bare
console.log/info/debug/tracereplacements fromvite.config.tsto avoid altering vendor/dependency code. - Updates the inline documentation to warn against using bare
console.*withdefinebecause of unintended vendor replacements.
| 'globalThis.console.log': 'undefined', | ||
| 'globalThis.console.info': 'undefined', | ||
| 'globalThis.console.debug': 'undefined', | ||
| 'globalThis.console.trace': 'undefined', |
There was a problem hiding this comment.
Defining globalThis.console.* to undefined will turn any matching call site into undefined(...), which throws a TypeError at runtime (the same failure mode described in the PR). Use a callable no-op (or another strategy that removes calls without leaving an uncallable identifier) so any surviving globalThis.console.*(...) becomes a safe no-op instead of a crash.
| 'globalThis.console.log': 'undefined', | |
| 'globalThis.console.info': 'undefined', | |
| 'globalThis.console.debug': 'undefined', | |
| 'globalThis.console.trace': 'undefined', | |
| 'globalThis.console.log': '((..._args) => {})', | |
| 'globalThis.console.info': '((..._args) => {})', | |
| 'globalThis.console.debug': '((..._args) => {})', | |
| 'globalThis.console.trace': '((..._args) => {})', |
| // Strip console calls in production (replaces terser drop_console). | ||
| // IMPORTANT: Only use globalThis.console.* — bare "console.log" does | ||
| // literal text replacement that hits vendor/dependency code too, | ||
| // turning their console.log(...) into undefined(...) which crashes. | ||
| ...(mode === 'production' ? { | ||
| 'globalThis.console.log': 'undefined', | ||
| 'globalThis.console.info': 'undefined', | ||
| 'globalThis.console.debug': 'undefined', | ||
| 'globalThis.console.trace': 'undefined', | ||
| 'console.log': 'undefined', | ||
| 'console.info': 'undefined', | ||
| 'console.debug': 'undefined', | ||
| 'console.trace': 'undefined', | ||
| } : {}), |
There was a problem hiding this comment.
With the bare console.* defines removed, this config no longer strips typical console.log/info/debug/trace usage in the app (only the rare globalThis.console.* form, which appears unused). Either adjust the comment/intent to reflect that console calls are no longer stripped, or update the stripping approach so it actually targets the app code without touching vendor dependencies.
🔄 Auto-Applying Copilot Code ReviewCopilot code review found 1 code suggestion(s) and 1 general comment(s). @copilot Please apply all of the following code review suggestions:
Also address these general comments:
Push all fixes in a single commit. Run Auto-generated by copilot-review-apply workflow. |
Adds a postbuild script that scans vendor bundles for `void 0(` — the minified form of `undefined()` — which indicates Vite's define config replaced `console.*` calls in dependency code. This would have caught the production crash from PR #4239 / #4248 before deployment. Also removes unused DEV_BAR_HEIGHT_PX import blocking tsc. Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Adds a postbuild script that scans vendor bundles for `void 0(` — the minified form of `undefined()` — which indicates Vite's define config replaced `console.*` calls in dependency code. This would have caught the production crash from PR #4239 / #4248 before deployment. Also removes unused DEV_BAR_HEIGHT_PX import blocking tsc. Signed-off-by: Andrew Anderson <andy@clubanderson.com>
#4252) Adds a postbuild script that scans vendor bundles for `void 0(` — the minified form of `undefined()` — which indicates Vite's define config replaced `console.*` calls in dependency code. This would have caught the production crash from PR #4239 / #4248 before deployment. Also removes unused DEV_BAR_HEIGHT_PX import blocking tsc. Signed-off-by: Andrew Anderson <andy@clubanderson.com>
PRODUCTION IS DOWN
PR #4239 added bare
console.log/console.debugto Vite'sdefineconfig. Vite's define does literal text replacement — it replacedconsole.log(...)withundefined(...)inside vendor dependencies (Tailwind Merge, etc.), causing:This crashes the entire app on
console.kubestellar.io— blank page, React never mounts.Fix
Remove bare
console.*forms from Vite define. Only useglobalThis.console.*which is specific enough to target our code without hitting vendor code.Verified
grep -c "void 0(" dist/assets/vendor-*.jsreturns 0 after fix (was crashing before)