Skip to content

⚡ Bolt: Optimize Card components to avoid re-renders on URL change#78

Open
nkissick-del wants to merge 1 commit intomainfrom
bolt/refactor-navigation-hooks-13386913763710375106
Open

⚡ Bolt: Optimize Card components to avoid re-renders on URL change#78
nkissick-del wants to merge 1 commit intomainfrom
bolt/refactor-navigation-hooks-13386913763710375106

Conversation

@nkissick-del
Copy link
Copy Markdown
Owner

⚡ Bolt: Refactor Card components to use stable navigation handlers

💡 What:
Replaced useNavigatePage with direct useNavigate and useCallback in ChatCard, SearchCard, and AgentCard.

🎯 Why:
useNavigatePage uses useSearchParams internally. This meant that any change to the URL query parameters (which happens frequently in this app for search, filtering, pagination) triggered a re-render of EVERY card in the list, even if the card data hadn't changed. This defeated the purpose of React.memo on these components.
Additionally, the navigation function returned by useNavigatePage was a new function instance on every render (due to the way it was called), causing the child HomeCard to re-render even if ChatCard props were stable (if ChatCard re-rendered for any reason).

📊 Impact:

  • Prevents unnecessary re-renders of all card components when URL parameters change.
  • Ensures onClick handlers are stable references.

microscope Measurement:

  • Verify that ChatCard, SearchCard, AgentCard no longer import useNavigatePage.
  • Verify that navigation (clicking cards) still works correctly.
  • (Code review) Confirm React.memo is now effective because props and hooks are stable.

PR created automatically by Jules for task 13386913763710375106 started by @nkissick-del

Removes dependency on `useNavigatePage` in `ChatCard`, `SearchCard`, and `AgentCard`.
This hook implicitly subscribes to `useSearchParams`, causing these components (and the entire list) to re-render whenever URL query parameters change (e.g. during filtering or pagination).
By using `useNavigate` directly with `useCallback`, we ensure:
1. Components only re-render when their direct props change (preserving `React.memo` benefits).
2. `onClick` handlers passed to `HomeCard` are stable, preventing unnecessary child re-renders.

Impact:
- Reduces re-renders of list items during navigation/search parameter updates.
- Improves performance of large lists.

Co-authored-by: nkissick-del <236767245+nkissick-del@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

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

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