Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dfdd550

Browse files
authored
Emit missing style warning on VideoConference when in development mode (#720)
1 parent 79d336b commit dfdd550

File tree

7 files changed

+46
-0
lines changed

7 files changed

+46
-0
lines changed

.changeset/slimy-flies-clean.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@livekit/components-react": patch
3+
"@livekit/components-styles": patch
4+
---
5+
6+
Emit missing style warning on VideoConference when in development mode
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as React from 'react';
2+
import { warnAboutMissingStyles } from '../utils';
3+
4+
/**
5+
* @internal
6+
*/
7+
export function useWarnAboutMissingStyles() {
8+
React.useEffect(() => {
9+
warnAboutMissingStyles();
10+
}, []);
11+
}

packages/react/src/prefabs/AudioConference.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { WidgetState } from '@livekit/components-core';
77
import { Chat } from './Chat';
88
import { ParticipantLoop } from '../components';
99
import { useParticipants } from '../hooks';
10+
import { useWarnAboutMissingStyles } from '../hooks/useWarnAboutMissingStyles';
1011

1112
/** @public */
1213
export interface AudioConferenceProps extends React.HTMLAttributes<HTMLDivElement> {}
@@ -34,6 +35,8 @@ export function AudioConference({ ...props }: AudioConferenceProps) {
3435
});
3536
const participants = useParticipants();
3637

38+
useWarnAboutMissingStyles();
39+
3740
return (
3841
<LayoutContextProvider onWidgetChange={setWidgetState}>
3942
<div className="lk-audio-conference" {...props}>

packages/react/src/prefabs/PreJoin.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { LocalUserChoices } from '@livekit/components-core';
1919
import { log } from '@livekit/components-core';
2020
import { ParticipantPlaceholder } from '../assets/images';
2121
import { useMediaDevices, usePersistentUserChoices } from '../hooks';
22+
import { useWarnAboutMissingStyles } from '../hooks/useWarnAboutMissingStyles';
2223

2324
const DEFAULT_USER_CHOICES: LocalUserChoices = {
2425
username: '',
@@ -369,6 +370,8 @@ export function PreJoin({
369370
}
370371
}
371372

373+
useWarnAboutMissingStyles();
374+
372375
return (
373376
<div className="lk-prejoin" {...htmlProps}>
374377
<div className="lk-video-container">

packages/react/src/prefabs/VideoConference.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useCreateLayoutContext } from '../context';
2222
import { usePinnedTracks, useTracks } from '../hooks';
2323
import { Chat } from './Chat';
2424
import { ControlBar } from './ControlBar';
25+
import { useWarnAboutMissingStyles } from '../hooks/useWarnAboutMissingStyles';
2526

2627
/**
2728
* @public
@@ -112,6 +113,8 @@ export function VideoConference({
112113
focusTrack?.publication?.trackSid,
113114
]);
114115

116+
useWarnAboutMissingStyles();
117+
115118
return (
116119
<div className="lk-video-conference" {...props}>
117120
{isWeb() && (

packages/react/src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import { mergeProps as mergePropsReactAria } from './mergeProps';
3+
import { log } from '@livekit/components-core';
34

45
/** @internal */
56
export function isProp<U extends HTMLElement, T extends React.HTMLAttributes<U>>(
@@ -31,3 +32,21 @@ export function cloneSingleChild(
3132
return child;
3233
});
3334
}
35+
36+
/**
37+
* @internal
38+
*/
39+
export function warnAboutMissingStyles(el?: HTMLElement) {
40+
if (
41+
// eslint-disable-next-line turbo/no-undeclared-env-vars
42+
(process?.env?.NODE_ENV === 'dev' || process?.env?.NODE_ENV === 'development') &&
43+
typeof window !== 'undefined'
44+
) {
45+
const target = el ?? document.querySelector('.lk-room-container');
46+
if (target && !getComputedStyle(target).getPropertyValue('--lk-has-imported-styles')) {
47+
log.warn(
48+
"It looks like you're not using the `@livekit/components-styles package`. To render the UI with the default styling, please import it in your layout or page.",
49+
);
50+
}
51+
}
52+
}

packages/styles/scss/components/_room.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
position: relative;
66
width: 100%;
77
height: 100%;
8+
--has-imported-styles: 'true'; // helper var used to warn users if they haven't imported the styles package
89

910
*[class^='lk-'],
1011
*[class*=' lk-'] {

0 commit comments

Comments
 (0)