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

bug: infinite loop on console error using quasar framework #4506

Closed
bazuka5801 opened this issue Apr 27, 2021 · 15 comments · Fixed by #4507 or #5186
Closed

bug: infinite loop on console error using quasar framework #4506

bazuka5801 opened this issue Apr 27, 2021 · 15 comments · Fixed by #4507 or #5186

Comments

@bazuka5801
Copy link
Contributor

bazuka5801 commented Apr 27, 2021

Bug Report

quasarframework/quasar#9029
Using new capacitor 3 with vue3 we have bad error handling, when in template any error, logger of capacitor3 throw an error (details in quasar issue)

Capacitor Version

npx cap doctor

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 2.4.7
  @capacitor/core: 2.4.7
  @capacitor/android: 2.4.7
  @capacitor/ios: 2.4.7

Installed Dependencies:

  @capacitor/cli: 3.0.0-rc.0
  @capacitor/core: 3.0.0-rc.0
  @capacitor/android: 3.0.0-rc.0
  @capacitor/ios: 3.0.0-rc.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

Android & iOS

Current Behavior

Stack overflow exception

Expected Behavior

Normal error output

Code Reproduction

https://github.com/bazuka5801/quasar-bug-avoid

bazuka5801 added a commit to bazuka5801/capacitor that referenced this issue Apr 27, 2021
@thomasvidas thomasvidas changed the title bug: vue3 support bug: infinite loop on console error using quasar framework Apr 28, 2021
@thomasvidas
Copy link
Contributor

I'm not sure I understand the problem after reading the quasar issue. Is the JSON that is erroring out circular?

@bazuka5801
Copy link
Contributor Author

bazuka5801 commented Apr 28, 2021

@thomasvidas Yes, problem with JSON.stringify method, that can't stop when serialize circular proxy (throwing StackOverflow), I write quick fix, which help me (posted commit + PR).

@bazuka5801
Copy link
Contributor Author

bazuka5801 commented May 2, 2021

Any updates? Up.

@thomasvidas
Copy link
Contributor

We're still aware of the issue, don't worry 😄 we were focused on getting the newest RC out the past several days.

thomasvidas pushed a commit that referenced this issue May 6, 2021
* fix: vue3 support #4506
* fix: additional JSON.stringify lines
* fix: safeStringify method context
@bazuka5801
Copy link
Contributor Author

bazuka5801 commented May 9, 2021

@thomasvidas Please, reopen, bug showing again with new update rc2.
On local machine I try link local package and add check for vue 3 proxy (vue 3 uses proxy in output, and when we serialize message we not check proxy -> in js we only track this when create)
I found few flags for proxy object and tested in local environment without loop -> and it's good point.

I extract vue core code for reactive and use this modification fix

const enum ReactiveFlags {
  SKIP = '__v_skip',
  IS_REACTIVE = '__v_isReactive',
  IS_READONLY = '__v_isReadonly',
  RAW = '__v_raw'
}

interface Target {
  [ReactiveFlags.SKIP]?: boolean
  [ReactiveFlags.IS_REACTIVE]?: boolean
  [ReactiveFlags.IS_READONLY]?: boolean
  [ReactiveFlags.RAW]?: any
}

const isReactive = (value: unknown): boolean => {
  if (isReadonly(value)) {
    return isReactive((value as Target)[ReactiveFlags.RAW])
  }
  return !!(value && (value as Target)[ReactiveFlags.IS_REACTIVE])
}

const isReadonly = (value: unknown): boolean => {
  return !!(value && (value as Target)[ReactiveFlags.IS_READONLY])
}

const isProxy = (value: unknown): boolean => {
  return isReactive(value) || isReadonly(value)
}


const safeStringify = (value: any): string => {
  const seen = new Set()
  return JSON.stringify(value, (_k, v) => {
    if (isProxy(v)) { return "proxy" }
    if (seen.has(v)) { return '...' }
    if (typeof v === 'object') { seen.add(v) }
    return v
  })
}

@thomasvidas
Copy link
Contributor

Can you provide a small Github repo with a reproducible example in a separate issue so we can take a deeper look at it? Since Capacitor also uses proxies in a similar way, I don't think it is a good idea to look for specific flags this way.

@bazuka5801
Copy link
Contributor Author

@thomasvidas reproduction link -> https://github.com/bazuka5801/quasar-bug-avoid
clear example

@bazuka5801
Copy link
Contributor Author

bazuka5801 commented May 11, 2021

@thomasvidas I found bug, when we merged PR, we don't run npm run build on /core folder and changes not applied in new release rc2 for android & ios platforms

@elylucas
Copy link
Contributor

@bazuka5801 could you try RC3 and let us know if it fixes the issue?

@bazuka5801
Copy link
Contributor Author

@elylucas step progress, another infinite message. Now - toJSON method of a serializing instance.

@bazuka5801
Copy link
Contributor Author

bazuka5801 commented May 15, 2021

I deep into debugging, found infinite loop reason (see screenshot)
When I trying call safeStringify(args[24]) (on proxy object) I get log message -> therefore go step safeStringify(args[24])
It's a recursion, and our main goal to fix output this message.
image

@bazuka5801
Copy link
Contributor Author

@elylucas Found a solution with check for proxy (linked pr)

@bazuka5801
Copy link
Contributor Author

@elylucas Please, reopen

@thoasty-dev
Copy link

This is also / still an issue on my end. Debugging in simulator becomes a pain with this error.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 10, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.