dioxus-web: Add Config::rootelement
#1851
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR affects dioxus-web and allows to specify a direct element as dom-root. Before, it was necessary to specify the element by ID. This is annoying, for example if the element was created dynamically.
It is now possible to directly specify the element:
This is equivalent to
The old approaches still work. This PR just adds the new method
Config::rootelement
. It is necessary for dynamically created elements, for example in shadow roots.Open problems
Unfortunately, it still does not work with iframes and popup windows, because of a nice JavaScript detail: JavaScript types like
Object
,Element
,Node
, ... are tied to a window. Therefore, JavaScript code like the following will print "false":This behaviour obviously transfers to WASM, i.e. the following code panics:
The last line is necessary because we need to cast
HtmlElement
toElement
. Unfortunately, this does not work, because rust does not support "Runtime types", for example types which are tied to specific windows which are created at runtime.Note that the problem is only caused by the fact that
dyn_into
uses theinstanceOf
operator to check if the cast is ok. Just usingbody.into()
works fine. I adjusted all places indioxus-web
, and it worked fine with both iframes and popup windows 馃殌馃殌馃殌However, this may be a little too risky for this PR. Maybe I'll add another after this one.
Issues
Closes #1848