Re: [w3c/webcomponents] Allow customizing base of a shadow root (#581)

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 `src` and `href` attributes in images, links, etc - this is error prone and impacts performance negatively.

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 `document.implementation.createHTMLDocument('')` with content:
```
<html>
<head>
<base href="http://foo.com">
</head>
<body>
  <div id="root">
    <img src="/logo.png">
    <a href="/contact">Contact</a>
  </div>
```

At this point:
```
doc.querySelector('a').href == 'http://foo.com/contact'
```

Next, I import most of this DOM into shadow root on a `bar.com` page, for instance like this:
```
var root = doc.getElementById('root');
var importedRoot = document.importNode(root, true);
```

Now:
```
importedRoot.querySelector('a').href == 'http://bar.com/contact'
```

It seems somewhat illogical from API point of view that I'd now have to rewrite anchors and images to still point to `foo.com` even though all the information is there. I realize that this is pretty arguable what should actually happen. But it also seems that there should be an easy way to preserve the base when importing a fragment of a DOM.

So, perhaps, supporting a `base` in shadow root is not the right answer, but the same can be enabled in other APIs, e.g. via `importNode`?


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/581#issuecomment-252691780

Received on Monday, 10 October 2016 17:48:47 UTC