feat: add Next.js Image optimization and fix dependency bundling #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of this pull request?
This PR migrates the components library to use Next.js's
next/imagecomponent for automatic image optimization and fixes critical dependency bundling issues that were preventing proper integration with consuming applications (helpcenter).What problem is this solving?
Problem 1: No image optimization
<img>tags without optimizationProblem 2: Bundling Next.js and React in components library
nextandreact-domwere independenciesinstead ofdevDependenciesProblem 3: ESM/CommonJS interop issues
next/imageimports from ESM modules returned objects instead of componentsnext/imagevsnext/image.js)Problem 4: SSR errors with useRouter
next/routerfailed in SSR contextsWhat changed?
1. Migrated to Next.js Image component 🖼️
2. Fixed dependency structure 📦
3. Added CommonJS default export fallback 🔧
4. Fixed router imports for SSR compatibility 🔀
5. Updated bundler config ⚙️
How should this be manually tested?
In the components library:
In consuming app (helpcenter):
Benefits
Image optimization:
Dependency management:
Compatibility:
Files changed
Source files:
src/lib/markdown-renderer/components.tsx- Migrated to Next.js Imagesrc/components/whats-next-card/index.tsx- Migrated to Next.js Imagesrc/components/sidebar-elements/index.tsx- Fixed router importsrc/components/search-*.tsx- Fixed router importssrc/utils/sidebar-utils.ts- Added SSR window checksConfiguration:
package.json- Moved dependencies, updated peerDependenciestsup.config.ts- Externalized Next.js modulesBuild artifacts:
dist/*- Rebuilt with new imports and externalsBreaking changes
None - This is backward compatible:
Types of changes
Related PRs
Consuming app (helpcenter):
Commits in this PR
feat: migrate ImageComponent to Next.js Image for optimizationfix: mark Next.js modules as external in bundler configfix: handle SSR in updateOpenPage by checking window availabilityfix: use next/compat/router to avoid SSR errors with useRouterfix: add .js extension to next/compat/router imports for ESMfix: change next/image.js imports to next/image for proper ESM resolutionfix: add CommonJS default export fallback for next/image importsfix: move next and react-dom from dependencies to devDependenciesTesting checklist
yarn build)yarn type-check)/_next/image)