-
-
Notifications
You must be signed in to change notification settings - Fork 264
fix: ensure distinct popup ids across menu instances #888
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
Open
atharv-sys32
wants to merge
1
commit into
react-component:master
Choose a base branch
from
atharv-sys32:fix/distinct-popup-uuid
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: react-component/menu
Length of output: 606
🏁 Script executed:
Repository: react-component/menu
Length of output: 249
🏁 Script executed:
Repository: react-component/menu
Length of output: 249
🏁 Script executed:
Repository: react-component/menu
Length of output: 2993
🌐 Web query:
@rc-component/util useId ssr-id useCompatId useOriginId💡 Result:
In the
@rc-component/utillibrary, theuseIdhook is a compatibility wrapper designed to manage ID generation consistently across environments, especially when React's nativeuseIdhook might not be available (e.g., in older React versions) or to handle specific synchronization requirements [1]. The implementation logic behind these functions is as follows: 1. useId (The Primary Hook): This is the main exported hook [1]. It acts as a gateway that checks if a nativeuseOriginIdis available [1]. If it is, it uses React's nativeuseId[1]. If not, it falls back touseCompatIdto provide a compatible ID generation mechanism [1]. It also prioritizes an externally providedidif passed by the developer, treating it as the "single source of truth," and returns a mock ID ('test-id') when running in test environments [1]. 2. useOriginId: This is an internal helper that resolves to React's nativeuseIdhook if it exists in the current environment [1]. It is used byuseIdto detect if the native capability is available [1]. 3. useCompatId: This is the fallback mechanism used when nativeuseIdis unavailable [1]. It generates IDs using a simple internal counter (starting with 'ssr-id' and incrementing viarc_unique_{number}) [1]. Because it relies onReact.useEffectto initialize, this ID is only generated on the client side, meaning it may not match across server-side and client-side rendering [1]. 4. ssr-id: This is not a function, but a default value ('ssr-id') used byuseCompatIdduring the initial render phase before the effect runs [1]. In practice, when using components from the Ant Design ecosystem (such as Tooltip, Select, or Menu), you importuseIddirectly from@rc-component/util[2][3][4]. The hook handles the underlying logic of whether to use native features or the compatibility fallback automatically [1].Citations:
🏁 Script executed:
Repository: react-component/menu
Length of output: 2872
补齐旧版 React 的 SSR 唯一性。
当前
package.json仍声明react/react-dom >=16.9.0,但新增的mergedUuid在旧版 React 中会落入@rc-component/util的兼容useId。该兼容路径 SSR 首屏返回ssr-id,到客户端useEffect后才生成rc_unique_*。两个无id的Menu因此会在 SSR 和 hydration 初始输出中得到相同的rc-menu-uuid-ssr-id,重复的弹层 ID 会影响data-menu-id和aria-controls关系。如果这个 peer range 仍有效,请使用 SSR 可水合的实例唯一 ID;否则提升到 React 18+,并增加旧版 React/SSR 回归测试。🤖 Prompt for AI Agents
Source: MCP tools