|
1 | 1 | import type { CreateHeadOptions, Head } from '@unhead/schema'
|
2 | 2 | import { IsBrowser } from '@unhead/shared'
|
3 |
| -import { DomPlugin } from './client/domPlugin' |
| 3 | +import { DomPlugin } from './client/plugins/domPlugin' |
| 4 | +import { ClientEventHandlerPlugin } from './client/plugins/eventHandlers' |
4 | 5 | import { unheadCtx } from './context'
|
5 | 6 | import { createHeadCore } from './createHead'
|
6 | 7 | import { DeprecationsPlugin } from './optionalPlugins/deprecations'
|
7 | 8 | import { PromisesPlugin } from './optionalPlugins/promises'
|
| 9 | +import { ServerEventHandlerPlugin } from './server/plugins/eventHandlers' |
| 10 | +import { PayloadPlugin } from './server/plugins/payload' |
8 | 11 |
|
9 | 12 | export function createServerHead<T extends Record<string, any> = Head>(options: CreateHeadOptions = {}) {
|
10 |
| - // @ts-expect-error untyped |
11 |
| - const head = createHeadCore<T>({ disableCapoSorting: true, ...options, document: false }) |
12 |
| - head.use(DeprecationsPlugin) |
13 |
| - head.use(PromisesPlugin) |
14 |
| - return head |
| 13 | + return createHeadCore<T>({ |
| 14 | + disableCapoSorting: true, |
| 15 | + ...options, |
| 16 | + // @ts-expect-error untyped |
| 17 | + document: false, |
| 18 | + plugins: [ |
| 19 | + ...(options.plugins || []), |
| 20 | + DomPlugin(), |
| 21 | + DeprecationsPlugin, |
| 22 | + PromisesPlugin, |
| 23 | + ServerEventHandlerPlugin, |
| 24 | + PayloadPlugin, |
| 25 | + ], |
| 26 | + }) |
15 | 27 | }
|
16 | 28 |
|
17 | 29 | export function createHead<T extends Record<string, any> = Head>(options: CreateHeadOptions = {}) {
|
18 |
| - const head = createHeadCore<T>({ disableCapoSorting: true, ...options }) |
19 |
| - head.use(DomPlugin()) |
20 |
| - head.use(DeprecationsPlugin) |
21 |
| - head.use(PromisesPlugin) |
| 30 | + const head = createHeadCore<T>({ disableCapoSorting: true, ...options, plugins: [ |
| 31 | + ...(options.plugins || []), |
| 32 | + DomPlugin(), |
| 33 | + DeprecationsPlugin, |
| 34 | + PromisesPlugin, |
| 35 | + ClientEventHandlerPlugin, |
| 36 | + ] }) |
22 | 37 | // should only be one instance client-side
|
23 | 38 | if (!head.ssr && IsBrowser) {
|
24 | 39 | unheadCtx.set(head, true)
|
|
0 commit comments