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

fix: Align types of rootNodeMap during root node tracking #39262

Merged
merged 5 commits into from
Apr 8, 2025

Conversation

sdobz
Copy link
Contributor

@sdobz sdobz commented Apr 6, 2025

Description

Issue #39261 describes a mismatch between initial discovery of root nodes and discovery of a new node with a parent.

ids.push(obj.parent)

  findRootNodeAncestor(obj, predicate = null) {
    let iterations = 0;
    let ids = this._rootNodeMap.get(obj);
    if (!ids) {
      ids = []; // !!! ARRAY TYPE !!!
    }
    if (obj !== null && obj !== void 0 && obj.parent) {
      ids.push(obj.parent); // Error: push does not exist on array
    }
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]); // !!! SET TYPE !!!
      } 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

This is one possible fix. It is unknown why adding parent to markdown frontmatter triggers this issue, there may be further upstream issues

Related Issues

Fixes #39261

@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 pieh removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 7, 2025
@pieh pieh changed the title Align types of rootNodeMap during root node tracking fix: Align types of rootNodeMap during root node tracking Apr 7, 2025
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.

Thanks!

@pieh pieh merged commit 1825669 into gatsbyjs:master Apr 8, 2025
31 of 35 checks passed
@github-project-automation github-project-automation bot moved this to To cherry-pick in V5 Release hotfixes Apr 8, 2025
pieh pushed a commit that referenced this pull request 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 pieh moved this from To cherry-pick to Backport PR opened in V5 Release hotfixes Apr 8, 2025
pieh pushed a commit that referenced this pull request 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]>
@pieh pieh moved this from Backport PR opened to Backported in V5 Release hotfixes Apr 8, 2025
@pieh
Copy link
Contributor

pieh commented Apr 9, 2025

Change was released in [email protected]

@pieh pieh moved this from Backported to Published in V5 Release hotfixes Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Published
Development

Successfully merging this pull request may close these issues.

GraphQL query error with markdown frontmatter image and parent
2 participants