Skip to content

Commit 7a72ceb

Browse files
emotaroemotaro
authored andcommitted
fix: dont add when helmetdata has already same instance
1 parent b1ee658 commit 7a72ceb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Dispatcher.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ export default class Dispatcher extends Component {
2222
this.emitChange();
2323
}
2424

25-
componentWillUnmount() {
26-
const { helmetInstances } = this.props.context;
27-
helmetInstances.remove(this);
28-
this.emitChange();
29-
}
30-
3125
emitChange() {
3226
const { helmetInstances, setHelmet } = this.props.context;
3327
let serverState = null;

src/HelmetData.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export default class HelmetData {
1616
helmetInstances: {
1717
get: () => (this.canUseDOM ? instances : this.instances),
1818
add: instance => {
19+
const alreadyHasSameInstance = (this.canUseDOM ? instances : this.instances).filter(instance => {
20+
const a = Object.entries({...instance.props, context: undefined}).sort();
21+
const b = Object.entries({...this.props, context: undefined}).sort();
22+
return JSON.stringify(a) === JSON.stringify(b);
23+
}).length > 0;
24+
if (alreadyHasSameInstance) {
25+
return;
26+
}
1927
(this.canUseDOM ? instances : this.instances).push(instance);
2028
},
2129
remove: instance => {

0 commit comments

Comments
 (0)