PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.59k stars 369 forks source link

[BUG] Overriding the default render fails when using the built in InlineCSUIContainer or OverlayCSUIContainer #1046

Open cheesestringer opened 3 months ago

cheesestringer commented 3 months ago

What happened?

Following the docs at https://docs.plasmo.com/framework/content-scripts-ui/life-cycle#renderer to override the default render using the built in Inline Container or overlay Container fails with the error: Cannot read properties of undefined (reading 'type') at injectAnchor (csui.ts:58:14).

To reproduce create a new content ui script with an InlineCSUIContainer or OverlayCSUIContainer.

InlineCSUIContainer:

import type {
  PlasmoCSConfig,
  PlasmoCSUIJSXContainer,
  PlasmoRender
} from "plasmo"
import { createRoot } from "react-dom/client"

export const config: PlasmoCSConfig = {
  matches: ["https://*/*"]
}

const InlineDemo = ({ anchor }) => <span>{anchor.innerText}</span>

export const render: PlasmoRender<PlasmoCSUIJSXContainer> = async (
  { anchor, createRootContainer },
  _,
  InlineCSUIContainer
) => {
  const rootContainer = await createRootContainer()

  const root = createRoot(rootContainer)
  root.render(
    <InlineCSUIContainer anchor={anchor}>
      <InlineDemo anchor={anchor} />
    </InlineCSUIContainer>
  )
}

export default InlineDemo 

OverlayCSUIContainer:

import type {
  PlasmoCSConfig,
  PlasmoCSUIJSXContainer,
  PlasmoRender
} from "plasmo"
import { createRoot } from "react-dom/client"

export const config: PlasmoCSConfig = {
  matches: ["https://*/*"]
}

const OverlayDemo = ({ anchor }) => <span>{anchor.innerText}</span>

export const render: PlasmoRender<PlasmoCSUIJSXContainer> = async (
  { anchor, createRootContainer },
  _,
  OverlayCSUIContainer
) => {
  const rootContainer = await createRootContainer()

  const root = createRoot(rootContainer)
  root.render(
    <OverlayCSUIContainer anchor={anchor}>
      <OverlayDemo anchor={anchor} />
    </OverlayCSUIContainer>
  )
}

export default OverlayDemo 

Version

Latest

What OS are you seeing the problem on?

Windows

What browsers are you seeing the problem on?

Microsoft Edge

Relevant log output

Uncaught (in promise) 
TypeError: Cannot read properties of undefined (reading 'type')
    at injectAnchor (csui.ts:58:14)
    at createShadowContainer (csui.ts:74:3)
    at async Object.render (demo.tsx:35:15)

(OPTIONAL) Contribution

Code of Conduct

theultimatecopilot commented 1 week ago

do you resolve this problem?