-
Notifications
You must be signed in to change notification settings - Fork 381
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
Allow customizing base URL of a shadow root #581
Comments
I can see that making a |
Yeah, we should allow As per the current spec, However, as far as I know, the reason is simply that we do not have bandwidth to support this as a v1 feature. Let's support this in v2 feature. We might want to update HTML Standard directly: https://html.spec.whatwg.org/#the-base-element |
We discussed this before and could not come up with a satisfactory design back then: https://www.w3.org/Bugs/Public/show_bug.cgi?id=20976#c23. (Note that if we go down this route anyway, if we overcome those obstacles somehow, we shouldn't repurpose the |
Note also that the use case discussed in OP is something that probably warrants the sometimes-discussed isolated shadow trees. Those would have their own base URL due to being isolated. |
Maybe |
Maybe, but see the bug I pointed to. It doesn't help when creating elements dynamically. |
One way to mitigate that might be adding |
Meaning element constructors are broken-by-design? |
@annevk : This is why I wanted to make But really, there is no way to know whether a given element is created for a shadow tree or not without giving some information about it. Also, constructor shouldn't be doing something different based to which tree it belongs. e.g. |
Is there any adoption phase that's executed when an element is appended into shadow root? Can the affected values be efficiently recalculated? E.g. it could look like a smaller-scope update when the document's |
Appending is too late for |
@annevk : I don't think implicitly preloading scripts while it's not connected to a document is a good pattern because that can easily lead to unintentional / accidental fetches users of the elements didn't intend. It's much better to manually |
Fair, but as long as the script still has to compute URLs itself, the benefit of this seems marginal, especially as it breaks common patterns. You really want isolation so the script has its own URL. |
What common patterns? Creating an element and expecting it to load before it gets connected to a document isn't really a common pattern these days. I'm not aware of any JS frameworks or libraries that do anything remotely close to that. |
And they don't load resources outside of that? Seems implausible. |
Some apps do load resources outside of their components but that's not gonna change just because they use shadow DOM or custom elements. Things like GraphQL isn't going to make disconnected component start fetching stuff, and that's by design. So I'm not at all convinced that prefecthing resources inside components disconnected from a document is something developers want. |
When loading a resource outside of DOM, the script has all necessary tools to construct the right URL already - this is correct. And it's certainly a valid use case. I don't think any additional help is needed for this. On the other hand, where help could be useful is specifically in declarative DOM that's imported into a shadow root. Without a way to affect this, we are left to rewrite Here's how I look at it from purely API standpoint. Suppose I have a detached DOM, e.g. loading via XHR or constructed as
At this point:
Next, I import most of this DOM into shadow root on a
Now:
It seems somewhat illogical from API point of view that I'd now have to rewrite anchors and images to still point to So, perhaps, supporting a |
@dvoytenko I think that's a reasonable suggestion. It will require quite a bit of work to make base URL a concept (potentially) bound to elements again and figure out all the edge cases, but in principle that seems doable if the current situation is indeed big enough of a hassle. A related question is whether this is a problem just for base URLs, or whether we also need to do this for language and similar such things. |
URL is the only one I can think off at this time. |
We're closing this. We're only interested in solving this as part of another feature, such as HTML Modules or Custom Element Registries. |
@annevk are there references to exploration of this for other features, e.g. CE registries? |
Are there any workarounds for this besides manually re-writing the URLs in all the elements as mentioned above? |
It'd be very convenient in a number of applications to be able to customize base in shadow root, either via
<base>
tag orbaseURI
property. Shadow root are now used for embeds (e.g. Twitter embed) and it'd be good to have relative URL resolution scoped to shadow root.The text was updated successfully, but these errors were encountered: