Skip to content

Commit a6bf3be

Browse files
committed
remove server rendered head tags when initialized and not hydrating
1 parent 1a5fd95 commit a6bf3be

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@solidjs/meta",
33
"description": "Write meta tags to the document head",
4-
"version": "0.28.1",
4+
"version": "0.28.2",
55
"author": "Ryan Carniato",
66
"license": "MIT",
77
"repository": {

src/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
createUniqueId,
66
JSX,
77
onCleanup,
8-
ParentComponent,
9-
useContext
8+
ParentComponent, sharedConfig, useContext
109
} from "solid-js";
1110
import { isServer, spread } from "solid-js/web";
1211

@@ -33,6 +32,11 @@ const cascadingTags = ["title", "meta"];
3332
const getTagType = (tag: TagDescription) => tag.tag + (tag.name ? `.${tag.name}"` : "");
3433

3534
const MetaProvider: ParentComponent<{ tags?: Array<TagDescription> }> = props => {
35+
if (!isServer && !sharedConfig.context) {
36+
const ssrTags = document.head.querySelectorAll(`[data-sm]`);
37+
// `forEach` on `NodeList` is not supported in Googlebot, so use a workaround
38+
Array.prototype.forEach.call(ssrTags, (ssrTag: Node) => ssrTag.parentNode!.removeChild(ssrTag));
39+
}
3640
const cascadedTagInstances = new Map();
3741

3842
// TODO: use one element for all tags of the same type, just swap out

0 commit comments

Comments
 (0)