Skip to content

Commit

Permalink
Throw error if the pageResource fails to load
Browse files Browse the repository at this point in the history
  • Loading branch information
blainekasten committed Feb 13, 2020
1 parent 178aad6 commit 96ab5d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/gatsby/cache-dir/__tests__/ensure-resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jest.mock("../loader", () => ({
afterAll(cleanup)

describe("EnsureResources", () => {
it("works", () => {
it("loads pages synchronously", () => {
const location = {
pathname: "/",
}
Expand All @@ -23,7 +23,6 @@ describe("EnsureResources", () => {
{data => JSON.stringify(data.pageResources)}
</EnsureResources>
)
console.log(container)

expect(getNodeText(container)).toMatchInlineSnapshot(
`"{\\"loadPageSync\\":true,\\"path\\":\\"/\\"}"`
Expand Down
16 changes: 10 additions & 6 deletions packages/gatsby/cache-dir/ensure-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ class EnsureResources extends React.Component {
})
}

componentDidMount() {
if (!this.state.pageResources) {
this.loadResources(this.props.location.pathname)
}
}

shouldComponentUpdate(nextProps, nextState) {
// Always return false if we're missing resources.
if (!nextState.pageResources) {
Expand Down Expand Up @@ -80,6 +74,16 @@ class EnsureResources extends React.Component {
}

render() {
if (!this.state.pageResources) {
console.warn(
`EnsureResources was not able to find resources for path: "${this.props.location.pathname}"`,
`This typically means that an issue occurred building components for that path`
)
throw new Error(
`EnsureResources was not able to find resources for path: "${this.props.location.pathname}"`
)
}

return this.props.children(this.state)
}
}
Expand Down

0 comments on commit 96ab5d5

Please sign in to comment.