Component with 3D/Threejs canvas tag always rendering last


Noob question about loading…

I am loading a component with a gltf model and it always renders the canvas tag last. I can put other content inside the component that will render in the right order, but the canvas tag always renders last.

I suspect I just need to use a wait type of command, but I am not finding any examples that I can lean on.

Can someone point me in the right direction for forcing my model component to load and canvas tag render before loading the rest of the page?

Thanks in advance!

Might help to provide some code examples. The way you stated it sounds like this is a react rendering issue. How is the data being added to the canvas? Thee way you described it sounds like you component runs the first render and then it does an update to draw the canvas and add it to the DOM.

import * as THREE from 'three'

import { MetaTags } from '@redwoodjs/web'

const Threejsmodel = () => {
  var SW = window.innerWidth,
    SH = window.innerHeight
  var scene = new THREE.Scene()

  var camera = new THREE.PerspectiveCamera(75, SW / SH, 0.1, 1000) // fov, aspect, near/far clip planes
  var renderer = new THREE.WebGLRenderer()

  renderer.setSize(SW, SH)

  var geometry = new THREE.BoxGeometry(1, 1, 1)
  var material = new THREE.MeshLambertMaterial({ color: 0x00ff00 })
  var cube = new THREE.Mesh(geometry, material)
  camera.position.z = 5

  var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5)
  directionalLight.position.set(0, 0, 5)

  function render() {
    renderer.render(scene, camera)
    cube.rotation.x += 0.005
    cube.rotation.y += 0.005

  return null

const HomePage = () => {
  return (
      <MetaTags title="Home" description="Home page" />
        This is the main section
          <div id="above"> this is above the model</div>
            <Threejsmodel />
          <div id="below"> this is below below</div>

export default HomePage