Skip to content

Commit

Permalink
fix: dont add when helmetdata already has same instance
Browse files Browse the repository at this point in the history
  • Loading branch information
emotaro authored and emotaro committed Jul 11, 2022
1 parent b1ee658 commit 82c6bbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/Dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ export default class Dispatcher extends Component {
this.emitChange();
}

componentWillUnmount() {
const { helmetInstances } = this.props.context;
helmetInstances.remove(this);
this.emitChange();
}

emitChange() {
const { helmetInstances, setHelmet } = this.props.context;
let serverState = null;
Expand Down
8 changes: 8 additions & 0 deletions src/HelmetData.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export default class HelmetData {
helmetInstances: {
get: () => (this.canUseDOM ? instances : this.instances),
add: instance => {
const alreadyHasSameInstance = (this.canUseDOM ? instances : this.instances).filter(instance => {
const a = Object.entries({...instance.props, context: undefined}).sort();
const b = Object.entries({...this.props, context: undefined}).sort();
return JSON.stringify(a) === JSON.stringify(b);
}).length > 0;
if (alreadyHasSameInstance) {
return;
}
(this.canUseDOM ? instances : this.instances).push(instance);
},
remove: instance => {
Expand Down

0 comments on commit 82c6bbb

Please sign in to comment.