Skip to content

Commit 8473797

Browse files
committed
fix: do not make page swapper height 100% by default
This was causing issues on nested layouts. Now you must be specific by using className & pageTransitionClassName.
1 parent ba2cafc commit 8473797

File tree

7 files changed

+36
-26
lines changed

7 files changed

+36
-26
lines changed

www/app/App.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import CookieBanner from './cookie-banner';
1616
import useFouc from './use-fouc-fix';
1717
import { useSeoData } from './App.data';
1818

19+
import styles from './App.module.css';
20+
1921
subscribeToRouter();
2022

2123
export const App = ({ Component, pageProps }) => {
@@ -62,7 +64,13 @@ export const App = ({ Component, pageProps }) => {
6264
pageProps={ pageProps }
6365
pageKey={ pageKey }
6466
defaultLayout={ <MainLayout /> }>
65-
{ (tree) => <PageSwapper node={ tree } nodeKey={ tree.key } /> }
67+
{ (tree) => (
68+
<PageSwapper
69+
node={ tree }
70+
nodeKey={ tree.key }
71+
pageTransitionClassName={ styles.pageTransition }
72+
className={ styles.pageSwapper } />
73+
) }
6674
</LayoutTree>
6775
</RouterScrollProvider>
6876
</>

www/app/App.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.pageSwapper {
2+
height: 100%;
3+
4+
& .pageTransition {
5+
height: 100%;
6+
}
7+
}

www/shared/react/main-layout/MainLayout.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ const MainLayout = ({ children, className, ...rest }) => (
1111
<div className={ classNames(styles.mainLayout, className) } { ...rest }>
1212
<Header className={ styles.header } />
1313

14-
<div className={ styles.content }>
14+
{ children &&
1515
<PageSwapper
1616
node={ children }
17-
nodeKey={ children.key }>
17+
nodeKey={ children.key }
18+
pageTransitionClassName={ styles.pageTransition }
19+
className={ styles.pageSwapper }>
1820
{ ({ node }) => (
1921
<>
2022
<div className={ styles.page }>{ node }</div>
2123
<Footer className={ styles.footer } />
2224
</>
2325
) }
2426
</PageSwapper>
25-
</div>
27+
}
2628
</div>
2729
);
2830

www/shared/react/main-layout/MainLayout.module.css

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111
flex: 0 0 auto;
1212
}
1313

14-
& .content {
14+
& .pageSwapper {
1515
display: flex;
1616
flex: 1 0;
1717
flex-direction: column;
1818

19-
& .page {
19+
& .pageTransition {
20+
display: flex;
2021
flex: 1 0;
21-
}
22+
flex-direction: column;
23+
24+
& .page {
25+
flex: 1 0;
26+
}
2227

23-
& .footer {
24-
flex: 0 0 auto;
28+
& .footer {
29+
flex: 0 0 auto;
30+
}
2531
}
2632
}
2733
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import classNames from 'classnames';
43
import RawPageSwapper from '@moxy/react-page-swapper'; // eslint-disable-line no-restricted-imports
54
import { useRouterScroll } from '@moxy/next-router-scroll';
65
import PageTransition from './page-transition';
76

8-
import styles from './PageSwapper.module.css';
9-
10-
const PageSwapper = ({ children, className, ...rest }) => {
7+
const PageSwapper = ({ children, pageTransitionClassName, ...rest }) => {
118
const { updateScroll } = useRouterScroll();
129

1310
return (
14-
<RawPageSwapper
15-
{ ...rest }
16-
updateScroll={ updateScroll }
17-
className={ classNames(styles.pageSwapper, className) }>
11+
<RawPageSwapper { ...rest } updateScroll={ updateScroll }>
1812
{ ({ node, ...rest }) => {
1913
if (typeof children === 'function') {
2014
node = children({ node, ...rest });
2115
}
2216

23-
return <PageTransition node={ node } { ...rest } />;
17+
return <PageTransition node={ node } className={ pageTransitionClassName } { ...rest } />;
2418
} }
2519
</RawPageSwapper>
2620
);
2721
};
2822

2923
PageSwapper.propTypes = {
3024
children: PropTypes.func,
31-
className: PropTypes.string,
25+
pageTransitionClassName: PropTypes.string,
3226
};
3327

3428
export default PageSwapper;

www/shared/react/page-swapper/PageSwapper.module.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

www/shared/react/page-swapper/page-transition/PageTransition.module.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
.fade {
2-
height: 100%;
3-
display: flex;
4-
flex-direction: column;
5-
62
&.enter {
73
opacity: 0;
84
}

0 commit comments

Comments
 (0)