feat: Support replace in prerender head.elements to remove existing tags#31
feat: Support replace in prerender head.elements to remove existing tags#31WBBB0730 wants to merge 1 commit intopreactjs:masterfrom
replace in prerender head.elements to remove existing tags#31Conversation
|
@rschristian Hi! I also considered an alternative API: {
head: {
remove: [
'meta[name="description"]',
]
}
}Not sure if it’s better or worse—just for reference. |
|
I have no involvement with this particular sub-project of Preact, best to discuss with other people. |
Sorry, I @mentioned the wrong person. |
|
This reads heavily like an LLM but no usage has been disclosed, in breach of the Code of Conduct: https://github.com/preactjs/vite-prerender-plugin?tab=coc-ov-file I also really dislike the API; we're in a 0-major, we can make breaking changes if really desired. I'd lean towards telling users not to put tags into their |
|
@rschristian Thank you for your reply. I’m sorry—I didn’t notice that CoC rule. The description of this PR was indeed supplemented with the help of an LLM, in order to more accurately describe the changes I made. I really need this feature because in the project I’m currently developing, we need to provide global default TDK in index.html, and due to some business constraints, they must be written in index.html rather than in a layout. At the same time, I need to allow certain pages to override the default TDK in some way. This plugin is truly great and has solved a major pain point for me. If you could suggest any alternative approach for achieving this, I would be very grateful. Or, if you have better suggestions regarding the API, I’m more than willing to cooperate and adjust the implementation accordingly. |
|
Would #32 suffice? |
Feat: Support
replacein prerender head.elements to remove existing tagsThis PR adds an optional way to replace existing
<head>tags when using the prerender API’shead.elements, without changing any default behavior.What changed
New optional
replacefield onhead.elementsitemshead.elementsmay now includereplace?: stringreplaceis a CSS selector used to target existing elements in the HTML templateReplacement logic (opt-in, default behavior unchanged)
replaceis provided:querySelectorAll(replace)on<head>and removes all matching nodesreplaceis not provided, the plugin behaves exactly as before (elements are simply appended to<head>)Documentation update
replaceusage snippet (e.g. replacing an existingmeta[name="description"])Why
Some projects include default head tags in the HTML template (like
description,canonical,og:*), but want prerendering to generate route-specific values. Without this, users can end up with duplicate<meta>tags. The newreplaceoption lets users precisely control what gets replaced using a familiar CSS selector.Compatibility / impact
replace, and only touches matching nodes within<head>Example