Calling a function on an HTML element created from a Preact Hook does not work #455
Labels
area:player
Is related to the player frontend. (Everything in aux-server/aux-web/aux-player)
area:runtime
Is related to the CasualOS runtime. (Everything in aux-runtime, aux-common, aux-vm, etc.)
bug
Something isn't working
Calling a function on a HTML element that was created from inside a Preact Hook callback does not work. This happens because CasualOS allows multiple distinct documents, and uses them to distinguish between function call handlers. Unfortunately, Preact doesn't know about these separate documents, so whenever an element needs to be created as a result of a Preact hook (like
useState()
), then it uses the default (_root
) document. This can cause a custom app to have elements from two distinct documents, and because function call handlers kept separate based on document, elements that are created in this way do not have functioning function call handlers (like.focus()
).See this gist for an example.
Possible solutions to this are to:
instanceof HTMLElement
)For now, the only workaround is to ditch using
os.registerApp()
andos.compileApp()
, and instead only usedocument
andos.appHooks.render()
. This would cause everything to use the same HTML document and therefore avoid the issue. Before usingdocument
, be sure to wait for the@onDocumentAvailable
shout.The text was updated successfully, but these errors were encountered: