Repository navigation
revert: 回滚 stream-diffs / @pierre/diffs 升级,修复代码块高亮 - #839
Merged
Merged
Conversation
Deploying markstream-vue with
|
| Latest commit: |
eba6dec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8a54df43.markstream-vue.pages.dev |
| Branch Preview URL: | https://revert-stream-diffs-upgrade.markstream-vue.pages.dev |
Deploying markstream-vue-docs with
|
| Latest commit: |
eba6dec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7339e285.markstream-vue-docs.pages.dev |
| Branch Preview URL: | https://revert-stream-diffs-upgrade.markstream-vue-docs.pages.dev |
Deploying markstream-nuxt with
|
| Latest commit: |
eba6dec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d7faea19.markstream-nuxt.pages.dev |
| Branch Preview URL: | https://revert-stream-diffs-upgrade.markstream-nuxt.pages.dev |
Deploying markstream-vue2 with
|
| Latest commit: |
eba6dec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cf234e7f.markstream-vue2.pages.dev |
| Branch Preview URL: | https://revert-stream-diffs-upgrade.markstream-vue2.pages.dev |
Deploying markstream-react with
|
| Latest commit: |
eba6dec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://274cbbd5.markstream-react.pages.dev |
| Branch Preview URL: | https://revert-stream-diffs-upgrade.markstream-react.pages.dev |
Deploying markstream-angular with
|
| Latest commit: |
eba6dec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d3ee14f5.markstream-angular.pages.dev |
| Branch Preview URL: | https://revert-stream-diffs-upgrade.markstream-angular.pages.dev |
Deploying markstream-svelte with
|
| Latest commit: |
eba6dec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3fd38737.markstream-svelte.pages.dev |
| Branch Preview URL: | https://revert-stream-diffs-upgrade.markstream-svelte.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
为什么回滚
3c958d4ab把@pierre/diffs从1.2.12升到1.6.4(stream-diffspeer 下限同时提到>=0.0.4),升级后代码块高亮坏掉。复现和定位结论如下。根因:
worker.js在同一个 worker 里被求值了两次只给
dist/worker/worker.js加console.log插桩(不改逻辑),在真实 playground dev + Chromium 下抓到:同一个 worker(performance.timeOrigin相同)里出现了两个 ESM 模块实例,import.meta.url不同:worker.js把renderOptions放在模块作用域,并注册self.addEventListener("message"),所以两份实例意味着:message监听器 → 每个请求被处理两次、回两次;getHighlighter()的import("./highlights-*.js")里被拉起来的,此时initialize已派发完,它永远收不到,renderOptions停在DEFAULT_THEMES;Theme "pierre-dark" has not been resolved。pierre-dark是上游默认主题,没有任何地方请求它,所以报错信息很有迷惑性。原因是 1.6.4 的 chunk 反向 import 入口:
highlights-*.js、shiki-*.js、stream-tokenizer-*.js都import ... from "./worker.js";Vite dev 把 worker 入口按worker.js?worker_file&type=module加载,chunk 里的./worker.js被解析成worker.js?v=<hash>,URL 不同 → 二次求值。1.2.12 是单文件worker.js、没有这种回边,所以不复现。prod 构建也不复现(Rollup 只产出一份,已验证)。之前用
{ dark, light }pair 初始化 pool 之所以"看起来修好了",是因为setRenderOptions在值相等时提前 return,pair 与同步的单名不相等才触发了广播,把两个实例都 seed 了 —— 模块仍然求值两次、每个请求仍然处理并回两次,只是DEFAULT_THEMES回退不再触发。所以那两个 workaround 属于掩盖,不是修复,本次一并 revert。这个 PR 做了什么
三个 revert,最终树与升级前(
3c958d4ab^)完全一致(git diff 3c958d4ab^ HEAD为空):eba6dec59Revert 升级本身@pierre/diffs^1.6.4→^1.2.12,stream-diffspeer>=0.0.4→>=0.0.2(安装的stream-diffs一直是0.0.2)preferredHighlighter的'auto'默认值、lineDiffType: 'word-line'、playground pool 的mainThreadMaxCharacters/ backend 参数,以及对应文档pnpm-lock.yamlscripts/benchmark-diffs-versions.mjs和.github/workflows/benchmark-diffs-upgrade.yml,以及test/code-block-preferred-highlighter.test.tsb0fab5111Revertplayground/src/main.ts的 pair 初始化6ae53391eRevertplayground-solid/src/workers.ts与playground/src/pages/perf-codeblock.vue的 pair 对齐验证
pnpm typecheck通过pnpm lint通过pnpm test -- --run:406 文件 / 3769 用例全部通过file请求只回一次success,零 console 错误;增强渲染面 shadow DOM 内 99 个 token span、4 种语法色git grep 'preferredHighlighter\|mainThreadMaxCharacters\|word-line'在src/ docs/ playground*/无残留后续
上游
@pierre/diffs的 chunk 回边问题(Vite dev 下 worker 入口被二次求值)会单独反馈给上游;在它修好之前不升级。stream-diffs本身不需要改动:它只在类型层面引用WorkerPoolManager,不构造 pool、不调用setRenderOptions。