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

fix($compile): fix (reverse) directive postLink fn execution order #4266

Closed
wants to merge 2 commits into from

Conversation

IgorMinar
Copy link
Contributor

previously the compile/link fns executed in this order controlled via priority:

  • CompilePriorityHigh, CompilePriorityMedium, CompilePriorityLow
  • PreLinkPriorityHigh, PreLinkPriorityMedium, PreLinkPriorityLow
  • link children
  • PostLinkPriorityHigh, PostLinkPriorityMedium, PostLinkPriorityLow

This was changed to:

  • CompilePriorityHigh, CompilePriorityMedium, CompilePriorityLow
  • PreLinkPriorityHigh, PreLinkPriorityMedium, PreLinkPriorityLow
  • link children
  • PostLinkPriorityLow, PostLinkPriorityMedium , PostLinkPriorityHigh

Using this order the child transclusion directive that gets replaced
onto the current element get executed correctly (see issue #3558),
and more generally the order of execution of post linking function
makes more sense. The incorrect order was an oversight that has
gone unnoticed for many suns and moons.

(FYI: postLink functions are the default linking functions)

BREAKING CHANGE: the order of postLink fn is now mirror opposite of
the order in which corresponding preLinking and compile functions
execute.

Very few directives in practice rely on order of postLinking function
(unlike on the order of compile functions), so in the rare case
of this change affecting an existing directive, it might be necessary
to convert it to a preLinking function (look at the diff of this
commit to see how an internal attribute interpolation directive
was adjusted).

Closes #3558

@mary-poppins
Copy link

This looks lovely!

@mhevery
Copy link
Contributor

mhevery commented Oct 3, 2013

LGTM

@btford
Copy link
Contributor

btford commented Oct 3, 2013

👍

@petebacondarwin
Copy link
Contributor

Is this related to or helps with this issue: #3868 ?

@IgorMinar
Copy link
Contributor Author

@petebacondarwin no, that issue is invalid.

previously the compile/link fns executed in this order controlled via priority:

- CompilePriorityHigh, CompilePriorityMedium, CompilePriorityLow
- PreLinkPriorityHigh, PreLinkPriorityMedium, PreLinkPriorityLow
- link children
- PostLinkPriorityHigh, PostLinkPriorityMedium, PostLinkPriorityLow

This was changed to:

- CompilePriorityHigh, CompilePriorityMedium, CompilePriorityLow
- PreLinkPriorityHigh, PreLinkPriorityMedium, PreLinkPriorityLow
- link children
- PostLinkPriorityLow, PostLinkPriorityMedium , PostLinkPriorityHigh

Using this order the child transclusion directive that gets replaced
onto the current element get executed correctly (see issue angular#3558),
and more generally, the order of execution of post linking function
makes more sense. The incorrect order was an oversight that has
gone unnoticed for many suns and moons.

(FYI: postLink functions are the default linking functions)

BREAKING CHANGE: the order of postLink fn is now mirror opposite of
the order in which corresponding preLinking and compile functions
execute.

Very few directives in practice rely on order of postLinking function
(unlike on the order of compile functions), so in the rare case
of this change affecting an existing directive, it might be necessary
to convert it to a preLinking function or give it negative priority
(look at the diff of this commit to see how an internal attribute
interpolation directive was adjusted).

Closes angular#3558
…irectives

Previously we would stop the compilation for both regular and element
transclusion directives which was wrong. Only element transclusion directives
should be terminal.
@IgorMinar
Copy link
Contributor Author

landed as 31f190d

@IgorMinar IgorMinar closed this Oct 4, 2013
mfield pushed a commit to mfield/angular.js that referenced this pull request Nov 8, 2013
Update the $compile docs to mention the change introduced in angular#4266.
petebacondarwin pushed a commit that referenced this pull request Nov 13, 2013
Update the $compile docs to mention the change introduced in #4266.

Closes #4843
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
Update the $compile docs to mention the change introduced in angular#4266.

Closes angular#4843
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
Update the $compile docs to mention the change introduced in angular#4266.

Closes angular#4843
@giovannibonetti
Copy link

Hi, there!
Does the execution order of postLink follow this pattern (reverse of preLink) even in this case here: http://jsfiddle.net/gkbonetti/tY72y/3/
(it involves nesting and multiple priorities)
I expected the parent postLink to be the last function to be executed (in the whole program). Why is it not like that?

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.

Link fn of a replace+transclude directive runs before transclusion takes place
6 participants