Skip to content
Closed
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -5426,6 +5426,112 @@ describe('offlineNavigations build artifacts', () => {
}
})

it('does not serve fallback HTML to offline redirecting server action submissions', async () => {
if (shouldSkipReplayWithCachedNavigations) {
return
}

const buildResult = await next.build()
expect(buildResult.exitCode).toBe(0)

await next.start({ skipBuild: true })

let page: Playwright.Page | undefined
try {
const browser = await next.browser('/docs', {
beforePageLoad(p: Playwright.Page) {
page = p
},
})
await waitForOfflineNavigationServiceWorker(browser, page!)

await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe(
'offline navigations page'
)
expect(
await browser.elementById('action-invalidation-marker').text()
).toBe('action invalidation marker')
})

await browser.eval((messageType) => {
localStorage.removeItem('__nextOfflineNavigationRedirectActionMessages')
navigator.serviceWorker.addEventListener('message', (event) => {
if (event.data?.type === messageType) {
const messages = JSON.parse(
localStorage.getItem(
'__nextOfflineNavigationRedirectActionMessages'
) ?? '[]'
)
messages.push(event.data)
localStorage.setItem(
'__nextOfflineNavigationRedirectActionMessages',
JSON.stringify(messages)
)
}
})
}, OFFLINE_NAVIGATION_FALLBACK_SERVED)

const failedActionRequest = page!.waitForEvent('requestfailed', {
predicate(request) {
return (
request.method() === 'POST' &&
request.url().startsWith(`${next.url}/docs`)
)
},
})

await page!.context().setOffline(true)
await browser
.elementById('redirect-after-offline-navigation-invalidation')
.click()

const request = await failedActionRequest
expect(request.failure()?.errorText).toMatch(
/ERR_INTERNET_DISCONNECTED|NS_ERROR_OFFLINE|offline/i
)

expect(
await browser.eval(() => ({
cache: document.documentElement.getAttribute(
'data-next-offline-navigation-cache'
),
fallback: document.documentElement.hasAttribute(
'data-next-offline-navigation-fallback'
),
fallbackMessages: JSON.parse(
localStorage.getItem(
'__nextOfflineNavigationRedirectActionMessages'
) ?? '[]'
),
marker:
document.getElementById('action-invalidation-marker')
?.textContent ?? null,
miss:
document.getElementById('__NEXT_OFFLINE_NAVIGATION_CACHE_MISS') ===
null
? null
: 'present',
pageText: document.querySelector('p')?.textContent ?? null,
search: location.search,
}))
).toEqual({
cache: null,
fallback: false,
fallbackMessages: [],
marker: 'action invalidation marker',
miss: null,
pageText: 'offline navigations page',
search: '',
})
} finally {
if (page) {
await page.context().setOffline(false)
}
await next.stop()
}
})

it('does not serve fallback HTML to offline form POST navigations', async () => {
if (shouldSkipReplayWithCachedNavigations) {
return
Expand Down
Loading