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

fix: rendering issue with few components using next-i18n on community pages #3384

Closed
wants to merge 3 commits into from

Conversation

SahilDahekar
Copy link
Contributor

@SahilDahekar SahilDahekar commented Nov 12, 2024

Description

  • Fixed NewsletterSubscribe component rendering issue on /community/tsc, /community/events , /community page by adding getStaticProps() function.
  • On /community/events page extracted All Events section into new component CommunityEvents to be able to use getStaticProps() function.
  • Removed uneccessary useState hook use for icon hover functionality on /community/tsc page.
  • Updated getI18nProps() function in the getStatic.ts by adding default locale as en.

Related issue(s)

Fixes #3381

Summary by CodeRabbit

  • New Features

    • Introduced the CommunityEvents component for displaying and filtering community events.
    • Added static properties functionality for improved data management in community pages.
  • Bug Fixes

    • Enhanced locale handling with a fallback mechanism to default to English if no language parameter is provided.
  • Refactor

    • Streamlined social media icon components by removing hover state management for simpler implementation.

Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

The pull request introduces a new React component, CommunityEvents, which manages and displays community events. It replaces state management in the EventIndex component, delegating event handling to CommunityEvents. Additionally, static properties are added to several components using makeStaticProps, enhancing data-fetching capabilities. Modifications also include refactoring social media icons in the tsc page to remove state management. Lastly, a fallback mechanism is implemented in the getI18nProps function to ensure a default locale.

Changes

File Change Summary
components/CommunityEvents.tsx Added CommunityEvents component; manages events and renders them conditionally.
pages/community/events/index.tsx Updated EventIndex to use CommunityEvents; removed state management and event filtering.
pages/community/index.tsx Added getStaticProps for static site generation.
pages/community/tsc.tsx Added getStaticProps; refactored social media icons to remove hover state management.
utils/getStatic.ts Modified getI18nProps to include a fallback for the locale variable.

Assessment against linked issues

Objective Addressed Explanation
Button should be named differently (issue #3381) No changes to button names were made in this PR.

Possibly related PRs

Suggested labels

ready-to-merge, bounty

Suggested reviewers

  • derberg
  • akshatnema
  • magicmatatjahu
  • Mayaleeeee
  • asyncapi-bot-eve
  • devilkiller-ag
  • sambhavgupta0705
  • anshgoyalevil

🐰 In the community, we gather and share,
Events to enjoy, with friends everywhere.
With filters and lists, we make it just right,
Join us in fun, from morning till night!
Let's hop to the beat, with joy and delight! 🌟


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>, 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 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

netlify bot commented Nov 12, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d5c9d59
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67339905caf0bf00081565f6
😎 Deploy Preview https://deploy-preview-3384--asyncapi-website.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.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Nov 12, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 46
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3384--asyncapi-website.netlify.app/

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.77%. Comparing base (6f15381) to head (d5c9d59).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3384   +/-   ##
=======================================
  Coverage   67.77%   67.77%           
=======================================
  Files          21       21           
  Lines         664      664           
=======================================
  Hits          450      450           
  Misses        214      214           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 2

🧹 Outside diff range and nitpick comments (4)
utils/getStatic.ts (2)

32-32: LGTM! Consider improving type safety.

The addition of the English locale fallback is a good defensive programming practice. However, the function could benefit from stronger typing.

Consider this type-safe improvement:

- export async function getI18nProps(ctx: any, ns = ['common']) {
-   const locale = ctx?.params?.lang ? ctx?.params?.lang : 'en';
+ type LocaleContext = {
+   params?: {
+     lang?: string;
+   };
+ };
+ export async function getI18nProps(ctx: LocaleContext, ns = ['common']) {
+   const locale = ctx?.params?.lang || 'en';

32-32: Simplify the conditional expression.

The current implementation uses a verbose ternary expression with multiple optional chaining operators.

Consider this more concise version:

- const locale = ctx?.params?.lang ? ctx?.params?.lang : 'en';
+ const locale = ctx?.params?.lang || 'en';
pages/community/events/index.tsx (1)

Line range hint 35-44: Consider enhancing calendar button accessibility

The calendar integration buttons could benefit from additional accessibility attributes.

Consider adding ARIA labels to provide more context:

 <GoogleCalendarButton 
+  aria-label="Add AsyncAPI events to Google Calendar"
   href='https://calendar.google.com/calendar/u/3?cid=Y19xOXRzZWlnbG9tZHNqNm5qdWh2YnB0czExY0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29t' 
 />
 <ICSFileButton
+  aria-label="Download AsyncAPI events calendar file"
   href='https://calendar.google.com/calendar/ical/c_q9tseiglomdsj6njuhvbpts11c%40group.calendar.google.com/public/basic.ics'
   className='mt-2 md:ml-2 md:mt-0'
 />
pages/community/tsc.tsx (1)

74-75: LGTM: Improved icon components with CSS-based hover effects

The refactoring improves performance by replacing JavaScript state management with CSS hover effects. However, there's an opportunity to make the hover colors more consistent across icons.

Consider standardizing the hover colors for better visual consistency:

-      <IconTwitter className={'hover:fill-black'} />
+      <IconTwitter className={'hover:fill-primary-600'} />
-      <IconGithub className={'hover:fill-black'} />
+      <IconGithub className={'hover:fill-primary-600'} />
-      <IconLinkedIn className={'hover:fill-linkedin'} />
+      <IconLinkedIn className={'hover:fill-primary-600'} />

Also applies to: 87-88, 100-102

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6f15381 and d5c9d59.

📒 Files selected for processing (5)
  • components/CommunityEvents.tsx (1 hunks)
  • pages/community/events/index.tsx (2 hunks)
  • pages/community/index.tsx (2 hunks)
  • pages/community/tsc.tsx (5 hunks)
  • utils/getStatic.ts (1 hunks)
🔇 Additional comments (10)
components/CommunityEvents.tsx (3)

1-11: LGTM! Well-organized imports with proper type definitions.

The imports are logically grouped and include all necessary components and types for the functionality.


16-42: LGTM! Well-structured responsive layout with proper error handling.

The component implements:

  • Responsive grid layout using Tailwind classes
  • Proper error handling for empty states
  • Clear visual hierarchy with appropriate spacing

1-45: Verify i18n integration with this component.

While the component has been successfully extracted, please ensure that:

  1. All text content is properly internationalized
  2. The component works correctly with the updated getI18nProps() function
pages/community/events/index.tsx (3)

4-4: LGTM: Proper implementation of i18n static props

The implementation of getStaticProps using makeStaticProps with the necessary i18n namespaces ('landing-page', 'footer', 'common') aligns well with fixing the rendering issues mentioned in the PR objectives.

Also applies to: 7-7, 18-20


91-91: LGTM: Clean integration of CommunityEvents component

The extraction of events listing into a separate CommunityEvents component improves code organization and aligns with the PR objectives.


Line range hint 27-156: Verify performance impact of the component structure

The Lighthouse report shows a low performance score (46). Let's verify if the component structure could be optimized.

✅ Verification successful

Performance impact verified and no issues found in the component structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential performance optimizations in the component

# Look for large component renders without memo
ast-grep --pattern 'export default function $COMPONENT() {
  $$$
  return (
    $$$
    <div className=$_>
      $$$
    </div>
    $$$
  );
}'

# Check for missing image optimizations
rg -l "img.*src=.*\.(png|jpg|jpeg|webp)" 

# Look for potential code splitting opportunities
ast-grep --pattern 'import $COMPONENT from $PATH'

Length of output: 976

pages/community/index.tsx (2)

6-6: LGTM!

The import of makeStaticProps is correctly added and follows project conventions.


18-20: Implementation looks good but verify i18n integration.

The addition of getStaticProps with the 'common' namespace should resolve the rendering issues with next-i18n. This ensures translations are available during static site generation.

Let's verify the i18n integration:

✅ Verification successful

i18n integration verified and functioning correctly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify i18n setup and usage
# Check for translation files and their usage

# Check if common namespace translations exist
echo "Checking for common namespace translations..."
fd -e json . public/locales -x echo "Found translation file: {}"

# Check for other components using makeStaticProps with common namespace
echo "\nChecking for similar implementations..."
rg "makeStaticProps\(\['common'\]\)" -A 2 -B 2

# Verify NewsletterSubscribe component usage
echo "\nChecking NewsletterSubscribe usage..."
rg "NewsletterSubscribe" -A 2 -B 2

Length of output: 9310

pages/community/tsc.tsx (2)

4-4: LGTM: Proper implementation of getStaticProps for i18n support

The implementation correctly uses makeStaticProps utility with the 'common' namespace, which aligns with Next.js internationalization best practices.

Also applies to: 14-16


Line range hint 319-324: Verify NewsletterSubscribe component's button labels

Given issue #3381 about incorrect button names, we should verify the labels rendered by the NewsletterSubscribe component.

Comment on lines +35 to +37
{events.map((event: Event, index: number) => {
return <EventPostItem key={index} id={event.title} post={event} />;
})}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using array indices as React keys.

Using array indices as keys can lead to issues with component state and performance when the list items can change (reordering, filtering, etc.). Consider using a unique identifier from the event data.

-{events.map((event: Event, index: number) => {
-  return <EventPostItem key={index} id={event.title} post={event} />;
+{events.map((event: Event) => {
+  return <EventPostItem key={event.title} id={event.title} post={event} />;

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

Comment on lines +13 to +15
const CommunityEvents = () => {
const [events, setEvents] = useState(getEvents(meetings));

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize state initialization to prevent unnecessary calculations.

The getEvents(meetings) call in useState will run on every render. Consider optimizing this by either:

  1. Moving the initialization outside the component
  2. Using useMemo to memoize the result
+const initialEvents = getEvents(meetings);
+
 const CommunityEvents = () => {
-  const [events, setEvents] = useState(getEvents(meetings));
+  const [events, setEvents] = useState(initialEvents);

Or with useMemo:

 const CommunityEvents = () => {
-  const [events, setEvents] = useState(getEvents(meetings));
+  const initialEvents = useMemo(() => getEvents(meetings), []);
+  const [events, setEvents] = useState(initialEvents);

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

@bandantonio
Copy link
Contributor

Potential duplicate of #3308

@SahilDahekar
Copy link
Contributor Author

Should this PR be closed then since this is a duplicate ?? @bandantonio

@bandantonio
Copy link
Contributor

@SahilDahekar I think yes. You can always compare the changes in both PRs and decide for yourself. But since the issue has already been closed, the linked PR can also be closed. If you find that the original PR lacks some info or can be improved, feel free to contribute to that PR directly but please try to avoid the situation, that was mentioned in that PR

I think PR #3308 is relevant to this issue and is still under review. You should avoid working on the issues which already have a PR open.

@SahilDahekar
Copy link
Contributor Author

Thanks @bandantonio for clarification . I am closing this PR and will directly contribute to the #3308 .

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.

[BUG] Button Name error in community/tsc page
3 participants