Skip to content

Fix issues related to set_props() in WebSocket callbacks#3759

Open
CNFeffery wants to merge 11 commits intoplotly:websocket-callbacksfrom
CNFeffery:websocket-callbacks
Open

Fix issues related to set_props() in WebSocket callbacks#3759
CNFeffery wants to merge 11 commits intoplotly:websocket-callbacksfrom
CNFeffery:websocket-callbacks

Conversation

@CNFeffery
Copy link
Copy Markdown
Contributor

@CNFeffery CNFeffery commented Apr 26, 2026

@CNFeffery
Copy link
Copy Markdown
Contributor Author

Based on the functional demonstration results of the local development version Dash, simulate the streaming content output effect similar to large language models:

demo

Core callback function code:

@app.callback(
    Input("load-stream-content", "nClicks"),
    websocket=True,
    running=[[Output("load-stream-content", "loading"), True, False]],
)
async def load_stream_content(nClicks):

    for s in test_markdown:
        await asyncio.sleep(0.02)

        p = Patch()
        p += s

        set_props("markdown-content", {"markdownStr": p})

@CNFeffery CNFeffery changed the title Fix the issue where Patch objects cannot be updated via set_props() in WebSocket callbacks Fix issues related to set_props() in WebSocket callbacks Apr 27, 2026
Comment thread dash/_callback_context.py Outdated
Comment on lines +375 to +376
if isinstance(value, Patch) or hasattr(value, "to_plotly_json"):
value = json.loads(to_json(value))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To get the full compatibility, it should to_json without condition, this ensure we can get all the supported prop types.
But then this extra loads might be expansive when serializing big object. Maybe instead of _send_json we have _send_plotly_json implemented in base that calls a regular _send(value: str).

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

Successfully merging this pull request may close these issues.

2 participants