-
-
Notifications
You must be signed in to change notification settings - Fork 530
Perf - Fix mobile detection hydration mismatch #2565
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
Conversation
…mprove website's performance
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis PR replaces direct runtime Changes
Sequence Diagram(s)sequenceDiagram
participant Component as UI Component
participant Hook as useIsMobile()
participant Window as window
Component->>Hook: call useIsMobile()
Hook->>Hook: init state = false
Hook->>Window: add resize listener (updateView)
Hook-->>Component: return isMobileView (initial false, then updated)
Note right of Hook: on mount/update -> compute and set isMobileView\non resize -> updateView -> set state
sequenceDiagram
participant OnboardingProvider
participant Steps as checklistIndexToOnboardingSteps
OnboardingProvider->>Steps: call (t, Component, isMobileView)
Steps-->>OnboardingProvider: steps configured using isDeviceMobile
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (13)**/*.*📄 CodeRabbit inference engine (.cursor/rules/bug-handling-with-todo-comments.mdc)
Files:
**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/next-js-conventions.mdc)
Files:
src/components/**/*.tsx📄 CodeRabbit inference engine (.cursor/rules/react-functional-components.mdc)
Files:
**/*.{tsx,jsx}📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.tsx📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.{ts,tsx,d.ts}📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Files:
{src,types}/**/*.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/**/*.tsx📄 CodeRabbit inference engine (CLAUDE.md)
Files:
{src,types}/**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/components/**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx,scss}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (3)📓 Common learnings📚 Learning: 2025-10-22T20:33:55.176ZApplied to files:
📚 Learning: 2025-10-26T10:22:52.381ZApplied to files:
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (14)
src/components/HomePage/ReadingSection/ChapterCard/index.tsx(3 hunks)src/components/HomePage/ReadingSection/index.tsx(4 hunks)src/components/Onboarding/OnboardingProvider.tsx(2 hunks)src/components/Onboarding/steps.ts(1 hunks)src/components/QuranReader/ContextMenu/hooks/useContextMenuState.ts(3 hunks)src/components/QuranReader/ContextMenu/index.tsx(3 hunks)src/components/QuranReader/SidebarNavigation/SidebarNavigation.tsx(2 hunks)src/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsx(3 hunks)src/components/QuranicCalendar/MyProgress/index.tsx(3 hunks)src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsx(6 hunks)src/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsx(4 hunks)src/components/Search/SearchInput/index.tsx(3 hunks)src/hooks/useIsMobile.ts(1 hunks)src/pages/index.tsx(3 hunks)
🧰 Additional context used
📓 Path-based instructions (14)
**/*.*
📄 CodeRabbit inference engine (.cursor/rules/bug-handling-with-todo-comments.mdc)
If you encounter a bug in existing code, or the instructions lead to suboptimal or buggy code, add comments starting with "TODO:" outlining the problems.
**/*.*: Utilize Early Returns: Use early returns to avoid nested conditions and improve readability.
Conditional Classes: Prefer conditional classes over ternary operators for class attributes.
**/*.*: Use comments sparingly, and when you do, make them meaningful.
Don't comment on obvious things. Excessive or unclear comments can clutter the codebase and become outdated.
Use comments to convey the 'why' behind specific actions or explain unusual behavior and potential pitfalls.
Provide meaningful information about the function's behavior and explain unusual behavior and potential pitfalls.
**/*.*: Write short functions that only do one thing.
Follow the single responsibility principle (SRP), which means that a function should have one purpose and perform it effectively.
If a function becomes too long or complex, consider breaking it into smaller, more manageable functions.Order functions with those that are composing other functions appearing earlier in the file. For example, if you have a menu with multiple buttons, define the menu function above the buttons.
**/*.*: Always add helpful comments to the code explaining what you are doing.
Never delete old comments, unless they are no longer relevant because the code has been rewritten or deleted.
**/*.*: Choose names for variables, functions, and classes that reflect their purpose and behavior.
A name should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent.
Use specific names that provide a clearer understanding of what the variables represent and how they are used.
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/next-js-conventions.mdc)
**/*.{js,jsx,ts,tsx}: Rely on Next.js Pages Router for state changes.
Minimize 'use client' usage: Prefer server components and Next.js SSR features.
Minimize 'use client' usage: Use 'use client' only for Web API access in small components.
Minimize 'use client' usage: Avoid using 'use client' for data fetching or state management.
**/*.{js,jsx,ts,tsx}: Optimize Web Vitals (LCP, CLS, FID)
Use dynamic loading for non-critical components using @src/components/dls/Spinner/Spinner.tsx
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
src/components/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/react-functional-components.mdc)
src/components/**/*.tsx: Always use React functional components with hooks.
Use React.FC for functional components with props.
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsx
**/*.{tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{tsx,jsx}: Use functional components over class components
Keep components small and focused
Extract reusable logic into custom hooks
Use composition over inheritance
Split large components into smaller, focused ones
Follow the Rules of Hooks
Use custom hooks for reusable logic
Use appropriate dependency arrays in useEffect
Implement cleanup in useEffect when needed
Avoid nested hooks
Use useState for local component state
Avoid prop drilling through proper state management
Implement proper memoization (useMemo, useCallback)
Use React.memo for expensive components
Avoid unnecessary re-renders
Implement proper lazy loading
Use proper key props in lists
Profile and optimize render performance
Show appropriate loading and error states
Handle async errors properly
Show user-friendly error messages
Implement proper fallback UI
Log errors appropriately
Handle edge cases gracefully
Use semantic HTML elements
Implement proper ARIA attributes
Ensure keyboard navigation
Handle focus management
Provide proper alt text for images
Use proper imports/exports
Document complex component logic
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/pages/index.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Implement proper prop types with TypeScript
**/*.tsx: Prefix interfaces for React props with 'Props' (e.g., ButtonProps)
Implement proper error boundariesReact: use functional components only; extract reusable logic into custom hooks; apply proper memoization (React.memo/useMemo/useCallback)
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/pages/index.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Use xstate for complex state logic
**/*.{ts,tsx}: TypeScript: prefer interfaces over type aliases for object shapes; avoid any; add explicit return types for public functions
Error handling: define and use custom error types; use async/await correctly; show user-friendly error messages
Use Redux Toolkit for state management and XState for complex state machines
Implement i18n with next-translate in components and utilities
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx,d.ts}: Prefer interfaces over types for object definitions
Use type for unions, intersections, and mapped types
Avoid usingany, preferunknownfor unknown types
Leverage TypeScript's built-in utility types
Use generics for reusable type patterns
Use PascalCase for type names and interfaces
Use camelCase for variables and functions
Use UPPER_CASE for constants
Use descriptive names with auxiliary verbs (e.g., isLoading, hasError)
Use explicit return types for public functions
Use arrow functions for callbacks and methods
Implement proper error handling with custom error types
Use function overloads for complex type scenarios
Prefer async/await over Promises
Use readonly for immutable properties
Leverage discriminated unions for type safety
Use type guards for runtime type checking
Implement proper null checking
Avoid type assertions unless necessary
Create custom error types for domain-specific errors
Use Result types for operations that can fail
Use try-catch blocks with typed catch clauses
Handle Promise rejections properly
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
{src,types}/**/*.ts?(x)
📄 CodeRabbit inference engine (CLAUDE.md)
Use TypeScript throughout the codebase with strict configuration
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
src/**/*.tsx
📄 CodeRabbit inference engine (CLAUDE.md)
Prefer React functional components for UI implementation
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/pages/index.tsx
{src,types}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use path aliases @/ for src and @/dls/* for design system imports
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
src/components/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Organize React components by feature and place DLS components under src/components/dls
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,js,jsx}: Order imports: React first, then external, then internal; alphabetize within groups with blank lines between groups
Naming: camelCase for variables/functions; PascalCase for types, interfaces, and React components; UPPER_CASE for constants
Functions should be <= 30 lines, prefer early returns, single responsibility, and descriptive names
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
**/*.{ts,tsx,js,jsx,scss}
📄 CodeRabbit inference engine (AGENTS.md)
Use Prettier formatting: single quotes, 2-space indentation, 100-character line width, and trailing commas
Files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/Onboarding/steps.tssrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsxsrc/hooks/useIsMobile.tssrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
src/pages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use Next.js Pages Router; place all route files under src/pages
Files:
src/pages/index.tsx
🧠 Learnings (18)
📓 Common learnings
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-07T08:38:28.343Z
Learning: Applies to **/*.tsx : React: use functional components only; extract reusable logic into custom hooks; apply proper memoization (React.memo/useMemo/useCallback)
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react-functional-components.mdc:0-0
Timestamp: 2025-08-01T08:50:22.602Z
Learning: Applies to src/components/**/*.tsx : Always use React functional components with hooks.
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Extract reusable logic into custom hooks
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Use custom hooks for reusable logic
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/use*.{tsx,jsx} : Keep hooks focused and simple
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-07T08:37:58.213Z
Learning: Applies to src/**/*.tsx : Prefer React functional components for UI implementation
Learnt from: jonybekov
Repo: quran/quran.com-frontend-next PR: 2537
File: src/redux/slices/session.ts:36-42
Timestamp: 2025-10-18T11:22:53.139Z
Learning: In Redux selectors, avoid calling functions that read from external state (cookies, localStorage, etc.) like `isLoggedIn()` from utils/auth/login. Instead, use reactive hooks like `useIsLoggedIn` directly in components and keep selectors focused only on Redux state to ensure proper memoization.
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Implement proper memoization (useMemo, useCallback)
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Avoid nested hooks
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Use functional components over class components
📚 Learning: 2025-10-28T09:59:48.894Z
Learnt from: afifvdin
Repo: quran/quran.com-frontend-next PR: 2557
File: src/components/QuranReader/ReflectionView/ReflectionBodyContainer/ReflectionBody/index.tsx:88-0
Timestamp: 2025-10-28T09:59:48.894Z
Learning: In src/components/QuranReader/ReflectionView/ReflectionBodyContainer/ReflectionBody/index.tsx, the empty `<div className={styles.separatorContainer} />` rendered when `isModal` is true is required for maintaining consistent spacing in modal view and should not be removed.
Applied to files:
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/pages/index.tsx
📚 Learning: 2025-10-18T11:22:53.139Z
Learnt from: jonybekov
Repo: quran/quran.com-frontend-next PR: 2537
File: src/redux/slices/session.ts:36-42
Timestamp: 2025-10-18T11:22:53.139Z
Learning: In Redux selectors, avoid calling functions that read from external state (cookies, localStorage, etc.) like `isLoggedIn()` from utils/auth/login. Instead, use reactive hooks like `useIsLoggedIn` directly in components and keep selectors focused only on Redux state to ensure proper memoization.
Applied to files:
src/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.ts
📚 Learning: 2025-08-01T08:50:54.518Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/use*.{tsx,jsx} : Keep hooks focused and simple
Applied to files:
src/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/hooks/useIsMobile.tssrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
📚 Learning: 2025-10-07T08:38:28.343Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-07T08:38:28.343Z
Learning: Applies to **/*.tsx : React: use functional components only; extract reusable logic into custom hooks; apply proper memoization (React.memo/useMemo/useCallback)
Applied to files:
src/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
📚 Learning: 2025-08-01T08:50:54.518Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Use custom hooks for reusable logic
Applied to files:
src/components/QuranReader/ContextMenu/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
📚 Learning: 2025-08-01T08:50:54.518Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Extract reusable logic into custom hooks
Applied to files:
src/components/QuranReader/ContextMenu/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/Onboarding/OnboardingProvider.tsxsrc/components/Search/SearchInput/index.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
📚 Learning: 2025-10-22T20:42:09.214Z
Learnt from: yousefdergham
Repo: quran/quran.com-frontend-next PR: 2547
File: src/pages/learning-plans/[slug]/lessons/[lessonSlugOrId]/index.tsx:35-59
Timestamp: 2025-10-22T20:42:09.214Z
Learning: Preference for quran.com-frontend-next: keep single-use, page-specific components inline. Example: NotEnrolledMessage in src/pages/learning-plans/[slug]/lessons/[lessonSlugOrId]/index.tsx should remain inline; extract only if reused elsewhere.
Applied to files:
src/components/QuranReader/ContextMenu/index.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.tssrc/pages/index.tsx
📚 Learning: 2025-08-01T08:50:03.171Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/next-js-conventions.mdc:0-0
Timestamp: 2025-08-01T08:50:03.171Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Minimize 'use client' usage: Use 'use client' only for Web API access in small components.
Applied to files:
src/components/QuranReader/ContextMenu/index.tsx
📚 Learning: 2025-10-09T11:21:33.919Z
Learnt from: zonetecde
Repo: quran/quran.com-frontend-next PR: 2523
File: src/components/QuranicCalendar/MyProgress/MonthCard.tsx:48-49
Timestamp: 2025-10-09T11:21:33.919Z
Learning: In the Quran in a Year calendar feature (src/components/QuranicCalendar/MyProgress/MonthCard.tsx), instant scrolling (window.scrollTo({ top: 0 }) without smooth behavior) is preferred over smooth scrolling when selecting a week. This is because instant scrolling provides immediate visual feedback of the verses and date changing, whereas smooth scrolling makes it look like nothing is changing during the animation.
Applied to files:
src/components/QuranicCalendar/MyProgress/index.tsxsrc/components/HomePage/ReadingSection/index.tsxsrc/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsx
📚 Learning: 2025-10-19T10:49:21.536Z
Learnt from: afifvdin
Repo: quran/quran.com-frontend-next PR: 2539
File: src/components/HomePage/ReadingSection/StreakOrGoalCard/index.tsx:50-54
Timestamp: 2025-10-19T10:49:21.536Z
Learning: In src/components/HomePage/ReadingSection/StreakOrGoalCard/index.tsx, the component intentionally uses different analytics event names based on goal state: `homepage_reading_streak_card` when no goal exists and `homepage_reading_goal_card_arrow` when a goal exists. This is by design to track different user interaction contexts.
Applied to files:
src/components/HomePage/ReadingSection/index.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsx
📚 Learning: 2025-08-01T08:50:22.602Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react-functional-components.mdc:0-0
Timestamp: 2025-08-01T08:50:22.602Z
Learning: Applies to src/components/**/*.tsx : Always use React functional components with hooks.
Applied to files:
src/components/HomePage/ReadingSection/index.tsxsrc/components/HomePage/ReadingSection/ChapterCard/index.tsx
📚 Learning: 2025-08-01T08:51:05.924Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/redux-toolkit-best-practices.mdc:0-0
Timestamp: 2025-08-01T08:51:05.924Z
Learning: Applies to src/redux/**/*.ts : Use Redux hooks (useSelector, useDispatch) in components.
Applied to files:
src/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.ts
📚 Learning: 2025-10-25T12:14:44.062Z
Learnt from: yousefdergham
Repo: quran/quran.com-frontend-next PR: 2547
File: src/pages/learning-plans/[slug]/lessons/[lessonSlugOrId]/index.tsx:58-64
Timestamp: 2025-10-25T12:14:44.062Z
Learning: In quran.com-frontend-next, router.query values (like slug) are not considered reactive dependencies by the project's react-hooks/exhaustive-deps rule and don't need to be included in useEffect dependency arrays. Toast functions from useToast() are also stable and don't need to be in deps.
Applied to files:
src/components/QuranReader/SidebarNavigation/SidebarNavigation.tsxsrc/components/QuranReader/ContextMenu/hooks/useContextMenuState.ts
📚 Learning: 2025-10-07T08:37:58.213Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-07T08:37:58.213Z
Learning: Applies to src/**/*.tsx : Prefer React functional components for UI implementation
Applied to files:
src/components/HomePage/ReadingSection/ChapterCard/index.tsx
📚 Learning: 2025-08-01T08:50:54.518Z
Learnt from: CR
Repo: quran/quran.com-frontend-next PR: 0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T08:50:54.518Z
Learning: Applies to **/*.{tsx,jsx} : Use functional components over class components
Applied to files:
src/components/HomePage/ReadingSection/ChapterCard/index.tsx
📚 Learning: 2025-10-19T11:34:07.609Z
Learnt from: afifvdin
Repo: quran/quran.com-frontend-next PR: 2540
File: src/components/Verse/PlainVerseText/index.tsx:4-4
Timestamp: 2025-10-19T11:34:07.609Z
Learning: In src/components/Verse/PlainVerseText/index.tsx, the translation for verse titles should be wired directly to the component using next-translate rather than passed as props from parent components, as this ensures the wording from locales is centralized and only needs to be changed in one place.
Applied to files:
src/components/HomePage/ReadingSection/ChapterCard/index.tsx
📚 Learning: 2025-10-26T10:22:52.381Z
Learnt from: afifvdin
Repo: quran/quran.com-frontend-next PR: 2540
File: src/components/QuranReader/TranslationView/TranslationText/TranslationAndReference.tsx:60-60
Timestamp: 2025-10-26T10:22:52.381Z
Learning: In src/components/QuranReader/TranslationView/TranslationText/TranslationAndReference.tsx, verse references displayed alongside chapter names should use English/Western numerals only, not localized numerals, as per design specifications.
Applied to files:
src/components/HomePage/ReadingSection/ChapterCard/index.tsx
🔇 Additional comments (13)
src/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsx (1)
8-8: LGTM! Proper migration to useIsMobile hook.The migration from
isMobile()function to theuseIsMobilehook is implemented correctly. The hook is called unconditionally at the top level, andisMobileViewis used consistently to determine mobile-specific behavior (closing sidebar after navigation). This prevents SSR/client hydration mismatches.Also applies to: 43-43, 81-81
src/components/HomePage/ReadingSection/ChapterCard/index.tsx (1)
12-12: LGTM! Clean migration to useIsMobile hook.The hook is properly integrated at the component level and used to control the display format of the translated chapter name. The desktop-first approach ensures consistent SSR rendering, avoiding hydration mismatches.
Also applies to: 34-34, 59-59
src/components/QuranicCalendar/MyProgress/index.tsx (1)
15-15: LGTM! Critical hydration fix for calendar layout.The migration to
useIsMobileis especially important here as it controls a major layout difference (CarouselView vs grid). Using the hook ensures consistent initial rendering between server and client, preventing layout shifts.Also applies to: 37-37, 86-86
src/components/Onboarding/OnboardingProvider.tsx (1)
13-13: LGTM! Proper hook integration with correct memoization.The migration includes the important detail of adding
isMobileViewto theuseMemodependency array (line 47), ensuring onboarding steps are recalculated when the mobile view state changes. This follows React best practices for memoization.Also applies to: 43-43, 46-47
src/components/QuranReader/ContextMenu/hooks/useContextMenuState.ts (1)
9-9: LGTM! Hook-based mobile detection in custom hook.The
useIsMobilehook is correctly integrated within this custom hook to control sidebar visibility logic. Using the hook instead of a direct function call ensures reactive updates and prevents hydration mismatches in sidebar behavior.Also applies to: 46-46, 84-84
src/components/Search/SearchInput/index.tsx (1)
15-15: LGTM! Consistent mobile detection for search behavior.The hook integration ensures the search input's mobile drawer behavior is determined reactively and consistently with SSR, preventing hydration issues when the search component initially renders.
Also applies to: 54-54, 98-98
src/components/QuranReader/SidebarNavigation/SidebarNavigation.tsx (1)
18-18: LGTM! Reactive mobile detection for outside-click handler.The hook is properly used to enable/disable the outside-click detector based on mobile view state. This ensures the sidebar's outside-click behavior is consistent with the initial server render, preventing hydration errors.
Also applies to: 43-43, 51-51
src/components/QuranReader/ContextMenu/index.tsx (1)
18-18: LGTM! Hook integration for responsive context menu layout.The
useIsMobilehook is correctly used to derive two computed values (isMobileScrolledViewandisNotMobileOrScrolledView) that control multiple rendering paths in the context menu. The desktop-first approach ensures consistent initial rendering across SSR and client hydration.Also applies to: 28-28, 57-58
src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsx (1)
10-10: LGTM! Clean migration to useIsMobile hook.The migration from
isMobile()function calls to theuseIsMobile()hook is consistent throughout the component. All mobile-specific conditionals now useisMobileView, which will help prevent hydration mismatches by maintaining stable markup between SSR and client-side hydration.Also applies to: 41-41, 66-66, 81-81, 93-93, 104-108
src/pages/index.tsx (1)
22-22: LGTM! Consistent mobile detection migration.The migration to
useIsMobile()hook is correct and aligns with the PR's goal of fixing hydration mismatches. TheisMobileViewis properly used to determine whether to renderMobileHomepageSections.Also applies to: 40-40, 59-61
src/components/HomePage/ReadingSection/index.tsx (1)
16-16: LGTM! Proper migration to hook-based mobile detection.The component correctly migrates to the
useIsMobile()hook, replacing allisMobile()function calls withisMobileView. The mobile-specific layout decisions now use a stable value that won't cause hydration mismatches.Also applies to: 35-35, 78-78, 116-127
src/components/Onboarding/steps.ts (1)
30-33: LGTM! Good design with parameterized mobile detection.The function now accepts
isDeviceMobileas a parameter with a desktop-first default (false), allowing the caller to pass in the mobile state from theuseIsMobile()hook. This approach correctly externalizes the mobile detection logic and maintains consistency with the broader migration pattern.Also applies to: 59-59, 113-116, 178-181, 228-231
src/hooks/useIsMobile.ts (1)
12-18: Let me check if there's conditional rendering/layout changes based on the mobile detection:Based on my verification, the review comment raises a valid and well-reasoned concern, though it remains empirically unverified.
Key findings:
Hook Implementation: The
useIsMobilehook correctly uses a desktop-first default (false) and updates viauseEffectpost-mount, preventing hydration mismatches.Widespread Usage: The hook is used in 24+ locations across layout-critical components (SidebarNavigation, ContextMenu, HomePage, ReadingSection, ChapterCard), where state changes could trigger visible reflows.
CLS Risk is Real: Industry patterns document this trade-off—adopting mobile-first or deferring rendering risks FOUC or CLS when guesses are wrong; rendering both variations causes shifts when one is removed.
Unverified Empirically: The provided script was instructional only, not actual test results. CLS impacts SEO as Google uses it to evaluate user experience and page rankings.
The review comment is sound but requires manual verification on actual mobile devices and throttled connections (Slow 3G) to measure whether the current CLS trade-off aligns with your performance goals. Test using Lighthouse and Chrome DevTools' Performance tab.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request refactors the mobile detection logic by replacing direct calls to the isMobile() utility function with a React hook useIsMobile(). This ensures proper SSR/CSR hydration alignment and reactive updates when the viewport is resized.
- Introduces
useIsMobilehook that manages mobile detection state reactively with window resize listeners - Replaces all instances of
isMobile()function calls with theuseIsMobile()hook across components - Updates the onboarding system to accept mobile state as a parameter instead of checking it internally
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/hooks/useIsMobile.ts | Simplified hook to use false as initial state for consistent SSR/CSR rendering |
| src/pages/index.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/Search/SearchInput/index.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/QuranicCalendar/WeeklyVerses/ActionButtons.tsx | Replaced isMobile() call with useIsMobile() hook and extracted label logic |
| src/components/QuranicCalendar/QuranicCalendarHero/ActionButtons.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/QuranicCalendar/MyProgress/index.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/QuranReader/SidebarNavigation/SidebarNavigationSelections.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/QuranReader/SidebarNavigation/SidebarNavigation.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/QuranReader/ContextMenu/index.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/QuranReader/ContextMenu/hooks/useContextMenuState.ts | Replaced isMobile() call with useIsMobile() hook |
| src/components/Onboarding/steps.ts | Removed internal isMobile() call and accepts mobile state as parameter |
| src/components/Onboarding/OnboardingProvider.tsx | Calls useIsMobile() and passes result to checklistIndexToOnboardingSteps |
| src/components/HomePage/ReadingSection/index.tsx | Replaced isMobile() call with useIsMobile() hook |
| src/components/HomePage/ReadingSection/ChapterCard/index.tsx | Replaced isMobile() call with useIsMobile() hook |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const markAsCompletedLabel = isMobileView | ||
| ? '\u2713' | ||
| : !isCompleted | ||
| ? t('mark-as-completed') | ||
| : t('week-completed'); |
Copilot
AI
Nov 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The ternary operator chain for markAsCompletedLabel is nested and harder to read. Consider refactoring to use a simpler if-else structure or extract to a separate function for better clarity.
|
replaced with #2568 |
…mprove website's performance
Summary
Refactored all the mobile-only conditionals to use our useIsMobile hook with a desktop-first default, so we don’t flip markup between SSR and hydration.
We keep the layout stable during hydration, so CLS drops, and we skip extra client re-renders, which helps TBT (both boost lighthouse score).
Replaced the checkmark emoji with its Unicode escape
\u2713Type of change
Test plan
I've checked with MCP Playwright that the changes took effect on the site.
Checklist
Summary by CodeRabbit