How to rotate environment map with mesh synchronously

When I rotate some meshes in scene,I also wanted to apply the same rotation to the environment map.
The code is as follows:

const envMapRotation = new THREE.Euler().setFromQuaternion(
    boxMesh.quaternion.clone()
  )
boxMesh.material.envMapRotation.copy(envMapRotation)
scene.backgroundRotation.copy(envMapRotation)

If you just rotate the x axis or the y axis or the z axis. The result was correct, with the top of the boxmesh pointing toward the sky of the environment map;
But If you rotate multiple axes at the same time,the boxmesh orientation is strange.

Does anyone know how to correctly set the ‘envMapRotation’? Thanks

Try applying the rotation to all the axis in reverse order, i.e. ZYX instead of XYZ. I had to do this to get rotations to look right when I was working on this: