Skip to content

Conversation

@DarkGenius
Copy link
Contributor

Summary

Fixed TypeError: useLayoutEffect is not a function error that occurs when @gravity-ui/uikit is used with Next.js optimizePackageImports option.

Problem

Error found when updating packages in gravity-ui/landing (PR).

screenshot

When Next.js is configured with:

experimental: {
  optimizePackageImports: ['@gravity-ui/uikit'],
}

the barrel imports (import { useLayoutEffect } from '../..') in hooks are not correctly resolved, causing useLayoutEffect to be undefined at runtime.

This breaks components like DropdownMenu, Select, and others that use useListNavigation internally.

@gravity-ui
Copy link
Contributor

gravity-ui bot commented Jan 17, 2026

Preview is ready.

@DarkGenius DarkGenius requested a review from imsitnikov January 17, 2026 13:08
@gravity-ui
Copy link
Contributor

gravity-ui bot commented Jan 17, 2026

🎭 Component Tests Report is ready.

Copy link
Collaborator

@ValeraS ValeraS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need to use experimental.optimizePackageImports for @gravity/uikit? I believe the tree-shaking problem has been resolved (#2324) and this option is no longer needed. Could you check this, please?

@@ -1,7 +1,7 @@
import * as React from 'react';

import {useLayoutEffect} from '../..';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is only with useListNavigation, because this import creates circular dependencies, and the other imports work fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I've removed the changes in other files.

@DarkGenius DarkGenius force-pushed the fix/fix-import-useLayoutEffect branch from b39b6e5 to c7648c4 Compare January 17, 2026 15:02
@DarkGenius
Copy link
Contributor Author

Do you still need to use experimental.optimizePackageImports for @gravity/uikit? I believe the tree-shaking problem has been resolved (#2324) and this option is no longer needed. Could you check this, please?

@imsitnikov Could you check this, please?

@imsitnikov
Copy link
Contributor

Do you still need to use experimental.optimizePackageImports for @gravity/uikit? I believe the tree-shaking problem has been resolved (#2324) and this option is no longer needed. Could you check this, please?

@imsitnikov Could you check this, please?

@dgaponov do you remember the reason of adding optimizePackageImports for uikit?

@DarkGenius DarkGenius merged commit 618b1bb into main Jan 19, 2026
5 checks passed
@DarkGenius DarkGenius deleted the fix/fix-import-useLayoutEffect branch January 19, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants