Skip to content

Support for Web Components, Shadow DOM, adoptedStyleSheets #1092

Open
@fregante

Description

@fregante

Context

I want to generate a standalone component to be loaded in a shadow DOM.

It seems that this gets me most of what I need:

  • own JS chunk
  • standalone CSS chunk that includes all the CSS dependencies (sub-imports of other .css files)
import shadow from 'react-shadow';

/// partial, pseudo-code

const {Component} = await import('./Component');

return <shadow.div><Component/></shadow.div>

At this point, a Component.css file is being generated and appended to document.head.

**The problem is that this stylesheet should be inside shadow.div

Feature Proposal

I'm not sure what would be the best way to achieve this, but perhaps:

  • add a magic comment to the import() to disable the automatic injection of the stylesheet
    e.g. import(/* webpackCss: no-inject */ './Component');
  • return the URL as an additional property, so that it can be handled autonomously
    e.g. const {Component, __miniCssUrl} = await import('./Component');

Related links

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