Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove multiplayer feature switches #4803

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions editor/src/components/canvas/dom-walker-caching.spec.browser2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,18 @@ describe('Dom-walker Caching', () => {
UPDATE_FROM_WORKER
],
SAVE_DOM_REPORT,
UPDATE_TOP_LEVEL_ELEMENTS_FROM_COLLABORATION_UPDATE,
UPDATE_EXPORTS_DETAIL_FROM_COLLABORATION_UPDATE,
UPDATE_IMPORTS_FROM_COLLABORATION_UPDATE,
SET_CANVAS_FRAMES,
SAVE_DOM_REPORT,
MERGE_WITH_PREV_UNDO: [
UPDATE_FROM_WORKER
],
SAVE_DOM_REPORT
SAVE_DOM_REPORT,
UPDATE_TOP_LEVEL_ELEMENTS_FROM_COLLABORATION_UPDATE,
UPDATE_EXPORTS_DETAIL_FROM_COLLABORATION_UPDATE,
UPDATE_IMPORTS_FROM_COLLABORATION_UPDATE
]`)

const saveDomReportActions = renderResult
Expand Down Expand Up @@ -211,12 +217,18 @@ describe('Dom-walker Caching', () => {
UPDATE_FROM_WORKER
],
SAVE_DOM_REPORT,
UPDATE_TOP_LEVEL_ELEMENTS_FROM_COLLABORATION_UPDATE,
UPDATE_EXPORTS_DETAIL_FROM_COLLABORATION_UPDATE,
UPDATE_IMPORTS_FROM_COLLABORATION_UPDATE,
SET_CANVAS_FRAMES,
SAVE_DOM_REPORT,
MERGE_WITH_PREV_UNDO: [
UPDATE_FROM_WORKER
],
SAVE_DOM_REPORT
SAVE_DOM_REPORT,
UPDATE_TOP_LEVEL_ELEMENTS_FROM_COLLABORATION_UPDATE,
UPDATE_EXPORTS_DETAIL_FROM_COLLABORATION_UPDATE,
UPDATE_IMPORTS_FROM_COLLABORATION_UPDATE
]`)

expect(saveDomReportActions.length).toBe(4)
Expand Down
17 changes: 7 additions & 10 deletions editor/src/components/editor/collaborative-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { v4 as UUID } from 'uuid'
import { IS_TEST_ENVIRONMENT, UTOPIA_BACKEND } from '../../common/env-vars'
import { HEADERS, MODE } from '../../common/server'
import { isFeatureEnabled } from '../../utils/feature-switches'
import type { EditorDispatch } from './action-types'
import { showToast } from './actions/action-creators'
import { notice } from '../common/notice'
Expand Down Expand Up @@ -109,7 +108,7 @@ async function claimControlOverProject(projectID: string | null): Promise<boolea
if (IS_TEST_ENVIRONMENT) {
return true
}
if (projectID == null || !isFeatureEnabled('Baton Passing For Control')) {
if (projectID == null) {
return null
}

Expand All @@ -126,7 +125,7 @@ async function snatchControlOverProject(projectID: string | null): Promise<boole
if (IS_TEST_ENVIRONMENT) {
return true
}
if (projectID == null || !isFeatureEnabled('Baton Passing For Control')) {
if (projectID == null) {
return null
}

Expand All @@ -143,7 +142,7 @@ async function releaseControlOverProject(projectID: string | null): Promise<void
if (IS_TEST_ENVIRONMENT) {
return
}
if (projectID == null || !isFeatureEnabled('Baton Passing For Control')) {
if (projectID == null) {
return
}

Expand All @@ -162,13 +161,11 @@ async function clearAllControlFromThisEditor(): Promise<void> {
if (IS_TEST_ENVIRONMENT) {
return
}
if (isFeatureEnabled('Baton Passing For Control')) {
const request = clearAllOfCollaboratorsControl(collaborationEditor)
const request = clearAllOfCollaboratorsControl(collaborationEditor)

const response = await callCollaborationEndpoint(request)
if (response.type !== 'RELEASE_CONTROL_RESULT') {
throw new Error(`Unexpected response: ${JSON.stringify(response)}`)
}
const response = await callCollaborationEndpoint(request)
if (response.type !== 'RELEASE_CONTROL_RESULT') {
throw new Error(`Unexpected response: ${JSON.stringify(response)}`)
}
}

Expand Down
5 changes: 2 additions & 3 deletions editor/src/components/editor/global-shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ import { isRight } from '../../core/shared/either'
import type { ElementPathTrees } from '../../core/shared/element-path-tree'
import { createPasteToReplacePostActionActions } from '../canvas/canvas-strategies/post-action-options/post-action-options'
import { wrapInDivStrategy } from './wrap-in-callbacks'
import { isFeatureEnabled } from '../../utils/feature-switches'
import { type ProjectServerState } from './store/project-server-state'
import { allowedToEditProject } from './store/collaborative-editing'
import { hasCommentPermission, getPermissions } from './store/permissions'
import { hasCommentPermission } from './store/permissions'

function updateKeysPressed(
keysPressed: KeysPressed,
Expand Down Expand Up @@ -368,7 +367,7 @@ export function handleKeyDown(
preventBrowserShortcuts(editor, event)

const allowedToEdit = allowedToEditProject(loginState, projectServerState)
const canComment = isFeatureEnabled('Multiplayer') && hasCommentPermission(loginState)
const canComment = hasCommentPermission(loginState)

// Ensure that any key presses are appropriately recorded.
const key = Keyboard.keyCharacterForCode(event.keyCode)
Expand Down
3 changes: 1 addition & 2 deletions editor/src/components/editor/liveblocks-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IS_TEST_ENVIRONMENT, UTOPIA_BACKEND } from '../../common/env-vars'
import { HEADERS, MODE } from '../../common/server'
import { cachedPromise } from '../../core/shared/promise-utils'
import { isFeatureEnabled } from '../../utils/feature-switches'

let isLiveblocksEnabledOnServer: boolean = false

Expand Down Expand Up @@ -41,5 +40,5 @@ export async function checkLiveblocksEnabledOnServer(): Promise<void> {
}

export function isLiveblocksEnabled(): boolean {
return isLiveblocksEnabledOnServer && isFeatureEnabled('Multiplayer')
return isLiveblocksEnabledOnServer
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { setFeatureForUnitTestsUseInDescribeBlockOnly, wait } from '../../../utils/utils.test-utils'
import { Y } from '../../../core/shared/yjs'
import {
RevisionsState,
Expand All @@ -22,7 +21,6 @@ import { testParseCode } from '../../../core/workers/parser-printer/parser-print
import {
deleteFileFromCollaboration,
updateExportsDetailFromCollaborationUpdate,
updateFile,
updateFileFromCollaboration,
updateImportsFromCollaborationUpdate,
updateTopLevelElementsFromCollaborationUpdate,
Expand Down Expand Up @@ -111,8 +109,6 @@ async function runAddHookForProjectChangesTest(test: AddHookForProjectChangesTes
}

describe('addHookForProjectChanges', () => {
setFeatureForUnitTestsUseInDescribeBlockOnly('Multiplayer', true)

it('adding file causes it to be added to the project contents', async () => {
const code = 'export const A = <div />'
const newParsedCode = testParseCode(code)
Expand Down
14 changes: 4 additions & 10 deletions editor/src/components/editor/store/collaborative-editing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ export function collateCollaborativeProjectChanges(
}
}
}
if (isFeatureEnabled('Multiplayer')) {
if (oldContents != newContents) {
zipContentsTree(oldContents, newContents, onElement)
}
if (oldContents != newContents) {
zipContentsTree(oldContents, newContents, onElement)
}

return changesToProcess
Expand Down Expand Up @@ -773,12 +771,8 @@ export function allowedToEditProject(
loginState: LoginState,
serverState: ProjectServerState,
): boolean {
if (isFeatureEnabled('Baton Passing For Control')) {
if (isLoggedIn(loginState)) {
return serverState.currentlyHolderOfTheBaton
} else {
return checkIsMyProject(serverState)
}
if (isLoggedIn(loginState)) {
return serverState.currentlyHolderOfTheBaton
} else {
return checkIsMyProject(serverState)
}
Expand Down
7 changes: 1 addition & 6 deletions editor/src/components/editor/store/editor-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ import type { ProjectServerState } from './project-server-state'
import type { ReparentTargetForPaste } from '../../canvas/canvas-strategies/strategies/reparent-utils'
import { GridMenuWidth } from '../../canvas/stored-layout'
import type { VariablesInScope } from '../../canvas/ui-jsx-canvas'
import { isFeatureEnabled } from '../../../utils/feature-switches'
import type { ActiveFrame } from '../../canvas/commands/set-active-frames-command'
import { Y } from '../../../core/shared/yjs'
import { removeUnusedImportsForRemovedElement } from '../import-utils'
Expand Down Expand Up @@ -442,12 +441,8 @@ export function emptyCollaborativeEditingSupportSession(): CollaborativeEditingS
}

export function emptyCollaborativeEditingSupport(): CollaborativeEditingSupport {
let session: CollaborativeEditingSupportSession | null = null
if (isFeatureEnabled('Multiplayer')) {
session = emptyCollaborativeEditingSupportSession()
}
return {
session: session,
session: emptyCollaborativeEditingSupportSession(),
}
}

Expand Down
39 changes: 15 additions & 24 deletions editor/src/components/editor/store/project-server-state.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as React from 'react'
import type { ProjectListing } from '../../../common/persistence'
import { IS_TEST_ENVIRONMENT } from '../../../common/env-vars'
import { fetchProjectMetadata } from '../../../common/server'
import type { EditorDispatch } from '../action-types'
import { updateProjectServerState } from '../actions/action-creators'
import { checkProjectOwned, projectIsStoredLocally } from '../persistence/persistence-backend'
import type { ProjectOwnership } from '../persistence/generic/persistence-types'
import { isFeatureEnabled } from '../../../utils/feature-switches'
import { CollaborationEndpoints } from '../collaborative-endpoints'

export interface ProjectMetadataFromServer {
Expand Down Expand Up @@ -174,22 +172,17 @@ function restartServerStateWatcher(
forkedFromProjectId: string | null,
dispatch: EditorDispatch,
): void {
if (isFeatureEnabled('Baton Passing For Control')) {
void updateProjectServerStateInStore(loggedIn, projectId, forkedFromProjectId, dispatch)
// Reset the multiplier if triggered from outside of `restartWatcherInterval`.
currentWatcherIntervalMultiplier = 1

function restartWatcherInterval(): void {
if (serverStateWatcherInstance != null) {
window.clearInterval(serverStateWatcherInstance)
}
serverStateWatcherInstance = window.setInterval(() => {
void updateProjectServerStateInStore(
loggedIn,
projectId,
forkedFromProjectId,
dispatch,
).then((result) => {
void updateProjectServerStateInStore(loggedIn, projectId, forkedFromProjectId, dispatch)
// Reset the multiplier if triggered from outside of `restartWatcherInterval`.
currentWatcherIntervalMultiplier = 1

function restartWatcherInterval(): void {
if (serverStateWatcherInstance != null) {
window.clearInterval(serverStateWatcherInstance)
}
serverStateWatcherInstance = window.setInterval(() => {
void updateProjectServerStateInStore(loggedIn, projectId, forkedFromProjectId, dispatch).then(
(result) => {
// If there's a failure, then double the multiplier and recreate the interval.
if (result === 'failure') {
if (currentWatcherIntervalMultiplier < 10) {
Expand All @@ -206,13 +199,11 @@ function restartServerStateWatcher(
restartWatcherInterval()
}
}
})
}, baseWatcherIntervalTime * currentWatcherIntervalMultiplier)
}
restartWatcherInterval()
} else {
void updateProjectServerStateInStore(loggedIn, projectId, forkedFromProjectId, dispatch)
},
)
}, baseWatcherIntervalTime * currentWatcherIntervalMultiplier)
}
restartWatcherInterval()
}

export const ProjectServerStateUpdater = React.memo(
Expand Down
10 changes: 2 additions & 8 deletions editor/src/core/commenting/comment-hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
canvasPoint,
getCanvasPointWithCanvasOffset,
isNotNullFiniteRectangle,
localPoint,
nullIfInfinity,
} from '../shared/math-utils'
import { MetadataUtils } from '../model/element-metadata-utils'
Expand All @@ -35,15 +34,10 @@ import * as EP from '../shared/element-path'
import { getCurrentTheme } from '../../components/editor/store/editor-state'
import { useMyUserId } from '../shared/multiplayer-hooks'
import { usePermissions } from '../../components/editor/store/permissions'
import { isFeatureEnabled } from '../../utils/feature-switches'
import { modify, toFirst } from '../shared/optics/optic-utilities'
import { filtered, fromObjectField, traverseArray } from '../shared/optics/optic-creators'
import { foldEither } from '../shared/either'
import {
SceneThreadMetadata,
isCanvasThreadMetadata,
liveblocksThreadMetadataToUtopia,
} from './comment-types'
import { isCanvasThreadMetadata, liveblocksThreadMetadataToUtopia } from './comment-types'

export function useCanvasCommentThreadAndLocation(comment: CommentId): {
location: CanvasPoint | null
Expand Down Expand Up @@ -451,7 +445,7 @@ export function useDataThemeAttributeOnBody() {
export function useCanComment() {
const canComment = usePermissions().comment

return isFeatureEnabled('Multiplayer') && canComment
return canComment
}

export function getThreadLocationOnCanvas(
Expand Down
Loading
Loading