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

GraphQL query error with markdown frontmatter image and parent #39261

Closed
2 tasks done
sdobz opened this issue Apr 6, 2025 · 0 comments · Fixed by #39262
Closed
2 tasks done

GraphQL query error with markdown frontmatter image and parent #39261

sdobz opened this issue Apr 6, 2025 · 0 comments · Fixed by #39262
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@sdobz
Copy link
Contributor

sdobz commented Apr 6, 2025

Preliminary Checks

Description

While writing markdown I use thumbnail and parent in the frontmatter to render a thumbnail in lists and to describe my site taxonomy. This blog was created in 2019, and I recently tried to upgrade all dependencies from Gatsby 3 to 5.

This issue occurs in my custom "createPages" code, though it persists when running the site and testing in the iGraphQL explorer

Diagnosis

While reading node-model.js I console.log'd ids and noted it was a Set

ids.push(obj.parent)

  findRootNodeAncestor(obj, predicate = null) {
    let iterations = 0;
    let ids = this._rootNodeMap.get(obj);
    console.log(ids); // DEBUG
    if (!ids) {
      ids = [];
    }
    if (obj !== null && obj !== void 0 && obj.parent) {
      ids.push(obj.parent);
    }
Set(1) { '1afed4c9-65b6-512d-97ab-5c2f6a7aca3b' }

Invesigating _rootNodeMap indeed, it is created as a set

nodeIds = new Set([nodeId])

    // don't need to track node itself
    if (!isNode) {
      let nodeIds = rootNodeMap.get(data);
      if (!nodeIds) {
        nodeIds = new Set([nodeId]);
      } else {
        nodeIds.add(nodeId);
      }
      rootNodeMap.set(data, nodeIds);
    }

There appears to be a type disparity between ids as a Set (.add) and ids as an Array (.push)

This code was added in Oct 2022 and includes the type disparity
696a7ba

Fix

Update the findRootNodeAncestor function to consistently treat nodeIds as a Set

#39262

Reproduction Link

https://github.com/sdobz/gatsby-markdown-frontmatter-repro

Steps to Reproduce

  1. npm init gatsby
    a. Enable markdown plugin
  2. https://www.gatsbyjs.com/docs/how-to/images-and-media/working-with-images-in-markdown/
  3. Create a markdown page with "parent" in the frontmatter and "thumbnail" pointing to a file

Expected Result

I expect to see one page listed in the print

Actual Result

I see graphql errors

{
  errors: [
    TypeError: ids.push is not a function
        at LocalNodeModel.findRootNodeAncestor
(/home/vkhougaz/projects/gatsby-markdown-frontmatter-issue/node_modules/gatsby/src/schema/node-model.js:527:11)
        at ContextualNodeModel.findRootNodeAncestor
(/home/vkhougaz/projects/gatsby-markdown-frontmatter-issue/node_modules/gatsby/src/schema/node-model.js:684:27)
        at fileByPathResolver
(/home/vkhougaz/projects/gatsby-markdown-frontmatter-issue/node_modules/gatsby/src/schema/resolvers.ts:526:46)
        at processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async Promise.all (index 0)
        at async Promise.all (index 0)
        at async Promise.all (index 0)
        at async Promise.all (index 1)
        at async Promise.all (index 0) {
      path: [Array],
      locations: [Array],
      extensions: [Object: null prototype] {}
    }
  ],
  data: [Object: null prototype] {
    allMarkdownRemark: [Object: null prototype] { edges: [Array] }
  }
}

Environment

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (16) x64 AMD Ryzen 7 3800XT 8-Core Processor
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 22.14.0 - /nix/store/bmakyv5ip1wc9jk155glzdw4vnnrym04-nodejs-22.14.0/bin/node
    Yarn: 1.22.22 - /nix/store/sfh8adsjz44xyismwlzamq25k6lk9igl-yarn-1.22.22/bin/yarn
    npm: 10.9.2 - /nix/store/bmakyv5ip1wc9jk155glzdw4vnnrym04-nodejs-22.14.0/bin/npm
  npmPackages:
    gatsby: ^5.14.1 => 5.14.1 
    gatsby-cli: ^5.14.0 => 5.14.0 
    gatsby-plugin-sharp: ^5.14.0 => 5.14.0 
    gatsby-source-filesystem: ^5.14.0 => 5.14.0 
    gatsby-transformer-remark: ^6.14.0 => 6.14.0 
    gatsby-transformer-sharp: ^5.14.0 => 5.14.0

Config Flags

No response

@sdobz sdobz added the type: bug An issue or pull request relating to a bug in Gatsby label Apr 6, 2025
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 6, 2025
pieh added a commit that referenced this issue Apr 8, 2025
* fix(gatsby): change ids in findRootNodeAncestor from array to set (#39261)

* Update packages/gatsby/src/schema/node-model.js

Co-authored-by: Michal Piechowiak <[email protected]>

* chore: fix lint

---------

Co-authored-by: sdobz <[email protected]>
Co-authored-by: Michal Piechowiak <[email protected]>
pieh pushed a commit that referenced this issue Apr 8, 2025
* fix(gatsby): change ids in findRootNodeAncestor from array to set (#39261)

* Update packages/gatsby/src/schema/node-model.js

Co-authored-by: Michal Piechowiak <[email protected]>

* chore: fix lint

---------

Co-authored-by: sdobz <[email protected]>
Co-authored-by: Michal Piechowiak <[email protected]>
(cherry picked from commit 1825669)
pieh pushed a commit that referenced this issue Apr 8, 2025
…39270)

* fix(gatsby): change ids in findRootNodeAncestor from array to set (#39261)

* Update packages/gatsby/src/schema/node-model.js

Co-authored-by: Michal Piechowiak <[email protected]>

* chore: fix lint

---------

Co-authored-by: sdobz <[email protected]>
Co-authored-by: Michal Piechowiak <[email protected]>
(cherry picked from commit 1825669)

Co-authored-by: Vincent Khougaz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant