Skip to content

Commit aa01140

Browse files
authored
Merge pull request #540 from omdsh-dev/feat/drop-rc7-fallback
feat(client): 删除 rc.7 宿主的 __DSH_MODULES__ 回退路径
2 parents 7b5c7dd + dc33087 commit aa01140

4 files changed

Lines changed: 14 additions & 22 deletions

File tree

src/client/chunk-loader.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
* arbitrary file names, so the plugin's own host route serves the chunks),
2424
* 2. read the factory from the global registry,
2525
* 3. call it with a require that resolves the platform externals through
26-
* `__DSH_MODULES__.import(spec)` — the seed-word branch, the one part of
27-
* the module system that is stable across versions.
26+
* the injected module system's `import(spec)` (the `ctx.modules` service)
27+
* — the seed-word branch, the one part of the module system that is
28+
* stable across versions.
2829
*
2930
* Caching contract (three layers, each with a failure path):
3031
* - In-memory: one in-flight promise per chunk, memoized until
@@ -90,8 +91,7 @@ const CHUNK_REVALIDATE_TIMEOUT_MS = 5_000
9091
* The client module system surface this loader needs to resolve externals.
9192
* DSH 0.1.0-rc.8 provides it as the `ctx.modules` service (no page global
9293
* anymore); the plugin injects it at activation via
93-
* {@link setChunkModuleSystem}. The rc.7-era `window.__DSH_MODULES__` global
94-
* remains as a fallback so older hosts and the test harness keep working.
94+
* {@link setChunkModuleSystem}.
9595
*/
9696
export interface ChunkModuleSystem {
9797
import(specifier: string): Promise<unknown>
@@ -123,12 +123,11 @@ export function setChunkModuleSystem(system: ChunkModuleSystem | undefined): voi
123123
}
124124

125125
/** Resolve the shell-installed module system (injected, then the plugin
126-
* global shared with chunk-bundle copies, then the rc.7 page global). */
126+
* global shared with chunk-bundle copies). */
127127
function moduleSystem(): ChunkModuleSystem | undefined {
128128
const g = globalThis as Record<string, unknown>
129129
return injectedModuleSystem
130130
?? g[MODULE_SYSTEM_GLOBAL] as ChunkModuleSystem | undefined
131-
?? (g as { __DSH_MODULES__?: ChunkModuleSystem }).__DSH_MODULES__
132131
}
133132

134133
/** The plugin-owned chunk factory registry the chunk scripts populate. */

src/client/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ export function apply(ctx: Context): void {
188188
}
189189
}
190190
try {
191-
// rc.8+ exposes the client module system as the `ctx.modules` service
192-
// (no window.__DSH_MODULES__ page global anymore); the chunk loader needs
193-
// it to resolve its externals, so inject it before anything can load a
194-
// lazy chunk. The loader falls back to the rc.7 global when absent.
191+
// rc.8+ exposes the client module system as the `ctx.modules` service;
192+
// the chunk loader needs it to resolve its externals, so inject it
193+
// before anything can load a lazy chunk.
195194
setChunkModuleSystem(ctx.modules)
196195
// Fresh chunk state for this activation: drop per-test fixtures and
197196
// revalidate loaded chunk scripts against the bundle route's ETags —

tests/add-plugin-modal.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { createRoot } from 'react-dom/client'
1919
import { act } from 'react-dom/test-utils'
2020
import * as primitives from '@deepseek-ai/dsh-client-ui-primitives'
2121
import { type PluginEntry } from '../src/client/plugins-shared.ts'
22+
import { builtinTabPlugins } from '../src/client/plugins-tabs.ts'
2223
import { builtinViewerPlugins } from '../src/client/plugins-viewers.ts'
2324
import { AddPluginModal, PluginListBody } from '../src/client/add-plugin-modal.tsx'
2425
import { createBetterSidebarService } from '../src/client/service.ts'

tests/chunk-loader.spec.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
* - externals resolve through the module system's seed branch (the stable,
99
* version-independent part), once per page,
1010
* - resetChunks drops the cache and the externals memo (HMR).
11-
* The production path runs against a fake `window.__DSH_MODULES__` and a
12-
* stub script loader that simulates the executed chunk script by assigning
13-
* the plugin-owned global factory registry.
11+
* The production path runs against a fake module system injected via
12+
* {@link setChunkModuleSystem} (mirroring the client half's `ctx.modules`
13+
* injection) and a stub script loader that simulates the executed chunk
14+
* script by assigning the plugin-owned global factory registry.
1415
*/
1516
import { beforeEach, describe, expect, it, vi } from 'vitest'
1617
import './browser-globals.ts'
@@ -33,14 +34,10 @@ function installModuleSystem(): FakeModuleSystem {
3334
const fake: FakeModuleSystem = {
3435
import: vi.fn(async (specifier: string) => ({ seed: specifier })),
3536
}
36-
;(globalThis as Record<string, unknown>).__DSH_MODULES__ = fake
37+
setChunkModuleSystem(fake)
3738
return fake
3839
}
3940

40-
function removeModuleSystem(): void {
41-
delete (globalThis as Record<string, unknown>).__DSH_MODULES__
42-
}
43-
4441
/** Simulate a chunk script executing: it assigns its factory to the registry. */
4542
function simulateScript(name: string, factory: (require: (spec: string) => unknown) => ChunkExports): void {
4643
const g = globalThis as { __dshChunks__?: Record<string, unknown> }
@@ -49,7 +46,6 @@ function simulateScript(name: string, factory: (require: (spec: string) => unkno
4946
}
5047

5148
beforeEach(() => {
52-
removeModuleSystem()
5349
setChunkModuleSystem(undefined)
5450
delete (globalThis as Record<string, unknown>).__dshChunks__
5551
resetChunks()
@@ -89,9 +85,6 @@ describe('test-registry path (vitest / jsdom-less environments)', () => {
8985
describe('production path (script injection + global registry + externals require)', () => {
9086
it('resolves externals through an injected ctx.modules system (rc.8 — no page global)', async () => {
9187
const modules = installModuleSystem()
92-
// rc.8 drops window.__DSH_MODULES__; the client half injects ctx.modules.
93-
removeModuleSystem()
94-
setChunkModuleSystem(modules)
9588
const loaded: string[] = []
9689
setChunkScriptLoaderForTests(async (src) => {
9790
loaded.push(src)

0 commit comments

Comments
 (0)