Skip to content

Commit de3ea24

Browse files
committed
fix(core): frame navigations on redirects
1 parent a3774ef commit de3ea24

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

core/lib/FrameNavigations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export default class FrameNavigations extends TypedEventEmitter<IFrameNavigation
221221
public assignLoaderId(navigation: INavigation, loaderId: string, url?: string): void {
222222
if (!loaderId) return;
223223

224-
this.historyByLoaderId[loaderId] = navigation;
224+
this.historyByLoaderId[loaderId] ??= navigation;
225225
navigation.loaderId = loaderId;
226226
if (
227227
url &&
@@ -306,7 +306,7 @@ export default class FrameNavigations extends TypedEventEmitter<IFrameNavigation
306306
if (!navigation) return;
307307
if (!navigation.loaderId && loaderId) {
308308
navigation.loaderId = loaderId;
309-
this.historyByLoaderId[loaderId] = navigation;
309+
this.historyByLoaderId[loaderId] ??= navigation;
310310
}
311311
if (navigation.stateChanges.has(newStatus)) {
312312
if (statusChangeDate && statusChangeDate < navigation.stateChanges.get(newStatus)) {

core/test/navigation.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,22 @@ perfObserver.observe({ type: 'largest-contentful-paint', buffered: true });
538538
});
539539

540540
describe('PaintingStable tests', () => {
541+
it('should trigger painting stable after a redirect', async () => {
542+
const startingUrl = `${koaServer.baseUrl}/stable-redirect`;
543+
koaServer.get('/stable-redirect', async ctx => {
544+
await new Promise(resolve => setTimeout(resolve, 100));
545+
ctx.redirect('/post-stable-redirect');
546+
});
547+
koaServer.get('/post-stable-redirect', ctx => {
548+
ctx.body = '<html lang="en"><body><h1>So stable</h1></body></html>';
549+
});
550+
const { tab } = await createSession();
551+
const resource = await tab.goto(startingUrl);
552+
await expect(tab.waitForLoad(LocationStatus.PaintingStable)).resolves.toBe(undefined);
553+
expect(resource.request.url).toBe(`${koaServer.baseUrl}/post-stable-redirect`);
554+
expect(resource.isRedirect).toBe(false);
555+
});
556+
541557
it('should trigger a painting stable on a page that never triggers load', async () => {
542558
const { tab } = await createSession();
543559

puppet/test/TestPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IPuppetPage } from '@secret-agent/interfaces/IPuppetPage';
2-
import { ILifecycleEvents, IPuppetFrame } from '@secret-agent/interfaces/IPuppetFrame';
2+
import { IPuppetFrame } from '@secret-agent/interfaces/IPuppetFrame';
33
import { IKeyboardKey } from '@secret-agent/interfaces/IKeyboardLayoutUS';
44
import { keyDefinitions } from '@secret-agent/puppet-chrome/interfaces/USKeyboardLayout';
55
import IPuppetContext from '@secret-agent/interfaces/IPuppetContext';

0 commit comments

Comments
 (0)