Skip to content

Attaching behaves unexpected, leads to a lost refresh/reload persistence #4751

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

Open
3 tasks done
philipsgithub opened this issue May 15, 2025 · 3 comments
Open
3 tasks done
Labels
analysis Status: Requires team/community input bug Type/scope: A problem that needs fixing ⚪️ minor Priority: Low impact, nice-to-have

Comments

@philipsgithub
Copy link

philipsgithub commented May 15, 2025

First Check

  • I added a very descriptive title here.
  • This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
  • I used the GitHub search to find a similar issue and came up empty.

Example Code

import math
import time
from nicegui import ui

attachable_groups = []
main_group = None
counter = 0
N = 3

with ui.scene().classes('w-full h-64') as scene:
    for i in range(N):
        with scene.group() as group_i:
            attachable_groups.append(group_i)
            scene.box().move((i+1)*2 + i).scale(i+1)
    
    with scene.group() as main_group:
        a = scene.box().move(-2)
        b = scene.box().move(0)
        c = scene.box().move(2)

def attach_new_group():
    global counter, attachable_groups, main_group

    counter +=1
    attachable_groups[counter % N].attach(main_group)

ui.timer(0.1, lambda: main_group.move(y=math.sin(time.time())).rotate(0, 0, time.time()))
ui.button('Attach', on_click=attach_new_group)
ui.run()

Description

I am working a lot with scenes and groups and attaching. and noticed some unexpected behaviors - at least to my current understanding of scenes and attaching.

I tried to create a minimal example of one thing that I discovered.

if i start the app and click the button ´N-1=2´ times, reloading the page leads to nonvisibility of all groups but the 0th one. subsequently if i keep pressing the button the 0th group keeps appearing at alternating locations (without moving when visible)

you have an idea, what might be wrong here (maybe in my code as well)?

NiceGUI Version

2.16.1

Python Version

Python 3.10.12

Browser

Edge

Operating System

Linux

Additional Context

No response

@philipsgithub
Copy link
Author

i just updated my MWE

@falkoschindler
Copy link
Contributor

Thanks for reporting this issue, @philipsgithub!

It looks like the order of the group definitions matters. This break after clicking the button and reloading the page:

with ui.scene() as scene:
    with scene.group() as sub_group:
        scene.sphere().move(x=2)
    with scene.group() as main_group:
        scene.box()

ui.button('Attach', on_click=lambda: sub_group.attach(main_group))

But this works well:

with ui.scene() as scene:
    with scene.group() as main_group:
        scene.box()
    with scene.group() as sub_group:
        scene.sphere().move(x=2)

ui.button('Attach', on_click=lambda: sub_group.attach(main_group))

@falkoschindler falkoschindler added the analysis Status: Requires team/community input label May 15, 2025
@philipsgithub
Copy link
Author

that's a really helpful observation.

I did some tests based on that and I think the behavior can be explained by: if a group is attached to a newer group, they both become invisible when reloading. however, if you keep the app running and attach it again back to the same or an older group and reload, it becomes visible again.

@falkoschindler falkoschindler added ⚪️ minor Priority: Low impact, nice-to-have bug Type/scope: A problem that needs fixing labels May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Status: Requires team/community input bug Type/scope: A problem that needs fixing ⚪️ minor Priority: Low impact, nice-to-have
Projects
None yet
Development

No branches or pull requests

2 participants