Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix styles to be sorted on static-entry.js #13482

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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