“Though this be madness, yet there is method in ’t.” Polonius’s line to the Danish prince may just as well apply to the Hamnet director Chloé Zhao and her dance-crazed cast and crew.

The Golden Globe-winning film-maker found that dancing along to Rihanna was the best way for her troupe to let off steam between emotional scenes on the film’s Globe Theatre set.

Zhao posted a video to social media of the production crew of Hamnet dancing it out to Rihanna’s 2011 hit We Found Love, many in full 16th-century costume, on the final day of filming at the London theatre.

The Shakespeare-inspired drama, based on Maggie O’Farrell’s novel, is a tearjerker but its stars, Paul Mescal and Jessie Buckley, are seen leading the fun on set. The clip opens with Mescal and Buckley carrying their young co-star Jacobi Jupe on stage and twirling him around in Bacchic fashion as Rihanna blares.

Jessie Buckley, center, as Agnes Hathaway in a scene from "Hamnet."

The performance of Jessie Buckley, centre, as Agnes has been widely praised

APGRZYBOWSKA/FOCUS FEATURES/AP

Jupe plays the titular role alongside his older brother Noah Jupe, who acts out the final scene as the Dane in tribute to Shakespeare’s son Hamnet.

Posting a video on social media, Zhao said that dancing was a form of catharsis for crew and cast. “Some of you have asked me what to do with all the emotions and how my cast and crew release them on set and the answer is: Dance Takes!”

Dry your eyes … what to read after seeing Hamnet

She added: “We want to share moments from our final Dance Take with you, on our last day in the Globe Theatre. It was a release that turned everything we’d been holding into joy, into shared catharsis.”

The video showing Mescal and Buckley twirling around on stage with the cast and crew has gone viral, racking up millions of views.

Chloé Zhao, Emily Watson, Noah Jupe, Paul Mescal, Jacobi Jupe, and Jessie Buckley pose for a portrait.

Left to right: Chloé Zhao, Emily Watson, Noah Jupe, Paul Mescal, Jacobi Jupe and Jessie Buckley

GARETH CATTERMOLE/GETTY

Zhao added: “If it moves you, join us! Dance with us. Share your version with us. However it looks, wherever you are. We can hold together, in community, what is too hard to hold on our own.

“This is why Shakespeare wrote his plays and why he brought people together in the Globe. We hope we made him proud.”