captivationsoftware / react-sticky

<Sticky /> component for awesome React apps
MIT License
2.64k stars 386 forks source link

Add onLoad function #253

Closed ksgy closed 6 years ago

ksgy commented 6 years ago

Add onLoad function to container to make sure translateZ is applied when the component loads, otherwise can cause rendering issues if hardware acceleration is enabled.

vcarl commented 6 years ago

Hey @ksgy thanks for the contribution! I'm not exactly sure how this change helps make sure translateZ is enabled, could you provide some more details about the problem you were seeing?

ksgy commented 6 years ago

Hey @vcarl, Sure! When a <Container> loads and hw acceleration is disabled the default style for the element doesn't contain the translateZ. But when user starts scrolling or resizing, the handler is called, checks if hw accel enabled. If enabled, applies translateZ on the <Sticky> element: https://github.com/captivationsoftware/react-sticky/blob/master/src/Sticky.js#L99

If the <Sticky> element has a position: fixed element inside, could be a rendering issue until the user starts scrolling or resizes the browser. Applying the translateZ style when the <Container> loads can avoid these rendering issues. I think it should be there anyway by default (if hw acceleration is enabled) to avoid different styles between the "loaded state" and state after a window event.

vcarl commented 6 years ago

So the first render pass doesn't include translateZ, and that can cause rendering errors? Could you make a demo of the problem in CodeSandbox? I'm wary of fixing problems without seeing it in action.

vcarl commented 6 years ago

Closing this, but happy to reopen if you can put together a demo!