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
fix(zone.js): defineProperty patch should not swallow error #37582
Conversation
f77a02b
to
795e34a
Compare
Thanks @JiaLiPassion. It would be great if we can land this PR! It's quite confusing that zone.js currently has the capacity of hiding Object.defineProperty errors that could surface in production.
44e4f32
to
ec39950
Compare
|
FYI I'm removing the merge label and adding back the presubmit label, as it seems there is one test that is consistently failing and doesn't appear to be a flake. @mhevery - Please add back the merge label once you've finished investigating. |
|
There is a CustomElement tests in g3 running on ie11-win7 which fails to bootstrap with this change. Seems like it can't be landed in the current form? Perhaps we can conditionally add the |
|
@mhevery , got it, I will make |
ec39950
to
e199358
Compare
|
FYI, I've started global presubmit to check behavior in Google's codebase. |
a159a52
to
d9a9e44
Compare
|
Thanks for additional updates @JiaLiPassion. I've started a new presubmit and will let you know the results once I have them. |
739880e
to
57891ac
Compare
It's a good question whether this is worth introducing a breaking change. Personally, I'd definitely say yes. Currently ZoneJS modifies native browser behavior. This wouldn't be a big deal at first glance, but it becomes a quite impacting issue IMO if the legacy browser ZoneJS bundle is conditionally loaded (as done in the CLI IIRC). It can then happen that your tests always pass, but once the application runs in production with a non-legacy browser, the application could suddenly break with runtime errors. |
LGTM. Sounds reasonable to make an exception for the registerElement patch.
|
FYI, I've started a new presubmit (+ global presubmit) and will keep this thread updated. |
|
Hi @JiaLiPassion, I'm still in a process of running tests in Google's codebase, but everything looks good so far. Since this is a breaking change, could you please update commit message to include the I've re-requested review from @mhevery once again, since implementation has changed since his last review. Misko, could you please have a look again? Thank you. |
|
FYI, global presubmit went well, @JiaLiPassion plz add the "action: merge" label once commit message is updated and there are no additional changes planned on your side. Thank you. |
|
@AndrewKushnir , thank you so much for the great help! I just updated the commit message to include the |
57891ac
to
bd0b527
Compare
Close angular#37432 zone.js monkey patches the `Object.defineProperty` API long time ago angular/zone.js@383b479 to resolve issues in very old version of Chrome web which override the property of `CustomElements`, and this is not an issue any longer, so we want to remove this monkey patch, since it may swallow the errors when the user want to define property on unconfigurable or frozen object properties. But currently there are several apps and tests depends on this patch, since it also change the `configurable` property to `true` by default, so in this PR we update the logic to not to swallow error any longer unless the property is the callbacks of `document.registerElements`. BREAKING CHANGE: ZoneJS no longer swallows errors produced by `Object.defineProperty` calls. Prior to this change, ZoneJS monkey patched `Object.defineProperty` and if there is an error (such as the property is not configurable or not writable) the patched logic swallowed it and only console.log was produced. This behavior used to hide real errors, so the logic is now updated to trigger original errors (if any). One exception where the patch remains in place is `document.registerElement` (to allow smooth transition for code/polyfills that rely on old behavior in legacy browsers). If your code relies on the old behavior (where errors were not thrown before), you may need to update the logic to handle the errors that are no longer masked by ZoneJS patch.
bd0b527
to
cd760ee
Compare
Since the `defineProperty` not swallow error any longer, now the tests compile
source code in `commonjs` mode, and the code generated includes the code like this
```
Object.defineProperty(exports, "__esModule", {value: true});
```
And the `exports` is undefined in some browsers, but the error is swallowed before
this PR, and all tests run successfully, but it is not correct behavior. After this PR,
the code above failed. So we need to compile the source code in `umd` mode.
cd760ee
to
cfd6217
Compare
Since the `defineProperty` not swallow error any longer, now the tests compile
source code in `commonjs` mode, and the code generated includes the code like this
```
Object.defineProperty(exports, "__esModule", {value: true});
```
And the `exports` is undefined in some browsers, but the error is swallowed before
this PR, and all tests run successfully, but it is not correct behavior. After this PR,
the code above failed. So we need to compile the source code in `umd` mode.
PR Close #37582
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Close #37432
zone.js monkey patches the
Object.definePropertyAPI long time agoangular/zone.js@383b479
to resolve issues in very old version of Chrome web which override the
property of
CustomElements, and this is not an issue any longer, sowe may remove this monkey patch, since it may swallow the errors when the user
want to define property on unconfigurable or frozen object properties.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Since
zone.jsdoesn't patchObject.definePropertyand not swallow the error when trying to define property on unconfigurable orundefinedobject, some application currently not throw error will begin to break.For example, in our
saucelabtest for IE and old firefox/chrome, before this PR, the code/spec are compiled tocommonjs, and the js code will look like this.And the
exportsisundefined, It should throw error that trying to defineProperty onundefined, sincezone.jsmonkey patch theObject.definePropertyand will catch the error and do nothing, so the test cases will continue to work.After this PR,
zone.jswill not do that any more, so the test cases will break.Other information