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

Megamenu: popup disappears when component undergoes a re-render while expanded #6459

Closed
peconomou929 opened this issue Apr 24, 2024 · 4 comments
Labels
Status: Needs Reproducer Issue needs a runnable reproducer

Comments

@peconomou929
Copy link
Contributor

Describe the bug

If one of the menus in a megamenu is expanded while the megamenu undergoes a re-render, then

  1. internally, the state is still expanded, but
  2. visually, the menu popup disappears

This leads to some unexpected behavior.

Reproducer

No response

PrimeReact version

10.6.3

React version

17.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

import "primereact/resources/themes/lara-light-cyan/theme.css";
import { MegaMenu } from 'primereact/megamenu';
import { useEffect, useState } from "react";

export default function App() {
  const [currentTime, setCurrentTime] = useState(0)

  const items = [
    {
      label: 'Furniture',
      items: [
        [
          {
            label: 'Living Room',
            items: [
              { label: 'Accessories' },
              { label: 'Armchair' },
              { label: 'Coffee Table' },
              { label: 'Couch' },
              { label: 'TV Stand' }]
          }
        ],
      ]
    },
    {
      label: 'Furniture',
      items: [
        [
          {
            label: 'Living Room',
            items: [
              { label: 'Accessories' },
              { label: 'Armchair' },
              { label: 'Coffee Table' },
              { label: 'Couch' },
              { label: 'TV Stand' }]
          }
        ],
      ]
    },
  ];

  useEffect(() => {
    const intervalId = setInterval(() => {
      setCurrentTime(Date.now())
    }, 3000)
    return () => {
      clearInterval(intervalId);
    }
  }, [])

  return (
    <div className="card">
      <MegaMenu model={items} />
    </div>
  )
}

Expected behavior

Menu popup should not disappear when megamenu undergoes a re-render.

@peconomou929 peconomou929 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 24, 2024
@peconomou929 peconomou929 changed the title Megamenu: "expanded" state not properly managed through re-renders Megamenu: popup disappears when component undergoes a re-render while expanded Apr 24, 2024
@Rekl0w
Copy link
Contributor

Rekl0w commented Apr 24, 2024

Interval makes the bug, try remove it. It works.

@melloware melloware added Status: Needs Reproducer Issue needs a runnable reproducer and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Apr 24, 2024
@peconomou929
Copy link
Contributor Author

Interval makes the bug, try remove it. It works.

The interval was intentional. I'm trying to show that there is a problem when the megamenu re-renders. Therefore, I set up my component to re-render every 3 seconds.

This may seem like an artificial scenario, but it still represents a more general issue. In my application, the rendering of my megamenu depends on data which is fetched asynchronously, and which can be fetched at different points in time while the app is running. This results in a re-render, and it is weird behavior that the megamenu simply disappears when this data is fetched.

@melloware
Copy link
Member

We should add a real StackBlitz reproducer to this ticket.

@Rekl0w
Copy link
Contributor

Rekl0w commented Apr 24, 2024

You can fetch demo data's from primeReact's. This may represent the situation.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Reproducer Issue needs a runnable reproducer
Projects
None yet
Development

No branches or pull requests

3 participants