# Adding imageSharp to query breaks page preview

**URL:** <https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559>\
**Category:** Developing with Prismic\
**Tags:** gatsby\
**Created:** [August 16, 2020, 11:56am UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559 "2020-08-16T11:56:46Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [August 16, 2020, 11:56am UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/1 "2020-08-16T11:56:46Z")

</div>

After adding a imageSharp to the query the previews stopped working the page completely. I have learned that the previews do not work with imageSharp and you need to use a fallback.

```
query pageQuery($uid: String!, $lang: String!) {
  prismic {
    page(uid: $uid, lang: $lang) {
      title
      description
      theme
      _meta {
        type
      }
      body {
        ... on PRISMIC_PageBodyQuote {
          type
          primary {
            quote_name
            quote_body
            quote_image
            quote_imageSharp {
              childImageSharp {
                fluid(maxWidth: 400) {
                  ...GatsbyImageSharpFluid
                }
              }
            }
          }
        }
      }
    }
  }
}

```

While debugging I have found this:

**NOTE** Images are not transformed in preview mode, so be sure to fall back to the default image when the sharp image is `null` .

```auto
import Img from 'gatsby-image';
import get from 'lodash/get';

// ...

const sharpImage = get(data, 'prismic.Author.profile_pictureSharp.childImageSharp.fluid');
return sharpImage ? (
  <Img fluid={sharpImage} />
) : (
  <img src={get(data, 'prismic.Author.profile_picture.url')} />
);

```

Later, we may add an `Image` component that does this for you and leverages the new Prismic Image API as a fallback for preview modes.

> **[gatsby-source-prismic-graphql | Gatsby](https://www.gatsbyjs.com/plugins/gatsby-source-prismic-graphql/?=prismic)**
>
> gatsby-source-prismic-graphql A Gatsby plugin for fetching source data from the Prismic headless CMS using Prismic’s beta GraphQL API. This…

This makes sense, yet I don't understand why by just adding this snippet breaks the previews completly.

```
quote_imageSharp {
  childImageSharp {
    fluid(maxWidth: 400) {
      ...GatsbyImageSharpFluid
    }
  }
}

```

Here is my package.json, could it be that I have to upgrade some packages?

```
{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "@loadable/component": "^5.13.1",
    "@tailwindcss/typography": "^0.2.0",
    "autoprefixer": "^9.8.0",
    "classnames": "^2.2.6",
    "gatsby": "^2.22.15",
    "gatsby-background-image": "^1.1.1",
    "gatsby-image": "^2.4.12",
    "gatsby-plugin-google-tagmanager": "^2.3.10",
    "gatsby-plugin-manifest": "^2.4.9",
    "gatsby-plugin-offline": "^3.2.7",
    "gatsby-plugin-postcss": "^2.3.4",
    "gatsby-plugin-prefetch-google-fonts": "^1.4.3",
    "gatsby-plugin-purgecss": "^5.0.0",
    "gatsby-plugin-react-helmet": "^3.3.2",
    "gatsby-plugin-react-svg": "^3.0.0",
    "gatsby-plugin-remove-trailing-slashes": "^2.3.11",
    "gatsby-plugin-sharp": "^2.6.18",
    "gatsby-source-filesystem": "^2.3.8",
    "gatsby-source-prismic-graphql": "^3.6.2",
    "gatsby-transformer-sharp": "^2.5.10",
    "postcss-import": "^12.0.1",
    "prismic-javascript": "^3.0.0",
    "prismic-reactjs": "^1.3.1",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-compare-image": "^3.0.2",
    "react-dom": "^16.12.0",
    "react-helmet": "^6.0.0",
    "react-intersection-observer": "^8.26.2",
    "react-scrollama": "^2.2.10",
    "swiper": "^6.0.4",
    "tailwindcss-fluid": "^0.2.0",
    "uid": "^1.0.0"
  },
  "resolutions": {
    "gatsby-source-graphql-universal": "3.3.0"
  },
  "devDependencies": {
    "@fullhuman/postcss-purgecss": "^2.3.0",
    "dotenv": "^8.2.0",
    "postcss-preset-env": "^6.7.0",
    "prettier": "2.0.5",
    "tailwindcss": "^1.4.6"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

```

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [August 17, 2020, 3:46pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/3 "2020-08-17T15:46:26Z")

</div>

Hi Anton,

Thank you for posting on the Prismic community, I will try to help you with this,

Let’s start by updating your dependency of [gatsby-source-prismic-graphql](https://www.npmjs.com/package/gatsby-source-prismic-graphql) to the [Prismic fork of the plugin](https://www.npmjs.com/package/@prismicio/gatsby-source-prismic-graphql) as Birkir’s plugin is not maintained anymore.

Please let us know if that doesn’t solve the issue,  
Fares

---

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [August 17, 2020, 4:32pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/4 "2020-08-17T16:32:30Z")

</div>

Hi Fares! Thanks for the tip. I have upgraded the gatsby-source-prismic-graphql, yet causes the following sources…

 ![Screenshot 2020-08-17 at 18.28.18](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/1X/520cbf24317a4391ba010d3f4ce9fa6635aa3626.png)

```
{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "@loadable/component": "^5.13.1",
    "@prismicio/gatsby-source-prismic-graphql": "^3.6.11",
    "@tailwindcss/typography": "^0.2.0",
    "autoprefixer": "^9.8.0",
    "classnames": "^2.2.6",
    "gatsby": "^2.22.15",
    "gatsby-background-image": "^1.1.1",
    "gatsby-image": "^2.4.12",
    "gatsby-plugin-google-tagmanager": "^2.3.10",
    "gatsby-plugin-manifest": "^2.4.9",
    "gatsby-plugin-offline": "^3.2.7",
    "gatsby-plugin-postcss": "^2.3.4",
    "gatsby-plugin-prefetch-google-fonts": "^1.4.3",
    "gatsby-plugin-purgecss": "^5.0.0",
    "gatsby-plugin-react-helmet": "^3.3.2",
    "gatsby-plugin-react-svg": "^3.0.0",
    "gatsby-plugin-remove-trailing-slashes": "^2.3.11",
    "gatsby-plugin-sharp": "^2.6.18",
    "gatsby-source-filesystem": "^2.3.8",
    "gatsby-transformer-sharp": "^2.5.10",
    "postcss-import": "^12.0.1",
    "prismic-javascript": "^3.0.0",
    "prismic-reactjs": "^1.3.1",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-compare-image": "^3.0.2",
    "react-dom": "^16.12.0",
    "react-helmet": "^6.0.0",
    "react-intersection-observer": "^8.26.2",
    "react-scrollama": "^2.2.10",
    "swiper": "^6.0.4",
    "tailwindcss-fluid": "^0.2.0",
    "uid": "^1.0.0"
  },
  "resolutions": {
    "gatsby-source-graphql-universal": "3.3.0"
  },
  "devDependencies": {
    "@fullhuman/postcss-purgecss": "^2.3.0",
    "dotenv": "^8.2.0",
    "postcss-preset-env": "^6.7.0",
    "prettier": "2.0.5",
    "tailwindcss": "^1.4.6"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}
```

---

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [August 17, 2020, 4:48pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/5 "2020-08-17T16:48:18Z")

</div>

Solved the last error by:

```
const {

registerLinkResolver,

} = require("@prismicio/gatsby-source-prismic-graphql")

const { linkResolver } = require("./src/utils/linkResolver")

registerLinkResolver(linkResolver)

```

Still the top 3 error remain. 2 are related to chacing the other points to the wrong route. 🤔

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [August 18, 2020, 2:19am UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/6 "2020-08-18T02:19:42Z")

</div>

> [@anton](#):
>
> **NOTE** Images are not transformed in preview mode, so be sure to fall back to the default image when the sharp image is `null`

Hey Anton, about the Image sharp question you had. We have a dedicated article that covers this topic. You can find it here: [Prismic Imgix Integration & Gatsby-Image](https://prismic.io/docs/gatsby/misc-topics/image-imgix-optimization)

There, we explain why you don't actually need to use the `gatsby-transformer-sharp` and `gatsby-plugin-sharp` plugins. Thanks to [The Image Optimization feature](https://user-guides.prismic.io/en/articles/3309829-image-optimization-imgix-integration) all your images are now processed out of the box.

Take a look at the documentation and tell us if it works for you ⭐

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [August 18, 2020, 9:32am UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/7 "2020-08-18T09:32:26Z")

</div>

Thanks @Pau for the help, @anton did you manage to solve the other errors after the switch to [Prismic fork of the plugin](https://www.npmjs.com/package/@prismicio/gatsby-source-prismic-graphql)?

Please let us know if you need any further help,  
Fares

---

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [August 19, 2020, 11:46am UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/8 "2020-08-19T11:46:21Z")

</div>

Thx for the help @Fares. I think updating the packages has solved the issue.

There are still some errors, yet I am not sure if they are related to the update.

The site works, I will investigate a bit further once I will have more time.

---

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [August 19, 2020, 11:48am UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/9 "2020-08-19T11:48:57Z")

</div>

For example when I run “gatsby develop” I get this message:

 ![Screenshot 2020-08-19 at 13.47.51](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/1X/61c9003756d35b8284fd77f4f045a5686622d1c4.png)

---

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [September 1, 2020, 2:42pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/11 "2020-09-01T14:42:42Z")

</div>

@Fares I finally found some spare time to do a fresh install of the new prismic plugin ( **@prismicio/gatsby-source-prismic-graphql** ), to see if the errors mentioned above are related to me updating the plugin.

Unfortunately, I got a new set of errors…

 ![Screenshot 2020-09-01 at 16.30.25](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/1X/cf8d9db78f4dc4f154d43498d1b830150dccfdfb.png)

Is there an example repo that I can fork and update the API\_KEY without running into errors?  
Otherwise, an example with package.json could help as well.

Cheers,  
Anton

---

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [September 1, 2020, 3:14pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/12 "2020-09-01T15:14:49Z")

</div>

Hi @Fares,

I have stumbled upon this article:

" Our documentation for Gatsby was created around the gatsby-source-prismic-graphql plugin. We are now having certain problems with this plugin which we have [discussed fully at length in this blog post](https://prismic.io/blog/gatsby-prismic-plugins). Now our current stance is that we recommend users not to build a new Prismic project with the gatsby-source-prismic-graphql plugin."

In the article it is recommended to switch to this plugin:

> **[angeloashmore/gatsby-source-prismic](https://github.com/angeloashmore/gatsby-source-prismic)**
>
> Gatsby source plugin for building websites using prismic.io as a data source - angeloashmore/gatsby-source-prismic

To be honest, this is a bit of a bummer… since this will become a fourth plugin that I will re-implement for this project…

Can you please confirm if previews are stable here (text, images)? Is there example repo with working code?

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [September 1, 2020, 3:51pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/13 "2020-09-01T15:51:14Z")

</div>

Hi Anton,

As I mentioned in this [thread](https://community.prismic.io/t/typeerror-cannot-read-property-pathname-of-undefined-withpreview-gatsby-source-prismic/1319/17), the multisession preview can still work if you use [our fork of gatsby-source-prismic-graphql](https://www.gatsbyjs.com/plugins/@prismicio/gatsby-source-prismic-graphql/?=gatsby-source-prismic-graphql) that we are still maintaining.

As mentioned in the blog post shared before we don’t recommend this plugin for new projects.

If you need a plugin that is a future proof solution that is recommended by Prismic, then I would advise you to use the [gatsby-source-prismic](https://www.gatsbyjs.com/plugins/gatsby-source-prismic/?=gatsby-source-prismic)  
Note that the multisession previews feature don’t work currently with this plugin.

Furthermore, if you need to use more stable SSR that works with multisession previews then I would advise you to use Next.js

Please let us know if you need any further assistance.

---

<div class="post-metadata">

**Author:** ![anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anton](https://community.prismic.io/u/anton)\
**Post date:** [September 4, 2020, 11:47am UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/14 "2020-09-04T11:47:17Z")

</div>

@Fares I think I have made this work. Thanks for the help! 🙌

I have another question that is related to previews, yet unrelated to this issue. I will create a separate topic for this.

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [September 4, 2020, 1:59pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/15 "2020-09-04T13:59:54Z")

</div>

Hi Anton,

Thanks for letting us know, and don’t hesitate to tag me in the new thread if you need my help.

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [September 15, 2020, 4:45pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/16 "2020-09-15T16:45:29Z")

</div>

closed on September 15, 2020, 4:45pm UTC, flag & select 'Something Else' to reopen.



---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 5:20pm UTC](https://community.prismic.io/t/adding-imagesharp-to-query-breaks-page-preview/1559/17 "2021-12-09T17:20:53Z")

</div>

Opened on December 9, 2021, 5:20pm UTC


