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

refactor: remove luxon package, replace with JS Intl library #12209

Merged
merged 8 commits into from
Mar 18, 2024
Merged

Conversation

wackerow
Copy link
Member

@wackerow wackerow commented Feb 16, 2024

Description

  • Updates getLocaleTimestamp.ts inside src/lib/utils/time.ts to use Intl.DateTimeFormat instead of luxon tooling.
  • Adds an optional options prop here to override display options as-needed
  • Remove usage of luxon inside CommunityEvents/index.tsx, replacing with updated usage of getLocaleTimestamp
  • yarn remove luxon @types/luxon

Related Issue

https://www.notion.so/efdn/Review-if-we-can-replace-some-packages-with-native-implementation-1875f79b99f04555aa60bb5f7b14e8c0?pvs=4

Fixes #12019

Summary by CodeRabbit

  • Refactor
    • Improved date handling across the app for better localization and efficiency.
  • New Features
    • Updated display logic for last updated and deploy dates to enhance user experience.
  • Chores
    • Removed unnecessary dependencies and streamlined date formatting.

@github-actions github-actions bot added dependencies 📦 Changes related to project dependencies review needed 👀 labels Feb 16, 2024
Copy link

netlify bot commented Feb 16, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit df0a954
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/65f87b49b6aa6e0008bb2fdc
😎 Deploy Preview https://deploy-preview-12209--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@nhsz
Copy link
Member

nhsz commented Feb 16, 2024

@wackerow Excellent! Seems we also need to remove @types/luxon

@wackerow
Copy link
Member Author

Good catch; removed the types package... thanks @nhsz!

Make lastUpdatedDate prop for Docs and Tutorials layouts required, remove force unwrap with !, use lastUpdatedDate as fallback for intlLastEdit
Temporary fix for `Export encountered errors on following paths: /_error: /500`
@wackerow wackerow marked this pull request as draft February 16, 2024 21:53
@wackerow
Copy link
Member Author

Getting a strange result where the lastDeployDate in the Footer is causing the build to fail with:

Export encountered errors on following paths:
        /_error: /500
       ...

Added a temporary debugging patch to check for paths starting with /500 and skipping the rendering of the deploy date for those cases. Want to see if this builds okay on Netlify (working locally), but I don't really see this as a final solution though; open to thoughts.

getLocaleTimestamp requires a date string but was occasionally getting an empty string or undefined; this confirms a value exists for the argument before rendering the component that makes this function call
@wackerow wackerow marked this pull request as ready for review February 18, 2024 07:05
@nhsz nhsz mentioned this pull request Feb 25, 2024
@corwintines corwintines self-assigned this Feb 26, 2024
Copy link
Contributor

coderabbitai bot commented Mar 12, 2024

Walkthrough

The changes primarily focus on refining date handling across various components and layouts by eliminating the luxon package in favor of native JavaScript Date functionalities and the Intl.DateTimeFormat options. This shift enhances performance and reduces dependency load. Additionally, the updates streamline the rendering logic for displaying last updated dates and refactor certain props and structure within layout components for clarity and efficiency.

Changes

Files Change Summary
src/components/CommunityEvents/index.tsx Refactored date handling using native JS, removed luxon, utilized Intl.DateTimeFormatOptions.
src/components/Footer.tsx,
src/layouts/...
Updated last updated date display logic to be conditional.
src/lib/utils/time.ts Replaced luxon with native Date API and added customization options for date formatting.
src/pages/developers/tutorials.tsx Adjusted date rendering logic to check for "Invalid Date" directly, removed luxon dependency.

Assessment against linked issues

