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

[Nextjs] New NextImage component #978

Merged
merged 61 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4c10236
Implement Nextjs Image nextjs package and styleguide
Dec 21, 2021
97f395d
WIP: Implement nextjs image in nextjs package and styleguide
Dec 22, 2021
95b4a0a
Refactored image loader
Dec 22, 2021
7c11318
Refactor way in which EE markup is applied
Dec 23, 2021
3649dcc
WIP: Start refactoring test for nextjs image
Dec 23, 2021
a214475
Merge branch 'dev' of github.com:Sitecore/jss into feature/449842-nex…
addy-pathania Jan 10, 2022
cfed137
added tests and completed todos
addy-pathania Jan 17, 2022
d6844cf
resolved merge conflicts
addy-pathania Jan 17, 2022
04b6359
removed unwanted code and added line to end of file
addy-pathania Jan 18, 2022
8d21c43
addressed review comments
addy-pathania Jan 20, 2022
083e89b
fixed unit tests
addy-pathania Jan 20, 2022
740db9b
removed dublicate code
addy-pathania Jan 20, 2022
87ed6f2
removed extra comments
addy-pathania Jan 21, 2022
5fe6b2b
merged with dev and resloved merge conflicts
addy-pathania Jan 21, 2022
898ff0b
updated yarn.lock
addy-pathania Jan 21, 2022
eef8112
updated yarn.lock, removed dubplicate interface
addy-pathania Jan 23, 2022
6d0cf28
removed changes in yarn.lock
addy-pathania Jan 24, 2022
5598f85
updated yarn.lock
addy-pathania Jan 24, 2022
0ac9715
updated yarn.lock
addy-pathania Jan 24, 2022
1251704
fixed linting error
addy-pathania Jan 24, 2022
9c5522b
updated deviceSizes comment in next.config
addy-pathania Jan 24, 2022
faa66b0
improved comments, added utility to get hostname
addy-pathania Jan 25, 2022
40044e0
removed path and loader from config
addy-pathania Jan 25, 2022
7ba16e8
added relative path to loader function
addy-pathania Jan 25, 2022
fee5dd5
added comment for path variable
addy-pathania Jan 25, 2022
565cf8e
updated error message, removed extra interface
addy-pathania Jan 26, 2022
78c58bf
fixed undefined path variable issue
addy-pathania Jan 26, 2022
cce1366
added test cases for the loader function
addy-pathania Jan 27, 2022
a9d87a3
renamed next-setup file
addy-pathania Jan 27, 2022
65b99f0
updated next.config comments, refactored redundant code
addy-pathania Jan 27, 2022
99b8fde
Merge branch 'dev' of github.com:Sitecore/jss into feature/449842-nex…
addy-pathania Feb 9, 2022
966d33f
added the fix from vercel regarding access to config in loader function
addy-pathania Feb 10, 2022
4a4efe2
removed blurDataUrl, made loader function more customizable, fixed tests
addy-pathania Feb 23, 2022
37ad4f9
Delete yarn.lock
addy-pathania Feb 23, 2022
bb97214
added yarn.lock
addy-pathania Feb 23, 2022
e57c8bf
updated yarn.lock
addy-pathania Feb 23, 2022
5b04db6
changed next version in template
addy-pathania Feb 24, 2022
2931885
removed redundant comments and files , changed error message
addy-pathania Feb 24, 2022
3c693eb
added test case for user custom loader function
addy-pathania Feb 24, 2022
be72d88
added another test case fro custom loader
addy-pathania Feb 24, 2022
20c2653
Merge branch 'dev' of github.com:Sitecore/jss into feature/449842-nex…
addy-pathania Feb 28, 2022
e7dc2bd
added test for absolute url, mock loader function
addy-pathania Feb 28, 2022
df3622e
added test for user sent custom loader
addy-pathania Feb 28, 2022
85cb80a
removed params object, added afterEach
addy-pathania Mar 1, 2022
970db0f
updated the afterEach call
addy-pathania Mar 1, 2022
7f90618
refactored mock loader tests
addy-pathania Mar 1, 2022
80462e8
created two describes for next image tests
addy-pathania Mar 1, 2022
e7476d3
updated tests description
addy-pathania Mar 1, 2022
6aec000
updated the order of tests and describes in next image tests
addy-pathania Mar 1, 2022
e3be2e8
Merge branch 'dev' of github.com:Sitecore/jss into feature/449842-nex…
addy-pathania Mar 2, 2022
55a7308
Simplified loader which does not depend on 'config' (not to be used a…
ambrauer Apr 5, 2022
069a216
Merge branch 'feature/449842-nextjs-image' of github.com:Sitecore/jss…
addy-pathania Apr 11, 2022
db9e21a
merged with dev
addy-pathania Apr 11, 2022
389e21b
updated image url, fixed classname bug for EE in next/image
addy-pathania Apr 12, 2022
e901234
added unit test
addy-pathania Apr 12, 2022
4f3061d
remove console.log
addy-pathania Apr 12, 2022
62d6f0c
resolved merge conflicts in yarn.lock file
addy-pathania Apr 12, 2022
0f1f69c
refactored util fucntions, removed redundant code
addy-pathania Apr 13, 2022
1fb1eb0
merged with dev
addy-pathania Apr 13, 2022
363c0a4
updated yarn.lock, refactored utils
addy-pathania Apr 13, 2022
65b9465
removed url-parse
addy-pathania Apr 14, 2022
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
@@ -1,4 +1,4 @@
import { Image, ImageField, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
import { NextImage, ImageField, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
import { ComponentProps } from 'lib/component-props';
import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
Expand All @@ -17,40 +17,46 @@ type StyleguideFieldUsageImageProps = ComponentProps &
*/
const StyleguideFieldUsageImage = (props: StyleguideFieldUsageImageProps): JSX.Element => (
<StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-image">
{/*
You can use any of the props available in the next/image.
E.g. we have used 'priority' to demonstrate how an image could be considered high priority and preload.
Lazy loading is automatically disabled for images using priority.
See here for all the features provided by next/image: https://nextjs.org/docs/api-reference/next/image
*/}
<p>Plain image</p>
<Image media={props.fields.sample1} />
<NextImage field={props.fields.sample1} priority height="51" width="204" />

{/*
Advanced image usage example
editable: controls whether image can be edited in Sitecore Experience Editor
imageParams: parameters that are passed to Sitecore to perform server-side resizing of the image.
unoptimized: disables next/image source optimization in favor of imageParams
imageParams: parameters that are passed to Sitecore to perform server-side resizing of the image
Sample rescales image to max 100x50 dimensions on the server, respecting aspect ratio
IMPORTANT: imageParams must be whitelisted for resizing to occur. See /sitecore/config/*.config (search for 'allowedMediaParams')
any other attributes: pass through to img tag
*/}
<p>Advanced image (not editable)</p>
<Image
<NextImage
field={props.fields.sample2}
editable={false}
unoptimized={true}
imageParams={{ mw: 100, mh: 50 }}
height="50"
width="94"
data-sample="other-attributes-pass-through"
/>

{/*
Srcset adaptive image usage example
Adaptive srcsets are supported using Sitecore server-side resizing.
The `srcSet` can use Sitecore image resizing parameters (i.e. w, h, mw, mh).
Sample create a srcset using two sizes (server resizing), 300 and 100px max widths, respecting aspect ratio.
IMPORTANT: srcSet params must be whitelisted for adaptive resizing to occur. See /sitecore/config/*.config (search for 'allowedMediaParams')
next/image generates responsive srcSet automatically based on layout. See https://nextjs.org/docs/api-reference/next/image#layout.
IMPORTANT: The generated sizes should match your Sitecore server-side allowlist. See /sitecore/config/*.config (search for 'allowedMediaParams')
*/}
<p>Srcset responsive image</p>
<Image
<NextImage
field={props.fields.sample2}
srcSet={[{ mw: 300 }, { mw: 100 }]}
sizes="(min-width: 960px) 300px, 100px"
className="img-fluid"
height="105"
width="200"
sizes="50vw"
layout="responsive"
/>
</StyleguideSpecimen>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Field } from '@sitecore-jss/sitecore-jss-nextjs';
/**
* Shared styleguide specimen fields
*/
export type StyleguideSpecimenFields = {
export type StyleguideSpecimenFields = {
fields: {
description: Field<string>;
heading: Field<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</apps>
<!--
IMAGE RESIZING WHITELIST
Using Sitecore server-side media resizing (i.e. the `imageParams` or `srcSet` props on the `<Image/>` helper component)
Using Sitecore server-side media resizing (i.e. the `imageParams` or `srcSet` props on the `<Image/>` helper component or the `<NextImage/>` helper component)
could expose your Sitecore server to a denial-of-service attack by rescaling an image with many arbitrary dimensions.
In JSS resizing param sets that are unknown are rejected by a whitelist.

Expand All @@ -115,10 +115,24 @@
<styleguide-image-sample>
mw=100,mh=50
</styleguide-image-sample>
<styleguide-image-sample-adaptive>
mw=300
mw=100
</styleguide-image-sample-adaptive>
<next-image-default>
mw=16
mw=32
mw=48
mw=64
mw=96
mw=128
mw=256
mw=384
mw=640
mw=750
mw=828
mw=1080
mw=1200
mw=1920
mw=2048
mw=3840
</next-image-default>
</allowedMediaParams>
</javaScriptServices>
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ export const getServerSideProps: GetServerSideProps = async (context) => {

return {
props,
<% if (prerender === 'SSG') { -%>
<% if (prerender === 'SSG') { -%>
// Next.js will attempt to re-generate the page:
// - When a request comes in
// - At most once every 5 seconds
revalidate: 5, // In seconds
<% } -%>
<% } -%>
notFound: props.notFound, // Returns custom 404 page with a status code of 404 when true
};
};
Expand Down
1 change: 1 addition & 0 deletions packages/sitecore-jss-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-string": "^1.5.0",
"chalk": "^4.1.2",
"del-cli": "^3.0.1",
"enzyme": "^3.10.0",
Expand Down
Loading