Переглянути джерело

feat: adding warning when canvas parent height is 0px

alvarosabu 2 роки тому
батько
коміт
42241036f0
1 змінених файлів з 7 додано та 1 видалено
  1. 7 1
      src/composables/useRenderer/index.ts

+ 7 - 1
src/composables/useRenderer/index.ts

@@ -1,3 +1,4 @@
+import { watch, watchEffect } from 'vue'
 /* eslint-disable max-len */
 import { watch, ref, shallowRef, computed, toRefs } from 'vue'
 import {
@@ -152,11 +153,16 @@ export function useRenderer(canvas: MaybeElementRef, container: MaybeElementRef,
   const { setState } = useTres()
 
   const { width, height } = resolveUnref(windowSize) ? useWindowSize() : useElementSize(container)
-  const { logError } = useLogger()
+  const { logError, logWarning } = useLogger()
   const { pixelRatio } = useDevicePixelRatio()
   const { pause, resume } = useRenderLoop()
   const aspectRatio = computed(() => width.value / height.value)
 
+  if (!resolveUnref(windowSize) && container?.value?.offsetHeight === 0) {
+    logWarning(`Oops... Seems like your canvas height is currently 0px, by default it takes the height of it's parent, so make sure it has some height with CSS.
+You could set windowSize=true to force the canvas to be the size of the window.`)
+  }
+
   const updateRendererSize = () => {
     if (!renderer.value) {
       return