strapi / starters-and-templates

Monorepo for all official Strapi v4 templates
MIT License
327 stars 117 forks source link

Strapi Starter Next Corporate Site - Error when creating new section #45

Open tiagomota79 opened 2 years ago

tiagomota79 commented 2 years ago

Using this starter.

I've followed the instructions to add a new section. It doesn't work - the new component will "render", but it receives no data other than the component name (__typename: "ComponentSectionsDuoContent").

My first instinct was that the query should be updated. So I updated the query in utils/api.js to include my new section. It now won't render anything, giving this error: image

[develop:frontend] TypeError: Cannot destructure property 'metadata' of 'global.attributes' as it is undefined.
[develop:frontend]     at MyApp (webpack-internal:///./pages/_app.js:57:5)
[develop:frontend]     at processChild (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3353:14)
[develop:frontend]     at resolve (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3270:5)
[develop:frontend]     at ReactDOMServerRenderer.render (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3753:22)
[develop:frontend]     at ReactDOMServerRenderer.read (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3690:29)
[develop:frontend]     at renderToString (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:4298:27)
[develop:frontend]     at Object.renderPage (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/next/dist/next-server/server/render.js:53:854)
[develop:frontend]     at Function.getInitialProps (webpack-internal:///./node_modules/next/dist/pages/_document.js:211:19)
[develop:frontend]     at loadGetInitialProps (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/next/dist/next-server/lib/utils.js:5:101)
[develop:frontend]     at renderToHTML (/Users/tiagomota/Documents/Projects/Polar/polaramp-website/frontend/node_modules/next/dist/next-server/server/render.js:53:1145)

Steps to reproduce:

SimplySayHi commented 2 years ago

Hi, I had the same issue. I found out that the solution is to add some lines to the graphql query in this file/frontend/utils/api.js. The query is inside the function getPageData

For example, I created the component Hello with a custom property mydescription, so I updated the query by adding:

... on ComponentSectionsHello {
    id
    mydescription
}

In general, the instructions are mostly wrong. The correct steps are: