-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fix: skip Balancer script if global one is already created #86
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -71,16 +71,16 @@ const relayout: RelayoutFn = (id, ratio, wrapper) => { | |||
// the function. | |||
if (!wrapper['__wrap_o']) { | |||
if (typeof ResizeObserver !== 'undefined') { | |||
;(wrapper['__wrap_o'] = new ResizeObserver(() => { | |||
; (wrapper['__wrap_o'] = new ResizeObserver(() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (injected) { | ||
return null | ||
} |
There was a problem hiding this comment.
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)
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:
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