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

new component element and hot-reloading #74

Closed
jamesdbrock opened this issue Nov 13, 2023 · 4 comments
Closed

new component element and hot-reloading #74

jamesdbrock opened this issue Nov 13, 2023 · 4 comments

Comments

@jamesdbrock
Copy link
Member

The new @component elements don't work with hot reloading.

Encountered exception while reloading: Error while reloading <MyApp id=0x7fffdbac48e0  />: New class expects prop (args) not present in old class
Traceback (most recent call last):
  File "/home/jbrock/work/oth/pyedifice/pyedifice/edifice/app.py", line 157, in event
    render_result = self._render_engine._refresh_by_class(classes)
  File "/home/jbrock/work/oth/pyedifice/pyedifice/edifice/engine.py", line 451, in _refresh_by_class
    raise ValueError(
Stemming from these renders:
ValueError: Error while reloading <MyApp id=0x7fffdbac48e0  />: New class expects prop (args) not present in old class

I think it has something to do with this.

def __init__(self, *args: P.args, **kwargs: P.kwargs):
name_to_val = defaults.copy()
name_to_val.update(filter(not_ignored, zip(varnames, args, strict=False)))
name_to_val.update(((k, v) for (k, v) in kwargs.items() if k[0] != "_"))
name_to_val["children"] = name_to_val.get("children") or []
self._register_props(name_to_val)

@jamesdbrock
Copy link
Member Author

To see hot reloading succeed and fail, check out branch hotreload1 which restores the old example tutorial program.

Hot reloading works:

python -m edifice examples/tutorial.py MyApp

Hot reloading doesn't work:

python -m edifice examples/tutorial_old.py MyApp

@considerate
Copy link
Member

My immediate thought is that this might be related to the children prop

@jamesdbrock
Copy link
Member Author

When hot reloading the new tutorial.py on this line

kwargs = {k: old_comp.props[k] for k, v in parameters[1:]

We have

old_comp.props = PropsDict({'children': []})

and

parameters = [
0: ('self', <Parameter "self">)
1: ('args', <Parameter "*args: P.args">)
2: ('kwargs', <Parameter "**kwargs...P.kwargs">)

So we get Exception has occurred: KeyError 'args'.

When hot reloading the tutorial_old.py on that line

parameters = [('self', <Parameter "self">)]

@jamesdbrock
Copy link
Member Author

jamesdbrock commented Nov 13, 2023

This is the hard part. We must somehow construct a new Element, using the required constructor arguments, which are the kwargs props. It doesn't have to be the right props, because we can just assign the right props on the next line after the Element is constructed. But constructing it is tricky.

parts[3] = new_comp_class(**kwargs)

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

No branches or pull requests

2 participants