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

feat(gatsby): write match-paths.json #13012

Merged
merged 2 commits into from
Apr 3, 2019
Merged

Conversation

Moocar
Copy link
Contributor

@Moocar Moocar commented Apr 2, 2019

Description

Writes match-paths.json during pages writing. This file contains a map of matchPath -> path. It will be used by #13004 when finding pages in the production-app. See https://github.com/gatsbyjs/gatsby/pull/13004/files#diff-06ce5193de7c2c01dd947a5001c147c3R60 for how it's used.

Related Issues

@Moocar Moocar requested a review from a team as a code owner April 2, 2019 01:11
@Moocar Moocar force-pushed the write-match-paths branch from 57c124a to e71c9a5 Compare April 2, 2019 05:15
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about oldPage being set. Rest is looking good.

Do you have a small example how you'll be able to trigger oldPage.matchPath !== page.matchPath

return {}
case `CREATE_PAGE`: {
const page = action.payload
if (page.matchPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast returns are easier to read in my opinion

Suggested change
if (page.matchPath) {
if (!page.matchPath) {
return state;
}

case `CREATE_PAGE`: {
const page = action.payload
if (page.matchPath) {
const { oldPage } = action
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think oldPage is set on the action.

@pieh
Copy link
Contributor

pieh commented Apr 2, 2019

In pages-writer.js we do iterate over pages redux substate anyway, so it might be easier to generate derivative matchPaths from it? So we don't have to have 2 reducers reacting to CREATE_PAGE/DELETE_PAGE?

I.e:

- let { program, jsonDataPaths, pages, matchPaths } = store.getState()
+ let { program, jsonDataPaths, pages } = store.getState()
  pages = [...pages.values()]
+ const matchPaths = {}

  const pagesComponentDependencies = {}

  // Write out pages.json
  let pagesData = []
  pages.forEach(({ path, matchPath, componentChunkName, jsonName }) => {
    const pageComponentsChunkNames = {
      componentChunkName,
    }

    if (program._[0] === `develop`) {
      pagesComponentDependencies[path] = pageComponentsChunkNames
    }

    pagesData.push({
      ...pageComponentsChunkNames,
      jsonName,
      path,
      matchPath,
    })
+
+   if (matchPath) {
+     matchPaths[matchPath] = path
+   }
  })

@Moocar
Copy link
Contributor Author

Moocar commented Apr 2, 2019

Apologies, this was a sloppy PR. The match-paths reducer was necessary in incremental build land, which this work originated from. But I never went back and de-incrementalized it. @pieh I like your suggestion. It's much clearer. I'll implement that now

@Moocar
Copy link
Contributor Author

Moocar commented Apr 2, 2019

Fixed in 966f035

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@pieh pieh merged commit cec5e28 into gatsbyjs:master Apr 3, 2019
@Moocar Moocar deleted the write-match-paths branch April 3, 2019 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants