[Bug] VtkLocalView: unmounting the view while it fetches arrays throws "Cannot read properties of undefined (reading 'forEach')"
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 66/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, python
Research direction
Start with VtkSyncView.js unmount handling and localview.js beforeDelete() and updateViewState(), then trace the pending progress callback in vtk.js SynchronizableRenderWindow. The report gives a reproducible Python script and browser steps; reproduce the error by hiding the view during a fetch, then verify that completion after unmount produces no error and does not render the deleted window.
Written by the indexing model from the issue text.
Description
Describe the bug
If a VtkLocalView is unmounted (for example by a v_if) while the browser is still fetching the arrays of a scene update, the fetch's completion callback renders the render window the view has already deleted, and the page throws an uncaught error:
TypeError: Cannot read properties of undefined (reading 'forEach')
at t.preRender (trame-vtk.js:3924:691)
at t.render (trame-vtk.js:3924:765)
at Object.<anonymous> (trame-vtk.js:3927:28917)
at Object.u [as invokeProgressDone] (trame-vtk.js:1:27315)
at end (trame-vtk.js:3927:27928)
at async Promise.all (index 0)
Nothing is visibly wrong (the view is gone), but an app that hides a local view while a large scene is still loading gets this uncaught error: for example, when the user switches tabs during an animation over a slow connection.
Versions: trame 4.0.0, trame-vtk 2.11.17 (bundling vue-vtk-js 3.3.5), vtk 9.7.2, Python 3.12. Also seen with trame 3.13.2, trame-vtk 2.11.15, vtk 9.6.2.
To Reproduce
The script below shows 2 million random points in a VtkLocalView inside a v_if. "Update, then hide" sends new points, then hides the view 0.3 s later (HIDE_AFTER), while the browser is still fetching the arrays.
pip install trame trame-vtk vtk, thenpython repro_unmount.py(it opens the page).- Open the browser console.
- Click "Update, then hide". The view disappears; a moment later the console shows the error.
- Click "Show" and repeat: it happens every time.
With HIDE_AFTER = 10 (the fetch completes before the view is hidden) the error does not appear. If the browser fetches the points in under 0.3 s, raise POINTS or lower HIDE_AFTER.
Driven headless with Playwright, 5 rounds each:
| trame / trame-vtk / vtk | HIDE_AFTER = 0.3 |
HIDE_AFTER = 10 |
|---|---|---|
| 4.0.0 / 2.11.17 / 9.7.2 | error in 5 of 5 | no error in 5 |
| 3.13.2 / 2.11.15 / 9.6.2 | error in 5 of 5 | no error in 5 |
Code
"""A VtkLocalView unmounted while it fetches arrays throws in the browser.
pip install trame trame-vtk vtk
python repro_unmount.py
Open the browser console and click "Update, then hide": the server sends the view a new point cloud (tens of MB of arrays), then hides the view while the browser is still fetching them. When the fetch completes, the console shows "TypeError: Cannot read properties of undefined (reading 'forEach')". Click "Show" and repeat.
"""
import asyncio
from trame.app import get_server
from trame.ui.html import DivLayout
from trame.widgets import html
from trame.widgets import vtk as vtk_widgets
from vtkmodules.vtkFiltersSources import vtkPointSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderer,
vtkRenderWindow,
)
POINTS = 2_000_000 # enough arrays that the browser takes a while to fetch them
HIDE_AFTER = 0.3 # seconds: the view is hidden while the fetch is still running
points = vtkPointSource(number_of_points=POINTS) # new random points at each update
mapper = vtkPolyDataMapper(input_connection=points.output_port)
renderer = vtkRenderer()
renderer.AddActor(vtkActor(mapper=mapper))
render_window = vtkRenderWindow(off_screen_rendering=True)
render_window.AddRenderer(renderer)
server = get_server(client_type="vue3")
server.state.show = True
def update_then_hide():
points.Modified()
view.update() # the browser starts fetching the new arrays
asyncio.get_running_loop().call_later(HIDE_AFTER, hide)
def hide():
with server.state:
server.state.show = False # unmounts the view mid-fetch
with DivLayout(server):
html.Button("Update, then hide", click=update_then_hide, disabled=("!show",))
html.Button("Show", click="show = true", disabled=("show",))
with html.Div(v_if=("show",), style="height: 80vh"):
view = vtk_widgets.VtkLocalView(render_window)
if __name__ == "__main__":
server.start()
Expected behavior
Unmounting a local view drops its pending scene updates: nothing is rendered after the view is gone, and no error is thrown.
Cause
The code is vue-vtk-js 3.3.5 (identical to its master) and vtk.js:
localview.jsupdateViewState()callsthis.renderWindow.synchronize(remoteState)and awaits it.- vtk.js's
synchronize()subscribes to the synchronizer context'sonProgressDone; its callback callsrenderWindow.render()once the arrays have arrived. - On unmount,
VtkSyncView.jscallsbeforeDelete(), which deletes the render window but leaves that subscription in place (the context outlives the view). When the fetch completes, the callback renders the deleted window:
vtk.js'sdelete()cleared its model, sopreRender()callsforEachon an undefinedmodel.renderers. The promiseupdateViewState()awaits then never settles.
A possible fix: unsubscribe the pending progress subscription in beforeDelete(), or have synchronize()'s callback skip render() when renderWindow.isDeleted().
Platform:
Device:
- Desktop
- Mobile
OS:
- Windows
- MacOS
- Linux
- Android
- iOS
Browsers Affected:
- Chrome
- Firefox
- Microsoft Edge
- Safari
- Opera
- Brave
- IE 11
Tested in Chromium 156.0.8078.4 (headless, through Playwright 1.64) on Linux, and by hand in Chromium 157.0.8103.50 on Linux, with the app reached through an SSH port forward. Other browsers not tested.
- Dominant language
- HTML
- Stars
- 37
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Kitware/trame-vtk
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Local Rendering not working on paraview >= 5.13May be free again @jourdain claimed this 227 days ago, and no pull request is open. Open
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in Kitware/trame-vtk
Similar issues
-
qa-manually-tested Status: Triage Type: Bug / Error
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
mermaid-js/mermaid-v13#1158 ·
Maintainers usually reply within 1 day
-
Bug Daily
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Expensify/App#107705 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
Changing shipping to country value from storefront homepage creates an invalid URLPossibly taken @Riamus78 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
medusajs/dtc-starter#106 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day