Skip to content

Commit 906b53d

Browse files
blittlestaylor
authored andcommitted
fix: move to a singleton for tracking Helmet instances
This resolves an issue where multiple HelmetProviders on the same page don't know about each other.
1 parent 7a7c114 commit 906b53d

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

jest.setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'raf/polyfill';
22
import { configure } from 'enzyme';
33
import Adapter from 'enzyme-adapter-react-16';
44
import ReactDOM from 'react-dom';
5+
import { clearInstances } from './src/HelmetData';
56

67
configure({ adapter: new Adapter() });
78

@@ -40,4 +41,5 @@ beforeEach(() => {
4041

4142
afterEach(() => {
4243
ReactDOM.unmountComponentAtNode(mount);
44+
clearInstances();
4345
});

src/HelmetData.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import mapStateOnServer from './server';
22

3-
export default class HelmetData {
4-
instances = [];
3+
const instances = [];
4+
5+
export function clearInstances() {
6+
instances.length = 0;
7+
}
58

9+
export default class HelmetData {
610
value = {
711
setHelmet: serverState => {
812
this.context.helmet = serverState;
913
},
1014
helmetInstances: {
11-
get: () => this.instances,
15+
get: () => instances,
1216
add: instance => {
13-
this.instances.push(instance);
17+
instances.push(instance);
1418
},
1519
remove: instance => {
16-
const index = this.instances.indexOf(instance);
17-
this.instances.splice(index, 1);
20+
const index = instances.indexOf(instance);
21+
instances.splice(index, 1);
1822
},
1923
},
2024
};
2125

22-
constructor(context, instances) {
26+
constructor(context) {
2327
this.context = context;
2428

25-
if (instances) {
26-
this.instances = instances;
27-
}
28-
2929
if (!HelmetData.canUseDOM) {
3030
context.helmet = mapStateOnServer({
3131
baseTag: [],

0 commit comments

Comments
 (0)