Shōgun’s Anna Sawai Felt Freest in Lady Mariko’s Final Decision
ByNicholas Quah,
a Vulture critic who covers podcasts, television, and pop culture
“Up until then I had to hold it all in.”
Photo: Copyright 2024, FX. All Rights Reserved.
This interview was published on April 17, 2024. Shōgun has since received 25 nominations for the 2024 Emmy Awards, including an Outstanding Lead Actress nod for Anna Sawai. Read all of Vulture’s Emmy-racecoverage here.
In a show where men wage war for a reason but “a woman is simply at war,” Lady Toda Mariko’s struggles stand apart. Torn between loyalty to her family, whose memory she desires to honor, and her husband, Buntaro, who denies her the chance, Shōgun’s resident translator, as portrayed by the preternaturally composed Anna Sawai, eventually finds herself central to Lord Yoshii Toranaga’s (Hiroyuki Sanada) grand plot to survive the political intrigue of Sengoku-period Japan. But as the deathly stakes escalate, her Catholic faith, fealty to Toranaga, and growing feelings for John Blackthorne (Cosmo Jarvis) force her into an impossible position, one she ultimately uses to her advantage as the many threats close in.
In penultimate episode “Crimson Sky,” Mariko must navigate her responsibility to Toranaga alongside the rules of Osaka castle set by Lord Ishido (Takehiro Hira), Toranaga’s archrival, when he holds the Council of Regents and other noble families hostage under the pretense of a threat against the heir’s life. In a succession of breathtaking sequences, Mariko weaponizes those clashing codes of honor to undermine Ishido’s position, first sacrificing her retinue and fruitlessly trying to fight off the castle guardsin order to draw out evidence of everyone’s captivity. Having failed, but identifying the possibility of disgracing Ishido, she forces his hand by threatening seppuku. The gambit seems to work — until Ishido retaliates by bringing ninjas into the compound to capture Mariko. In a tragic, poetic moment, she commits to her role in Toranaga’s plan, sacrificing herself in an explosion meant to bust open the room they were holed up in, resolving her many tensions with an act that would finally bring her and her disgraced family honor.
“Mariko is not precious about her life,” Sawai, who’s been on a tear of late with impressive performances in Pachinko and Monarch: The Legacy of Monsters, tells Vulture. “She does truly believe death can be a greater cause. You can live a long life and not make much meaning of it, right? Or you can die early and still have a big impact.”
Lady Mariko covers the door in an act of sacrifice, which seems to come after a moment of realization. Walk me through that sequence. After the seppuku scene, when Ishido gives her permission to leave, she feels like she has fulfilled her duty to her lord. But once she realizes she wouldn’t be able to leave, she’s again unable to fulfill that duty. Now, there’s no question: She needs to make a statement against what Ishido is doing. She wants to make it clear that what’s happening is not right. So when she realizes they’re going to blow the place open and capture everybody, she runs toward the door because that’s everything she needs to do. She wants to serve her lord. She wants to finish her father’s fight. It’s also just what she wants.
It’s a striking culmination of events, too. Earlier, she has that great scene in the courtyard where she’s forcing Ishido to act and daring his men to commit violence. It’s brutal, because so many of her guards end up getting killed. She doesn’t believe she’s actually going to die in that situation, and the point is not to kill the men. It’s to prove everyone has been taken hostage. I think she realizes that they have to force her to stop. She’s not for violence, but to prove the point, violence has to happen. What makes it so heavy is that so many people have to die.
Mariko starts out the series a little aimless, like she’s drifting through her existence. How would you describe the arc she goes through over the course of Shōgun? There’s so much evolution. When we first meet her, she’s there because she has to be there. Later, we come to understand that even though she wants to kill herself, her husband won’t let her. Once she’s given the task of translator, it gives her more meaning. Now she’s needed.
When Buntaro supposedly dies, we see her come to life a bit. I love episode four because she becomes more free and colorful. She doesn’t feel tied down. She’s more interesting in some ways. But when he comes back, she shuts down. She doesn’t want to be there anymore. He’s accusing her of things, and she’s very much lost again. That’s why she asks for permission to take her own life. It’s a very dark time for her; she believes her lord is going to give up, but she can’t do anything about it because she’s not the type to say, “No, you have to fight.” At the end of episode eight, when everyone is grieving the loss of Hiromatsu, it’s revealed to her that this was the plan all along. Hiromatsu sacrificed his life to serve his lord, and Toranaga-sama tells her it’s now her turn to play the role. That’s when she finds clarity and purpose. She knows her duty.
In this episode, it’s her performing all of it. It’s so beautiful because we get to see so many different sides of her. When she’s speaking to Ochiba, we see a softer side. She misses her friend, and she wants her to accept what she’s about to do. When she confronts Ishido and his men, we see her being outspoken and powerful. And in the seppuku scene and the action of her sacrificing herself to send a message, that’s her more quiet, core power. That episode was so liberating to shoot, because up until then I had to hold it all in.
Mariko’s relationship to Christianity is fascinating. In the opening of this episode, we see the origins of her faith, when Father Martin Alvito comes in at a low time in her life. It tracks as a little opportunistic, yet it still gives her a kind of peace and power. It could’ve been anyone who simply showed her that they cared. At that moment, she was on the verge of dying and she didn’t have anything. She was drawn to the faith for the belief, not for the politics or the money. It’s about having the meaning to keep going; it’s not important to her that the priests get land and are able to build a church. When something saves you, you stick with it. That’s why she holds it closely to her heart.
At the same time, she’s a samurai. She serves her lord. But taking your life has a different meaning when you’re a Catholic than when you’re a samurai. That seppuku scene is very interesting because she did ask Kiyama-sama to second her. But on the day, he’s not there, and the person who does come to second her is Blackthorne, who is a Protestant and therefore not allowed to kill in that way. But he steps in because he cares that much about her. It’s such a beautiful scene because of all the sacrifices everyone is making.
What do you think draws Mariko to Blackthorne? In Japanese culture, you have three hearts: The first is for the public to see, the second is for your close friends and family, and the third is just for you. With Blackthorne, she doesn’t have to show him any respect. She doesn’t really care what he thinks, and because of that, she’s showing her second heart to him.
Yet, he is so understanding. He’s like, “Show me more. Why are you showing a surface-level face to your husband? I want to know what you want.” That allows her to become very vulnerable with him, and the fact she’s being accepted for who she is, that’s very refreshing.
They also get to debate. I get the sense he’s the rare person she gets to have real philosophical conversations with. They differ on the nature of freedom, for example: She finds it in ritual and roles; he wants to be on a boat and sail the high seas. Listening to you say that, I was thinking: Yeah, well, opposites attract. It’s fascinating to her that he’s so, so different.
Where do you personally come down on the definition of freedom? Oh my gosh. That’s a really good question. Even while we were doing those scenes, I was questioning what it was. After first reading the line when Mariko says, “If freedom is all you ever live for, you’ll never be free of yourself,” I was like, gasp. That’s going way too deep! Honestly, I don’t know what freedom is. Maybe we’re not free at all living in this world. I don’t have an answer for that.
How’s working with Cosmo Jarvis as a screen partner? I’m a big fan of his yelling. I don’t think I’ve ever met an actor who’s so devoted and dedicated. He went full out. I learned so much watching him walk on set and already be Blackthorne. After talking to him once we wrapped, I was like, “This is not the Cosmo I know.” He seems so much softer now. I know he says that he’s not Method, and I will respect him for saying that, but I think he doesn’t even realize he’s becoming the character at times. It was a special experience getting to share all those months with him.
He had very specific thoughts on some lines. To me, it was like, “Well, it could be this, it could be that.” And he’s like, “No, it has to be this. It doesn’t make sense!” I loved working with him. He truly blew my mind.
I’ve heard actors can sometimes subconsciously ingest qualities of a character they’ve played for a while. Do you have a sense if you’re taking anything from Mariko with you? When I watch interviews I did while we were shooting, I feel like my whole energy is different. It’s a bit weird. [Laughs] It’s not even that I’m speaking like Mariko or anything. It’s just not me. I don’t know what was going on. Maybe I was trying so hard to remove myself from the character that things went a different direction.
What were the biggest things you learned working on this show? There were a lot of smaller things. I didn’t know much about jidaegeki [Japanese period dramas set before the Meiji restoration], and now I feel more comfortable if they ask me to wear a kimono. I can walk in them properly now. Those kinds of things.
But working with the creatives on this show — Justin Marks, Rachel Kondo, Hiroyuki Sanada, Eriko Miyagawa — really changed it all. They were so trusting of each other. They delegated to the Japanese people when necessary. They were able to say, “This is my baby, but if it’s going to serve the project because the Japanese have to do things or speak in this way, then we do it.” Everyone was so respectful, which doesn’t happen all the time. It turned out to be the best and most authentic version of it. If there’s anything big I’m taking away from Shōgun, it’s that you have to really work with the right people.
I noticed you used the phrase “defer to the Japanese people.” May I ask if you see yourself as Japanese? Oh, I’m completely Japanese. Both my parents are fully Japanese. I think the only reason people aren’t sure about it is because I was born in New Zealand. I was there for two years, then I moved around: I was in Hong Kong briefly, then I spent five years in the Philippines, then back to Japan when I was 10, and I’ve been here since. So I feel very Japanese. I guess I’ve been so lucky to keep my English-language pronunciation to a point where people might think I grew up in America or something, but that’s not the case. I absolutely define myself as Japanese with elements of a different education because I moved around.
I didn’t know you lived in the Philippines! Did growing up there stick with you? Oh yeah! I love the Philippines so much. I remember when we were moving out, I was so sad. I didn’t want to leave. I don’t know if I completely fell in love with Japan in the beginning — it was more that I missed the Philippines so much. But yeah, now Japan is my home. I choose to be here as long as I can.
I don’t know if Japanese people will see me and be like, “Oh, she’s a little too … She doesn’t have the Japanese elements,” but I think I can switch it on and off. That’s the beauty of growing up in different countries. You have different sides, right?
How has the reception to Shōgun been in Japan where you are? I actually haven’t talked about it to many people who aren’t my friends. All of my friends are so supportive that anything they watch, they’ll be like, “Oh, we’re loving it, blah, blah, blah.” So I don’t know what the public is saying.
But I’ve gone to theaters to watch a movie where they showed the trailer for Shōgun. To see something not made in Japan be celebrated here — I haven’t seen that before. If we’re dealing with Japanese themes, I want the Japanese people to be proud of that and say, “That looks right.”
You’ve had a busy stretch of late: Pachinko, Monarch, now Shōgun. What’s next for you? We’ve finished Pachinko season two, so that should be coming out soon. But right now, I’m focusing on doing press for Shōgun and seeing how it lands. I have no idea what my year is going to look like yet, so we’ll have to see.
I’m a huge fan of Giri/Haji, in which you had one of your first roles. Is season two ever happening? Oh my gosh! You need to talk to Tak [Takehiro Hira, who plays Ishido]. I mean, we shot that in 2018–2019, so it’s been a couple of years. If they wanted to do another season, I would love to read it. It ends where there could be a season two, right? That was so lovely. I should write to Julian Farino and see if there’s anything going on.
By submitting your email, you agree to our
Terms and Privacy Notice
and to receive email correspondence from us. This site is protected by reCAPTCHA and the Google
Privacy Policy and
Terms of Service apply.
or
Already a subscriber?
What is your email?
This email will be used to sign into all New York sites. By submitting your email, you agree to our Terms and Privacy Policy and to receive email correspondence from us.
Password must be at least 8 characters and contain:
Lower case letters (a-z)
Upper case letters (A-Z)
Numbers (0-9)
Special Characters (!@#$%^&*)
This password will be used to sign into all New York sites. By submitting your email, you agree to our Terms and Privacy Policy and to receive email correspondence from us.
You’re in!
As part of your account, you’ll receive occasional updates and offers from New York, which you can opt out of anytime.
or
Already a subscriber?
What is your email?
This email will be used to sign into all New York sites. By submitting your email, you agree to our Terms and Privacy Policy and to receive email correspondence from us.
Password must be at least 8 characters and contain:
Lower case letters (a-z)
Upper case letters (A-Z)
Numbers (0-9)
Special Characters (!@#$%^&*)
This password will be used to sign into all New York sites. By submitting your email, you agree to our Terms and Privacy Policy and to receive email correspondence from us.
You’re in!
As part of your account, you’ll receive occasional updates and offers from New York, which you can opt out of anytime.
Already a subscriber?
Already a subscriber?
`;
// integrate Sub(x) scripts and elements
if (hostname !== 'subs.nymag.com') { // do not integrate on this subdomain
document.head.appendChild(trackingScript);
document.body.insertAdjacentHTML('beforeend', subXAnimationElements);
}
There was an error processing the request. Please try again later."}).catch(e=>console.error("Error verifying email: ",e)))(r.querySelector(".content"),o.bannerCTAVerification)})):(l.remove(),s.remove()),o.dismissable||n.remove(),o.useAlertIcon||a.remove(),r.classList.add("show"),n.addEventListener("click",()=>{u(),r.classList.remove("show")})}else r.remove()}});
}, {"1":1,"6":6,"12":12,"35":35,"40":40}];
window.modules["global-nav.client"] = [function(require,module,exports){"use strict";const dom=require(4),auth=require(12),signInButton=dom.find(".user-signin"),signOutButton=dom.find(".user-signout"),globalNav=dom.find('[class^="global-nav"]'),body=dom.find("body"),dropdownItems=dom.findAll(".dropdown-wrap"),gtm=require(1),appendLandingPageParams=require(135),pageUri=require(124).getPageUri(),subscriptionPromoLinks=dom.findAll(".persist-params"),searchString=window.location.search||"";function closeDropdowns(e){let n=globalNav.querySelectorAll(".dropdown.open");dropdownItems.forEach(function(t){let o=t.querySelector(".dropdown");!n||t.contains(e.target)&&27!==e.keyCode||o.classList.remove("open")})}function gtmSendReport(e,n,t){let o={eventCategory:"ecommerce",eventAction:"componentClick",brand:e,dimension23:"global-nav",list:pageUri,pageZone:"header",variant:"nav-link"};"global-nav-link"===t&&(o.eventLabel=n.href),gtm.reportNow(o)}function updateElementTargetUrlsIfQueryStrings(e){if(searchString){const n=new URLSearchParams(searchString);let t=e.href;if(t.includes("?")){const o=t.split("?"),i=new URLSearchParams(o[1]);for(let e of n.entries())i.set(e[0],e[1]);t=`${o[0]}?${i.toString()}`,e.href=t}else e.href=`${t}?${n.toString()}`}}function init(e){const n=e.querySelectorAll(".to-landing-page");window.addEventListener("auth:init",()=>{signInButton.addEventListener("click",function(e){e.preventDefault(),auth.showEmbeddedLoginFlow("top navigation")}),signOutButton.addEventListener("click",function(e){e.preventDefault(),gtmSendReport("Sign Out",e.target,"user-info-link"),auth.logout()}),auth.isAuthenticated()&&e.classList.add("signed-in"),auth.isSubscriber()&&e.classList.add("subscribed"),e.querySelectorAll(".user-link").forEach(e=>{e.classList.add("active")}),subscriptionPromoLinks.forEach(e=>{updateElementTargetUrlsIfQueryStrings(e)}),appendLandingPageParams(n)})}dropdownItems.forEach(function(e){e.addEventListener("click",function(){e.querySelector(".dropdown").classList.toggle("open")})}),body.addEventListener("click",closeDropdowns),document.addEventListener("keydown",closeDropdowns),globalNav.addEventListener("click",function(e){let n=e.target;n.classList.contains("global-nav-track")&>mSendReport(n.text,n,"global-nav-link")}),module.exports=init;
}, {"1":1,"4":4,"12":12,"124":124,"135":135}];
window.modules["aaa-module-mounting.legacy"] = [function(require,module,exports){"use strict";const _pickBy=require(221),_each=require(406),Fingerprint2=require(408),DS=require(407),Eventify=require(246);function registerGlobals(){window.DS=DS,window.Eventify=Eventify,window.Fingerprint2=Fingerprint2,DS.value("Eventify",Eventify),DS.value("Fingerprint2",Fingerprint2),DS.value("$document",window.document),DS.value("$window",window)}function mountDollarSliceComponents(){DS.service("components",["$document","$module",function(e,n){var o=_pickBy(n.definitions,e=>e.providerStrategy===n.providers.controller),r=Object.keys(o);function t(e){return o=>{try{n.get(e,o)}catch(e){logMountError(o,e)}}}_each(r,n=>{var o=e.querySelectorAll('[data-uri*="/_components/'+n+'/"]'),r=e.querySelectorAll('[data-uri$="/_components/'+n+'"]');_each(o,t(n)),_each(r,t(n))}),this.components=r}]),DS.get("components")}function logMountError(e,n){const o=e.outerHTML.slice(0,e.outerHTML.indexOf(e.innerHTML));console.error("Error attaching controller to "+o,n)}registerGlobals(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{mountDollarSliceComponents()}):mountDollarSliceComponents();
}, {"221":221,"246":246,"406":406,"407":407,"408":408}];
window.modules["ads.legacy"] = [function(require,module,exports){"use strict";const _map=require(118),_forEach=require(107),_isString=require(268),_intersectionWith=require(409),_isEqual=require(274),_each=require(406),_debounce=require(182),_sortBy=require(205),page=require(124),visit=require(114);DS.service("adService",["Eventify","$cid","$document","$window",function(e,t,a,i){var o,n,s,r,d,c,u,l,g={},p=this,h=[],f=visit.getQueryParamsObject(["utm_campaign"]),m=document.querySelector('script[data-type="ad-a9"]'),b=[],w=!1,v=[],y=document.querySelector('script[data-name="ad-doubleverify"]');document.querySelector('script[data-name="concert-ads"]')||(i.NYM={},i.NYM.analytics={},i.NYM.analytics.adStartTime=i.performance.now(),i.googletag=i.googletag||{},i.googletag.cmd=i.googletag.cmd||[],u=i.googletag,(m||y)&&(i.googletag.cmd=i.googletag.cmd||[],i.googletag.cmd.push(function(){i.googletag.pubads().disableInitialLoad()})),m&&(l=i.setInterval(function(){void 0!==window.apstag&&void 0!==window.apstag.timeout&&(i.clearInterval(l),window.apstag.cleared=!0,l=null)},10),setTimeout(function(){l&&(i.clearInterval(l),i.googletag.pubads().refresh(),window.apstag||console.log("MESSAGE: Timeout for A9 load exceeded, aborting"))},500)),y&&(b.push(new Promise(function(e){w?e():v.push(e)})),c=i.setTimeout(T,2500)),o=function(e){var t,a,o=e.data,n=[];return o.loaded?e:(o.loaded=!0,t=null,(t=o.sizes?u.defineSlot(o.name,o.sizes,o.id).addService(u.pubads()):u.defineOutOfPageSlot(o.name,o.id).addService(u.pubads())).setTargeting("adid",o.id),f.hasOwnProperty("utm_campaign")&&t.setTargeting("utmcamp",f.utm_campaign),a=p.getAdCount(o.label),t.setTargeting("label",o.label+"_"+o.site+"-"+a),u.display(o.id),u.pubads().addEventListener("slotOnload",function(){i.NYM.analytics.firstAdLoadTime||(i.NYM.analytics.firstAdLoadTime=i.performance.now(),i.NYM.analytics.firstAdLoadLabel=e.data.label)}),n=_(o),Promise.all(b).then(function(){n?window.apstag&&window.apstag.cleared?window.apstag.fetchBids({slots:[n],timeout:window.apstag.timeout},function(){u.cmd.push(function(){window.apstag.setDisplayBids(),u.pubads().refresh([t],{changeCorrelator:!1})})}):y&&u.pubads().refresh([t],{changeCorrelator:!1}):u.pubads().refresh([t],{changeCorrelator:!1})}),e.slot=t,e)},n=function(e){var a,i,o,n=t(),s=e.getAttribute("data-name"),r=e.getAttribute("data-sizes"),d=e.getAttribute("data-label"),c=e.getAttribute("data-site");n=e.id,r&&r.length?(r=r.split(","),a=[],_map(r,function(e){e=e.split("x"),i=parseInt(e[0]),o=parseInt(e[1]),a.push([i,o])})):(e.classList.add("oop"),a=!1),this.data={id:n,name:s,sizes:a,loaded:!1,label:d,site:c},g[n]=this},r=function(e){u.cmd.push(function(){var t=o(e);g[e.data.id]=t})},s=function(e){var t=[];e.slot?(t=_(e))&&window.apstag&&window.apstag.cleared&&window.apstag.fetchBids({slots:[t],timeout:window.apstag.timeout},function(){u.cmd.push(function(){window.apstag.setDisplayBids(),u.pubads().refresh([e.slot],{changeCorrelator:!1})})}):e&&r(e)},u.cmd.push(function(){var e,t,o,n=page.getMeta("article:tag"),s=page.getMeta("author"),r=i.location.href,d=(e=a.head.querySelector(".head-gtm"),t=a.body.querySelector(".gtm"),e&&"top"===e.getAttribute("data-gtm")?"gtmtop":t&&"bottom"===t.getAttribute("data-gtm")?"gtmbottom":"");o=[],_forEach([n,s,d],function(e){_forEach(e.split(","),function(e){(e=e.trim().toLowerCase().replace(/\s/g,"-").replace(/\'|\’/g,"")).length&&o.push(e)})}),u.pubads().setTargeting("kw",o),u.pubads().setTargeting("entry_group",o),r=r.slice(r.lastIndexOf("/")+1),u.pubads().setTargeting("pn",r),u.companionAds().setRefreshUnfilledSlots(!0),u.pubads().enableAsyncRendering(),u.enableServices()}),this.load=r,this.create=function(e){return new n(e)},this.refresh=function(e){var t;_isString(e)?(t=this.getById(e),s(t)):s(e)},this.remove=function(e){var t=e.data.id;a.getElementById(t).innerHTML=""},this.getAdCount=function(e){var t,a=0,i=Object.keys(g);return _each(i,function(i){(t=g[i]).data.loaded&&t.data.label===e&&a++}),a},this.getById=function(e){return g[e]},d=_debounce(function(){var e={TopLeaderboard:1,RightColTopMPU:2,outOfPage:99,"homepageTakeover/TopLeaderboard":1},t=_sortBy(h,function(t){return e[t.data.label]||10});_forEach(t,function(e){return e.data.sizes?r(e):i.setTimeout(function(){r(e)},2e3)}),y&&window.PQ.cmd.push(()=>{try{window.PQ.loadSignals(["ids","bsc","vlp"],T)}catch(e){T(),console.error(`There has been an error loading Double Verify signals: ${e}`)}}),h=[]},10),this.addToPageLoadQueue=function(e){h.push(e),d()});function _(e){var t,a=e.sizes;return a=_intersectionWith(a,[[970,250],[970,90],[728,90],[300,600],[300,250],[320,100],[320,50]],_isEqual),e.sizes&&e.sizes.length&&(t={slotID:e.id,sizes:a,slotName:e.label}),t}function T(){i.clearTimeout(c),w=!0,_forEach(v,function(e){e()})}}]);
}, {"107":107,"114":114,"118":118,"124":124,"182":182,"205":205,"268":268,"274":274,"406":406,"409":409}];
window.modules["cid.legacy"] = [function(require,module,exports){"use strict";DS.service("$cid",function(){var r=Math.floor(100*Math.random());return function(){return"cid-"+ ++r}});
}, {}];
window.modules["client.legacy"] = [function(require,module,exports){"use strict";require("cid.legacy"),require("ads.legacy"),require("facebook.legacy"),require("aaa-module-mounting.legacy");
}, {"cid.legacy":"cid.legacy","ads.legacy":"ads.legacy","facebook.legacy":"facebook.legacy","aaa-module-mounting.legacy":"aaa-module-mounting.legacy"}];
window.modules["facebook.legacy"] = [function(require,module,exports){"use strict";DS.service("facebook",[function(){this.fb=function(i){window.FB&&window.FB[i].apply(this,Array.prototype.slice.call(arguments,1))}}]);
}, {}];
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o typeof key === 'string' && key.match(/\.legacy$/)).forEach(key => window.require(key));
}
function tryToMount(fn, el, name) {
try {
fn(el); // init the controller
} catch (e) {
const elementTag = el.outerHTML.slice(0, el.outerHTML.indexOf(el.innerHTML));
console.error(`Error initializing controller for "${name}" on "${elementTag}"`, e);
}
}
/**
* mount client.js component controllers
*/
function mountComponentModules() {
Object.keys(window.modules).filter(key => typeof key === 'string' && key.match(/\.client$/)).forEach(key => {
let controllerFn = window.require(key);
if (typeof controllerFn === 'function') {
const name = key.replace('.client', ''),
instancesSelector = `[data-uri*="_components/${name}/"]`,
defaultSelector = `[data-uri$="_components${name}"]`,
instances = document.querySelectorAll(instancesSelector),
defaults = document.querySelectorAll(defaultSelector);
for (let el of instances) {
tryToMount(controllerFn, el, name);
}
for (let el of defaults) {
tryToMount(controllerFn, el, name);
}
}
});
}
// Make sure that a `window.process.env.NODE_ENV` is available in the client for any dependencies,
// services, or components that could require it
// note: the `` value is swapped for the actual environment variable in /lib/cmd/compile/scripts.js
window.process = window.process || {};
window.process.env = window.process.env || {};
if (!window.process.env.NODE_ENV) {
window.process.env.NODE_ENV = '';
}
// note: legacy controllers that require legacy services (e.g. dollar-slice) must
// wait for DOMContentLoaded to initialize themselves, as the files themselves must be mounted first
mountLegacyServices();
mountComponentModules();
// ]]