Skip to content

Commit

Permalink
fix: create multiple layouts from same components with different cont…
Browse files Browse the repository at this point in the history
…ext (#3039)

The bug appears in pages-writer.js:89 , we need to use the layout id as identifier instead of his path

fixes #3025
  • Loading branch information
abumalick authored and KyleAMathews committed Nov 27, 2017
1 parent 2b771ed commit c3d7413
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const queue = {
const pageResources = {
component: syncRequires.components[page.componentChunkName],
json: syncRequires.json[page.jsonName],
layout: syncRequires.layouts[page.layoutComponentChunkName],
layout: syncRequires.layouts[page.layout],
page,
}
cb(pageResources)
Expand Down Expand Up @@ -308,7 +308,7 @@ const queue = {
})

page.layoutComponentChunkName &&
getResourceModule(page.layoutComponentChunkName, (err, l) => {
getResourceModule(page.layout, (err, l) => {
if (err) {
console.log(`Loading the Layout for ${page.path} failed`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getPage = path => pages.find(page => page.path === path)
const defaultLayout = props => <div>{props.children()}</div>

const getLayout = page => {
const layout = syncRequires.layouts[page.layoutComponentChunkName]
const layout = syncRequires.layouts[page.layout]
return layout ? layout : defaultLayout
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const preferDefault = m => m && m.default || m
syncRequires += `exports.layouts = {\n${pageLayouts
.map(
l =>
` "${l.componentChunkName}": preferDefault(require("${
` "${l.id}": preferDefault(require("${
l.componentWrapperPath
}"))`
)
Expand Down Expand Up @@ -124,7 +124,7 @@ const preferDefault = m => m && m.default || m
asyncRequires += `exports.layouts = {\n${pageLayouts
.map(
l =>
` "${l.componentChunkName}": require("gatsby-module-loader?name=${
` "${l.id}": require("gatsby-module-loader?name=${
l.componentChunkName
}!${l.componentWrapperPath}")`
)
Expand Down

0 comments on commit c3d7413

Please sign in to comment.