Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 3 tasks
veedeo opened this issue Oct 1, 2023 · 3 comments
Open
2 of 3 tasks
Labels
bug Something isn't working

Comments

@veedeo
Copy link
Contributor

veedeo commented Oct 1, 2023

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

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.
@veedeo veedeo added the bug Something isn't working label Oct 1, 2023
@gchust
Copy link

gchust commented Oct 25, 2023

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 />)
}

@wkABXY
Copy link

wkABXY commented Apr 12, 2024

need a complete example,please。

@wkABXY
Copy link

wkABXY commented Apr 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants