Skip to content

Commit a8c2f39

Browse files
LBascorbic
andauthored
chore: Update image API to remove maxWidth/maxHeight (#28985)
* in progress * update tests * remove maxHeight and maxWidth references * add warning * not sure how that was ever throwing tbh * typo * Update wording * Fix types * propTypes check Co-authored-by: Matt Kane <matt@gatsbyjs.com>
1 parent addc9e9 commit a8c2f39

File tree

24 files changed

+179
-438
lines changed

24 files changed

+179
-438
lines changed

e2e-tests/gatsby-static-image/src/pages/constrained.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const ConstrainedPage = () => (
1111
<div data-testid="image-constrained-limit">
1212
<StaticImage
1313
src="../images/citrus-fruits.jpg"
14-
maxWidth={500}
14+
width={500}
1515
alt="Citrus fruits"
1616
/>
1717
</div>
1818
<div data-testid="image-constrained-override">
1919
<StaticImage
2020
src="../images/citrus-fruits.jpg"
21-
maxWidth={500}
21+
width={500}
2222
sizes="100vw"
2323
alt="Citrus fruits"
2424
/>

e2e-tests/gatsby-static-image/src/pages/fluid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const FluidPage = () => (
99
<StaticImage
1010
src="../images/citrus-fruits.jpg"
1111
layout="fluid"
12-
maxWidth={700}
12+
width={700}
1313
alt="Citrus fruits"
1414
/>
1515
</div>

e2e-tests/visual-regression/src/pages/images/avif.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Page = () => {
99
query {
1010
file(relativePath: { eq: "cornwall.jpg" }) {
1111
childImageSharp {
12-
gatsbyImageData(maxWidth: 1024, layout: CONSTRAINED, formats: [AVIF])
12+
gatsbyImageData(width: 1024, layout: CONSTRAINED, formats: [AVIF])
1313
}
1414
}
1515
}

e2e-tests/visual-regression/src/pages/images/constrained.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Page = () => {
99
query {
1010
file(relativePath: { eq: "cornwall.jpg" }) {
1111
childImageSharp {
12-
gatsbyImageData(maxWidth: 1024, layout: CONSTRAINED)
12+
gatsbyImageData(width: 1024, layout: CONSTRAINED)
1313
}
1414
}
1515
}

e2e-tests/visual-regression/src/pages/images/fluid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Page = () => {
99
query {
1010
file(relativePath: { eq: "cornwall.jpg" }) {
1111
childImageSharp {
12-
gatsbyImageData(maxWidth: 1024, layout: FLUID)
12+
gatsbyImageData(width: 1024, layout: FLUID)
1313
}
1414
}
1515
}

e2e-tests/visual-regression/src/pages/static-images/avif.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Page = () => {
1212
src="../../images/cornwall.jpg"
1313
alt="cornwall"
1414
formats={["avif"]}
15-
maxWidth={1024}
15+
width={1024}
1616
/>
1717
</TestWrapper>
1818
</Layout>

e2e-tests/visual-regression/src/pages/static-images/constrained.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Page = () => {
1111
<StaticImage
1212
src="../../images/cornwall.jpg"
1313
alt="cornwall"
14-
maxWidth={1024}
14+
width={1024}
1515
/>
1616
</TestWrapper>
1717
</Layout>

e2e-tests/visual-regression/src/pages/static-images/fluid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import Layout from "../../components/layout"
66
const Page = () => {
77
return (
88
<Layout>
9-
<h1>Fluid, maxWidth</h1>
9+
<h1>Fluid, width</h1>
1010
<TestWrapper style={{ display: `block` }}>
1111
<StaticImage
1212
src="../../images/cornwall.jpg"
1313
loading="eager"
1414
layout="fluid"
15-
maxWidth={1024}
15+
width={1024}
1616
alt="cornwall"
1717
/>
1818
</TestWrapper>

packages/gatsby-plugin-image/README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export const Dino = () => (
5757
<StaticImage
5858
src="trex.png"
5959
placeholder="none"
60-
layout="fluid"
61-
maxWidth={200}
60+
layout="constrained"
61+
width={200}
6262
alt="T-Rex"
6363
transformOptions={{ grayscale: true }}
6464
/>
@@ -294,7 +294,7 @@ JSON type, meaning you don't specify the individual fields, but are instead give
294294
```graphql
295295
coverImage: file(relativePath: { eq: "plant.jpg" }) {
296296
childImageSharp {
297-
gatsbyImageData(maxWidth: 720, layout: FLUID, placeholder: TRACED_SVG)
297+
gatsbyImageData(width: 720, layout: CONSTRAINED, placeholder: TRACED_SVG)
298298
}
299299
}
300300
```
@@ -316,13 +316,8 @@ The optional helper function `getImage` takes a file node and returns `file?.chi
316316

317317
These arguments can be passed to the `gatsbyImageData()` resolver:
318318

319-
- **width**: The display width of the generated image. The actual largest image resolution will be this value multiplied by the largest value in outputPixelDensities. Ignored if layout = FLUID or CONSTRAINED, where you should use "maxWidth" instead.
319+
- **width**: The display width of the generated image for layout = FIXED, if layout = CONSTRAINED it's the display width of the largest generated image. The actual largest image resolution will be this value multiplied by the largest value in outputPixelDensities.
320320
- **height**: If set, the height of the generated image. If omitted, it is calculated from the supplied width, matching the aspect ratio of the source image.
321-
- **maxWidth**:
322-
Maximum display width of generated files.
323-
The actual largest image resolution will be this value multiplied by the largest value in outputPixelDensities
324-
This only applies when layout = FLUID or CONSTRAINED. For other layout types, use "width"
325-
- **maxHeight**: If set, the generated image is a maximum of this height, cropping if necessary. If the image layout is "constrained" then the image will be limited to this height. If the aspect ratio of the image is different than the source, then the image will be cropped.`,
326321
- **placeholder**: Format of generated placeholder image.
327322
- `BLURRED`: (default) a blurred, low resolution image, encoded as a base64 data URI
328323
- `TRACED_SVG`: a low-resolution traced SVG of the image.
@@ -333,7 +328,7 @@ These arguments can be passed to the `gatsbyImageData()` resolver:
333328
- `FIXED`: A static image size, that does not resize according to the screen width
334329
- `FLUID`: The image resizes to fit its container. Pass a "sizes" option if it isn't going to be the full width of the screen.
335330
- **outputPixelDensities**: A list of image pixel densities to generate, for high-resolution (retina) screens. It will never generate images larger than the source, and will always include a 1x image.
336-
Default is `[ 0.25, 0.5, 1, 2 ]`, for fluid/constrained images, and `[ 1, 2 ]` for fixed. In this case, an image with a fluid layout and maxWidth = 400 would generate images at 100, 200, 400 and 800px wide
331+
Default is `[ 0.25, 0.5, 1, 2 ]`, for fluid/constrained images, and `[ 1, 2 ]` for fixed.
337332
- **sizes**: The "[sizes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images)" attribute, passed to the `<img>` tag. This describes the display size of the image. This does not affect the generated images, but is used by the browser to decide which images to download. You can leave this blank for fixed images, or if the responsive image container will be the full width of the screen. In these cases we will generate an appropriate value. If, however, you are generating responsive images that are not the full width of the screen, you should provide a sizes property for best performance. You can alternatively pass this value to the component.
338333
- **formats**: an array of file formats to generate. The default is `[AUTO, WEBP]`, which means it will generate images in the same format as the source image, as well as in the next-generation [WebP](https://developers.google.com/speed/webp) format. We strongly recommend you do not change this option, as doing so will affect performance scores.
339334
- **quality**: The default quality. This is overridden by any format-specific options

packages/gatsby-plugin-image/src/__tests__/image-utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ const args: IGatsbyImageHelperArgs = {
3737

3838
const fluidArgs: IGatsbyImageHelperArgs = {
3939
...args,
40-
width: undefined,
41-
maxWidth: 400,
4240
layout: `fluid`,
4341
}
4442

4543
const constrainedArgs: IGatsbyImageHelperArgs = {
46-
...fluidArgs,
44+
...args,
4745
layout: `constrained`,
4846
}
4947

0 commit comments

Comments
 (0)