Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
Swapped react-router-scroll with react-router-scroll-async
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmr committed Dec 21, 2016
1 parent f0ee11e commit f0c4a28
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
11 changes: 8 additions & 3 deletions extensions/roc-package-web-app-react/app/client/create-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import createHistory from 'history/lib/createBrowserHistory';
import { supportsHistory } from 'history/lib/DOMUtils';
import debug from 'debug';
import { useRedial } from 'react-router-redial';
import useScroll from 'react-router-scroll/lib/useScroll';
import useScroll from 'react-router-scroll-async/lib/useScroll';

import { rocConfig } from '../shared/universal-config';

Expand Down Expand Up @@ -163,19 +163,24 @@ export default function createClient({ createRoutes, createStore, mountNode }) {
));
}

let updateScroll = () => {};

const finalComponent = compose(createComponent)(
<Router
history={history}
routes={routes}
render={applyRouterMiddleware(
useScroll(),
useScroll({
updateScroll: (cb) => { updateScroll = cb; },
}),
useRedial({
locals,
initialLoading,
beforeTransition: rocConfig.runtime.fetch.client.beforeTransition,
afterTransition: rocConfig.runtime.fetch.client.afterTransition,
parallel: rocConfig.runtime.fetch.client.parallel,
})
onCompleted: (type) => type === 'beforeTransition' && updateScroll(),
}),
)}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion extensions/roc-package-web-app-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"react-router": "~2.8.1",
"react-router-redial": "~0.3.0",
"react-router-redux": "~4.0.2",
"react-router-scroll": "~0.3.2",
"react-router-scroll-async": "~0.5.0",
"react-server-status": "~1.0.0",
"redial": "~0.5.0",
"redux": "~3.4.0",
Expand Down
57 changes: 40 additions & 17 deletions extensions/roc-package-web-app-react/src/roc/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { generateDependencies } from 'roc';
import { warn } from 'roc/log/default/large';

import config from '../config/roc.config';
import meta from '../config/roc.config.meta';

const packageJSON = require('../../package.json');

let warnForReactRouterScroll = true;

export default {
config,
meta,
Expand All @@ -15,23 +18,43 @@ export default {
require.resolve('roc-plugin-react'),
],
dependencies: {
exports: generateDependencies(packageJSON, [
'history',
'intl',
'intl-locales-supported',
'react-helmet',
'react-redux',
'react-router',
'react-router-redux',
'react-server-status',
'redial',
'redux-saga',
'react-router-redial',
'react-router-scroll',
'redux',
'redux-thunk',
'roc-package-web-app',
]),
exports: {
...generateDependencies(packageJSON, [
'history',
'intl',
'intl-locales-supported',
'react-helmet',
'react-redux',
'react-router',
'react-router-redux',
'react-server-status',
'redial',
'redux-saga',
'react-router-redial',
'react-router-scroll-async',
'redux',
'redux-thunk',
'roc-package-web-app',
]),
'react-router-scroll': {
version: 'DEPRECATED - Use react-router-scroll-async',
resolve: ({ request }) => {
// We will currently write out this two times, once when we build the application with webpack
// and once when we run it in Node. A nice way to give the warnings we print out more substance
// is to provide the instance that the function is running in, something we could provide.
if (warnForReactRouterScroll) {
warn(
'react-router-scroll is deprecated, please change references to react-router-scroll-async',
'Deprecation'
);
}
warnForReactRouterScroll = false;
return require.resolve(
request.replace('react-router-scroll', 'react-router-scroll-async')
);
},
},
},
uses: generateDependencies(packageJSON, [
'nunjucks',
]),
Expand Down

0 comments on commit f0c4a28

Please sign in to comment.