Skip to content

Commit 37ae4f4

Browse files
committed
Minor fixes
1 parent 3b2ca63 commit 37ae4f4

File tree

11 files changed

+37
-30
lines changed

11 files changed

+37
-30
lines changed

__tests__/__snapshots__/misc.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ exports[`misc Declarative API only adds new tags and preserves tags when renderi
2727
exports[`misc Declarative API only adds new tags and preserves tags when rendering additional Helmet instances 5`] = `"<meta content="Test description" name="description" data-rh="true">"`;
2828
2929
exports[`misc Declarative API recognizes valid tags regardless of attribute ordering 1`] = `"<meta content="Test Description" name="description" data-rh="true">"`;
30+
31+
exports[`misc Declarative API throws on invalid elements 1`] = `"Only elements types base, body, Symbol(react.fragment), head, html, link, meta, noscript, script, style, title are allowed. Helmet does not support rendering <div> elements. Refer to our API for more information."`;
32+
33+
exports[`misc Declarative API throws on invalid self-closing elements 1`] = `"Only elements types base, body, Symbol(react.fragment), head, html, link, meta, noscript, script, style, title are allowed. Helmet does not support rendering <div> elements. Refer to our API for more information."`;

__tests__/misc.test.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,7 @@ describe('misc', () => {
350350
);
351351
};
352352

353-
expect(renderInvalid).toThrow(
354-
'Only elements types base, body, head, html, link, meta, noscript, script, style, title, Symbol(react.fragment) are allowed. Helmet does not support rendering <div> elements. Refer to our API for more information.',
355-
);
353+
expect(renderInvalid).toThrowErrorMatchingSnapshot();
356354

357355
global.console.error = consoleError;
358356
});
@@ -377,9 +375,7 @@ describe('misc', () => {
377375
/* eslint-enable react/no-unknown-property */
378376
};
379377

380-
expect(renderInvalid).toThrow(
381-
'Only elements types base, body, head, html, link, meta, noscript, script, style, title, Symbol(react.fragment) are allowed. Helmet does not support rendering <div> elements. Refer to our API for more information.',
382-
);
378+
expect(renderInvalid).toThrowErrorMatchingSnapshot();
383379

384380
global.console.error = consoleError;
385381
});

jest/browser-utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
type FunctionComponent,
33
type ReactNode,
4-
act,
54
StrictMode,
5+
act,
66
} from 'react';
77

8-
import { createRoot, type Root } from 'react-dom/client';
8+
import { type Root, createRoot } from 'react-dom/client';
99

1010
import Provider from '../src/Provider';
1111
import type { HelmetDataContext, HelmetServerState } from '../src/types';

src/Helmet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import {
2+
Children,
23
type FunctionComponent,
34
type ReactElement,
45
type ReactNode,
5-
Children,
66
use,
77
useEffect,
88
useId,
99
} from 'react';
1010

11-
import { REACT_TAG_MAP, TAG_NAMES, VALID_TAG_NAMES } from './constants';
12-
1311
import { Context } from './Provider';
1412

13+
import { REACT_TAG_MAP, TAG_NAMES, VALID_TAG_NAMES } from './constants';
14+
1515
import type {
1616
BaseProps,
1717
BodyProps,

src/Provider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import {
55
useRef,
66
} from 'react';
77

8+
import { commitTagChanges } from './client';
9+
10+
import { IS_DOM_ENVIRONMENT } from './constants';
11+
import { newServerState } from './server';
812
import type {
913
ContextValue,
1014
HelmetDataContext,
1115
HelmetProps,
1216
HelmetProviderHeap,
1317
} from './types';
14-
15-
import { newServerState } from './server';
16-
import { IS_DOM_ENVIRONMENT } from './constants';
1718
import { calcAggregatedState } from './utils';
18-
import { commitTagChanges } from './client';
1919

2020
export const Context = createContext<ContextValue | undefined>(undefined);
2121

src/client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { flattenArray } from './utils';
1818

1919
type TagUpdates = {
2020
allTags: HTMLElement[];
21-
oldTags: HTMLElement[];
2221
newTags: HTMLElement[];
22+
oldTags: HTMLElement[];
2323
};
2424

2525
type TagUpdateList = Record<string, TagUpdates>;
@@ -92,8 +92,13 @@ function updateTags(type: string, tags: HelmetChildProps[]) {
9292
}
9393
}
9494

95-
oldTags.forEach((tag: Node) => tag.parentNode?.removeChild(tag));
96-
newTags.forEach((tag) => headElement.appendChild(tag));
95+
oldTags.forEach((tag: Node) => {
96+
tag.parentNode?.removeChild(tag);
97+
});
98+
99+
newTags.forEach((tag) => {
100+
headElement.appendChild(tag);
101+
});
97102

98103
// TODO: Do we really need this return value anywhere? Especially `oldTags`
99104
// that have been removed from DOM already?

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum ATTRIBUTE_NAMES {
2121
export enum TAG_NAMES {
2222
BASE = 'base',
2323
BODY = 'body',
24+
FRAGMENT = 'Symbol(react.fragment)',
2425
HEAD = 'head',
2526
HTML = 'html',
2627
LINK = 'link',
@@ -29,7 +30,6 @@ export enum TAG_NAMES {
2930
SCRIPT = 'script',
3031
STYLE = 'style',
3132
TITLE = 'title',
32-
FRAGMENT = 'Symbol(react.fragment)',
3333
}
3434

3535
export const SEO_PRIORITY_TAGS = {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type * from './types';
22

33
export { default as Helmet } from './Helmet';
4-
export { default as HelmetProvider } from './Provider';
54
export { default as MetaTags } from './MetaTags';
5+
export { default as HelmetProvider } from './Provider';

src/server.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77

88
import {
99
HELMET_ATTRIBUTE,
10-
TAG_NAMES,
10+
HTML_TAG_MAP,
1111
REACT_TAG_MAP,
12+
TAG_NAMES,
1213
TAG_PROPERTIES,
13-
HTML_TAG_MAP,
1414
} from './constants';
1515

1616
import type {

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {
22
BaseHTMLAttributes,
3-
HtmlHTMLAttributes,
43
HTMLAttributes,
4+
HtmlHTMLAttributes,
55
LinkHTMLAttributes,
66
MetaHTMLAttributes,
77
ReactNode,
@@ -51,8 +51,8 @@ export type HelmetTags = {
5151
};
5252

5353
export type HelmetDatum<T = ReactNode> = {
54-
toString(): string;
5554
toComponent(): T;
55+
toString(): string;
5656
};
5757

5858
export type HelmetHTMLBodyDatum = HelmetDatum<HTMLAttributes<HTMLBodyElement>>;
@@ -138,8 +138,8 @@ export type HelmetPropBooleans = {
138138
* Properties accepted by <Helmet> components.
139139
*/
140140
export type HelmetProps = HelmetPropArrays
141-
& HelmetPropObjects
142141
& HelmetPropBooleans
142+
& HelmetPropObjects
143143
& {
144144
base?: BaseProps;
145145
children?: ReactNode;

0 commit comments

Comments
 (0)