Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 6 additions & 16 deletions packages/void/src/pages/navigation-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,23 +706,13 @@ export async function createPageNavigationEngine(
window.location.href = method === 'GET' ? url : response.url;
return undefined;
}
commitTarget.fetchUrl = redirectUrl.pathname + redirectUrl.search;
// The browser already followed the redirect: treat the final response as the GET
// result for the destination instead of fetching it a second time.
method = 'GET';
fetchUrl = redirectUrl.pathname + redirectUrl.search;
url = fetchUrl + redirectUrl.hash;
commitTarget.fetchUrl = fetchUrl;
commitTarget.hash = redirectUrl.hash;
return loadNavigationShell(
id,
redirectUrl.pathname + redirectUrl.search + redirectUrl.hash,
redirectUrl.pathname + redirectUrl.search,
'GET',
{
preserveScroll: options.preserveScroll,
preserveState: options.preserveState,
replace: options.replace,
viewTransition: options.viewTransition,
},
signal,
commitTarget,
deferredRegistry,
);
}

if (response && method !== 'GET' && !response.ok) {
Expand Down
9 changes: 3 additions & 6 deletions packages/void/test/unit/pages-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,18 +1131,15 @@ describe('createVoidRouter other-origin visits', () => {

it('follows a same-host Capacitor action redirect in place', async () => {
const { router, fetchMock, applyUpdate } = await createRouter('capacitor://localhost');
const response = pageJson({});
const response = pageJson({ component: 'users', props: { users: [] } });
Object.defineProperties(response, {
redirected: { value: true },
url: { value: 'capacitor://localhost/users' },
});
fetchMock.mockResolvedValueOnce(response);
await router.visit('/submit', { method: 'POST' });
expect(fetchMock).toHaveBeenNthCalledWith(
2,
'/users',
expect.objectContaining({ method: 'GET' }),
);
// The redirect destination is rendered from the followed response, not fetched again.
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(applyUpdate).toHaveBeenCalledTimes(1);
expect(window.location.href).toBeUndefined();
});
Expand Down