question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Match path's aren't correctly sorted

See original GitHub issue

Description

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

  1. Starting from the default Gatsby starter, create a src/pages/app.js and src/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: "/*",
    })
  }
}
  1. Run gatsby build

  2. 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:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wardpeetcommented, Sep 5, 2019

Fixed in gatsby@2.15.8

0reactions
kirbycoolcommented, Sep 5, 2019

Awesome thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex to match paths that don't match a specific pattern ...
The first answer was not correct, that's why I post again. Solution. The following regex will match ...
Read more >
Tree-like data, sorting nodes by connecting relationships
The nodes are not ordered properly (on no level of depth). It looks as if the path-variable wich is "handed over" in the...
Read more >
Path Matching :: Gloo Edge Docs
The route rules in a Virtual Service can use path matching rules to match requests to routes based on the context path. There...
Read more >
How to Use sorted() and sort() in Python - Real Python
In this guide, you'll learn how to sort various types of data in different data structures, customize the order, and work with two...
Read more >
glob — Unix style pathname pattern expansion ... - Python Docs
For example, '[?]' matches the character '?' . See also. The pathlib module offers high-level path objects ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found