gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.22k stars 10.32k forks source link

Gatsby V3 does not create page in onCreatePage function after deletePage #31055

Closed Baivaras closed 3 years ago

Baivaras commented 3 years ago

Description

Recently I migrated my project from gatsby V2 to V3 and after migration, some of the code does not work as it supposed to.

A scenario which I was using and which I need to achieve right now:

  1. I have different subfolders under the /pages folder, every subfolder has index.js files and is named uppercase
  2. In gatsby-node.js file in onCreatePage function I delete page with deletePage function and create a new one with a different slug with createPage function.

my gatsby-node.js code:

  export const onCreatePage = ({ page, actions }) => {
      const { deletePage, createPage } = actions;

      const page_path = toLower(page.path);

      deletePage(page);

      if (page.componentPath === `${__dirname}/src/pages/HomePage/index.js`) {
        // create a new page but with '/' as path
        createPage({ ...page, path: '/' });
      } else if (page_path.match(/^\/account/)) {
        page.matchPath = '/account/*';

        // Create the new page.
        createPage({ ...page, path: page_path });
      } else if (
        page_path.match(/^\/kitchensink/) &&
        process.env.NODE_ENV === `production`
      ) {
        //pass
      } else {
        // create a new page but make slug all lowercase as page subfolders are named uppercase
        createPage({ ...page, path: page_path });
      }
    };

After migration, this method deletes the page but does not create a new one, seems that createPage function does not work anymore or it has some issues. As a result, I do not get any pages as it was deleted, it does not appear in the public folder structure either.

Maybe I do not spot my mistake, tried many different things to solve the issue but did not work.

Is there any way to force gatsby URLs to be JUST lowercase?

Thanks for any help

Steps to reproduce

-

Expected result

The expected result is to have each page created with a lower case slug when pages folder sub-directories are named uppercase

Actual result

Pages are getting deleted with deletePage but not created with createPage function as it used to be in gatsby V2

Environment

System: OS: macOS 11.2.3 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.1 - ~/.nvm/versions/node/v14.15.1/bin/node npm: 7.9.0 - ~/.nvm/versions/node/v14.15.1/bin/npm Languages: Python: 2.7.16 - /Users/baivaras/.pyenv/shims/python Browsers: Chrome: 90.0.4430.85 Firefox: 86.0 Safari: 14.0.3 npmPackages: gatsby: ^3.3.1 => 3.3.1 gatsby-codemods: ^2.3.0 => 2.3.0 gatsby-image: ^3.3.0 => 3.3.0 gatsby-plugin-anchor-links: ^1.2.1 => 1.2.1 gatsby-plugin-eslint: ^3.0.0 => 3.0.0 gatsby-plugin-facebook-pixel: ^1.0.5 => 1.0.5 gatsby-plugin-force-trailing-slashes: ^1.0.5 => 1.0.5 gatsby-plugin-google-analytics: ^3.3.0 => 3.3.0 gatsby-plugin-google-tagmanager: ^3.3.0 => 3.3.0 gatsby-plugin-hotjar: ^1.1.1 => 1.1.1 gatsby-plugin-image: ^1.3.1 => 1.3.1 gatsby-plugin-mailchimp: ^5.2.2 => 5.2.2 gatsby-plugin-manifest: ^3.3.0 => 3.3.0 gatsby-plugin-offline: ^4.3.0 => 4.3.0 gatsby-plugin-page-creator: ^3.3.0 => 3.3.0 gatsby-plugin-react-helmet: ^4.3.0 => 4.3.0 gatsby-plugin-react-svg: ^3.0.1 => 3.0.1 gatsby-plugin-remove-console: 0.0.2 => 0.0.2 gatsby-plugin-remove-trailing-slashes: ^3.3.0 => 3.3.0 gatsby-plugin-robots-txt: ^1.5.6 => 1.5.6 gatsby-plugin-s3: ^0.3.8 => 0.3.8 gatsby-plugin-sass: ^4.3.0 => 4.3.0 gatsby-plugin-sharp: ^3.3.1 => 3.3.1 gatsby-plugin-sitemap: ^3.3.0 => 3.3.0 gatsby-plugin-styled-components: ^4.3.0 => 4.3.0 gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.22 => 1.1.22 gatsby-plugin-zopfli: ^2.0.0 => 2.0.0 gatsby-source-airtable: ^2.1.1 => 2.1.1 gatsby-source-filesystem: ^3.3.0 => 3.3.0 gatsby-source-wordpress: ^5.3.1 => 5.3.1 gatsby-transformer-remark: ^4.0.0 => 4.0.0 gatsby-transformer-sharp: ^3.3.0 => 3.3.0 npmGlobalPackages: gatsby-cli: 3.3.0

vladar commented 3 years ago

Hi @Baivaras !

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

pieh commented 3 years ago

Miminal repro https://github.com/pieh/i31055

Current working theory: https://github.com/gatsbyjs/gatsby/blob/a35d615f9c8d596230ecd1f121f214b9879eb7d3/packages/gatsby/src/commands/build-utils.ts#L84-L167

Doesn't take into account that /TEST/ and /test/ would produce same (in terms of case insensitive filesystems) files and first create one vartiant and then deletes it.