Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cached content if Promise rejected #497

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export function getContent([lang, name]) {
if (!ext) url += '.md';

// In prod, never re-fetch the content (url is just a convenient compound cache key)
if (process.env.NODE_ENV === 'production' && url in CACHE) {
return CACHE[url];
}
// if (process.env.NODE_ENV === 'production' && url in CACHE) {
// // eslint-disable-next-line no-console
// console.log(CACHE);
// return CACHE[url];
// }

let fallback = false;
const res = fetch(url)
Expand All @@ -45,6 +47,11 @@ export function getContent([lang, name]) {
.then(data => {
data.fallback = fallback;
return data;
})
.catch(err => {
// eslint-disable-next-line no-console
console.log(err);
CACHE[url] = undefined;
});
return (CACHE[url] = res);
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/hydrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class Hydrator extends Component {
_render(props) {
const { Child } = this;
// hydrate on first run, then normal renders thereafter
const doRender = process.env.NODE_ENV!=='production' || this.hydrated ? render : hydrate;
doRender(
const doRender =
process.env.NODE_ENV !== 'production' || this.hydrated ? render : hydrate;
render(
<ContextProvider context={this.context}>
<Child {...props} />
</ContextProvider>,
Expand Down