Skip to content

Caline 缺陷修复·前端:缓存头 + bundle 自动初始化(QA #7 缺陷③④) - #18

Merged
todosdev[bot] merged 3 commits into
mainfrom
tds/conv-01a1ec3a-670e-77b7-942e-9596759a5465
Nov 18, 2026
Merged

todosdev[bot] merged 3 commits into
mainfrom
tds/conv-01a1ec3a-670e-77b7-942e-9596759a5465

Conversation

@todosdev

@todosdev todosdev Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 解决 QA chore(deps): update dependency i18next to v27.2.10 #7 缺陷③:在 web/public/_headers 中增加 Cloudflare Static Assets 自定义头规则,为 /client/* 配置 24h 强缓存与 CORS 头(public, max-age=86400, stale-while-revalidate=604800,Access-Control-Allow-Origin: *),兼顾边缘长缓存与版本平滑更新。
  • 解决 QA chore(deps): update dependency i18next to v27.2.10 #7 缺陷④:在客户端 bundle 中实现带严格意图门控的 autoInit() 与 scheduleAutoInit(),支持 <script> 的 data-* 属性、window.CALINE_CONFIG、或显式 #caline 容器自动挂载,并杜绝无配置引入时的双实例挂载和在 <head> 中生成非法 DOM。
  • 保持显式 Caline.init(options) API 100% 兼容;缺省 serverURL 时优雅降级为 location.origin 并输出警告,杜绝原有的 TypeError 崩溃。

Changes

  • web/public/_headers:新建静态资源头配置文件,声明 /client/* 长缓存(24h max-age + 7d SWR)与开放 CORS,同时为 /assets/* 提供 1 年 immutable 缓存,构建后自动输出到 web/dist/_headers。
  • client/src/index.ts:
    • 新增 autoInit() 与 scheduleAutoInit(),增加严格门控(仅在检测到 window.CALINE_CONFIG、<script data-*> 或页面显式 [data-caline]/#caline 时启动)。
    • 支持「一行 script 即工作」自动在 script 后插入 #caline 容器,但严格排除 <head> 内部 script 避免非法 DOM 结构。
    • 在 CalineWidget 构造函数中支持缺省 serverURL 回退至 location.origin,容器打上 data-caline-initialized 防重复标记,并联动触发 [data-caline-count] 和 [data-caline-pageview] 自动填充。
  • client/test/widget.test.ts & client/test/bundle.test.ts:补充 10 项单元测试,覆盖自动初始化、一行 script 嵌入、门控与 <head> 保护、防重复挂载及 _headers 配置断言。
  • web/public/client/v1.js:重新打包并同步更新 bundle 产物,构建后 gzip 体积为 8.78KB(严格满足 ≤ 30KB 约束)。

Testing

  • pnpm test:全套 411 个测试全绿(shared 12、client 27、worker 230、web 142)。
  • pnpm lint & pnpm format:check:Biome 检查通过,0 错误 0 警告。
  • pnpm typecheck:client + web + worker 三包严格 TypeScript 校验通过。
  • pnpm check:identity:项目身份标识扫描通过,白名单外零残留。
  • pnpm check:deploy:wrangler deploy --dry-run 静态资产打包 13 个文件校验通过。

mapxn and others added 3 commits November 18, 2026 09:23
Add web/public/_headers to provide 24h cache-control and CORS headers
for /client/* assets. Implement autoInit and scheduleAutoInit in client
bundle to support zero-config one-line script embedding with data-*
attributes, window.CALINE_CONFIG fallback, and container auto-creation.

Checkpoint: HyyoBCjDuicFPajSTdAcA
Gate autoInit to execute only when explicit intent is declared via
window.CALINE_CONFIG, script data-* attributes, or caline containers.
Prevent inserting container div when script is located inside head.

Checkpoint: s66D420pXvmab99oeQc3R
@todosdev
todosdev Bot merged commit 1661216 into main Nov 18, 2026
@mapxn
mapxn deleted the tds/conv-01a1ec3a-670e-77b7-942e-9596759a5465 branch November 23, 2026 10:55
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