Skip to content

依旧 XML 渲染问题 #668

Description

@yyswys-yjyj

问题描述

Operit 1.12.0 中,通过 ToolPkg.registerXmlRenderPlugin 注册的 XML 渲染插件,在消息列表刷新(如新消息插入、上下文回滚等场景)时,会导致 composeDsl 组件完全重建,所有用户交互状态(useState)丢失。

表现为:

  • UI 抽搐:组件先销毁再重建,会话篇幅缩短
  • 滚动锚失效:重建后滚动位置回到上方某处
  • 状态丢失:由工具包自定义的逻辑这时候会丢失(比如计划工具包中提交后的状态)

根因分析

xml_render 路径的 executionContextKey 构建函数 buildXmlRenderComposeDslExecutionContextKey 包含了 renderInstanceKey

private fun buildXmlRenderComposeDslExecutionContextKey(
    containerPackageName: String,
    screenPath: String,
    renderInstanceKey: Any?
): String {
    return listOfNotNull(
        "toolpkg_xml_render",
        containerKey,
        screenKey,
        instanceKey?.takeIf { it.isNotBlank() }  // ← renderInstanceKey
    ).joinToString(":")
}

renderInstanceKey 变化时(消息列表刷新导致),executionContextKey 变化,ToolPkgManager.getToolPkgExecutionEngine 返回新的 JsEngine 实例,导致 memoStore(即 useState 底层存储)完全丢失。

ToolPkgComposeDslScreen 路径(非 xml_render)使用 containerPackageName + uiModuleId 作为 remember key,不受此问题影响。

受影响的内置包(只找到一个内置包)

  • com.operit.plan_mode_bundle

复现步骤

  1. 安装 com.operit.plan_mode_bundle 插件
  2. AI 发送一份计划
  3. 提交或请求计划状态
  4. 观察:XML意外刷新,回到初始状态,同时因为活跃的会话的篇幅大幅缩短导致滚动锚会瞬间跑到上方

Metadata

Metadata

Assignees

No one assigned

    Labels

    UI-UXVisual interaction issues such as interface alignment, bubbles, and themes.界面对齐、气泡、主题等视觉交互问题tool-calling工具规划/调用/处理问题Tool planning/call/handling issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions