Skip to content
Esc

noctcore-three/explicit-shadow-map-type

No deprecated PCFSoftShadowMap, named or picked by <Canvas shadows>.

three.js r182 made PCFShadowMap filter softly and deprecated PCFSoftShadowMap for WebGLRenderer (migration guide, 181 to 182: “Use PCFShadowMap which is now soft as well”). From r183 that renderer logs “PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead.” and swaps the type itself. WebGPURenderer kept its own soft filter until r186 (migration guide, 185 to 186), which removed it, warns the same way and marked the constant @deprecated. Code that still asks for the soft type gets a console warning and the other filter.

Incorrect · src/renderer.ts
// rule options: {"threeVersion":182}
import { PCFSoftShadowMap, WebGLRenderer } from 'three';
const renderer = new WebGLRenderer({ antialias: true });
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = PCFSoftShadowMap;
Correct · src/renderer.ts
// rule options: {"threeVersion":182}
import { PCFShadowMap, WebGLRenderer } from 'three';
const renderer = new WebGLRenderer({ antialias: true });
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = PCFShadowMap;

React Three Fiber hides the same choice behind a shorthand. Up to 9.x, <Canvas shadows> sets gl.shadowMap.type = PCFSoftShadowMap, and so do shadows={true} and shadows="soft". The shortest way to turn shadows on therefore asks for the deprecated type. Name the type instead:

Incorrect · src/App.tsx
// rule options: {"threeVersion":186,"fiberVersion":9}
import { Canvas } from '@react-three/fiber';
export const App = () => (
<Canvas shadows>
<Scene />
</Canvas>
);
Correct · src/App.tsx
// rule options: {"threeVersion":186,"fiberVersion":9}
import { Canvas } from '@react-three/fiber';
export const App = () => (
<Canvas shadows="percentage">
<Scene />
</Canvas>
);

From the release that deprecated the type for the renderer the file uses:

  • every use of PCFSoftShadowMap imported from three or three/webgpu (named, renamed, or as THREE.PCFSoftShadowMap through import * as THREE), wherever it is used: an assignment to shadowMap.type, a comparison, the object form <Canvas shadows={{ type: PCFSoftShadowMap }}>;
  • when the project is known to run React Three Fiber below 10, the shadows prop of <Canvas> (imported from @react-three/fiber) written as shadows, shadows={true} or shadows="soft".

Which release that is depends on the renderer, read from the file’s imports:

The file imports Reported from
three/webgpu or three/tsl (the WebGPU build), or one of extraModules (a re-export that may be either build) r186
anything else (three, add-ons, @react-three/*) r182

React Three Fiber 10 (checked at 10.0.0-alpha.6) maps shadows, shadows={true} and shadows="soft" to PCFShadowMap, so there the shorthand is fine and only the constant is reported. Every release up to 9.8.2 maps them to PCFSoftShadowMap.

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.182.0 is r182, 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 a type that release needs;
  3. the installed copy under node_modules, when no manifest declares a range the rule can read (a catalog: or workspace: protocol, a tag such as latest, a URL).

“Below 10” for React Three Fiber is read the other way round, because there an open range must not be taken for its lowest version: the fiberVersion option when set; else the @react-three/fiber range, when every version it allows is below 10 (^9.8.2, >=8 <10); else, for a range that is open upwards (>=9, *) or is not a version range, the installed copy.

Both lookups walk from the linted file’s directory up to the workspace root (the directory with a lockfile or .git). Without a workspace root they stop 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/App.tsx · 2 reports
// rule options: {"threeVersion":186,"fiberVersion":9}
import * as THREE from 'three';
import { Canvas } from '@react-three/fiber';
export const Preview = () => <Canvas shadows="soft" />;
export const Stage = () => <Canvas shadows={{ type: THREE.PCFSoftShadowMap }} />;
Correct · src/App.tsx
// rule options: {"threeVersion":186,"fiberVersion":9}
import * as THREE from 'three';
import { Canvas } from '@react-three/fiber';
export const Preview = () => <Canvas shadows="percentage" />;
export const Stage = () => <Canvas shadows={{ type: THREE.PCFShadowMap }} />;

Without the two options, the verdict depends on package.json files and on node_modules. ESLint’s --cache does not see an edit to either, so after an 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 r182, 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 file that renders through WebGPURenderer without importing three/webgpu or three/tsl itself (the renderer is created elsewhere): it is read as WebGLRenderer code, and reported from r182.
  • <Canvas shadows> when the project is not known to run React Three Fiber below 10: version 10 or later, a range that can reach 10 with no installed copy below it, or no version at all. The constant is still reported there.
  • PCFSoftShadowMap on r182 to r185 in a file that imports three/webgpu, three/tsl or one of extraModules: WebGPURenderer still has its own soft filter on those releases.
  • shadows="basic", shadows="percentage", shadows="variance", shadows={false}, and a value the rule cannot read (shadows={quality.shadows}).
  • A shadows prop on anything that is not React Three Fiber’s Canvas, and a PCFSoftShadowMap that is not three.js’s (a local constant, a property of another object).
  • An import of PCFSoftShadowMap that is never used.
  • A renderer that never sets a type: three.js defaults to PCFShadowMap.
Correct · src/App.tsx
// rule options: {"threeVersion":181,"fiberVersion":9}
import { Canvas } from '@react-three/fiber';
export const App = () => (
<Canvas shadows>
<Scene />
</Canvas>
);
Option Type Default Meaning
threeVersion integer read from disk The three.js revision the project uses (182 for r182, published as 0.182.x). Overrides the version read from package.json and node_modules.
fiberVersion integer read from disk The React Three Fiber major the project uses (9 for 9.x). Overrides what is 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/explicit-shadow-map-type': ['error', { threeVersion: 186, fiberVersion: 9 }]

Set the options when the versions on disk are not the ones that ship: 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 r182 and declares that range in peerDependencies is already left alone: the lowest version of the range decides, and on r181 PCFSoftShadowMap is a filter of its own. Leave the rule off if the console warning does not bother you. It is opt-in because the deprecated type still renders (as PCFShadowMap), so when to rename it is the project’s call.

Checked against three.js r181 (no deprecation), r182 (deprecated for WebGLRenderer), r183, r185 (WebGPURenderer still has its soft filter), r186 (removed there) and r187, and against React Three Fiber 8.18.0, 9.0.0 to 9.8.2, and 10.0.0-alpha.6.