In multisite setup, the error pages in XMC are not rendered for each site. #1622
Replies: 3 comments 6 replies
-
@isyedakhtar Hey, I think it's possible to create an issue ticket there: https://github.com/sitecorelabs/xmcloud-foundation-head-dev/issues export const getStaticProps: GetStaticProps = async (context) => {
const path =
context.params === undefined
? '/'
: Array.isArray(context.params.path)
? context.params.path.join('/')
: context.params.path ?? '/';
// Get site name (from path)
const siteData = getSiteRewriteData(path, config.jssAppName);
// Resolve site by name
const site = siteResolver.getByName(siteData.siteName);
const errorPagesService = new GraphQLErrorPagesService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
siteName: site.name,
language: context.locale || config.defaultLanguage,
});
let resultErrorPages: ErrorPages | null = null;
if (!process.env.DISABLE_SSG_FETCH) {
try {
resultErrorPages = await errorPagesService.fetchErrorPages();
} catch (error) {
console.log('Error occurred while fetching error pages');
console.log(error);
}
}
return {
props: {
headLinks: [],
layoutData: resultErrorPages?.notFoundPage?.rendered || null,
},
};
}; |
Beta Was this translation helpful? Give feedback.
-
@matkovskyi Can you, please, take a look a this issue and consider implementing it if it's possible? Seems like it's a limitation for multisite solutions using ErrorPages, isn't it? |
Beta Was this translation helpful? Give feedback.
-
Next.js (Pages Router) only allows static 404/500 error pages, and they are compiled during build time. If you have i18n configured, those locales will be taken into account (and static versions of each language are built). This works because i18n is a built-in feature of Next.js. However, multisite is not and relies on dynamic site resolution and custom rewrite path segments to be used during build time. This is a known limitation for JSS multisite. The starter code uses your configured default site for the 404/500 page content. Note this is not a problem on Next.js App Router (which we will provide support for in the future). Even the official Next.js multi-tenant example did not have multi-tenant error pages until App Router 😉. |
Beta Was this translation helpful? Give feedback.
-
Description
In (headless) SXA, we can define the error pages either on the Sitegrouping or Settings item itself. XM Foundation repo code is pulling the layout from edge for those error pages and renders them. For example in getStaticProps of 404.tsx
export const getStaticProps: GetStaticProps = async (context) => { const site = siteResolver.getByName(config.jssAppName); const errorPagesService = new GraphQLErrorPagesService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, siteName: site.name, language: context.locale || config.defaultLanguage, }); }
When getting the site information, we are using config.jssAppName. It works well for a single website hosted. If we are using the multisite plugin and have a single project, every site would render the error pages defined for the website that has a presence in config.jssAppName i.e. package.json app name.
Can someone suggest, what's the best way of tackling this. I thought to resolve it by removing the getStaticProps and use the Sitecore context within the main function. That could be a quick resolution but no SSG for a static page.
Additional information
I couldn't find a way to create a discussion under the repo https://github.com/sitecorelabs/xmcloud-foundation-head so thought to start a thread here.
Beta Was this translation helpful? Give feedback.
All reactions