Skip to content

Commit 09069ff

Browse files
authored
[v2] WIP implementing RFC #2 removing special layout component (#4887)
[v2] Implement RFC #2 removing special layout component
1 parent 7df551e commit 09069ff

File tree

112 files changed

+1890
-2455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1890
-2455
lines changed

.babel-preset.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function preset(context, options = {}) {
4242
],
4343
plugins: [
4444
r("@babel/plugin-proposal-class-properties"),
45+
r("@babel/plugin-proposal-optional-chaining"),
4546
[
4647
r("@babel/plugin-transform-runtime"),
4748
{

Breaking Changes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* Remove explicit polyfill and use the new builtins: usage support in babel 7.
66
* Changed `modifyBabelrc` to `onCreateBabelConfig`
77
* Changed `modifyWebpackConfig` to `onCreateWebpackConfig`
8-
* inlining css changed — remove it as done automatically by core now.
8+
* inlining css changed — remove it from any custom html.js as done automatically by core now.

docs/docs/api-specification.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ See
5656
## Concepts
5757

5858
* _Page_ — a site page with a pathname, a template component, and optional
59-
graphql query and layout component
59+
graphql query.
6060
* _Page Component_ — React.js component that renders a page and can optionally
61-
specify a layout component and a graphql query
61+
specify a graphql query
6262
* _Component extensions_ — extensions that are resolvable as components. `.js`
6363
and `.jsx` are supported by core. But plugins can add support for other
6464
compile-to-js languages.

docs/docs/building-with-components.md

+1-29
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ A basic directory structure of a project might look like this:
4040
   │      └── 01-03-2017
4141
   │         └── index.md
4242
   ├── templates
43-
   │ └── post.jsx
44-
45-
└── layouts
46-
└── index.jsx
43+
   └── post.jsx
4744
```
4845

4946
### Page components
@@ -117,31 +114,6 @@ export const pageQuery = graphql`
117114
`;
118115
```
119116

120-
### Layout components
121-
122-
`src/layouts/index.jsx` (optional) wraps page components. You can use it for
123-
portions of pages that are shared across pages like headers and footers.
124-
125-
You can use the `location` prop to render conditionally based on the page
126-
URL.
127-
128-
Example:
129-
130-
```jsx
131-
import React from "react";
132-
import Navigation from "../components/Navigation/Navigation.jsx";
133-
134-
export default class Template extends React.Component {
135-
render() {
136-
if (this.props.location.pathname !== "/") {
137-
return <Navigation>{this.props.children()}</Navigation>;
138-
} else {
139-
return this.props.children();
140-
}
141-
}
142-
}
143-
```
144-
145117
### HTML component
146118

147119
`src/html.jsx` is responsible for everything other than where Gatsby lives in

docs/docs/creating-and-modifying-pages.md

-32
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ exports.createPages = ({ boundActionCreators, graphql }) => {
8484
createPage({
8585
path,
8686
component: blogPostTemplate,
87-
// If you have a layout component at src/layouts/blog-layout.js
88-
layout: `blog-layout`,
8987
// In your blog post template's graphql query, you can use path
9088
// as a GraphQL variable to query for data from the markdown file.
9189
context: {
@@ -133,33 +131,3 @@ exports.onCreatePage = ({ page, boundActionCreators }) => {
133131
});
134132
};
135133
```
136-
137-
### Choosing the page layout
138-
139-
By default, all pages will use the layout found at `/layouts/index.js`.
140-
141-
You may wish to choose a custom layout for certain pages (such as removing
142-
header and footer for landing pages). You can choose the layout component when
143-
creating pages with the `createPage` action by adding a layout key to the page
144-
object or modify pages created elsewhere using the `onCreatePage` API. All
145-
components in the `/layouts/` directory are automatically available.
146-
147-
```javascript
148-
// Implement the Gatsby API “onCreatePage”. This is
149-
// called after every page is created.
150-
exports.onCreatePage = async ({ page, boundActionCreators }) => {
151-
const { createPage } = boundActionCreators;
152-
153-
return new Promise((resolve, reject) => {
154-
if (page.path.match(/^\/landing-page/)) {
155-
// It's assumed that `landingPage.js` exists in the `/layouts/` directory
156-
page.layout = "landingPage";
157-
158-
// Update the page.
159-
createPage(page);
160-
}
161-
162-
resolve();
163-
});
164-
};
165-
```

examples/client-only-paths/gatsby-config.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ module.exports = {
44
},
55
plugins: [
66
{
7-
resolve: `gatsby-plugin-google-analytics`,
7+
resolve: `gatsby-plugin-typography`,
88
options: {
9-
trackingId: `UA-93349937-2`,
9+
pathToConfigModule: `src/utils/typography`,
1010
},
1111
},
12-
`gatsby-plugin-offline`,
1312
],
1413
}

examples/client-only-paths/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
"version": "1.0.0",
66
"author": "Kyle Mathews <[email protected]>",
77
"dependencies": {
8-
"gatsby": "latest",
9-
"gatsby-plugin-google-analytics": "latest",
10-
"gatsby-plugin-offline": "latest",
11-
"gatsby-source-drupal": "latest",
8+
"gatsby": "canary",
9+
"gatsby-plugin-typography": "canary",
1210
"lodash": "^4.16.4",
11+
"react": "^16.3.1",
1312
"react-addons-css-transition-group": "^15.5.2",
14-
"react-typography": "^0.15.0",
13+
"react-dom": "^16.3.1",
14+
"react-typography": "^0.16.13",
1515
"slash": "^1.0.0",
16-
"typography": "^0.15.8",
17-
"typography-breakpoint-constants": "^0.14.0"
16+
"typography": "^0.16.6",
17+
"typography-breakpoint-constants": "^0.15.10"
1818
},
1919
"keywords": [
2020
"gatsby"
@@ -25,4 +25,4 @@
2525
"develop": "gatsby develop",
2626
"build": "gatsby build"
2727
}
28-
}
28+
}

examples/client-only-paths/src/html.js

-67
This file was deleted.

examples/client-only-paths/src/layouts/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react"
22
import { Link } from "gatsby"
33

4-
import { rhythm } from "../utils/typography"
4+
import typography from "../utils/typography"
5+
const { rhythm } = typography
56

67
class DefaultLayout extends React.Component {
78
render() {
@@ -21,7 +22,7 @@ class DefaultLayout extends React.Component {
2122
Example of adding client only paths
2223
</h3>
2324
</Link>
24-
{this.props.children()}
25+
{this.props.children}
2526
</div>
2627
)
2728
}

examples/client-only-paths/src/pages/index.js

+36-33
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,54 @@ import ReactCSSTransitionGroup from "react-addons-css-transition-group"
44
import { Route, Redirect } from "react-router-dom"
55

66
import "./main.css"
7+
import Layout from "../layouts"
78

89
class AnimationExample extends React.Component {
910
render() {
1011
return (
11-
<div style={{ position: `relative`, minHeight: `80vh` }}>
12-
<Route
13-
render={({ location }) => (
14-
<div style={styles.fill}>
15-
<Route
16-
exact
17-
path="/"
18-
render={() => <Redirect to="/10/90/50" />}
19-
/>
12+
<Layout>
13+
<div style={{ position: `relative`, minHeight: `80vh` }}>
14+
<Route
15+
render={({ location }) => (
16+
<div style={styles.fill}>
17+
<Route
18+
exact
19+
path="/"
20+
render={() => <Redirect to="/10/90/50" />}
21+
/>
2022

21-
<ul style={styles.nav}>
22-
<NavLink to="/10/90/50">Red</NavLink>
23-
<NavLink to="/120/100/40">Green</NavLink>
24-
<NavLink to="/200/100/40">Blue</NavLink>
25-
<NavLink to="/310/100/50">Pink</NavLink>
26-
</ul>
23+
<ul style={styles.nav}>
24+
<NavLink to="/10/90/50">Red</NavLink>
25+
<NavLink to="/120/100/40">Green</NavLink>
26+
<NavLink to="/200/100/40">Blue</NavLink>
27+
<NavLink to="/310/100/50">Pink</NavLink>
28+
</ul>
2729

28-
<div style={styles.content}>
29-
<ReactCSSTransitionGroup
30-
transitionName="fade"
31-
transitionEnterTimeout={300}
32-
transitionLeaveTimeout={300}
33-
>
34-
{/* no different than other usage of
30+
<div style={styles.content}>
31+
<ReactCSSTransitionGroup
32+
transitionName="fade"
33+
transitionEnterTimeout={300}
34+
transitionLeaveTimeout={300}
35+
>
36+
{/* no different than other usage of
3537
ReactCSSTransitionGroup, just make
3638
sure to pass `location` to `Route`
3739
so it can match the old location
3840
as it animates out
3941
*/}
40-
<Route
41-
location={location}
42-
key={location.key}
43-
path="/:h/:s/:l"
44-
component={HSL}
45-
/>
46-
</ReactCSSTransitionGroup>
42+
<Route
43+
location={location}
44+
key={location.key}
45+
path="/:h/:s/:l"
46+
component={HSL}
47+
/>
48+
</ReactCSSTransitionGroup>
49+
</div>
4750
</div>
48-
</div>
49-
)}
50-
/>
51-
</div>
51+
)}
52+
/>
53+
</div>
54+
</Layout>
5255
)
5356
}
5457
}

examples/gatsbygram/.babelrc

-4
This file was deleted.

examples/gatsbygram/gatsby-browser.js

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ exports.shouldUpdateScroll = args => {
99
return false
1010
}
1111
}
12+
13+
exports.onInitialClientRender = () => {
14+
window.___GATSBYGRAM_INITIAL_RENDER_COMPLETE = true
15+
}

examples/gatsbygram/gatsby-config.js

+6
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,11 @@ module.exports = {
6767
trackingId: `UA-91652198-1`,
6868
},
6969
},
70+
{
71+
resolve: `gatsby-plugin-typography`,
72+
options: {
73+
pathToConfigModule: `src/utils/typography`,
74+
},
75+
},
7076
],
7177
}

0 commit comments

Comments
 (0)