♻️(frontend) clean Sonar warnings in PiP overlay primitives

Replace verbose checks and nested ternaries with clearer PiP-safe logic.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Cyril
2026-05-06 13:23:41 +02:00
parent c239a7f2e5
commit 47ec78973b
6 changed files with 26 additions and 28 deletions
@@ -33,11 +33,11 @@ const copyStyles = (source: Document, target: Document) => {
} }
const syncThemeAttribute = (source: Document, target: Document) => { const syncThemeAttribute = (source: Document, target: Document) => {
const theme = source.documentElement.getAttribute('data-lk-theme') const theme = source.documentElement.dataset.lkTheme
if (theme) { if (theme) {
target.documentElement.setAttribute('data-lk-theme', theme) target.documentElement.dataset.lkTheme = theme
} else { } else {
target.documentElement.removeAttribute('data-lk-theme') delete target.documentElement.dataset.lkTheme
} }
} }
@@ -26,5 +26,5 @@ export const RoomPiP = (): ReactNode => {
onClose: close, onClose: close,
children: <PipView />, children: <PipView />,
}) })
return portal as ReactNode return portal
} }
@@ -5,7 +5,8 @@ import { roomPiPStore } from '@/stores/roomPiP'
export const useRoomPiP = () => { export const useRoomPiP = () => {
const { isOpen } = useSnapshot(roomPiPStore) const { isOpen } = useSnapshot(roomPiPStore)
const isSupported = const isSupported =
typeof globalThis !== 'undefined' && 'documentPictureInPicture' in globalThis typeof globalThis !== 'undefined' &&
'documentPictureInPicture' in globalThis
const open = useCallback(() => { const open = useCallback(() => {
roomPiPStore.isOpen = true roomPiPStore.isOpen = true
+1 -2
View File
@@ -28,8 +28,7 @@ export const Menu = ({
// Detect if we're in PiP: portal container is in a different document than the main window // Detect if we're in PiP: portal container is in a different document than the main window
const isInPiP = useMemo( const isInPiP = useMemo(
() => () =>
portalContainer && !!portalContainer?.ownerDocument &&
portalContainer.ownerDocument &&
portalContainer.ownerDocument !== document, portalContainer.ownerDocument !== document,
[portalContainer] [portalContainer]
) )
@@ -1,4 +1,4 @@
import { type ReactNode } from 'react' import { type ReactElement, type ReactNode } from 'react'
import { import {
OverlayArrow, OverlayArrow,
Tooltip as RACTooltip, Tooltip as RACTooltip,
@@ -27,11 +27,12 @@ export const TooltipWrapper = ({
tooltipType, tooltipType,
children, children,
}: { }: {
children: ReactNode children: ReactElement
} & TooltipWrapperProps) => { } & TooltipWrapperProps) => {
const portalContainer = useOverlayPortalContainer() const portalContainer = useOverlayPortalContainer()
const isExternalDocument = const isExternalDocument =
portalContainer && portalContainer.ownerDocument !== document !!portalContainer?.ownerDocument &&
portalContainer.ownerDocument !== document
return tooltip ? ( return tooltip ? (
isExternalDocument ? ( isExternalDocument ? (
@@ -113,6 +113,20 @@ export const VisualOnlyTooltip = ({
}) })
: children : children
const translateY = effectiveBottom ? 'translateY(0)' : 'translateY(-100%)'
const translateXY = effectiveBottom
? 'translate(-50%, 0)'
: 'translate(-50%, -100%)'
const tooltipInlineStyle: React.CSSProperties & Record<string, string> = {
top: `${position?.top}px`,
left: computedStyle ? `${computedStyle.left}px` : `${position?.left}px`,
transform: computedStyle ? translateY : translateXY,
...(computedStyle
? { '--tooltip-arrow-left': `${computedStyle.arrowLeft}px` }
: null),
}
return ( return (
<> <>
<div <div
@@ -160,24 +174,7 @@ export const VisualOnlyTooltip = ({
}), }),
}, },
})} })}
style={{ style={tooltipInlineStyle}
top: `${position.top}px`,
left: computedStyle
? `${computedStyle.left}px`
: `${position.left}px`,
transform: computedStyle
? effectiveBottom
? 'translateY(0)'
: 'translateY(-100%)'
: effectiveBottom
? 'translate(-50%, 0)'
: 'translate(-50%, -100%)',
...(computedStyle
? {
'--tooltip-arrow-left': `${computedStyle.arrowLeft}px`,
}
: null),
}}
> >
{tooltip} {tooltip}
</div>, </div>,