Skip to content

on_render: wrapping the hook's result in another component fails when nested #173

Closed

Description

@JuroOravec

Problem

An on_render hook can wrap its own output in another component:

class Inner(Component):
    def on_render(self):
        result, error = yield
        return Frame(body=result)

This works when Inner renders on its own. When Inner is used inside another component's template, turning the page into HTML raises:

RuntimeError: The same rendered component id was encountered more than once during serialization

On interactive pages it fails even when Inner is the outermost component. The on_render docstring and docs/design/component_on_render.md suggest passing the result around like this is supported.

Cause

The hook's result is still marked as Inner's own output. When Frame embeds it, Inner's id appears twice in the tree: once for the new output and once nested inside Frame. _append_frame_parts in serialize.py (about lines 994-1003) compares a child's id only with its immediate parent's, so the nested copy gets the same placeholder key, and the duplicate check in build_frames (serialize.py:709) raises. At the top level the outer copy uses the root key, so only one copy is checked, which is why it works when rendered alone.

Fix direction

Serialization needs to tell the two copies apart (the hook's earlier result versus the component's final output) on both the static and the Vue paths, and decide which component's scoped-CSS marker the embedded content gets.

Workaround

Wrap in the template where the component is used (<c-Frame><c-Inner /></c-Frame>), as /advanced/hooks/ shows.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions