Sample
three 0.185.1: Instantiating CanvasTexture defaults colorSpace to NoColorSpace ('') and drops any 10th colorSpace constructor argument, requiring explicit property assignment for sRGB rendering.
Verified sample for npm three 0.185.1: Instantiating CanvasTexture defaults colorSpace to NoColorSpace ('') and drops any 10th colorSpace constructor…
sha256:76e53c188825fc068b8db9d23f2b29d68e28aa2ed5e181712e439cc05858541c
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 3
- Signing keys that built it
- 3
Declared environment
node linux x64 node node npm
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-17 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-09-07 |
Case
HOW- Goal
- Instantiating CanvasTexture defaults colorSpace to NoColorSpace ('') and drops any 10th colorSpace constructor argument, requiring explicit property assignment for sRGB rendering.
- Packages
- Symbols
-
- THREE.CanvasTexture.colorSpace
- Environment
- node
- Created
- 2026-08-17T09:15:09Z
Contract
- CanvasTexture initializes colorSpace to NoColorSpace ('') and silently drops any 10th colorSpace constructor argument because its constructor accepts only 9 parameters.
- Base Texture constructor accepts colorSpace as its 10th argument and initializes colorSpace directly.
- Assigning colorSpace on CanvasTexture mutates the property directly without updating needsUpdate or incrementing texture.version.
- Cloning a CanvasTexture copies the colorSpace setting to the new instance, and toJSON serializes the colorSpace string.
Files
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
Source
# three — CanvasTexture Color Space Management
## Known Solution Search
`search_known_solution` returned hits for `pkg:npm/three@0.185.1` covering `CanvasTexture` lifecycle and `needsUpdate` versioning (`sha256:961598ac78d3b67c9b8b2e7ca83648daa11ea9e976e9ef72e5fd7dc4fdc5a4a4`), `SkinnedMesh.applyBoneTransform`, and `ShaderMaterial`. None addressed `colorSpace` or `THREE.CanvasTexture.colorSpace`.
## Pinned Release
- Package: `three`
- Release: `0.185.1` (npm)
## Observed Behavior
1. **Default Color Space**: `new CanvasTexture(canvas)` initializes `colorSpace` to `THREE.NoColorSpace` (empty string `''`) instead of `THREE.SRGBColorSpace` (`'srgb'`), even though HTML `<canvas>` elements natively produce sRGB color data.
2. **Constructor Parameter Dropping**: The base `Texture` constructor accepts 10 arguments, where the 10th parameter is `colorSpace`. In contrast, `CanvasTexture` declares only 9 constructor parameters (`canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy`) and passes only those 9 parameters to `super()`. Any 10th argument passed to `new CanvasTexture(...)` is silently dropped, leaving `colorSpace` as `''`.
3. **Plain Instance Property**: `colorSpace` is an own property on the instance rather than an accessor property on `Texture.prototype`. Setting `texture.colorSpace = THREE.SRGBColorSpace` directly modifies the string value without automatically setting `needsUpdate = true` or incrementing `texture.version`.
4. **Cloning and Serialization**: Calling `.clone()` on a `CanvasTexture` copies the configured `colorSpace` string to the cloned instance. Serializing with `.toJSON()` preserves the `colorSpace` string in the output object.
5. **Legacy Encoding Removal**: The legacy `texture.encoding` property evaluates to `undefined`, confirming that modern Three.js relies exclusively on `colorSpace`.
## Failure Mode
- **Silent rendering inaccuracies**: Because `CanvasTexture.colorSpace` defaults to `NoColorSpace` (`''`), shaders treat the texture as unmanaged/linear color data. Colors drawn onto the canvas appear washed out or darker when rendered in a standard color-managed scene unless the application explicitly assigns `texture.colorSpace = THREE.SRGBColorSpace` after instantiation.
- **Silent constructor argument failure**: Developers attempting to configure color space via constructor arguments (following the base `Texture` signature) experience a silent failure where the 10th argument is ignored and the texture remains in `NoColorSpace`.
{"case":{"believed":"CanvasTexture defaults colorSpace to SRGBColorSpace or forwards a colorSpace constructor argument like Texture.","caseId":"case:sha256:c6ed52744acc4c3f969641652c7dbe4f412fad9bd85b5002cec5d4ffa4237219","contract":["CanvasTexture initializes colorSpace to NoColorSpace ('') and silently drops any 10th colorSpace constructor argument because its constructor accepts only 9 parameters.","Base Texture constructor accepts colorSpace as its 10th argument and initializes colorSpace directly.","Assigning colorSpace on CanvasTexture mutates the property directly without updating needsUpdate or incrementing texture.version.","Cloning a CanvasTexture copies the colorSpace setting to the new instance, and toJSON serializes the colorSpace string."],"goal":"Instantiating CanvasTexture defaults colorSpace to NoColorSpace ('') and drops any 10th colorSpace constructor argument, requiring explicit property assignment for sRGB rendering.","kind":"HOW","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["THREE.CanvasTexture.colorSpace"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["THREE.CanvasTexture.colorSpace"],"verifierAdapter":"node-typescript@1"}
{
"name": "three-canvastexture-colorspace",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "three-canvastexture-colorspace",
"version": "1.0.0",
"dependencies": {
"three": "0.185.1"
}
},
"node_modules/three": {
"version": "0.185.1",
"resolved": "https://registry.npmjs.org/three/-/three-0.185.1.tgz",
"integrity": "sha512-5aojFCXKwnjBRZvUnt3WFfEcvUJgkN5LlijRFN95hMy8WVkG4I0QNcJE+OuWvuJ0bOdStrbfXn0pkd6/QyiAlg==",
"license": "MIT"
}
}
}
{
"name": "three-canvastexture-colorspace",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"three": "0.185.1"
}
}
import assert from 'node:assert/strict';
import * as THREE from 'three';
// 1. CanvasTexture defaults colorSpace to NoColorSpace ('') rather than SRGBColorSpace ('srgb')
const mockCanvas = { width: 256, height: 256, data: new Uint8Array(4) };
const ctDefault = new THREE.CanvasTexture(mockCanvas);
assert.strictEqual(
ctDefault.colorSpace,
THREE.NoColorSpace,
'CanvasTexture.colorSpace must default to THREE.NoColorSpace'
);
assert.strictEqual(
ctDefault.colorSpace,
'',
'THREE.NoColorSpace is the empty string'
);
assert.notStrictEqual(
ctDefault.colorSpace,
THREE.SRGBColorSpace,
'CanvasTexture.colorSpace does not default to THREE.SRGBColorSpace'
);
// 2. CanvasTexture constructor drops the 10th colorSpace argument, unlike base Texture constructor
const baseTextureWithColorSpace = new THREE.Texture(
mockCanvas,
THREE.UVMapping,
THREE.ClampToEdgeWrapping,
THREE.ClampToEdgeWrapping,
THREE.LinearFilter,
THREE.LinearMipmapLinearFilter,
THREE.RGBAFormat,
THREE.UnsignedByteType,
THREE.Texture.DEFAULT_ANISOTROPY,
THREE.SRGBColorSpace
);
assert.strictEqual(
baseTextureWithColorSpace.colorSpace,
THREE.SRGBColorSpace,
'Base Texture constructor must accept colorSpace as 10th argument'
);
const ctWithConstructorColorSpace = new THREE.CanvasTexture(
mockCanvas,
THREE.UVMapping,
THREE.ClampToEdgeWrapping,
THREE.ClampToEdgeWrapping,
THREE.LinearFilter,
THREE.LinearMipmapLinearFilter,
THREE.RGBAFormat,
THREE.UnsignedByteType,
THREE.Texture.DEFAULT_ANISOTROPY,
THREE.SRGBColorSpace
);
assert.strictEqual(
ctWithConstructorColorSpace.colorSpace,
THREE.NoColorSpace,
'CanvasTexture constructor only accepts 9 parameters and silently drops the 10th colorSpace argument'
);
// 3. colorSpace is an instance data property, so mutating it does not auto-increment version or set needsUpdate
const ct = new THREE.CanvasTexture(mockCanvas);
const initialVersion = ct.version;
assert.strictEqual(
Object.prototype.hasOwnProperty.call(ct, 'colorSpace'),
true,
'colorSpace must exist as an own property on the instance'
);
assert.strictEqual(
Object.getOwnPropertyDescriptor(THREE.Texture.prototype, 'colorSpace'),
undefined,
'colorSpace is not defined on Texture.prototype'
);
ct.colorSpace = THREE.SRGBColorSpace;
assert.strictEqual(
ct.colorSpace,
'srgb',
'Assigning colorSpace property updates the value to "srgb"'
);
assert.strictEqual(
ct.version,
initialVersion,
'Assigning colorSpace must not increment texture version'
);
assert.strictEqual(
ct.needsUpdate,
undefined,
'needsUpdate remains undefined as it is a setter-only property'
);
// 4. Texture cloning copies the colorSpace value
ct.colorSpace = THREE.LinearSRGBColorSpace;
const cloned = ct.clone();
assert.strictEqual(
cloned.colorSpace,
THREE.LinearSRGBColorSpace,
'Cloning a CanvasTexture must preserve the configured colorSpace'
);
// 5. Texture serialization (toJSON) captures colorSpace
const jsonOutput = ct.toJSON();
assert.strictEqual(
jsonOutput.colorSpace,
THREE.LinearSRGBColorSpace,
'toJSON() must include colorSpace in the serialized texture payload'
);
// 6. Legacy encoding property is undefined
assert.strictEqual(
ct.encoding,
undefined,
'CanvasTexture.encoding must be undefined in modern three.js'
);