Hello, this most likely will be a question for the WeWeb team. I have an issue, where the components I’ve created, that rely on the Vue’s onMounted()
method fire twice. Let me explain.
Basically what happens, is that when I drop the element into the canvas, after the latest update, It appears to get created twice. Once for a brief moment, and then it disappears and once is a regular element, that’s being created. When I use ref()
on this component, for example on a video, or a div, to pass to a script/work with later on, I get null, which causes often fatal issues with the program running.
So let’s say I have a video component like this:
<template>
<div>
<div class="brotilities-camera" :style="{ 'aspect-ratio': calculatedRatio }">
<video :class="{ 'user-facing': isUserFacing }" ref="video" muted autoplay playsinline></video>
</div>
</div>
</template>
When I do an onMounted()
like this (simplified for this example)
const video = ref(null);
// Gets the Media Stream
const getMediaStream = async (additionalConstraints = {}) => {
console.log(video.value) // Logging
// Set the src for the <videos>
video.value.srcObject = stream; // Here it is manifested
await new Promise(resolve => {
video.value.onloadedmetadata = resolve; // Here it is manifested
});
};
onMounted(async () => {
console.log(video.value) // Logging
// Initiate the MediaStream and set the videos
mediaStream.value = await getMediaStream();
})
Then I get the following logs.
I tried guarding this with an if(video.value)
, I also tried using nextTick()
but nothing really helps. This is plaguing all of my components that use onMounted to work with refs, effectively costing me a huge amount of money and time without any way of fixing it. I’d like to request some help, because this is not normal Vue behavior (I have the same exact component in Vue and it works).
This wasn’t happening before the latest update, so I’m guessing it’s something new you guys introduced.
Maybe @Alexis or @Kevin you guys could help me shed some light on this? I’m planning to release the camera component, but I already spent like too much time on this, doing workarounds to make this work in WeWeb, but every time, a WeWeb particular thing stops me.