ENG-1551 - Fixing "Serverless function has exceeded ..."#927
Conversation
- Introduced a new blogDirectory.ts file to centralize the blog directory path management. - Updated readBlogs.tsx and page.tsx to import and use BLOG_DIRECTORY instead of the previously hardcoded BLOG_PATH. - Removed the BLOG_PATH constant from constants.ts to streamline the codebase.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThis PR refactors blog directory path resolution by introducing a new module that computes the blog directory path using Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/website/app/(home)/blog/blogDirectory.ts (1)
1-9: Consider usingnew URL()pattern for more robust file path resolution.The current implementation using
fileURLToPath(import.meta.url)works correctly in Next.js 15 and Turbopack. However, the more robust pattern for file path resolution isnew URL('./relative-path', import.meta.url).pathname, which explicitly constructs a file URL and is more resilient to bundler transformations.If you prefer stronger type safety and consistency with modern ESM patterns, consider refactoring to:
Suggested refactor
import path from "node:path"; const BLOG_MODULE_PATH = new URL(".", import.meta.url).pathname; export const BLOG_DIRECTORY = path.join(BLOG_MODULE_PATH, "posts");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/website/app/`(home)/blog/blogDirectory.ts around lines 1 - 9, Replace the fileURLToPath(import.meta.url) approach with the new URL(...) pattern for more robust ESM path resolution: update the BLOG_MODULE_PATH initialization to use new URL(".", import.meta.url).pathname, remove the unused fileURLToPath import, and keep BLOG_DIRECTORY built via path.join(BLOG_MODULE_PATH, "posts") so that BLOG_MODULE_PATH and BLOG_DIRECTORY use the new URL-based pathname resolution.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/website/app/`(home)/blog/blogDirectory.ts:
- Around line 1-9: Replace the fileURLToPath(import.meta.url) approach with the
new URL(...) pattern for more robust ESM path resolution: update the
BLOG_MODULE_PATH initialization to use new URL(".", import.meta.url).pathname,
remove the unused fileURLToPath import, and keep BLOG_DIRECTORY built via
path.join(BLOG_MODULE_PATH, "posts") so that BLOG_MODULE_PATH and BLOG_DIRECTORY
use the new URL-based pathname resolution.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f8071cc0-f673-4e38-9787-62d9f84c136c
📒 Files selected for processing (4)
apps/website/app/(home)/blog/[slug]/page.tsxapps/website/app/(home)/blog/blogDirectory.tsapps/website/app/(home)/blog/readBlogs.tsxapps/website/app/data/constants.ts
💤 Files with no reviewable changes (1)
- apps/website/app/data/constants.ts
" Root cause was the blog filesystem lookup used by / and /blog. It was resolving the blog directory from process.cwd(), which made Next/Vercel’s file tracer over-approximate the dependency set and pull in most of apps/website/.next including webpack cache packs, plus all of apps/website/public. That matches your Vercel log: .next ~228.5 MB + public ~49 MB, and it also explains why a redeploy sometimes passes, since the .next/cache contents vary between builds."
"...the home/blog traces dropped from roughly 573 MB each to about 1.8 MB, which is exactly the Vercel issue we were trying to eliminate."
Summary by CodeRabbit