-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(vue): property access on undefined in errorHandler #5279
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(vue): property access on undefined in errorHandler #5279
Conversation
bb1e3d3
to
9a6df86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the contribution! Especially big props for adding tests! I left two suggestions - let me know if you find the time to integrate them into your PR, otherwise we can take over!
const describeSkipNode8 = CURRENT_NODE_VERSION === '8' ? xdescribe : describe; | ||
|
||
describe('attachErrorHandler', () => { | ||
describeSkipNode8('attachProps', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you figure out why these tests were failing for node 8? If yes, we should probably add a comment here why we're skipping these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I have no idea why they are failing. I don't know if it has to do with jest
or the fact that I use @sentry/browser
in my tests.
But since @sentry/browser
(nor @sentry/hub
) tests are not skipped in node 8. And the fact that you already have a bunch of tests using getCurrentHub.withScope
in the hub package tells me that it's probably jest
🤔 (or my code)
packages/vue/src/errorhandler.ts
Outdated
if (options.attachProps && vm && (vm.$options?.propsData || vm.$props)) { | ||
// Vue2 - $options.propsData | ||
// Vue3 - $props | ||
metadata.propsData = vm.$options.propsData || vm.$props; | ||
metadata.propsData = vm.$options?.propsData || vm.$props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your change should work perfectly fine, we (sadly) have to constantly consider bundle size in our SDKs. Optional chains are transpiled to especially large code so I suggest we change it to the following:
if (options.attachProps && vm && (vm.$options?.propsData || vm.$props)) { | |
// Vue2 - $options.propsData | |
// Vue3 - $props | |
metadata.propsData = vm.$options.propsData || vm.$props; | |
metadata.propsData = vm.$options?.propsData || vm.$props; | |
if (options.attachProps && vm && vm.$options) { | |
// Vue2 - $options.propsData | |
// Vue3 - $props | |
metadata.propsData = vm.$options.propsData || vm.$props; |
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional chains are transpiled to especially large code
I had no idea 😅
What do you think?
I'll have to suggest something else as it breaks some tests I wrote
Especially because in your suggestion, the outer condition prevents the attachement of props for vue 3 ($props
will be defined, but won't satisfy the condition)
This one, less compact, works:
if (options.attachProps && vm) {
// Vue2 - $options.propsData
// Vue3 - $props
if (vm.$options && vm.$options.propsData) {
metadata.propsData = vm.$options.propsData;
} else if (vm.$props) {
metadata.propsData = vm.$props;
}
}
Would it work for you ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah you're totally right - my bad. The last snippet you shared works. Thank you!
packages/vue/tsconfig.test.json
Outdated
@@ -5,7 +5,7 @@ | |||
|
|||
"compilerOptions": { | |||
// should include all types from `./tsconfig.json` plus types for all test frameworks used | |||
"types": ["jest"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw that you managed to get the tests working for node 8 - awesome! I think we can remove this again then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I just did it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
Authors
@Arinono
Issue
Fixes #5277
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint
) & (yarn test
).