Skip to content

Commit 360643d

Browse files
authored
fix(react): setupIonicReact no longer crashes in SSR environment (#24604)
1 parent 35e5235 commit 360643d

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

packages/react/src/components/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ export const setupIonicReact = (config: IonicConfig = {}) => {
197197
* TODO: Remove when all integrations have been
198198
* migrated to CE build.
199199
*/
200-
document.documentElement.classList.add('ion-ce');
200+
if (typeof (document as any) !== 'undefined') {
201+
document.documentElement.classList.add('ion-ce');
202+
}
201203

202204
initialize({
203205
...config

packages/vue/src/ionic-vue.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,23 @@ const getHelperFunctions = () => {
2121
export const IonicVue: Plugin = {
2222

2323
async install(_: App, config: IonicConfig = {}) {
24-
if (typeof (window as any) !== 'undefined') {
25-
26-
/**
27-
* By default Ionic Framework hides elements that
28-
* are not hydrated, but in the CE build there is no
29-
* hydration.
30-
* TODO: Remove when all integrations have been
31-
* migrated to CE build.
32-
*/
24+
/**
25+
* By default Ionic Framework hides elements that
26+
* are not hydrated, but in the CE build there is no
27+
* hydration.
28+
* TODO: Remove when all integrations have been
29+
* migrated to CE build.
30+
*/
31+
if (typeof (document as any) !== 'undefined') {
3332
document.documentElement.classList.add('ion-ce');
34-
35-
const { ael, rel, ce } = getHelperFunctions();
36-
initialize({
37-
...config,
38-
_ael: ael,
39-
_rel: rel,
40-
_ce: ce
41-
});
4233
}
34+
35+
const { ael, rel, ce } = getHelperFunctions();
36+
initialize({
37+
...config,
38+
_ael: ael,
39+
_rel: rel,
40+
_ce: ce
41+
});
4342
}
4443
};

0 commit comments

Comments
 (0)