mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
fix: cleanup WebGL resources before reinitializing viewer on model switch
Address CodeRabbit review feedback:
- Call viewer.cleanup() before initializeStandaloneViewer in watcher to prevent
WebGL context leaks on 3D-to-3D model switches
- Add { flush: 'post' } to ensure DOM is ready before initialization
- Assert cleanup is called before reinitialization in test
- Unmount wrappers in all tests to prevent cross-test coupling
This commit is contained in:
@@ -57,13 +57,15 @@ describe('Preview3d', () => {
|
||||
}
|
||||
|
||||
it('initializes the viewer on mount', async () => {
|
||||
await mountPreview3d()
|
||||
const wrapper = await mountPreview3d()
|
||||
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledOnce()
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledWith(
|
||||
expect.any(HTMLElement),
|
||||
'http://localhost/view?filename=model.glb'
|
||||
)
|
||||
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('cleans up the viewer on unmount', async () => {
|
||||
@@ -113,10 +115,13 @@ describe('Preview3d', () => {
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
|
||||
expect(cleanup).toHaveBeenCalledOnce()
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledOnce()
|
||||
expect(initializeStandaloneViewer).toHaveBeenCalledWith(
|
||||
expect.any(HTMLElement),
|
||||
'http://localhost/view?filename=model-b.glb'
|
||||
)
|
||||
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -13,11 +13,16 @@ const containerRef = useTemplateRef('containerRef')
|
||||
|
||||
const viewer = ref(useLoad3dViewer())
|
||||
|
||||
watch([containerRef, () => modelUrl], async () => {
|
||||
if (!containerRef.value || !modelUrl) return
|
||||
watch(
|
||||
[containerRef, () => modelUrl],
|
||||
async () => {
|
||||
if (!containerRef.value || !modelUrl) return
|
||||
|
||||
await viewer.value.initializeStandaloneViewer(containerRef.value, modelUrl)
|
||||
})
|
||||
viewer.value.cleanup()
|
||||
await viewer.value.initializeStandaloneViewer(containerRef.value, modelUrl)
|
||||
},
|
||||
{ flush: 'post' }
|
||||
)
|
||||
|
||||
onUnmounted(() => {
|
||||
viewer.value.cleanup()
|
||||
|
||||
Reference in New Issue
Block a user