SPOILER ALERT: Do not read if you have not yet watched “Chapter Seventy-Eight,” the 14th episode of the fourth season of “Jane the Virgin.”

Justin Baldoni is no stranger to directing. Before he booked the role of Rafael on the CW’s “Jane the Virgin” he had spent two years focusing primarily on behind the scenes work directing and producing with his company Wayfarer Entertainment. There he has helmed docuseries such as “My Last Days” and he’s even prepping a feature film. But his first behind-the-scenes scripted television credit just came in the fourth season of “Jane the Virgin.”

“[Series creator] Jennie [Snyder Urman] is a wizard and a mastermind, and she knows my history and the work that I’ve done — she knows I gravitate to more emotional things — so I think she had that in mind when she gave me this episode,” Baldoni tells Variety.

Even from the first read of the script, Baldoni knew “Chapter Seventy-Eight” would be a very “important and powerful episode.” In it, Xiomara (Andrea Navedo) — and her whole family by extension — must come to terms with her breast cancer diagnosis. Baldoni has quite the resume of directing projects about real people with cancer — he notes that there have been a few “My Last Days” profilees living with breast cancer specifically — and his aunt also had stage 4 breast cancer but has thankfully “had no evidence of [the disease] for the last 10 years.”

“I was just really grateful that Jennie allowed me to direct an episode like this and bring a little bit of my own perspective and viewpoint into it, especially for my aunt,” he says.

Here, Baldoni breaks down his small screen scripted directorial debut, including cherishing the comedic moments of an otherwise very heavy episode, how he directed himself differently than his castmates, and why he ran this set the same way he would a docuseries.

“Jane the Virgin” episodes are always a mix of comedy and drama, but this one felt a bit heavier than usual. What did you think was most important to do with the tone here?

What I found so refreshing and nice about this particular episode was that all of the storylines were actually connected — which is really rare on our show because there’s so many different things and so many different plot points happening. They were all in some way connected to Xo’s diagnosis, and the moments we weren’t with Xo, it was a chance for the audience to regroup — to take a breath and laugh before we got back into the heavy. There are so many women dealing with this exact same thing, and it’s not funny — you can’t make cancer funny. You have to have a deep reverence for it, and that’s something I was going for as the director. But you can create funny experiences around it, and that laughter can be our medicine. We started with it quickly with Rogelio saying “breast wing” at the dinner table. There’s little ways where it’s almost like relieving the pressure — you’re poking a little hole in it so you can breathe before you dive back into a heavy scene. It’s balanced out with things like Rafael thinking Petra has a crush on Jane.

Jane (Gina Rodriguez) reacting to the mud bath at the spa definitely brought the comedy but it also seemed like a complicated element to add.

The mud bath scene was just so hilarious and fun to shoot because Gina is like a modern day reincarnation of Lucille Ball and the writing speaks for itself. [She and Andrea] sat in that tub for hours between 11 and 2 in the morning on the final night of shooting. They were troopers. And that was what made me so honored to get to work with them because there was not one complaint. And that’s not comfortable! Andrea and Gina just showed up 1000% for me and I just felt the support and the love, and it was just beautiful. I thought one of the more complicated things in this episode, personally, was figuring out how to shoot all of these nude women in the locker room scene without it being distracting to the reason why they’re there. Xo had to see them and realize so much about herself. Being a man, especially at this moment in time, being respectful of the situation was important. But it was not because I’m a man or coming from a man’s perspective. It was, “How do you get the point of [the scene] across in a short time while not taking away from the moment itself?” And also I wanted to make sure I made all of the women feel very comfortable in that situation. So in general, overall, I felt that was much more of a tricky scene for me.

What was your process for those trickier or more emotional scenes?

I love approaching scenes in two different ways. One is how I can create a safe space with my actors for them to experience everything they need to experience for the character. The belief in them as the filmmaker that they can explore freely and creatively without any fear that it won’t work. The first step for me is trying to create on-set love and comfort and just safety, especially when you need to be really emotional. The second thing is figuring out how I can capture the emotions cinematically with the camera. What can the camera be doing at this moment to help the audience understand what this person is feeling? So what’s the camera doing and why? If it’s moving or if it’s just being still, there’s a reason for that. I approached every scene in both of those ways, but we don’t have a lot of time. This is a very challenging show. There’s so many scenes and it moves so fast and our camera moves have to be really poignant and meaningful. It was a really fun challenge. My cast — my friends here — they’re my family, and they really showed up in a way that I was really moved. It makes me emotional even talking about it. I was just so proud of them.

