Skip to content

⚡ Bolt: Optimize ScheduleContainer Rendering#43

Open
anyulled wants to merge 4 commits into
mainfrom
bolt-optimize-schedule-container-6933441994853421305
Open

⚡ Bolt: Optimize ScheduleContainer Rendering#43
anyulled wants to merge 4 commits into
mainfrom
bolt-optimize-schedule-container-6933441994853421305

Conversation

@anyulled
Copy link
Copy Markdown
Owner

⚡ Bolt: Optimize ScheduleContainer Rendering

💡 What:
Implemented conditional rendering for the ScheduleContainer component using a new useMediaQuery hook. Instead of rendering both desktop (ScheduleGrid) and mobile (ScheduleMobile) views and hiding one with CSS, the application now renders only the relevant component for the current viewport.

🎯 Why:
Rendering both views doubled the number of DOM nodes and React components for the schedule, which is a heavy part of the application (potentially hundreds of session cards). This wasted memory and CPU during reconciliation, especially on mobile devices.

📊 Impact:

  • Reduces the number of DOM nodes for the schedule section by approximately 50%.
  • Reduces memory usage and improves responsiveness on mobile devices.
  • No visual change or layout shift (initial render matches server HTML).

🔬 Measurement:
Verified with unit tests in __tests__/components/schedule/ScheduleContainer.test.tsx that confirm:

  1. Both components are rendered initially (for SSR/Hydration matching).
  2. Only the desktop component is rendered when the media query does not match.
  3. Only the mobile component is rendered when the media query matches.

PR created automatically by Jules for task 6933441994853421305 started by @anyulled

- Implements `useMediaQuery` hook to detect viewport size.
- Updates `ScheduleContainer` to conditionally render `ScheduleGrid` (desktop) or `ScheduleMobile` (mobile) based on viewport size.
- Prevents rendering both components and hiding one with CSS, reducing DOM nodes and memory usage.
- Maintains SSR and hydration compatibility by rendering both (hidden) initially.
- Adds `__tests__/components/schedule/ScheduleContainer.test.tsx` to verify the logic.

Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
devbcn Ready Ready Preview, Comment Feb 14, 2026 9:53am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 14, 2026

Warning

Rate limit exceeded

@anyulled has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bolt-optimize-schedule-container-6933441994853421305

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @anyulled, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant performance optimization for the ScheduleContainer component by refactoring its rendering logic. Instead of rendering both desktop and mobile versions and hiding one with CSS, the component now uses a new useMediaQuery hook to conditionally render only the appropriate view. This change aims to reduce DOM node count, memory usage, and CPU overhead, particularly on mobile devices, thereby improving overall application responsiveness.

Highlights

  • Conditional Rendering: Implemented conditional rendering for the ScheduleContainer component, dynamically showing either the desktop (ScheduleGrid) or mobile (ScheduleMobile) view based on viewport size.
  • Performance Optimization: Eliminated rendering both desktop and mobile views simultaneously, significantly reducing DOM nodes and React component count, especially beneficial for mobile devices.
  • New useMediaQuery Hook: Introduced a custom useMediaQuery React hook to efficiently detect media query matches, ensuring proper Server-Side Rendering (SSR) and hydration behavior.
  • Improved Resource Usage: Reduced memory consumption and CPU load during React reconciliation, leading to better responsiveness without visual changes.
Changelog
  • tests/components/schedule/ScheduleContainer.test.tsx
    • Added new test file for ScheduleContainer.
    • Implemented tests to verify initial SSR/hydration rendering of both desktop and mobile components.
    • Added tests to confirm only ScheduleGrid renders on desktop after hydration.
    • Added tests to confirm only ScheduleMobile renders on mobile after hydration.
  • components/schedule/ScheduleContainer.tsx
    • Imported the new useMediaQuery hook.
    • Integrated useMediaQuery to determine the isMobile state.
    • Modified rendering logic to conditionally display ScheduleGrid or ScheduleMobile based on isMobile state, with a special condition to render both during SSR/hydration.
  • hooks/useMediaQuery.ts
    • Added a new custom hook file.
    • Created a useMediaQuery hook that returns boolean | null to handle SSR and client-side media query matching.
Activity
  • PR created automatically by Jules for task 6933441994853421305, initiated by @anyulled.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant performance optimization by conditionally rendering the desktop and mobile schedule views instead of rendering both and hiding one with CSS. The new useMediaQuery hook is a great addition for handling responsive logic, and the new tests properly cover the different rendering scenarios. My feedback includes a few suggestions to enhance the code's clarity and maintainability.

