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

Calling a function on an HTML element created from a Preact Hook does not work #455

Open
KallynGowdy opened this issue Apr 24, 2024 · 0 comments
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

Comments

@KallynGowdy
Copy link
Member

KallynGowdy commented Apr 24, 2024

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:

  1. Rework the frontend so that elements are not separated by document and so then functions can be called no matter where they have been created. (This would only fix this particular issue)
  2. Rework the backend so that there is only ever one document. (This would fix not only this issue, but also additional issues that can arise if users end up moving elements between custom apps or trying to compare elements using instanceof HTMLElement)

For now, the only workaround is to ditch using os.registerApp() and os.compileApp(), and instead only use document and os.appHooks.render(). This would cause everything to use the same HTML document and therefore avoid the issue. Before using document, be sure to wait for the @onDocumentAvailable shout.

@KallynGowdy KallynGowdy converted this from a draft issue Apr 24, 2024
@KallynGowdy KallynGowdy added bug Something isn't working area:runtime Is related to the CasualOS runtime. (Everything in aux-runtime, aux-common, aux-vm, etc.) area:player Is related to the player frontend. (Everything in aux-server/aux-web/aux-player) labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
Status: Backlog
Development

No branches or pull requests

1 participant