First of all, Tatum and Beyoncé had never met—so that moment when she struts onstage to join him was their first meeting ever.
"He's dressed as her, dancing and singing to her song," Casey Patterson, an executive producer on the show, told THR. "We were just hoping he would keep dancing."
The show had been trying to get Beyoncé on for a year. According to Patterson, "She's been the holy grail, and we've always been in contact with her camp. They know when we're gearing up for production." Apparently Chan sent her a video message a few days before the show, and according to Patterson "that's what put it over the top," because Bey finally agreed to an appearance just one night before production.
In the meantime, Chan's wife, Jenna Dewan Tatum, had no idea a Beyoncé cameo was even a possibility. So the total shock you see on her face in the clip is completely genuine.