isDOM doesn't work on elements outside of current window

未关闭
#644 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
typescript
领域
frontend

调研方向

从所引用的行开始检查 src/Dom/findDOMNode.ts,并比较它对来自另一个窗口的元素的行为。然后检查 src/Dom/isVisible.ts,其中报告了相同的跨窗口问题。确认这两个 utility 都能处理当前窗口之外的元素,同时不改变对当前窗口节点的行为。

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

描述

This code https://github.com/react-component/util/blob/288022820d2ab899c799ac6336155dedf3e9a766/src/Dom/findDOMNode.ts#L3-L7

Fails when node is not inside the current window. The main use case is using one screen for presentation and another screen for information that the presenter see.

an idea of a fix:

const nodeWindow = node?.ownerDocument?.defaultView;
return node instanceof nodeWindow.HTMLElement || node instanceof nodeWindow.SVGElement;

The issue is that the above code doesn't really work because you need to know if node is an Element first before getting the window, so we'll need a better idea for a fix.

a fix that I feel like is a hack:

return "nodeType" in node && node === Node.ELEMENT_NODE && "tagName" in node;

I don't know if this is good enough, but it works, fixes the bug.

same thing also happens here https://github.com/react-component/util/blob/288022820d2ab899c799ac6336155dedf3e9a766/src/Dom/isVisible.ts#L6

主要语言
TypeScript
星标
670
派生
205
平均合并
15 天 17 小时
30 天内合并 PR
6

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

react-component/util 的其他 Issue

查看 react-component/util 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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