# 加载、缓存与诊断参考

动态加载、优先级、overrides、缓存、样式和运行时观察。

<span id="elegir-el-nivel-de-carga"></span>

<span class="section-anchor" id="section-1"></span>

## 选择加载层级

完整生命周期使用 `wu.mount`。`wu.prefetch` 提前请求已注册应用资源，`wu.use` 加载通过 exports 发布的组件。`WuLoader` 是独立加载器，不替代 core 的目录、sandbox 或 grants。

Overrides 和检查工具属于宿主。指标衡量观察到的某段过程，不保证浏览器已完成绘制。完整流程请参阅[应用加载](/zh-cn/docs/framework/loading/)和[诊断](/zh-cn/docs/framework/troubleshooting/)。

<span class="section-anchor" id="section-2"></span>

## wu.use

加载另一应用声明的组件 export。

`wu.use("app.component"): Promise<unknown>`

- **参数：** 精确名称 app.component；提供方 manifest 必须声明 wu.exports。
- **返回值：** 存在时为 default export，否则为模块 namespace。
- **错误：** 应用/export 缺失、目录穿越、无效 URL 或导入失败会拒绝。
- **权限：** 宿主；加载组件在消费方 realm 内执行代码。
- **清理：** 使用组件的 renderer 实例负责管理 cleanup。

```js
const ProductCard = await wu.use('catalog.ProductCard');
```

运行时存在此方法，但 WuCore 声明缺失。它不会在不同框架之间转换组件。

参考：`src/core/wu-core.js`.

<span class="section-anchor" id="section-3"></span>

## wu.prefetchAll

请求预加载全部已注册应用。

`wu.prefetchAll(options?): Promise<void> | (() => void)`

- **参数：** 与 prefetch 相同的触发选项。
- **返回值：** 即时 Promise 或延迟触发器 cleanup。
- **错误：** 预加载是向浏览器发出请求，不确认 renderer 能挂载。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 选择延迟触发器时保存 cleanup。

```js
await wu.prefetchAll({ on: 'immediate' });
```

参考：`src/core/wu-prefetch.js`.

<span class="section-anchor" id="section-4"></span>

## new WuLoader

创建具备缓存和进行中请求去重的代码与组件 loader。

`new WuLoader({ maxCacheSize?, cacheTTL? }?): WuLoader`

- **参数：** maxCacheSize 限制条目数量，默认 50；cacheTTL 单位毫秒，默认 1800000。
- **返回值：** 包含 loadApp、loadComponent、preload、isAvailable 和 clearCache 的实例。
- **错误：** 创建不会注册应用或执行生命周期。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** loader.clearCache() 释放缓存条目。

```js
import { WuLoader } from 'wu-framework';
const loader = new WuLoader({ maxCacheSize: 20, cacheTTL: 60000 });
```

参考：`src/core/wu-loader.js`.

<span class="section-anchor" id="section-5"></span>

## WuLoader.loadApp

下载入口代码文本，供加载流程使用。

`loader.loadApp(appUrl, manifest?): Promise<string>`

- **参数：** 基础 URL 和带可选 entry 的 manifest。
- **返回值：** 代码字符串；不执行 mount，也不注册应用。
- **错误：** Fetch 失败、无效响应或 entry 解析失败会拒绝。
- **权限：** 宿主，受环境网络访问限制。
- **清理：** clearCache(base) 丢弃供后续读取复用的缓存。

```js
const code = await loader.loadApp('/apps/catalog', { entry: 'entry.js' });
```

参考：`src/core/wu-loader.js`.

<span class="section-anchor" id="section-6"></span>

## WuLoader.loadComponent

导入限制在应用基础目录内的组件。

`loader.loadComponent(appUrl, componentPath): Promise<unknown>`

- **参数：** 基础地址和组件相对路径；不允许绝对 URL 或目录穿越。
- **返回值：** default export 或导入 namespace。
- **错误：** 路径超出基础目录或导入失败时拒绝。
- **权限：** 模块在同一上下文执行代码，不是 scoped RPC。
- **清理：** 原生 import 保留模块缓存。

```js
const card = await loader.loadComponent('/apps/catalog', 'components/card.js');
```

参考：`src/core/wu-loader.js`.

<span class="section-anchor" id="section-7"></span>

## WuLoader.preload

为应用列表提前下载代码。

`loader.preload(appConfigs: WuAppConfig[]): Promise<void>`

- **参数：** 包含 name 和 url 的配置数组。
- **返回值：** 预加载遍历完成的 Promise。
- **错误：** 预加载逐个捕获应用失败；挂载前检查可用性。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不挂载 renderers；clearCache 释放缓存文本。

```js
await loader.preload([{ name: 'catalog', url: '/apps/catalog' }]);
```

参考：`src/core/wu-loader.js`.

<span class="section-anchor" id="section-8"></span>

## WuLoader.isAvailable

查询 URL 是否正确响应 HEAD。

`loader.isAvailable(url): Promise<boolean>`

- **参数：** 待检查 URL。
- **返回值：** 布尔值，网络错误转换为 false。
- **错误：** 服务器拒绝 HEAD 时，即使 GET 可用也可能返回 false。
- **权限：** 宿主网络访问。
- **清理：** 不创建订阅或持久进程。

```js
const available = await loader.isAvailable('/apps/catalog/entry.js');
```

参考：`src/core/wu-loader.js`.

<span class="section-anchor" id="section-9"></span>

## WuLoader.clearCache

丢弃 loader 缓存的文本和记录。

`loader.clearCache(pattern?): void`

- **参数：** 可选模式；无模式时清空 loader 缓存。
- **返回值：** void。
- **错误：** 不使浏览器 ESM 缓存失效。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
loader.clearCache('catalog');
```

参考：`src/core/wu-loader.js`.

<span class="section-anchor" id="section-10"></span>

## WuLoader.getStats

查询 loader 缓存和进行中的 imports。

`loader.getStats(): object`

- **参数：** 无参数。
- **返回值：** 指标对象。
- **错误：** 不代表应用挂载状态。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.log(loader.getStats());
```

参考：`src/core/wu-loader.js`.

<span class="section-anchor" id="section-11"></span>

## wu.override

配置开发用 URL 替换。

`wu.override(name, url, options?): void`

- **参数：** name 和已授权 URL；options.maxAge/path 配置 override 持久化。
- **返回值：** void
- **错误：** 系统验证域名和配置；override 不会自动 remount。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 共享会话前移除开发 overrides。

```js
wu.override('catalog', 'http://localhost:4101');
```

参考：`src/core/wu-overrides.js`.

<span class="section-anchor" id="section-12"></span>

## wu.removeOverride

移除 URL 替换。

`wu.removeOverride(name): void`

- **参数：** 精确应用名称。
- **返回值：** void
- **错误：** 系统验证域名和配置；override 不会自动 remount。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 共享会话前移除开发 overrides。

```js
wu.removeOverride('catalog');
```

参考：`src/core/wu-overrides.js`.

<span class="section-anchor" id="section-13"></span>

## wu.getOverrides

查询活动 URL 替换。

`wu.getOverrides(): Record<string,string>`

- **参数：** 无参数。
- **返回值：** Record<string,string>
- **错误：** 系统验证域名和配置；override 不会自动 remount。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 共享会话前移除开发 overrides。

```js
console.log(wu.getOverrides());
```

参考：`src/core/wu-overrides.js`.

<span class="section-anchor" id="section-14"></span>

## wu.clearOverrides

移除全部活动替换。

`wu.clearOverrides(): void`

- **参数：** 无参数。
- **返回值：** void
- **错误：** 系统验证域名和配置；override 不会自动 remount。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 共享会话前移除开发 overrides。

```js
wu.clearOverrides();
```

参考：`src/core/wu-overrides.js`.

<span class="section-anchor" id="section-15"></span>

## normalizeStyleMode

规范化样式配置别名。

`normalizeStyleMode(mode): string | undefined`

- **参数：** 模式字符串或 undefined。
- **返回值：** none→isolated；own-only→fully-isolated；其他值不验证直接传递。
- **错误：** 本身不验证 manifest 是否允许该模式。
- **权限：** 纯函数，不授予权限。
- **清理：** 不创建订阅或持久进程。

```js
import { normalizeStyleMode } from 'wu-framework';
console.log(normalizeStyleMode('own-only'));
```

参考：`src/core/wu-sandbox.js`.

<span class="section-anchor" id="section-16"></span>

## resolveDomOwnership

解析显式所有权及 nativeShadow/framework 别名。

`resolveDomOwnership(options?): "wu" | "app" | "light"`

- **参数：** domOwnership 优先，其次 nativeShadow；Lit 默认选择 app。
- **返回值：** 实际生效的所有权。
- **错误：** 不创建 Shadow DOM，也不验证 renderer 是否实现其边界。
- **权限：** 配置函数，不是安全控制。
- **清理：** 不创建订阅或持久进程。

```js
import { resolveDomOwnership } from 'wu-framework';
console.log(resolveDomOwnership({ framework: 'lit' }));
```

参考：`src/core/wu-sandbox.js`.

<span class="section-anchor" id="section-17"></span>

## wu.tagStyleAsApp

为 CSS bridge 将 style/link 样式表归属到应用。

`wu.tagStyleAsApp(element, appName): void`

- **参数：** style/link 元素和应用名称。
- **返回值：** void。
- **错误：** 归属标记不能替代 manifest 的 styleMode。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 所属者结束时移除样式表。

```js
const style = document.createElement('style');
style.textContent = ':host { color: var(--accent); }';
wu.tagStyleAsApp(style, 'catalog');
document.head.append(style);
```

参考：`src/core/wu-core.js`.

<span class="section-anchor" id="section-18"></span>

## new WuCache

创建带 TTL 和可选存储的 LRU 缓存。

`new WuCache(options?): WuCache`

- **参数：** maxSize 单位 MB；maxItems；TTL 单位 ms；persistent，以及 memory/localStorage/sessionStorage 类型的 storage。
- **返回值：** 缓存实例。
- **错误：** 条目过大或操作限额可能阻止存储。
- **权限：** 宿主；不要用持久存储作为授权。
- **清理：** cache.clear() 释放条目和持久 namespace。

```js
import { WuCache } from 'wu-framework';
const cache = new WuCache({ maxSize: 2, maxItems: 20, defaultTTL: 60000, storage: 'memory' });
```

参考：`src/core/wu-cache.js`.

<span class="section-anchor" id="section-19"></span>

## WuCache.get

读取未过期条目并更新 LRU 顺序。

`cache.get(key): unknown | null`

- **参数：** 条目键。
- **返回值：** 保存值；缺失、过期或 rate limit 时为 null。
- **错误：** null 无法区分 miss、过期或 cooldown，请查看指标。
- **权限：** 访问所属缓存，不应用 store grants。
- **清理：** 不创建订阅或持久进程。

```js
const result = cache.get('catalog-result');
```

内存读取返回保存的引用，不像 WuStore 那样返回独立快照。

参考：`src/core/wu-cache.js`.

<span class="section-anchor" id="section-20"></span>

## WuCache.set

保存值并应用空间和过期限制。

`cache.set(key, value, ttl?): boolean`

- **参数：** 键、值及毫秒 TTL；由于使用 ||，ttl=0 会采用 defaultTTL。
- **返回值：** 存储成功为 true；大小、错误或 rate limit 导致 false。
- **错误：** 捕获失败并返回 false；storage 配额可能限制持久化。
- **权限：** 宿主；验证要持久保存的数据。
- **清理：** delete(key) 移除一条，clear() 移除全部。

