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

Dynamically adding panels in child component throws Previous layout not found for panel index #372

Closed
davidfant opened this issue Jul 11, 2024 · 5 comments · Fixed by #375
Labels
help wanted Extra attention is needed

Comments

@davidfant
Copy link

I'm running into problems with defining panels within a child component and dynamically adding children. When trying to resize, the following error is console logged and the panel sizes don't change:
Previous layout not found for panel index

Example:

const ChildWithDynamicPanels = () => {
  const [extra, setExtra] = useState(2);
  return (
    <>
      {Array.from({ length: extra }).map((_, i) => (
        <Fragment key={i}>
          <PanelResizeHandle />
          <Panel id={`extra-${i}`} order={i}>
            <div style={{ width: "100%", background: "red" }}>{i}</div>
          </Panel>
        </Fragment>
      ))}
      <button onClick={() => setExtra((e) => e + 1)}>Add</button>
    </>
  );
};

export function Parent({
  panels,
  children,
}: ResizablePanelsProps) {
  return (
    <PanelGroup      direction="horizontal"    >
      <ChildWithDynamicPanels />
    </PanelGroup>
  );
}

Behavior I'm seeing in the reproable example above:

  1. Dragging the first two children works because they were defined on the initial render
  2. When adding a new child, the first drag creates lots of errors and resets all sizes to be equal. Subsequent resizing works.
  3. If everything in ChildWithDynamicPanels is moved into Parent, then there's no error. However, when adding a new panel, the resizing is reset and each panel gets the same size (unlike point 2 where the reset doesn't happen until dragging is attempted)

The reason I need this is because I'm using NextJS App Router, where depending on the current route additional panels might be rendered based on the route. This means that these Panels will be within a separate page.tsx file and thus not rendered as a direct child to the panel group. If there's a better way to do this for the NextJS App Router scenario, please let me know!

@bvaughn
Copy link
Owner

bvaughn commented Jul 12, 2024

@davidfant Can you please share a runnable repro of the problem you're reporting?

The code snippet you shared doesn't really make sense. (The props passed to Parent aren't even use.) But more than that, it's better if I can just click a link and start looking at the problem rather than spending time trying to re-create it.

@davidfant
Copy link
Author

@bvaughn
Copy link
Owner

bvaughn commented Jul 15, 2024

Thanks. I can see the error now. Made it into a Sandbox here and recorded a Replay here.

@bvaughn bvaughn added the help wanted Extra attention is needed label Jul 18, 2024
@bvaughn
Copy link
Owner

bvaughn commented Jul 21, 2024

Okay I think I see the problem here.

@bvaughn
Copy link
Owner

bvaughn commented Jul 21, 2024

Fix published in version 2.0.22


❤️ → ☕ givebrian.coffee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants