Skip to content

fix: resolve PDF imports via Webpack 5 Asset Modules and refactor tem…#628

Open
devbyhimans wants to merge 1 commit into
Muneerali199:mainfrom
devbyhimans:fix/pdf-imports-and-build
Open

fix: resolve PDF imports via Webpack 5 Asset Modules and refactor tem…#628
devbyhimans wants to merge 1 commit into
Muneerali199:mainfrom
devbyhimans:fix/pdf-imports-and-build

Conversation

@devbyhimans
Copy link
Copy Markdown
Contributor

@devbyhimans devbyhimans commented May 20, 2026

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 .pdf files are imported as modules in the project. Previously, next.config.js was configured to use file-loader for .pdf files, but the file-loader package was not installed in package.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 deprecated file-loader package 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-nextjs library. They have been updated to use the standard @/lib/supabase/server helper (powered by @supabase/ssr), aligned with the rest of the codebase.

Fixes #597

Type of Change

  • New feature (e.g., new page, component, or functionality)
  • Bug fix (non-breaking change that fixes an issue)
  • UI/UX improvement (design, layout, or styling updates)
  • Performance optimization (e.g., code splitting, caching)
  • Documentation update (README, contribution guidelines, etc.)
  • Other (please specify): ____________________

Changes Made

  • Webpack Configuration (next.config.js): Updated the .pdf loader rule to use Webpack 5 Asset Modules (type: 'asset/resource') and output files to static/files/.
  • TypeScript Definitions (types/global.d.ts): Added declare module '*.pdf'; to support importing PDF files as module strings.
  • Supabase Route Handler Refactoring: Refactored the template API routes to use @/lib/supabase/server client instead of the uninstalled @supabase/auth-helpers-nextjs:
    • app/api/templates/[id]/route.ts
    • app/api/templates/[id]/shares/route.ts
    • app/api/templates/[id]/shares/[shareId]/route.ts
  • Build Stabilization (next.config.js): Disabled the experimental workerThreads flag which caused a DataCloneError timeout crash during static page data collection (next build).

Dependencies

  • No new dependencies were added. Webpack 5 Asset Modules are built-in natively.

Add Screenshots

(No UI changes were made in this PR)

Checklist

  • My code follows the style guidelines of this project.
  • I have tested my changes across major browsers/devices.
  • I have tested my changes in development mode (npm run dev).
  • I have written or updated related tests, if necessary.
  • This is already assigned Issue to me, not an unassigned issue.

Summary by CodeRabbit

  • Refactor

    • Updated Supabase client initialization across template API routes to streamline authentication handling.
  • Chores

    • Removed experimental worker threads configuration flag.
    • Enhanced PDF file asset handling for improved compatibility.
    • Added TypeScript support for PDF file imports.

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 20, 2026

👷 Deploy request for docmagic1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 9978fe3

@netlify
Copy link
Copy Markdown

netlify Bot commented May 20, 2026

👷 Deploy request for docmagic-muneer pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 9978fe3

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

@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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

The PR refactors Supabase client initialization across three API route files by replacing the deprecated createRouteHandlerClient({ cookies }) pattern with an awaited createRoute() call, and updates build configuration to handle PDF assets using Webpack 5's native asset/resource type with corresponding TypeScript module typing.

Changes

Supabase Server Client Migration

Layer / File(s) Summary
Template endpoint client migration
app/api/templates/[id]/route.ts
GET, PUT, and DELETE handlers initialize Supabase via await createRoute() instead of the deprecated cookies-based approach; imports are updated to reflect the new createRoute dependency from @/lib/supabase/server.
Template shares endpoints client migration
app/api/templates/[id]/shares/route.ts, app/api/templates/[id]/shares/[shareId]/route.ts
GET and POST handlers in the shares list route, and DELETE and PATCH handlers in the share detail route, all switch to the new await createRoute() pattern for consistent Supabase client initialization across the shares management API surface.

PDF Asset Handling and Build Configuration

Layer / File(s) Summary
PDF build configuration and typing
next.config.js, types/global.d.ts
Webpack PDF asset rule changes from file-loader to Webpack 5's built-in type: 'asset/resource' with output path static/files/[name][ext], experimental config removes the workerThreads flag, and a new global TypeScript module declaration (declare module '*.pdf') allows type-safe PDF imports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • #597: The webpack PDF file-loader replacement and PDF module typing directly address the build-level handling of PDF asset imports described in this issue.

Suggested labels

type:bug, level:intermediate, quality:clean

Poem

🐰 From cookies to routes, the client takes flight,
PDF assets bundled, configured just right,
Supabase calls echo through shares and through spreads,
Build pipelines humming with webpack threads shed,
Clean migration done, the app stands up straight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: PDF imports resolution via Webpack and Supabase refactoring of template routes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering all required template sections with clear explanations of changes, motivation, and testing verification.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
next.config.js (1)

77-80: ⚡ Quick win

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between 281dd99 and 9978fe3.

📒 Files selected for processing (5)
  • app/api/templates/[id]/route.ts
  • app/api/templates/[id]/shares/[shareId]/route.ts
  • app/api/templates/[id]/shares/route.ts
  • next.config.js
  • types/global.d.ts

@devbyhimans
Copy link
Copy Markdown
Contributor Author

@Muneerali199
Please Review this PR request and assign the appropiate tags and approve it

@Muneerali199 Muneerali199 added the gssoc:approved Required GSSoC approval label label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Required GSSoC approval label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Fix Missing file-loader Dependency Causing PDF Import Build Failures

2 participants