Insights

How to Fix Sitecore XM Cloud "GraphQL: No Context Found" in JSS 21.6

Mimic our hotfix for a Sitecore Experience Edge error in 21.6

What Causes the "No Context Found" Error in JSS 21.6?

I recently upgraded our XM Cloud solution from version 21.5.3 to 21.6. After updating the dependencies, copying across all the new files, and comparing all file changes, I encountered an error when attempting to access the next.js front end of our solution. Sitecore Experience Editor was working fine, but every time I accessed the front end, the following error would halt my progress:

Error message from a Sitecore GraphQL server indicating a 404 not found error. 

I opened my rendering-1 logs inside docker, and I was able to get a nice formatted version of the error. The key focus points of this error is the “GraphQL: 404” and “Detail: No sitecore context”.

⨯ ClientError: GraphQL Error(Code: 404) : {
      "response": {
        "type": "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4",
        "title": "NotFound",
        "detail": "No sitecore context",
        "instance": "https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1",
        "status": 404,
        "headers": {}
      },
      "request": {
        "query": "query {\n      layout(site:\"getfishtank\", routePath:\"/\", language:\"en\"){\n        item {\n          rendered\n        }\n      }\n    }"
      }
    }
    at C:\app\node_modules\@sitecore-jss\sitecore-jss\node_modules\graphql-request\dist\index.js:359:31
    at step (C:\app\node_modules\@sitecore-jss\sitecore-jss\node_modules\graphql-request\dist\index.js:63:23)
    at Object.next (C:\app\node_modules\@sitecore-jss\sitecore-jss\node_modules\graphql-request\dist\index.js:44:53)
    at fulfilled (C:\app\node_modules\@sitecore-jss\sitecore-jss\node_modules\graphql-request\dist\index.js:35:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  response: {
    type: 'https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4',
    title: 'NotFound',
    detail: 'No sitecore context',
    instance: 'https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1',
    status: 404,
    headers: Headers { [Symbol(map)]: [Object: null prototype] }
  },
  request: {
    query: 'query {\n' +
      '      layout(site:"getfishtank", routePath:"/", language:"en"){\n' +
      '        item {\n' +
      '          rendered\n' +
      '        }\n' +
      '      }\n' +
      '    }',
    variables: undefined
  },
  page: '/_site_getfishtank'
}

How We Fixed the "GraphQL: No Context Found Error"

We tried multiple things to fix the error; however, we noticed that the Sitecore Experience Edge URL was incorrect. Inside the error above, it's listed as edge-platform.sitecorecloud.io, when the actual link was supposed to be edge.sitecorecloud.io.

After some mild digging, we noticed that there was a new file added in 21.6 called edge-platform.ts, located under scripts/config/plugins. This was the only file that referenced “edge-platform”. After updating the fallback URL inside this file, everything started to work.

Screenshot of code configuring Sitecore edge URL with environment variables. 
const sitecoreEdgeUrl =
      process.env[`${constantCase('sitecoreEdgeUrl')}`]?.replace(/\/$/, '') ||
      'https://edge.sitecorecloud.io/';


Meet Tyler Holmes

Full Stack Developer

🇬🇧🧑‍💻🏸

Tyler is an experienced Full Stack Developer who has worked on a plethora of unique projects. He possesses a deep understanding of Technical SEO, C#, and React/Next.js.

Connect with Tyler