Visitar URL original
fix(zone.js): onbeforeunload should check return value by JiaLiPassion · Pull Request #49597 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20250805095719/https://github.com/angular/angular/pull/49597
Skip to content

fix(zone.js): onbeforeunload should check return value #49597

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

Closed
wants to merge 1 commit into from

Conversation

JiaLiPassion
Copy link
Contributor

Close #47579

onbeforeunload handler return value is used to show confirm or not.

window.onbeforeunload = function (e) {
  return 'something';
}

But

window.addEventListener('beforeunload', function() {
  return 'something';
});

Doesn't work.

And currently, zone.js patch all onProperty such as onbeforeunload to addEventListener call, so onbeforeunload not working.

So this PR revert the original behavior for onbeforeunload event.

@JiaLiPassion JiaLiPassion added area: zones Issues related to zone.js target: minor This PR is targeted for the next minor release labels Mar 26, 2023
@ngbot ngbot bot added this to the Backlog milestone Mar 26, 2023
Close angular#47579

onbeforeunload handler return value is used to show confirm or not.

```
window.onbeforeunload = function (e) {
  return 'something';
}
```

But

```
window.addEventListener('beforeunload', function() {
  return 'something';
});
```
Doesn't work.

And currently, zone.js patch all `onProperty` such as `onbeforeunload`
to `addEventListener` call, so `onbeforeunload` not working.
We need to set `e.returnValue` in addEventListener to make it work.

So this PR check if the event is beforeunload, we set the event.returnValue
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release and removed target: minor This PR is targeted for the next minor release labels Dec 14, 2023
@alan-agius4 alan-agius4 removed the request for review from AndrewKushnir December 14, 2023 14:20
@alan-agius4 alan-agius4 added the action: global presubmit The PR is in need of a google3 global presubmit label Dec 14, 2023
@alan-agius4
Copy link
Contributor

TGP

@alan-agius4 alan-agius4 self-assigned this Dec 14, 2023
@alan-agius4
Copy link
Contributor

alan-agius4 commented Dec 14, 2023 •

TGP deflake

@alan-agius4
Copy link
Contributor

alan-agius4 commented Dec 14, 2023 •

This change also looks like it breaks a large number of targets in G3
http://test/OCL:590917899:BASE:591161730:1702626362453:ee39f92b

@alan-agius4 alan-agius4 removed their assignment Dec 14, 2023
@alan-agius4 alan-agius4 added state: blocked and removed action: global presubmit The PR is in need of a google3 global presubmit labels Dec 14, 2023
@aparzi
Copy link
Contributor

aparzi commented Jan 24, 2024

Please it is possible accepted this PR. Thanks

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: zones Issues related to zone.js state: blocked target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

beforeunload return value is not respected
4 participants