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

feat: Code Refactor & Upgrade to Next.js 15 / React 19-RC #836

Merged
merged 20 commits into from
Oct 26, 2024

Conversation

philipbrembeck
Copy link
Collaborator

@philipbrembeck philipbrembeck commented Oct 19, 2024

Summary by Sourcery

Upgrade the project to Next.js 15 and React 19-RC, refactoring components for improved modularity and performance. Introduce new components for barcode scanning and product result display, and enhance sharing functionality. Update build and CI configurations to align with the latest dependencies and Node.js version.

New Features:

  • Introduce a new ViewportScanner component for barcode scanning with camera switching capabilities.
  • Add a ProductResultView component to display product details including vegan status, nutriscore, and grade.
  • Implement a ShareButton component for sharing product details across various platforms.

Enhancements:

  • Refactor the ShareButton component to use a more modular and maintainable approach with useMemo.
  • Improve the Footer component by introducing a FooterLink sub-component for better reusability.
  • Refactor the ModalWrapper component to use useCallback and useRef for better performance and readability.

Build:

  • Upgrade to Next.js 15 and React 19-RC, updating related dependencies in pnpm-lock.yaml.
  • Update ESLint configuration to use stricter TypeScript rules and improve import order settings.

CI:

  • Update Node.js version to 20.x and pnpm version to 9.12.1 in GitHub Actions workflows.

Tests:

  • Remove outdated OLED mode test and update barcode input test to match new URL patterns.

Copy link

stackblitz bot commented Oct 19, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

sourcery-ai bot commented Oct 19, 2024

Reviewer's Guide by Sourcery

This pull request performs a major upgrade to Next.js 15 and React 19-RC while significantly refactoring the codebase. The changes focus on improving component architecture, type safety, and performance through modern React patterns and better code organization. The upgrade includes configuration updates, dependency updates, and extensive component refactoring.

Class diagram for new and updated components

classDiagram
    class ProductResultView {
        +ProductResultView(result: ProductResult, sources: Sources, productState: ProductState, barcode: string)
    }
    class ViewportScanner {
        +ViewportScanner(onDetected: function, setScanning: function)
    }
    class IngredientsForm {
        +IngredientsForm()
    }
    class ShareButton {
        +ShareButton(productName: string, barcode: string)
    }
    class ModalWrapper {
        +ModalWrapper(id: string, buttonType: string, buttonClass: string, buttonText: string, children: ReactNode)
    }
    class FooterLink {
        +FooterLink(href: string, src: string, alt: string, className: string, width: number, height: number)
    }
    class SupportOption {
        +SupportOption()
    }
    class NavItem {
        +NavItem(href: string, iconClass: string, translationKey: string, isActive: boolean)
    }
Loading

File-Level Changes

Change Details Files
Upgrade core framework dependencies and configuration
  • Upgrade Next.js from 14.2.15 to 15.0.1
  • Upgrade React from 18.3.1 to 19.0.0-RC
  • Update ESLint configuration with stricter TypeScript rules
  • Update Node.js version to 20.x in CI workflow
  • Configure Million.js compiler optimization
pnpm-lock.yaml
.eslintrc.json
next.config.ts
.github/workflows/pr.yml
Refactor components into smaller, more focused modules with improved type safety
  • Split Check component into multiple smaller components with dedicated responsibilities
  • Create new ViewportScanner component with improved camera handling
  • Refactor ShareButton to use useMemo for share options
  • Create new ProductResultView component for displaying product details
  • Implement new IngredientsForm component with better state management
src/components/Check/index.tsx
src/components/Scanner/ViewportScanner.tsx
src/components/elements/share.tsx
src/components/Check/ProductResult.tsx
src/components/IngredientsCheck/IngredientsForm.tsx
Improve component architecture and code organization
  • Move component-specific types to dedicated model files
  • Create utility functions for product and ingredient actions
  • Implement server-side data fetching for privacy policy and impressum pages
  • Remove deprecated OLED mode component and tests
  • Simplify layout structure by removing redundant wrappers
