From b058e6add90e5e82d1a5eeb910eb33ae376fd984 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Mon, 30 Jun 2025 18:02:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8(frontend)=20replace=20logical=20OR?= =?UTF-8?q?=20with=20nullish=20coalescing=20operator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `||` operators and conditional checks with `??` where appropriate for safer null/undefined handling. Nullish coalescing only triggers for null/undefined values, preventing unexpected behavior with falsy values like 0 or empty strings. --- src/frontend/src/components/AppInitialization.tsx | 2 +- src/frontend/src/components/Avatar.tsx | 2 +- src/frontend/src/components/ErrorScreen.tsx | 2 +- src/frontend/src/features/home/routes/Home.tsx | 2 +- .../src/features/rooms/livekit/hooks/useRaisedHand.ts | 4 ++-- .../src/features/settings/components/SettingsDialog.tsx | 2 +- .../src/features/settings/components/tabs/AccountTab.tsx | 2 +- src/frontend/vite.config.ts | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/components/AppInitialization.tsx b/src/frontend/src/components/AppInitialization.tsx index 5b5b8a49..b52cb9fa 100644 --- a/src/frontend/src/components/AppInitialization.tsx +++ b/src/frontend/src/components/AppInitialization.tsx @@ -14,7 +14,7 @@ export const AppInitialization = () => { support = {}, silence_livekit_debug_logs = false, custom_css_url = '', - } = data || {} + } = data ?? {} useAnalytics(analytics) useSupport(support) diff --git a/src/frontend/src/components/Avatar.tsx b/src/frontend/src/components/Avatar.tsx index 3268b8d0..87a33743 100644 --- a/src/frontend/src/components/Avatar.tsx +++ b/src/frontend/src/components/Avatar.tsx @@ -51,7 +51,7 @@ export const Avatar = ({ style, ...props }: AvatarProps) => { - const initial = name?.trim()?.charAt(0) || '' + const initial = name?.trim()?.charAt(0) ?? '' return (
- + {!!body && (
diff --git a/src/frontend/src/features/home/routes/Home.tsx b/src/frontend/src/features/home/routes/Home.tsx index 6830117f..ecfd243c 100644 --- a/src/frontend/src/features/home/routes/Home.tsx +++ b/src/frontend/src/features/home/routes/Home.tsx @@ -251,7 +251,7 @@ export const Home = () => { setLaterRoomId(null)} /> diff --git a/src/frontend/src/features/rooms/livekit/hooks/useRaisedHand.ts b/src/frontend/src/features/rooms/livekit/hooks/useRaisedHand.ts index 02351caa..0979403a 100644 --- a/src/frontend/src/features/rooms/livekit/hooks/useRaisedHand.ts +++ b/src/frontend/src/features/rooms/livekit/hooks/useRaisedHand.ts @@ -9,7 +9,7 @@ type useRaisedHandProps = { export function useRaisedHand({ participant }: useRaisedHandProps) { // fixme - refactor this part to rely on attributes const { metadata } = useParticipantInfo({ participant }) - const parsedMetadata = JSON.parse(metadata || '{}') + const parsedMetadata = JSON.parse(metadata ?? '{}') const toggleRaisedHand = () => { if (isLocal(participant)) { @@ -19,5 +19,5 @@ export function useRaisedHand({ participant }: useRaisedHandProps) { } } - return { isHandRaised: parsedMetadata.raised || false, toggleRaisedHand } + return { isHandRaised: parsedMetadata.raised ?? false, toggleRaisedHand } } diff --git a/src/frontend/src/features/settings/components/SettingsDialog.tsx b/src/frontend/src/features/settings/components/SettingsDialog.tsx index ec1ef05f..c690a227 100644 --- a/src/frontend/src/features/settings/components/SettingsDialog.tsx +++ b/src/frontend/src/features/settings/components/SettingsDialog.tsx @@ -18,7 +18,7 @@ export const SettingsDialog = (props: SettingsDialogProps) => {

]} />

diff --git a/src/frontend/src/features/settings/components/tabs/AccountTab.tsx b/src/frontend/src/features/settings/components/tabs/AccountTab.tsx index 14bc7b34..a8bb2d19 100644 --- a/src/frontend/src/features/settings/components/tabs/AccountTab.tsx +++ b/src/frontend/src/features/settings/components/tabs/AccountTab.tsx @@ -17,7 +17,7 @@ export const AccountTab = ({ id, onOpenChange }: AccountTabProps) => { const { saveUsername } = usePersistentUserChoices() const room = useRoomContext() const { user, isLoggedIn, logout } = useUser() - const [name, setName] = useState(room?.localParticipant.name || '') + const [name, setName] = useState(room?.localParticipant.name ?? '') const handleOnSubmit = () => { if (room) room.localParticipant.setName(name) diff --git a/src/frontend/vite.config.ts b/src/frontend/vite.config.ts index 9b614f76..eb3dcdbe 100644 --- a/src/frontend/vite.config.ts +++ b/src/frontend/vite.config.ts @@ -9,7 +9,7 @@ export default defineConfig(({ mode }) => { plugins: [react(), tsconfigPaths()], server: { port: parseInt(env.VITE_PORT) || 3000, - host: env.VITE_HOST || 'localhost', + host: env.VITE_HOST ?? 'localhost', allowedHosts: ['.nip.io'], }, }