Skip to content

Commit

Permalink
feat: adding warning when canvas parent height is 0px
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Mar 28, 2023
1 parent 8b2bbb3 commit 4224103
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/composables/useRenderer/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { watch, watchEffect } from 'vue'
/* eslint-disable max-len */
import { watch, ref, shallowRef, computed, toRefs } from 'vue'
import {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4224103

Please sign in to comment.