Skip to content

Commit 0e7b9e8

Browse files
committed
fix(components): better SSR support
1 parent 964af1e commit 0e7b9e8

File tree

6 files changed

+60
-6
lines changed

6 files changed

+60
-6
lines changed

src/react/shared/f7.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable import/no-mutable-exports */
22
import Framework7 from 'framework7/lite';
3-
import { extend } from './utils';
3+
import { extend, unsetRouterIds } from './utils';
44

55
let f7;
66
let f7events;
@@ -13,6 +13,16 @@ const f7routers = {
1313
modals: null,
1414
};
1515

16+
const cleanup = () => {
17+
unsetRouterIds();
18+
delete theme.ios;
19+
delete theme.md;
20+
delete theme.aurora;
21+
f7routers.views = [];
22+
f7routers.tabs = [];
23+
f7routers.modals = null;
24+
};
25+
1626
const f7initEvents = () => {
1727
f7events = new Framework7.Events();
1828
};
@@ -31,7 +41,10 @@ const f7init = (rootEl, params = {}, init = true) => {
3141
theme.aurora = device.desktop && device.electron;
3242
theme.md = !theme.ios && !theme.aurora;
3343
}
34-
if (f7) return;
44+
// eslint-disable-next-line
45+
if (f7 && typeof window !== 'undefined') return;
46+
47+
cleanup();
3548

3649
const instance = new Framework7(f7Params);
3750
f7 = instance;

src/react/shared/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ export function getExtraAttrs(props = {}) {
133133
let routerIdCounter = 0;
134134
let routerComponentIdCounter = 0;
135135

136+
export function unsetRouterIds() {
137+
routerIdCounter = 0;
138+
routerComponentIdCounter = 0;
139+
}
140+
136141
export function getRouterId() {
137142
routerIdCounter += 1;
138143
return `${now()}_${routerIdCounter}`;

src/svelte/shared/f7.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable import/no-mutable-exports */
22
// eslint-disable-next-line
33
import Framework7 from 'framework7/lite';
4-
import { extend } from './utils';
4+
import { extend, unsetRouterIds } from './utils';
55

66
let f7;
77
let f7events;
@@ -14,6 +14,16 @@ const f7routers = {
1414
modals: null,
1515
};
1616

17+
const cleanup = () => {
18+
unsetRouterIds();
19+
delete theme.ios;
20+
delete theme.md;
21+
delete theme.aurora;
22+
f7routers.views = [];
23+
f7routers.tabs = [];
24+
f7routers.modals = null;
25+
};
26+
1727
const f7initEvents = () => {
1828
f7events = new Framework7.Events();
1929
};
@@ -32,7 +42,10 @@ const f7init = (rootEl, params = {}, init = true) => {
3242
theme.aurora = device.desktop && device.electron;
3343
theme.md = !theme.ios && !theme.aurora;
3444
}
35-
if (f7) return;
45+
// eslint-disable-next-line
46+
if (f7 && typeof window !== 'undefined') return;
47+
48+
cleanup();
3649

3750
const instance = new Framework7(f7Params);
3851
f7 = instance;

src/svelte/shared/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export function createEmitter(createEventDispatcher, props) {
9191
let routerIdCounter = 0;
9292
let routerComponentIdCounter = 0;
9393

94+
export function unsetRouterIds() {
95+
routerIdCounter = 0;
96+
routerComponentIdCounter = 0;
97+
}
98+
9499
export function getRouterId() {
95100
routerIdCounter += 1;
96101
return `${now()}_${routerIdCounter}`;

src/vue/shared/f7.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable import/no-mutable-exports */
22
import Framework7 from 'framework7/lite';
3-
import { extend } from './utils';
3+
import { extend, unsetRouterIds } from './utils';
44

55
let f7;
66
let f7events;
@@ -13,6 +13,16 @@ const f7routers = {
1313
modals: null,
1414
};
1515

16+
const cleanup = () => {
17+
unsetRouterIds();
18+
delete theme.ios;
19+
delete theme.md;
20+
delete theme.aurora;
21+
f7routers.views = [];
22+
f7routers.tabs = [];
23+
f7routers.modals = null;
24+
};
25+
1626
const f7initEvents = () => {
1727
f7events = new Framework7.Events();
1828
};
@@ -31,7 +41,10 @@ const f7init = (rootEl, params = {}, init = true) => {
3141
theme.aurora = device.desktop && device.electron;
3242
theme.md = !theme.ios && !theme.aurora;
3343
}
34-
if (f7) return;
44+
// eslint-disable-next-line
45+
if (f7 && typeof window !== 'undefined') return;
46+
47+
cleanup();
3548

3649
const instance = new Framework7(f7Params);
3750
f7 = instance;

src/vue/shared/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export function classNames(...args) {
7070
let routerIdCounter = 0;
7171
let routerComponentIdCounter = 0;
7272

73+
export function unsetRouterIds() {
74+
routerIdCounter = 0;
75+
routerComponentIdCounter = 0;
76+
}
77+
7378
export function getRouterId() {
7479
routerIdCounter += 1;
7580
return `${now()}_${routerIdCounter}`;

0 commit comments

Comments
 (0)