Skip to content

Commit

Permalink
[Next.js][Multi-site] Better page props site resolution for editing/p…
Browse files Browse the repository at this point in the history
…review (#1304)
  • Loading branch information
ambrauer authored Jan 26, 2023
1 parent 76363e6 commit e34b9f0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class SitePlugin implements Plugin {
order = 0;

async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
if (context.preview) return props;

const path =
context.params === undefined
? '/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class PersonalizePlugin implements Plugin {
order = 3;

async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
if (context.preview) return props;

const path =
context.params === undefined
? '/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ErrorPagesPlugin implements Plugin {
order = 3;

async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
if (context.preview) return props;

const errorPagesService = new GraphQLErrorPagesService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SiteInfo } from '@sitecore-jss/sitecore-jss-nextjs';
import { editingDataService } from '@sitecore-jss/sitecore-jss-nextjs/editing';
import { SitecorePageProps } from 'lib/page-props';
import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
Expand All @@ -16,6 +17,7 @@ class PreviewModePlugin implements Plugin {
`Unable to get editing data for preview ${JSON.stringify(context.previewData)}`
);
}
props.site = data.layoutData.sitecore.context.site as SiteInfo;
props.locale = data.language;
props.layoutData = data.layoutData;
props.dictionary = data.dictionary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { SitecorePageProps } from 'lib/page-props';
import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
import { Plugin } from '..';
import { siteResolver } from 'lib/site-resolver';
import config from 'temp/config';

class SitePlugin implements Plugin {
order = 0;

async exec(props: SitecorePageProps) {
async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
if (context.preview) return props;

// Resolve site by name
props.site = siteResolver.getByName(config.jssAppName);

Expand Down

0 comments on commit e34b9f0

Please sign in to comment.