Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(dsh-tauri-ui): 样式表自报 data-plugin 归属,不再被宿主连带删除

hairyfc56bcf400166
diff --git a/packages/dsh-tauri-model-config/src/client/register/styles.ts b/packages/dsh-tauri-model-config/src/client/register/styles.ts
index 38500a00..c52e15e1 100644
--- a/packages/dsh-tauri-model-config/src/client/register/styles.ts
+++ b/packages/dsh-tauri-model-config/src/client/register/styles.ts
@@ -1,10 +1,11 @@
import { mountStyle } from 'dsh-tauri-ui/client'
import { defineRegister } from 'dsh-tauri/client'
+import { PLUGIN_ID } from '../../shared/constants'
import { OVERRIDES_STYLE_ID, STYLES_ID } from '../constants'
import { modelsStylesNode } from '../models/styles'
import { modelsOverridesNode } from '../models/styles.overrides'
export const registerStyles = defineRegister((controller) => {
- controller.add(mountStyle(modelsStylesNode, STYLES_ID))
- controller.add(mountStyle(modelsOverridesNode, OVERRIDES_STYLE_ID))
+ controller.add(mountStyle(modelsStylesNode, STYLES_ID, PLUGIN_ID))
+ controller.add(mountStyle(modelsOverridesNode, OVERRIDES_STYLE_ID, PLUGIN_ID))
})
diff --git a/packages/dsh-tauri-panel-scheduler/src/client/register/session-icons.ts b/packages/dsh-tauri-panel-scheduler/src/client/register/session-icons.ts
index 4f4e0394..9ccd53ec 100644
--- a/packages/dsh-tauri-panel-scheduler/src/client/register/session-icons.ts
+++ b/packages/dsh-tauri-panel-scheduler/src/client/register/session-icons.ts
@@ -4,6 +4,7 @@ import { Clock, Icon, mountStyle } from 'dsh-tauri-ui/client'
import { compact, defineRegister, map } from 'dsh-tauri/client'
import { createElement } from 'react'
import { createRoot } from 'react-dom/client'
+import { PLUGIN_ID } from '../../shared/constants'
import { SESSION_ICON_ATTRIBUTE, SESSION_ICON_STYLE_ID, SIDEBAR_SELECTOR } from '../constants'
import { store } from '../store'
import sessionIconStyle from '../styles/index.cssr'
@@ -78,7 +79,7 @@ function scan(): void {
export const sessionIconsFeature = defineRegister<ClientContext>((controller) => {
if (typeof document === 'undefined')
return
- controller.add(mountStyle(sessionIconStyle, SESSION_ICON_STYLE_ID))
+ controller.add(mountStyle(sessionIconStyle, SESSION_ICON_STYLE_ID, PLUGIN_ID))
controller.observe(document.body, scan)
controller.add(store.scheduler.$subscribe(scan))
diff --git a/packages/dsh-tauri-panel-scheduler/src/client/register/styles.ts b/packages/dsh-tauri-panel-scheduler/src/client/register/styles.ts
index f55bcfe4..442fa552 100644
--- a/packages/dsh-tauri-panel-scheduler/src/client/register/styles.ts
+++ b/packages/dsh-tauri-panel-scheduler/src/client/register/styles.ts
@@ -1,8 +1,9 @@
import { mountStyle } from 'dsh-tauri-ui/client'
import { defineRegister } from 'dsh-tauri/client'
+import { PLUGIN_ID } from '../../shared/constants'
import { STYLE_ID } from '../constants'
import indexStyle from '../styles/index.cssr'
export const stylesFeature = defineRegister((controller) => {
- controller.add(mountStyle(indexStyle, STYLE_ID))
+ controller.add(mountStyle(indexStyle, STYLE_ID, PLUGIN_ID))
})
diff --git a/packages/dsh-tauri-pet/src/client/register/styles.ts b/packages/dsh-tauri-pet/src/client/register/styles.ts
index 47644e6c..53f7b8a9 100644
--- a/packages/dsh-tauri-pet/src/client/register/styles.ts
+++ b/packages/dsh-tauri-pet/src/client/register/styles.ts
@@ -1,9 +1,10 @@
import { mountStyle } from 'dsh-tauri-ui/client'
import { defineRegister } from 'dsh-tauri/client'
+import { PLUGIN_ID } from '../../shared/constants'
import { PET_STYLES_ID } from '../constants'
import petEntryStyle from '../styles/index.cssr'
/** 侧栏入口与设置行布局的公共样式(无组件面)。 */
export const stylesFeature = defineRegister((controller) => {
- controller.add(mountStyle(petEntryStyle, PET_STYLES_ID))
+ controller.add(mountStyle(petEntryStyle, PET_STYLES_ID, PLUGIN_ID))
})
diff --git a/packages/dsh-tauri-running-changes/src/client/components/running-changes-chip.tsx b/packages/dsh-tauri-running-changes/src/client/components/running-changes-chip.tsx
index eedeef3f..224f9dc5 100644
--- a/packages/dsh-tauri-running-changes/src/client/components/running-changes-chip.tsx
+++ b/packages/dsh-tauri-running-changes/src/client/components/running-changes-chip.tsx
@@ -8,6 +8,7 @@ import type { RunningChangesChipProps } from './running-changes-chip.types'
* 后提示条自行消失。
*/
import { useMountStyle } from 'dsh-tauri-ui/client'
+import { PLUGIN_ID } from '../../shared/constants'
import { RUNNING_CHANGES_CHIP_STYLE_ID, RUNNING_CHANGES_COUNTS_STYLE_ID } from '../constants'
import { useLiveChanges } from '../hooks/use-live-changes'
import { locale } from '../locales'
@@ -16,8 +17,8 @@ import { ChangeCounts } from './change-counts'
import chipStyle from './running-changes-chip.cssr'
export function RunningChangesChip(props: RunningChangesChipProps): ReactElement | null {
- useMountStyle(chipStyle, RUNNING_CHANGES_CHIP_STYLE_ID)
- useMountStyle(countsStyle, RUNNING_CHANGES_COUNTS_STYLE_ID)
+ useMountStyle(chipStyle, RUNNING_CHANGES_CHIP_STYLE_ID, PLUGIN_ID)
+ useMountStyle(countsStyle, RUNNING_CHANGES_COUNTS_STYLE_ID, PLUGIN_ID)
locale.useLocale()
const sessionId = props.sessionId
// owner 份额(InputZone.session)明确说「没在跑」时连轮询都不开;
diff --git a/packages/dsh-tauri-session/src/client/components/archive-panel.tsx b/packages/dsh-tauri-session/src/client/components/archive-panel.tsx
index a2fa4f8f..21d53f6d 100644
--- a/packages/dsh-tauri-session/src/client/components/archive-panel.tsx
+++ b/packages/dsh-tauri-session/src/client/components/archive-panel.tsx
@@ -5,6 +5,7 @@ import type { ArchivePanelProps, DeleteConfirm } from './archive-panel.types'
import { Button, ChevronDown, Chip, Ellipsis, FolderOpen, Icon, IconButton, Input, Magnifier, Menu, Modal, Toast, TrashBin, useMountStyle } from 'dsh-tauri-ui/client'
import { isEmpty, useWatchImmediate } from 'dsh-tauri/client'
import { useCallback, useState } from 'react'
+import { PLUGIN_ID } from '../../shared/constants'
import { SESSION_STYLE_ID } from '../constants'
import { useArchiveView } from '../hooks/use-archive-view'
import { locale } from '../locales'
@@ -22,7 +23,7 @@ import { formatTime, projectOptions } from './archive-panel.utils'
/** 设置页「归档」分区:已归档的聊天列表(搜索 / 排序 / 项目筛选 / 取消归档 / 彻底删除)。 */
export function ArchivePanel(props: ArchivePanelProps): ReactElement | null {
- useMountStyle(archivePanelStyle, SESSION_STYLE_ID)
+ useMountStyle(archivePanelStyle, SESSION_STYLE_ID, PLUGIN_ID)
const { ui, rows, visible, groups, busy } = useArchiveView(props)
locale.useLocale()
const [confirm, setConfirm] = useState<DeleteConfirm>(null)
diff --git a/packages/dsh-tauri-session/src/client/register/styles.ts b/packages/dsh-tauri-session/src/client/register/styles.ts
index 4165ef15..6f3423cc 100644
--- a/packages/dsh-tauri-session/src/client/register/styles.ts
+++ b/packages/dsh-tauri-session/src/client/register/styles.ts
@@ -1,8 +1,9 @@
import { mountStyle } from 'dsh-tauri-ui/client'
import { defineRegister } from 'dsh-tauri/client'
+import { PLUGIN_ID } from '../../shared/constants'
import { SESSION_MENU_STYLE_ID } from '../constants'
import workspaceMenuStyle from '../styles/workspace-menu.cssr'
export const stylesFeature = defineRegister((controller) => {
- controller.add(mountStyle(workspaceMenuStyle, SESSION_MENU_STYLE_ID))
+ controller.add(mountStyle(workspaceMenuStyle, SESSION_MENU_STYLE_ID, PLUGIN_ID))
})
diff --git a/packages/dsh-tauri-ui-playground/src/client/ui/components-playground/ui-components.tsx b/packages/dsh-tauri-ui-playground/src/client/ui/components-playground/ui-components.tsx
index 642a1fce..23892a7c 100644
--- a/packages/dsh-tauri-ui-playground/src/client/ui/components-playground/ui-components.tsx
+++ b/packages/dsh-tauri-ui-playground/src/client/ui/components-playground/ui-components.tsx
@@ -29,6 +29,7 @@ import {
Xmark,
} from 'dsh-tauri-ui/client'
import { useState } from 'react'
+import { PLUGIN_ID } from '../../../shared/constants'
import { UI_COMPONENTS_STYLE_ID } from '../../constants'
import uiComponentsStyle from './ui-components.cssr'
@@ -117,7 +118,7 @@ function SourceCard({ entry }: { entry: UiComponentEntry }): ReactElement {
}
export function UiComponentsPanel(): ReactElement {
- useMountStyle(uiComponentsStyle, UI_COMPONENTS_STYLE_ID)
+ useMountStyle(uiComponentsStyle, UI_COMPONENTS_STYLE_ID, PLUGIN_ID)
const [checked, setChecked] = useState(true)
const [activePill, setActivePill] = useState('alpha')
const [query, setQuery] = useState('')
diff --git a/packages/dsh-tauri-ui/src/client/hooks/use-mount-style.ts b/packages/dsh-tauri-ui/src/client/hooks/use-mount-style.ts
index d0e6b9e8..3ea969c5 100644
--- a/packages/dsh-tauri-ui/src/client/hooks/use-mount-style.ts
+++ b/packages/dsh-tauri-ui/src/client/hooks/use-mount-style.ts
@@ -2,13 +2,13 @@ import type { CNode } from 'css-render'
import { useEffect, useRef } from 'react'
import { mountStyle } from '../utils/style'
-export function useMountStyle(cnode: CNode, id?: string): void {
+export function useMountStyle(cnode: CNode, id?: string, owner?: string): void {
const disposerRef = useRef<(() => void) | null>(null)
useEffect(() => {
- disposerRef.current = mountStyle(cnode, id)
+ disposerRef.current = mountStyle(cnode, id, owner)
return () => {
disposerRef.current?.()
disposerRef.current = null
}
- }, [cnode, id])
+ }, [cnode, id, owner])
}
diff --git a/packages/dsh-tauri-ui/src/client/utils/style.test.ts b/packages/dsh-tauri-ui/src/client/utils/style.test.ts
new file mode 100644
index 00000000..aee4caeb
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/utils/style.test.ts
@@ -0,0 +1,153 @@
+/**
+ * client/utils/style.test.ts — cssr 样式表的挂载与归属契约。
+ *
+ * 单元车道没有 DOM,这里按 `mountStyle` 真正用到的那一小块表面(`document.head` /
+ * `createElement` / `querySelector` / `insertBefore` / `removeChild`)搭一个替身;
+ * 断言对象是**文档里有哪些标签、标签带什么属性**,与实现无关。
+ *
+ * 守 issue #655 的两条链路:
+ * - 标签必须自报 `data-plugin` 归属,否则会被宿主的 `claimStyles` 认领给下一个物化的
+ * 插件,再被那个插件的重载 `removeOwnedStyles` 一并删除;
+ * - 同 id 的旧表必须换成新节点自己的活表,否则旧模块实例卸载时会把新实例刚复用的那张
+ * 删掉(css-render 只删「记在自己 `els` 里的表」),而引用计数还停在 >0,样式永不回挂。
+ */
+
+import type { CNode } from 'css-render'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { cssr } from './cssr'
+import { mountStyle } from './style'
+
+const STYLE_ID = 'dsh-tauri-ui-test-styles'
+const OWNER = 'dsh-tauri-ui-test-owner'
+
+class FakeStyleElement {
+ textContent = ''
+ parentElement: FakeHead | null = null
+ private readonly attributes = new Map<string, string>()
+
+ setAttribute(name: string, value: string): void {
+ this.attributes.set(name, value)
+ }
+
+ getAttribute(name: string): string | null {
+ return this.attributes.get(name) ?? null
+ }
+
+ remove(): void {
+ this.parentElement?.removeChild(this)
+ }
+}
+
+class FakeHead {
+ readonly children: FakeStyleElement[] = []
+
+ create(): FakeStyleElement {
+ return new FakeStyleElement()
+ }
+
+ querySelector(selector: string): FakeStyleElement | null {
+ if (selector === 'style, link')
+ return this.children[0] ?? null
+ const match = /^style\[cssr-id="(.+)"\]$/.exec(selector)
+ if (match === null)
+ return null
+ return this.children.find(child => child.getAttribute('cssr-id') === match[1]) ?? null
+ }
+
+ insertBefore(node: FakeStyleElement, reference: FakeStyleElement | null): void {
+ const index = reference === null ? -1 : this.children.indexOf(reference)
+ if (index < 0)
+ this.children.push(node)
+ else
+ this.children.splice(index, 0, node)
+ node.parentElement = this
+ }
+
+ removeChild(node: FakeStyleElement): void {
+ const index = this.children.indexOf(node)
+ if (index >= 0)
+ this.children.splice(index, 1)
+ node.parentElement = null
+ }
+}
+
+function installFakeDocument(): FakeHead {
+ const head = new FakeHead()
+ vi.stubGlobal('document', {
+ head,
+ createElement: () => head.create(),
+ querySelector: (selector: string) => head.querySelector(selector),
+ })
+ return head
+}
+
+/** 每个用例用独立节点:`mountCounts` 按节点身份记数,模块级状态不跨用例串味。 */
+function styleNode(): CNode {
+ return cssr.c('div', { color: 'red' })
+}
+
+afterEach(() => {
+ vi.unstubAllGlobals()
+})
+
+describe('mountStyle', () => {
+ it('挂载后样式标签自报 data-plugin 归属,释放时摘掉', () => {
+ const head = installFakeDocument()
+ const release = mountStyle(styleNode(), STYLE_ID, OWNER)
+
+ expect(head.children).toHaveLength(1)
+ expect(head.children[0]?.getAttribute('data-plugin')).toBe(OWNER)
+
+ release()
+ expect(head.children).toHaveLength(0)
+ })
+
+ it('同一个节点重复挂载只落一张表,最后一个消费者释放时才摘掉', () => {
+ const head = installFakeDocument()
+ const node = styleNode()
+ const first = mountStyle(node, STYLE_ID, OWNER)
+ const second = mountStyle(node, STYLE_ID, OWNER)
+
+ expect(head.children).toHaveLength(1)
+
+ first()
+ expect(head.children, '还有消费者持有,不得摘表').toHaveLength(1)
+
+ second()
+ expect(head.children).toHaveLength(0)
+ })
+
+ it('标签被外部删掉后再次挂载会补回来,不留「计数非零但样式缺席」', () => {
+ const head = installFakeDocument()
+ const node = styleNode()
+ mountStyle(node, STYLE_ID, OWNER)
+ head.children[0]?.remove()
+ expect(head.children).toHaveLength(0)
+
+ mountStyle(node, STYLE_ID, OWNER)
+
+ expect(
+ head.querySelector(`style[cssr-id="${STYLE_ID}"]`),
+ '样式必须在文档里,而不是只在引用计数里',
+ ).not.toBeNull()
+ })
+
+ it('插件重载:旧实例遗留的同 id 表被换成新节点的活表,旧实例卸载摘不掉它', () => {
+ const head = installFakeDocument()
+ const stale = mountStyle(styleNode(), STYLE_ID, OWNER)
+ const fresh = mountStyle(styleNode(), STYLE_ID, OWNER)
+ expect(head.children).toHaveLength(1)
+
+ // 旧实例的清理晚于新实例的挂载:css-render 只删「记在自己 els 里的那张表」,
+ // 新实例必须先把手里的表换成文档里的活表,否则这一删就再也回不来。
+ stale()
+ expect(
+ head.querySelector(`style[cssr-id="${STYLE_ID}"]`),
+ '新实例的活表不得被旧实例摘掉',
+ ).not.toBeNull()
+ expect(head.children[0]?.getAttribute('data-plugin')).toBe(OWNER)
+
+ fresh()
+ expect(head.children).toHaveLength(0)
+ })
+})
diff --git a/packages/dsh-tauri-ui/src/client/utils/style.ts b/packages/dsh-tauri-ui/src/client/utils/style.ts
index f6f9eb52..a9bc2306 100644
--- a/packages/dsh-tauri-ui/src/client/utils/style.ts
+++ b/packages/dsh-tauri-ui/src/client/utils/style.ts
@@ -1,8 +1,29 @@
import type { CNode } from 'css-render'
+import { PLUGIN_ID } from '../../shared/constants'
+
+/**
+ * 样式标签的归属者属性。
+ *
+ * 宿主的客户端模块系统(`@deepseek-ai/dsh-client-modules`)在每个插件 factory 物化后调
+ * `claimStyles`:把文档里所有**没有 `data-plugin`** 的 `<style>` 盖上「刚物化的那个插件」
+ * 的戳;该插件随后重载时 `removeOwnedStyles` 会把它们一并删掉(0.1.6-alpha.2 起)。css-render
+ * 只写 `cssr-id`,不自报归属就会被别的插件收养、再被别人的重载误删(issue #655)。
+ */
+const OWNER_ATTRIBUTE = 'data-plugin'
const mountCounts = new Map<CNode, number>()
-export function mountStyle(cnode: CNode, id?: string): () => void {
+function existingElement(id?: string): HTMLStyleElement | null {
+ return id === undefined ? null : document.querySelector<HTMLStyleElement>(`style[cssr-id="${id}"]`)
+}
+
+/**
+ * 挂载一张 cssr 样式表,返回释放函数;同一个 `CNode` 多次挂载只落一个标签。
+ * @param cnode - `.cssr.ts` 导出的样式节点。
+ * @param id - 样式标签的 `cssr-id`,也是卸载时的唯一凭据。
+ * @param owner - 归属插件 id,落进 `data-plugin`;默认本插件(本助手由 `dsh-tauri-ui` 提供)。
+ */
+export function mountStyle(cnode: CNode, id?: string, owner: string = PLUGIN_ID): () => void {
const release = (): void => {
const next = (mountCounts.get(cnode) ?? 1) - 1
if (next <= 0) {
@@ -16,8 +37,14 @@ export function mountStyle(cnode: CNode, id?: string): () => void {
if (typeof document === 'undefined')
return () => {}
const count = mountCounts.get(cnode) ?? 0
- if (count === 0)
- cnode.mount({ id, head: true })
+ const existing = existingElement(id)
+ // 计数不为零也要确认标签还在:宿主回收、别的插件清理、或插件重载时新旧模块实例短暂并存
+ // (css-render 遇到同 id 会直接复用并把它记在**旧**节点名下,旧实例卸载时会把它删掉),
+ // 都会让这张表消失而计数仍停在 >0——不重挂它在本页生命周期内不会自己回来(issue #655)。
+ if (count === 0 || (id !== undefined && existing === null)) {
+ existing?.remove()
+ cnode.mount({ id, head: true }).setAttribute(OWNER_ATTRIBUTE, owner)
+ }
mountCounts.set(cnode, count + 1)
return release
}
diff --git a/packages/dsh-tauri-worktree/src/client/register/session-icons.ts b/packages/dsh-tauri-worktree/src/client/register/session-icons.ts
index 8af3c193..4f3bf26c 100644
--- a/packages/dsh-tauri-worktree/src/client/register/session-icons.ts
+++ b/packages/dsh-tauri-worktree/src/client/register/session-icons.ts
@@ -4,6 +4,7 @@ import { CircleTree, Icon, mountStyle } from 'dsh-tauri-ui/client'
import { defineRegister, findKey } from 'dsh-tauri/client'
import { createElement } from 'react'
import { createRoot } from 'react-dom/client'
+import { PLUGIN_ID } from '../../shared/constants'
import {
SESSION_ICON_ATTRIBUTE,
SESSION_ICON_STYLE_ID,
@@ -23,7 +24,7 @@ function removeIcon(icon: Element): void {
export const sessionIconsFeature = defineRegister<ClientContext>((controller) => {
if (typeof document === 'undefined')
return
- controller.add(mountStyle(sessionIconStyle, SESSION_ICON_STYLE_ID))
+ controller.add(mountStyle(sessionIconStyle, SESSION_ICON_STYLE_ID, PLUGIN_ID))
function reactKey(element: Element, prefix: 'session-' | ''): string | undefined {
const fiberName = findKey(element, (_value, key) => key.startsWith('__reactFiber$'))
diff --git a/packages/dsh-tauri-worktree/src/client/register/styles.ts b/packages/dsh-tauri-worktree/src/client/register/styles.ts
index 79d43e27..58ef5154 100644
--- a/packages/dsh-tauri-worktree/src/client/register/styles.ts
+++ b/packages/dsh-tauri-worktree/src/client/register/styles.ts
@@ -1,8 +1,9 @@
import { mountStyle } from 'dsh-tauri-ui/client'
import { defineRegister } from 'dsh-tauri/client'
+import { PLUGIN_ID } from '../../shared/constants'
import { WORKTREE_STYLE_ID } from '../constants'
import worktreeStyle from '../styles/index.cssr'
export const stylesFeature = defineRegister((controller) => {
- controller.add(mountStyle(worktreeStyle, WORKTREE_STYLE_ID))
+ controller.add(mountStyle(worktreeStyle, WORKTREE_STYLE_ID, PLUGIN_ID))
})
diff --git a/packages/dsh-tauri/src/client/register/sidebar-tweaks.ts b/packages/dsh-tauri/src/client/register/sidebar-tweaks.ts
index 3db9bbf5..d678e448 100644
--- a/packages/dsh-tauri/src/client/register/sidebar-tweaks.ts
+++ b/packages/dsh-tauri/src/client/register/sidebar-tweaks.ts
@@ -8,6 +8,7 @@
* 一律用稳定的 aria-label 属性选择器,不用生成的 CSS module 类名:CSS 规则天然覆盖
* React 后续重渲染,卸载时按同一个 style id 移除。
*/
+import { PLUGIN_ID } from '../../shared/constants'
import { NEW_SESSION_SELECTOR } from '../constants'
import { CssRender } from '../modules/css-render'
import { reportPluginError } from '../utils/error'
@@ -26,7 +27,9 @@ export const sidebarTweaksFeature = defineRegister((controller) => {
c(COLLAPSE_SIDEBAR_SELECTOR, { display: 'none !important' }),
c(NEW_SESSION_SELECTOR, { justifyContent: 'center !important' }),
])
- style.mount({ id: SIDEBAR_TWEAKS_STYLE_ID, head: true })
+ // 必须自报归属:宿主的客户端模块系统会把没有 `data-plugin` 的 <style> 认领给下一个
+ // 物化的插件,并在它重载时一并删除(issue #655)。
+ style.mount({ id: SIDEBAR_TWEAKS_STYLE_ID, head: true }).setAttribute('data-plugin', PLUGIN_ID)
controller.add(() => style.unmount({ id: SIDEBAR_TWEAKS_STYLE_ID }))
}
catch (error) {
diff --git a/test/e2e/plugins/dsh-tauri-ui.e2e.ts b/test/e2e/plugins/dsh-tauri-ui.e2e.ts
index 087576fa..7199846c 100644
--- a/test/e2e/plugins/dsh-tauri-ui.e2e.ts
+++ b/test/e2e/plugins/dsh-tauri-ui.e2e.ts
@@ -474,4 +474,36 @@ describe('L2 客户端', () => {
await app.close()
}
})
+
+ /**
+ * 样式的**归属**是宿主回收的前提(issue #655)。
+ *
+ * 宿主的客户端模块系统在每个插件 factory 物化后调 `claimStyles`:把文档里所有没有
+ * `data-plugin` 的 `<style>` 盖上「刚物化的那个插件」的戳,之后该插件重载
+ * (`removeOwnedStyles`)就把它们一并删掉。css-render 只写 `cssr-id`,不自报归属的
+ * 表会被别的插件收养、再被别人的重载误删;而插件的引用计数还停在 >0,样式不会回挂——
+ * 症状就是用户报的「偶发 UI 整体混乱,刷新才好」。断言对象是真实页面里的 DOM。
+ */
+ it('验证插件 cssr 样式标签都自报 data-plugin 归属,不会被别人的重载连带删除', async () => {
+ const app = await newDshPage(browser, { ready: PET_STYLES })
+ try {
+ const ownership = await app.frame.evaluate(() => {
+ const tags = Array.from(document.querySelectorAll('style[cssr-id]'))
+ return {
+ total: tags.length,
+ untagged: tags.filter(tag => !tag.hasAttribute('data-plugin')).map(tag => tag.getAttribute('cssr-id')),
+ }
+ })
+
+ expect(ownership.total, '前置:本批插件必须真的挂上了 cssr 样式表,否则这条断言无从谈起').toBeGreaterThan(0)
+ expect(
+ ownership.untagged,
+ `未自报归属的 cssr 标签会被 claimStyles 认领给下一个物化的插件,再被它的 removeOwnedStyles 删除(实测未归属:${JSON.stringify(ownership.untagged)})`,
+ ).toEqual([])
+ expect(app.errors, '样式归属不得抛出应用级错误').toEqual([])
+ }
+ finally {
+ await app.close()
+ }
+ })
})