```js
const cached = cache.set('catalog-result', { count: 12 }, 30000);
```

参考：`src/core/wu-cache.js`.

<span class="section-anchor" id="section-21"></span>

## WuCache.delete

从内存及配置的后端存储删除条目。

`cache.delete(key): void`

- **参数：** 精确键。
- **返回值：** void
- **错误：** 持久化取决于 storage 可用性和配额。
- **权限：** 缓存所属者的权限。
- **清理：** 不创建订阅或持久进程。

```js
cache.delete('catalog-result');
```

参考：`src/core/wu-cache.js`.

<span class="section-anchor" id="section-22"></span>

## WuCache.clear

清空此实例缓存及配置的存储。

`cache.clear(): void`

- **参数：** 无参数。
- **返回值：** void
- **错误：** 持久化取决于 storage 可用性和配额。
- **权限：** 缓存所属者的权限。
- **清理：** 不创建订阅或持久进程。

```js
cache.clear();
```

参考：`src/core/wu-cache.js`.

<span class="section-anchor" id="section-23"></span>

## WuCache.getStats

查询 hits、misses、evictions、大小和 rate limiting。

`cache.getStats(): object`

- **参数：** 无参数。
- **返回值：** object
- **错误：** 持久化取决于 storage 可用性和配额。
- **权限：** 缓存所属者的权限。
- **清理：** 不创建订阅或持久进程。

```js
console.log(cache.getStats());
```

参考：`src/core/wu-cache.js`.

<span class="section-anchor" id="section-24"></span>

## WuCache.getRateLimitStatus

查询操作是否处于 cooldown 及其配额。

`cache.getRateLimitStatus(): object`

- **参数：** 无参数。
- **返回值：** object
- **错误：** 持久化取决于 storage 可用性和配额。
- **权限：** 缓存所属者的权限。
- **清理：** 不创建订阅或持久进程。

```js
console.log(cache.getRateLimitStatus());
```

参考：`src/core/wu-cache.js`.

<span class="section-anchor" id="section-25"></span>

## wu.getStats

汇总 core 各子系统状态和指标。

`wu.getStats(): object`

- **参数：** 无参数。
- **返回值：** 诊断对象。
- **错误：** 不替代挂载测试或 HTTP 检查。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.log(wu.getStats());
```

参考：`src/core/wu-core.js`.

<span class="section-anchor" id="section-26"></span>

## wu.getManifestDiagnostics

读取应用间声明式依赖错误。

`wu.getManifestDiagnostics(): WuManifestImportDiagnostic[]`

- **参数：** 无参数；依赖 imports preflight。
- **返回值：** 按消费者/import/提供方组织的诊断列表。
- **错误：** 不自动检查 bundle 全部传递 imports。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.table(wu.getManifestDiagnostics());
```

参考：`src/core/wu-core.js`.

<span class="section-anchor" id="section-27"></span>

## wu.showInspector

打开按需加载的可视检查器。

`wu.showInspector(): Promise<{ close(): void } | null>`

- **参数：** 无参数。
- **返回值：** close handle，未打开时为 null。
- **错误：** chunk 加载或 DOM 环境可能阻止打开。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** close() 或 wu.hideInspector() 移除 overlay。

```js
const inspector = await wu.showInspector();
// Al cerrar tu herramienta:
inspector?.close();
```

参考：`src/core/wu-core.js`.

<span class="section-anchor" id="section-28"></span>

## wu.hideInspector

若存在检查 overlay，则关闭。

`wu.hideInspector(): Promise<void>`

- **参数：** 无参数。
- **返回值：** 关闭 Promise。
- **错误：** 不删除应用或 store 数据。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 移除诊断界面。

```js
await wu.hideInspector();
```

参考：`src/core/wu-core.js`.

<span class="section-anchor" id="section-29"></span>

## wu.performance.startMeasure

标记应用或全局耗时测量的起点。

`wu.performance.startMeasure(name, appName?): void`

- **参数：** 测量名称；appName 默认为 global。
- **返回值：** void。
- **错误：** disabled 配置会跳过记录。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 使用同一名称/应用调用 endMeasure。

```js
wu.performance.startMeasure('load-catalog', 'catalog');
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-30"></span>

## wu.performance.endMeasure

结束耗时测量，启用时发布到指标和 User Timing。

`wu.performance.endMeasure(name, appName?): number`

- **参数：** 与 startMeasure 相同的名称/应用。
- **返回值：** 毫秒数；没有起始标记则为 0。
- **错误：** 缺少标记返回 0，不虚构时长。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 移除此测量的起始标记。

```js
const ms = wu.performance.endMeasure('load-catalog', 'catalog');
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-31"></span>

## wu.performance.generateReport

汇总实例性能统计。

`wu.performance.generateReport(): object`

- **参数：** 无参数。
- **返回值：** object
- **错误：** User Timing 可用性取决于环境。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.log(wu.performance.generateReport());
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-32"></span>

## wu.performance.getMetrics

读取特定应用指标。

`wu.performance.getMetrics(appName): object | null`

- **参数：** 精确名称；没有测量时为 null。
- **返回值：** object | null
- **错误：** User Timing 可用性取决于环境。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.log(wu.performance.getMetrics('catalog'));
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-33"></span>

## wu.performance.getAllMetrics

读取测量器中所有应用的指标。

`wu.performance.getAllMetrics(): object`

- **参数：** 无参数。
- **返回值：** object
- **错误：** User Timing 可用性取决于环境。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.log(wu.performance.getAllMetrics());
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-34"></span>

## wu.performance.clearMetrics

清除一个或所有应用的测量。

`wu.performance.clearMetrics(appName?): void`

- **参数：** 可选名称。
- **返回值：** void
- **错误：** User Timing 可用性取决于环境。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
wu.performance.clearMetrics('catalog');
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-35"></span>

## wu.performance.getDevToolsEntries

读取 WU 发出的 User Timing 条目。

`wu.performance.getDevToolsEntries(options?): PerformanceEntry[]`

- **参数：** type 为 mark、measure 或 all；appName 可选。
- **返回值：** PerformanceEntry[]
- **错误：** User Timing 可用性取决于环境。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.table(wu.performance.getDevToolsEntries({ type: 'measure', appName: 'catalog' }));
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-36"></span>

## wu.performance.observe

通过 PerformanceObserver 监听新的 WU User Timing 条目。

`wu.performance.observe(callback, { type? }?): () => void`

- **参数：** PerformanceEntry 回调；type 默认为 measure。
- **返回值：** Cleanup；observer 不可用时返回空函数。
- **错误：** 缺少 PerformanceObserver 不抛出，回调失败会记录。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** stop() 断开 observer。

```js
const stop = wu.performance.observe(entry => console.log(entry.duration), { type: 'measure' });
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-37"></span>

## wu.performance.configure

配置测量、历史上限、User Timing 和阈值。

`wu.performance.configure(options): void`

- **参数：** enabled、maxMeasurements、devtoolsTimeline 和按名称配置的 thresholds。
- **返回值：** void。
- **错误：** 超出阈值产生警告，不取消操作。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
wu.performance.configure({ enabled: true, maxMeasurements: 100, devtoolsTimeline: true });
```

参考：`src/core/wu-performance.js`.

<span class="section-anchor" id="section-38"></span>

## wu.errorBoundary.register

添加故障分类与恢复处理函数。

`wu.errorBoundary.register(handler): void`

- **参数：** name、canHandle(error) 和 handle(error,context)。
- **返回值：** void。
- **错误：** 缺少任何成员会抛出；按顺序遍历 handlers。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不返回 unsubscribe；在宿主生命周期内管理这些扩展。