Objective Addressed Explanation
Investigate & replace luxon with native solutions (#12019)

The changes effectively address the primary objective outlined in the linked issue by replacing luxon with native JavaScript solutions for date handling and formatting. This aligns with the goal of reducing dependency load and utilizing native functionalities for performance and simplicity.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a1feedc and 408fb01.
Files ignored due to path filters (2)
  • package.json is excluded by: !**/*.json
  • yarn.lock is excluded by: !**/*.lock
Files selected for processing (8)
  • src/components/CommunityEvents/index.tsx (8 hunks)
  • src/components/Footer.tsx (1 hunks)
  • src/layouts/Docs.tsx (3 hunks)
  • src/layouts/Static.tsx (1 hunks)
  • src/layouts/Tutorial.tsx (3 hunks)
  • src/layouts/Upgrade.tsx (2 hunks)
  • src/lib/utils/time.ts (1 hunks)
  • src/pages/developers/tutorials.tsx (3 hunks)
Additional comments: 12
src/lib/utils/time.ts (1)
  • 3-16: The refactoring of getLocaleTimestamp to use Intl.DateTimeFormat instead of luxon and the addition of an options parameter for customization are good improvements. This change leverages native JavaScript capabilities, potentially simplifying the codebase and reducing dependency footprint. The implementation correctly handles the optional options parameter, providing a default format when not specified. This approach aligns well with best practices for flexibility and usability in utility functions.

One minor suggestion is to ensure thorough testing of this function across different locales and options to verify the correctness of the date formatting in various use cases. Additionally, consider documenting the expected format of the timestamp string and any limitations or considerations related to the Intl.DateTimeFormat usage, especially regarding browser compatibility.

src/layouts/Static.tsx (1)
  • 121-129: The conditional rendering of the last updated date in the StaticLayout component based on the existence of lastUpdatedDate is a good practice. It ensures that the UI only displays relevant information when available, enhancing the user experience. The use of getLocaleTimestamp for formatting the date is consistent with the project's approach to date handling after the refactor.

Ensure that the lastUpdatedDate prop is properly passed and updated across all usages of StaticLayout to maintain the accuracy of the displayed date. Additionally, consider adding a brief comment explaining the conditional rendering logic for future maintainability.

src/components/CommunityEvents/index.tsx (1)
  • 31-45: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [34-52]

The refactoring in the Event component to use getLocaleTimestamp for date formatting and the removal of the language prop in favor of using the useRouter hook to get the locale are positive changes. These adjustments align with the overall goal of leveraging native JavaScript capabilities and simplifying the codebase. The use of Intl.DateTimeFormatOptions for specifying the date format is appropriate and provides flexibility for different event date presentations.

Ensure that the removal of the language prop and the reliance on the useRouter hook do not introduce any regressions in how event dates are displayed across different locales. It might be beneficial to add tests or checks to verify the correct behavior in various locale settings.

src/layouts/Upgrade.tsx (1)
  • 197-202: The addition of conditional rendering for the last updated date in the UpgradeLayout component based on the existence of lastUpdatedDate is a good practice, similar to the approach taken in other layouts. This ensures that the date is only displayed when available, maintaining a clean and relevant user interface.

However, the Skeleton component import at the top of the file does not seem to be used within the provided code snippet. If the Skeleton component is intended for use in parts of the layout not shown in the snippet, ensure its usage aligns with the loading state representation. If it's not being used, consider removing the import to keep the codebase clean and minimize bundle size.

src/layouts/Tutorial.tsx (2)
  • 168-176: The update to the TutorialLayoutProps type to include additional properties and the modification to the structure is a positive change, enhancing the type safety and clarity of the component's props. This change aligns with TypeScript best practices for defining component props more precisely.

However, ensure that all usages of the TutorialLayout component throughout the project have been updated to pass the required props according to the new type definition. This is crucial to avoid type errors and ensure the component functions as expected.

  • 194-195: The update to the intlLastEdit assignment to use lastUpdatedDate if gitHubLastEdit.data is not available is a sensible fallback mechanism. This ensures that the component can still display a relevant last updated date even if the GitHub last edit information is not available, maintaining the accuracy and relevance of the information presented to the user.

Consider adding a comment explaining the fallback logic for future maintainability, especially for developers who might not be familiar with the context behind the GitHub last edit feature.

src/layouts/Docs.tsx (2)
  • 209-220: The change to make lastUpdatedDate a required property in the DocsLayoutProps type is a good practice, ensuring that all documents have a last updated date for transparency and user information. This aligns with the goal of maintaining accurate and up-to-date documentation.

However, similar to the previous file, ensure that all usages of the DocsLayout component throughout the project have been updated to pass the lastUpdatedDate prop. This is crucial for maintaining consistency and avoiding runtime errors due to missing required props.

  • 236-237: The update to the intlLastEdit assignment to use lastUpdatedDate if gitHubLastEdit.data is not available is a sensible approach, ensuring that the component can display a relevant last updated date in all scenarios. This fallback mechanism enhances the robustness of the component by providing a default value when GitHub last edit information is not available.

As mentioned previously, consider documenting this fallback logic for clarity and maintainability.

src/components/Footer.tsx (1)
  • 301-306: The update to conditionally render the last deploy date in the Footer component based on the existence of lastDeployDate is a good improvement. This change ensures that the deploy date is only displayed when available, which is a clean and user-friendly approach.

Ensure that the lastDeployDate prop is accurately passed to the Footer component in all relevant places within the project. Additionally, consider adding a brief comment explaining the conditional rendering logic for future maintainability.

src/pages/developers/tutorials.tsx (3)
  • 36-36: The import statement for getLocaleTimestamp correctly aligns with the PR's objective to replace luxon with native JavaScript solutions for date manipulation.
  • 129-132: The changes to the published function, including the direct check for "Invalid Date", align well with the PR's objective and simplify the date handling logic by removing unnecessary constants.
  • 477-478: The integration of the published function within the TutorialPage component for conditional rendering of the published date is correctly implemented and aligns with the PR's objectives.

Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

Nice job! All looks fine @wackerow except this one in the tutorials page
image

Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 408fb01 and df0a954.
Files selected for processing (1)
  • src/pages/developers/tutorials.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pages/developers/tutorials.tsx

Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

Fixed! merging @wackerow 💪🏼

@pettinarip pettinarip merged commit 88de114 into dev Mar 18, 2024
10 checks passed
@pettinarip pettinarip deleted the rm-luxon branch March 18, 2024 18:31
This was referenced Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies 📦 Changes related to project dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate & replace luxon with native solutions
4 participants