fix: OpenInTab icon oversized before CSS loads in shortcut-triggered popup#291
fix: OpenInTab icon oversized before CSS loads in shortcut-triggered popup#291
Conversation
Co-authored-by: ujiro99 <677231+ujiro99@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #291 +/- ##
==========================================
- Coverage 19.10% 19.09% -0.01%
==========================================
Files 308 308
Lines 28730 28742 +12
Branches 1317 1317
==========================================
Hits 5488 5488
- Misses 23242 23254 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
ショートカット経由で開いたポップアップで、Shadow DOM の CSS 適用前に OpenInTab の SVG アイコンが巨大表示される問題を抑止するため、ページの読み込み完了を待ってボタンを描画する変更です。
Changes:
OpenInTabにisPageReadyを追加し、enableOpenInTab && isPageReadyのときのみ描画するように変更window.loadを購読してページ完了後にisPageReadyをtrueに更新
| const [isPageReady, setIsPageReady] = useState( | ||
| document.readyState === "complete", | ||
| ) | ||
|
|
There was a problem hiding this comment.
isPageReadyをdocument.readyState === "complete"で判定していますが、manifest の既定run_atはdocument_idleのため、実行時点でreadyStateがすでにcompleteになっているケースが多く、この条件が実質的に効かない可能性があります。- さらに、この判定は Shadow DOM に挿入している
icons.css/content_script.cssの fetch・style 挿入完了とは無関係なので、「CSS適用前に SVG が巨大表示される」事象を確実に防げません。 - 対応案として、CSS 挿入処理(
content_script.tsxのinsertCss)を Promise 化して完了通知(カスタムイベント発火、または ShadowRoot へdata-styles-ready付与など)を出し、このコンポーネント側はその通知を待って描画を解禁する形が確実です。
| const [isPageReady, setIsPageReady] = useState( | |
| document.readyState === "complete", | |
| ) | |
| const [isPageReady, setIsPageReady] = useState(false) |
There was a problem hiding this comment.
@copilot
対応案でもいですが、すこし処理が複雑、かつ分散します。
別案として、OpenInTab.tsxの要素自体のstyleで非表示化し、cssが読み込まれたらそこで表示する方式はどうですか?
There was a problem hiding this comment.
ご提案の方式に変更しました(commit 21687a9)。
変更内容:
OpenInTab.tsx:isPageReadyステートとloadイベントリスナーを削除し、div にstyle={{ visibility: "hidden" }}を追加OpenInTab.css:.OpenInTabにvisibility: visible !importantを追加
これにより、CSS適用前は visibility: hidden(インラインスタイルが優先)でアイコンが非表示となり、content_script.css がシャドウDOMに注入された後は CSS の visibility: visible !important がインラインスタイルを上書きして表示されます。
Co-authored-by: ujiro99 <677231+ujiro99@users.noreply.github.com>
When a popup window is opened via shortcut key, the content script renders React immediately at
document_idle, but the shadow DOM CSS files (icons.css,content_script.css) are fetched asynchronously. SincecanOpenInTabresolves quickly,OpenInTabrenders before CSS is applied — causing the raw SVG (viewBox="0 0 512 512") to display at full size.Changes
OpenInTab.tsx: Addstyle={{ visibility: "hidden" }}inline style to the outer div so the element is hidden before CSS is applied.OpenInTab.css: Addvisibility: visible !importantto.OpenInTabso that once the CSS file is injected into the shadow DOM, it overrides the inline style and reveals the button at the correct size.Before CSS loads, the inline
visibility: hiddentakes precedence and the element is invisible. Oncecontent_script.cssis injected into the shadow DOM, the CSS rule's!importantoverrides the inline style and the button appears at the correct size.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.