react-component / react-component/trigger

Does not work when rendered inside an iframe

オープン
#623 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、HTMLBodyElement と HTMLHtmlElement を instanceof でチェックしている trigger と popup の位置決めコードを探します。提供されている TypeScript の iframe の例を再現し、可視領域の計算が別のドキュメントに属する要素をどのように扱うかを確認します。iframe ドキュメント内でも親ドキュメント内でも、trigger と popup の配置が正しく機能すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
react, typescript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
58/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。