```js
wu.errorBoundary.register({ name: 'catalog-error', canHandle: error => error.name === 'CatalogError', async handle(error) { return { recovered: false, action: 'none', message: error.message }; } });
```

默认通用 fallback 可能先于后添加的 handlers。依赖此注册前检查顺序。

参考：`src/core/wu-error-boundary.js`.

<span class="section-anchor" id="section-39"></span>

## wu.errorBoundary.handle

分类故障并获得恢复决定。

`wu.errorBoundary.handle(error, context?): Promise<object>`

- **参数：** Error 和 context；core 在 mount 期间解释部分 actions。
- **返回值：** 包含 recovered、action 和 handler 信息的结果。
- **错误：** action 名称本身不会改变 URL、超时或权限。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 重试前，恢复流程应释放失败尝试。

```js
const recovery = await wu.errorBoundary.handle(new Error('Entry no disponible'), { appName: 'catalog', phase: 'mount' });
```

参考：`src/core/wu-error-boundary.js`.

<span class="section-anchor" id="section-40"></span>

## wu.errorBoundary.getErrorLog

读取 boundary 保留的最近错误。

`wu.errorBoundary.getErrorLog(limit?: number): object[]`

- **参数：** limit 默认 10。
- **返回值：** 最近条目的数组。
- **错误：** 内存诊断，不是持久记录。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.table(wu.errorBoundary.getErrorLog(5));
```

参考：`src/core/wu-error-boundary.js`.

<span class="section-anchor" id="section-41"></span>

## wu.errorBoundary.getStats

汇总错误数量、handlers 和类型。

`wu.errorBoundary.getStats(): object`

- **参数：** 无参数。
- **返回值：** 包含 totalErrors、handlers、errorsByType 和 recentErrors 的对象。
- **错误：** 不包含从未经过此 boundary 的失败。
- **权限：** 宿主 API，scoped facade 不暴露。
- **清理：** 不创建订阅或持久进程。

```js
console.log(wu.errorBoundary.getStats());
```

参考：`src/core/wu-error-boundary.js`.

<span class="section-anchor" id="section-42"></span>

## WuLoadingStrategy

创建加载策略并启动 idle 处理。

`new WuLoadingStrategy(core)`

- **参数：** core 实例。
- **返回值：** 带默认策略的协调器。
- **错误：** 传播无效配置错误；检查异步操作结果。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** cleanup 取消 idle 回调，并以 null 完成等待队列。

```js
import { WuLoadingStrategy } from 'wu-framework';
const strategies = new WuLoadingStrategy(wu);
strategies.cleanup();
```

参考：`src/core/wu-strategies.js`.

<span class="section-anchor" id="section-43"></span>

## strategies.register

注册或替换加载策略。

`strategies.register(name, strategy): void`

- **参数：** strategy.load(appName,config) 必填；shouldPreload 和 priority 可选。
- **返回值：** void。
- **错误：** strategy.load 不是函数时抛出。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
strategies.register('custom', {
  shouldPreload: false,
  priority: 'low',
  load: async (name, config) => { console.log(name, config); return null; },
});
```

参考：`src/core/wu-strategies.js`.

<span class="section-anchor" id="section-44"></span>

## strategies.load

执行 config.strategy 指定的策略。

`strategies.load(appName, config): Promise<unknown>`

- **参数：** 名称与 config；默认 lazy。
- **返回值：** 已注册 load 函数的结果。
- **错误：** 未知策略记录警告并回退 lazy；load 错误会传播。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
await strategies.load('card', { strategy: 'custom' });
```

参考：`src/core/wu-strategies.js`.

<span class="section-anchor" id="section-45"></span>

## strategies.preload

依次预加载策略要求预加载的应用。

`strategies.preload(apps): Promise<void>`

- **参数：** 包含 name 和 strategy 的配置列表。
- **返回值：** 遍历 Promise；捕获单个失败。
- **错误：** 单个失败被记录，并继续下一应用。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
await strategies.preload([{ name: 'card', strategy: 'custom' }]);
```

参考：`src/core/wu-strategies.js`.

<span class="section-anchor" id="section-46"></span>

## strategies.getStats

查询已注册策略及 idle 队列大小。

`strategies.getStats(): object`

- **参数：** 无参数。
- **返回值：** {totalStrategies,strategies,idleQueueSize,isIdle}。
- **错误：** 本地读取，无副作用。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
console.log(strategies.getStats());
```

参考：`src/core/wu-strategies.js`.

<span class="section-anchor" id="section-47"></span>

## strategies.cleanup

停止 idle 队列并释放待处理等待。

`strategies.cleanup(): void`

- **参数：** 无参数。
- **返回值：** void。
- **错误：** 即使某次解析失败，清理仍尝试完成每项等待。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 取消 idle/timer 并清空队列，待处理项解析为 null。

```js
strategies.cleanup();
```

参考：`src/core/wu-strategies.js`.

<span class="section-anchor" id="section-48"></span>

## wu.sandbox.addStyles

向已有 sandbox 插入 CSS。

`wu.sandbox.addStyles(appName, css): void`

- **参数：** 名称和 CSS 字符串。
- **返回值：** void。
- **错误：** sandbox 不存在时记录警告并返回。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
wu.sandbox.addStyles('card', ':host{display:block}');
```

sandbox 属性由 core 管理。应用仍挂载时不要调用 cleanupAll，请使用 wu.unmount 协调生命周期。

参考：`src/core/wu-sandbox.js`.

<span class="section-anchor" id="section-49"></span>

## wu.sandbox.loadExternalStyles

向 sandbox 插入 stylesheet link。

`wu.sandbox.loadExternalStyles(appName, href): void`

- **参数：** 名称和 CSS URL。
- **返回值：** void；不等待样式表 load。
- **错误：** 缺少 sandbox 会警告，样式表网络错误不作为 Promise 返回。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
wu.sandbox.loadExternalStyles('card', '/styles/card.css');
```

sandbox 属性由 core 管理。应用仍挂载时不要调用 cleanupAll，请使用 wu.unmount 协调生命周期。

参考：`src/core/wu-sandbox.js`.

<span class="section-anchor" id="section-50"></span>

## wu.sandbox.getStyleStats

查询 style bridge 统计。

`wu.sandbox.getStyleStats(): object | null`

- **参数：** 无参数。
- **返回值：** 统计对象或 null。
- **错误：** 读取不执行网络操作。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
console.log(wu.sandbox.getStyleStats());
```

sandbox 属性由 core 管理。应用仍挂载时不要调用 cleanupAll，请使用 wu.unmount 协调生命周期。

参考：`src/core/wu-sandbox.js`.

<span class="section-anchor" id="section-51"></span>

## wu.sandbox.reinjectStyles

按应用隔离模式重新注入样式。

`wu.sandbox.reinjectStyles(appName): Promise<void>`

- **参数：** 已注册 sandbox 名称。
- **返回值：** Promise<void>。
- **错误：** sandbox 缺失或 isolated 模式时不操作；其他模式应用其样式选择规则。
- **权限：** 宿主管理 API，不包含在微应用 scoped facade 中。
- **清理：** 运行时所属者管理资源及其 cleanup 函数。

```js
await wu.sandbox.reinjectStyles('card');
```

sandbox 属性由 core 管理。应用仍挂载时不要调用 cleanupAll，请使用 wu.unmount 协调生命周期。

参考：`src/core/wu-sandbox.js`.

在 4.0 中，没有 `allowedDomains` 的 override 只接受 loopback hosts 或页面 hostname。其他 host 需要显式 allowlist。该限制同时适用于程序化 overrides 和从 cookies 恢复的 overrides。