fix: sequential injection of tags in transformIndexHtml (#5851)#6901
fix: sequential injection of tags in transformIndexHtml (#5851)#6901patak-cat merged 3 commits intovitejs:mainfrom
Conversation
|
same question, can't wait. |
|
@tyouzu1 As a workaround, you can currently use the |
Already seen. No test yet. Thanks anyway |
|
I think this makes sense, it is already added for discussion in a team meeting. We'll try to get to it before the v3 release. |
|
Just to clarify. This PR changes the order slightly. For example, if there are two plugins like this: {
plugins: [
{
name: 'hook1',
transformIndexHtml(html) {
return [
{ tag: 'meta', children: 'hook1-pre', injectTo: 'head-prepend' },
{ tag: 'meta', children: 'hook1', injectTo: 'head' }
]
}
},
{
name: 'hook2',
transformIndexHtml(html) {
return [
{ tag: 'meta', children: 'hook2-pre', injectTo: 'head-prepend' },
{ tag: 'meta', children: 'hook2', injectTo: 'head' }
]
}
}
]
}<!-- output before this PR -->
<head>
<meta>hook1-pre</meta>
<meta>hook2-pre</meta>
<meta>hook1</meta>
<meta>hook2</meta>
</head>
<!-- output after this PR -->
<head>
<meta>hook2-pre</meta>
<meta>hook1-pre</meta>
<meta>hook1</meta>
<meta>hook2</meta>
</head> |
patak-cat
left a comment
There was a problem hiding this comment.
The new order is what I would expect 👍🏼
I would consider the order change a bug fix.
Description
The built-in
htmlplugin provides atransformIndexHtmlhook for all plugins, which inputs contents ofindex.htmland outputs modified contents and some tags to inject. But alltagsto inject are injected after all plugins'transformIndexHtmlhook, so tags injected by previous plugins are not visible to next ones.It closes #5851.
Additional context
I changed the code to handle tags injection after each plugin's hook, so the performance inevitably degrades. Is it acceptable? If not, should we use other ways such as adding another parameter to
transformIndexHtmlto receive tags that previous plugins want to inject?What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).