Child component cannot access context that the parent can access?
I have a file like this:
As you can see, the
RichTextPlugin
component renders the Placeholder
component. Except that I get an error:
... which is the error thrown by useLexicalComposerContext
when the context is empty.
Now, the useLexicalComposerContext
is called in the parent component as well, and it returns the editor successfully, no errors (I added logs to double check as well). So why is the child unable to access it?
I also added some getOwner
logs (not shown), and they show the parent as having an owner, but that the owner of the child is null
.
I'm quite frustrated, if anyone has an idea, please help!2 Replies
Could it have something to do with the fragments?
I checked that, it's not that
I'm realizing now that this is all more complicated than the information I gave above. sigh
Still trying to narrow down where the issue is
Okay, I figured it out
The error is actually thrown later in the child component, at a line like this:
Now,
useLexicalEditable
internally calls useLexicalComposerContext
, but useLexicalEditable
is defined in a .ts
(compiled to .js
) file while these components were declared in .tsx
(compile to .jsx
) file. For further context, these files are all inside a package, the issue did not appear when using the package in the monorepo where it was declared
So my guess is that vite ends up with different files / instances of the context (because only .jsx files are fed through the solid vite plugin), so code in .js
files weren't able to see the context defined in .jsx
files
Something roughly like that, I expect those here who have worked on the tooling side of things would have a better idea
So, solved
Now, what is the right way of marking this as answered?