Skip to content

fix: web 播放器读取环境变量时缺少 process 守卫 - #39

Merged
flycran merged 3 commits into
mainfrom
fix/web-process-undefined
Nov 9, 2026
Merged

flycran merged 3 commits into
mainfrom
fix/web-process-undefined

Conversation

@flycran

@flycran flycran commented Nov 9, 2026

Copy link
Copy Markdown
Owner

问题

3.4.0 发布后线上 web 播放器报 process is not defined。

fetchContributions 直接读取 process.env.GITHUB_TOKEN,而 web 端的调用链是:

src/web/index.ts → gensvg() → startSimulation() → fetchContributions()

web 播放器没有注入 calendarList,因此会执行到该行;浏览器里没有 process,直接抛 ReferenceError。

修复

环境变量读取加运行时守卫,浏览器侧视为无 token,回落到 gh-calendar:

const envToken =
  typeof process === 'undefined'
    ? undefined
    : process.env.GITHUB_TOKEN?.trim()

验证

  • bun biome check .、tsc --noEmit 通过
  • bun test:112 pass / 0 fail
  • npm run build:web 产物中该表达式已带守卫:typeof process>"u"?void 0:process.env.GITHUB_TOKEN?.trim()
  • dist/ 已重建

浏览器构建里没有 process,fetchContributions 直接读 process.env.GITHUB_TOKEN 会抛 ReferenceError。加运行时判断,浏览器侧按无 token 处理并回落到 gh-calendar。
@flycran
flycran merged commit d1b615c into main Nov 9, 2026
5 checks passed
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