Skip to content
Merged
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
12 changes: 12 additions & 0 deletions packages/react/test/integration/react-pages-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,18 @@ function registerClientTests(getBase: () => string, coverage: 'smoke' | 'full')
document.querySelector('h1')?.textContent?.includes('Welcome'),
);
expect(await page.title()).toBe('Home | React Pages Demo');

await page.click('a[href="/deferred"]');
await page.waitForFunction(() =>
document.querySelector('h1')?.textContent?.includes('Deferred'),
);
expect(await page.title()).toBe('');

await page.goBack();
await page.waitForFunction(() =>
document.querySelector('h1')?.textContent?.includes('Welcome'),
);
expect(await page.title()).toBe('Home | React Pages Demo');
} finally {
await page.context().close();
}
Expand Down
4 changes: 1 addition & 3 deletions packages/void/src/pages/head-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,5 @@ export function applyClientHead(head: HeadDescriptor | undefined): void {
cursor = el.nextSibling as Node | null;
}

if (head?.title !== undefined) {
document.title = head.title;
}
document.title = head?.title ?? '';
}
18 changes: 18 additions & 0 deletions packages/void/test/unit/pages-head-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ describe('head-client', () => {
expect(children).toEqual([]);
});

it('clears document.title when the next head does not set a title', () => {
stubDocumentHead();
document.title = 'Previous Title';

applyClientHead({ link: [{ rel: 'stylesheet', href: '/a.css' }] });

expect(document.title).toBe('');
});

it('clears document.title when the next head is undefined', () => {
stubDocumentHead();
document.title = 'Previous Title';

applyClientHead(undefined);

expect(document.title).toBe('');
});

it('does not preserve tags whose attributes only match through signature delimiters', () => {
const staleStylesheet = new HeadElement('link', {
'data-void-head': '',
Expand Down