Skip to content
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(utils): Prevent iterating over VueViewModel #8981

Conversation

Duncanxyz
Copy link
Contributor

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).

close #8980

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Duncanxyz thanks for opening this PR! I'm not too happy about including framework-specific edge cases in a general package but I think there's no way around it. Also, we did this before as we can see in the code (and in a nother place for Vue iirc).

I have an important question though: Is there a chance that other objects than VueViewModel might unnecessarily be normalized here? Can other Vue objects have the same _isVue flag? In case yes, maybe it's still fine to normalize them but we should probably change the string to something more generic like "[VueObject]". If this is not possible, let's leave it as is.

Comment on lines +220 to 223

// React's SyntheticEvent thingy
if (isSyntheticEvent(value)) {
return '[SyntheticEvent]';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I guess there's precedence for handling this stuff like this in a general package of ours 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tricky thing is that some people end up just using @sentry/browser even when using a framework like React or Vue.

but I think we should re-examine this in v8 and see if we can somehow inject in framework specific processing.

packages/utils/test/is.test.ts Outdated Show resolved Hide resolved
packages/utils/test/is.test.ts Show resolved Hide resolved
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question: Have you tested this only with Vue 2 or also with Vue 3? I just want to avoid this fix having a negative impact on Vue 3, given that it's the version that's actually supported and not EOL.

@Duncanxyz
Copy link
Contributor Author

Duncanxyz commented Sep 12, 2023

I'm not too happy about including framework-specific edge cases in a general package but I think there's no way around it. Also, we did this before as we can see in the code (and in a nother place for Vue iirc).

I agree, this is not an elegant solution. Perhaps in the future, we can implement it through a plugin approach, where additional handling can be injected when referencing framework-specific packages (e.g., @sentry/vue).

I have an important question though: Is there a chance that other objects than VueViewModel might unnecessarily be normalized here? Can other Vue objects have the same _isVue flag? In case yes, maybe it's still fine to normalize them but we should probably change the string to something more generic like "[VueObject]". If this is not possible, let's leave it as is.

I took the naming reference from @sentry/vue. The _isVue (vue2) and __isVue (vue3) properties are only used to determine if it's a Vue instance, while there are other Vue object type checks like __v_isRef, __v_isReactive, and __v_isVNode. However, the current issue usually occurs only on Vue instance objects.

My experience with naming might not be extensive enough, so do you have any suggestions regarding this?

One more question: Have you tested this only with Vue 2 or also with Vue 3? I just want to avoid this fix having a negative impact on Vue 3, given that it's the version that's actually supported and not EOL.

I have tested both Vue 2 and Vue 3, but the issue only occurs in Vue 2. After your reminder, I finded that Vue 3 had similar issues and handling before (#4743, #5916, #6014), which essentially were caused by accessing illegal properties of the Vue instance during the rendering process, and warning in Vue's DEV mode. I will make changes to the code later to ensure compatibility with both Vue 2 and Vue 3.

Copy link
Member

@Lms24 Lms24 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 explaining!

Perhaps in the future, we can implement it through a plugin approach

Maybe, yes - good idea! But for now, this is fine.

However, the current issue usually occurs only on Vue instance objects.
My experience with naming might not be extensive enough, so do you have any suggestions regarding this?

No, after reading your explanations, I think it's fine to keep it as-is.

I will make changes to the code later to ensure compatibility with both Vue 2 and Vue 3.

So just to confirm before we ✅ , this PR currently fixes an issue that's only present in Vue 2 and Vue 3 is not affected by this PR? Then we're good :)

@Duncanxyz
Copy link
Contributor Author

Duncanxyz commented Sep 12, 2023

#8981 (comment)
I have tested both Vue 2 and Vue 3, but the issue only occurs in Vue 2.

I made a mistake; Vue 3 also has issues, just with different colors 😅. The code I just submitted includes compatibility optimizations for both Vue 2 and Vue 3.

vue2:
vue2

vue3:
vue3

Copy link
Member

@Lms24 Lms24 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 reworking this! I think this looks good for now. In case we run into problems we can always revisit.

Comment on lines +220 to 223

// React's SyntheticEvent thingy
if (isSyntheticEvent(value)) {
return '[SyntheticEvent]';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tricky thing is that some people end up just using @sentry/browser even when using a framework like React or Vue.

but I think we should re-examine this in v8 and see if we can somehow inject in framework specific processing.

@Lms24 Lms24 merged commit 90ee2a4 into getsentry:develop Sep 13, 2023
68 checks passed
Lms24 added a commit that referenced this pull request Sep 13, 2023
@Lms24
Copy link
Member

Lms24 commented Sep 13, 2023

@Duncanxyz this will go out in version 7.69.0 in the next couple of hours. Thanks again!

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.

Warning when console logging Vue ViewModel
3 participants