customizer refresh breaks with this code but I don’t understand why

The menu argument is used to output a particular menu item to a particular location in the theme.

Suppose you created and a menu in the Dashboard and want it to load in the main navigation bar without setting it in the ‘Manage Locations’ tab in the Dashboard. In that case, you will enter the menu ID/name/slug/object in the menu argument of wp_nav_menu. Check out the codex –
https://developer.wordpress.org/reference/functions/wp_nav_menu/

The theme_location will be ignored in this case.

Regarding your issue, you have entered ‘primary’ in the menu argument. You need to verify if any of the menus you created have ‘primary’ as slug or name.