From 82c6bbbf15e8ec64994968d1b3ae4b93bea414f4 Mon Sep 17 00:00:00 2001 From: emotaro Date: Mon, 11 Jul 2022 18:21:58 +0900 Subject: [PATCH] fix: dont add when helmetdata already has same instance --- src/Dispatcher.js | 6 ------ src/HelmetData.js | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Dispatcher.js b/src/Dispatcher.js index d45825a0..7d5c027b 100644 --- a/src/Dispatcher.js +++ b/src/Dispatcher.js @@ -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; diff --git a/src/HelmetData.js b/src/HelmetData.js index 7885abf4..d27da984 100644 --- a/src/HelmetData.js +++ b/src/HelmetData.js @@ -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 => {