Skip to content

Commit

Permalink
Fix styles to be sorted on static-entry.js
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-jay committed Apr 19, 2019
1 parent 6150722 commit c66c4de
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/gatsby/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ const chunkMapping = JSON.parse(
fs.readFileSync(`${process.cwd()}/public/chunk-map.json`, `utf-8`)
)

// Compare styles by names
const compareStyleNames = ({ name: nameA }, { name: nameB }) => {
const [numberA, numberB] = [nameA, nameB].map(name =>
Number(name.replace(/^(\d+).*/, `$1`))
)

// do not swap if names don't start with number
return numberA - numberB || 0
}

// const testRequireError = require("./test-require-error")
// For some extremely mysterious reason, webpack adds the above module *after*
// this module so that when this code runs, testRequireError is undefined.
Expand Down Expand Up @@ -254,9 +264,9 @@ export default (pagePath, callback) => {
const scripts = scriptsAndStyles.filter(
script => script.name && script.name.endsWith(`.js`)
)
const styles = scriptsAndStyles.filter(
style => style.name && style.name.endsWith(`.css`)
)
const styles = scriptsAndStyles
.filter(style => style.name && style.name.endsWith(`.css`))
.sort(compareStyleNames)

apiRunner(`onRenderBody`, {
setHeadComponents,
Expand Down

0 comments on commit c66c4de

Please sign in to comment.