diff --git a/packages/gatsby/cache-dir/__tests__/ensure-resources.tsx b/packages/gatsby/cache-dir/__tests__/ensure-resources.tsx new file mode 100644 index 0000000000000..0613effcbdb04 --- /dev/null +++ b/packages/gatsby/cache-dir/__tests__/ensure-resources.tsx @@ -0,0 +1,33 @@ +import React from "react" +import EnsureResources from "../ensure-resources" +import { render, getNodeText, cleanup } from "@testing-library/react" + +jest.mock(`../loader`, () => { + return { + loadPageSync(path: string): { loadPageSync: boolean; path: string } { + return { loadPageSync: true, path } + }, + loadPage(path: string): Promise<{ loadPage: boolean; path: string }> { + return Promise.resolve({ loadPage: true, path }) + }, + } +}) + +afterAll(cleanup) + +describe(`EnsureResources`, () => { + it(`loads pages synchronously`, () => { + const location = { + pathname: `/`, + } + const { container } = render( + + {(data: any): string => JSON.stringify(data.pageResources)} + + ) + + expect(getNodeText(container)).toMatchInlineSnapshot( + `"{\\"loadPageSync\\":true,\\"path\\":\\"/\\"}"` + ) + }) +}) diff --git a/packages/gatsby/cache-dir/ensure-resources.js b/packages/gatsby/cache-dir/ensure-resources.js index 2c67ce2619857..e67c6b1423b9e 100644 --- a/packages/gatsby/cache-dir/ensure-resources.js +++ b/packages/gatsby/cache-dir/ensure-resources.js @@ -74,6 +74,14 @@ class EnsureResources extends React.Component { } render() { + if (process.env.NODE_ENV !== `production` && !this.state.pageResources) { + throw new Error( + `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. +Run \`gatsby clean\` to remove any cached elements.` + ) + } + return this.props.children(this.state) } } diff --git a/tsconfig.json b/tsconfig.json index 0b0873225b647..866b23e3c91b6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,8 @@ "strictPropertyInitialization": true, "noFallthroughCasesInSwitch": true, "resolveJsonModule": true, - "esModuleInterop": true + "esModuleInterop": true, + "jsx": "preserve" }, "exclude": ["peril/*", "examples/*"] }