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

fix rendering issue #442

Merged
merged 2 commits into from
Jul 17, 2023
Merged

fix rendering issue #442

merged 2 commits into from
Jul 17, 2023

Conversation

fscherf
Copy link
Member

@fscherf fscherf commented Jul 13, 2023

This PR fixes a rendering problem in client2 when moving nodes within a tree, and contains a patch to make client errors more readable in log

@fscherf fscherf added the bug Something isn't working label Jul 13, 2023
Previously, a raised `lona.errors.ClientError` was logged two times. Once by
the view runtime, that received the error, and a second time by the general
logging setup of Lona. The first log entry contained the JavaScript traceback,
raised by the browser, the second log entry contained the full Python traceback
from the server side.

    LonaWorker_0                   ERROR    12:39:31.344648 lona.view_runtime client error raised:
    node with id 39 is already cached

    LonaRuntimeWorker_0            ERROR    12:39:31.345355 lona.view_runtime Exception raised while running </home/fscherf/devel/lona/test_project/views/view_types/interactive_view.py.InteractiveView object at 0x7f979c06cc10>
      Traceback (most recent call last):
        File "/home/fscherf/devel/lona/lona/view_runtime.py", line 348, in start
          return_value=self.view.handle_request(self.request),
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/fscherf/devel/lona/test_project/views/view_types/interactive_view.py", line 56, in handle_request
          self.sleep(float(interval.value))
        File "/home/fscherf/devel/lona/lona/view.py", line 344, in sleep
          return self._await_sync(asyncio.sleep(delay, result))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/fscherf/devel/lona/lona/view.py", line 109, in _await_sync
          ).result()
            ^^^^^^^^
        File "/home/fscherf/.pyenv/versions/3.11.4/lib/python3.11/concurrent/futures/_base.py", line 456, in result
          return self.__get_result()
                 ^^^^^^^^^^^^^^^^^^^
        File "/home/fscherf/.pyenv/versions/3.11.4/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
          raise self._exception
        File "/home/fscherf/devel/lona/lona/view.py", line 104, in await_awaitable
          raise cast(StopReason, self._view_runtime.stop_reason)

The second log entry does not contain any meaningful information, and
the Python traceback only contains Lona framework code, never application code.
Thus it only made these errors harder to read.

This patch adds a new rule to `lona.logging.LogFilter` to filter out log
entries containing a `lona.errors.ClientError` traceback.

Signed-off-by: Florian Scherf <mail@florianscherf.de>
Previously, client2 crashed when an already rendered node was moved by
appending or inserting it twice within the same HTML tree.

    moving_node = Div('node 3')

    html = HTML(
        Div(
            'node 1',
            moving_node,
        ),
        Div('node 2'),
    )

    self.show(html)

    html[1].append(moving_node)

    self.show(html)  # resulted in: ERROR  lona.view_runtime  client error raised: node with id 952 is already cached

When a node is moved by adding it twice to the same node tree, internally, it
gets destroyed at the old location, and a new node, with the old id, gets
rendered in the new location.

Previously, the rendering engines node cache got not cleaned after the first
step, so all child nodes of `moving_node`, which is a text node with the text
"node 3" in this case, remained cached.
When the rendering engine attempted to render a new div, identical to the
former removed one, the cache function would raise an error because the old
text node still was cached.

This patch adds a cache cleaning call to the rendering engines `_remove_node`
method and adds a rendering test for moving nodes.

Signed-off-by: Florian Scherf <mail@florianscherf.de>
@fscherf fscherf force-pushed the fscherf/fix-rendering-issue branch from 9eea5e0 to 3cd59e6 Compare July 13, 2023 13:29
Copy link
Contributor

@SmithChart SmithChart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any insight to the Javascript-side, so I am probably not the one to have an opinion on that.
Otherwise. LGTM.

@fscherf
Copy link
Member Author

fscherf commented Jul 17, 2023

@SmithChart: Thanks for having a look anyway!

@fscherf fscherf merged commit e865598 into master Jul 17, 2023
5 checks passed
@fscherf fscherf deleted the fscherf/fix-rendering-issue branch July 17, 2023 12:43
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 this pull request may close these issues.

2 participants