@@ -6,7 +6,7 @@ import { DepthDownsamplingPass, EffectComposer as EffectComposerImpl, NormalPass
66
77import { isWebGL2Available } from ' three-stdlib'
88import type { ShallowRef } from ' vue'
9- import { computed , provide , shallowRef , watch , onUnmounted , watchEffect , onMounted } from ' vue'
9+ import { computed , provide , shallowRef , watch , onUnmounted } from ' vue'
1010import { effectComposerInjectionKey } from ' ./injectionKeys'
1111
1212export interface EffectComposerProps {
@@ -56,11 +56,6 @@ const setNormalPass = () => {
5656 }
5757}
5858
59- watchEffect (() => {
60- if (effectComposer .value && sizes .width .value && sizes .height .value )
61- effectComposer .value .setSize (sizes .width .value , sizes .height .value )
62- })
63-
6459const effectComposerParams = computed (() => {
6560 const plainEffectComposer = new EffectComposerImpl ()
6661 const params = {
@@ -88,14 +83,15 @@ const initEffectComposer = () => {
8883 if (! props .disableNormalPass ) setNormalPass ()
8984}
9085
91- let stop = () => { } // defining this prevents error in watcher
86+ watch ([renderer , scene , camera , () => props .disableNormalPass ], () => {
87+ if (! sizes .width .value || ! sizes .height .value ) return
88+ initEffectComposer ()
89+ })
9290
93- stop = watch ( [sizes .height , sizes .width ], () => {
91+ watch (() => [sizes .width . value , sizes .height . value ], ([ width , height ] ) => {
9492 // effect composer should only live once the canvas has a size > 0
95- if (! sizes .height .value && ! sizes .width .value ) return
96-
97- watchEffect (initEffectComposer )
98- stop ?.()
93+ if (! width && ! height ) return
94+ effectComposer .value ? effectComposer .value .setSize (width , height ) : initEffectComposer ()
9995}, {
10096 immediate: true ,
10197})
0 commit comments