Skip to content

Commit

Permalink
fix(core): duplicate html title tags during ssg (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Jun 19, 2024
1 parent 8017edd commit c91f6d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions e2e/tests/custom-headers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ test.describe('custom headers', async () => {
}
});

test('should render only one title tag during ssg', async ({ page }) => {
await page.goto(`http://localhost:${appPort}`, {
waitUntil: 'networkidle',
});
const titleDoms = await page.$$('title');
expect(titleDoms.length).toBe(1);
});

test('config headers should be injected', async ({ page }) => {
await page.goto(`http://localhost:${appPort}`, {
waitUntil: 'networkidle',
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export async function renderPages(

const { helmet } = helmetContext.context;
let html = htmlTemplate
// During ssr, we already have the title in react-helmet
.replace(/<title>(.*?)<\/title>/gi, '')
// Don't use `string` as second param
// To avoid some special characters transformed to the marker, such as `$&`, etc.
.replace(APP_HTML_MARKER, () => appHtml)
Expand Down

0 comments on commit c91f6d3

Please sign in to comment.