react-wrap-balancer icon indicating copy to clipboard operation
react-wrap-balancer copied to clipboard

Convert Balancer and Provider to server components

Open awndrw opened this issue 2 years ago • 4 comments

Fixes #23 A large part of react-wrap-balancer can run on the server. I've moved all code that strictly needs to run on the client to client.ts. This allowed both Balancer and Provider to be converted to server components. There are a few significant changes:

  • RelayoutScript is also rendered on the server and uses a local variable to determine if the relayout function has already been rendered at a global level
  • React Context was removed entirely and the Provider component only renders the relayout script
  • All code that must run on the client was moved to ClientBalancer (effects, relayout) and the rest stayed in Balancer to be rendered on the server

awndrw avatar Jan 23 '23 00:01 awndrw

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

Name Status Preview Comments Updated
react-wrap-balancer ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 23, 2023 at 0:19AM (UTC)

vercel[bot] avatar Jan 23 '23 00:01 vercel[bot]

Should Balancer continue to be a client component so it can continue to be used in other client components (see this doc)? I chose to make it a server component so we could remove React Context and render the relayout script and provider on the server, but there might be a better way of doing this.

awndrw avatar Jan 23 '23 00:01 awndrw

Any progress on this? Will be really helpful

CodeWithShreyans avatar May 18 '23 16:05 CodeWithShreyans

Cannot set a CSP nonce the server script, that should probably be added.

HofmannZ avatar Jan 15 '24 10:01 HofmannZ