Skip to content

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

Merged
merged 5 commits into from
Jun 20, 2022

Conversation

Arinono
Copy link
Contributor

@Arinono Arinono commented Jun 17, 2022

Authors

@Arinono

Issue

Fixes #5277

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

@Arinono Arinono force-pushed the fix/5277/vue-options-undefined branch from bb1e3d3 to 9a6df86 Compare June 17, 2022 20:20
@Arinono Arinono marked this pull request as ready for review June 17, 2022 20:48
@lforst lforst self-requested a review June 20, 2022 08:27
Copy link
Contributor

@lforst lforst left a 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', () => {
Copy link
Contributor

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.

Copy link
Contributor Author

@Arinono Arinono Jun 20, 2022

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)

Comment on lines 20 to 23
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;
Copy link
Contributor

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:

Suggested change
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?

Copy link
Contributor Author

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
Screenshot 2022-06-20 at 12 06 00

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 ?

Copy link
Contributor

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!

@Arinono Arinono requested a review from lforst June 20, 2022 11:07
@@ -5,7 +5,7 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["jest"]
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@lforst lforst left a 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!

@lforst lforst changed the title fix(vue): options can be undefined in errorHandler fix(vue): property access on undefined in errorHandler Jun 20, 2022
@lforst lforst merged commit 2870f1d into getsentry:master Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vm.$options is undefined when attaching props from Vue component
2 participants