facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
225.07k stars 45.89k forks source link

custom use directives + using closure serializer #28619

Open harrysolovay opened 3 months ago

harrysolovay commented 3 months ago

I'd like guidance around reusing the (canary) compiler's closure serializer. It seems the "use [env]" directive approach could work well for a wide range of multi-env use cases. I'm not sure if the React team's intention is to make this pluggable / if there's a good approach to patching it today... but any guidance would be greatly appreciated.

For example, how might we implement a "use worker" directive?

worker.ts

"use worker"

export function computeTheThing(): Promise<string> {
  // ...
  return result
}

MyPage.tsx

import { computeTheThing } from "./worker.ts"

export default function MyPage() {
  return (
    <button onClick={() => computeTheThing().then((v) => console.log(v))}>
      Click me!
    </button>
  )
}

Ideally, we could associate the new "use worker" directive with a transform function. This directive could then be used similarly to "use server".

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

harrysolovay commented 2 weeks ago

bump