Match path's aren't correctly sorted
See original GitHub issueDescription
Hi team! I’ve been encountering some inconsistencies with match path sorting. With two pages with match paths of /*
and /txt/*
, the /*
page gets sorted before the /txt/*
page. But if I include a /app/*
page, that gets correctly sorted before /*
.
This was addressed by @pieh in https://github.com/gatsbyjs/gatsby/pull/9719, but the fix seems incomplete.
Steps to reproduce
- Starting from the default Gatsby starter, create a
src/pages/app.js
andsrc/pages/txt.js
, and create have a gatsby-node.js like this:
exports.onCreatePage = ({ page, actions }) => {
const { createPage } = actions
if (page.path.match(/^\/app/)) {
createPage({
...page,
matchPath: "/app/*",
})
}
if (page.path.match(/^\/txt/)) {
createPage({
...page,
matchPath: "/txt/*",
})
}
if (page.path === "/") {
createPage({
...page,
matchPath: "/*",
})
}
}
-
Run
gatsby build
-
Check
.cache/match-paths.json
. It should look like this:
[
{
"path": "/app/",
"matchPath": "/app/*"
},
{
"path": "/",
"matchPath": "/*"
},
{
"path": "/txt/",
"matchPath": "/txt/*"
}
]
Note: Changing the /txt/
page’s matchPath to /app/*
doesn’t change the ordering. It looks like matchPath isn’t taken into account or is superseded by some other sorting.
[
{
"path": "/app/",
"matchPath": "/app/*"
},
{
"path": "/",
"matchPath": "/*"
},
{
"path": "/txt/",
"matchPath": "/app/*"
}
]
Expected result
/txt/*
should be sorted before /*
because it is more specific (more path segments)
Actual result
/txt/*
is sorted after /*
Environment
System: OS: macOS 10.14.5 CPU: (8) x64 Intel® Core™ i7-7820HQ CPU @ 2.90GHz Shell: 3.0.2 - /usr/local/bin/fish Binaries: Node: 12.3.1 - ~/.asdf/shims/node Yarn: 1.16.0 - ~/.asdf/shims/yarn npm: 6.9.0 - ~/.asdf/shims/npm Languages: Python: 2.7.15 - /Users/thanx/.asdf/shims/python Browsers: Chrome: 75.0.3770.142 Safari: 12.1.1 npmPackages: gatsby: ^2.13.39 => 2.13.39 gatsby-image: ^2.2.6 => 2.2.6 gatsby-plugin-manifest: ^2.2.4 => 2.2.4 gatsby-plugin-offline: ^2.2.4 => 2.2.4 gatsby-plugin-react-helmet: ^3.1.2 => 3.1.2 gatsby-plugin-sharp: ^2.2.9 => 2.2.9 gatsby-source-filesystem: ^2.1.6 => 2.1.6 gatsby-transformer-sharp: ^2.2.4 => 2.2.4
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Fixed in
gatsby@2.15.8
Awesome thank you!