wxt-dev / wxt-dev/wxt

Ant Design CSS not loading properly with Shadow Root UI in WXT content script

Open
#1,658 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending-triage
Dominant language
TypeScript
Stars
10.5k
Forks
564
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

I'm developing a browser extension using WXT and trying to implement Ant Design components within a Shadow Root UI in a content script. While the component structure is being rendered correctly, the Ant Design styles are not being properly applied to the components within the shadow root.

As you can see from the shadow root code, the button is rendered with Ant Design classes (ant-btn, ant-btn-default, etc.) but it's not displaying with the expected Ant Design styling.

Reproduction
  1. Create a WXT extension with a content script
  2. Set up Ant Design in the project
  3. Create a content script with the following code structure:

download.content/index.tsx:

import React from 'react';
import ReactDOM from 'react-dom/client';
import '@ant-design/v5-patch-for-react-19';
import App from './app';

export default defineContentScript({
  matches: ['<all_urls>'],
  cssInjectionMode: 'ui',

  async main(ctx) {
    const ui = await createShadowRootUi(ctx, {
      name: 'download-ui',
      position: 'modal',
      anchor: 'body',
      mode: 'closed',
      onMount: (container) => {
        const app = document.createElement('div');
        container.append(app);

        const root = ReactDOM.createRoot(app);
        root.render(<App />);
        return root;
      },
      onRemove: (root) => {
        root?.unmount();
      },
    });
    ui.mount();
  },
});

download.content/app.tsx:

import 'antd/dist/reset.css';
import React from 'react';
import { JSX } from 'react';
import { Button, ConfigProvider } from 'antd';

function App(): JSX.Element {
  return (
    <ConfigProvider>
      <Button variant={'solid'} color={'cyan'}>
        Click Me
      </Button>
    </ConfigProvider>
  );
}
export default App;

Expected behavior: The Ant Design button should display with full Ant Design styling, including proper colors, shadows, and visual effects.

Actual behavior: The button is rendered with basic HTML styling and Ant Design classes, but the actual CSS styling from Ant Design is not applied correctly within the shadow root.

Any guidance on how to correctly load Ant Design styles within a shadow root UI would be greatly appreciated.

Steps to reproduce

No response

System Info
System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz
    Memory: 17.69 GB / 31.84 GB
  Binaries:
    Node: 22.15.0 - D:\nodejs\node.EXE
    npm: 10.9.2 - D:\nodejs\npm.CMD
    pnpm: 10.10.0 - D:\nodejs\pnpm.CMD
    bun: 1.2.11 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (134.0.3124.51)
    Internet Explorer: 11.0.19041.4355
Used Package Manager

pnpm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with download.content/index.tsx and download.content/app.tsx, using the provided WXT, React, Ant Design, and Shadow Root setup. Inspect how cssInjectionMode: 'ui' handles styles in the shadow root; done means the Button receives its expected Ant Design colors, shadows, and visual effects.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.