From ba410b23a2e61586d643bcca851c3819eb3f34c0 Mon Sep 17 00:00:00 2001 From: Chris Plummer Date: Tue, 29 Aug 2023 08:34:08 -0500 Subject: [PATCH] log when the context does not exist instead of throwing errors --- src/Dispatcher.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Dispatcher.js b/src/Dispatcher.js index d45825a0..724e1c37 100644 --- a/src/Dispatcher.js +++ b/src/Dispatcher.js @@ -19,11 +19,27 @@ export default class Dispatcher extends Component { } componentDidUpdate() { + if (!this.props.context.helmetInstances) { + // eslint-disable-next-line no-console + console.trace( + 'No helmet context was found, make sure to wrap your app in a HelmetProvider' + ); + return; + } + this.emitChange(); } componentWillUnmount() { const { helmetInstances } = this.props.context; + if (!helmetInstances) { + // eslint-disable-next-line no-console + console.trace( + 'No helmet context was found, make sure to wrap your app in a HelmetProvider' + ); + return; + } + helmetInstances.remove(this); this.emitChange(); } @@ -57,6 +73,14 @@ export default class Dispatcher extends Component { this.rendered = true; const { helmetInstances } = this.props.context; + if (!helmetInstances) { + // eslint-disable-next-line no-console + console.trace( + 'No helmet context was found, make sure to wrap your app in a HelmetProvider' + ); + return; + } + helmetInstances.add(this); this.emitChange(); }