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 Vue 3 loop #1145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix Vue 3 loop #1145

wants to merge 1 commit into from

Conversation

b3bb0
Copy link

@b3bb0 b3bb0 commented Oct 3, 2024

Fix loop in vue 3

Description of the change

in Vue 3: when rollbar is triggered by a throw error from inside a helper or the router
(I suspect also some other odd placed) including the vm variable can generate an infinte loop
The (proxy) data included in vm are not really needed for debug purposes

Allso added new. tiny feature to fire on warnings from vue

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • [x ] All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

Fix loop in vue 3
Comment on lines +11 to +22
// In case the error is from the router or am helper
// calling vm could generate a loop and freeze the browser
// rollbar.error(error, { vueComponent: vm, info });

rollbar.error(error, { info });

if (app.config.devtools) console.error(error);
}


app.config.warningHandler = (error, vm, info) => {
rollbar.warning(error, { info });

Choose a reason for hiding this comment

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

I think a more appropriate example is to grab the most relevant and common data off the component, with coalesced fallbacks to empty data.

I also think it's best to stick with the existing format of multiline conditionals. It's a style choice, but the more common one, and since that's how the example was previously styled, I think we should stick to it for consistency across the docs

Suggested change
// In case the error is from the router or am helper
// calling vm could generate a loop and freeze the browser
// rollbar.error(error, { vueComponent: vm, info });
rollbar.error(error, { info });
if (app.config.devtools) console.error(error);
}
app.config.warningHandler = (error, vm, info) => {
rollbar.warning(error, { info });
// In case the error is from the router or a helper
// calling vm could generate a loop and freeze the browser
// Instead, we pick the relevant data off the vm instance
const vueComponent = {
name: vm.$options?.name ?? 'AnonymousComponent',
props: vm.$props ?? {},
data: vm.$data ?? {},
attributes: vm.$attributes ?? {},
route: vm.$route ?? {},
};
rollbar.error(error, { vueComponent, info });
if (app.config.devtools) {
console.error(error);
}
app.config.warningHandler = (error, vm, info) => {
rollbar.warning(error, { vueComponent, info });

app.config.warningHandler = (error, vm, info) => {
rollbar.warning(error, { info });

if (app.config.devtools) console.log('just a warning, but!,error)

Choose a reason for hiding this comment

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

For consistency across the docs, I suggest we keep this to multiline format

Suggested change
if (app.config.devtools) console.log('just a warning, but!,error)
if (app.config.devtools) {
console.log('just a warning, but!, error)
}

@itsalaidbacklife
Copy link

I agree that the docs should be changed. This is a fairly egregious oversight as the introductory docs for vue apps literally tell you to log in a way that will crash your application.

That said I think that this should be renamed and not necessarily considered a resolution to #1126 since it only updates the docs (which we should do), but ideally rollbar should update in such a way as to handle proxy vue 3 components so as not to crash the app if you tried to log a full component. I'm not sure if this is possible, but given what a footgun 'logging your component instance' is, it would be nice if some guard rails could be put in place besides just the example documentation

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.

Rollbar in Vue app causes freeze / 100% CPU usage (inf. recursion)
2 participants