Skip to content

Comments

feat: add headTagInsertCheck warning#16555

Merged
bluwy merged 2 commits intovitejs:mainfrom
PengBoUESTC:feature/add-warning-for-html-inject
May 29, 2024
Merged

feat: add headTagInsertCheck warning#16555
bluwy merged 2 commits intovitejs:mainfrom
PengBoUESTC:feature/add-warning-for-html-inject

Conversation

@PengBoUESTC
Copy link
Contributor

Description

add warning message for applyHtmlTransforms.

there will be an abnormal scene, when we try to use some tags in head element, such as div.

here is an example:

<!DOCTYPE html>
<html>
  <head>
    <div>test div in head</div>
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  </head>

  <body>
    body
  </body>
</html>

in browser:
截屏2024-04-29 下午5 35 48

截屏2024-04-29 下午5 38 03

it will be better for developer, if vite provide some warn message.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@PengBoUESTC PengBoUESTC requested a review from sapphi-red May 1, 2024 02:13
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this warning won't happen that much, but I think the complexity is small enough.

if (!tags.length) return
const { logger } = ctx.server?.config || {}
const message = tags.reduce<string[]>((res, tagDescriptor) => {
if (!HeadElement[tagDescriptor.tag]) res.push(`<${tagDescriptor.tag}>`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for other reviewers: I confirmed that custom elements are not allowed in <head>.

@sapphi-red sapphi-red added feat: html p2-nice-to-have Not breaking anything but nice to have (priority) labels May 1, 2024
@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

@bluwy bluwy added this to the 5.3 milestone May 13, 2024
@bluwy bluwy merged commit 9f02a9f into vitejs:main May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: html p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants