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

Add support for React Compiler #853

Closed
wants to merge 2 commits into from
Closed

Add support for React Compiler #853

wants to merge 2 commits into from

Conversation

L-Qun
Copy link

@L-Qun L-Qun commented Aug 28, 2024

Now the users can enable the react compiler by adding a new field reactCompiler: true in the waku.config.ts file.

Let's take a look at the effects before and after enabling react compiler optimization.

const Child = () => {
  console.log("render");
  return <div>Child</div>;
};

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

  const handleIncrement = () => setCount((c) => c + 1);

  return (
    <section className="border-blue-400 -mx-4 mt-4 rounded border border-dashed p-4">
      <div>Count: {count}</div>
      <button
        onClick={handleIncrement}
        className="rounded-sm bg-black px-2 py-0.5 text-sm text-white"
      >
        Increment
      </button>
      <Child />
    </section>
  );
};

When the Child component re-renders, it will console "render".

before enabling the react compiler:
20240828231420_rec_

after enabling the react compiler:
20240828230748_rec_

Copy link

vercel bot commented Aug 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Aug 28, 2024 3:27pm

Copy link

codesandbox-ci bot commented Aug 28, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@L-Qun L-Qun changed the title feat: enable experimental react compiler optimization Add support for React Compiler Aug 28, 2024
@L-Qun
Copy link
Author

L-Qun commented Aug 28, 2024

Accordingly, update the React documentation. reactjs/react.dev#7133

@dai-shi
Copy link
Owner

dai-shi commented Aug 28, 2024

We don't do this at least for now.
You can create vite.config.ts instead. See: https://x.com/dai_shi/status/1794171384761094385

Now, may I ask you to add ./docs/guides/react-compiler.mdx for the instruction? That would be helpful.

@L-Qun
Copy link
Author

L-Qun commented Aug 29, 2024

#857

@dai-shi
Copy link
Owner

dai-shi commented Aug 29, 2024

Now, I wonder how you made it work without "annotation". 🤔

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.

2 participants