gatsby: gatsby-source-contentful: Maximum call stack size exceeded

Not sure if this is a bug or not. And unfortunately I don’t really have much time this week to investigate. But I thought I might as well put this up here.

I’m using the gatsby-source-contentful plugin. In my contentful content model I’m having two content types, both with the new Richtext editor. Problems occurs when I have entry links to each other.

To be more clear. Say I have two pages, home and about. If I link from home -> about and from about -> home inside the Richtext editor I get this error.

Like I said before. Not sure if this is a bug.

Here’s a callstack https://pastebin.com/fD676e6j

Environment (if relevant)

  System:
    OS: macOS 10.14.3
    CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
    Shell: 3.0.0 - /usr/local/bin/fish
  Binaries:
    Node: 10.15.0 - /var/folders/vh/cx86q1vs2xz5rxlf8b8cny2r0000gn/T/yarn--1548706327929-0.8647198662198463/node
    Yarn: 1.13.0 - /var/folders/vh/cx86q1vs2xz5rxlf8b8cny2r0000gn/T/yarn--1548706327929-0.8647198662198463/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  Browsers:
    Chrome: 71.0.3578.98
    Safari: 12.0.3
  npmPackages:
    gatsby: 2.0.98 => 2.0.98 
    gatsby-plugin-layout: 1.0.11 => 1.0.11 
    gatsby-plugin-offline: 2.0.21 => 2.0.21 
    gatsby-plugin-react-helmet: 3.0.5 => 3.0.5 
    gatsby-plugin-styled-components: 3.0.4 => 3.0.4 
    gatsby-source-contentful: 2.0.26 => 2.0.26 
    gatsby-transformer-remark: 2.2.0 => 2.2.0 

gatsby-config.js:

plugins: [
        {
            resolve: 'gatsby-plugin-styled-components',
            options: {
                displayName: false
            }
        },
        'gatsby-plugin-react-helmet',
        {
            resolve: 'gatsby-plugin-layout',
            options: {
                component: require.resolve('./src/components/Layout')
            }
        },
        {
            resolve: 'gatsby-source-contentful',
            options: {
                spaceId: '<spaceID>',
                accessToken: process.env.CONTENTFUL_ACCESS_TOKEN
            }
        },
        {
            resolve: '@contentful/gatsby-transformer-contentful-richtext',
            options: contentfulRenderOptions
        },
        'gatsby-plugin-offline'
    ]

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 66 (34 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm that this fix (released with v 2.7.8) solves my problem 👍

Thanks a lot!

edit: I meant version number 2.1.78.

Spooky quiet indeed. But not ready to be closed

Ok. Can repro. On it.

Hi - is there a solution to this issue? It seems to severely limit Contentful’s functionality with Gatsby. Any update would be much appreciated!

@jayhostan I think my PR (#14612) provides a decent temp solution.

However, a longer-term solution (which I discussed offline with @Khaledgarbaya) would be to properly match Contentful’s real GraphQL API. In their docs, they describe a links property that lists all linked entries. Then you could simply control which fields of which content types you want to pull. I believe this would resolve the infinite-recursion issue, but I haven’t explored it enough yet to know for sure.

Deleting lock files and node_modules plus updating to gatsby v2.19.16 and gatsby-source-contentful v2.1.85 fixes the issue for me.

@pvdz WOW that was fast, thank you! When I get a chance, I’ll try it with my real-life repo and see if it fixes the issue.

Confirmed. Looking into a fix now.

🚨 I’ve created a minimal reproduction of this issue! 🚨

This appears to still be a problem on the latest version of Gatsby, even after #20039 was merged.

Here is the repo: https://github.com/jessepinho/gatsby-contentful-infinite-loop-repro

Here’s the Contentful Discovery app with all the data (note that a bug in the app prevents it from showing article records): https://discovery.contentful.com/entries/by-content-type?delivery_access_token=04QAYaRsr548atM4KwInDCWk8v84agx0uS7r8LrQutk&preview=false&preview_access_token=&space_id=j66qheg22uli

And a demonstration GIF: screencap

@pvdz could you please reopen this issue? (I don’t have rights to.)

There is a repro in the form of an e2e test in this PR: https://github.com/gatsbyjs/gatsby/pull/15358

It’s not isolated from contentful, but it should demonstrate the issue still.

It would be great if you could create a minimal repro with tihs, or at least a repo that I can just clone and build to repro the case if nothing else.

I’ll try to revisit this on Monday. Thanks for the input!

@richhiggins it will happen if your linked entry links back to the current entry, thus creating an infinite loop

Thank you very much for taking a look at this. Unfortunately Gatsby 2.18.5 continues to give me the same error on Contentful rich texts (“maximum call stack size exceeded”) whenever a richtext field has an embedded reference to a content type that includes a richtext field. Will try to submit a minimal repro.

We’ve landed a fix for the stack overflow caused by circular dependencies. That fix should resolve this issue. Please check it with the next version bump (or from master). If that does not fix the problem, please reopen with a new (minimal) repro.

Thanks everyone for helping out and for your patience.

Considering that this has been open for 6 months now, I’d rather stick with the workaround, we’ve been running that in production since then and based on my experience it covers most common scenarios. I’m ok with a bottle of Pinot Noir as well as this is not a permanent solution.

I think we are using a newer version with gatsby where the workaround does not cover some of the scenarios. Our build keeps on crashing 😃 But A for effort 😃

Just wanted to chime in that we’re also experiencing the same issue, and I have tried using @jessepinho’s PR but for some reason that didn’t have any effect. Not sure how I can help though.

Hey @simoneb, Any reason you didn’t make a pull request since your fork fixed the issue?

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label “not stale” to keep this issue open!

Thanks for being a part of the Gatsby community! 💪💜

@karenhou It’s not reference fields that’s the problem. It makes sense to have references one way. What I’m talking about is the Rich text field which has Entry hyperlink support. If you want to create a <a href> to another entry you’d do it that way. Problems occurs when two content entries link to each other. Which would be a very valid case.

Say you have a 3 part article that would link to each other in the beginning. That would never work right now if you’re not fine hardcoding the links.