plasmo icon indicating copy to clipboard operation
plasmo copied to clipboard

[BUG] getInlineAnchorList() and custom getRootContainer() enter infinite loop

Open veedeo opened this issue 1 year ago • 3 comments

What happened?

This code works as expected

export default Anchor;

export const getInlineAnchorList: PlasmoGetInlineAnchorList = async () =>
  document.querySelectorAll(`.comments-comment-texteditor .comments-comment-box__button-group`);

But I would like to customize root Container:

  1. prepend to anchor children
  2. dont use Shadow DOM

So when I add a custom getRootContainer() it runs in infinite loop, what Im missing here?

export default Anchor;

export const getInlineAnchorList: PlasmoGetInlineAnchorList = async () =>
  document.querySelectorAll(`.comments-comment-texteditor .comments-comment-box__button-group`);

export const getRootContainer: PlasmoGetRootContainer = ({ anchor, mountState }) => {
  console.log(anchor, mountState);
  return anchor.element;
}

Version

Latest

What OS are you seeing the problem on?

No response

What browsers are you seeing the problem on?

No response

Relevant log output

No response

(OPTIONAL) Contribution

  • [ ] I would like to fix this BUG via a PR

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] I checked the current issues for duplicate problems.

veedeo avatar Oct 01 '23 18:10 veedeo

I have faced the same issue, but if we are also customizing renderer, then everything works right.

So anyone faced this issue could try the solution below

export const render: PlasmoRender<PlasmoCSUIJSXContainer> = async ({
  createRootContainer
}) => {
  const rootContainer = await createRootContainer()
  const root = createRoot(rootContainer)
  root.render(<SomeComponent />)
}

gchust avatar Oct 25 '23 12:10 gchust

need a complete example,please。

wkABXY avatar Apr 12 '24 12:04 wkABXY

export const getInlineAnchor = async () => document.querySelector(".home")

export const getRootContainer: PlasmoGetRootContainer = async ({ anchor }) => {
  return anchor.element.appendChild(document.createElement("div"))
}

const PlasmoOverlay: FC<PlasmoCSUIProps> = () => {
  return (...)
}

export const render: PlasmoRender<PlasmoCSUIJSXContainer> = async ({
  anchor,
  createRootContainer
}) => {
  console.log(anchor.element)
  const rootContainer = await createRootContainer(anchor)
  const root = createRoot(rootContainer)
  root.render(<PlasmoOverlay />)
}

export default PlasmoOverlay

enter infinite loop

wkABXY avatar Apr 12 '24 12:04 wkABXY