From 360643d96a03b345c83b88c9ff06e9aa254dee81 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 19 Jan 2022 15:48:46 -0500 Subject: [PATCH] fix(react): setupIonicReact no longer crashes in SSR environment (#24604) --- packages/react/src/components/index.ts | 4 +++- packages/vue/src/ionic-vue.ts | 33 +++++++++++++------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/react/src/components/index.ts b/packages/react/src/components/index.ts index 84c29e0527..5f88dc0ce2 100644 --- a/packages/react/src/components/index.ts +++ b/packages/react/src/components/index.ts @@ -197,7 +197,9 @@ export const setupIonicReact = (config: IonicConfig = {}) => { * TODO: Remove when all integrations have been * migrated to CE build. */ - document.documentElement.classList.add('ion-ce'); + if (typeof (document as any) !== 'undefined') { + document.documentElement.classList.add('ion-ce'); + } initialize({ ...config diff --git a/packages/vue/src/ionic-vue.ts b/packages/vue/src/ionic-vue.ts index 96ff935a89..d16bbcdb48 100644 --- a/packages/vue/src/ionic-vue.ts +++ b/packages/vue/src/ionic-vue.ts @@ -21,24 +21,23 @@ const getHelperFunctions = () => { export const IonicVue: Plugin = { async install(_: App, config: IonicConfig = {}) { - if (typeof (window as any) !== 'undefined') { - - /** - * By default Ionic Framework hides elements that - * are not hydrated, but in the CE build there is no - * hydration. - * TODO: Remove when all integrations have been - * migrated to CE build. - */ + /** + * By default Ionic Framework hides elements that + * are not hydrated, but in the CE build there is no + * hydration. + * TODO: Remove when all integrations have been + * migrated to CE build. + */ + if (typeof (document as any) !== 'undefined') { document.documentElement.classList.add('ion-ce'); - - const { ael, rel, ce } = getHelperFunctions(); - initialize({ - ...config, - _ael: ael, - _rel: rel, - _ce: ce - }); } + + const { ael, rel, ce } = getHelperFunctions(); + initialize({ + ...config, + _ael: ael, + _rel: rel, + _ce: ce + }); } };