Skip to content

fix: compatibility and robustness hardening, 0.1.2 - #1

Merged
wowayou merged 2 commits into
mainfrom
claude/keen-meitner-dwa6sa
Sep 30, 2026
Merged

wowayou merged 2 commits into
mainfrom
claude/keen-meitner-dwa6sa

Conversation

@wowayou

@wowayou wowayou commented Sep 30, 2026

Copy link
Copy Markdown
Owner

概要

兼容性与健壮性加固,发布为 0.1.2。需要改配置:否——现有 items / tracking 配置原样可用,新增的构建期报错只针对此前就无法正常工作的输入。

改动

客户端归因(src/tracking.js)

  • 没有 window / document 的环境(SSR、测试、Worker)里调用不再抛 ReferenceError;跨 iframe 的元素按 nodeType 识别。
  • one-widget:click 派发与 dataLayer 推送互相隔离:页面监听器抛错、或 dataLayer 被定义成非数组,都不会影响另一路上报或链接跳转。
  • enhancePromotionWidgets() 中单个 widget 出错不再中断其它 widget。
  • 中键点击(新标签页打开)通过 auxclick 上报;右键不上报。
  • ?from= 去首尾空白、忽略大小写匹配,上报配置里的写法(此前 ?from=GitHub 归入 other)。

渲染与模型(src/render.js、src/model.js、src/registry.js、src/icons.js)

  • 全部条目禁用时返回空字符串,不再输出空 <nav> 地标;空白 ariaLabel 回落到默认值。
  • tracking 字符串去空白、allowlist 去重;options 可为 null。
  • CMS / JSON 导出的 null 可选字段视为未设置。
  • 平台 hosts 按 URL#hostname 规则规范化(大小写、IDN、结尾点号、误贴的 scheme);带路径的条目仍不匹配,避免意外扩大到整个域名。protocols 可省略冒号;platforms / icons 接受 Map。
  • 新增构建期报错:无收件人的 mailto:;platforms / icons 为数组或非对象;registry / iconRegistry 不是 Map。

包与类型

  • package.json 增加 main、types、typesVersions 与导出的 default 条件,moduleResolution: "node10" 及只认 default 条件的工具也能解析。
  • 类型接受 readonly 数组与可空 options;TrackingEnvironment 从主入口导出。

样式(src/styles.css)

  • 长标签换行不撑破 390px 视口;inline 滚动容器不再裁掉焦点环;无 :focus-visible 时回落 :focus;forced-colors 下保留边框;sr-only 改用 clip-path。

CI

  • 新增 .github/workflows/ci.yml:Node 20 / 22 / 24 跑 npm run check + pack:check,Astro 5 / 6 / 7 构建 fixture 并断言。

升级后可见的行为变化

  • 中键点击开始计数,统计量可能略增。
  • 大小写不同的来源不再归入 other。
  • 全部禁用时不再输出空 <nav>。

验证

  • npm run check:41 个测试通过(原 27 个),契约测试未改动。
  • Astro fixture 在 5.18.2 / 6.4.8 / 7.3.5 上实际构建并通过 verify.mjs。
  • 类型声明在 TypeScript NodeNext、bundler、node10 三种解析方式下通过。
  • Chromium 实测构建产物:左键 / 中键上报、右键不上报,?from=GitHub → github,390px 无横向溢出,Tab 焦点环可见。
  • 本地只有 Node 22;Node 20 / 24 由本 PR 的 CI 首次验证。

发布说明

v0.1.2 tag 打在本分支 head 上。请用 Create a merge commit 合并,这样 tag 指向的提交会留在 main 历史里(squash / rebase 会生成新提交,tag 就不在 main 上了)。

🤖 Generated with Claude Code

https://claude.ai/code/session_01SSHDa6j758YbQZUK7QHez4


Generated by Claude Code

No consumer config changes are needed; only inputs that were already
silently broken now fail at build time.

- tracking: never touch window/document when they are absent, so the
  enhancement is a no-op in SSR/tests instead of a ReferenceError;
  recognise cross-realm elements by nodeType
- tracking: isolate the one-widget:click dispatch and the dataLayer push
  so a throwing listener or a non-array dataLayer cannot break the other
  sink or navigation; one bad widget no longer stops the rest
- tracking: report middle-click opens via auxclick; ignore right clicks
- tracking: match ?from= case-insensitively after trimming, and report
  the configured spelling so buckets stay low-cardinality
- render: return "" when no item is enabled instead of an empty <nav>
  landmark; blank ariaLabel falls back to the default; trim tracking
  strings and de-duplicate the allowlist; accept null options
- model: treat null optional fields (JSON/CMS exports) as unset; reject
  mailto: links without a recipient
- registry: normalise declared hosts like URL#hostname (case, IDN,
  trailing dot, pasted scheme) while leaving path-scoped entries
  unmatched as before; protocols may omit the colon; a differently-cased
  custom key replaces the built-in; accept Map definitions; reject
  non-object platforms/icons and non-Map registries with clear errors
- package: add main/types/typesVersions and "default" export conditions
  so node10 resolution and default-only tooling resolve entries and types
- types: readonly item arrays, nullable options, TrackingEnvironment
  exported from the main entry
- css: wrap long labels, keep the focus ring unclipped in the inline
  scroller, :focus fallback without :focus-visible, forced-colors
  borders, clip-path for sr-only text
- ci: GitHub Actions on Node 20/22/24 plus Astro 5/6/7 fixture builds
- docs: CHANGELOG 0.1.2 (unreleased), README and architecture notes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SSHDa6j758YbQZUK7QHez4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SSHDa6j758YbQZUK7QHez4
@wowayou
wowayou merged commit 2a9dfe8 into main Sep 30, 2026
6 checks passed
@wowayou
wowayou deleted the claude/keen-meitner-dwa6sa branch September 30, 2026 12:00
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.

2 participants