export default function ScheduleContainer({ initialSchedule, year }: ScheduleContainerProps) {
const { savedSessionIds } = useScheduleContext();
const [showSavedOnly, setShowSavedOnly] = useState(false);
const isMobile = useMediaQuery("(max-width: 991px)");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The media query string (max-width: 991px) is hardcoded. This is considered a "magic string" and can make maintenance harder. If this breakpoint is used elsewhere or needs to be updated, it would have to be changed in multiple places. It's a best practice to define such values as constants in a shared theme or constants file and reference it here, for example: const isMobile = useMediaQuery(breakpoints.lg);.

Comment on lines +58 to +69
{(isMobile === null || isMobile === false) && (
<div className="d-none d-lg-block">
<ScheduleGrid schedule={filteredSchedule} year={year} />
</div>
)}

{/* Mobile View */}
{(isMobile === null || isMobile === true) && (
<div className="d-lg-none">
<ScheduleMobile schedule={filteredSchedule} year={year} />
</div>
)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The conditional rendering logic is correct, but it can be simplified for better readability. The expressions isMobile === null || isMobile === false and isMobile === null || isMobile === true can be made more concise by checking for the opposite case, which also correctly handles the null state during server-side rendering.

      {/* Desktop View */}
      {isMobile !== true && (
        <div className="d-none d-lg-block">
          <ScheduleGrid schedule={filteredSchedule} year={year} />
        </div>
      )}

      {/* Mobile View */}
      {isMobile !== false && (
        <div className="d-lg-none">
          <ScheduleMobile schedule={filteredSchedule} year={year} />
        </div>
      )}

Comment thread hooks/useMediaQuery.ts
Comment on lines +13 to +34
useEffect(() => {
const media = window.matchMedia(query);
if (media.matches !== matches) {
setMatches(media.matches);
}
const listener = (e: MediaQueryListEvent) => setMatches(e.matches);

// Support for older browsers and modern ones
if (media.addEventListener) {
media.addEventListener("change", listener);
} else {
media.addListener(listener);
}
return () => {
if (media.removeEventListener) {
media.removeEventListener("change", listener);
} else {
media.removeListener(listener);
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [query]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The useEffect hook can be simplified to improve readability and remove the need for eslint-disable-next-line. You can set the initial state directly on the client-side render. React is smart enough to bail out of a re-render if the state value doesn't change, so there's no performance penalty. This change makes the hook's logic clearer and aligns better with standard hook patterns.

  useEffect(() => {
    const media = window.matchMedia(query);

    // Set the initial value on the client.
    setMatches(media.matches);

    const listener = (e: MediaQueryListEvent) => setMatches(e.matches);

    // Support for older browsers and modern ones
    if (media.addEventListener) {
      media.addEventListener("change", listener);
    } else {
      media.addListener(listener);
    }

    return () => {
      if (media.removeEventListener) {
        media.removeEventListener("change", listener);
      } else {
        media.removeListener(listener);
      }
    };
  }, [query]);

…ting

- Implements `useMediaQuery` hook to conditionally render `ScheduleGrid` (desktop) or `ScheduleMobile` (mobile) components.
- Significantly reduces DOM nodes and memory usage by unmounting the hidden view instead of using CSS `display: none`.
- Maintains SSR compatibility by rendering both components initially (hidden).
- Fixes formatting issues in `__tests__/components/schedule/ScheduleContainer.test.tsx`, `components/schedule/ScheduleContainer.tsx`, and `stylelint.config.mjs` to resolve CI lint failure.
- Verified with unit tests (`npm test __tests__/components/schedule/ScheduleContainer.test.tsx`) and lint checks (`npm run lint`).

Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com>
- Implements `useMediaQuery` hook to conditionally render `ScheduleGrid` (desktop) or `ScheduleMobile` (mobile) components.
- Significantly reduces DOM nodes and memory usage by unmounting the hidden view instead of using CSS `display: none`.
- Maintains SSR compatibility by rendering both components initially (hidden).
- Fixes formatting issues in `__tests__/components/schedule/ScheduleContainer.test.tsx` and `components/schedule/ScheduleContainer.tsx`.
- Verified with unit tests (`npm test __tests__/components/schedule/ScheduleContainer.test.tsx`) and lint checks (`npm run lint`).
- Note: Unrelated Cypress failure on home page ignored as changes are isolated to Schedule component.

Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com>
…ting

- Implements `useMediaQuery` hook to conditionally render `ScheduleGrid` (desktop) or `ScheduleMobile` (mobile) components.
- Significantly reduces DOM nodes and memory usage by unmounting the hidden view instead of using CSS `display: none`.
- Maintains SSR compatibility by rendering both components initially (hidden).
- Fixes formatting issues in `__tests__/components/schedule/ScheduleContainer.test.tsx` and `components/schedule/ScheduleContainer.tsx`.
- Verified with unit tests (`npm test __tests__/components/schedule/ScheduleContainer.test.tsx`) and lint checks (`npm run lint`).
- Note: Unrelated Cypress failure on home page ignored as changes are isolated to Schedule component.

Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com>
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