Skip to content

Commit

Permalink
Merge branch 'master' into fix-windows-test
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews authored Nov 13, 2017
2 parents 3403b73 + 3267d6e commit fb62b54
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/gatsby-link/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export interface GatsbyLinkProps extends NavLinkProps {

export const navigateTo: (path: string) => void;

export const withPrefix: (path: string) => string;

export default class GatsbyLink extends React.Component<GatsbyLinkProps> { }
17 changes: 15 additions & 2 deletions packages/gatsby/cache-dir/component-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ const DefaultLayout = ({ children }) => <div>{children()}</div>
class ComponentRenderer extends React.Component {
constructor(props) {
super()
let location = props.location

// This covers layout for when page not found, especially during production
if (!loader.getPage(location.pathname)) {
location = Object.assign({}, location, {
...location,
pathname: `/404.html`,
})
}

this.state = {
location: props.location,
location,
pageResources: loader.getResourcesForPathname(props.location.pathname),
}
}
Expand Down Expand Up @@ -61,7 +71,10 @@ class ComponentRenderer extends React.Component {
// This is only useful on delayed transitions as the page will get rendered
// without the necessary page resources and then re-render once those come in.
emitter.on(`onPostLoadPageResources`, e => {
if (e.page.path === loader.getPage(this.state.location.pathname).path) {
if (
loader.getPage(this.state.location.pathname) &&
e.page.path === loader.getPage(this.state.location.pathname).path
) {
this.setState({ pageResources: e.pageResources })
}
})
Expand Down
13 changes: 9 additions & 4 deletions packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,15 @@ const queue = {
navigator.serviceWorker
.getRegistrations()
.then(function(registrations) {
for (let registration of registrations) {
registration.unregister()
// We would probably need this to
// prevent unnecessary reloading of the page
// while unregistering of ServiceWorker is not happening
if (registrations.length) {
for (let registration of registrations) {
registration.unregister()
}
window.location.reload()
}
window.location.reload()
})
}
}
Expand All @@ -249,7 +254,7 @@ const queue = {

if (!page) {
console.log(`A page wasn't found for "${path}"`)
return
return cb()
}

// Use the path from the page so the pathScriptsCache uses
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ apiRunnerAsync(`onClientEntry`).then(() => {
})
} else {
return createElement(ComponentRenderer, {
location: { page: true, pathname: `/404.html` },
page: true,
location: { pathname: `/404.html` },
})
}
},
Expand Down

0 comments on commit fb62b54

Please sign in to comment.