Skip to content

Conversation

@rebelchris
Copy link
Contributor

@rebelchris rebelchris commented Dec 24, 2025

Problem

Extension builds were failing with ERROR in [entry] [initial] js/newtab.bundle.js Invalid array length after commit 4d36738 which added OpportunityEditRecruiterModal.

Root Cause

The modal imports from lib/schema/opportunity.ts, which contains complex zod validation schemas. When webpack processes this file during extension builds, Next.js 15.4.10's Babel plugin attempts to optimize/rewrite code patterns and hits a bug when processing:

  • Large numeric literals with underscores (100_000_000, 1_000_000)
  • Complex nested zod schemas with refinements
  • Dynamic array patterns like [0, 0.5, 1].map(item => z.literal(item, {...}))

The Babel regex rewriting plugin creates an invalid internal array structure, causing the "Invalid array length" error.

Solution

Conditionally exclude opportunity-related modals from extension builds by checking process.env.TARGET_BROWSER at compile time. These modals are webapp-only features (job posting management) and should never be loaded in the extension anyway.

Why this approach:

  • ✅ Webpack performs compile-time replacement of process.env.*, enabling proper tree-shaking
  • ✅ The problematic imports are never processed during extension builds
  • ✅ No impact on webapp functionality
  • ✅ Cleaner than trying to rewrite complex zod schemas or webpack exclusions

Changes

  • packages/shared/src/components/modals/common.tsx: Wrapped OpportunityEditModal and OpportunityEditRecruiterModal in conditional checks
  • packages/shared/src/lib/schema/opportunity.ts: Minor optimization of roleType union (changed from .map() to explicit literals)

Testing

  • ✅ Extension build completes successfully
  • ✅ Webapp build unaffected (modals load normally)
  • ✅ Extension doesn't include unnecessary opportunity modal code

Notes

This is a workaround for a Next.js 15.4.10 Babel bug. The issue may be resolved in future Next.js versions, but this approach has the added benefit of reducing extension bundle size by excluding webapp-only features.

Preview domain

https://hotfix-webpack-build.preview.app.daily.dev

@vercel
Copy link

vercel bot commented Dec 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
daily-webapp Ready Ready Preview Dec 24, 2025 9:35am
1 Skipped Deployment
Project Deployment Review Updated (UTC)
storybook Ignored Ignored Dec 24, 2025 9:35am

Copy link
Member

@idoshamun idoshamun left a comment

Choose a reason for hiding this comment

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

we just need to make sure it works in webapp

@rebelchris rebelchris merged commit 3c63f64 into main Dec 24, 2025
12 checks passed
@rebelchris rebelchris deleted the hotfix-webpack-build branch December 24, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants