Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Next.js] Next 13 upgrade #1324

Merged
merged 6 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ const Navigation = (): JSX.Element => {
return (
<div className="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom">
<h5 className="my-0 me-md-auto fw-normal">
<Link href="/">
<a className="text-dark">
<img src={`${publicUrl}/sc_logo.svg`} alt="Sitecore" />
</a>
<Link className="text-dark" href="/">
<img src={`${publicUrl}/sc_logo.svg`} alt="Sitecore" />
</Link>
</h5>
<nav className="my-2 my-md-0 me-md-3">
Expand All @@ -27,14 +25,14 @@ const Navigation = (): JSX.Element => {
>
{t('Documentation')}
</a>
<Link href="/styleguide">
<a className="p-2 text-dark">{t('Styleguide')}</a>
<Link className="p-2 text-dark" href="/styleguide">
{t('Styleguide')}
</Link>
<Link href="/graphql">
<a className="p-2 text-dark">{t('GraphQL')}</a>
<Link className="p-2 text-dark" href="/graphql">
{t('GraphQL')}
</Link>
<Link href="/tracking">
<a className="p-2 text-dark">{t('Tracking')}</a>
<Link className="p-2 text-dark" href="/tracking">
{t('Tracking')}
</Link>
</nav>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ const Navigation = (): JSX.Element => {
return (
<div className="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom">
<h5 className="my-0 me-md-auto fw-normal">
<Link href="/">
<a className="text-dark">
<img src={`${publicUrl}/sc_logo.svg`} alt="Sitecore" />
</a>
<Link href="/" className="text-dark">
<img src={`${publicUrl}/sc_logo.svg`} alt="Sitecore" />
</Link>
</h5>
<nav className="my-2 my-md-0 me-md-3">
Expand All @@ -27,11 +25,11 @@ const Navigation = (): JSX.Element => {
>
{t('Documentation')}
</a>
<Link href="/styleguide">
<a className="p-2 text-dark">{t('Styleguide')}</a>
<Link className="p-2 text-dark" href="/styleguide">
{t('Styleguide')}
</Link>
<Link href="/graphql">
<a className="p-2 text-dark">{t('GraphQL')}</a>
<Link className="p-2 text-dark" href="/graphql">
{t('GraphQL')}
</Link>
</nav>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ const StyleguideFieldUsageImage = (props: StyleguideFieldUsageImageProps): JSX.E
IMPORTANT: The generated sizes should match your Sitecore server-side allowlist. See /sitecore/config/*.config (search for 'allowedMediaParams')
illiakovalenko marked this conversation as resolved.
Show resolved Hide resolved
*/}
<p>Srcset responsive image</p>
<NextImage
field={props.fields.sample2}
height="105"
width="200"
sizes="50vw"
layout="responsive"
priority
/>
<div style={{ position: 'relative', height: 160, width: 300 }}>
<NextImage
field={props.fields.sample2}
sizes="(min-width: 960px) 300px, 100px"
fill
priority
/>
</div>
</StyleguideSpecimen>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const GraphQLIntegratedDemo = (props: GraphQlIntegratedDemoProps): JSX.Element =
{contextItem.children.results.map((child: Item) => (
<li key={child.id}>
<NextLink href={child.url.path}>
<a>{child.pageTitle.value}</a>
{child.pageTitle.value}
</NextLink>
&nbsp; (editable title too! <Text field={child.pageTitle.jsonValue} />)
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const StyleguideCustomRouteType = (): JSX.Element => {
<RichText field={fields.content} />

<Link href="/styleguide">
<a>Return to the Styleguide</a>
Return to the Styleguide
</Link>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const StyleguideMultilingual = (props: StyleguideMultilingualProps): JSX.Element
<p>
{/* In case if href already includes locale: https://nextjs.org/docs/advanced-features/i18n-routing#transition-between-locales */}
<Link href="/en/styleguide" locale={false}>
<a>Show in English</a>
Show in English
</Link>
<br />
<Link href="/styleguide" locale="<%- language %>">
<a>Show in <%- language %></a>
Show in <%- language %>
</Link>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const StyleguideRouteFields = (props: StyleguideRouteFieldsProps): JSX.Element =
</p>
<p>
<Link href="/styleguide/custom-route-type">
<a>Sample of using a custom route type</a>
Sample of using a custom route type
</Link>
</p>
</StyleguideSpecimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ const disconnectedPlugin = (nextConfig = {}) => {
},
];
},

webpack: (config, options) => {
// Prevent webpack-5 from throwing error for sitecore-import.json when app first starts
config.resolve.fallback = {
'sitecore/manifest/sitecore-import.json': false,
...config.resolve.fallback
};

// Overload the Webpack config if it was already overloaded
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}

return config;
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ const styleguidePlugin = (nextConfig = {}) => {
...nextConfig.i18n,
locales: ['en', '<%- language %>'],
},
webpack: (config, options) => {
illiakovalenko marked this conversation as resolved.
Show resolved Hide resolved
// Prevent webpack-5 from throwing error for sitecore-import.json when app first starts
config.resolve.fallback = {
'sitecore/manifest/sitecore-import.json': false,
...config.resolve.fallback,
};

// Overload the Webpack config if it was already overloaded
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}

return config;
},
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@sitecore-jss/sitecore-jss-nextjs": "^21.1.0-canary",
"graphql": "~15.8.0",
"graphql-tag": "^2.12.6",
"next": "^12.3.4",
"next": "^13.1.6",
"next-localization": "^0.12.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down Expand Up @@ -63,7 +63,6 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-yaml": "^0.5.0",
"graphql-let": "^0.18.6",
"next-transpile-modules": "^10.0.0",
illiakovalenko marked this conversation as resolved.
Show resolved Hide resolved
"npm-run-all": "~4.1.5",
"prettier": "^2.8.3",
"ts-node": "^10.9.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
const withTM = require('next-transpile-modules')(['@sitecore-jss/sitecore-jss-nextjs'], {
resolveSymlinks: false,
});
const path = require('path');

const CWD = process.cwd();

/**
* @param {import('next').NextConfig} nextConfig
*/
const monorepoPlugin = (nextConfig = {}) => {
return withTM(Object.assign({}, nextConfig, {
return Object.assign({}, nextConfig, {
webpack: (config, options) => {
if (options.isServer) {
config.externals = ['react', 'vertx', ...config.externals];
}

config.resolve.alias['react'] = path.resolve(CWD, '.', 'node_modules', 'react');

// Overload the Webpack config if it was already overloaded
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}

return config;
}
}));
});
};

module.exports = monorepoPlugin;
4 changes: 2 additions & 2 deletions packages/sitecore-jss-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"eslint-plugin-react": "^7.32.1",
"jsdom": "^21.1.0",
"mocha": "^10.2.0",
"next": "^12.3.4",
"next": "^13.1.6",
"nock": "^13.3.0",
"nyc": "^15.1.0",
"react": "^18.2.0",
Expand All @@ -65,7 +65,7 @@
"typescript": "~4.9.4"
},
"peerDependencies": {
"next": "^12.3.4",
"next": "^13.1.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
17 changes: 7 additions & 10 deletions packages/sitecore-jss-nextjs/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
href={{ pathname: href, query: querystring, hash: anchor }}
key="link"
locale={false}
title={value.title}
target={value.target}
className={value.class}
{...htmlLinkProps}
ref={ref}
>
<a
title={value.title}
target={value.target}
className={value.class}
{...htmlLinkProps}
ref={ref}
>
{text}
{children}
</a>
{text}
{children}
</NextLink>
);
}
Expand Down
Loading