Namefeature/service detail pages#95
Conversation
The pre-rendering script failed in GitHub Actions because Puppeteer could not launch Chrome without sandbox support (Ubuntu 23.10+ / AppArmor). Fix: pass --no-sandbox and --disable-setuid-sandbox to puppeteer.launch() so Chrome starts correctly in the headless CI environment. Also restore scripts/prerender.js and re-add the build step with puppeteer as a devDependency. Update ci.yml Node from 20 to 22 (deprecation notice). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughA new ChangesPuppeteer Pre-render Pipeline
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
scripts/prerender.js (1)
92-97: ⚡ Quick winScope
--no-sandboxflags to CI-only execution.Keeping sandbox disabled for all environments weakens local security posture; apply these args only when
process.env.CIis truthy.Proposed fix
- browser = await puppeteer.launch({ - headless: true, - args: ['--no-sandbox', '--disable-setuid-sandbox'], - }); + const launchArgs = process.env.CI + ? ['--no-sandbox', '--disable-setuid-sandbox'] + : []; + browser = await puppeteer.launch({ + headless: true, + args: launchArgs, + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/prerender.js` around lines 92 - 97, The puppeteer.launch() call unconditionally disables sandbox security features for all environments, weakening local security. Modify the args array passed to puppeteer.launch() to conditionally include the '--no-sandbox' and '--disable-setuid-sandbox' flags only when process.env.CI is truthy, ensuring sandbox protection is maintained in local development while allowing these flags only in CI/CD environments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/prerender.js`:
- Line 18: The hardcoded PORT constant set to 3000 creates port collision issues
in local development environments, and the startServer function does not
properly handle or reject on listen errors. Modify the PORT constant to use a
dynamic value from environment variables (with a fallback) instead of hardcoding
it to 3000, and update the startServer function to properly catch and reject
when the server fails to listen on the assigned port. Apply these changes
throughout the file wherever PORT is referenced and wherever startServer is
called (including the locations mentioned in the comment at lines 22-24, 70-73,
90, and 111).
- Around line 35-40: The directory traversal protection check using
filePath.startsWith(distDirResolved) is vulnerable because it only performs a
prefix comparison without checking for path separators. This allows bypassing
the check with sibling paths that share the same prefix. Replace this check with
a separator-safe containment verification by ensuring that after the
distDirResolved path, there is either nothing or a path separator (use
path.sep), or alternatively use path.relative() to verify the resolved path does
not escape the directory with parent references like '..'.
---
Nitpick comments:
In `@scripts/prerender.js`:
- Around line 92-97: The puppeteer.launch() call unconditionally disables
sandbox security features for all environments, weakening local security. Modify
the args array passed to puppeteer.launch() to conditionally include the
'--no-sandbox' and '--disable-setuid-sandbox' flags only when process.env.CI is
truthy, ensuring sandbox protection is maintained in local development while
allowing these flags only in CI/CD environments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e2563ce8-248d-486b-aa7e-610aeaad09e8
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
.github/workflows/ci.ymlpackage.jsonscripts/prerender.js
Description
Summary
scripts/prerender.js(reverted in Revert "reduce the time of prerender screen for better seo and crawbility" #87) with--no-sandbox --disable-setuid-sandboxargs so Puppeteer can launch in GitHub Actions on Ubuntu 23.10+ (AppArmor blocks unprivileged user namespaces without this flag)puppeteer: ^25.1.0to devDependencies and restoresvite build && node scripts/prerender.jsbuild scriptRoot cause
Job 82516834683 failed with:
[FATAL] No usable sandbox! If you are running on Ubuntu 23.10+...Fixes the CI build failure.
Summary by CodeRabbit
New Features
Chores