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

🚀 Smart Render: A friendlier way to improve React’s performance & reduce bundle size (tree sharking built in) 🎯 #32360

Open
nguyenvanhieu1996 opened this issue Feb 12, 2025 · 2 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@nguyenvanhieu1996
Copy link

React version: Affects all versions, but particularly relevant for React 19+.

Steps To Reproduce

  1. Create a simple React component using useState.
  2. Update the state and observe that the entire component re-renders, even though only part of the UI actually changes.

Code example:

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  console.log("Component re-rendered");

  return (
    <div>
      <p>{count}</p>
      <button onClick={() => setCount(count + 1)}>Increase</button>
    </div>
  );
}


export default Counter;

👉 Problem: Every time count updates, the entire Counter component re-renders, even though only <p>{count}</p> needs to change.

The current behavior

  1. React re-renders the entire component when state changes, even if only a small part of the UI is affected.
  2. Developers must manually optimize performance using memo(), useMemo(), and useCallback().
  3. This leads to larger bundle sizes and harder-to-maintain code.

The expected behavior

🚀 Only <p>{count}</p> updates, instead of re-rendering the whole component.
📦 No need for memo, useMemo, or useCallback, making React simpler to use.
⚡ Improved performance and smaller bundle size without extra manual optimizations.
✅ Use a single useState or useRef to keep things simple but effective.

Would love to hear thoughts from the React team and the community! 🚀🔥

@nguyenvanhieu1996 nguyenvanhieu1996 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Feb 12, 2025
@markerikson
Copy link
Contributor

There's two answers here.

The first is that React's entire rendering model is at a per-component level of granularity. You can't render less than a component at once.

That said, the other answer here is the React Compiler, which does the automatic transformation of logic within a component to ensure that only the pieces of child output that rely on changed data will actually be updated:

@nguyenvanhieu1996 nguyenvanhieu1996 changed the title 🚀 Smart Render: A friendlier way to improve React’s performance & reduce bundle size 🎯 🚀 Smart Render: A friendlier way to improve React’s performance & reduce bundle size (built in) 🎯 Feb 15, 2025
@nguyenvanhieu1996
Copy link
Author

Thanks @markerikson ! Hope that React Compiler will be built into React and tools will automatically analyze components and libraries deeply to generate the best possible output for performance and bundle size. Every application needs this by default! 🚀✨

@nguyenvanhieu1996 nguyenvanhieu1996 changed the title 🚀 Smart Render: A friendlier way to improve React’s performance & reduce bundle size (built in) 🎯 🚀 Smart Render: A friendlier way to improve React’s performance & reduce bundle size (tree sharking built in) 🎯 Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants