Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

feat: remove useHead artifacts #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div>This page needs no JavaScript (of course!)!</div>
</template>

<style scoped>
div {
color: red;
Expand Down
7 changes: 7 additions & 0 deletions src/runtime/nitro-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ export default <NitroAppPlugin> function (nitroApp) {
if (i !== -1) {
htmlContext.head[i] = htmlContext.head[i].replace(JS_HINT_RE, '')
}

// clean up useHead artifacts
htmlContext.htmlAttrs = htmlContext.htmlAttrs.filter(a => !a.includes('data-head-attrs'))
htmlContext.bodyAttrs = htmlContext.bodyAttrs.filter(a => !a.includes('data-head-attrs'))
htmlContext.head = htmlContext.head
.map(k => k.replace(/<meta[^>]+name="head:count"[^>]+content="[^>]*"[^>]*>/g, ''))
.filter(Boolean)
})
}
12 changes: 6 additions & 6 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ describe('nuxt zero-js', async () => {
const html = await $fetch('/')
expect(html.replace(/\.[^.]+\.css/g, '.css').replace(/ data-v-[^>]*/g, ''))
.toMatchInlineSnapshot(`
"<!DOCTYPE html>
<html data-head-attrs=\\"\\">
<head><title></title><meta charset=\\"utf-8\\"><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\"><meta name=\\"head:count\\" content=\\"2\\"><link rel=\\"preload\\" as=\\"style\\" href=\\"/_nuxt/entry.css\\"><link rel=\\"stylesheet\\" href=\\"/_nuxt/entry.css\\"></head>
<body data-head-attrs=\\"\\"><div id=\\"__nuxt\\"><div>This page needs no JavaScript (of course!)!</div></div></body>
</html>"
`)
"<!DOCTYPE html>
<html >
<head><title></title><meta charset=\\"utf-8\\"><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\"><link rel=\\"preload\\" as=\\"style\\" href=\\"/_nuxt/entry.css\\"><link rel=\\"stylesheet\\" href=\\"/_nuxt/entry.css\\"></head>
<body ><div id=\\"__nuxt\\"><div>This page needs no JavaScript (of course!)!</div></div></body>
</html>"
`)
})
})