Skip to content
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

[Bug] there is an obvious flicker when the defaultSizes contains zero on first render #537

Closed
percy507 opened this issue Jan 29, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@percy507
Copy link
Contributor

See the gif, the defaultSizes is [0, 10000]. I refresh page three times. The flicker occurs twice.

2023-01-29 16 28 05

@percy507
Copy link
Contributor Author

Ahhh, I notice there is a PR (#526) which can solve this problem.

@johnwalley
Copy link
Owner

Hi @percy507. Thanks for submitting this issue. I'll get onto #526 and hopefully that will resolve this.

@johnwalley
Copy link
Owner

#526 has been merged and released as v1.18.0. Let me know if it helps 👍

@johnwalley johnwalley self-assigned this Feb 2, 2023
@johnwalley johnwalley added the bug Something isn't working label Feb 2, 2023
@percy507
Copy link
Contributor Author

percy507 commented Feb 3, 2023

Hi @johnwalley,

See the gif, the defaultSizes is [0, 10000]. I refresh page three times. The flicker occurs twice.

Well, after some test, the #526 can resolve the problem what I found in storybook.

But unfortunately, the same problem happens in my personal project. I made a demo, it can reproduce the flicker. https://codesandbox.io/s/thirsty-wind-bzqg9h?file=/src/App.tsx

After some test and debug, I found some unwanted behaviors.

  • After initializing the Allotment component, the onChange method is called which is not triggered manually.
  • When the visible of Pane is false, the init size of the pane should be 0 before it mounted. But during my debug, I found it's size first init as its minSize, then cause the visible is false, re-layout to the right size. (I guess this is why the flicker occurs)

@johnwalley
Copy link
Owner

Thanks for the fast, detailed feedback. I'll try to tackle this soon.

@percy507
Copy link
Contributor Author

percy507 commented Sep 22, 2023

After initializing the Allotment component, the onChange method is called which is not triggered manually.

Now we can use onDragEnd instead of onChange.

When the visible of Pane is false, the init size of the pane should be 0 before it mounted. But during my debug, I found it's size first init as its minSize, then cause the visible is false, re-layout to the right size. (I guess this is why the flicker occurs)

For this one, I delete the below commented code in this place. Then everything works fine.

I guess the flicker (layout shift) happens because the gap time is a bit long between execute code of update views and first execute setDimensionsInitialized(true).

useResizeObserver({
  ref: containerRef,
  onResize: ({ width, height }) => {
    if (width && height) {
      splitViewRef.current?.layout(vertical ? height : width);
      layoutService.current.setSize(vertical ? height : width);
      // setDimensionsInitialized(true);
    }
  },
});

useIsomorphicLayoutEffect(() => {
  // if (!dimensionsInitialized) {
    // const { height, width } = containerRef.current.getBoundingClientRect();
    // splitViewRef.current?.layout(vertical ? height : width);
    // layoutService.current.setSize(vertical ? height : width);
    setDimensionsInitialized(true);
  // }
}, [
  // dimensionsInitialized, 
  // vertical
]);

percy507 added a commit to z-note/allotment that referenced this issue Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants