CCP 1039     

Art. 1039.  Effect of dismissal of principal action

If an incidental demand has been pleaded prior to motion by plaintiff in the principal action to dismiss the principal action, a subsequent dismissal thereof shall not in any way affect the incidental action, which must be tried and decided independently of the principal action.