Skip to content

Commit ac6d52c

Browse files
committed
Optimization of Community Loader and routing...
to avoid unnecessary reloading of related code chunks.
1 parent 0c37799 commit ac6d52c

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

docs/code-splitting.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ First of all, under the hood `SplitRoute` uses **react-router**'s `Route` to mak
8282
8383
In general, you want to ensure that `renderServer` and `renderClientAsync` functions render exactly the same component, so that when you go directly to the route, you don't see any changes in the page during its loading, it just loads in its target form from the beginning. Though, technically, it is not obligatory to render the same in this functions. If they render different things, then the components rendered by `renderServer` will be visible until the moment when the `renderClientAsync` finishes rendering at the client side, and then the content will be switched to the result of `renderClientAsync`.
8484
85-
- By default, when you leave a split route, the CSS reference is removed from the document. You can pass in boolean `cacheCss` option to prevent it.
86-
8785
### Caveats
8886
8987
Here are some non-trivial points, that should be merged into the body of documentation above, but for now they are just mentioned here as points to remember:

src/shared/containers/tc-communities/Loader.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Loader extends React.Component {
6666
}
6767

6868
/* Community does not require authorization. */
69-
if (!meta.authorizedGroupIds) return <Community meta={meta} />;
69+
if (!meta.authorizedGroupIds) return Community({ meta });
7070

