Skip to content

fix: distinguish numeric and string notification keys - #422

Open
mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/numeric-string-key-collision
Open

mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/numeric-string-key-collision

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Notices are tracked by key in several places (NotificationList, getIndex, and useListPosition, which stores sizes and offsets), and each of them converts the key with String(key). A numeric key 1 and a string key '1' are valid, different keys (open / close compare them strictly), but they end up with the same entry in those maps. The two notices then get the same index and the same stacking offset, so they are laid out as one.

Real result of the new test (two notices opened with key: 1 and key: '1', offsetHeight mocked to 50), from the original source:

data-notification-index of the two notices
before ['1', '1']
after ['1', '0'] and --notification-y of 50px and 0px

The fix adds one helper, getNoticeKey(key) (${typeof key}-${key}), in useListPosition and uses it everywhere the string form of the key was used, including the React key of the list item. After closing 1, only the '1' notice remains.

Tests: added distinguishes numeric and string keys with the same string representation in tests/hooks.test.tsx; it fails on the original source and passes now. vitest run passes (6 files, 66 tests), npm run tsc is clean, and npm run lint reports 0 errors (10 warnings; I did not compare the warning count with the base branch). Open PR #409 edits src/Notification.tsx src/hooks/useNoticeTimer.ts tests/index.test.tsx tests/useNoticeTimer.test.tsx , which are different files from the ones changed here.

Summary by CodeRabbit

  • Bug 修复
    • 修复数字键与相同内容的字符串键被视为同一条通知的问题。现在两条通知可分别显示、正确排列和关闭。

@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@mokshupadhyay is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

通知键现在包含键类型和键值。通知列表使用该键进行索引查找、渲染、尺寸注册和偏移查询。新增测试验证数字键 1 与字符串键 '1' 可以作为不同通知显示和关闭。

Changes

通知键类型区分

Layer / File(s) Summary
定义带类型的通知键
src/hooks/useListPosition/index.ts
新增 getNoticeKey,根据键的类型和值生成字符串。位置和尺寸映射使用转换后的键。
接入通知列表并验证
src/NotificationList/index.tsx, tests/hooks.test.tsx
通知列表在索引查找、列表键集合、React key、尺寸注册和偏移查询中使用 getNoticeKey。测试验证数字键与字符串键分别保留,并检查顺序、索引和偏移。

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: zombiej

Merge Risk: Minimal · up to d8cf4

This change makes numeric and string notification keys such as 1 and '1' behave as separate notifications for display, stacking and closing. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix: distinguish numeric and string notification keys”准确描述了主要变更。变更新增 getNoticeKey,使数字键 1 与字符串键 '1' 不再冲突,并新增测试验证两者可同时显示。标题简短,并说明了修复的核心内容。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

我是兔子,蹦过通知列表,
数字一和字符串一,各有名字。
键带类型,位置也分明,
轻轻关掉数字那条,
字符串通知仍在闪亮。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05963ed2-09c9-4d44-b085-8371c346920a
Commits

Reviewing files that changed from the base of the PR and between 8e4f422 and d8cf474.

Files selected for processing: 3

  • src/NotificationList/index.tsx
  • src/hooks/useListPosition/index.ts
  • tests/hooks.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.22%. Comparing base (8e4f422) to head (d8cf474).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #422   +/-   ##
=======================================
  Coverage   99.21%   99.22%           
=======================================
  Files          12       12           
  Lines         383      385    +2     
  Branches      103      103           
=======================================
+ Hits          380      382    +2     
  Misses          3        3           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mokshupadhyay

Copy link
Copy Markdown
Contributor Author

Hi @yoyo837, a friendly ping: this is ready for review whenever you have time. Happy to adjust anything. Thanks!

This branch has not been deployed

No deployments
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.

1 participant