-
-
Notifications
You must be signed in to change notification settings - Fork 243
fix(trigger): avoid render-based reset for interaction-level deduplication #601
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -372,9 +372,18 @@ export function generateTrigger( | |
| openRef.current = mergedOpen; | ||
|
|
||
| const lastTriggerRef = React.useRef<boolean[]>([]); | ||
| lastTriggerRef.current = []; | ||
| const resetScheduledRef = React.useRef(false); | ||
|
|
||
| const internalTriggerOpen = useEvent((nextOpen: boolean) => { | ||
| // `lastTriggerRef` is for interaction-level deduplication; do not reset it on render. | ||
| if (!resetScheduledRef.current) { | ||
| resetScheduledRef.current = true; | ||
| queueMicrotask(() => { | ||
| resetScheduledRef.current = false; | ||
| lastTriggerRef.current = []; | ||
| }); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's examine the code context around lines 377-385
wc -l src/index.tsxRepository: react-component/trigger Length of output: 84 🏁 Script executed: # Read the specific lines in context
sed -n '370,395p' src/index.tsxRepository: react-component/trigger Length of output: 982 🏁 Script executed: # Search for queueMicrotask usage in the file
rg -n "queueMicrotask" src/index.tsx -A 3 -B 3Repository: react-component/trigger Length of output: 396 🌐 Web query:
💡 Result: Short summary
Sources
🏁 Script executed: # Check package.json for browser target configuration
cat package.json | head -50Repository: react-component/trigger Length of output: 1356 🏁 Script executed: # Search for any polyfill or compatibility handling for queueMicrotask
rg "queueMicrotask|Promise.*resolve.*then|polyfill" --type-list | head -20Repository: react-component/trigger Length of output: 456 🏁 Script executed: # Check if there's any Babel configuration that might handle polyfills
ls -la | grep -E "babel|tsconfig|\.browserlistrc"Repository: react-component/trigger Length of output: 130 🏁 Script executed: # Search for browser targets in tsconfig or similar
find . -maxdepth 2 -name "tsconfig*.json" -o -name ".babelrc*" -o -name "browserslist"Repository: react-component/trigger Length of output: 82 🏁 Script executed: # Check tsconfig.json
cat tsconfig.jsonRepository: react-component/trigger Length of output: 441 🏁 Script executed: # Search for polyfill or queueMicrotask usage more broadly
rg "queueMicrotask" -B 3 -A 3Repository: react-component/trigger Length of output: 466 🏁 Script executed: # Check if there's any polyfill setup
rg "polyfill|Promise.*then|core-js" --type ts --type tsxRepository: react-component/trigger Length of output: 94 🏁 Script executed: # Look for any global setup or index files that might handle compatibility
cat src/index.tsx | head -100Repository: react-component/trigger Length of output: 3214 去重逻辑正确,出色地解决了受控模式下的问题! 使用
微任务在当前同步代码完成后、下一次事件循环前执行,这正好符合交互级别去重的时序需求。 浏览器兼容性注意: 🤖 Prompt for AI Agents |
||
|
|
||
| setInternalOpen(nextOpen); | ||
|
|
||
| // Enter or Pointer will both trigger open state change | ||
|
|
||
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.
6b09c6f
这个直接回滚掉是不是就好了,也不用支持 React 16 了