Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Multiple references to the same asset in SASS/CSS url() breaks replacement process #196

Closed
HARVS1789UK opened this issue Oct 22, 2019 · 4 comments

Comments

@HARVS1789UK
Copy link

  • Operating System: Windows 10
  • Node Version: 10.16.3
  • NPM Version: 6.9.0
  • webpack Version: 4.41.2
  • url-loader Version: 2.2.0

Expected Behavior

  • Multiple CSS classes reference the same url-loader managed asset, for example:
.next-button {
    background-image: url('../images/icons/arrow-right.svg');
}
. right-arrow {
    background-image: url('../images/icons/arrow-right.svg');
}
  • On a build, both of these relative paths are replaced with the data URI representing arrow-right.svg

Actual Behavior

  • The first instance is correctly replaced
  • The data URI for this asset is discarded (assets are probably held in an array for replacement, array.pop() or similar is called and after the first replacement, discarded)
  • The second occurrence is incorrectly replaced with the data URI of whatever my next url-loader managed asset for replacement would be (in my case, a Facebook SVG icon)
  • This behavior continues for all later replacements, they are all one iteration off
  • The second instance is replaced with

Code

webpack.config.js - https://gist.github.com/HARVS1789UK/345ddf7ff48839982a7d3eb744b4510c

.carousel-control-next-icon {
    background-image: url('../images/icons/arrow-right.svg');
}

// Other CSS, then

.icon-arrow {
    background-image: url('../images/icons/arrow-right.svg');
}

.icon-prefix {
    display: inline-block;

    &.facebook {
        background-image: url('../images/icons/facebook-icon.svg');
    }

    &.google-plus {
        background-image: url('../images/icons/google-plus-icon.svg');
    }
}

In this scenario, .icon-arrow will have a data URI holding the Facebook icon, .facebook will show a Google Plus icon and .google-plus will be url(undefined);

How Do We Reproduce?

Include references to the same asset in multiple SASS/CSS url() definitions, review the output

@alexander-akait
Copy link
Member

alexander-akait commented Oct 22, 2019

Something wrong in your configuration, please create minimum reproducible test repo

The data URI for this asset is discarded (assets are probably held in an array for replacement, array.pop() or similar is called and after the first replacement, discarded)

No logic with array in code because it is unnecessary

@alexander-akait
Copy link
Member

Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!

@yenshih
Copy link

yenshih commented Dec 19, 2019

I've encountered the same issue. It's a bug of extract-loader. peerigon/extract-loader#54

@geonanorch
Copy link

same issue here, and as discussed in the issue mentioned by @yenshih (thanks!), replacing extract-loader with extract-text-loader fixed this rather major bug.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants