react-component / react-component/trigger

Does not work when rendered inside an iframe

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

还没有人认领这个 Issue。

主要语言
TypeScript
星标
391
派生
245
PR 合并指标
30 天内没有已合并 PR

描述

Minimal reproduction

import { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import RcTooltip from 'rc-tooltip';
import 'rc-tooltip/assets/bootstrap.css';

function IframeContent({ container }: { container: HTMLElement }) {
  return createPortal(
    <RcTooltip
      overlay="Hello from tooltip"
      placement="top"
      getTooltipContainer={() => container}
    >
      <button>Hover me</button>
    </RcTooltip>,
    container,
  );
}

export default function App() {
  const iframeRef = useRef<HTMLIFrameElement>(null);
  const [mountEl, setMountEl] = useState<HTMLElement | null>(null);

  useEffect(() => {
    const iframe = iframeRef.current;
    if (!iframe) return;

    const onLoad = () => {
      setMountEl(iframe.contentDocument?.body ?? null);
    };

    iframe.addEventListener('load', onLoad);
    if (iframe.contentDocument?.readyState === 'complete') onLoad();

    return () => iframe.removeEventListener('load', onLoad);
  }, []);

  return (
    <>
      <iframe
        ref={iframeRef}
        srcDoc="<!DOCTYPE html><html><body></body></html>"
        style={{ width: '100%', height: 200, border: '1px solid #ccc' }}
      />
      {mountEl && <IframeContent container={mountEl} />}
    </>
  );
}

Expected behavior

@rc-component/trigger should support trigger and popup elements rendered inside iframe documents.

Popup positioning and visible area calculation should work regardless of whether the DOM elements come from the parent document or an iframe document.

Actual behavior

When rendered inside an iframe, popup alignment/visible area calculation can be incorrect because iframe <body> and <html> elements fail the instanceof HTMLBodyElement / instanceof HTMLHtmlElement checks.

贡献指南

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

从这里开始

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

调研方向

首先定位检查 HTMLBodyElement 和 HTMLHtmlElement 是否为 instanceof 的 trigger 和 popup 定位代码。复现提供的 TypeScript iframe 示例,并检查可见区域计算如何处理来自其他文档的元素。当 trigger 和 popup 在 iframe 文档以及父文档中都能正确对齐时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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