web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.19k stars 108 forks source link

[Bug]: there are 2 title tags in the html > head tag of the console #1164

Closed jl917 closed 1 week ago

jl917 commented 2 weeks ago

版本信息

System:
    OS: macOS 14.4
    CPU: (8) arm64 Apple M1
    Memory: 68.33 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Brave Browser: 124.1.65.123
    Chrome: 125.0.6422.142
    Safari: 17.4
  npmPackages:
    rspress: ^1.23.1 => 1.23.1

问题详情

控制台 html > head 标签里有2个title 标签

스크린샷 2024-06-10 오후 9 23 30

一个 head 元素只能包含一个 title 元素 https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/title

复现链接

https://rspress.dev/guide/start/introduction

复现步骤

复现

SoonIter commented 2 weeks ago

Investigation

When overwriting the html template, rspress keeps both html.title and <Helmet /> which is imported from react-helmet-async

https://github.com/web-infra-dev/rspress/blob/150f770aaa3a02407af3ac3e25f0df36ddc4ac59/packages/core/src/node/build.ts#L157-L167

// template.html
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <!--<?- GENERATOR ?>-->
  <!--<?- HEAD ?>-->  ==> be replaced with   `helmet?.title?.toString()`  ==>  <title data-rh="true">Default Title - Index Suffix</title>
  <title>Default Title</title>
</head>

It will only appear in ssg and will be fixed in the next version.