-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R128 - Server Side Rendering issues #21715
Conversation
Hmm, it'll be good to figure out what caused this 🤔 |
@mrdoob Well, it seems that |
@mrdoob Well, I did talk too fast, after further investigation differents errors with the same problem have appeared. It seems that's it might be related to examples now being maybe embedded with three.js? So for example now this line: This PR should fix that issue. I'm trying to automate some SSR tests to prevent this type of issue: I'd be happy to implement it to three repo if we succeed to make a clean test process. Related issue: |
I don't understand how this issue was introduced with It was investigated once to make the core node compatible here #20824 but the suggestion were not implemented due to the related complexity. |
this imo should be avoided, it's a side-effect: const loader = new TextureLoader().setPath( './textures/tiltbrush/' );
const shaders = {
'Light': {
uniforms: {
mainTex: { value: loader.load( 'Light.webp' ) }, there is no benefit here, it just prevents tree shaking and node. shaders is only used in getMaterial in the instance of TiltLoader, it probably would be for the best to do: let shaders = null
function getMaterial( GUID ) {
if (!shaders) {
const loader = new TextureLoader().setPath( './textures/tiltbrush/' )
shaders = { ... }
}
const name = BRUSH_LIST_ARRAY[ GUID ]; there's a very useful article about tree shaking here: https://twitter.com/AndaristRake/status/1384496467994456067 side-effects is the # 1 in that list, and this one is easy to avoid. |
@Mugen87, while what @drcmda is saying is correct, the use of Here is a fix that i've applied to This issue has probably been around since the loader was added, but because all our (pmndrs) libraries use |
I do not yet understand this, sorry. The texture loading in |
So the file const loader = new TextureLoader().setPath( './textures/tiltbrush/' );
const shaders = {
'Light': {
uniforms: {
mainTex: { value: loader.load( 'Light.webp' ) },
alphaTest: { value: 0.067 },
emission_gain: { value: 0.45 },
alpha: { value: 1 },
},
vertexShader: `
precision highp float;
precision highp int;
attribute vec2 uv;
attribute vec4 color;
attribute vec3 position;
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat3 normalMatrix;
uniform vec3 cameraPosition;
varying vec2 vUv;
varying vec3 vColor;
${ common.colors.LinearToSrgb }
${ common.colors.hsv }
void main() {
vUv = uv;
vColor = lookup(color.rgb);
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
}
`,
fragmentShader: `
precision highp float;
precision highp int;
uniform float emission_gain;
uniform sampler2D mainTex;
uniform float alphaTest;
varying vec2 vUv;
varying vec3 vColor;
${ common.colors.BloomColor }
${ common.colors.SrgbToLinear }
void main(){
vec4 col = texture2D(mainTex, vUv);
vec3 color = vColor;
color = BloomColor(color, emission_gain);
color = color * col.rgb;
color = color * col.a;
color = SrgbToLinear(color);
gl_FragColor = vec4(color, 1.0);
}
`,
side: 2,
transparent: true,
depthFunc: 2,
depthWrite: true,
depthTest: false,
blending: 5,
blendDst: 201,
blendDstAlpha: 201,
blendEquation: 100,
blendEquationAlpha: 100,
blendSrc: 201,
blendSrcAlpha: 201,
}
}; are evaluated before the function Edit: link to code in |
additionally to what josh said, the line is executed on the server, and there it fails. this currently affects all SSR solutions: next, gatsby, etc. also testing of course. as for tree shaking, that will also fail as a separate issue, once you start to flat bundle jsm. i think generally it's good practice to keep an eye on side-effects in global or module space - there are only downsides. |
Thanks for the additional details! I've filed a PR based on the suggestions of this thread. |
Closing in favor of #21721. |
No worries, glad we could all help! |
Hello!
Description
With the latest version (r128) I now get this error on an SSR architecture:
This PR fixes the issue by checking if the "document" exists.