Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: update i18n version and routing #568

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Technologic101
Copy link

@Technologic101 Technologic101 commented Jan 11, 2025

Refactors routing to use i18n v3, bumps puppeteer version

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced internationalization support with improved routing and localization configuration
  • Dependency Updates

    • Updated next-intl to version 3.26.3
    • Updated puppeteer to version 22.5.0
    • Re-added @sparticuz/chromium dependency
  • Configuration Changes

    • Streamlined internationalization middleware and routing setup
    • Simplified message retrieval process for locales
  • Chores

    • Removed postinstall script from project configuration

Copy link

vercel bot commented Jan 11, 2025

@Technologic101 is attempting to deploy a commit to the al1abb-team Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jan 11, 2025

Walkthrough

The pull request introduces comprehensive changes to the project's internationalization (i18n) implementation using the next-intl library. The modifications span across multiple files, centralizing routing and localization configuration, updating dependency versions, and streamlining message retrieval. The changes aim to improve the application's internationalization approach by leveraging the latest features of the next-intl library and creating a more consistent routing and localization strategy.

Changes

File Change Summary
app/[locale]/layout.tsx Updated message retrieval using getMessages() from next-intl/server
app/components/reusables/LanguageSelector.tsx Modified router import from next-intl/client to custom @/i18n/routing
i18n/request.ts Added new default export with getRequestConfig for locale handling
i18n/routing.ts Introduced routing configuration with defineRouting and navigation components
middleware.ts Updated middleware to use centralized routing configuration
next.config.js Added next-intl plugin configuration
package.json Updated next-intl, puppeteer, and re-added @sparticuz/chromium dependencies

Sequence Diagram

sequenceDiagram
    participant Client
    participant Routing
    participant Middleware
    participant Layout
    participant Locales

    Client->>Routing: Request page
    Routing->>Middleware: Validate locale
    Middleware->>Routing: Return valid locale
    Routing->>Locales: Fetch messages
    Locales-->>Layout: Provide messages
    Layout->>Client: Render internationalized page
Loading

Poem

🌍 Internationalize with glee,
A rabbit's code, now swift and free!
Locales dance, routing so bright,
Next-intl makes everything right! 🐰
Hop along the multilingual way!

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
i18n/request.ts (2)

9-11: Consider improving type safety

The type assertion as any could be replaced with a more specific type to maintain better type safety.

