OK, I found the reason why the Next.js section model code snippet wasn’t working (see point 2 above). According Next.js’ docs:
getStaticProps
can only be exported from a page . You can’t export it from non-page files.
I was copy/pasting the snippet into a component file, since that’s what the snippet looks like. So getStaticProps
never fired and the HTML content for the section was never fetched, resulting in an empty-looking component. (The component was still mounted in the VDOM but it didn’t have any content.)
Using <BuilderComponent model="header" />
worked because it wasn’t setting the content to null
. But then the problem is that it renders in the browser rather than at build-time. I’m guessing it fetches the content client side if you don’t give it content to render server side.
I would recommend updating the Next.js docs accordingly since the snippet provided implies that you should be creating a separate component file, which doesn’t work.