Skip to content

Commit

Permalink
move roomStatus check into MultiplayerWrapper (#4760)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrmendy authored Jan 18, 2024
1 parent 036e904 commit 82013b6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 36 deletions.
13 changes: 3 additions & 10 deletions editor/src/components/canvas/controls/new-canvas-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ export const NewCanvasControls = React.memo((props: NewCanvasControlsProps) => {

const ref = React.useRef<HTMLDivElement | null>(null)

const roomStatus = useStatus()

const multiplayerActive = isFeatureEnabled('Multiplayer') && roomStatus === 'connected'

if (isLiveMode(canvasControlProps.editorMode) && !canvasControlProps.keysPressed.cmd) {
return (
<div
Expand Down Expand Up @@ -256,12 +252,9 @@ export const NewCanvasControls = React.memo((props: NewCanvasControlsProps) => {
<ElementContextMenu contextMenuInstance='context-menu-canvas' />
<ElementContextMenu contextMenuInstance='context-menu-canvas-no-selection' />
</div>
{when(
roomStatus === 'connected',
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<MultiplayerPresence />
</MultiplayerWrapper>,
)}
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<MultiplayerPresence />
</MultiplayerWrapper>
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ const RemixSceneLabel = React.memo<RemixSceneLabelProps>((props) => {

const [navigationData] = useAtom(RemixNavigationAtom)

const roomStatus = useStatus()
const currentPath = (navigationData[EP.toString(props.target)] ?? null)?.location.pathname

const pathLabel = getRemixLocationLabel(currentPath)
Expand Down Expand Up @@ -275,12 +274,9 @@ const RemixSceneLabel = React.memo<RemixSceneLabelProps>((props) => {

return (
<CanvasOffsetWrapper>
{when(
roomStatus === 'connected',
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<RemixScenePathUpdater targetPathString={EP.toString(props.target)} />
</MultiplayerWrapper>,
)}
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<RemixScenePathUpdater targetPathString={EP.toString(props.target)} />
</MultiplayerWrapper>
<FlexRow
onMouseOver={labelSelectable ? onMouseOver : NO_OP}
onMouseOut={labelSelectable ? onMouseLeave : NO_OP}
Expand Down
1 change: 0 additions & 1 deletion editor/src/components/canvas/multiplayer-presence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
useOthersListener,
useRoom,
useSelf,
useStatus,
useStorage,
useUpdateMyPresence,
} from '../../../liveblocks.config'
Expand Down
20 changes: 3 additions & 17 deletions editor/src/components/editor/canvas-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,6 @@ function switchToSelectModeCloseMenus(dispatch: EditorDispatch) {

export const WrapInDivButtonTestId = 'wrap-in-div-button'

const UnreadThreadsIndicatorWrapper = React.memo(() => {
const roomStatus = useStatus()

// without the roomStatus check, Liveblocks will flood the server with authentication requests
return (
<>
{when(
roomStatus === 'connected',
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<UnreadThreadsIndicator />
</MultiplayerWrapper>,
)}
</>
)
})

const UnreadThreadsIndicator = React.memo(() => {
const canvasToolbarMode = useToolbarMode()

Expand Down Expand Up @@ -571,7 +555,9 @@ export const CanvasToolbar = React.memo(() => {
disabled={commentButtonDisabled}
/>
</Tooltip>
<UnreadThreadsIndicatorWrapper />
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<UnreadThreadsIndicator />
</MultiplayerWrapper>
</div>,
)}
<Separator />
Expand Down
7 changes: 6 additions & 1 deletion editor/src/utils/multiplayer-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CommentProps } from '@liveblocks/react-comments'
import { Comment } from '@liveblocks/react-comments'
import type { CSSProperties } from 'react'
import React from 'react'
import type { UserMeta } from '../../liveblocks.config'
import { useStatus, type UserMeta } from '../../liveblocks.config'
import { MultiplayerAvatar } from '../components/user-bar'
import {
multiplayerColorFromIndex,
Expand All @@ -16,6 +16,11 @@ type Fallback = NonNullable<React.ReactNode> | null

export const MultiplayerWrapper = React.memo(
(props: { errorFallback: Fallback; suspenseFallback: Fallback; children: any }) => {
const roomStatus = useStatus()
if (roomStatus !== 'connected') {
return null
}

return (
<ErrorBoundary fallback={props.errorFallback}>
<ClientSideSuspense fallback={props.suspenseFallback}>
Expand Down

0 comments on commit 82013b6

Please sign in to comment.