You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today I used patch-package to patch gatsby-background-image@1.4.1 for the project I'm working on.
When loading some images, in particular using the GatsbyImageSharpFluid_withWebp fragment, I got this error: TypeError: Cannot use 'in' operator to search for 'tracedSVG' in /static/leasing-hero-7243173125ec92963d5a31594d1cee6b.jpgat EFel.t.getCurrentFromData (ImageUtils.js:76)at t.switchImageSettings (ImageHandling.js:75)at t.n.render (index.js:273)at $o (react-dom.production.min.js:4289)at Jo (react-dom.production.min.js:4280)at Tl (react-dom.production.min.js:6722)at js (react-dom.production.min.js:5696)at Ms (react-dom.production.min.js:5685)at xs (react-dom.production.min.js:5441)at react-dom.production.min.js:2877
Investigating with a debugger, I noticed that sometimes a string is passed in the data parameter of the getCurrentFromData function, in which case the in operator results in a TypeError. Adding this type guard prevents the crash.
Here is the diff that solved my problem:
diff --git a/node_modules/gatsby-background-image/lib/ImageUtils.js b/node_modules/gatsby-background-image/lib/ImageUtils.js
index bbb3e13..9e7853e 100644
--- a/node_modules/gatsby-background-image/lib/ImageUtils.js+++ b/node_modules/gatsby-background-image/lib/ImageUtils.js@@ -66,6 +66,10 @@ var getCurrentFromData = function getCurrentFromData(_ref) {
}) : "";
}
+ if(typeof data !== 'object') {+ return "";+ }+
if ((propName === "currentSrc" || propName === 'src') && propName in data) {
return getUrlString({
imageString: checkLoaded ? imageLoaded(data) && data[propName] || "" : data[propName],
mkay, strange, when I add your patch to the sources in gbitest & add a breakpoint on return ""; it get's never hit.
Could you add a reproduction case for it?
Hi there!
As @timhagn momentarily is the main contributor to this package, this issue
has been automatically marked as stale because it has not had
any recent activity.
It will be closed if no further activity occurs, though we're open to
suggestions on how to get more maintainers!
Thank you for your contributions : )!
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
gatsby-background-image@1.4.1
for the project I'm working on.When loading some images, in particular using the
GatsbyImageSharpFluid_withWebp
fragment, I got this error:TypeError: Cannot use 'in' operator to search for 'tracedSVG' in /static/leasing-hero-7243173125ec92963d5a31594d1cee6b.jpgat EFel.t.getCurrentFromData (ImageUtils.js:76)at t.switchImageSettings (ImageHandling.js:75)at t.n.render (index.js:273)at $o (react-dom.production.min.js:4289)at Jo (react-dom.production.min.js:4280)at Tl (react-dom.production.min.js:6722)at js (react-dom.production.min.js:5696)at Ms (react-dom.production.min.js:5685)at xs (react-dom.production.min.js:5441)at react-dom.production.min.js:2877
Investigating with a debugger, I noticed that sometimes a
string
is passed in thedata
parameter of thegetCurrentFromData
function, in which case thein
operator results in aTypeError
. Adding this type guard prevents the crash.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: