Wildhoney / ReactShadow

:beginner: Utilise Shadow DOM in React with all the benefits of style encapsulation.
https://react-shadow.herokuapp.com/
MIT License
1.29k stars 80 forks source link

Can useLayoutEffect() be used instead of useEffect() to make rendering synchronous? #113

Closed gregjacobs closed 1 year ago

gregjacobs commented 3 years ago

In the file https://github.com/Wildhoney/ReactShadow/blob/master/src/core/index.js#L28, the useEffect() hook is used which makes the rendering of the shadow dom element asynchronous. Using useLayoutEffect() instead would make the rendering synchronous.

useEffect() causes a delay in rendering shadow dom elements compared to non-shadow elements. It also affects unit tests where we now need to wait a clock tick until the shadow dom element appears, causing difficult-to-debug tests when we miss this.

Seems like a simple fix?

Wildhoney commented 3 years ago

Sure — sounds good @gregjacobs Would you like to open a PR and I can get it merged?

TheSharpieOne commented 1 year ago

I believe this can be closed with #145

Wildhoney commented 1 year ago

Thanks for the heads up @TheSharpieOne