Conversation
4aeadf9 to
452680c
Compare
pynecone/components/component.py
Outdated
| """ | ||
| # If it's already an event chain, return it. | ||
| if isinstance(value, Var): | ||
| if isinstance(value, EventChain): |
There was a problem hiding this comment.
I think here the code is correct but the comment is incorrect.
Can we revert the code, but fix the comment to say:
# If it's a var, return it.There was a problem hiding this comment.
Maybe in addition, we need the EventChain check? But we definitely need this current one. What code did you run that raised the ValueError?
There was a problem hiding this comment.
EventChain check is for CustomComponent.
I run the same code from #310.
class State(pc.State):
some_var: bool
def index():
return pc.box(pc.icon(tag="AddIcon", on_click=State.some_var))some_var is passed as a BaseVar, it is a child class of Var, so it is caught at first if statement.
There was a problem hiding this comment.
Can you explain more about why we definitely need the current one when we create EventChain? BaseVar shouldn't be returned in my opinion.
There was a problem hiding this comment.
Ahh I see - you're right this is causing the other bug it looks like. We need this line for the CustomComponent feature that I'm working on (it's not released yet, but it will allow you to create memoized React components for better performance).
But I think in adding that line it caused this other bug. Let me think a bit more on how to resolve this.
Basically for CustomComponent it can take in a Var, but for regular components it should not allow it.
There was a problem hiding this comment.
Maybe we can add a line like
if isinstance(self, CustomComponent):
if isinstance(value, Var):
return valueThen it should fix this bug, but still work for the new feature.
There was a problem hiding this comment.
Ok. Should I change the code as you suggest? or just close this pr and wait for your new feature?
There was a problem hiding this comment.
I just did a quick fix as you suggest. Thanks for the help.
40d634f to
af351c9
Compare
Resolve: #310
Validate EventChain explicitly, so other types will be caught as a ValueError