Skip to content

Issue with Next.js ^14.0.2 in DEV environment #247

@andre-lergier

Description

@andre-lergier

Since updating Next.js from v14.0.1 to v14.0.2 and v14.0.3 the useResizeDetector() hook is no more working in the local development environment.

On the initial render the hook always returns undefined.
If I edit the component after it's first render and the dev server triggers a rerender, the hook returns the correct values.

This can be simulated with the following code:

export function NavigationMenuBar() {
  const { height: menuBarHeight, ref: menuBarRef } = useResizeDetector();

  useEffect(() => {
    console.log('menuBarHeight', menuBarHeight);

    document.documentElement.style.setProperty(
      '--navigation-menu-bar-height',
      `${Math.floor(menuBarHeight || 0)}px`,
    );
  }, [menuBarHeight]);

  return (
      <nav ref={menuBarRef}>Nav</nav>
  );
}

In the production build or with Next.js v14.0.1 everything is working as expected.

I know that this might be a Next.js issue, but I currently don't understand what could cause this problem - so it's difficult to me to open an issue there.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions