`@effect/ui-kit` (Effect-TS/ui): `onMount` callbacks assume browser DOM nodes and crash-unmount subtrees on non-DOM `Html` hosts

未关闭
#11,058 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@effect-bot 已经在做这个了。

开始于 2026年11月29日。

  • #632 来自 @effect-bot —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
领域
frontend, mobile

调研方向

Read the reported mount callbacks in packages/ui-kit/src/Dialog.ts:602, ScrollArea.ts:434, and Toast.ts:478, then inspect the other affected files under packages/ui-kit/src/. Start by running the linked reproduction’s pnpm repro:test and reviewing its host helper and tests. Done means the listed primitives mount on a non-DOM Html host without an uncaught TypeError or subtree teardown; a linked open pull request is already addressing this issue.

由索引模型根据 Issue 内容生成。

描述

What version of Effect is running?
  • effect: 4.1.6
  • @effect/ui & @effect/ui-kit: Effect-TS/ui main at 77391ee50ae3d3175d670facbf675e9a819ba6a6
What steps can reproduce the bug?
  1. Clone the minimal reproduction branch:
    git clone -b repros/non-dom-host-uikit-bugs https://github.com/cliffordfajardo/ui.git effect-ui-repro
    cd effect-ui-repro
    pnpm install
    pnpm repro:test
    
  2. Mount a component using Dialog, Drawer, ScrollArea, or ToastProvider onto a valid non-DOM Renderer.Host that renders the Html vocabulary (elements: [Html.name]) with runsMounts: true and provides Html.Host, HtmlSubscription.AnimationFrames, HtmlSubscription.MediaQueries, and HtmlSubscription.GlobalEvents (see _helpers/nonDomHtmlHost.ts and 01-uikit-mounts-crash-non-dom-host/repro.test.ts).

Minimal sketch:

// Host renders Html vocabulary onto non-DOM objects (e.g. a native host like ns-effect-ui's MasonHost)
const host = makeNonDomHtmlHost({ runsMounts: true })
const container = makeNode("element", "root")

yield* Renderer.mount(DialogHostApp, {}, container, {
  fallback: (failure, h) => h.div("CRASHED")
}).pipe(Effect.provideContext(makeNonDomContext(host)))
What is the expected behavior?

Components in @effect/ui-kit should either:

  • guard browser-DOM-only operations in their Mount.make / Mount.makeStream callbacks (e.g. checking for ownerDocument / defaultView / getRootNode and gracefully becoming a no-op on non-DOM nodes), or
  • expose a host capability / DOM-mount contract so custom Html hosts that support onMount for app/host mounts do not crash when rendering @effect/ui-kit primitives.

At minimum, opening a Drawer/Dialog or mounting a ScrollArea/ToastProvider on a non-DOM Html host should not throw an uncaught TypeError and tear down the entire component subtree (including the trigger button and app content).

What do you see instead?

27 modules in packages/ui-kit/src/ unconditionally assume the mounted node is a browser HTMLElement / HTMLDialogElement inside Mount.make / Mount.makeStream. When the mount runs on a non-DOM Html host, it throws synchronously and mountRun.ts invokes Kernel.fail(inst, "mount", failure, ...), tearing down the subtree to its error fallback:

  • Drawer / Dialog (packages/ui-kit/src/Dialog.ts:602):
    ERROR: /Repro01DrawerApp/Drawer[]/Dialog[] failed in mount TypeError: Cannot read properties of undefined (reading 'defaultView')
        at packages/ui-kit/src/Dialog.ts:602:38
    
  • ScrollArea (packages/ui-kit/src/ScrollArea.ts:434):
    ERROR: /Repro01ScrollAreaApp/ScrollArea[] failed in mount TypeError: Cannot read properties of undefined (reading 'defaultView')
        at packages/ui-kit/src/ScrollArea.ts:434:49
    
  • ToastProvider (packages/ui-kit/src/Toast.ts:478):
    ERROR: /Repro01ToastApp/ToastProvider[] failed in mount TypeError: node.getRootNode is not a function
        at packages/ui-kit/src/Toast.ts:478:27
    
Additional information

Encountered while porting an @effect/ui + @effect/ui-kit web app onto NativeScript via ns-effect-ui's MasonHost (a non-DOM Renderer.Host implementing elements: [Html.name]).

Setting runsMounts: false on the host avoids these crashes, but disables all onMount callbacks globally (including non-DOM host mounts) and exposes gaps where @effect/ui-kit only implements interaction behavior inside mounts (filed separately).

Related downstream tracking issue: https://github.com/nstudio/ns-effect-ui/issues/3

主要语言
TypeScript
星标
16.7k
派生
808
平均合并
21 小时 22 分钟
30 天内合并 PR
486

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。