-  if (!locale || !routing.locales.includes(locale as any)) {
+  if (!locale || !routing.locales.includes(locale as string)) {

13-16: Consider implementing message caching

The dynamic import of locale messages on each request could impact performance. Consider implementing a caching mechanism for frequently accessed locales.

i18n/routing.ts (1)

8-8: Consider explicit locale mapping

While locale.code works, consider making the locale mapping more explicit for better maintainability.

-  locales: LOCALES.map((locale) => locale.code),
+  locales: LOCALES.map(({code}) => code),
app/[locale]/layout.tsx (1)

88-88: Consider adding timeZone prop for consistent date handling

When using next-intl v3, it's recommended to specify the timeZone prop for consistent date handling across different locales.

-                <NextIntlClientProvider messages={messages}>
+                <NextIntlClientProvider 
+                    messages={messages}
+                    timeZone="UTC"
+                >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 643f355 and 3d56177.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • app/[locale]/layout.tsx (3 hunks)
  • app/components/reusables/LanguageSelector.tsx (1 hunks)
  • i18n/request.ts (1 hunks)
  • i18n/routing.ts (1 hunks)
  • middleware.ts (1 hunks)
  • next.config.js (2 hunks)
  • package.json (3 hunks)
🔇 Additional comments (7)
middleware.ts (1)

1-4: Well-structured middleware implementation!

The changes effectively centralize the routing configuration by importing from @/i18n/routing, following next-intl v3 best practices. This approach improves maintainability by keeping locale configuration in a single location.

i18n/routing.ts (1)

16-17: Well-structured navigation exports!

The exported navigation utilities provide a clean API while maintaining internationalization support.

next.config.js (2)

24-24: Verify plugin composition order

The current plugin composition looks correct. However, ensure that withNextIntl doesn't interfere with withBundleAnalyzer's functionality. Consider monitoring bundle size reports after this change.


Line range hint 7-9: Verify puppeteer-core compatibility

Since the PR mentions updating Puppeteer version, ensure that the serverComponentsExternalPackages configuration is still required and compatible with the new version.

✅ Verification successful

Configuration is correct and necessary

The serverComponentsExternalPackages configuration for puppeteer-core is still required as it's actively used in server-side code (services/invoice/server/generatePdfService.ts) for PDF generation in production. The configuration is compatible with the updated version 22.5.0.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check package.json for puppeteer version
rg -A 1 '"puppeteer(-core)?":\s*"[^"]*"' package.json

# Check if other packages require similar external configuration
rg -l 'require\(["\']puppeteer(-core)?["\']\)' .

Length of output: 390


Script:

#!/bin/bash
# Search for puppeteer-core imports/requires
rg -l "from ['\"]puppeteer-core['\"]|require\\(['\"]puppeteer-core['\"]\\)" .

# Search for files with .server suffix or "use server" directive that use puppeteer
rg -l "puppeteer(-core)?" --glob "**/*.server.{js,ts,jsx,tsx}" .
rg -l "^['\"](server|use server)['\"]\s*;.*puppeteer(-core)?" .

# Check if there are any server components using puppeteer
rg -C 2 "puppeteer(-core)?" --glob "**/*.server.{js,ts,jsx,tsx}" .

Length of output: 291


Script:

#!/bin/bash
# Check for any puppeteer usage in app directory
rg -l "puppeteer(-core)?" app/

# Look for API routes using puppeteer
rg -l "puppeteer(-core)?" --glob "app/api/**/*.{js,ts}" .
rg -l "puppeteer(-core)?" --glob "pages/api/**/*.{js,ts}" .

# Search for any puppeteer usage patterns
rg -C 2 "puppeteer(-core)?" .

Length of output: 12294

app/components/reusables/LanguageSelector.tsx (1)

6-6: Verify the routing configuration setup

The import path has been updated to use a custom routing configuration. Ensure that @/i18n/routing is properly set up with the new next-intl v3 routing configuration.

Consider adding documentation about the new routing setup in the README or a dedicated i18n documentation file.

✅ Verification successful

Import change is correctly implemented

The custom routing setup at i18n/routing.ts is properly configured using next-intl v3's defineRouting and createNavigation. The import change in LanguageSelector.tsx is valid and consistent with the application's i18n architecture.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the routing configuration exists and is properly set up
rg -l "defineRouting|createSharedPathnamesNavigation" "app/i18n"

Length of output: 113


Script:

#!/bin/bash
# Find i18n related files and directories
fd -t f "i18n" --exec rg -l "defineRouting|createSharedPathnamesNavigation|useRouter" {}

Length of output: 90


Script:

#!/bin/bash
# Find all i18n related files
echo "=== i18n related files ==="
fd "i18n"

echo -e "\n=== Files containing routing setup ==="
rg -l "routing|navigation" --type ts --type tsx

Length of output: 249


Script:

#!/bin/bash
# List contents of i18n directory
echo "=== Contents of i18n directory ==="
ls -la i18n/

echo -e "\n=== Files containing routing setup ==="
rg -t ts "routing|navigation" --glob "*.{ts,tsx}"

Length of output: 2442

package.json (2)

66-66: Verify Puppeteer and Chromium version compatibility

The PR updates both Puppeteer and adds @sparticuz/chromium. Ensure these versions are compatible and the removal of the postinstall script doesn't affect the setup.

Consider documenting the Puppeteer setup and any environment-specific requirements in the README.

Also applies to: 75-75


41-41: Verify next-intl v3 migration changes

The update from next-intl v2 to v3 is a major version bump that includes breaking changes. Ensure all breaking changes have been addressed:

  • Routing configuration updates
  • Message loading changes
  • Client/Server components separation
✅ Verification successful

next-intl v3 migration appears correctly implemented

The codebase already follows the v3 patterns:

  • Correct usage of NextIntlClientProvider
  • Server-side message loading with getMessages
  • Proper app directory [locale] routing structure
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential missed migration updates
rg "useTranslations|useLocale|useNow|useTimeZone" "app/"

Length of output: 56


Script:

#!/bin/bash
# Find next-intl usage and config files
rg "from 'next-intl'" -A 2
rg "from \"next-intl\"" -A 2

# Look for i18n configuration files
fd -g "*i18n*.{js,ts,tsx,json}"

# Look for messages or translations
fd -g "*messages*.{js,ts,tsx,json}"
fd -g "*translations*.{js,ts,tsx,json}"

Length of output: 531

Comment on lines +73 to +74

const messages = await getMessages()
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for message loading

The error handling for message loading has been removed. Consider adding error handling to gracefully handle cases where messages fail to load.

-    const messages = await getMessages()
+    try {
+        const messages = await getMessages()
+    } catch (error) {
+        console.error('Failed to load messages:', error);
+        notFound();
+    }

Committable suggestion skipped: line range outside the PR's diff.

Copy link

vercel bot commented Jan 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
invoify ❌ Failed (Inspect) Jan 15, 2025 7:33am

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.

1 participant