Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f696d9d

Browse files
committed
fix: sync transformHtmlTemplate
1 parent 5d9f1fe commit f696d9d

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import type { RenderSSRHeadOptions, Unhead } from '../types'
1+
import type { SSRHeadPayload, Unhead } from '../types'
22
import { applyHeadToHtml, parseHtmlForIndexes, parseHtmlForUnheadExtraction } from '../parser'
3-
import { renderSSRHead } from './renderSSRHead'
43

54
/**
65
* Transform an HTML template string by extracting any head tags and attributes from it, pushing them to Unhead,
76
* and injecting the resulting head tags back into the HTML.
87
* Uses optimized parsing and index-based HTML construction for best performance.
98
*/
109
/* @__NO_SIDE_EFFECTS__ */
11-
export async function transformHtmlTemplate(head: Unhead<any>, html: string, options?: RenderSSRHeadOptions) {
10+
export function transformHtmlTemplate(head: Unhead<any, SSRHeadPayload>, html: string) {
1211
const template = parseHtmlForUnheadExtraction(html)
1312
head.push(template.input, { _index: 0 })
14-
const headHtml = renderSSRHead(head, options)
15-
return applyHeadToHtml(template, headHtml)
13+
return applyHeadToHtml(template, head.render())
1614
}
1715

1816
/**
@@ -25,9 +23,8 @@ export async function transformHtmlTemplate(head: Unhead<any>, html: string, opt
2523
* ordered incorrectly, so use with caution.
2624
*/
2725
/* @__NO_SIDE_EFFECTS__ */
28-
export async function transformHtmlTemplateRaw(head: Unhead<any>, html: string, options?: RenderSSRHeadOptions) {
29-
const headHtml = renderSSRHead(head, options)
26+
export function transformHtmlTemplateRaw(head: Unhead<any, SSRHeadPayload>, html: string) {
3027
// For raw mode, we only need indexes, not head extraction
3128
const template = parseHtmlForIndexes(html)
32-
return applyHeadToHtml(template, headHtml)
29+
return applyHeadToHtml(template, head.render())
3330
}

packages/unhead/test/unit/server/ssr.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createHead } from '@unhead/dom'
21
import { describe, it } from 'vitest'
32
import { useHead, useSeoMeta } from '../../../src'
43
import { renderSSRHead } from '../../../src/server'
@@ -391,7 +390,7 @@ describe('ssr', () => {
391390
</style>
392391
</head>
393392
`
394-
const processedHtml = await transformHtmlTemplate(createHead(), input)
393+
const processedHtml = transformHtmlTemplate(createServerHeadWithContext(), input)
395394
expect(processedHtml).toMatchInlineSnapshot(`
396395
"
397396
<head>

packages/unhead/test/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { CreateClientHeadOptions, CreateServerHeadOptions, ResolvableHead, SerializableHead, SSRHeadPayload, Unhead } from '../src/types'
1+
import type { ServerUnhead } from '../src/server'
2+
import type { CreateClientHeadOptions, CreateServerHeadOptions, SerializableHead, SSRHeadPayload } from '../src/types'
23
import { JSDOM } from 'jsdom'
34
import { createHead as createClientHead } from '../src/client'
45
import { createHead as createServerHead } from '../src/server'
@@ -8,7 +9,7 @@ export function createClientHeadWithContext(resolvedOptions: CreateClientHeadOpt
89
return createClientHead(resolvedOptions)
910
}
1011

11-
export function createServerHeadWithContext(resolvedOptions: CreateServerHeadOptions = {}): Unhead<ResolvableHead> {
12+
export function createServerHeadWithContext(resolvedOptions: CreateServerHeadOptions = {}): ServerUnhead {
1213
return createServerHead({
1314
disableDefaults: true,
1415
...resolvedOptions,

0 commit comments

Comments
 (0)