Skip to content

Detached model state on render of unmounted context consumer where context provider value does not change. #847

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

Closed
Archmonger opened this issue Dec 1, 2022 · 10 comments
Labels
priority-1-high Should be resolved ASAP.
Milestone

Comments

@Archmonger
Copy link
Contributor

Archmonger commented Dec 1, 2022

Current Situation

Context should be able to be scoped to conditionally rendered components, and when those subcomponents are removed the deletion of the Context should be handled gracefully.

See: https://github.com/Archmonger/Conreq/blob/d64b3ba879d263b36ab4806d4790d44cefea1045/conreq/_core/components.py#L46-L64

Traceback (most recent call last):
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\django\contrib\staticfiles\handlers.py", line 101, in __call__
    return await self.application(scope, receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\routing.py", line 62, in __call__
    return await application(scope, receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\security\websocket.py", line 37, in __call__
    return await self.application(scope, receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\sessions.py", line 263, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\sessions.py", line 263, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\auth.py", line 185, in __call__
    return await super().__call__(scope, receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\middleware.py", line 24, in __call__
    return await self.inner(scope, receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\routing.py", line 116, in __call__
    return await application(
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\consumer.py", line 94, in app
    return await consumer(scope, receive, send)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\consumer.py", line 62, in __call__
    await await_many_dispatch([receive], self.dispatch)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\utils.py", line 50, in await_many_dispatch
    await dispatch(result)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\consumer.py", line 73, in dispatch
    await handler(message)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\channels\generic\websocket.py", line 238, in websocket_disconnect
    await self.disconnect(message["code"])
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\django_idom\websocket\consumer.py", line 42, in disconnect
    await self._idom_dispatcher_future
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\django_idom\websocket\consumer.py", line 76, in _run_dispatch_loop
    await serve_json_patch(
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\serve.py", line 44, in serve_json_patch
    async with create_task_group() as task_group:
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\serve.py", line 84, in _single_outgoing_loop
    await send(await render_json_patch(layout))
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\serve.py", line 53, in render_json_patch
    return VdomJsonPatch.create_from(await layout.render())
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 153, in render
    result = await self._debug_render()
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 142, in render
    return self._create_layout_update(model_state)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 161, in _create_layout_update
    new_state = _copy_component_model_state(old_state)
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 528, in _copy_component_model_state
    parent: Optional[_ModelState] = old_model_state.parent
  File "C:\Users\Markg\Documents\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 661, in parent
    assert parent is not None, "detached model state"
AssertionError: detached model state

Can be replicated by pulling the latest Conreq branch, and clicking between the any of the "settings" sidebar tabs, then going to a different tab.

Proposed Actions

Determine root cause and fix.

@Archmonger Archmonger added type: bug priority-1-high Should be resolved ASAP. labels Dec 1, 2022
@Archmonger Archmonger added this to the 1.0 milestone Dec 1, 2022
@rmorshea
Copy link
Collaborator

rmorshea commented Dec 1, 2022

I cloned the repo but don't understand how to reproduce. All I see is this when I load up the app:

image

I see no errors when navigating between tabs.

@Archmonger
Copy link
Contributor Author

Wanna hop on a call on Saturday for me to demo?

@rmorshea
Copy link
Collaborator

rmorshea commented Dec 2, 2022

I'm away this weekend unfortunately so will have till next week.

@Archmonger
Copy link
Contributor Author

Archmonger commented Dec 2, 2022

Okay, the issue should specifically happen if you click on the Settings tab (which has a scoped context), then click off of the tab onto something like App Store.

Based on the screenshot it looks like you cloned the wrong branch.

Needs to be the app_store branch, which is the only branch with IDOM integration.

@Archmonger
Copy link
Contributor Author

Let me know if you've been able to replicate this on the app_store branch

@rmorshea
Copy link
Collaborator

rmorshea commented Dec 8, 2022

I've had trouble getting it set up. I can't remember the error I was experiencing at the moment. Can try and post later.

@Archmonger
Copy link
Contributor Author

@rmorshea I can demo today if you are available.

@rmorshea
Copy link
Collaborator

I'll be available at 5:30 Pacific Time.

@rmorshea
Copy link
Collaborator

rmorshea commented Jan 7, 2023

Still need to create a reproducible example, but always rendering the whole tree (as suggested in this comment) seems to fix this problem.

@rmorshea rmorshea mentioned this issue Jan 7, 2023
3 tasks
@rmorshea rmorshea changed the title Exception upon removal of component containing a local Context Detached model state on render of context consumer if unmounted and context value does not change. Jan 8, 2023
@Archmonger
Copy link
Contributor Author

Closed by #870

@rmorshea rmorshea changed the title Detached model state on render of context consumer if unmounted and context value does not change. Detached model state on render of unmounted context consumer and context value does not change. Jan 9, 2023
@rmorshea rmorshea changed the title Detached model state on render of unmounted context consumer and context value does not change. Detached model state on render of unmounted context consumer where context provider value does not change. Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-1-high Should be resolved ASAP.
Projects
None yet
Development

No branches or pull requests

2 participants