Three.js: How to prevent flickering, which occurs when page restarts. (White flashing)

On my discover flickering occurs when page “off”. Effect act during 1-2ms in canvas. Moreover this problem may occur or not occur in any canvas blocks on page.
I tested more variants of solution this problem: wrote simple version of code, hided HTML until scene rendering, changed background on canvas and parents blocks, but nothing work.

I also tested more simple version with scene from tutorial three.js, but scene also flickering.

Maybe somebody encounter with this problem, give me advice please! ????

Attach video with problem in thread

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>/*Styles*/
import styled from 'styled-components';
export const BlockForModel = styled.div`
width: 1200px;
height: 800px;
opacity: 0;
`
</code>
<code>/*Styles*/ import styled from 'styled-components'; export const BlockForModel = styled.div` width: 1200px; height: 800px; opacity: 0; ` </code>
/*Styles*/
import styled from 'styled-components';

export const BlockForModel = styled.div`
  width: 1200px;
  height: 800px;
  opacity: 0;
`
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>/*React*/
import React, {useEffect, useRef} from 'react';
import PropTypes from 'prop-types';
/*Created components*/
import {CreateScene} from "@ui/functions/tests/InitialTest";
/*Styles*/
import * as S from './styles/styles';
const ModelStandard = () => {
const modelCanvas = useRef(null)
useEffect(() => {
if (modelCanvas.current){
CreateScene(modelCanvas.current)
}
}, )
return (
<S.BlockForModel ref={modelCanvas}></S.BlockForModel>
);
};
export default ModelStandard;
</code>
<code>/*React*/ import React, {useEffect, useRef} from 'react'; import PropTypes from 'prop-types'; /*Created components*/ import {CreateScene} from "@ui/functions/tests/InitialTest"; /*Styles*/ import * as S from './styles/styles'; const ModelStandard = () => { const modelCanvas = useRef(null) useEffect(() => { if (modelCanvas.current){ CreateScene(modelCanvas.current) } }, ) return ( <S.BlockForModel ref={modelCanvas}></S.BlockForModel> ); }; export default ModelStandard; </code>
/*React*/
import React, {useEffect, useRef} from 'react';
import PropTypes from 'prop-types';

/*Created components*/
import {CreateScene} from "@ui/functions/tests/InitialTest";

/*Styles*/
import * as S from './styles/styles';



const ModelStandard = () => {
    const modelCanvas = useRef(null)

    useEffect(() => {
        if (modelCanvas.current){
            CreateScene(modelCanvas.current)
        }
    }, )

    return (
        <S.BlockForModel ref={modelCanvas}></S.BlockForModel>
    );
};

export default ModelStandard;
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import * as THREE from 'three';
export function CreateScene(block){
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, block.offsetWidth / block.offsetHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( block.offsetWidth, block.offsetHeight );
block.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
function animate() {
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
}
block.style.opacity = "100%"
renderer.setAnimationLoop( animate );
}
</code>
<code>import * as THREE from 'three'; export function CreateScene(block){ const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, block.offsetWidth / block.offsetHeight, 0.1, 1000 ); const renderer = new THREE.WebGLRenderer(); renderer.setSize( block.offsetWidth, block.offsetHeight ); block.appendChild( renderer.domElement ); const geometry = new THREE.BoxGeometry( 1, 1, 1 ); const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } ); const cube = new THREE.Mesh( geometry, material ); scene.add( cube ); camera.position.z = 5; function animate() { cube.rotation.x += 0.01; cube.rotation.y += 0.01; renderer.render( scene, camera ); } block.style.opacity = "100%" renderer.setAnimationLoop( animate ); } </code>
import * as THREE from 'three';


export function CreateScene(block){
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera( 75, block.offsetWidth / block.offsetHeight, 0.1, 1000 );

    const renderer = new THREE.WebGLRenderer();
    renderer.setSize( block.offsetWidth, block.offsetHeight );
    block.appendChild( renderer.domElement );

    const geometry = new THREE.BoxGeometry( 1, 1, 1 );
    const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );

    const cube = new THREE.Mesh( geometry, material );
    scene.add( cube );

    camera.position.z = 5;

    function animate() {
        cube.rotation.x += 0.01;
        cube.rotation.y += 0.01;
        renderer.render( scene, camera );
    }

    block.style.opacity = "100%"
    renderer.setAnimationLoop( animate );
}

New contributor

AlexGroz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật