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

Implemented a "safe apply" pattern to the event directives. #5402

Closed
wants to merge 1 commit into from
Closed

Implemented a "safe apply" pattern to the event directives. #5402

wants to merge 1 commit into from

Conversation

mike-schenk
Copy link

Should resolve #5401

@IgorMinar
Copy link
Contributor

I'm sorry, but I wasn't able to verify your CLA signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let me know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@caitp
Copy link
Contributor

caitp commented Dec 13, 2013

Make sure your git author email address (git config user.email) matches the email address you sign(ed) the CLA with

When the DOM is modified during a digest cycle it can cause the blur
event to be raised. Change the code to call $apply only if necessary.

Should resolve #5401
@mike-schenk
Copy link
Author

O.K. I had the CLA signed. I'm still getting familiar with GIT and GitHub. Hopefully the latest commit looks right.

@caitp
Copy link
Contributor

caitp commented Dec 13, 2013

In particular it needs to be signed with [email protected] for this patch, which it probably is now. It will probably take a while for the script to run again

@petebacondarwin
Copy link
Contributor

I would really rather not use "safe apply" to fix this. @caitp - you were going to take a look?
In any case it would be great to have a unit test that demos this problem.

@caitp
Copy link
Contributor

caitp commented Dec 16, 2013

It's interesting because (the error thrown in the jsfiddle) doesn't appear to affect FF or IE. I'll poke through it some time this week to see what the underlying cause is, probably tomorrow or Wednesday.

@petebacondarwin
Copy link
Contributor

@caitp
Copy link
Contributor

caitp commented Dec 17, 2013

$timeout is an option, but if we use that in ngEventDirs that's a pretty breaking change which would potentially require changes to a lot of tests ($timeout.flush() everywhere). I haven't looked into the reason why we're hitting that outside of FF yet, though, so it's possible that it's A) not implemented very well in the repro case, or B) some other problem.

@petebacondarwin
Copy link
Contributor

I think that it is only an issue for focus/blur events. So these
should/could be implemented separately from ngEvents

On 17 December 2013 22:39, Caitlin Potter [email protected] wrote:

$timeout is an option, but if we use that in ngEventDirs that's a pretty
breaking change which would potentially require changes to a lot of tests.
I haven't looked into the reason why we're hitting that outside of FF yet,
though, so it's possible that it's A) not implemented very well in the
repro case, or B) some other problem.


Reply to this email directly or view it on GitHubhttps://github.com//pull/5402#issuecomment-30799016
.

@caitp
Copy link
Contributor

caitp commented Dec 17, 2013

well, "$safeApply" would have the advantage of not breaking the API at all, but maybe it's not such a big deal to use $timeout for just those couple events. Still, it seems like it shouldn't be necessary at all, I'm sure there's something wrong happening which could be avoided.

@mike-schenk do you want some help bundling focus/blur into a separate directive "group" similar to the other one, but using $timeout? you'll need to add another line like this to make that work --- Actually I'm wrong, I guess you wouldn't really need that, heh. http://plnkr.co/edit/H05z8Y5nXSFYg0qT3CIP?p=preview working example, see the copy of angular.js around L#17731

It's just a bit unfortunate that it adds a whole bunch of code :(

@ghost ghost assigned IgorMinar Dec 20, 2013
@IgorMinar
Copy link
Contributor

there might be a better way to fix this, please see: #5401 (comment)

@portersi
Copy link

I thought Angular was going to make all applies be safe applies... that's not happening? In some cases where you have multiple levels of callback which may or may not be async, it becomes impossible to tell if you'd be in a $digest or not, and really what's the harm of gracefully handling redundant $apply calls?

@mary-poppins
Copy link

CLA signature verified! Thank you!

Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes).

@btford btford removed the gh: PR label Aug 20, 2014
tbosch added a commit to tbosch/angular.js that referenced this pull request Aug 27, 2014
…$evalAsync`

BREAKING CHANGE:
The `blur` and `focus` event fire synchronously, also during DOM operations
that add/remove elements. This lead to errors as the Angular model was not
in a consistent state.

This change executes the expression of those events now asynchronously.

Fixes angular#4979
Fixes angular#5945
Closes angular#8803
Closes angular#6910
Closes angular#5402
tbosch added a commit to tbosch/angular.js that referenced this pull request Aug 28, 2014
…$evalAsync`

BREAKING CHANGE:
The `blur` and `focus` event fire synchronously, also during DOM operations
that remove elements. This lead to errors as the Angular model was not
in a consistent state. See this [fiddle](http://jsfiddle.net/fq1dq5yb/) for a demo.

This change executes the expression of those events using
`scope.$evalAsync` if an `$apply` is in progress, otherwise
keeps the old behavior.

Fixes angular#4979
Fixes angular#5945
Closes angular#8803
Closes angular#6910
Closes angular#5402
tbosch added a commit to tbosch/angular.js that referenced this pull request Aug 28, 2014
…$evalAsync`

BREAKING CHANGE:
The `blur` and `focus` event fire synchronously, also during DOM operations
that remove elements. This lead to errors as the Angular model was not
in a consistent state. See this [fiddle](http://jsfiddle.net/fq1dq5yb/) for a demo.

This change executes the expression of those events using
`scope.$evalAsync` if an `$apply` is in progress, otherwise
keeps the old behavior.

Fixes angular#4979
Fixes angular#5945
Closes angular#8803
Closes angular#6910
Closes angular#5402
@tbosch tbosch closed this in 719c747 Aug 28, 2014
tbosch added a commit that referenced this pull request Aug 29, 2014
…$evalAsync`

BREAKING CHANGE:
The `blur` and `focus` event fire synchronously, also during DOM operations
that remove elements. This lead to errors as the Angular model was not
in a consistent state. See this [fiddle](http://jsfiddle.net/fq1dq5yb/) for a demo.

This change executes the expression of those events using
`scope.$evalAsync` if an `$apply` is in progress, otherwise
keeps the old behavior.

Fixes #4979
Fixes #5945
Closes #8803
Closes #6910
Closes #5402
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.

nBlur causes "$digest already in progress" when ngRepeat causes the blur event
7 participants