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

misc: change strategy for link prefetch test #45234

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion packages/next/src/client/use-intersection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export function useIntersection<T extends Element>({
const isDisabled: boolean = disabled || !hasIntersectionObserver

const [visible, setVisible] = useState(false)
// const [element, setElement] = useState<T | null>(null)
const elementRef = useRef<T | null>(null)
const setElement = useCallback((element: T | null) => {
elementRef.current = element
Expand Down
29 changes: 17 additions & 12 deletions test/integration/preload-viewport/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,18 +436,23 @@ describe('Prefetching Links in viewport', () => {
it('should not add an another observer for a prefetched page', async () => {
// info: both `/` and `/de-duped` ref the `/first` page, which we don't
// want to be re-fetched/re-observed.
const browser = await webdriver(appPort, '/')
await browser.eval(`(function() {
window.calledPrefetch = false
window.next.router.prefetch = function() {
window.calledPrefetch = true
return Promise.resolve()
}
window.next.router.push('/de-duped')
})()`)
await waitFor(2 * 1000)
const calledPrefetch = await browser.eval(`window.calledPrefetch`)
expect(calledPrefetch).toBe(false)
const browser = await webdriver(appPort, '/', {
waitHydration: false,
})

let requests = []

browser.on('request', (req) => {
ijjk marked this conversation as resolved.
Show resolved Hide resolved
requests.push(new URL(req.url()).pathname)
})

await waitFor(3 * 1000)
const initialRequests = requests.length
await browser.eval(`window.next.router.push('/de-duped')`)
await waitFor(3 * 1000)
const finalRequests = requests.length

expect(finalRequests).toBe(initialRequests + 1)
})

it('should prefetch with a different asPath for a prefetched page', async () => {
Expand Down