fix: resolve PDF imports via Webpack 5 Asset Modules and refactor tem…#628
fix: resolve PDF imports via Webpack 5 Asset Modules and refactor tem…#628devbyhimans wants to merge 1 commit into
Conversation
…plates routes to supabase/server
👷 Deploy request for docmagic1 pending review.Visit the deploys page to approve it
|
👷 Deploy request for docmagic-muneer pending review.Visit the deploys page to approve it
|
|
@devbyhimans is attempting to deploy a commit to the muneerali199's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe PR refactors Supabase client initialization across three API route files by replacing the deprecated ChangesSupabase Server Client Migration
PDF Asset Handling and Build Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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)
next.config.js (1)
77-80: ⚡ Quick winConsider adding
[contenthash]for cache busting.The current pattern
static/files/[name][ext]generates stable URLs but may cause stale cache issues if PDF content changes while the filename remains the same. Including a content hash ensures browsers and CDNs fetch updated files.♻️ Suggested enhancement
type: 'asset/resource', generator: { - filename: 'static/files/[name][ext]', + filename: 'static/files/[name].[contenthash][ext]', },🤖 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 `@next.config.js` around lines 77 - 80, Update the webpack asset generator filename to include a content hash so updated PDFs invalidate caches: change the generator.filename pattern used in the asset/resource rule (the configuration object with keys type: 'asset/resource' and generator) from 'static/files/[name][ext]' to a hash-based pattern (e.g., include [contenthash] or [contenthash:8] like 'static/files/[name].[contenthash][ext]') so filenames change when file content changes.
🤖 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.
Nitpick comments:
In `@next.config.js`:
- Around line 77-80: Update the webpack asset generator filename to include a
content hash so updated PDFs invalidate caches: change the generator.filename
pattern used in the asset/resource rule (the configuration object with keys
type: 'asset/resource' and generator) from 'static/files/[name][ext]' to a
hash-based pattern (e.g., include [contenthash] or [contenthash:8] like
'static/files/[name].[contenthash][ext]') so filenames change when file content
changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 57d96861-785d-46ab-8970-d08721d97c78
📒 Files selected for processing (5)
app/api/templates/[id]/route.tsapp/api/templates/[id]/shares/[shareId]/route.tsapp/api/templates/[id]/shares/route.tsnext.config.jstypes/global.d.ts
|
@Muneerali199 |
fix #597 : resolve PDF imports via Webpack 5 Asset Modules and refactor templates routes to supabase/server
Description
This PR fixes a build crash that occurs when
.pdffiles are imported as modules in the project. Previously,next.config.jswas configured to usefile-loaderfor.pdffiles, but thefile-loaderpackage was not installed inpackage.json, causing builds to fail.We resolved this cleanly by configuring Webpack 5's native Asset Modules (
type: 'asset/resource'), which eliminates the need for the deprecatedfile-loaderpackage entirely.Additionally, this PR refactors three template-related API routes that were broken in production builds because they referenced the legacy and missing
@supabase/auth-helpers-nextjslibrary. They have been updated to use the standard@/lib/supabase/serverhelper (powered by@supabase/ssr), aligned with the rest of the codebase.Fixes #597
Type of Change
Changes Made
next.config.js): Updated the.pdfloader rule to use Webpack 5 Asset Modules (type: 'asset/resource') and output files tostatic/files/.types/global.d.ts): Addeddeclare module '*.pdf';to support importing PDF files as module strings.@/lib/supabase/serverclient instead of the uninstalled@supabase/auth-helpers-nextjs:app/api/templates/[id]/route.tsapp/api/templates/[id]/shares/route.tsapp/api/templates/[id]/shares/[shareId]/route.tsnext.config.js): Disabled the experimentalworkerThreadsflag which caused aDataCloneErrortimeout crash during static page data collection (next build).Dependencies
Add Screenshots
(No UI changes were made in this PR)
Checklist
npm run dev).Summary by CodeRabbit
Refactor
Chores