Skip to content

Commit

Permalink
Use startTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamish Williams committed Apr 24, 2022
1 parent 28bb00b commit a330847
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 29 deletions.
4 changes: 2 additions & 2 deletions scripts/generate-sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function addPage(page) {

return ` <url>
<loc>${`${process.env.NEXT_PUBLIC_WEBSITE_URL}${route}`}</loc>
<changefreq>hourly</changefreq>
<changefreq>monthly</changefreq>
</url>`;
}

Expand All @@ -30,7 +30,7 @@ async function addPost(post) {

return ` <url>
<loc>${`${process.env.NEXT_PUBLIC_WEBSITE_URL}${path}`}</loc>
<changefreq>hourly</changefreq>
<changefreq>monthly</changefreq>
</url>`;
}

Expand Down
2 changes: 2 additions & 0 deletions src/components/Carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export const Carousel = ({ width, height, images, placeholder, ...rest }) => {
renderer.current = new WebGLRenderer({
canvas: canvas.current,
antialias: false,
alpha: true,
powerPreference: 'high-performance',
failIfMajorPerformanceCaveat: true,
});
camera.current = new OrthographicCamera(...cameraOptions);
scene.current = new Scene();
Expand Down
17 changes: 13 additions & 4 deletions src/components/Model/Model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { animate, useReducedMotion, useSpring } from 'framer-motion';
import { useInViewport } from 'hooks';
import { createRef, useCallback, useEffect, useRef, useState } from 'react';
import {
createRef,
startTransition,
useCallback,
useEffect,
useRef,
useState,
} from 'react';
import {
AmbientLight,
Color,
Expand Down Expand Up @@ -84,6 +91,7 @@ export const Model = ({
alpha: true,
antialias: false,
powerPreference: 'high-performance',
failIfMajorPerformanceCaveat: true,
});

renderer.current.setPixelRatio(2);
Expand Down Expand Up @@ -380,8 +388,6 @@ const Device = ({
let loadFullResTexture;
let playAnimation;

const image = await resolveSrcFromSrcSet(texture);

const [placeholder, gltf] = await Promise.all([
await textureLoader.current.loadAsync(texture.placeholder.src),
await modelLoader.loadAsync(url),
Expand All @@ -407,6 +413,7 @@ const Device = ({
applyScreenTexture(placeholder, placeholderScreen.current);

loadFullResTexture = async () => {
const image = await resolveSrcFromSrcSet(texture);
const fullSize = await textureLoader.current.loadAsync(image);
await applyScreenTexture(fullSize, node);

Expand Down Expand Up @@ -508,7 +515,9 @@ const Device = ({
}
};

onLoad();
startTransition(() => {
onLoad();
});

return () => {
animation?.stop();
Expand Down
8 changes: 4 additions & 4 deletions src/components/Navbar/navData.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export const navLinks = [
label: 'Details',
pathname: '/#details',
},
{
label: 'Articles',
pathname: '/articles',
},
// {
// label: 'Articles',
// pathname: '/articles',
// },
{
label: 'Contact',
pathname: '/contact',
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from './useAppContext';
export * from './useFormInput';
export * from './useFoucFix';
export * from './useHasMounted';
export * from './useInterval';
export * from './useInViewport';
export * from './useLocalStorage';
export * from './useParallax';
export * from './usePrevious';
export * from './useWindowSize';
export * from './useScrollToHash';
export * from './useFoucFix';
export * from './useHasMounted';
export * from './useWindowSize';
5 changes: 2 additions & 3 deletions src/layouts/Home/DisplacementSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
PerspectiveCamera,
Scene,
SphereBufferGeometry,
UniformsLib,
UniformsUtils,
Vector2,
WebGLRenderer,
Expand Down Expand Up @@ -56,7 +55,9 @@ export const DisplacementSphere = props => {
renderer.current = new WebGLRenderer({
canvas: canvasRef.current,
antialias: false,
alpha: true,
powerPreference: 'high-performance',
failIfMajorPerformanceCaveat: true,
});
renderer.current.setSize(innerWidth, innerHeight);
renderer.current.setPixelRatio(1);
Expand All @@ -70,8 +71,6 @@ export const DisplacementSphere = props => {
material.current = new MeshPhongMaterial();
material.current.onBeforeCompile = shader => {
uniforms.current = UniformsUtils.merge([
UniformsLib['ambient'],
UniformsLib['lights'],
shader.uniforms,
{ time: { type: 'f', value: 0 } },
]);
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ProjectSummary } from 'layouts/Home/ProjectSummary';
import { useEffect, useRef, useState } from 'react';
import styles from './Home.module.css';

const disciplines = ['Developer', 'Prototyper', 'Animator', 'Illustrator', 'Mod maker'];
const disciplines = ['Developer', 'Prototyper', 'Animator', 'Illustrator', 'Modder'];

export const Home = () => {
const [visibleSections, setVisibleSections] = useState([]);
Expand Down
13 changes: 8 additions & 5 deletions src/pages/projects/smart-sparrow/Earth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useInViewport, useWindowSize } from 'hooks';
import {
createContext,
memo,
startTransition,
useCallback,
useContext,
useEffect,
Expand Down Expand Up @@ -193,7 +194,9 @@ export const Earth = ({
renderer.current = new WebGLRenderer({
canvas: canvas.current,
antialias: false,
alpha: true,
powerPreference: 'high-performance',
failIfMajorPerformanceCaveat: true,
});
renderer.current.setPixelRatio(1);
renderer.current.outputEncoding = sRGBEncoding;
Expand Down Expand Up @@ -394,13 +397,13 @@ export const Earth = ({
}
};

setTimeout(() => {
startTransition(() => {
handleLoad();
}, 2000);

setTimeout(() => {
setLoaderVisible(true);
}, 3000);
setTimeout(() => {
setLoaderVisible(true);
}, 1000);
});
}, [loaded, position, scale]);

useEffect(() => {
Expand Down
13 changes: 7 additions & 6 deletions src/pages/projects/volkihar-knight/Armor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { tokens } from 'components/ThemeProvider/theme';
import { Transition } from 'components/Transition';
import { useReducedMotion, useSpring } from 'framer-motion';
import { useInViewport } from 'hooks';
import { useCallback, useEffect, useRef, useState } from 'react';
import { startTransition, useCallback, useEffect, useRef, useState } from 'react';
import {
ACESFilmicToneMapping,
CubeTextureLoader,
Expand Down Expand Up @@ -63,6 +63,7 @@ export const Armor = ({
alpha: true,
antialias: false,
powerPreference: 'high-performance',
failIfMajorPerformanceCaveat: true,
});

renderer.current.setPixelRatio(2);
Expand Down Expand Up @@ -126,13 +127,13 @@ export const Armor = ({
renderFrame();
};

setTimeout(() => {
startTransition(() => {
load();
}, 2000);

setTimeout(() => {
setLoaderVisible(true);
}, 3000);
setTimeout(() => {
setLoaderVisible(true);
}, 1000);
});

const unsubscribeX = rotationX.onChange(value => {
modelGroup.current.rotation.x = value;
Expand Down
1 change: 0 additions & 1 deletion src/utils/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const cleanMaterial = material => {
*/
export const cleanRenderer = renderer => {
renderer.dispose();
renderer.forceContextLoss();
renderer = null;
};

Expand Down

0 comments on commit a330847

Please sign in to comment.