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

Circular structure bug when referencing the $el in a different variable #78

Closed
pomartel opened this issue Nov 26, 2020 · 8 comments · Fixed by #80
Closed

Circular structure bug when referencing the $el in a different variable #78

pomartel opened this issue Nov 26, 2020 · 8 comments · Fixed by #80
Labels
bug Something isn't working
Milestone

Comments

@pomartel
Copy link

Referencing the $el in another object attribute will cause a bug when the devtool stringifies the object.

var component = function() {
  return(
    {
      msg: 'Hello Alpine.js',
      init() {
        this.div = this.$el 
      }
    }
   )
}

See this page here with the console opened: https://cdpn.io/pomartel/debug/abmbyNg/xJAjOeOZonJk
The Codepen source here: https://codepen.io/pomartel/pen/abmbyNg

@HugoDF HugoDF added the bug Something isn't working label Nov 27, 2020
@HugoDF
Copy link
Collaborator

HugoDF commented Nov 27, 2020

Solution here is probably to try to detect Alpine variables that are DOM Nodes and display "DOM Node" or "HTMLElement" instead of the actual value, a bit like we do for "function"

See the following codepen to detect HTMLElement https://codepen.io/hugodf/pen/OJRJwXJ

@pomartel
Copy link
Author

pomartel commented Dec 3, 2020

Thanks for taking care of this guys. It almost works except when I wrap my $el in a jquery object like this $($el). Sorry if I'm doing funny things with my Alpine setup! 😆

https://codepen.io/pomartel/pen/abmbyNg

@HugoDF
Copy link
Collaborator

HugoDF commented Dec 3, 2020

@pomartel that's cause it's a jQuery instance 😂 I wonder how we can detect that

@pomartel
Copy link
Author

pomartel commented Dec 3, 2020

I wonder if it's going to be possible to manage all the weird situations like this one. Maybe just wrap it in a try catch and display it as an "Unknown Element"?

@HugoDF
Copy link
Collaborator

HugoDF commented Dec 3, 2020

I guess we can do el instanceof jQuery || el instanceof $ but we'll need to check that jQuery or $ exist 🤔

The other way to do it is to try to unfurl the jQuery wrapper property.get && property.get(0) instanceof HTMLElement or property[0] instanceof HTMLElement

@HugoDF
Copy link
Collaborator

HugoDF commented Dec 3, 2020

I wonder if it's going to be possible to manage all the weird situations like this one. Maybe just wrap it in a try catch and display it as an "Unknown Element"?

the problem with this is that I think the error happens on JSON.stringify, so if we try/catch that, none of the components or their state will be communicated to the devtools.

I think we can look at this again if we start sending data more piecemeal (eg. send components, send a component's top-level fields, send field values instead of 1 massive message that has everything in it) which we started looking at in #10

@HugoDF
Copy link
Collaborator

HugoDF commented Dec 3, 2020

@pomartel let's move the discussion to #101 I've got something working that will avoid the crash with jQuery values and with elements inside of arrays/objects (#96 )

@HugoDF
Copy link
Collaborator

HugoDF commented Dec 3, 2020

Here's what the UI looks like btw, should be good enough for now, I get that having the devtools crash is probably the top priority.

Screenshot 2020-12-03 at 15 22 01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants