Skip to content

Commit bb51a1f

Browse files
committed
chore: rename pjax
1 parent ae3b7cc commit bb51a1f

26 files changed

+97
-79
lines changed

__tests__/cases/non-parallel/pjax.commits-page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectToFind, expectToNotFind, sleep, waitForLegacyPJAXRedirect } from '../../utils'
1+
import { expectToFind, expectToNotFind, sleep, waitForRedirect } from '../../utils'
22

33
describe(`in Gitako project page`, () => {
44
beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako/commits/develop'))
@@ -10,7 +10,7 @@ describe(`in Gitako project page`, () => {
1010
)
1111
if (commitLinks.length < 2) throw new Error(`No enough commits`)
1212
commitLinks[i].click()
13-
await waitForLegacyPJAXRedirect()
13+
await waitForRedirect()
1414
await expectToFind('div.commit')
1515
await sleep(1000)
1616

__tests__/cases/non-parallel/pjax.files-page.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { expectToFind, expectToNotFind, sleep, waitForLegacyPJAXRedirect } from '../../utils'
1+
import {
2+
expectToFind,
3+
expectToNotFind,
4+
sleep, waitForRedirect
5+
} from '../../utils'
26

37
describe(`in Gitako project page`, () => {
48
beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako/tree/develop/src'))
@@ -9,7 +13,7 @@ describe(`in Gitako project page`, () => {
913
`.js-details-container div[role="row"] div[role="rowheader"] a[title*="."]`,
1014
)
1115
if (commitLinks.length < 2) throw new Error(`No enough files`)
12-
await waitForLegacyPJAXRedirect(async () => {
16+
await waitForRedirect(async () => {
1317
await commitLinks[i].click()
1418
})
1519
await expectToFind('table.js-file-line-container')

__tests__/cases/non-parallel/pjax.general.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
expandFloatModeSidebar,
44
patientClick,
55
selectFileTreeItem,
6-
sleep,
7-
waitForLegacyPJAXRedirect,
6+
sleep, waitForRedirect
87
} from '../../utils'
98

109
describe(`in Gitako project page`, () => {
@@ -15,14 +14,14 @@ describe(`in Gitako project page`, () => {
1514

1615
await expandFloatModeSidebar()
1716
await patientClick(selectFileTreeItem('src/analytics.ts'))
18-
await waitForLegacyPJAXRedirect()
17+
await waitForRedirect()
1918
await collapseFloatModeSidebar()
2019

2120
await page.click('a[data-selected-links^="repo_issues "]')
22-
await waitForLegacyPJAXRedirect()
21+
await waitForRedirect()
2322

2423
await page.click('a[data-selected-links^="repo_pulls "]')
25-
await waitForLegacyPJAXRedirect()
24+
await waitForRedirect()
2625

2726
page.goBack()
2827
await sleep(1000)

__tests__/cases/non-parallel/pjax.internal.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
expectToNotFind,
55
patientClick,
66
selectFileTreeItem,
7-
sleep,
8-
waitForLegacyPJAXRedirect,
7+
sleep, waitForRedirect
98
} from '../../utils'
109

1110
describe(`in Gitako project page`, () => {
@@ -16,12 +15,12 @@ describe(`in Gitako project page`, () => {
1615

1716
await expandFloatModeSidebar()
1817
await patientClick(selectFileTreeItem('.babelrc'))
19-
await waitForLegacyPJAXRedirect()
18+
await waitForRedirect()
2019

2120
// The selector for file content
2221
await expectToFind('table.js-file-line-container')
2322

24-
await waitForLegacyPJAXRedirect(async () => {
23+
await waitForRedirect(async () => {
2524
await sleep(1000) // This prevents failing in some cases due to some mystery scheduling issue of puppeteer or jest
2625
page.goBack()
2726
})

__tests__/cases/non-parallel/project-page.gitako.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
expectToFind,
44
expectToNotFind,
55
scroll,
6-
selectFileTreeItem,
6+
selectFileTreeItem
77
} from '../../utils'
88

99
describe(`in Gitako project page`, () => {
@@ -28,7 +28,7 @@ describe(`in Gitako project page`, () => {
2828
const box = await filesEle?.boundingBox()
2929
if (box) {
3030
await page.mouse.move(box.x + 40, box.y + 40)
31-
await scroll({ totalDistance: 7000, stepDistance: 100 })
31+
await scroll({ totalDistance: 10000, stepDistance: 100 })
3232

3333
// node of tsconfig.json should be rendered now
3434
await expectToFind(selectFileTreeItem('tsconfig.json'))

__tests__/cases/parallel/expand-to-target.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { expectToFind, selectFileTreeItem, sleep, waitForLegacyPJAXRedirect } from '../../utils'
1+
import { expectToFind, selectFileTreeItem, sleep, waitForRedirect } from '../../utils'
22

33
describe(`in Gitako project page`, () => {
44
beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako/tree/develop/src'))
55

6-
it('expand to target on load and after PJAX', async () => {
6+
it('expand to target on load and after redirect', async () => {
77
await sleep(3000)
88

99
// Expect Gitako sidebar to have expanded src to see contents
@@ -12,7 +12,7 @@ describe(`in Gitako project page`, () => {
1212
await page.click(
1313
`.js-details-container div[role="row"] div[role="rowheader"] [title="components"]`,
1414
)
15-
await waitForLegacyPJAXRedirect()
15+
await waitForRedirect()
1616

1717
// Expect Gitako sidebar to have expanded components and see contents
1818
await expectToFind(selectFileTreeItem('src/components/Gitako.tsx'))

__tests__/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ export async function waitForLegacyPJAXRedirect(action?: () => void | Promise<vo
7171
return promise
7272
}
7373

74+
export async function waitForTurboRedirect(action?: () => void | Promise<void>) {
75+
const promise = once('turbo:load', 'document')
76+
await action?.()
77+
return promise
78+
}
79+
80+
export async function waitForRedirect(action?: () => void | Promise<void>) {
81+
let fired = false
82+
const $action =
83+
action &&
84+
(() => {
85+
if (fired) return
86+
fired = true
87+
return action()
88+
})
89+
return Promise.race([waitForLegacyPJAXRedirect($action), waitForTurboRedirect($action)])
90+
}
91+
7492
export function selectFileTreeItem(path: string): string {
7593
return `.gitako-side-bar .files a[title="${path}"]`
7694
}

src/components/FileExplorer/Node.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const Node = React.memo(function Node({
5252
title={node.path}
5353
target={node.type === 'commit' ? '_blank' : undefined}
5454
rel="noopener noreferrer"
55-
{...platform.delegatePJAXProps?.({ node })}
55+
{...platform.delegateFastRedirectAnchorProps?.({ node })}
5656
>
5757
<div className={'node-item-label'}>
5858
<NodeItemIcon node={node} open={expanded} loading={loading} />

src/components/FileExplorer/hooks/useHandleKeyDown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import * as DOMHelper from 'utils/DOMHelper'
33
import { OperatingSystems, os } from 'utils/general'
4-
import { loadWithPJAX } from 'utils/hooks/usePJAX'
4+
import { loadWithFastRedirect } from 'utils/hooks/useFastRedirect'
55
import { VisibleNodes } from 'utils/VisibleNodesGenerator'
66
import { AlignMode } from '../useVirtualScroll'
77
import { VisibleNodesGeneratorMethods } from './useVisibleNodesGeneratorMethods'
@@ -100,7 +100,7 @@ export function useHandleKeyDown(
100100
} else if (focusedNode.type === 'blob') {
101101
const focusedNodeElement = DOMHelper.findNodeElement(focusedNode, event.currentTarget)
102102
if (focusedNodeElement && focusedNode.url)
103-
loadWithPJAX(focusedNode.url, focusedNodeElement)
103+
loadWithFastRedirect(focusedNode.url, focusedNodeElement)
104104
} else if (focusedNode.type === 'commit') {
105105
window.open(focusedNode.url)
106106
}
@@ -119,7 +119,7 @@ export function useHandleKeyDown(
119119
event.currentTarget,
120120
)
121121
if (focusedNodeElement && focusedNode.url)
122-
loadWithPJAX(focusedNode.url, focusedNodeElement)
122+
loadWithFastRedirect(focusedNode.url, focusedNodeElement)
123123
} else if (focusedNode.type === 'commit') {
124124
window.open(focusedNode.url)
125125
}

src/components/FileExplorer/hooks/useOnNodeClick.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useConfigs } from 'containers/ConfigsContext'
22
import * as React from 'react'
33
import { isOpenInNewWindowClick } from 'utils/general'
4-
import { loadWithPJAX } from 'utils/hooks/usePJAX'
4+
import { loadWithFastRedirect } from 'utils/hooks/useFastRedirect'
55
import { AlignMode } from '../useVirtualScroll'
66
import { VisibleNodesGeneratorMethods } from './useVisibleNodesGeneratorMethods'
77

@@ -35,7 +35,7 @@ export function useHandleNodeClick(
3535
const isHashLink = node.url.includes('#')
3636
if (!isHashLink) {
3737
event.preventDefault()
38-
loadWithPJAX(node.url, event.currentTarget)
38+
loadWithFastRedirect(node.url, event.currentTarget)
3939
}
4040
}
4141
break

0 commit comments

Comments
 (0)