Skip to content

Commit fe27e8b

Browse files
committed
[#11][#12] Problems with "prioritizeSeoTags"
1 parent c266d18 commit fe27e8b

File tree

3 files changed

+122
-3
lines changed

3 files changed

+122
-3
lines changed

__tests__/browser/MetaTags.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/** @jest-environment jsdom */
2+
3+
import { renderClient } from '../../jest/browser-utils';
4+
5+
import { Helmet, MetaTags } from '../../src';
6+
import { HELMET_ATTRIBUTE } from '../../src/constants';
7+
8+
test('with "prioritizeSeoTags"', () => {
9+
renderClient(
10+
<>
11+
<Helmet prioritizeSeoTags />
12+
<MetaTags
13+
description="Test description"
14+
extraMetaTags={[{
15+
content: 'extra meta tag content',
16+
name: 'extra meta tag',
17+
}]}
18+
image="https://some.url.com/image.png"
19+
siteName="Test web site"
20+
socialDescription="Social description"
21+
socialTitle="Social title"
22+
title="Test Title"
23+
url="https://some.url.com"
24+
>
25+
Abc
26+
</MetaTags>
27+
</>,
28+
);
29+
30+
const tags = [...document.head.querySelectorAll(`[${HELMET_ATTRIBUTE}]`)];
31+
expect(tags).toMatchSnapshot();
32+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`with "prioritizeSeoTags" 1`] = `
4+
[
5+
<meta
6+
content="Test description"
7+
data-rh="true"
8+
name="description"
9+
/>,
10+
<meta
11+
content="summary_large_image"
12+
data-rh="true"
13+
name="twitter:card"
14+
/>,
15+
<meta
16+
content="Social title"
17+
data-rh="true"
18+
name="twitter:title"
19+
/>,
20+
<meta
21+
content="Social description"
22+
data-rh="true"
23+
name="twitter:description"
24+
/>,
25+
<meta
26+
content="https://some.url.com/image.png"
27+
data-rh="true"
28+
name="twitter:image"
29+
/>,
30+
<meta
31+
content="@Test web site"
32+
data-rh="true"
33+
name="twitter:site"
34+
/>,
35+
<meta
36+
content="Social title"
37+
data-rh="true"
38+
name="og:title"
39+
/>,
40+
<meta
41+
content="https://some.url.com/image.png"
42+
data-rh="true"
43+
name="og:image"
44+
/>,
45+
<meta
46+
content="Social title"
47+
data-rh="true"
48+
name="og:image:alt"
49+
/>,
50+
<meta
51+
content="Social description"
52+
data-rh="true"
53+
name="og:description"
54+
/>,
55+
<meta
56+
content="Test web site"
57+
data-rh="true"
58+
name="og:sitename"
59+
/>,
60+
<meta
61+
content="https://some.url.com"
62+
data-rh="true"
63+
name="og:url"
64+
/>,
65+
<meta
66+
content="extra meta tag content"
67+
data-rh="true"
68+
name="extra meta tag"
69+
/>,
70+
]
71+
`;

src/client.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function updateTitle(
165165
updateAttributes(TAG_NAMES.TITLE, attributes);
166166
}
167167

168+
// eslint-disable-next-line complexity
168169
export function commitTagChanges(
169170
newState: AggregatedState,
170171
firstRender: boolean,
@@ -178,6 +179,7 @@ export function commitTagChanges(
178179
meta,
179180
noscript,
180181
onChangeClientState,
182+
priority,
181183
script,
182184
style,
183185
title,
@@ -190,10 +192,24 @@ export function commitTagChanges(
190192

191193
const tagUpdates: TagUpdateList = {
192194
baseTag: updateTags(TAG_NAMES.BASE, base ? [base] : []),
193-
linkTags: updateTags(TAG_NAMES.LINK, links ?? []),
194-
metaTags: updateTags(TAG_NAMES.META, meta ?? []),
195+
196+
linkTags: updateTags(TAG_NAMES.LINK, [
197+
...priority?.links ?? [],
198+
...links ?? [],
199+
]),
200+
201+
metaTags: updateTags(TAG_NAMES.META, [
202+
...priority?.meta ?? [],
203+
...meta ?? [],
204+
]),
205+
195206
noscriptTags: updateTags(TAG_NAMES.NOSCRIPT, noscript ?? []),
196-
scriptTags: updateTags(TAG_NAMES.SCRIPT, script ?? []),
207+
208+
scriptTags: updateTags(TAG_NAMES.SCRIPT, [
209+
...priority?.script ?? [],
210+
...script ?? [],
211+
]),
212+
197213
styleTags: updateTags(TAG_NAMES.STYLE, style ?? []),
198214
};
199215

0 commit comments

Comments
 (0)