Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix($compile): support transcluding multi-element directives #15555

Merged

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Dec 29, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.

What is the current behavior? (You can also link to an open issue here)
Transcluding multi-element directives (e.g. foo-start/foo-end) is not supported on elements with multi-slot transclusion (a uterdir error is thrown).

What is the new behavior (if this is a feature change)?
Transcluded nodes are put into a DocumentFragment, where they can be traversed via .nextSibling. This way, transcluding multi-element directives on elements with multi-slot transclusion works correctly.

Does this PR introduce a breaking change?
No.

Please check if the PR fulfills these requirements

Other information:
Fixes #15554.

@@ -2480,7 +2480,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {

// We have transclusion slots,
// collect them up, compile them and store their transclusion functions
$template = [];
$template = window.document.createDocumentFragment();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use $window or $document?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other places inside this file use window directly (e.g. here, here and here). Normally, I would prefer $window (or $document). But it doesn't bother me too much here because:

  1. This file is dealing with pretty "low-level" stuff.
  2. Switching to $window would be a breaking change (since every $window or $document mock should then provide the necessary APIs).

@jbedard
Copy link
Contributor

jbedard commented May 4, 2018

@gkalpak what's the status of this? Seems like a reasonable fix...

@gkalpak
Copy link
Member Author

gkalpak commented May 4, 2018

Status: Waiting for approval 😁

@gkalpak gkalpak modified the milestones: Backlog, 1.7.x May 9, 2018
@gkalpak gkalpak self-assigned this May 9, 2018
@petebacondarwin petebacondarwin self-assigned this May 14, 2018
Previously, transcluding multi-element directives (e.g. `foo-start`/`foo-end`)
was not supported on elements with multi-slot transclusion (a `uterdir` error
was thrown).
This commit fixes it by putting the transcluded nodes into a DocumentFragment,
where they can be traversed via `.nextSibling`.

Fixes angular#15554
@gkalpak gkalpak force-pushed the fix-compile-multi-element-transclusion branch from 5a2db25 to f1948e2 Compare May 23, 2018 19:23
@Narretz
Copy link
Contributor

Narretz commented May 25, 2018

LGTM with one question - does this affect performance? Creating a document fragment is more expensive than creating an array. But I assume it's okay since it only happens for slot transclusion.

@gkalpak
Copy link
Member Author

gkalpak commented May 25, 2018

Yes, it olny affects directives with transclusion and yes it should be a little slower (not much though according to my totally inadequate jsperf) and I don't expect it to have any noticeable impact.

@Narretz Narretz merged commit 78b9f61 into angular:master May 26, 2018
@Narretz
Copy link
Contributor

Narretz commented May 26, 2018

We'll find out :D

Narretz pushed a commit that referenced this pull request May 26, 2018
Previously, transcluding multi-element directives (e.g. `foo-start`/`foo-end`)
was not supported on elements with multi-slot transclusion (a `uterdir` error
was thrown).
This commit fixes it by putting the transcluded nodes into a DocumentFragment,
where they can be traversed via `.nextSibling`.

Fixes #15554
Closes #15555
@gkalpak gkalpak deleted the fix-compile-multi-element-transclusion branch May 26, 2018 19:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix($compile): support transcluding multi-element directives
5 participants