question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[gatsby-plugin-image] mobile vs. desktop logo conflicting with gatsby-image-wrapper

See original GitHub issue

My site’s desktop logo/mobile logo differing sizes are stepping on each other. At first I thought this was an issue with my code so I opened a discussion question for help but after further research I believe it is a bug.

Description

I found two similar issues #30096 and #30841 and a patch was pushed in version 1.4 to address. However, I am running v1.6.0 and I am still having a similar issue.

Here is my code:

import React from "react"
import { Link, useStaticQuery, graphql } from "gatsby"

import Navigation from "../components/navigation"
import Slider from "../components/slider"
import { GatsbyImage, getImage, withArtDirection } from "gatsby-plugin-image";
import Footer from "../components/footer"
import Pagination from "../templates/blog-pagination"

const Layout = ({ location, children }) => {
  const rootPath = `${__PATH_PREFIX__}/`
  let header

  const data = useStaticQuery(graphql`{
  desktopLogo: file(absolutePath: {regex: "/FfT_Logo_Desktop.png/"}) {
    childImageSharp {
      gatsbyImageData(
        width: 500
        quality: 100
        placeholder: TRACED_SVG
        formats: [AUTO, WEBP, AVIF]
        layout: FULL_WIDTH
      )
    }
  }
  mobileLogo: file(absolutePath: {regex: "/FfT_Logo_Mobile.png/"}) {
    childImageSharp {
      gatsbyImageData(
        quality: 100
        placeholder: BLURRED
        formats: [AUTO, WEBP, AVIF]
        layout: CONSTRAINED
      )
    }
  }
}
`)

const logos = withArtDirection(getImage(data.mobileLogo), [
  {
    media: "(min-width: 768px)",
    image: getImage(data.desktopLogo),
  },
])

  if (location.pathname === rootPath) {
    header = (
      <div class="px-4 mb-6 md:ml-20">
        <GatsbyImage image={logos} alt="Fallfish Tenkara" />
      </div>
    )
  } else {
    header = (
      <div class="px-4 mb-6 md:ml-20">
        <Link to={`/`}>
          <GatsbyImage image={logos} alt="Fallfish Tenkara" />
        </Link>
      </div>
        
    )
  }
  return (
    <div class="flex flex-col">
      <Navigation />
      <header class="pr-2">{header}</header>  
        <div class="hidden md:block w-2/3 mx-auto">
          <Slider />
        </div>
      <div class="bg-gray-200 mb-4 w-full lg:w-2/3 mx-auto overflow-hidden rounded-lg shadow-xl">
        <main>{children}</main>
        <Pagination />
      </div>
        <Footer />
    </div>
  )
}

export default Layout

If I open dev tools within localhost and edit the gatsby-image-wrapper from constrained to full_width then the logo is rendered “correctly”. However, if I update within my code constrained to full_width then I get a slew of error messages in the console and local host (see screenshot below).

Screen Shot 2021-06-04 at 2 19 01 PM

Also, I get Uncaught (in promise) ChunkLoadError: Loading hot update chunk node_modules_gatsby-plugin-image_dist_lazy-hydrate-4711f4b0_js failed. (missing: http://localhost:8000/node_modules_gatsby-plugin-image_dist_lazy-hydrate-4711f4b0_js.e64bd67ae4a8e3135120.hot-update.js) in the console which may be related to #18866 (???) After clearing the error messages the logo is still rendering incorrectly (both the live site and localhost currently have this issue)…

Here are two screen shots of the before and after edits of gatsby-image-wrapper from the dev tools. full_width

constrained

So, it would seem that the edits I am making in the query with useStaticQuery are not being pushed to gatsby-image-wrapper for some reason…

Steps to reproduce

You should see the issue on the home page of my minimum repo here make sure to switch from mobile to desktop view in dev tools to see the logo switch…

Expected result

I should be able to seamlessly switch from my desktop logo and mobile logo and have the appropriate sizes of the png files rendered on the screen.

Actual result

The logo is only partially showing, or zoomed all the way in and when I attempt to edit the code in layout.js I get multiple runtime errors (that are often cleared by refreshing the browser but sometimes have to be cleared with gatsby clean and restart of localhost) and ChunkLoadErrors (as mentioned above in Description

Environment

System: OS: macOS 11.4 CPU: (8) x64 Intel® Core™ i7-1068NG7 CPU @ 2.30GHz Shell: 5.8 - /bin/zsh Binaries: Node: 16.2.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.15.1 - /usr/local/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Firefox: 88.0.1 Safari: 14.1.1 npmPackages: gatsby: ^3.6.1 => 3.6.1 gatsby-awesome-pagination: ^0.3.8 => 0.3.8 gatsby-plugin-disqus: ^1.2.2 => 1.2.2 gatsby-plugin-feed: ^3.5.0 => 3.5.0 gatsby-plugin-gatsby-cloud: ^2.5.0 => 2.5.0 gatsby-plugin-google-analytics: ^3.5.0 => 3.5.0 gatsby-plugin-image: ^1.6.0 => 1.6.0 gatsby-plugin-manifest: ^3.5.0 => 3.5.0 gatsby-plugin-offline: ^4.5.1 => 4.5.1 gatsby-plugin-postcss: ^4.5.0 => 4.5.0 gatsby-plugin-react-helmet: ^4.5.0 => 4.5.0 gatsby-plugin-sharp: ^3.6.0 => 3.6.0 gatsby-remark-copy-linked-files: ^4.2.1 => 4.2.1 gatsby-remark-images: ^5.2.1 => 5.2.1 gatsby-remark-prismjs: ^5.2.1 => 5.2.1 gatsby-remark-responsive-iframe: ^4.2.1 => 4.2.1 gatsby-remark-smartypants: ^4.2.0 => 4.2.0 gatsby-source-filesystem: ^3.6.0 => 3.6.0 gatsby-transformer-remark: ^4.2.0 => 4.2.0 gatsby-transformer-sharp: ^3.6.0 => 3.6.0 npmGlobalPackages: gatsby-cli: 2.12.111

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:24 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
Isaac-Taitcommented, Sep 9, 2021

Not stale - the issues is still persisting

3reactions
adam993commented, Dec 27, 2021

Still having this issue, on Gatsby ^4.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby Image
The new Gatsby image plugin has better performance, cool new features and a simpler API. See the migration guide to learn how to...
Read more >
Gatsby-Image: Different images for Mobile / Desktop?
Using the method in your question will likely result in the browser downloading both images. gatsby-image has support for art direction and give ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found