Usually “Jane the Virgin” episodes are from Jane’s perspective, but this episode really allowed the audience to see not only what Xo was going through but also a little bit of the male gaze when Rafael was watching Petra (Yael Grobglas) practicing what she was going to say to J.R. (Rosario Dawson).

What I thought was so funny was being able to see things from Rafael’s perspective and how wrong he was. Something as sweet as a real kind, loving gesture from Petra to Jane can be looked at with [misconception]. It’s not saying that one gender is more right than the other, but I do that all of the time where I overhear something and I think I hear something and that’s all I hear. It was fun to explore that because it’s comedy — that’s all it is — and it takes us away from the cancer for a second and it takes us away from the horror of the reality of what so many women go through.

Do you feel like you directed yourself differently than how you directed your castmates?

I’m notoriously hard on myself anyway, and that’s just something that I’ll just be in therapy about for a very long time, I’m sure. That’s not something that’s going to be cured overnight. But this was my first time directing scripted television and my first time acting at the same time as directing, and I learned a lot. I can tell you that I didn’t give myself as much time as my co-stars because I want them to shine and I was thinking so much about them but not as much about myself, and consequently I didn’t ask for many takes. If there are actors who are going to direct their shows reading this, it’s something that I won’t do next time. I’ll make sure I give myself an equal amount of takes because at the end of the day, it’s better for the show. And I think that can be a trap that those of us who are actors and also directors can fall into, because we think we don’t need anymore — “OK I got it, I don’t need to watch it back, let’s move on” — but no, you should watch it back, it’s better for the show.

What was the compromise like between your own directorial instincts and the things you knew you needed to do — or couldn’t do — in order to make this episode feel like it fit seamlessly with all of the other episodes?

I think it’s important as a director to always try to express what you feel [and] the way you see a scene or the way you see something — but at the same time you always have to remember, when you’re doing TV, this is not my show. This is Jennie Urman’s show, she’s the brilliant woman who created it, and it’s my job to be of service to her vision. So the way I approached it was, “I’m making ‘Jane the Virgin’ but if I can put a little bit of what is in Justin’s heart then I will feel really, really, really good about it.” I just looked for little moments.

What was an example of something you put in that you feel really good about?

There’s a shot that I saw as soon as I read the script — right after Xiomara’s diagnosis where she’s sitting in the car. I wanted to be outside the window, from the corner, and have her gazing out. I wanted to be focused on the reflection of the window and what is happening outside — to have her detached from everything — and then to rack focus on her. Those moments, when they stay in, are really fun because it’s the magic of creation — the magic of being able to see something on the page and make it real.

How similar did your experience directing “Jane the Virgin” end up being to some of the docu-projects you’ve done in the past?

The spirit of the work and the energy and the atmosphere that I want to create is, I would say, identical. I don’t like people arguing or talking over each other. I really try to start every day with love, and as utopian as that sounds, I really believe it translates and allows people to explore. At the end of the day art is really about exploration and being vulnerable, and you need to feel safe to do that. So whether I’m telling the story of someone who’s dying of cancer or telling the story of someone who has cancer in a scripted show, both of them need to feel like they can trust me. They’re giving me something, and in exchange I have to give them something — to be present and vulnerable and be willing to go somewhere with them, wherever they want to go. The emotional through-line is also the same. In a docuseries it’s not called a scene, but wherever I am in shooting, I’m trying to find the truth in that.

The very end of your episode is almost a tag to tip a new mystery to come. How much did you feel you had to know about what was coming to shoot the moment in the right way to set it up?

I knew a little bit of what was coming, and really, there’s not a lot of options for how you can shoot that, so I tried to get as creative as I could. It was one of our last shots on one of our last nights, and I asked them to wet down the street because I feel like rain and the wetness of a street in the dark night helps us feel some danger. Especially when it’s lit a certain way, you know something not good is about to happen. And when we were shooting it, I saw a shadow, and I said, “Let’s start on the shadow!” We just played around and tried to make feet walking as ominous as possible.

“Jane the Virgin” airs Fridays at 9 p.m. on the CW.