src/components/Check/models/*
src/components/Check/utils/*
src/app/[locale]/privacy-policy/page.tsx
src/app/[locale]/impressum/page.tsx
src/components/elements/contents/oledmode.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Great job on the refactoring! The code is cleaner and more maintainable. However, we noticed that the OLEDMode component was removed from the More page. Was this intentional?
  • The improvements in code structure, especially in components like ShareButton and Modal, are commendable. Good use of React best practices and TypeScript features throughout.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/components/elements/share.tsx Outdated Show resolved Hide resolved
src/components/footer.tsx Show resolved Hide resolved
@philipbrembeck
Copy link
Collaborator Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Hardcoded PayPal donation link with a specific button ID found. (link)

Overall Comments:

  • Using React 19 RC and Next.js 15 in production could introduce instability. Consider waiting for stable releases or thoroughly testing these pre-release versions.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/components/elements/share.tsx Outdated Show resolved Hide resolved
src/components/elements/share.tsx Show resolved Hide resolved
src/components/elements/modalwrapper.tsx Outdated Show resolved Hide resolved
src/components/elements/contents/donate.tsx Show resolved Hide resolved
docs/assets/prism.js Outdated Show resolved Hide resolved
docs/assets/prism.js Outdated Show resolved Hide resolved
docs/assets/prism.js Outdated Show resolved Hide resolved
docs/assets/prism.js Outdated Show resolved Hide resolved
docs/assets/prism.js Outdated Show resolved Hide resolved
docs/assets/prism.js Outdated Show resolved Hide resolved
@philipbrembeck
Copy link
Collaborator Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Potential hard-coded PayPal donation link detected. (link)

Overall Comments:

  • The OLED mode component was removed from the more page without explanation. Was this intentional? If so, please document the reasoning for this change.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/components/elements/share.tsx Show resolved Hide resolved
src/components/elements/share.tsx Show resolved Hide resolved
src/components/elements/modalwrapper.tsx Outdated Show resolved Hide resolved
src/components/elements/contents/donate.tsx Show resolved Hide resolved
@philipbrembeck
Copy link
Collaborator Author

philipbrembeck commented Oct 26, 2024

The update to Next.js 15 still breaks the next-intl provider, even tough it seems to be not critical. There's the following console error occurring:

[ Server ]  Error: Route "/[locale]" used `headers().get('X-NEXT-INTL-LOCALE')`. `headers()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis

Which is allegedly fixed in [email protected], but we still geht this error (currently on ^3.23.5) (see amannn/next-intl#1391).

We should test the impact of this on staging.

@sourcery-ai review

@philipbrembeck philipbrembeck changed the title feat: Refactor code feat: Minor Code Refactor & Upgrade to Next.js 15 / React 19-RC Oct 26, 2024
@philipbrembeck
Copy link
Collaborator Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using the latest stable React 18 version instead of React 19 RC for production use. While the RC may work, it's generally safer to wait for the stable release before upgrading.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/components/elements/share.tsx Show resolved Hide resolved
@philipbrembeck philipbrembeck changed the title feat: Minor Code Refactor & Upgrade to Next.js 15 / React 19-RC feat: Code Refactor & Upgrade to Next.js 15 / React 19-RC Oct 26, 2024
@philipbrembeck
Copy link
Collaborator Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Potential hard-coded PayPal donation link found. (link)

Overall Comments:

  • The removal of documentation files (/docs/*) should be addressed - please provide an alternative documentation solution or restore these files to maintain project documentation.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/components/elements/contents/donate.tsx Show resolved Hide resolved
src/components/Check/utils/product-helpers.ts Show resolved Hide resolved
src/components/Check/utils/product-helpers.ts Show resolved Hide resolved
src/components/Check/utils/product-helpers.ts Show resolved Hide resolved
src/components/Scanner/ViewportScanner.tsx Show resolved Hide resolved
src/components/elements/modalwrapper.tsx Show resolved Hide resolved
src/components/elements/modalwrapper.tsx Show resolved Hide resolved
@philipbrembeck
Copy link
Collaborator Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Potential hard-coded PayPal donation link found. (link)

Overall Comments:

  • Consider adding unit tests for the new refactored components to maintain test coverage, particularly for the ViewportScanner and ProductResultView components.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/components/Check/index.tsx Show resolved Hide resolved
src/components/Check/utils/product-helpers.ts Show resolved Hide resolved
src/components/IngredientsCheck/IngredientsForm.tsx Outdated Show resolved Hide resolved
src/components/elements/contents/donate.tsx Show resolved Hide resolved
src/components/Check/utils/product-helpers.ts Show resolved Hide resolved
src/components/Check/utils/product-helpers.ts Show resolved Hide resolved
src/components/Check/utils/product-helpers.ts Show resolved Hide resolved
src/components/Scanner/ViewportScanner.tsx Show resolved Hide resolved
src/components/elements/modalwrapper.tsx Show resolved Hide resolved
src/components/elements/modalwrapper.tsx Show resolved Hide resolved
Copy link

sonarqubecloud bot commented Oct 26, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
1.2% Duplication on New Code

See analysis details on SonarCloud

@philipbrembeck philipbrembeck merged commit e830504 into staging Oct 26, 2024
3 of 4 checks passed
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