Skip to content

Conversation

@falkoschindler
Copy link
Contributor

@falkoschindler falkoschindler commented Nov 8, 2025

Motivation

Inspired by discussion #5201, I asked myself (and Sonnet 4.5) what it takes to share NiceGUI pages.

Implementation

A core idea is that we don't need to immediately evaluate the page function, but we can wait until it is visited for the first time. Instead of re-creating a new client on every visit, we store it and re-use it for subsequent visits. To avoid cyclic references (bad for reference counting), we use a weak reference. The resulting implementation is rather simple.

At the moment this is only an experiment.

Example usage:

@ui.page('/', shared=True)
def page():
    ui.label(f'The time is {time.time()}')
    ui.input('Enter your name').on('keydown.enter', lambda e: ui.label(f'Hello, {e.sender.value}!'))
    ui.button('Notify', on_click=lambda: ui.notify('Hello, world!'))

Progress

  • I chose a meaningful title that completes the sentence: "If applied, this PR will..."
  • The implementation is complete.
  • Pytests have been added (or are not necessary).
  • Documentation has been added (or is not necessary).

@falkoschindler falkoschindler added feature Type/scope: New feature or enhancement analysis Status: Requires team/community input labels Nov 8, 2025
(cherry picked from commit 1fe5acf)
@rodja
Copy link
Member

rodja commented Nov 9, 2025

Interesting! But it will re-introduce some of the strangeness which we encountered with auto-index client:

  1. all visitors have the request object of the first visitor (and therefore also the same client.ip)
  2. client cleanup (eg. pruning) requires special attention
  3. what about ui.download?
  4. will app.storage.tab work?
  5. how to handle returns of await ui.run_javascript? Will there be multiple return values?

@evnchn
Copy link
Collaborator

evnchn commented Nov 9, 2025

By principle, one-to-one actions will not work when the Python<->Browser relationship is one-to-many.

I foresee we need to state very clearly that when shared=True stuff may break and that is just an inherent limitation, and possibly for the user's sake we may need to add back the checks we dropped in #5005.

Nevertheless I think this PR is good. Second-class support is better than no support, I guess. I'll never look back for my code, though.

@falkoschindler falkoschindler added this to the 3.x milestone Nov 19, 2025
@falkoschindler falkoschindler added in progress Status: Someone is working on it and removed analysis Status: Requires team/community input labels Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Type/scope: New feature or enhancement in progress Status: Someone is working on it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants