Merge pull request #36034 from overleaf/mj-free-user-intermittent

[web] differentiate free and paid users for intermittent connection timeouts

GitOrigin-RevId: 9c1847ff3dae7290b7c8d1093ef6dc05ae3b76aa
This commit is contained in:
Mathias Jakobsen
2026-09-17 11:43:34 +00:00
committed by Copybot
parent 774f2c8f06
commit 7a5b1da06d
2 changed files with 115 additions and 16 deletions
@@ -2,6 +2,7 @@ import { FC, useState } from 'react'
import { EditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
import { IdeReactContext } from '@/features/ide-react/context/ide-react-context'
import { UnsavedDocsProvider } from '@/features/ide-react/context/unsaved-docs-context'
import { SplitTestProvider } from '@/shared/context/split-test-context'
import { IdeEventEmitter } from '@/features/ide-react/create-ide-event-emitter'
import type { DocumentContainer } from '@/features/ide-react/editor/document-container'
import type { PermissionsLevel } from '@/features/ide-react/types/permissions'
@@ -34,8 +35,26 @@ function makeOpenDocsStub(
function mount(
openDocs = makeOpenDocsStub(),
onSetPermissionsLevel: (level: PermissionsLevel) => void = () => {}
onSetPermissionsLevel: (level: PermissionsLevel) => void = () => {},
{
isPremiumUser = false,
intermittentConnectionImprovementsEnabled = false,
}: {
isPremiumUser?: boolean
intermittentConnectionImprovementsEnabled?: boolean
} = {}
) {
// the provider reads getMeta('ol-user') to decide the lock threshold; the
// `versioning` feature marks a premium user
window.metaAttributesCache.set('ol-user', {
features: isPremiumUser ? { versioning: true } : {},
})
// the provider reads the split test variant via useFeatureFlag
window.metaAttributesCache.set('ol-splitTestVariants', {
'intermittent-connection-improvements':
intermittentConnectionImprovementsEnabled ? 'enabled' : 'default',
})
const debugTimers = { current: {} as Record<string, number> }
const Wrapper: FC = () => {
@@ -53,11 +72,15 @@ function mount(
}))
return (
<IdeReactContext.Provider value={contextValue}>
<EditorManagerContext.Provider value={{ openDocs, debugTimers } as any}>
<UnsavedDocsProvider />
</EditorManagerContext.Provider>
</IdeReactContext.Provider>
<SplitTestProvider>
<IdeReactContext.Provider value={contextValue}>
<EditorManagerContext.Provider
value={{ openDocs, debugTimers } as any}
>
<UnsavedDocsProvider />
</EditorManagerContext.Provider>
</IdeReactContext.Provider>
</SplitTestProvider>
)
}
@@ -117,6 +140,74 @@ describe('<UnsavedDocsProvider />', function () {
cy.get('@setPermissionsLevel').should('have.been.calledWith', 'owner')
})
describe('with intermittent-connection-improvements enabled', function () {
it('does not lock a free user before the raised 120s threshold', function () {
const setPermissionsLevel = cy.stub().as('setPermissionsLevel')
const now = performance.now()
// 100s would exceed the default 30s limit, but not the raised free limit
const openDocs = makeOpenDocsStub([
makeDocStub('doc1', { pendingAt: now - 100_000 }),
])
mount(openDocs, setPermissionsLevel, {
isPremiumUser: false,
intermittentConnectionImprovementsEnabled: true,
})
cy.tick(1000)
cy.get('@setPermissionsLevel').should('not.have.been.called')
})
it('locks a free user after the raised 120s threshold', function () {
const setPermissionsLevel = cy.stub().as('setPermissionsLevel')
const now = performance.now()
const openDocs = makeOpenDocsStub([
makeDocStub('doc1', { pendingAt: now - 121_000 }),
])
mount(openDocs, setPermissionsLevel, {
isPremiumUser: false,
intermittentConnectionImprovementsEnabled: true,
})
cy.tick(1000)
cy.get('@setPermissionsLevel').should('have.been.calledWith', 'readOnly')
})
it('does not lock a premium user before the raised 600s threshold', function () {
const setPermissionsLevel = cy.stub().as('setPermissionsLevel')
const now = performance.now()
// 200s exceeds the free 120s limit, but not the premium 600s limit
const openDocs = makeOpenDocsStub([
makeDocStub('doc1', { pendingAt: now - 200_000 }),
])
mount(openDocs, setPermissionsLevel, {
isPremiumUser: true,
intermittentConnectionImprovementsEnabled: true,
})
cy.tick(1000)
cy.get('@setPermissionsLevel').should('not.have.been.called')
})
it('locks a premium user after the raised 600s threshold', function () {
const setPermissionsLevel = cy.stub().as('setPermissionsLevel')
const now = performance.now()
const openDocs = makeOpenDocsStub([
makeDocStub('doc1', { pendingAt: now - 601_000 }),
])
mount(openDocs, setPermissionsLevel, {
isPremiumUser: true,
intermittentConnectionImprovementsEnabled: true,
})
cy.tick(1000)
cy.get('@setPermissionsLevel').should('have.been.calledWith', 'readOnly')
})
})
it('calls event.preventDefault() on beforeunload when there are unsaved changes', function () {
const openDocs = makeOpenDocsStub([
makeDocStub('doc1', { pendingAt: performance.now() - 5_000 }),