7171
/* Visitor is not authenticated. */
7272
if (!visitorGroups) {
@@ -82,7 +82,7 @@ class Loader extends React.Component {
8282
/* Visitor belongs to at least one of the groups authorized to access this
8383
* community. */
8484
if (_.intersection(visitorGroups.map(g => g.id), meta.authorizedGroupIds)) {
85-
return <Community meta={meta} />;
85+
return Community({ meta });
8686
}
8787

8888
/* Visitor is not authorized to access this community. */

src/shared/routes/Communities/Veterans/Routes.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Route, Switch } from 'react-router-dom';
1414
import ChallengeListing from '../ChallengeListing';
1515
import Leaderboard from '../Leaderboard';
1616

17-
export default function Wipro({ base, meta }) {
17+
export default function Routes({ base, meta }) {
1818
return (
1919
<Route
2020
component={({ match }) => (
@@ -56,11 +56,11 @@ export default function Wipro({ base, meta }) {
5656
);
5757
}
5858

59-
Wipro.defaultProps = {
59+
Routes.defaultProps = {
6060
base: '',
6161
};
6262

63-
Wipro.propTypes = {
63+
Routes.propTypes = {
6464
base: PT.string,
6565
meta: PT.shape().isRequired,
6666
};

src/shared/routes/Communities/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { requireWeak, resolveWeak, SplitRoute } from 'utils/router';
1212
export default function ChunkLoader({ base, communityId, meta }) {
1313
return (
1414
<SplitRoute
15-
cacheCss
1615
chunkName="communities"
1716
renderClientAsync={() =>
1817
import(

src/shared/routes/index.jsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ function Routes({ subdomains }) {
4242
<Route exact path="/" component={Content} />
4343
{ Examples() }
4444
<Route
45-
component={({ match }) => (
45+
render={({ match }) => (
4646
<CommunityLoader
47-
communityComponent={({ meta }) => (
48-
<Communities
49-
base={match.url}
50-
communityId={match.params.communityId}
51-
meta={meta}
52-
/>
53-
)}
47+
communityComponent={({ meta }) => {
48+
let base = match.url;
49+
while (base.endsWith('/')) base = base.slice(0, -1);
50+
return (
51+
<Communities
52+
base={base}
53+
communityId={match.params.communityId}
54+
meta={meta}
55+
/>
56+
);
57+
}}
5458
communityId={match.params.communityId}
5559
/>
5660
)}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"disclaimer":"Usage subject to terms: https://openexchangerates.org/terms","license":"https://openexchangerates.org/license","timestamp":1503320400,"base":"USD","rates":{"AED":3.673158,"AFN":68.656,"ALL":112.41,"AMD":478.39,"ANG":1.779113,"AOA":165.9205,"ARS":17.34,"AUD":1.258533,"AWG":1.788333,"AZN":1.686,"BAM":1.662492,"BBD":2,"BDT":81.260068,"BGN":1.661406,"BHD":0.37722,"BIF":1738.3,"BMD":1,"BND":1.362399,"BOB":6.971365,"BRL":3.143578,"BSD":1,"BTC":0.000245786919,"BTN":64.109632,"BWP":10.199062,"BYN":1.930973,"BZD":2.014625,"CAD":1.257105,"CDF":1600.102407,"CHF":0.965015,"CLF":0.02406,"CLP":642.74,"CNH":6.674255,"CNY":6.66995,"COP":2987.85,"CRC":576.636761,"CUC":1,"CUP":25.5,"CVE":93.739999,"CZK":22.1381,"DJF":177.88,"DKK":6.313208,"DOP":47.235401,"DZD":109.8775,"EGP":17.751,"ERN":15.335,"ETB":23.365963,"EUR":0.848867,"FJD":2.029307,"FKP":0.775561,"GBP":0.775561,"GEL":2.3901,"GGP":0.775561,"GHS":4.41592,"GIP":0.775561,"GMD":45.25,"GNF":8888.3,"GTQ":7.270847,"GYD":207.863351,"HKD":7.823825,"HNL":23.362162,"HRK":6.285378,"HTG":64.443846,"HUF":257.4805,"IDR":13349.27042,"ILS":3.61777,"IMP":0.775561,"INR":64.1222,"IQD":1167.4,"IRR":32829,"ISK":105.58884,"JEP":0.775561,"JMD":127.77,"JOD":0.709001,"JPY":108.9369,"KES":103.1,"KGS":68.727849,"KHR":4114.8,"KMF":419.45,"KPW":900,"KRW":1138.3,"KWD":0.301816,"KYD":0.832923,"KZT":332.730868,"LAK":8282.1,"LBP":1505.7,"LKR":153.078195,"LRD":114.700001,"LSL":13.173642,"LYD":1.370305,"MAD":9.477963,"MDL":17.849263,"MGA":2958.4,"MKD":52.2547,"MMK":1358.8,"MNT":2439.959961,"MOP":8.053858,"MRO":364.81,"MUR":33.435,"MVR":15.47,"MWK":725.275,"MXN":17.66503,"MYR":4.286787,"MZN":61.28,"NAD":13.195,"NGN":362.5,"NIO":29.950331,"NOK":7.88513,"NPR":102.543085,"NZD":1.364778,"OMR":0.385005,"PAB":1,"PEN":3.242597,"PGK":3.180222,"PHP":51.3985,"PKR":105.328422,"PLN":3.62423,"PYG":5576.1,"QAR":3.638,"RON":3.89236,"RSD":101.355,"RUB":58.984213,"RWF":827.576066,"SAR":3.7504,"SBD":7.754399,"SCR":13.638957,"SDG":6.673181,"SEK":8.080053,"SGD":1.361433,"SHP":0.775561,"SLL":7550,"SOS":578.19,"SRD":7.438,"SSP":125.3948,"STD":20813.700196,"SVC":8.745961,"SYP":514.98999,"SZL":13.163774,"THB":33.244,"TJS":8.805499,"TMT":3.466667,"TND":2.404752,"TOP":2.215897,"TRY":3.495594,"TTD":6.767229,"TWD":30.33,"TZS":2240,"UAH":25.476771,"UGX":3601.15,"USD":1,"UYU":28.563778,"UZS":4152.15,"VEF":10.303375,"VND":22718.166667,"VUV":104.118876,"WST":2.488972,"XAF":556.820087,"XAG":0.05864423,"XAU":0.00077622,"XCD":2.70255,"XDR":0.709706,"XOF":556.820087,"XPD":0.00106943,"XPF":101.296748,"XPT":0.00101627,"YER":249.878749,"ZAR":13.167543,"ZMW":9.014201,"ZWL":322.355011}}
1+
{"disclaimer":"Usage subject to terms: https://openexchangerates.org/terms","license":"https://openexchangerates.org/license","timestamp":1503399600,"base":"USD","rates":{"AED":3.673019,"AFN":68.387,"ALL":112.55,"AMD":476.515,"ANG":1.771845,"AOA":165.9205,"ARS":17.325,"AUD":1.265029,"AWG":1.788333,"AZN":1.7,"BAM":1.6639,"BBD":2,"BDT":80.939,"BGN":1.664065,"BHD":0.377261,"BIF":1731.5,"BMD":1,"BND":1.362596,"BOB":6.944074,"BRL":3.1642,"BSD":1,"BTC":0.000254483797,"BTN":59.909724,"BWP":10.158618,"BYN":1.923225,"BZD":2.006554,"CAD":1.258689,"CDF":1600.102407,"CHF":0.965888,"CLF":0.02394,"CLP":643.093466,"CNH":6.66775,"CNY":6.6627,"COP":2987.01,"CRC":573.4675,"CUC":1,"CUP":25.5,"CVE":93.843617,"CZK":22.2122,"DJF":177.893333,"DKK":6.327696,"DOP":47.053722,"DZD":110.159159,"EGP":17.769952,"ERN":15.341862,"ETB":23.271505,"EUR":0.850823,"FJD":2.009699,"FKP":0.77966,"GBP":0.77966,"GEL":2.389525,"GGP":0.77966,"GHS":4.4275,"GIP":0.77966,"GMD":45.25,"GNF":8853.5,"GTQ":7.240934,"GYD":207.0974,"HKD":7.826115,"HNL":23.271595,"HRK":6.2985,"HTG":64.184,"HUF":258.507,"IDR":13345.237631,"ILS":3.62159,"IMP":0.77966,"INR":64.155,"IQD":1162.8,"IRR":32840.5,"ISK":105.893433,"JEP":0.77966,"JMD":127.300536,"JOD":0.709001,"JPY":109.2927619,"KES":103.16,"KGS":60.187066,"KHR":4098.75,"KMF":397.129997,"KPW":900,"KRW":1135.65,"KWD":0.30193,"KYD":0.829567,"KZT":332.64,"LAK":8249.65,"LBP":1499.85,"LKR":153.06,"LRD":114.700001,"LSL":13.119775,"LYD":1.364986,"MAD":9.477025,"MDL":17.900385,"MGA":2946.9,"MKD":52.4,"MMK":1353.5,"MNT":2439.7609,"MOP":8.021147,"MRO":363.385,"MUR":33.364,"MVR":14.596667,"MWK":725.3,"MXN":17.67967,"MYR":4.2805,"MZN":61.365,"NAD":13.21625,"NGN":361,"NIO":29.829763,"NOK":7.916412,"NPR":102.13956,"NZD":1.373152,"OMR":0.385022,"PAB":1,"PEN":3.239525,"PGK":3.167804,"PHP":51.289,"PKR":104.905,"PLN":3.637954,"PYG":5554.3,"QAR":3.6237,"RON":3.900091,"RSD":101.5575,"RUB":59.0603,"RWF":826.672132,"SAR":3.750799,"SBD":7.754399,"SCR":13.546491,"SDG":6.646367,"SEK":8.117208,"SGD":1.362567,"SHP":0.77966,"SLL":7550,"SOS":576.388119,"SRD":7.438,"SSP":125.546,"STD":20837.600445,"SVC":8.710859,"SYP":414.87666,"SZL":13.112571,"THB":33.2375,"TJS":8.769872,"TMT":3.4667,"TND":2.465703,"TOP":2.218744,"TRY":3.49974,"TTD":6.740654,"TWD":30.306919,"TZS":2239,"UAH":25.376878,"UGX":3586.7,"USD":1,"UYU":28.494266,"UZS":4135.9,"VEF":10.339723,"VND":22723.202982,"VUV":105.009694,"WST":2.499798,"XAF":558.103452,"XAG":0.05878903,"XAU":0.00077736,"XCD":2.70255,"XDR":0.709489,"XOF":558.103452,"XPD":0.00106907,"XPF":101.530218,"XPT":0.00102592,"YER":250.349999,"ZAR":13.210727,"ZMW":9.025,"ZWL":322.355011}}

0 commit comments

Comments
 (0)