Skip to content

Commit a1f4719

Browse files
committed
fix: issues in SSR mode
1 parent b7a6fdd commit a1f4719

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

jest.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ module.exports = compose(
1414
'./jest.setup.js',
1515
];
1616

17-
config.moduleNameMapper = {
18-
'NextScrollBehavior\\.node$': '<rootDir>/src/scroll-behavior/NextScrollBehavior.browser.js',
19-
...config.moduleNameMapper,
20-
};
21-
2217
return config;
2318
},
2419
);

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
"lib",
99
"es"
1010
],
11-
"browser": {
12-
"lib/scroll-behavior/NextScrollBehavior.node.js": "./lib/scroll-behavior/NextScrollBehavior.browser.js",
13-
"es/scroll-behavior/NextScrollBehavior.node.js": "./es/scroll-behavior/NextScrollBehavior.browser.js"
14-
},
1511
"homepage": "https://github.com/moxystudio/next-router-scroll#readme",
1612
"author": "Afonso Reis <[email protected]>",
1713
"license": "MIT",

src/RouterScrollProvider.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const useScrollBehavior = (shouldUpdateScroll) => {
2929

3030
shouldUpdateScrollRef.current = shouldUpdateScroll;
3131

32-
if (!scrollBehaviorRef.current && typeof window !== 'undefined') {
32+
if (!scrollBehaviorRef.current) {
3333
scrollBehaviorRef.current = new NextScrollBehavior(
34-
(...args) => shouldUpdateScrollRef.current?.(...args),
34+
(...args) => shouldUpdateScrollRef.current(...args),
3535
);
3636
}
3737

@@ -50,9 +50,9 @@ const ScrollBehaviorProvider = ({ disableNextLinkScroll, shouldUpdateScroll, chi
5050

5151
// Create facade to use as the provider value.
5252
const providerValue = useMemo(() => ({
53-
updateScroll: scrollBehavior ? scrollBehavior.updateScroll.bind(scrollBehavior) : () => {},
54-
registerElement: scrollBehavior ? scrollBehavior.registerElement.bind(scrollBehavior) : () => {},
55-
unregisterElement: scrollBehavior ? scrollBehavior.unregisterElement.bind(scrollBehavior) : () => {},
53+
updateScroll: scrollBehavior.updateScroll.bind(scrollBehavior),
54+
registerElement: scrollBehavior.registerElement.bind(scrollBehavior),
55+
unregisterElement: scrollBehavior.unregisterElement.bind(scrollBehavior),
5656
}), [scrollBehavior]);
5757

5858
return (
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export default class NextScrollBehaviorMock {}
1+
export default class NextScrollBehaviorMock {
2+
updateScroll() {}
3+
registerElement() {}
4+
unregisterElement() {}
5+
}

src/scroll-behavior/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export { default } from './NextScrollBehavior.node';
1+
/* eslint-disable import/no-commonjs */
2+
3+
module.exports = typeof window === 'undefined' ?
4+
require('./NextScrollBehavior.node') :
5+
require('./NextScrollBehavior.browser');

0 commit comments

Comments
 (0)