Skip to content

Add support for using lazyStyleTag use() from a JavaScript module (injecting into multiple shadow DOMs) #565

Open
@mikeaustin

Description

@mikeaustin

Feature Proposal

When using lazyStyleTag and use({ target: shadowRoot }) inside a shared JavaScript module, only the first call to use injects a style element. The other shadow elements that call use() have no styles. I've duplicated the module and loaded each and the problem does not exist. There may be other options such somehow forcing separate module instances, but I'm not sure.

In index.js, I believe the following condition prevents use() from injecting duplicate styles:

if (!(refs++)) {
    update = API(content, options);
}

https://github.com/webpack-contrib/style-loader/blob/master/src/index.js#L131

One possible solution is to give an id to each injected style element, instead of having a global refs value.

Feature Use Case

loading JS modules injected into shadow elements, so modules can be loaded dynamically.

Please paste the results of npx webpack-cli info here, and mention other relevant information

System:
OS: macOS 12.1
CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
Memory: 122.11 MB / 16.00 GB
Binaries:
Node: 14.18.1 - /usr/local/bin/node
npm: 6.14.15 - /usr/local/bin/npm
Browsers:
Chrome: 101.0.4951.64
Chrome Canary: 104.0.5071.0
Firefox: 98.0.1
Safari: 15.2
Safari Technology Preview: 15.4
Packages:
css-loader: ^6.7.1 => 6.7.1
css-modules-typescript-loader: ^4.0.1 => 4.0.1
styles-loader: ^4.0.1 => 4.0.1
ts-loader: ^9.3.0 => 9.3.0
webpack-cli: ^4.9.2 => 4.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions