Partial Derivatives of Spherical Angles and Refracted Ray w.r.t Surface u,v

I am reading on "Specular Manifold Sampling" paper with the implementaion(for the simple case) here on Mitsuba at github. As part of the calculation it needs to compute

1. partial derivatives of spherical angles w.r.t surface u, v. which is calculated in this method

Basically given a normalized vector w(x,y,z) and it's partial derivatives dw/du and dw/dv vectors, how do you calculate:

dtheta/du, dtheta/dv , dphi/du , dphi/dv ? (theta and phi are spherical coords of w)

2. partial derivatives of refracted ray w.r.t surface u, v implemented here. ie. Given an incoming ray, surface normal and their partial derivative vectors w.r.t to surface u,v, what are partial derivatives of the refracted ray w.r.t u and v?

I guess it's using chain rule but I don't fully understand the math behind these two.

For example for the first case : dtheta/du = dtheta/dz . dz/du and dtheta/dz comes from derivative of theta = cos^-1(z) w.r.t z. But I don't understand how dphi/du is calculated.