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 3: gatsby-plugin-image partially rerendering images

See original GitHub issue

Description

We migrated to gatsby3 and to the new gatsby-plugin-image. Everything works fine except the following issue:

There is 48 cards with GatsbyImage component. The cards with the images are rendered just fine, but after clicking sort by, the page is re-rendered and some cards are empty, gatsby-image-wrapper is empty, which means that GatsbyImage is not re-rendered and the following error is shown in the console:

DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

Steps to reproduce

https://603fcf118d59a000077eecb0--gatsbys-adika-torefront.netlify.app/categories/clothing__tops__all/

click on sort by , or another filter

Here is minimal example repo: https://github.com/creotip/gatsby-3-images-error

Expected result

Should re-render images

Actual result

Partiallly re-rendered images

Environment

System: OS: macOS 11.1 CPU: (8) x64 Intel® Core™ i5-1038NG7 CPU @ 2.00GHz Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.3 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.9 - /usr/local/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 89.0.4389.72 Firefox: 86.0 Safari: 14.0.2 npmPackages: gatsby: ^3.0.0 => 3.0.0 gatsby-image: ^3.0.0 => 3.0.0 gatsby-plugin-image: ^1.0.0 => 1.0.0 gatsby-plugin-lodash: ^4.0.0 => 4.0.0 gatsby-plugin-manifest: ^3.0.0 => 3.0.0 gatsby-plugin-material-ui: ^2.1.10 => 2.1.10 gatsby-plugin-offline: ^4.0.0 => 4.0.0 gatsby-plugin-react-helmet: ^4.0.0 => 4.0.0 gatsby-plugin-react-svg: ^3.0.0 => 3.0.0 gatsby-plugin-remove-fingerprints: 0.0.2 => 0.0.2 gatsby-plugin-resolve-src: ^2.1.0 => 2.1.0 gatsby-plugin-root-import: ^2.0.6 => 2.0.6 gatsby-plugin-sharp: ^3.0.0 => 3.0.0 gatsby-plugin-styled-components: ^4.0.0 => 4.0.0 gatsby-source-filesystem: ^3.0.0 => 3.0.0 gatsby-transformer-sharp: ^3.0.0 => 3.0.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:34 (7 by maintainers)

github_iconTop GitHub Comments

11reactions
ascorbiccommented, Apr 16, 2021

Could everyone who experienced this please install gatsby-plugin-image@1.4.0-next.1 and see if it fixes it.

5reactions
philr35commented, Apr 7, 2021

I just started getting Target container is not a DOM element. all over my app, same as @popeating

react-dom.development.js:26091 Uncaught (in promise) Error: Target container is not a DOM element.
    at render (react-dom.development.js:26091)
    at m (lazy-hydrate.tsx:91)
    at eval (gatsby-image.browser.tsx:92)

I’m using gatsby-plugin-image: ^1.2.0-next.0 => 1.2.0


edit: Upgrading to gatsby-plugin-image: ^1.3.0-next.1 => 1.3.0-next.1 did not work.


edit: Downgrading to gatsby-plugin-image: 1.1.2 => 1.1.2 WORKED!

Conclusion:

The error only comes up when images are being unmounted dynamically. In my case applying an image filter which dynamically renders new images and unmounts the old ones. This was quite difficult to debug since the error itself gives not hints into what is actually the problem.

Quick fix:

Downgrade to gatsby-plugin-image@1.1.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating from gatsby-image to gatsby-plugin-image
This document is provided to help users of gatsby-image migrate to using gatsby-plugin-image . Note that you can use both packages at the...
Read more >
gatsby-plugin-image | <StaticImage /> Does not display the ...
The problem is when I want to render static images using the StaticImage Component. Here is an example: import laptop from '@images/laptop.png';.
Read more >
Gatsby Changelog | 5.3.0
For example, in gatsby-plugin-image you were able to use it with tracedSvg and ... As of Gatsby 5 we're no longer supporting Gatsby...
Read more >
The 5 most used Gatsby.js plugins explained
In simple words, Gatsby-image is the plugin that is going to allow you to render your images. When I started with Gatsby.js ,...
Read more >
Make your designer happier with Gatsby's image ...
Thankfully, Gatsby provides three (3) separate plugins for that: ... resize, enhance and re-format images through its functional API, ...
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