Skip to content
Esc

noctcore-three/no-deprecated-clock

No new Clock() on a three.js release that has deprecated it.

three.js r183 deprecated Clock in favour of Timer (migration guide, 182 to 183). From that release on, every new Clock() logs “Clock: This module has been deprecated. Please use THREE.Timer instead.” to the console, and the class is on its way out of the library.

Timer (in the core since r179) is not a drop-in rename. You call timer.update() once per frame, and getDelta() and getElapsed() then return the same values however often they are read in that frame, where Clock.getDelta() restarts the measurement on every call. A timer can also follow the Page Visibility API (timer.connect(document), then timer.dispose()), so a tab that was in the background does not come back with one huge delta.

Incorrect · src/loop.ts
// rule options: {"threeVersion":183}
import { Clock } from 'three';
const clock = new Clock();
renderer.setAnimationLoop(() => {
mixer.update(clock.getDelta());
renderer.render(scene, camera);
});
Correct · src/loop.ts
// rule options: {"threeVersion":183}
import { Timer } from 'three';
const timer = new Timer();
timer.connect(document);
renderer.setAnimationLoop((time) => {
timer.update(time);
mixer.update(timer.getDelta());
renderer.render(scene, camera);
});

new Clock() and new THREE.Clock(), where Clock is imported from three or three/webgpu (named, renamed, or through import * as THREE), in a project on three.js r183 or later.

The three.js version is read in this order:

  1. the threeVersion option, when set;
  2. the three range in the nearest package.json that declares it. The lowest version the range allows counts: ^0.183.0 is r183, and >=0.170.0 is r170 even when r187 is installed, so a library that still supports an older release is not told to drop an API that release needs;
  3. the installed node_modules/three/package.json, when no manifest declares a range the rule can read (a catalog: or workspace: protocol, a tag such as latest, a URL).

The lookup walks from the linted file’s directory up to the workspace root (the directory with a lockfile or .git). Without a workspace root it stops at the first directory that has a package.json, and with no package.json above the file either nothing is read and the version is unknown.

Incorrect · src/Spin.tsx
// rule options: {"threeVersion":187}
import * as THREE from 'three';
import { useFrame } from '@react-three/fiber';
import { useMemo, useRef } from 'react';
export function Spin() {
const ref = useRef<THREE.Mesh>(null!);
const clock = useMemo(() => new THREE.Clock(), []);
useFrame(() => {
ref.current.rotation.y = clock.getElapsedTime();
});
return <mesh ref={ref} />;
}
Correct · src/Spin.tsx
// rule options: {"threeVersion":187}
import * as THREE from 'three';
import { useFrame } from '@react-three/fiber';
import { useRef } from 'react';
export function Spin() {
const ref = useRef<THREE.Mesh>(null!);
useFrame((state) => {
ref.current.rotation.y = state.clock.elapsedTime;
});
return <mesh ref={ref} />;
}

Without threeVersion, the verdict depends on package.json files and on node_modules. ESLint’s --cache does not see an edit to either, so after a three.js upgrade a cached file keeps its old result until it changes; see rules that read other files.

  • Files that import neither three (or a three/* subpath), three-stdlib, an @react-three/* package nor one of extraModules: the rule only runs in three.js code, so another engine’s API with the same names (a Phaser or Babylon camera) is never read as three.js. Only static import declarations count: a file that loads three.js only through import() or require() is skipped, which can hide a report but never adds one.
  • Any project below r183, and any project whose three.js version cannot be read (no option, no manifest that declares three, no installed copy): an unknown version reports nothing.
  • A clock the code did not construct: React Three Fiber’s state.clock and useThree((state) => state.clock) are built by the library, which is the one to replace them.
  • A Clock that is not three.js’s: one imported from another module, or a local class, also one that shadows the import where it is constructed.
  • A class that extends Clock, and a Clock reached without a static import (require('three')).
Correct · src/loop.ts
// rule options: {"threeVersion":182}
import { Clock } from 'three';
const clock = new Clock();
renderer.setAnimationLoop(() => {
mixer.update(clock.getDelta());
renderer.render(scene, camera);
});
Option Type Default Meaning
threeVersion integer read from disk The three.js revision the project uses (183 for r183, published as 0.183.x). Overrides the version read from package.json and node_modules.
allowIn string[] (globs) [] Files the rule skips, matched against the absolute path and the path relative to the working directory or workspace root.
extraModules string[] [] More module specifiers that mark a file as three.js code (a project module that re-exports three.js, such as @acme/engine); subpaths match too, and their imports count as three.js classes and R3F hooks.
'noctcore-three/no-deprecated-clock': ['error', { threeVersion: 183 }]

Set threeVersion when the version on disk is not the one that ships: a monorepo whose lint runs from a directory with no three in reach, or a range kept wide for other reasons.

A library that supports three.js releases older than r179, where Timer is not in the core, and that declares that range in peerDependencies, is already left alone: the lowest version of the range decides. Leave the rule off if you prefer to move off Clock only when three.js removes it. It is opt-in because a deprecated API still works, so when to migrate is the project’s call.

Checked against three.js r182 (no deprecation), r183 (the release that added it) and r187 (the latest at the time of writing).