Skip to content

Conversation

@mixeden
Copy link

@mixeden mixeden commented Nov 13, 2023

Hi, this is a great library, thanks for developing it :)

The problem I stumbled upon (and am fixing in this PR) is as follows.

There are two ways to use this library:

  • You use Balancer without a Provider. In this case, each Balancer has its own script that calculates the layout and does other things.
  • You use a Balancer with a Provider. In this case, they all have one common script that calculates the layout.

Now imagine you have a strict CSP and you need to pass a nonce. You pass the nonce to the Provider and do not pass it to Balancers.

This lib creates an empty script tag for each Balancer in case of global script injection. Since you don't pass the nonce to each Balancer, the CSP doesn't work (as there still is a script for each Balancer).

I fixed this by just not returning any script tag in case of global script injection.
Seems that this PR is associated with #78, but I'm not sure

@vercel
Copy link

vercel bot commented Nov 13, 2023

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

Name Status Preview Comments Updated (UTC)
react-wrap-balancer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2023 6:57pm

if (!wrapper['__wrap_o']) {
if (typeof ResizeObserver !== 'undefined') {
;(wrapper['__wrap_o'] = new ResizeObserver(() => {
; (wrapper['__wrap_o'] = new ResizeObserver(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the miscellaneous changes in this PR? Like this whitespace.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +99 to +101
if (injected) {
return null
}
Copy link
Collaborator

@pacocoursey pacocoursey Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no sorry this doesn't work at all… it's required to inject the script so that each instance of <Balancer /> is correctly balanced on SSR. Otherwise, you end up with this layout shift (on browsers that do not support text-wrap: balance, i.e. Safari)

ILUzvkAZ.mp4

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