react-dom.development.js 885 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147
  1. /** @license React v16.13.1
  2. * react-dom.development.js
  3. *
  4. * Copyright (c) Facebook, Inc. and its affiliates.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. */
  9. 'use strict';
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
  12. typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
  13. (global = global || self, factory(global.ReactDOM = {}, global.React));
  14. }(this, (function (exports, React) { 'use strict';
  15. var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
  16. // Current owner and dispatcher used to share the same ref,
  17. // but PR #14548 split them out to better support the react-debug-tools package.
  18. if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
  19. ReactSharedInternals.ReactCurrentDispatcher = {
  20. current: null
  21. };
  22. }
  23. if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
  24. ReactSharedInternals.ReactCurrentBatchConfig = {
  25. suspense: null
  26. };
  27. }
  28. // by calls to these methods by a Babel plugin.
  29. //
  30. // In PROD (or in packages without access to React internals),
  31. // they are left as they are instead.
  32. function warn(format) {
  33. {
  34. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  35. args[_key - 1] = arguments[_key];
  36. }
  37. printWarning('warn', format, args);
  38. }
  39. }
  40. function error(format) {
  41. {
  42. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  43. args[_key2 - 1] = arguments[_key2];
  44. }
  45. printWarning('error', format, args);
  46. }
  47. }
  48. function printWarning(level, format, args) {
  49. // When changing this logic, you might want to also
  50. // update consoleWithStackDev.www.js as well.
  51. {
  52. var hasExistingStack = args.length > 0 && typeof args[args.length - 1] === 'string' && args[args.length - 1].indexOf('\n in') === 0;
  53. if (!hasExistingStack) {
  54. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  55. var stack = ReactDebugCurrentFrame.getStackAddendum();
  56. if (stack !== '') {
  57. format += '%s';
  58. args = args.concat([stack]);
  59. }
  60. }
  61. var argsWithFormat = args.map(function (item) {
  62. return '' + item;
  63. }); // Careful: RN currently depends on this prefix
  64. argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
  65. // breaks IE9: https://github.com/facebook/react/issues/13610
  66. // eslint-disable-next-line react-internal/no-production-logging
  67. Function.prototype.apply.call(console[level], console, argsWithFormat);
  68. try {
  69. // --- Welcome to debugging React ---
  70. // This error was thrown as a convenience so that you can use this stack
  71. // to find the callsite that caused this warning to fire.
  72. var argIndex = 0;
  73. var message = 'Warning: ' + format.replace(/%s/g, function () {
  74. return args[argIndex++];
  75. });
  76. throw new Error(message);
  77. } catch (x) {}
  78. }
  79. }
  80. if (!React) {
  81. {
  82. throw Error( "ReactDOM was loaded before React. Make sure you load the React package before loading ReactDOM." );
  83. }
  84. }
  85. var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
  86. var funcArgs = Array.prototype.slice.call(arguments, 3);
  87. try {
  88. func.apply(context, funcArgs);
  89. } catch (error) {
  90. this.onError(error);
  91. }
  92. };
  93. {
  94. // In DEV mode, we swap out invokeGuardedCallback for a special version
  95. // that plays more nicely with the browser's DevTools. The idea is to preserve
  96. // "Pause on exceptions" behavior. Because React wraps all user-provided
  97. // functions in invokeGuardedCallback, and the production version of
  98. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  99. // like caught exceptions, and the DevTools won't pause unless the developer
  100. // takes the extra step of enabling pause on caught exceptions. This is
  101. // unintuitive, though, because even though React has caught the error, from
  102. // the developer's perspective, the error is uncaught.
  103. //
  104. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  105. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  106. // DOM node, and call the user-provided callback from inside an event handler
  107. // for that fake event. If the callback throws, the error is "captured" using
  108. // a global event handler. But because the error happens in a different
  109. // event loop context, it does not interrupt the normal program flow.
  110. // Effectively, this gives us try-catch behavior without actually using
  111. // try-catch. Neat!
  112. // Check that the browser supports the APIs we need to implement our special
  113. // DEV version of invokeGuardedCallback
  114. if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
  115. var fakeNode = document.createElement('react');
  116. var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
  117. // If document doesn't exist we know for sure we will crash in this method
  118. // when we call document.createEvent(). However this can cause confusing
  119. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  120. // So we preemptively throw with a better message instead.
  121. if (!(typeof document !== 'undefined')) {
  122. {
  123. throw Error( "The `document` global was defined when React was initialized, but is not defined anymore. This can happen in a test environment if a component schedules an update from an asynchronous callback, but the test has already finished running. To solve this, you can either unmount the component at the end of your test (and ensure that any asynchronous operations get canceled in `componentWillUnmount`), or you can change the test itself to be asynchronous." );
  124. }
  125. }
  126. var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
  127. // set this to true at the beginning, then set it to false right after
  128. // calling the function. If the function errors, `didError` will never be
  129. // set to false. This strategy works even if the browser is flaky and
  130. // fails to call our global error handler, because it doesn't rely on
  131. // the error event at all.
  132. var didError = true; // Keeps track of the value of window.event so that we can reset it
  133. // during the callback to let user code access window.event in the
  134. // browsers that support it.
  135. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  136. // dispatching: https://github.com/facebook/react/issues/13688
  137. var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event'); // Create an event handler for our fake event. We will synchronously
  138. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  139. // call the user-provided callback.
  140. var funcArgs = Array.prototype.slice.call(arguments, 3);
  141. function callCallback() {
  142. // We immediately remove the callback from event listeners so that
  143. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  144. // nested call would trigger the fake event handlers of any call higher
  145. // in the stack.
  146. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  147. // window.event assignment in both IE <= 10 as they throw an error
  148. // "Member not found" in strict mode, and in Firefox which does not
  149. // support window.event.
  150. if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
  151. window.event = windowEvent;
  152. }
  153. func.apply(context, funcArgs);
  154. didError = false;
  155. } // Create a global error event handler. We use this to capture the value
  156. // that was thrown. It's possible that this error handler will fire more
  157. // than once; for example, if non-React code also calls `dispatchEvent`
  158. // and a handler for that event throws. We should be resilient to most of
  159. // those cases. Even if our error event handler fires more than once, the
  160. // last error event is always used. If the callback actually does error,
  161. // we know that the last error event is the correct one, because it's not
  162. // possible for anything else to have happened in between our callback
  163. // erroring and the code that follows the `dispatchEvent` call below. If
  164. // the callback doesn't error, but the error event was fired, we know to
  165. // ignore it because `didError` will be false, as described above.
  166. var error; // Use this to track whether the error event is ever called.
  167. var didSetError = false;
  168. var isCrossOriginError = false;
  169. function handleWindowError(event) {
  170. error = event.error;
  171. didSetError = true;
  172. if (error === null && event.colno === 0 && event.lineno === 0) {
  173. isCrossOriginError = true;
  174. }
  175. if (event.defaultPrevented) {
  176. // Some other error handler has prevented default.
  177. // Browsers silence the error report if this happens.
  178. // We'll remember this to later decide whether to log it or not.
  179. if (error != null && typeof error === 'object') {
  180. try {
  181. error._suppressLogging = true;
  182. } catch (inner) {// Ignore.
  183. }
  184. }
  185. }
  186. } // Create a fake event type.
  187. var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
  188. window.addEventListener('error', handleWindowError);
  189. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  190. // errors, it will trigger our global error handler.
  191. evt.initEvent(evtType, false, false);
  192. fakeNode.dispatchEvent(evt);
  193. if (windowEventDescriptor) {
  194. Object.defineProperty(window, 'event', windowEventDescriptor);
  195. }
  196. if (didError) {
  197. if (!didSetError) {
  198. // The callback errored, but the error event never fired.
  199. error = new Error('An error was thrown inside one of your components, but React ' + "doesn't know what it was. This is likely due to browser " + 'flakiness. React does its best to preserve the "Pause on ' + 'exceptions" behavior of the DevTools, which requires some ' + "DEV-mode only tricks. It's possible that these don't work in " + 'your browser. Try triggering the error in production mode, ' + 'or switching to a modern browser. If you suspect that this is ' + 'actually an issue with React, please file an issue.');
  200. } else if (isCrossOriginError) {
  201. error = new Error("A cross-origin error was thrown. React doesn't have access to " + 'the actual error object in development. ' + 'See https://fb.me/react-crossorigin-error for more information.');
  202. }
  203. this.onError(error);
  204. } // Remove our event listeners
  205. window.removeEventListener('error', handleWindowError);
  206. };
  207. invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
  208. }
  209. }
  210. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  211. var hasError = false;
  212. var caughtError = null; // Used by event system to capture/rethrow the first error.
  213. var hasRethrowError = false;
  214. var rethrowError = null;
  215. var reporter = {
  216. onError: function (error) {
  217. hasError = true;
  218. caughtError = error;
  219. }
  220. };
  221. /**
  222. * Call a function while guarding against errors that happens within it.
  223. * Returns an error if it throws, otherwise null.
  224. *
  225. * In production, this is implemented using a try-catch. The reason we don't
  226. * use a try-catch directly is so that we can swap out a different
  227. * implementation in DEV mode.
  228. *
  229. * @param {String} name of the guard to use for logging or debugging
  230. * @param {Function} func The function to invoke
  231. * @param {*} context The context to use when calling the function
  232. * @param {...*} args Arguments for function
  233. */
  234. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  235. hasError = false;
  236. caughtError = null;
  237. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  238. }
  239. /**
  240. * Same as invokeGuardedCallback, but instead of returning an error, it stores
  241. * it in a global so it can be rethrown by `rethrowCaughtError` later.
  242. * TODO: See if caughtError and rethrowError can be unified.
  243. *
  244. * @param {String} name of the guard to use for logging or debugging
  245. * @param {Function} func The function to invoke
  246. * @param {*} context The context to use when calling the function
  247. * @param {...*} args Arguments for function
  248. */
  249. function invokeGuardedCallbackAndCatchFirstError(name, func, context, a, b, c, d, e, f) {
  250. invokeGuardedCallback.apply(this, arguments);
  251. if (hasError) {
  252. var error = clearCaughtError();
  253. if (!hasRethrowError) {
  254. hasRethrowError = true;
  255. rethrowError = error;
  256. }
  257. }
  258. }
  259. /**
  260. * During execution of guarded functions we will capture the first error which
  261. * we will rethrow to be handled by the top level error handler.
  262. */
  263. function rethrowCaughtError() {
  264. if (hasRethrowError) {
  265. var error = rethrowError;
  266. hasRethrowError = false;
  267. rethrowError = null;
  268. throw error;
  269. }
  270. }
  271. function hasCaughtError() {
  272. return hasError;
  273. }
  274. function clearCaughtError() {
  275. if (hasError) {
  276. var error = caughtError;
  277. hasError = false;
  278. caughtError = null;
  279. return error;
  280. } else {
  281. {
  282. {
  283. throw Error( "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue." );
  284. }
  285. }
  286. }
  287. }
  288. var getFiberCurrentPropsFromNode = null;
  289. var getInstanceFromNode = null;
  290. var getNodeFromInstance = null;
  291. function setComponentTree(getFiberCurrentPropsFromNodeImpl, getInstanceFromNodeImpl, getNodeFromInstanceImpl) {
  292. getFiberCurrentPropsFromNode = getFiberCurrentPropsFromNodeImpl;
  293. getInstanceFromNode = getInstanceFromNodeImpl;
  294. getNodeFromInstance = getNodeFromInstanceImpl;
  295. {
  296. if (!getNodeFromInstance || !getInstanceFromNode) {
  297. error('EventPluginUtils.setComponentTree(...): Injected ' + 'module is missing getNodeFromInstance or getInstanceFromNode.');
  298. }
  299. }
  300. }
  301. var validateEventDispatches;
  302. {
  303. validateEventDispatches = function (event) {
  304. var dispatchListeners = event._dispatchListeners;
  305. var dispatchInstances = event._dispatchInstances;
  306. var listenersIsArr = Array.isArray(dispatchListeners);
  307. var listenersLen = listenersIsArr ? dispatchListeners.length : dispatchListeners ? 1 : 0;
  308. var instancesIsArr = Array.isArray(dispatchInstances);
  309. var instancesLen = instancesIsArr ? dispatchInstances.length : dispatchInstances ? 1 : 0;
  310. if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
  311. error('EventPluginUtils: Invalid `event`.');
  312. }
  313. };
  314. }
  315. /**
  316. * Dispatch the event to the listener.
  317. * @param {SyntheticEvent} event SyntheticEvent to handle
  318. * @param {function} listener Application-level callback
  319. * @param {*} inst Internal component instance
  320. */
  321. function executeDispatch(event, listener, inst) {
  322. var type = event.type || 'unknown-event';
  323. event.currentTarget = getNodeFromInstance(inst);
  324. invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
  325. event.currentTarget = null;
  326. }
  327. /**
  328. * Standard/simple iteration through an event's collected dispatches.
  329. */
  330. function executeDispatchesInOrder(event) {
  331. var dispatchListeners = event._dispatchListeners;
  332. var dispatchInstances = event._dispatchInstances;
  333. {
  334. validateEventDispatches(event);
  335. }
  336. if (Array.isArray(dispatchListeners)) {
  337. for (var i = 0; i < dispatchListeners.length; i++) {
  338. if (event.isPropagationStopped()) {
  339. break;
  340. } // Listeners and Instances are two parallel arrays that are always in sync.
  341. executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
  342. }
  343. } else if (dispatchListeners) {
  344. executeDispatch(event, dispatchListeners, dispatchInstances);
  345. }
  346. event._dispatchListeners = null;
  347. event._dispatchInstances = null;
  348. }
  349. var FunctionComponent = 0;
  350. var ClassComponent = 1;
  351. var IndeterminateComponent = 2; // Before we know whether it is function or class
  352. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  353. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  354. var HostComponent = 5;
  355. var HostText = 6;
  356. var Fragment = 7;
  357. var Mode = 8;
  358. var ContextConsumer = 9;
  359. var ContextProvider = 10;
  360. var ForwardRef = 11;
  361. var Profiler = 12;
  362. var SuspenseComponent = 13;
  363. var MemoComponent = 14;
  364. var SimpleMemoComponent = 15;
  365. var LazyComponent = 16;
  366. var IncompleteClassComponent = 17;
  367. var DehydratedFragment = 18;
  368. var SuspenseListComponent = 19;
  369. var FundamentalComponent = 20;
  370. var ScopeComponent = 21;
  371. var Block = 22;
  372. /**
  373. * Injectable ordering of event plugins.
  374. */
  375. var eventPluginOrder = null;
  376. /**
  377. * Injectable mapping from names to event plugin modules.
  378. */
  379. var namesToPlugins = {};
  380. /**
  381. * Recomputes the plugin list using the injected plugins and plugin ordering.
  382. *
  383. * @private
  384. */
  385. function recomputePluginOrdering() {
  386. if (!eventPluginOrder) {
  387. // Wait until an `eventPluginOrder` is injected.
  388. return;
  389. }
  390. for (var pluginName in namesToPlugins) {
  391. var pluginModule = namesToPlugins[pluginName];
  392. var pluginIndex = eventPluginOrder.indexOf(pluginName);
  393. if (!(pluginIndex > -1)) {
  394. {
  395. throw Error( "EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `" + pluginName + "`." );
  396. }
  397. }
  398. if (plugins[pluginIndex]) {
  399. continue;
  400. }
  401. if (!pluginModule.extractEvents) {
  402. {
  403. throw Error( "EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `" + pluginName + "` does not." );
  404. }
  405. }
  406. plugins[pluginIndex] = pluginModule;
  407. var publishedEvents = pluginModule.eventTypes;
  408. for (var eventName in publishedEvents) {
  409. if (!publishEventForPlugin(publishedEvents[eventName], pluginModule, eventName)) {
  410. {
  411. throw Error( "EventPluginRegistry: Failed to publish event `" + eventName + "` for plugin `" + pluginName + "`." );
  412. }
  413. }
  414. }
  415. }
  416. }
  417. /**
  418. * Publishes an event so that it can be dispatched by the supplied plugin.
  419. *
  420. * @param {object} dispatchConfig Dispatch configuration for the event.
  421. * @param {object} PluginModule Plugin publishing the event.
  422. * @return {boolean} True if the event was successfully published.
  423. * @private
  424. */
  425. function publishEventForPlugin(dispatchConfig, pluginModule, eventName) {
  426. if (!!eventNameDispatchConfigs.hasOwnProperty(eventName)) {
  427. {
  428. throw Error( "EventPluginRegistry: More than one plugin attempted to publish the same event name, `" + eventName + "`." );
  429. }
  430. }
  431. eventNameDispatchConfigs[eventName] = dispatchConfig;
  432. var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
  433. if (phasedRegistrationNames) {
  434. for (var phaseName in phasedRegistrationNames) {
  435. if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
  436. var phasedRegistrationName = phasedRegistrationNames[phaseName];
  437. publishRegistrationName(phasedRegistrationName, pluginModule, eventName);
  438. }
  439. }
  440. return true;
  441. } else if (dispatchConfig.registrationName) {
  442. publishRegistrationName(dispatchConfig.registrationName, pluginModule, eventName);
  443. return true;
  444. }
  445. return false;
  446. }
  447. /**
  448. * Publishes a registration name that is used to identify dispatched events.
  449. *
  450. * @param {string} registrationName Registration name to add.
  451. * @param {object} PluginModule Plugin publishing the event.
  452. * @private
  453. */
  454. function publishRegistrationName(registrationName, pluginModule, eventName) {
  455. if (!!registrationNameModules[registrationName]) {
  456. {
  457. throw Error( "EventPluginRegistry: More than one plugin attempted to publish the same registration name, `" + registrationName + "`." );
  458. }
  459. }
  460. registrationNameModules[registrationName] = pluginModule;
  461. registrationNameDependencies[registrationName] = pluginModule.eventTypes[eventName].dependencies;
  462. {
  463. var lowerCasedName = registrationName.toLowerCase();
  464. possibleRegistrationNames[lowerCasedName] = registrationName;
  465. if (registrationName === 'onDoubleClick') {
  466. possibleRegistrationNames.ondblclick = registrationName;
  467. }
  468. }
  469. }
  470. /**
  471. * Registers plugins so that they can extract and dispatch events.
  472. */
  473. /**
  474. * Ordered list of injected plugins.
  475. */
  476. var plugins = [];
  477. /**
  478. * Mapping from event name to dispatch config
  479. */
  480. var eventNameDispatchConfigs = {};
  481. /**
  482. * Mapping from registration name to plugin module
  483. */
  484. var registrationNameModules = {};
  485. /**
  486. * Mapping from registration name to event name
  487. */
  488. var registrationNameDependencies = {};
  489. /**
  490. * Mapping from lowercase registration names to the properly cased version,
  491. * used to warn in the case of missing event handlers. Available
  492. * only in true.
  493. * @type {Object}
  494. */
  495. var possibleRegistrationNames = {} ; // Trust the developer to only use possibleRegistrationNames in true
  496. /**
  497. * Injects an ordering of plugins (by plugin name). This allows the ordering
  498. * to be decoupled from injection of the actual plugins so that ordering is
  499. * always deterministic regardless of packaging, on-the-fly injection, etc.
  500. *
  501. * @param {array} InjectedEventPluginOrder
  502. * @internal
  503. */
  504. function injectEventPluginOrder(injectedEventPluginOrder) {
  505. if (!!eventPluginOrder) {
  506. {
  507. throw Error( "EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React." );
  508. }
  509. } // Clone the ordering so it cannot be dynamically mutated.
  510. eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
  511. recomputePluginOrdering();
  512. }
  513. /**
  514. * Injects plugins to be used by plugin event system. The plugin names must be
  515. * in the ordering injected by `injectEventPluginOrder`.
  516. *
  517. * Plugins can be injected as part of page initialization or on-the-fly.
  518. *
  519. * @param {object} injectedNamesToPlugins Map from names to plugin modules.
  520. * @internal
  521. */
  522. function injectEventPluginsByName(injectedNamesToPlugins) {
  523. var isOrderingDirty = false;
  524. for (var pluginName in injectedNamesToPlugins) {
  525. if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
  526. continue;
  527. }
  528. var pluginModule = injectedNamesToPlugins[pluginName];
  529. if (!namesToPlugins.hasOwnProperty(pluginName) || namesToPlugins[pluginName] !== pluginModule) {
  530. if (!!namesToPlugins[pluginName]) {
  531. {
  532. throw Error( "EventPluginRegistry: Cannot inject two different event plugins using the same name, `" + pluginName + "`." );
  533. }
  534. }
  535. namesToPlugins[pluginName] = pluginModule;
  536. isOrderingDirty = true;
  537. }
  538. }
  539. if (isOrderingDirty) {
  540. recomputePluginOrdering();
  541. }
  542. }
  543. var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
  544. var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  545. var _assign = ReactInternals.assign;
  546. var PLUGIN_EVENT_SYSTEM = 1;
  547. var IS_REPLAYED = 1 << 5;
  548. var IS_FIRST_ANCESTOR = 1 << 6;
  549. var restoreImpl = null;
  550. var restoreTarget = null;
  551. var restoreQueue = null;
  552. function restoreStateOfTarget(target) {
  553. // We perform this translation at the end of the event loop so that we
  554. // always receive the correct fiber here
  555. var internalInstance = getInstanceFromNode(target);
  556. if (!internalInstance) {
  557. // Unmounted
  558. return;
  559. }
  560. if (!(typeof restoreImpl === 'function')) {
  561. {
  562. throw Error( "setRestoreImplementation() needs to be called to handle a target for controlled events. This error is likely caused by a bug in React. Please file an issue." );
  563. }
  564. }
  565. var stateNode = internalInstance.stateNode; // Guard against Fiber being unmounted.
  566. if (stateNode) {
  567. var _props = getFiberCurrentPropsFromNode(stateNode);
  568. restoreImpl(internalInstance.stateNode, internalInstance.type, _props);
  569. }
  570. }
  571. function setRestoreImplementation(impl) {
  572. restoreImpl = impl;
  573. }
  574. function enqueueStateRestore(target) {
  575. if (restoreTarget) {
  576. if (restoreQueue) {
  577. restoreQueue.push(target);
  578. } else {
  579. restoreQueue = [target];
  580. }
  581. } else {
  582. restoreTarget = target;
  583. }
  584. }
  585. function needsStateRestore() {
  586. return restoreTarget !== null || restoreQueue !== null;
  587. }
  588. function restoreStateIfNeeded() {
  589. if (!restoreTarget) {
  590. return;
  591. }
  592. var target = restoreTarget;
  593. var queuedTargets = restoreQueue;
  594. restoreTarget = null;
  595. restoreQueue = null;
  596. restoreStateOfTarget(target);
  597. if (queuedTargets) {
  598. for (var i = 0; i < queuedTargets.length; i++) {
  599. restoreStateOfTarget(queuedTargets[i]);
  600. }
  601. }
  602. }
  603. var enableProfilerTimer = true; // Trace which interactions trigger each commit.
  604. var enableDeprecatedFlareAPI = false; // Experimental Host Component support.
  605. var enableFundamentalAPI = false; // Experimental Scope support.
  606. var warnAboutStringRefs = false;
  607. // the renderer. Such as when we're dispatching events or if third party
  608. // libraries need to call batchedUpdates. Eventually, this API will go away when
  609. // everything is batched by default. We'll then have a similar API to opt-out of
  610. // scheduled work and instead do synchronous work.
  611. // Defaults
  612. var batchedUpdatesImpl = function (fn, bookkeeping) {
  613. return fn(bookkeeping);
  614. };
  615. var discreteUpdatesImpl = function (fn, a, b, c, d) {
  616. return fn(a, b, c, d);
  617. };
  618. var flushDiscreteUpdatesImpl = function () {};
  619. var batchedEventUpdatesImpl = batchedUpdatesImpl;
  620. var isInsideEventHandler = false;
  621. var isBatchingEventUpdates = false;
  622. function finishEventHandler() {
  623. // Here we wait until all updates have propagated, which is important
  624. // when using controlled components within layers:
  625. // https://github.com/facebook/react/issues/1698
  626. // Then we restore state of any controlled component.
  627. var controlledComponentsHavePendingUpdates = needsStateRestore();
  628. if (controlledComponentsHavePendingUpdates) {
  629. // If a controlled event was fired, we may need to restore the state of
  630. // the DOM node back to the controlled value. This is necessary when React
  631. // bails out of the update without touching the DOM.
  632. flushDiscreteUpdatesImpl();
  633. restoreStateIfNeeded();
  634. }
  635. }
  636. function batchedUpdates(fn, bookkeeping) {
  637. if (isInsideEventHandler) {
  638. // If we are currently inside another batch, we need to wait until it
  639. // fully completes before restoring state.
  640. return fn(bookkeeping);
  641. }
  642. isInsideEventHandler = true;
  643. try {
  644. return batchedUpdatesImpl(fn, bookkeeping);
  645. } finally {
  646. isInsideEventHandler = false;
  647. finishEventHandler();
  648. }
  649. }
  650. function batchedEventUpdates(fn, a, b) {
  651. if (isBatchingEventUpdates) {
  652. // If we are currently inside another batch, we need to wait until it
  653. // fully completes before restoring state.
  654. return fn(a, b);
  655. }
  656. isBatchingEventUpdates = true;
  657. try {
  658. return batchedEventUpdatesImpl(fn, a, b);
  659. } finally {
  660. isBatchingEventUpdates = false;
  661. finishEventHandler();
  662. }
  663. } // This is for the React Flare event system
  664. function discreteUpdates(fn, a, b, c, d) {
  665. var prevIsInsideEventHandler = isInsideEventHandler;
  666. isInsideEventHandler = true;
  667. try {
  668. return discreteUpdatesImpl(fn, a, b, c, d);
  669. } finally {
  670. isInsideEventHandler = prevIsInsideEventHandler;
  671. if (!isInsideEventHandler) {
  672. finishEventHandler();
  673. }
  674. }
  675. }
  676. function flushDiscreteUpdatesIfNeeded(timeStamp) {
  677. // event.timeStamp isn't overly reliable due to inconsistencies in
  678. // how different browsers have historically provided the time stamp.
  679. // Some browsers provide high-resolution time stamps for all events,
  680. // some provide low-resolution time stamps for all events. FF < 52
  681. // even mixes both time stamps together. Some browsers even report
  682. // negative time stamps or time stamps that are 0 (iOS9) in some cases.
  683. // Given we are only comparing two time stamps with equality (!==),
  684. // we are safe from the resolution differences. If the time stamp is 0
  685. // we bail-out of preventing the flush, which can affect semantics,
  686. // such as if an earlier flush removes or adds event listeners that
  687. // are fired in the subsequent flush. However, this is the same
  688. // behaviour as we had before this change, so the risks are low.
  689. if (!isInsideEventHandler && (!enableDeprecatedFlareAPI )) {
  690. flushDiscreteUpdatesImpl();
  691. }
  692. }
  693. function setBatchingImplementation(_batchedUpdatesImpl, _discreteUpdatesImpl, _flushDiscreteUpdatesImpl, _batchedEventUpdatesImpl) {
  694. batchedUpdatesImpl = _batchedUpdatesImpl;
  695. discreteUpdatesImpl = _discreteUpdatesImpl;
  696. flushDiscreteUpdatesImpl = _flushDiscreteUpdatesImpl;
  697. batchedEventUpdatesImpl = _batchedEventUpdatesImpl;
  698. }
  699. var DiscreteEvent = 0;
  700. var UserBlockingEvent = 1;
  701. var ContinuousEvent = 2;
  702. var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  703. var _ReactInternals$Sched = ReactInternals$1.Scheduler,
  704. unstable_cancelCallback = _ReactInternals$Sched.unstable_cancelCallback,
  705. unstable_now = _ReactInternals$Sched.unstable_now,
  706. unstable_scheduleCallback = _ReactInternals$Sched.unstable_scheduleCallback,
  707. unstable_shouldYield = _ReactInternals$Sched.unstable_shouldYield,
  708. unstable_requestPaint = _ReactInternals$Sched.unstable_requestPaint,
  709. unstable_getFirstCallbackNode = _ReactInternals$Sched.unstable_getFirstCallbackNode,
  710. unstable_runWithPriority = _ReactInternals$Sched.unstable_runWithPriority,
  711. unstable_next = _ReactInternals$Sched.unstable_next,
  712. unstable_continueExecution = _ReactInternals$Sched.unstable_continueExecution,
  713. unstable_pauseExecution = _ReactInternals$Sched.unstable_pauseExecution,
  714. unstable_getCurrentPriorityLevel = _ReactInternals$Sched.unstable_getCurrentPriorityLevel,
  715. unstable_ImmediatePriority = _ReactInternals$Sched.unstable_ImmediatePriority,
  716. unstable_UserBlockingPriority = _ReactInternals$Sched.unstable_UserBlockingPriority,
  717. unstable_NormalPriority = _ReactInternals$Sched.unstable_NormalPriority,
  718. unstable_LowPriority = _ReactInternals$Sched.unstable_LowPriority,
  719. unstable_IdlePriority = _ReactInternals$Sched.unstable_IdlePriority,
  720. unstable_forceFrameRate = _ReactInternals$Sched.unstable_forceFrameRate,
  721. unstable_flushAllWithoutAsserting = _ReactInternals$Sched.unstable_flushAllWithoutAsserting;
  722. // A reserved attribute.
  723. // It is handled by React separately and shouldn't be written to the DOM.
  724. var RESERVED = 0; // A simple string attribute.
  725. // Attributes that aren't in the whitelist are presumed to have this type.
  726. var STRING = 1; // A string attribute that accepts booleans in React. In HTML, these are called
  727. // "enumerated" attributes with "true" and "false" as possible values.
  728. // When true, it should be set to a "true" string.
  729. // When false, it should be set to a "false" string.
  730. var BOOLEANISH_STRING = 2; // A real boolean attribute.
  731. // When true, it should be present (set either to an empty string or its name).
  732. // When false, it should be omitted.
  733. var BOOLEAN = 3; // An attribute that can be used as a flag as well as with a value.
  734. // When true, it should be present (set either to an empty string or its name).
  735. // When false, it should be omitted.
  736. // For any other value, should be present with that value.
  737. var OVERLOADED_BOOLEAN = 4; // An attribute that must be numeric or parse as a numeric.
  738. // When falsy, it should be removed.
  739. var NUMERIC = 5; // An attribute that must be positive numeric or parse as a positive numeric.
  740. // When falsy, it should be removed.
  741. var POSITIVE_NUMERIC = 6;
  742. /* eslint-disable max-len */
  743. var ATTRIBUTE_NAME_START_CHAR = ":A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
  744. /* eslint-enable max-len */
  745. var ATTRIBUTE_NAME_CHAR = ATTRIBUTE_NAME_START_CHAR + "\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
  746. var ROOT_ATTRIBUTE_NAME = 'data-reactroot';
  747. var VALID_ATTRIBUTE_NAME_REGEX = new RegExp('^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$');
  748. var hasOwnProperty = Object.prototype.hasOwnProperty;
  749. var illegalAttributeNameCache = {};
  750. var validatedAttributeNameCache = {};
  751. function isAttributeNameSafe(attributeName) {
  752. if (hasOwnProperty.call(validatedAttributeNameCache, attributeName)) {
  753. return true;
  754. }
  755. if (hasOwnProperty.call(illegalAttributeNameCache, attributeName)) {
  756. return false;
  757. }
  758. if (VALID_ATTRIBUTE_NAME_REGEX.test(attributeName)) {
  759. validatedAttributeNameCache[attributeName] = true;
  760. return true;
  761. }
  762. illegalAttributeNameCache[attributeName] = true;
  763. {
  764. error('Invalid attribute name: `%s`', attributeName);
  765. }
  766. return false;
  767. }
  768. function shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag) {
  769. if (propertyInfo !== null) {
  770. return propertyInfo.type === RESERVED;
  771. }
  772. if (isCustomComponentTag) {
  773. return false;
  774. }
  775. if (name.length > 2 && (name[0] === 'o' || name[0] === 'O') && (name[1] === 'n' || name[1] === 'N')) {
  776. return true;
  777. }
  778. return false;
  779. }
  780. function shouldRemoveAttributeWithWarning(name, value, propertyInfo, isCustomComponentTag) {
  781. if (propertyInfo !== null && propertyInfo.type === RESERVED) {
  782. return false;
  783. }
  784. switch (typeof value) {
  785. case 'function': // $FlowIssue symbol is perfectly valid here
  786. case 'symbol':
  787. // eslint-disable-line
  788. return true;
  789. case 'boolean':
  790. {
  791. if (isCustomComponentTag) {
  792. return false;
  793. }
  794. if (propertyInfo !== null) {
  795. return !propertyInfo.acceptsBooleans;
  796. } else {
  797. var prefix = name.toLowerCase().slice(0, 5);
  798. return prefix !== 'data-' && prefix !== 'aria-';
  799. }
  800. }
  801. default:
  802. return false;
  803. }
  804. }
  805. function shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag) {
  806. if (value === null || typeof value === 'undefined') {
  807. return true;
  808. }
  809. if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, isCustomComponentTag)) {
  810. return true;
  811. }
  812. if (isCustomComponentTag) {
  813. return false;
  814. }
  815. if (propertyInfo !== null) {
  816. switch (propertyInfo.type) {
  817. case BOOLEAN:
  818. return !value;
  819. case OVERLOADED_BOOLEAN:
  820. return value === false;
  821. case NUMERIC:
  822. return isNaN(value);
  823. case POSITIVE_NUMERIC:
  824. return isNaN(value) || value < 1;
  825. }
  826. }
  827. return false;
  828. }
  829. function getPropertyInfo(name) {
  830. return properties.hasOwnProperty(name) ? properties[name] : null;
  831. }
  832. function PropertyInfoRecord(name, type, mustUseProperty, attributeName, attributeNamespace, sanitizeURL) {
  833. this.acceptsBooleans = type === BOOLEANISH_STRING || type === BOOLEAN || type === OVERLOADED_BOOLEAN;
  834. this.attributeName = attributeName;
  835. this.attributeNamespace = attributeNamespace;
  836. this.mustUseProperty = mustUseProperty;
  837. this.propertyName = name;
  838. this.type = type;
  839. this.sanitizeURL = sanitizeURL;
  840. } // When adding attributes to this list, be sure to also add them to
  841. // the `possibleStandardNames` module to ensure casing and incorrect
  842. // name warnings.
  843. var properties = {}; // These props are reserved by React. They shouldn't be written to the DOM.
  844. var reservedProps = ['children', 'dangerouslySetInnerHTML', // TODO: This prevents the assignment of defaultValue to regular
  845. // elements (not just inputs). Now that ReactDOMInput assigns to the
  846. // defaultValue property -- do we need this?
  847. 'defaultValue', 'defaultChecked', 'innerHTML', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'style'];
  848. reservedProps.forEach(function (name) {
  849. properties[name] = new PropertyInfoRecord(name, RESERVED, false, // mustUseProperty
  850. name, // attributeName
  851. null, // attributeNamespace
  852. false);
  853. }); // A few React string attributes have a different name.
  854. // This is a mapping from React prop names to the attribute names.
  855. [['acceptCharset', 'accept-charset'], ['className', 'class'], ['htmlFor', 'for'], ['httpEquiv', 'http-equiv']].forEach(function (_ref) {
  856. var name = _ref[0],
  857. attributeName = _ref[1];
  858. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  859. attributeName, // attributeName
  860. null, // attributeNamespace
  861. false);
  862. }); // These are "enumerated" HTML attributes that accept "true" and "false".
  863. // In React, we let users pass `true` and `false` even though technically
  864. // these aren't boolean attributes (they are coerced to strings).
  865. ['contentEditable', 'draggable', 'spellCheck', 'value'].forEach(function (name) {
  866. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  867. name.toLowerCase(), // attributeName
  868. null, // attributeNamespace
  869. false);
  870. }); // These are "enumerated" SVG attributes that accept "true" and "false".
  871. // In React, we let users pass `true` and `false` even though technically
  872. // these aren't boolean attributes (they are coerced to strings).
  873. // Since these are SVG attributes, their attribute names are case-sensitive.
  874. ['autoReverse', 'externalResourcesRequired', 'focusable', 'preserveAlpha'].forEach(function (name) {
  875. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  876. name, // attributeName
  877. null, // attributeNamespace
  878. false);
  879. }); // These are HTML boolean attributes.
  880. ['allowFullScreen', 'async', // Note: there is a special case that prevents it from being written to the DOM
  881. // on the client side because the browsers are inconsistent. Instead we call focus().
  882. 'autoFocus', 'autoPlay', 'controls', 'default', 'defer', 'disabled', 'disablePictureInPicture', 'formNoValidate', 'hidden', 'loop', 'noModule', 'noValidate', 'open', 'playsInline', 'readOnly', 'required', 'reversed', 'scoped', 'seamless', // Microdata
  883. 'itemScope'].forEach(function (name) {
  884. properties[name] = new PropertyInfoRecord(name, BOOLEAN, false, // mustUseProperty
  885. name.toLowerCase(), // attributeName
  886. null, // attributeNamespace
  887. false);
  888. }); // These are the few React props that we set as DOM properties
  889. // rather than attributes. These are all booleans.
  890. ['checked', // Note: `option.selected` is not updated if `select.multiple` is
  891. // disabled with `removeAttribute`. We have special logic for handling this.
  892. 'multiple', 'muted', 'selected' // NOTE: if you add a camelCased prop to this list,
  893. // you'll need to set attributeName to name.toLowerCase()
  894. // instead in the assignment below.
  895. ].forEach(function (name) {
  896. properties[name] = new PropertyInfoRecord(name, BOOLEAN, true, // mustUseProperty
  897. name, // attributeName
  898. null, // attributeNamespace
  899. false);
  900. }); // These are HTML attributes that are "overloaded booleans": they behave like
  901. // booleans, but can also accept a string value.
  902. ['capture', 'download' // NOTE: if you add a camelCased prop to this list,
  903. // you'll need to set attributeName to name.toLowerCase()
  904. // instead in the assignment below.
  905. ].forEach(function (name) {
  906. properties[name] = new PropertyInfoRecord(name, OVERLOADED_BOOLEAN, false, // mustUseProperty
  907. name, // attributeName
  908. null, // attributeNamespace
  909. false);
  910. }); // These are HTML attributes that must be positive numbers.
  911. ['cols', 'rows', 'size', 'span' // NOTE: if you add a camelCased prop to this list,
  912. // you'll need to set attributeName to name.toLowerCase()
  913. // instead in the assignment below.
  914. ].forEach(function (name) {
  915. properties[name] = new PropertyInfoRecord(name, POSITIVE_NUMERIC, false, // mustUseProperty
  916. name, // attributeName
  917. null, // attributeNamespace
  918. false);
  919. }); // These are HTML attributes that must be numbers.
  920. ['rowSpan', 'start'].forEach(function (name) {
  921. properties[name] = new PropertyInfoRecord(name, NUMERIC, false, // mustUseProperty
  922. name.toLowerCase(), // attributeName
  923. null, // attributeNamespace
  924. false);
  925. });
  926. var CAMELIZE = /[\-\:]([a-z])/g;
  927. var capitalize = function (token) {
  928. return token[1].toUpperCase();
  929. }; // This is a list of all SVG attributes that need special casing, namespacing,
  930. // or boolean value assignment. Regular attributes that just accept strings
  931. // and have the same names are omitted, just like in the HTML whitelist.
  932. // Some of these attributes can be hard to find. This list was created by
  933. // scraping the MDN documentation.
  934. ['accent-height', 'alignment-baseline', 'arabic-form', 'baseline-shift', 'cap-height', 'clip-path', 'clip-rule', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'dominant-baseline', 'enable-background', 'fill-opacity', 'fill-rule', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-name', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'horiz-adv-x', 'horiz-origin-x', 'image-rendering', 'letter-spacing', 'lighting-color', 'marker-end', 'marker-mid', 'marker-start', 'overline-position', 'overline-thickness', 'paint-order', 'panose-1', 'pointer-events', 'rendering-intent', 'shape-rendering', 'stop-color', 'stop-opacity', 'strikethrough-position', 'strikethrough-thickness', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-decoration', 'text-rendering', 'underline-position', 'underline-thickness', 'unicode-bidi', 'unicode-range', 'units-per-em', 'v-alphabetic', 'v-hanging', 'v-ideographic', 'v-mathematical', 'vector-effect', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'word-spacing', 'writing-mode', 'xmlns:xlink', 'x-height' // NOTE: if you add a camelCased prop to this list,
  935. // you'll need to set attributeName to name.toLowerCase()
  936. // instead in the assignment below.
  937. ].forEach(function (attributeName) {
  938. var name = attributeName.replace(CAMELIZE, capitalize);
  939. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  940. attributeName, null, // attributeNamespace
  941. false);
  942. }); // String SVG attributes with the xlink namespace.
  943. ['xlink:actuate', 'xlink:arcrole', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type' // NOTE: if you add a camelCased prop to this list,
  944. // you'll need to set attributeName to name.toLowerCase()
  945. // instead in the assignment below.
  946. ].forEach(function (attributeName) {
  947. var name = attributeName.replace(CAMELIZE, capitalize);
  948. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  949. attributeName, 'http://www.w3.org/1999/xlink', false);
  950. }); // String SVG attributes with the xml namespace.
  951. ['xml:base', 'xml:lang', 'xml:space' // NOTE: if you add a camelCased prop to this list,
  952. // you'll need to set attributeName to name.toLowerCase()
  953. // instead in the assignment below.
  954. ].forEach(function (attributeName) {
  955. var name = attributeName.replace(CAMELIZE, capitalize);
  956. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  957. attributeName, 'http://www.w3.org/XML/1998/namespace', false);
  958. }); // These attribute exists both in HTML and SVG.
  959. // The attribute name is case-sensitive in SVG so we can't just use
  960. // the React name like we do for attributes that exist only in HTML.
  961. ['tabIndex', 'crossOrigin'].forEach(function (attributeName) {
  962. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  963. attributeName.toLowerCase(), // attributeName
  964. null, // attributeNamespace
  965. false);
  966. }); // These attributes accept URLs. These must not allow javascript: URLS.
  967. // These will also need to accept Trusted Types object in the future.
  968. var xlinkHref = 'xlinkHref';
  969. properties[xlinkHref] = new PropertyInfoRecord('xlinkHref', STRING, false, // mustUseProperty
  970. 'xlink:href', 'http://www.w3.org/1999/xlink', true);
  971. ['src', 'href', 'action', 'formAction'].forEach(function (attributeName) {
  972. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  973. attributeName.toLowerCase(), // attributeName
  974. null, // attributeNamespace
  975. true);
  976. });
  977. var ReactDebugCurrentFrame = null;
  978. {
  979. ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  980. } // A javascript: URL can contain leading C0 control or \u0020 SPACE,
  981. // and any newline or tab are filtered out as if they're not part of the URL.
  982. // https://url.spec.whatwg.org/#url-parsing
  983. // Tab or newline are defined as \r\n\t:
  984. // https://infra.spec.whatwg.org/#ascii-tab-or-newline
  985. // A C0 control is a code point in the range \u0000 NULL to \u001F
  986. // INFORMATION SEPARATOR ONE, inclusive:
  987. // https://infra.spec.whatwg.org/#c0-control-or-space
  988. /* eslint-disable max-len */
  989. var isJavaScriptProtocol = /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*\:/i;
  990. var didWarn = false;
  991. function sanitizeURL(url) {
  992. {
  993. if (!didWarn && isJavaScriptProtocol.test(url)) {
  994. didWarn = true;
  995. error('A future version of React will block javascript: URLs as a security precaution. ' + 'Use event handlers instead if you can. If you need to generate unsafe HTML try ' + 'using dangerouslySetInnerHTML instead. React was passed %s.', JSON.stringify(url));
  996. }
  997. }
  998. }
  999. /**
  1000. * Get the value for a property on a node. Only used in DEV for SSR validation.
  1001. * The "expected" argument is used as a hint of what the expected value is.
  1002. * Some properties have multiple equivalent values.
  1003. */
  1004. function getValueForProperty(node, name, expected, propertyInfo) {
  1005. {
  1006. if (propertyInfo.mustUseProperty) {
  1007. var propertyName = propertyInfo.propertyName;
  1008. return node[propertyName];
  1009. } else {
  1010. if ( propertyInfo.sanitizeURL) {
  1011. // If we haven't fully disabled javascript: URLs, and if
  1012. // the hydration is successful of a javascript: URL, we
  1013. // still want to warn on the client.
  1014. sanitizeURL('' + expected);
  1015. }
  1016. var attributeName = propertyInfo.attributeName;
  1017. var stringValue = null;
  1018. if (propertyInfo.type === OVERLOADED_BOOLEAN) {
  1019. if (node.hasAttribute(attributeName)) {
  1020. var value = node.getAttribute(attributeName);
  1021. if (value === '') {
  1022. return true;
  1023. }
  1024. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  1025. return value;
  1026. }
  1027. if (value === '' + expected) {
  1028. return expected;
  1029. }
  1030. return value;
  1031. }
  1032. } else if (node.hasAttribute(attributeName)) {
  1033. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  1034. // We had an attribute but shouldn't have had one, so read it
  1035. // for the error message.
  1036. return node.getAttribute(attributeName);
  1037. }
  1038. if (propertyInfo.type === BOOLEAN) {
  1039. // If this was a boolean, it doesn't matter what the value is
  1040. // the fact that we have it is the same as the expected.
  1041. return expected;
  1042. } // Even if this property uses a namespace we use getAttribute
  1043. // because we assume its namespaced name is the same as our config.
  1044. // To use getAttributeNS we need the local name which we don't have
  1045. // in our config atm.
  1046. stringValue = node.getAttribute(attributeName);
  1047. }
  1048. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  1049. return stringValue === null ? expected : stringValue;
  1050. } else if (stringValue === '' + expected) {
  1051. return expected;
  1052. } else {
  1053. return stringValue;
  1054. }
  1055. }
  1056. }
  1057. }
  1058. /**
  1059. * Get the value for a attribute on a node. Only used in DEV for SSR validation.
  1060. * The third argument is used as a hint of what the expected value is. Some
  1061. * attributes have multiple equivalent values.
  1062. */
  1063. function getValueForAttribute(node, name, expected) {
  1064. {
  1065. if (!isAttributeNameSafe(name)) {
  1066. return;
  1067. }
  1068. if (!node.hasAttribute(name)) {
  1069. return expected === undefined ? undefined : null;
  1070. }
  1071. var value = node.getAttribute(name);
  1072. if (value === '' + expected) {
  1073. return expected;
  1074. }
  1075. return value;
  1076. }
  1077. }
  1078. /**
  1079. * Sets the value for a property on a node.
  1080. *
  1081. * @param {DOMElement} node
  1082. * @param {string} name
  1083. * @param {*} value
  1084. */
  1085. function setValueForProperty(node, name, value, isCustomComponentTag) {
  1086. var propertyInfo = getPropertyInfo(name);
  1087. if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
  1088. return;
  1089. }
  1090. if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
  1091. value = null;
  1092. } // If the prop isn't in the special list, treat it as a simple attribute.
  1093. if (isCustomComponentTag || propertyInfo === null) {
  1094. if (isAttributeNameSafe(name)) {
  1095. var _attributeName = name;
  1096. if (value === null) {
  1097. node.removeAttribute(_attributeName);
  1098. } else {
  1099. node.setAttribute(_attributeName, '' + value);
  1100. }
  1101. }
  1102. return;
  1103. }
  1104. var mustUseProperty = propertyInfo.mustUseProperty;
  1105. if (mustUseProperty) {
  1106. var propertyName = propertyInfo.propertyName;
  1107. if (value === null) {
  1108. var type = propertyInfo.type;
  1109. node[propertyName] = type === BOOLEAN ? false : '';
  1110. } else {
  1111. // Contrary to `setAttribute`, object properties are properly
  1112. // `toString`ed by IE8/9.
  1113. node[propertyName] = value;
  1114. }
  1115. return;
  1116. } // The rest are treated as attributes with special cases.
  1117. var attributeName = propertyInfo.attributeName,
  1118. attributeNamespace = propertyInfo.attributeNamespace;
  1119. if (value === null) {
  1120. node.removeAttribute(attributeName);
  1121. } else {
  1122. var _type = propertyInfo.type;
  1123. var attributeValue;
  1124. if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
  1125. // If attribute type is boolean, we know for sure it won't be an execution sink
  1126. // and we won't require Trusted Type here.
  1127. attributeValue = '';
  1128. } else {
  1129. // `setAttribute` with objects becomes only `[object]` in IE8/9,
  1130. // ('' + value) makes it output the correct toString()-value.
  1131. {
  1132. attributeValue = '' + value;
  1133. }
  1134. if (propertyInfo.sanitizeURL) {
  1135. sanitizeURL(attributeValue.toString());
  1136. }
  1137. }
  1138. if (attributeNamespace) {
  1139. node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
  1140. } else {
  1141. node.setAttribute(attributeName, attributeValue);
  1142. }
  1143. }
  1144. }
  1145. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  1146. function describeComponentFrame (name, source, ownerName) {
  1147. var sourceInfo = '';
  1148. if (source) {
  1149. var path = source.fileName;
  1150. var fileName = path.replace(BEFORE_SLASH_RE, '');
  1151. {
  1152. // In DEV, include code for a common special case:
  1153. // prefer "folder/index.js" instead of just "index.js".
  1154. if (/^index\./.test(fileName)) {
  1155. var match = path.match(BEFORE_SLASH_RE);
  1156. if (match) {
  1157. var pathBeforeSlash = match[1];
  1158. if (pathBeforeSlash) {
  1159. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
  1160. fileName = folderName + '/' + fileName;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
  1166. } else if (ownerName) {
  1167. sourceInfo = ' (created by ' + ownerName + ')';
  1168. }
  1169. return '\n in ' + (name || 'Unknown') + sourceInfo;
  1170. }
  1171. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  1172. // nor polyfill, then a plain number is used for performance.
  1173. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  1174. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  1175. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
  1176. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
  1177. var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
  1178. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
  1179. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
  1180. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  1181. var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
  1182. var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
  1183. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
  1184. var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
  1185. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
  1186. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
  1187. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
  1188. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  1189. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  1190. function getIteratorFn(maybeIterable) {
  1191. if (maybeIterable === null || typeof maybeIterable !== 'object') {
  1192. return null;
  1193. }
  1194. var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
  1195. if (typeof maybeIterator === 'function') {
  1196. return maybeIterator;
  1197. }
  1198. return null;
  1199. }
  1200. var Uninitialized = -1;
  1201. var Pending = 0;
  1202. var Resolved = 1;
  1203. var Rejected = 2;
  1204. function refineResolvedLazyComponent(lazyComponent) {
  1205. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  1206. }
  1207. function initializeLazyComponentType(lazyComponent) {
  1208. if (lazyComponent._status === Uninitialized) {
  1209. lazyComponent._status = Pending;
  1210. var ctor = lazyComponent._ctor;
  1211. var thenable = ctor();
  1212. lazyComponent._result = thenable;
  1213. thenable.then(function (moduleObject) {
  1214. if (lazyComponent._status === Pending) {
  1215. var defaultExport = moduleObject.default;
  1216. {
  1217. if (defaultExport === undefined) {
  1218. error('lazy: Expected the result of a dynamic import() call. ' + 'Instead received: %s\n\nYour code should look like: \n ' + "const MyComponent = lazy(() => import('./MyComponent'))", moduleObject);
  1219. }
  1220. }
  1221. lazyComponent._status = Resolved;
  1222. lazyComponent._result = defaultExport;
  1223. }
  1224. }, function (error) {
  1225. if (lazyComponent._status === Pending) {
  1226. lazyComponent._status = Rejected;
  1227. lazyComponent._result = error;
  1228. }
  1229. });
  1230. }
  1231. }
  1232. function getWrappedName(outerType, innerType, wrapperName) {
  1233. var functionName = innerType.displayName || innerType.name || '';
  1234. return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
  1235. }
  1236. function getComponentName(type) {
  1237. if (type == null) {
  1238. // Host root, text node or just invalid type.
  1239. return null;
  1240. }
  1241. {
  1242. if (typeof type.tag === 'number') {
  1243. error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
  1244. }
  1245. }
  1246. if (typeof type === 'function') {
  1247. return type.displayName || type.name || null;
  1248. }
  1249. if (typeof type === 'string') {
  1250. return type;
  1251. }
  1252. switch (type) {
  1253. case REACT_FRAGMENT_TYPE:
  1254. return 'Fragment';
  1255. case REACT_PORTAL_TYPE:
  1256. return 'Portal';
  1257. case REACT_PROFILER_TYPE:
  1258. return "Profiler";
  1259. case REACT_STRICT_MODE_TYPE:
  1260. return 'StrictMode';
  1261. case REACT_SUSPENSE_TYPE:
  1262. return 'Suspense';
  1263. case REACT_SUSPENSE_LIST_TYPE:
  1264. return 'SuspenseList';
  1265. }
  1266. if (typeof type === 'object') {
  1267. switch (type.$$typeof) {
  1268. case REACT_CONTEXT_TYPE:
  1269. return 'Context.Consumer';
  1270. case REACT_PROVIDER_TYPE:
  1271. return 'Context.Provider';
  1272. case REACT_FORWARD_REF_TYPE:
  1273. return getWrappedName(type, type.render, 'ForwardRef');
  1274. case REACT_MEMO_TYPE:
  1275. return getComponentName(type.type);
  1276. case REACT_BLOCK_TYPE:
  1277. return getComponentName(type.render);
  1278. case REACT_LAZY_TYPE:
  1279. {
  1280. var thenable = type;
  1281. var resolvedThenable = refineResolvedLazyComponent(thenable);
  1282. if (resolvedThenable) {
  1283. return getComponentName(resolvedThenable);
  1284. }
  1285. break;
  1286. }
  1287. }
  1288. }
  1289. return null;
  1290. }
  1291. var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
  1292. function describeFiber(fiber) {
  1293. switch (fiber.tag) {
  1294. case HostRoot:
  1295. case HostPortal:
  1296. case HostText:
  1297. case Fragment:
  1298. case ContextProvider:
  1299. case ContextConsumer:
  1300. return '';
  1301. default:
  1302. var owner = fiber._debugOwner;
  1303. var source = fiber._debugSource;
  1304. var name = getComponentName(fiber.type);
  1305. var ownerName = null;
  1306. if (owner) {
  1307. ownerName = getComponentName(owner.type);
  1308. }
  1309. return describeComponentFrame(name, source, ownerName);
  1310. }
  1311. }
  1312. function getStackByFiberInDevAndProd(workInProgress) {
  1313. var info = '';
  1314. var node = workInProgress;
  1315. do {
  1316. info += describeFiber(node);
  1317. node = node.return;
  1318. } while (node);
  1319. return info;
  1320. }
  1321. var current = null;
  1322. var isRendering = false;
  1323. function getCurrentFiberOwnerNameInDevOrNull() {
  1324. {
  1325. if (current === null) {
  1326. return null;
  1327. }
  1328. var owner = current._debugOwner;
  1329. if (owner !== null && typeof owner !== 'undefined') {
  1330. return getComponentName(owner.type);
  1331. }
  1332. }
  1333. return null;
  1334. }
  1335. function getCurrentFiberStackInDev() {
  1336. {
  1337. if (current === null) {
  1338. return '';
  1339. } // Safe because if current fiber exists, we are reconciling,
  1340. // and it is guaranteed to be the work-in-progress version.
  1341. return getStackByFiberInDevAndProd(current);
  1342. }
  1343. }
  1344. function resetCurrentFiber() {
  1345. {
  1346. ReactDebugCurrentFrame$1.getCurrentStack = null;
  1347. current = null;
  1348. isRendering = false;
  1349. }
  1350. }
  1351. function setCurrentFiber(fiber) {
  1352. {
  1353. ReactDebugCurrentFrame$1.getCurrentStack = getCurrentFiberStackInDev;
  1354. current = fiber;
  1355. isRendering = false;
  1356. }
  1357. }
  1358. function setIsRendering(rendering) {
  1359. {
  1360. isRendering = rendering;
  1361. }
  1362. }
  1363. // Flow does not allow string concatenation of most non-string types. To work
  1364. // around this limitation, we use an opaque type that can only be obtained by
  1365. // passing the value through getToStringValue first.
  1366. function toString(value) {
  1367. return '' + value;
  1368. }
  1369. function getToStringValue(value) {
  1370. switch (typeof value) {
  1371. case 'boolean':
  1372. case 'number':
  1373. case 'object':
  1374. case 'string':
  1375. case 'undefined':
  1376. return value;
  1377. default:
  1378. // function, symbol are assigned as empty strings
  1379. return '';
  1380. }
  1381. }
  1382. /**
  1383. * Copyright (c) 2013-present, Facebook, Inc.
  1384. *
  1385. * This source code is licensed under the MIT license found in the
  1386. * LICENSE file in the root directory of this source tree.
  1387. */
  1388. var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
  1389. var ReactPropTypesSecret_1 = ReactPropTypesSecret;
  1390. var printWarning$1 = function() {};
  1391. {
  1392. var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
  1393. var loggedTypeFailures = {};
  1394. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  1395. printWarning$1 = function(text) {
  1396. var message = 'Warning: ' + text;
  1397. if (typeof console !== 'undefined') {
  1398. console.error(message);
  1399. }
  1400. try {
  1401. // --- Welcome to debugging React ---
  1402. // This error was thrown as a convenience so that you can use this stack
  1403. // to find the callsite that caused this warning to fire.
  1404. throw new Error(message);
  1405. } catch (x) {}
  1406. };
  1407. }
  1408. /**
  1409. * Assert that the values match with the type specs.
  1410. * Error messages are memorized and will only be shown once.
  1411. *
  1412. * @param {object} typeSpecs Map of name to a ReactPropType
  1413. * @param {object} values Runtime values that need to be type-checked
  1414. * @param {string} location e.g. "prop", "context", "child context"
  1415. * @param {string} componentName Name of the component for error messages.
  1416. * @param {?Function} getStack Returns the component stack.
  1417. * @private
  1418. */
  1419. function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
  1420. {
  1421. for (var typeSpecName in typeSpecs) {
  1422. if (has(typeSpecs, typeSpecName)) {
  1423. var error;
  1424. // Prop type validation may throw. In case they do, we don't want to
  1425. // fail the render phase where it didn't fail before. So we log it.
  1426. // After these have been cleaned up, we'll let them throw.
  1427. try {
  1428. // This is intentionally an invariant that gets caught. It's the same
  1429. // behavior as without this statement except with a better message.
  1430. if (typeof typeSpecs[typeSpecName] !== 'function') {
  1431. var err = Error(
  1432. (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
  1433. 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
  1434. );
  1435. err.name = 'Invariant Violation';
  1436. throw err;
  1437. }
  1438. error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
  1439. } catch (ex) {
  1440. error = ex;
  1441. }
  1442. if (error && !(error instanceof Error)) {
  1443. printWarning$1(
  1444. (componentName || 'React class') + ': type specification of ' +
  1445. location + ' `' + typeSpecName + '` is invalid; the type checker ' +
  1446. 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
  1447. 'You may have forgotten to pass an argument to the type checker ' +
  1448. 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
  1449. 'shape all require an argument).'
  1450. );
  1451. }
  1452. if (error instanceof Error && !(error.message in loggedTypeFailures)) {
  1453. // Only monitor this failure once because there tends to be a lot of the
  1454. // same error.
  1455. loggedTypeFailures[error.message] = true;
  1456. var stack = getStack ? getStack() : '';
  1457. printWarning$1(
  1458. 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
  1459. );
  1460. }
  1461. }
  1462. }
  1463. }
  1464. }
  1465. /**
  1466. * Resets warning cache when testing.
  1467. *
  1468. * @private
  1469. */
  1470. checkPropTypes.resetWarningCache = function() {
  1471. {
  1472. loggedTypeFailures = {};
  1473. }
  1474. };
  1475. var checkPropTypes_1 = checkPropTypes;
  1476. var ReactDebugCurrentFrame$2 = null;
  1477. var ReactControlledValuePropTypes = {
  1478. checkPropTypes: null
  1479. };
  1480. {
  1481. ReactDebugCurrentFrame$2 = ReactSharedInternals.ReactDebugCurrentFrame;
  1482. var hasReadOnlyValue = {
  1483. button: true,
  1484. checkbox: true,
  1485. image: true,
  1486. hidden: true,
  1487. radio: true,
  1488. reset: true,
  1489. submit: true
  1490. };
  1491. var propTypes = {
  1492. value: function (props, propName, componentName) {
  1493. if (hasReadOnlyValue[props.type] || props.onChange || props.readOnly || props.disabled || props[propName] == null || enableDeprecatedFlareAPI ) {
  1494. return null;
  1495. }
  1496. return new Error('You provided a `value` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultValue`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
  1497. },
  1498. checked: function (props, propName, componentName) {
  1499. if (props.onChange || props.readOnly || props.disabled || props[propName] == null || enableDeprecatedFlareAPI ) {
  1500. return null;
  1501. }
  1502. return new Error('You provided a `checked` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultChecked`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
  1503. }
  1504. };
  1505. /**
  1506. * Provide a linked `value` attribute for controlled forms. You should not use
  1507. * this outside of the ReactDOM controlled form components.
  1508. */
  1509. ReactControlledValuePropTypes.checkPropTypes = function (tagName, props) {
  1510. checkPropTypes_1(propTypes, props, 'prop', tagName, ReactDebugCurrentFrame$2.getStackAddendum);
  1511. };
  1512. }
  1513. function isCheckable(elem) {
  1514. var type = elem.type;
  1515. var nodeName = elem.nodeName;
  1516. return nodeName && nodeName.toLowerCase() === 'input' && (type === 'checkbox' || type === 'radio');
  1517. }
  1518. function getTracker(node) {
  1519. return node._valueTracker;
  1520. }
  1521. function detachTracker(node) {
  1522. node._valueTracker = null;
  1523. }
  1524. function getValueFromNode(node) {
  1525. var value = '';
  1526. if (!node) {
  1527. return value;
  1528. }
  1529. if (isCheckable(node)) {
  1530. value = node.checked ? 'true' : 'false';
  1531. } else {
  1532. value = node.value;
  1533. }
  1534. return value;
  1535. }
  1536. function trackValueOnNode(node) {
  1537. var valueField = isCheckable(node) ? 'checked' : 'value';
  1538. var descriptor = Object.getOwnPropertyDescriptor(node.constructor.prototype, valueField);
  1539. var currentValue = '' + node[valueField]; // if someone has already defined a value or Safari, then bail
  1540. // and don't track value will cause over reporting of changes,
  1541. // but it's better then a hard failure
  1542. // (needed for certain tests that spyOn input values and Safari)
  1543. if (node.hasOwnProperty(valueField) || typeof descriptor === 'undefined' || typeof descriptor.get !== 'function' || typeof descriptor.set !== 'function') {
  1544. return;
  1545. }
  1546. var get = descriptor.get,
  1547. set = descriptor.set;
  1548. Object.defineProperty(node, valueField, {
  1549. configurable: true,
  1550. get: function () {
  1551. return get.call(this);
  1552. },
  1553. set: function (value) {
  1554. currentValue = '' + value;
  1555. set.call(this, value);
  1556. }
  1557. }); // We could've passed this the first time
  1558. // but it triggers a bug in IE11 and Edge 14/15.
  1559. // Calling defineProperty() again should be equivalent.
  1560. // https://github.com/facebook/react/issues/11768
  1561. Object.defineProperty(node, valueField, {
  1562. enumerable: descriptor.enumerable
  1563. });
  1564. var tracker = {
  1565. getValue: function () {
  1566. return currentValue;
  1567. },
  1568. setValue: function (value) {
  1569. currentValue = '' + value;
  1570. },
  1571. stopTracking: function () {
  1572. detachTracker(node);
  1573. delete node[valueField];
  1574. }
  1575. };
  1576. return tracker;
  1577. }
  1578. function track(node) {
  1579. if (getTracker(node)) {
  1580. return;
  1581. } // TODO: Once it's just Fiber we can move this to node._wrapperState
  1582. node._valueTracker = trackValueOnNode(node);
  1583. }
  1584. function updateValueIfChanged(node) {
  1585. if (!node) {
  1586. return false;
  1587. }
  1588. var tracker = getTracker(node); // if there is no tracker at this point it's unlikely
  1589. // that trying again will succeed
  1590. if (!tracker) {
  1591. return true;
  1592. }
  1593. var lastValue = tracker.getValue();
  1594. var nextValue = getValueFromNode(node);
  1595. if (nextValue !== lastValue) {
  1596. tracker.setValue(nextValue);
  1597. return true;
  1598. }
  1599. return false;
  1600. }
  1601. var didWarnValueDefaultValue = false;
  1602. var didWarnCheckedDefaultChecked = false;
  1603. var didWarnControlledToUncontrolled = false;
  1604. var didWarnUncontrolledToControlled = false;
  1605. function isControlled(props) {
  1606. var usesChecked = props.type === 'checkbox' || props.type === 'radio';
  1607. return usesChecked ? props.checked != null : props.value != null;
  1608. }
  1609. /**
  1610. * Implements an <input> host component that allows setting these optional
  1611. * props: `checked`, `value`, `defaultChecked`, and `defaultValue`.
  1612. *
  1613. * If `checked` or `value` are not supplied (or null/undefined), user actions
  1614. * that affect the checked state or value will trigger updates to the element.
  1615. *
  1616. * If they are supplied (and not null/undefined), the rendered element will not
  1617. * trigger updates to the element. Instead, the props must change in order for
  1618. * the rendered element to be updated.
  1619. *
  1620. * The rendered element will be initialized as unchecked (or `defaultChecked`)
  1621. * with an empty value (or `defaultValue`).
  1622. *
  1623. * See http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
  1624. */
  1625. function getHostProps(element, props) {
  1626. var node = element;
  1627. var checked = props.checked;
  1628. var hostProps = _assign({}, props, {
  1629. defaultChecked: undefined,
  1630. defaultValue: undefined,
  1631. value: undefined,
  1632. checked: checked != null ? checked : node._wrapperState.initialChecked
  1633. });
  1634. return hostProps;
  1635. }
  1636. function initWrapperState(element, props) {
  1637. {
  1638. ReactControlledValuePropTypes.checkPropTypes('input', props);
  1639. if (props.checked !== undefined && props.defaultChecked !== undefined && !didWarnCheckedDefaultChecked) {
  1640. error('%s contains an input of type %s with both checked and defaultChecked props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the checked prop, or the defaultChecked prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component', props.type);
  1641. didWarnCheckedDefaultChecked = true;
  1642. }
  1643. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue) {
  1644. error('%s contains an input of type %s with both value and defaultValue props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component', props.type);
  1645. didWarnValueDefaultValue = true;
  1646. }
  1647. }
  1648. var node = element;
  1649. var defaultValue = props.defaultValue == null ? '' : props.defaultValue;
  1650. node._wrapperState = {
  1651. initialChecked: props.checked != null ? props.checked : props.defaultChecked,
  1652. initialValue: getToStringValue(props.value != null ? props.value : defaultValue),
  1653. controlled: isControlled(props)
  1654. };
  1655. }
  1656. function updateChecked(element, props) {
  1657. var node = element;
  1658. var checked = props.checked;
  1659. if (checked != null) {
  1660. setValueForProperty(node, 'checked', checked, false);
  1661. }
  1662. }
  1663. function updateWrapper(element, props) {
  1664. var node = element;
  1665. {
  1666. var controlled = isControlled(props);
  1667. if (!node._wrapperState.controlled && controlled && !didWarnUncontrolledToControlled) {
  1668. error('A component is changing an uncontrolled input of type %s to be controlled. ' + 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', props.type);
  1669. didWarnUncontrolledToControlled = true;
  1670. }
  1671. if (node._wrapperState.controlled && !controlled && !didWarnControlledToUncontrolled) {
  1672. error('A component is changing a controlled input of type %s to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', props.type);
  1673. didWarnControlledToUncontrolled = true;
  1674. }
  1675. }
  1676. updateChecked(element, props);
  1677. var value = getToStringValue(props.value);
  1678. var type = props.type;
  1679. if (value != null) {
  1680. if (type === 'number') {
  1681. if (value === 0 && node.value === '' || // We explicitly want to coerce to number here if possible.
  1682. // eslint-disable-next-line
  1683. node.value != value) {
  1684. node.value = toString(value);
  1685. }
  1686. } else if (node.value !== toString(value)) {
  1687. node.value = toString(value);
  1688. }
  1689. } else if (type === 'submit' || type === 'reset') {
  1690. // Submit/reset inputs need the attribute removed completely to avoid
  1691. // blank-text buttons.
  1692. node.removeAttribute('value');
  1693. return;
  1694. }
  1695. {
  1696. // When syncing the value attribute, the value comes from a cascade of
  1697. // properties:
  1698. // 1. The value React property
  1699. // 2. The defaultValue React property
  1700. // 3. Otherwise there should be no change
  1701. if (props.hasOwnProperty('value')) {
  1702. setDefaultValue(node, props.type, value);
  1703. } else if (props.hasOwnProperty('defaultValue')) {
  1704. setDefaultValue(node, props.type, getToStringValue(props.defaultValue));
  1705. }
  1706. }
  1707. {
  1708. // When syncing the checked attribute, it only changes when it needs
  1709. // to be removed, such as transitioning from a checkbox into a text input
  1710. if (props.checked == null && props.defaultChecked != null) {
  1711. node.defaultChecked = !!props.defaultChecked;
  1712. }
  1713. }
  1714. }
  1715. function postMountWrapper(element, props, isHydrating) {
  1716. var node = element; // Do not assign value if it is already set. This prevents user text input
  1717. // from being lost during SSR hydration.
  1718. if (props.hasOwnProperty('value') || props.hasOwnProperty('defaultValue')) {
  1719. var type = props.type;
  1720. var isButton = type === 'submit' || type === 'reset'; // Avoid setting value attribute on submit/reset inputs as it overrides the
  1721. // default value provided by the browser. See: #12872
  1722. if (isButton && (props.value === undefined || props.value === null)) {
  1723. return;
  1724. }
  1725. var initialValue = toString(node._wrapperState.initialValue); // Do not assign value if it is already set. This prevents user text input
  1726. // from being lost during SSR hydration.
  1727. if (!isHydrating) {
  1728. {
  1729. // When syncing the value attribute, the value property should use
  1730. // the wrapperState._initialValue property. This uses:
  1731. //
  1732. // 1. The value React property when present
  1733. // 2. The defaultValue React property when present
  1734. // 3. An empty string
  1735. if (initialValue !== node.value) {
  1736. node.value = initialValue;
  1737. }
  1738. }
  1739. }
  1740. {
  1741. // Otherwise, the value attribute is synchronized to the property,
  1742. // so we assign defaultValue to the same thing as the value property
  1743. // assignment step above.
  1744. node.defaultValue = initialValue;
  1745. }
  1746. } // Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug
  1747. // this is needed to work around a chrome bug where setting defaultChecked
  1748. // will sometimes influence the value of checked (even after detachment).
  1749. // Reference: https://bugs.chromium.org/p/chromium/issues/detail?id=608416
  1750. // We need to temporarily unset name to avoid disrupting radio button groups.
  1751. var name = node.name;
  1752. if (name !== '') {
  1753. node.name = '';
  1754. }
  1755. {
  1756. // When syncing the checked attribute, both the checked property and
  1757. // attribute are assigned at the same time using defaultChecked. This uses:
  1758. //
  1759. // 1. The checked React property when present
  1760. // 2. The defaultChecked React property when present
  1761. // 3. Otherwise, false
  1762. node.defaultChecked = !node.defaultChecked;
  1763. node.defaultChecked = !!node._wrapperState.initialChecked;
  1764. }
  1765. if (name !== '') {
  1766. node.name = name;
  1767. }
  1768. }
  1769. function restoreControlledState(element, props) {
  1770. var node = element;
  1771. updateWrapper(node, props);
  1772. updateNamedCousins(node, props);
  1773. }
  1774. function updateNamedCousins(rootNode, props) {
  1775. var name = props.name;
  1776. if (props.type === 'radio' && name != null) {
  1777. var queryRoot = rootNode;
  1778. while (queryRoot.parentNode) {
  1779. queryRoot = queryRoot.parentNode;
  1780. } // If `rootNode.form` was non-null, then we could try `form.elements`,
  1781. // but that sometimes behaves strangely in IE8. We could also try using
  1782. // `form.getElementsByName`, but that will only return direct children
  1783. // and won't include inputs that use the HTML5 `form=` attribute. Since
  1784. // the input might not even be in a form. It might not even be in the
  1785. // document. Let's just use the local `querySelectorAll` to ensure we don't
  1786. // miss anything.
  1787. var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]');
  1788. for (var i = 0; i < group.length; i++) {
  1789. var otherNode = group[i];
  1790. if (otherNode === rootNode || otherNode.form !== rootNode.form) {
  1791. continue;
  1792. } // This will throw if radio buttons rendered by different copies of React
  1793. // and the same name are rendered into the same form (same as #1939).
  1794. // That's probably okay; we don't support it just as we don't support
  1795. // mixing React radio buttons with non-React ones.
  1796. var otherProps = getFiberCurrentPropsFromNode$1(otherNode);
  1797. if (!otherProps) {
  1798. {
  1799. throw Error( "ReactDOMInput: Mixing React and non-React radio inputs with the same `name` is not supported." );
  1800. }
  1801. } // We need update the tracked value on the named cousin since the value
  1802. // was changed but the input saw no event or value set
  1803. updateValueIfChanged(otherNode); // If this is a controlled radio button group, forcing the input that
  1804. // was previously checked to update will cause it to be come re-checked
  1805. // as appropriate.
  1806. updateWrapper(otherNode, otherProps);
  1807. }
  1808. }
  1809. } // In Chrome, assigning defaultValue to certain input types triggers input validation.
  1810. // For number inputs, the display value loses trailing decimal points. For email inputs,
  1811. // Chrome raises "The specified value <x> is not a valid email address".
  1812. //
  1813. // Here we check to see if the defaultValue has actually changed, avoiding these problems
  1814. // when the user is inputting text
  1815. //
  1816. // https://github.com/facebook/react/issues/7253
  1817. function setDefaultValue(node, type, value) {
  1818. if ( // Focused number inputs synchronize on blur. See ChangeEventPlugin.js
  1819. type !== 'number' || node.ownerDocument.activeElement !== node) {
  1820. if (value == null) {
  1821. node.defaultValue = toString(node._wrapperState.initialValue);
  1822. } else if (node.defaultValue !== toString(value)) {
  1823. node.defaultValue = toString(value);
  1824. }
  1825. }
  1826. }
  1827. var didWarnSelectedSetOnOption = false;
  1828. var didWarnInvalidChild = false;
  1829. function flattenChildren(children) {
  1830. var content = ''; // Flatten children. We'll warn if they are invalid
  1831. // during validateProps() which runs for hydration too.
  1832. // Note that this would throw on non-element objects.
  1833. // Elements are stringified (which is normally irrelevant
  1834. // but matters for <fbt>).
  1835. React.Children.forEach(children, function (child) {
  1836. if (child == null) {
  1837. return;
  1838. }
  1839. content += child; // Note: we don't warn about invalid children here.
  1840. // Instead, this is done separately below so that
  1841. // it happens during the hydration codepath too.
  1842. });
  1843. return content;
  1844. }
  1845. /**
  1846. * Implements an <option> host component that warns when `selected` is set.
  1847. */
  1848. function validateProps(element, props) {
  1849. {
  1850. // This mirrors the codepath above, but runs for hydration too.
  1851. // Warn about invalid children here so that client and hydration are consistent.
  1852. // TODO: this seems like it could cause a DEV-only throw for hydration
  1853. // if children contains a non-element object. We should try to avoid that.
  1854. if (typeof props.children === 'object' && props.children !== null) {
  1855. React.Children.forEach(props.children, function (child) {
  1856. if (child == null) {
  1857. return;
  1858. }
  1859. if (typeof child === 'string' || typeof child === 'number') {
  1860. return;
  1861. }
  1862. if (typeof child.type !== 'string') {
  1863. return;
  1864. }
  1865. if (!didWarnInvalidChild) {
  1866. didWarnInvalidChild = true;
  1867. error('Only strings and numbers are supported as <option> children.');
  1868. }
  1869. });
  1870. } // TODO: Remove support for `selected` in <option>.
  1871. if (props.selected != null && !didWarnSelectedSetOnOption) {
  1872. error('Use the `defaultValue` or `value` props on <select> instead of ' + 'setting `selected` on <option>.');
  1873. didWarnSelectedSetOnOption = true;
  1874. }
  1875. }
  1876. }
  1877. function postMountWrapper$1(element, props) {
  1878. // value="" should make a value attribute (#6219)
  1879. if (props.value != null) {
  1880. element.setAttribute('value', toString(getToStringValue(props.value)));
  1881. }
  1882. }
  1883. function getHostProps$1(element, props) {
  1884. var hostProps = _assign({
  1885. children: undefined
  1886. }, props);
  1887. var content = flattenChildren(props.children);
  1888. if (content) {
  1889. hostProps.children = content;
  1890. }
  1891. return hostProps;
  1892. }
  1893. var didWarnValueDefaultValue$1;
  1894. {
  1895. didWarnValueDefaultValue$1 = false;
  1896. }
  1897. function getDeclarationErrorAddendum() {
  1898. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  1899. if (ownerName) {
  1900. return '\n\nCheck the render method of `' + ownerName + '`.';
  1901. }
  1902. return '';
  1903. }
  1904. var valuePropNames = ['value', 'defaultValue'];
  1905. /**
  1906. * Validation function for `value` and `defaultValue`.
  1907. */
  1908. function checkSelectPropTypes(props) {
  1909. {
  1910. ReactControlledValuePropTypes.checkPropTypes('select', props);
  1911. for (var i = 0; i < valuePropNames.length; i++) {
  1912. var propName = valuePropNames[i];
  1913. if (props[propName] == null) {
  1914. continue;
  1915. }
  1916. var isArray = Array.isArray(props[propName]);
  1917. if (props.multiple && !isArray) {
  1918. error('The `%s` prop supplied to <select> must be an array if ' + '`multiple` is true.%s', propName, getDeclarationErrorAddendum());
  1919. } else if (!props.multiple && isArray) {
  1920. error('The `%s` prop supplied to <select> must be a scalar ' + 'value if `multiple` is false.%s', propName, getDeclarationErrorAddendum());
  1921. }
  1922. }
  1923. }
  1924. }
  1925. function updateOptions(node, multiple, propValue, setDefaultSelected) {
  1926. var options = node.options;
  1927. if (multiple) {
  1928. var selectedValues = propValue;
  1929. var selectedValue = {};
  1930. for (var i = 0; i < selectedValues.length; i++) {
  1931. // Prefix to avoid chaos with special keys.
  1932. selectedValue['$' + selectedValues[i]] = true;
  1933. }
  1934. for (var _i = 0; _i < options.length; _i++) {
  1935. var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
  1936. if (options[_i].selected !== selected) {
  1937. options[_i].selected = selected;
  1938. }
  1939. if (selected && setDefaultSelected) {
  1940. options[_i].defaultSelected = true;
  1941. }
  1942. }
  1943. } else {
  1944. // Do not set `select.value` as exact behavior isn't consistent across all
  1945. // browsers for all cases.
  1946. var _selectedValue = toString(getToStringValue(propValue));
  1947. var defaultSelected = null;
  1948. for (var _i2 = 0; _i2 < options.length; _i2++) {
  1949. if (options[_i2].value === _selectedValue) {
  1950. options[_i2].selected = true;
  1951. if (setDefaultSelected) {
  1952. options[_i2].defaultSelected = true;
  1953. }
  1954. return;
  1955. }
  1956. if (defaultSelected === null && !options[_i2].disabled) {
  1957. defaultSelected = options[_i2];
  1958. }
  1959. }
  1960. if (defaultSelected !== null) {
  1961. defaultSelected.selected = true;
  1962. }
  1963. }
  1964. }
  1965. /**
  1966. * Implements a <select> host component that allows optionally setting the
  1967. * props `value` and `defaultValue`. If `multiple` is false, the prop must be a
  1968. * stringable. If `multiple` is true, the prop must be an array of stringables.
  1969. *
  1970. * If `value` is not supplied (or null/undefined), user actions that change the
  1971. * selected option will trigger updates to the rendered options.
  1972. *
  1973. * If it is supplied (and not null/undefined), the rendered options will not
  1974. * update in response to user actions. Instead, the `value` prop must change in
  1975. * order for the rendered options to update.
  1976. *
  1977. * If `defaultValue` is provided, any options with the supplied values will be
  1978. * selected.
  1979. */
  1980. function getHostProps$2(element, props) {
  1981. return _assign({}, props, {
  1982. value: undefined
  1983. });
  1984. }
  1985. function initWrapperState$1(element, props) {
  1986. var node = element;
  1987. {
  1988. checkSelectPropTypes(props);
  1989. }
  1990. node._wrapperState = {
  1991. wasMultiple: !!props.multiple
  1992. };
  1993. {
  1994. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue$1) {
  1995. error('Select elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled select ' + 'element and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components');
  1996. didWarnValueDefaultValue$1 = true;
  1997. }
  1998. }
  1999. }
  2000. function postMountWrapper$2(element, props) {
  2001. var node = element;
  2002. node.multiple = !!props.multiple;
  2003. var value = props.value;
  2004. if (value != null) {
  2005. updateOptions(node, !!props.multiple, value, false);
  2006. } else if (props.defaultValue != null) {
  2007. updateOptions(node, !!props.multiple, props.defaultValue, true);
  2008. }
  2009. }
  2010. function postUpdateWrapper(element, props) {
  2011. var node = element;
  2012. var wasMultiple = node._wrapperState.wasMultiple;
  2013. node._wrapperState.wasMultiple = !!props.multiple;
  2014. var value = props.value;
  2015. if (value != null) {
  2016. updateOptions(node, !!props.multiple, value, false);
  2017. } else if (wasMultiple !== !!props.multiple) {
  2018. // For simplicity, reapply `defaultValue` if `multiple` is toggled.
  2019. if (props.defaultValue != null) {
  2020. updateOptions(node, !!props.multiple, props.defaultValue, true);
  2021. } else {
  2022. // Revert the select back to its default unselected state.
  2023. updateOptions(node, !!props.multiple, props.multiple ? [] : '', false);
  2024. }
  2025. }
  2026. }
  2027. function restoreControlledState$1(element, props) {
  2028. var node = element;
  2029. var value = props.value;
  2030. if (value != null) {
  2031. updateOptions(node, !!props.multiple, value, false);
  2032. }
  2033. }
  2034. var didWarnValDefaultVal = false;
  2035. /**
  2036. * Implements a <textarea> host component that allows setting `value`, and
  2037. * `defaultValue`. This differs from the traditional DOM API because value is
  2038. * usually set as PCDATA children.
  2039. *
  2040. * If `value` is not supplied (or null/undefined), user actions that affect the
  2041. * value will trigger updates to the element.
  2042. *
  2043. * If `value` is supplied (and not null/undefined), the rendered element will
  2044. * not trigger updates to the element. Instead, the `value` prop must change in
  2045. * order for the rendered element to be updated.
  2046. *
  2047. * The rendered element will be initialized with an empty value, the prop
  2048. * `defaultValue` if specified, or the children content (deprecated).
  2049. */
  2050. function getHostProps$3(element, props) {
  2051. var node = element;
  2052. if (!(props.dangerouslySetInnerHTML == null)) {
  2053. {
  2054. throw Error( "`dangerouslySetInnerHTML` does not make sense on <textarea>." );
  2055. }
  2056. } // Always set children to the same thing. In IE9, the selection range will
  2057. // get reset if `textContent` is mutated. We could add a check in setTextContent
  2058. // to only set the value if/when the value differs from the node value (which would
  2059. // completely solve this IE9 bug), but Sebastian+Sophie seemed to like this
  2060. // solution. The value can be a boolean or object so that's why it's forced
  2061. // to be a string.
  2062. var hostProps = _assign({}, props, {
  2063. value: undefined,
  2064. defaultValue: undefined,
  2065. children: toString(node._wrapperState.initialValue)
  2066. });
  2067. return hostProps;
  2068. }
  2069. function initWrapperState$2(element, props) {
  2070. var node = element;
  2071. {
  2072. ReactControlledValuePropTypes.checkPropTypes('textarea', props);
  2073. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValDefaultVal) {
  2074. error('%s contains a textarea with both value and defaultValue props. ' + 'Textarea elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled textarea ' + 'and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component');
  2075. didWarnValDefaultVal = true;
  2076. }
  2077. }
  2078. var initialValue = props.value; // Only bother fetching default value if we're going to use it
  2079. if (initialValue == null) {
  2080. var children = props.children,
  2081. defaultValue = props.defaultValue;
  2082. if (children != null) {
  2083. {
  2084. error('Use the `defaultValue` or `value` props instead of setting ' + 'children on <textarea>.');
  2085. }
  2086. {
  2087. if (!(defaultValue == null)) {
  2088. {
  2089. throw Error( "If you supply `defaultValue` on a <textarea>, do not pass children." );
  2090. }
  2091. }
  2092. if (Array.isArray(children)) {
  2093. if (!(children.length <= 1)) {
  2094. {
  2095. throw Error( "<textarea> can only have at most one child." );
  2096. }
  2097. }
  2098. children = children[0];
  2099. }
  2100. defaultValue = children;
  2101. }
  2102. }
  2103. if (defaultValue == null) {
  2104. defaultValue = '';
  2105. }
  2106. initialValue = defaultValue;
  2107. }
  2108. node._wrapperState = {
  2109. initialValue: getToStringValue(initialValue)
  2110. };
  2111. }
  2112. function updateWrapper$1(element, props) {
  2113. var node = element;
  2114. var value = getToStringValue(props.value);
  2115. var defaultValue = getToStringValue(props.defaultValue);
  2116. if (value != null) {
  2117. // Cast `value` to a string to ensure the value is set correctly. While
  2118. // browsers typically do this as necessary, jsdom doesn't.
  2119. var newValue = toString(value); // To avoid side effects (such as losing text selection), only set value if changed
  2120. if (newValue !== node.value) {
  2121. node.value = newValue;
  2122. }
  2123. if (props.defaultValue == null && node.defaultValue !== newValue) {
  2124. node.defaultValue = newValue;
  2125. }
  2126. }
  2127. if (defaultValue != null) {
  2128. node.defaultValue = toString(defaultValue);
  2129. }
  2130. }
  2131. function postMountWrapper$3(element, props) {
  2132. var node = element; // This is in postMount because we need access to the DOM node, which is not
  2133. // available until after the component has mounted.
  2134. var textContent = node.textContent; // Only set node.value if textContent is equal to the expected
  2135. // initial value. In IE10/IE11 there is a bug where the placeholder attribute
  2136. // will populate textContent as well.
  2137. // https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
  2138. if (textContent === node._wrapperState.initialValue) {
  2139. if (textContent !== '' && textContent !== null) {
  2140. node.value = textContent;
  2141. }
  2142. }
  2143. }
  2144. function restoreControlledState$2(element, props) {
  2145. // DOM component is still mounted; update
  2146. updateWrapper$1(element, props);
  2147. }
  2148. var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
  2149. var MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
  2150. var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
  2151. var Namespaces = {
  2152. html: HTML_NAMESPACE,
  2153. mathml: MATH_NAMESPACE,
  2154. svg: SVG_NAMESPACE
  2155. }; // Assumes there is no parent namespace.
  2156. function getIntrinsicNamespace(type) {
  2157. switch (type) {
  2158. case 'svg':
  2159. return SVG_NAMESPACE;
  2160. case 'math':
  2161. return MATH_NAMESPACE;
  2162. default:
  2163. return HTML_NAMESPACE;
  2164. }
  2165. }
  2166. function getChildNamespace(parentNamespace, type) {
  2167. if (parentNamespace == null || parentNamespace === HTML_NAMESPACE) {
  2168. // No (or default) parent namespace: potential entry point.
  2169. return getIntrinsicNamespace(type);
  2170. }
  2171. if (parentNamespace === SVG_NAMESPACE && type === 'foreignObject') {
  2172. // We're leaving SVG.
  2173. return HTML_NAMESPACE;
  2174. } // By default, pass namespace below.
  2175. return parentNamespace;
  2176. }
  2177. /* globals MSApp */
  2178. /**
  2179. * Create a function which has 'unsafe' privileges (required by windows8 apps)
  2180. */
  2181. var createMicrosoftUnsafeLocalFunction = function (func) {
  2182. if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
  2183. return function (arg0, arg1, arg2, arg3) {
  2184. MSApp.execUnsafeLocalFunction(function () {
  2185. return func(arg0, arg1, arg2, arg3);
  2186. });
  2187. };
  2188. } else {
  2189. return func;
  2190. }
  2191. };
  2192. var reusableSVGContainer;
  2193. /**
  2194. * Set the innerHTML property of a node
  2195. *
  2196. * @param {DOMElement} node
  2197. * @param {string} html
  2198. * @internal
  2199. */
  2200. var setInnerHTML = createMicrosoftUnsafeLocalFunction(function (node, html) {
  2201. if (node.namespaceURI === Namespaces.svg) {
  2202. if (!('innerHTML' in node)) {
  2203. // IE does not have innerHTML for SVG nodes, so instead we inject the
  2204. // new markup in a temp node and then move the child nodes across into
  2205. // the target node
  2206. reusableSVGContainer = reusableSVGContainer || document.createElement('div');
  2207. reusableSVGContainer.innerHTML = '<svg>' + html.valueOf().toString() + '</svg>';
  2208. var svgNode = reusableSVGContainer.firstChild;
  2209. while (node.firstChild) {
  2210. node.removeChild(node.firstChild);
  2211. }
  2212. while (svgNode.firstChild) {
  2213. node.appendChild(svgNode.firstChild);
  2214. }
  2215. return;
  2216. }
  2217. }
  2218. node.innerHTML = html;
  2219. });
  2220. /**
  2221. * HTML nodeType values that represent the type of the node
  2222. */
  2223. var ELEMENT_NODE = 1;
  2224. var TEXT_NODE = 3;
  2225. var COMMENT_NODE = 8;
  2226. var DOCUMENT_NODE = 9;
  2227. var DOCUMENT_FRAGMENT_NODE = 11;
  2228. /**
  2229. * Set the textContent property of a node. For text updates, it's faster
  2230. * to set the `nodeValue` of the Text node directly instead of using
  2231. * `.textContent` which will remove the existing node and create a new one.
  2232. *
  2233. * @param {DOMElement} node
  2234. * @param {string} text
  2235. * @internal
  2236. */
  2237. var setTextContent = function (node, text) {
  2238. if (text) {
  2239. var firstChild = node.firstChild;
  2240. if (firstChild && firstChild === node.lastChild && firstChild.nodeType === TEXT_NODE) {
  2241. firstChild.nodeValue = text;
  2242. return;
  2243. }
  2244. }
  2245. node.textContent = text;
  2246. };
  2247. // Do not use the below two methods directly!
  2248. // Instead use constants exported from DOMTopLevelEventTypes in ReactDOM.
  2249. // (It is the only module that is allowed to access these methods.)
  2250. function unsafeCastStringToDOMTopLevelType(topLevelType) {
  2251. return topLevelType;
  2252. }
  2253. function unsafeCastDOMTopLevelTypeToString(topLevelType) {
  2254. return topLevelType;
  2255. }
  2256. /**
  2257. * Generate a mapping of standard vendor prefixes using the defined style property and event name.
  2258. *
  2259. * @param {string} styleProp
  2260. * @param {string} eventName
  2261. * @returns {object}
  2262. */
  2263. function makePrefixMap(styleProp, eventName) {
  2264. var prefixes = {};
  2265. prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
  2266. prefixes['Webkit' + styleProp] = 'webkit' + eventName;
  2267. prefixes['Moz' + styleProp] = 'moz' + eventName;
  2268. return prefixes;
  2269. }
  2270. /**
  2271. * A list of event names to a configurable list of vendor prefixes.
  2272. */
  2273. var vendorPrefixes = {
  2274. animationend: makePrefixMap('Animation', 'AnimationEnd'),
  2275. animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
  2276. animationstart: makePrefixMap('Animation', 'AnimationStart'),
  2277. transitionend: makePrefixMap('Transition', 'TransitionEnd')
  2278. };
  2279. /**
  2280. * Event names that have already been detected and prefixed (if applicable).
  2281. */
  2282. var prefixedEventNames = {};
  2283. /**
  2284. * Element to check for prefixes on.
  2285. */
  2286. var style = {};
  2287. /**
  2288. * Bootstrap if a DOM exists.
  2289. */
  2290. if (canUseDOM) {
  2291. style = document.createElement('div').style; // On some platforms, in particular some releases of Android 4.x,
  2292. // the un-prefixed "animation" and "transition" properties are defined on the
  2293. // style object but the events that fire will still be prefixed, so we need
  2294. // to check if the un-prefixed events are usable, and if not remove them from the map.
  2295. if (!('AnimationEvent' in window)) {
  2296. delete vendorPrefixes.animationend.animation;
  2297. delete vendorPrefixes.animationiteration.animation;
  2298. delete vendorPrefixes.animationstart.animation;
  2299. } // Same as above
  2300. if (!('TransitionEvent' in window)) {
  2301. delete vendorPrefixes.transitionend.transition;
  2302. }
  2303. }
  2304. /**
  2305. * Attempts to determine the correct vendor prefixed event name.
  2306. *
  2307. * @param {string} eventName
  2308. * @returns {string}
  2309. */
  2310. function getVendorPrefixedEventName(eventName) {
  2311. if (prefixedEventNames[eventName]) {
  2312. return prefixedEventNames[eventName];
  2313. } else if (!vendorPrefixes[eventName]) {
  2314. return eventName;
  2315. }
  2316. var prefixMap = vendorPrefixes[eventName];
  2317. for (var styleProp in prefixMap) {
  2318. if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
  2319. return prefixedEventNames[eventName] = prefixMap[styleProp];
  2320. }
  2321. }
  2322. return eventName;
  2323. }
  2324. /**
  2325. * To identify top level events in ReactDOM, we use constants defined by this
  2326. * module. This is the only module that uses the unsafe* methods to express
  2327. * that the constants actually correspond to the browser event names. This lets
  2328. * us save some bundle size by avoiding a top level type -> event name map.
  2329. * The rest of ReactDOM code should import top level types from this file.
  2330. */
  2331. var TOP_ABORT = unsafeCastStringToDOMTopLevelType('abort');
  2332. var TOP_ANIMATION_END = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationend'));
  2333. var TOP_ANIMATION_ITERATION = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationiteration'));
  2334. var TOP_ANIMATION_START = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationstart'));
  2335. var TOP_BLUR = unsafeCastStringToDOMTopLevelType('blur');
  2336. var TOP_CAN_PLAY = unsafeCastStringToDOMTopLevelType('canplay');
  2337. var TOP_CAN_PLAY_THROUGH = unsafeCastStringToDOMTopLevelType('canplaythrough');
  2338. var TOP_CANCEL = unsafeCastStringToDOMTopLevelType('cancel');
  2339. var TOP_CHANGE = unsafeCastStringToDOMTopLevelType('change');
  2340. var TOP_CLICK = unsafeCastStringToDOMTopLevelType('click');
  2341. var TOP_CLOSE = unsafeCastStringToDOMTopLevelType('close');
  2342. var TOP_COMPOSITION_END = unsafeCastStringToDOMTopLevelType('compositionend');
  2343. var TOP_COMPOSITION_START = unsafeCastStringToDOMTopLevelType('compositionstart');
  2344. var TOP_COMPOSITION_UPDATE = unsafeCastStringToDOMTopLevelType('compositionupdate');
  2345. var TOP_CONTEXT_MENU = unsafeCastStringToDOMTopLevelType('contextmenu');
  2346. var TOP_COPY = unsafeCastStringToDOMTopLevelType('copy');
  2347. var TOP_CUT = unsafeCastStringToDOMTopLevelType('cut');
  2348. var TOP_DOUBLE_CLICK = unsafeCastStringToDOMTopLevelType('dblclick');
  2349. var TOP_AUX_CLICK = unsafeCastStringToDOMTopLevelType('auxclick');
  2350. var TOP_DRAG = unsafeCastStringToDOMTopLevelType('drag');
  2351. var TOP_DRAG_END = unsafeCastStringToDOMTopLevelType('dragend');
  2352. var TOP_DRAG_ENTER = unsafeCastStringToDOMTopLevelType('dragenter');
  2353. var TOP_DRAG_EXIT = unsafeCastStringToDOMTopLevelType('dragexit');
  2354. var TOP_DRAG_LEAVE = unsafeCastStringToDOMTopLevelType('dragleave');
  2355. var TOP_DRAG_OVER = unsafeCastStringToDOMTopLevelType('dragover');
  2356. var TOP_DRAG_START = unsafeCastStringToDOMTopLevelType('dragstart');
  2357. var TOP_DROP = unsafeCastStringToDOMTopLevelType('drop');
  2358. var TOP_DURATION_CHANGE = unsafeCastStringToDOMTopLevelType('durationchange');
  2359. var TOP_EMPTIED = unsafeCastStringToDOMTopLevelType('emptied');
  2360. var TOP_ENCRYPTED = unsafeCastStringToDOMTopLevelType('encrypted');
  2361. var TOP_ENDED = unsafeCastStringToDOMTopLevelType('ended');
  2362. var TOP_ERROR = unsafeCastStringToDOMTopLevelType('error');
  2363. var TOP_FOCUS = unsafeCastStringToDOMTopLevelType('focus');
  2364. var TOP_GOT_POINTER_CAPTURE = unsafeCastStringToDOMTopLevelType('gotpointercapture');
  2365. var TOP_INPUT = unsafeCastStringToDOMTopLevelType('input');
  2366. var TOP_INVALID = unsafeCastStringToDOMTopLevelType('invalid');
  2367. var TOP_KEY_DOWN = unsafeCastStringToDOMTopLevelType('keydown');
  2368. var TOP_KEY_PRESS = unsafeCastStringToDOMTopLevelType('keypress');
  2369. var TOP_KEY_UP = unsafeCastStringToDOMTopLevelType('keyup');
  2370. var TOP_LOAD = unsafeCastStringToDOMTopLevelType('load');
  2371. var TOP_LOAD_START = unsafeCastStringToDOMTopLevelType('loadstart');
  2372. var TOP_LOADED_DATA = unsafeCastStringToDOMTopLevelType('loadeddata');
  2373. var TOP_LOADED_METADATA = unsafeCastStringToDOMTopLevelType('loadedmetadata');
  2374. var TOP_LOST_POINTER_CAPTURE = unsafeCastStringToDOMTopLevelType('lostpointercapture');
  2375. var TOP_MOUSE_DOWN = unsafeCastStringToDOMTopLevelType('mousedown');
  2376. var TOP_MOUSE_MOVE = unsafeCastStringToDOMTopLevelType('mousemove');
  2377. var TOP_MOUSE_OUT = unsafeCastStringToDOMTopLevelType('mouseout');
  2378. var TOP_MOUSE_OVER = unsafeCastStringToDOMTopLevelType('mouseover');
  2379. var TOP_MOUSE_UP = unsafeCastStringToDOMTopLevelType('mouseup');
  2380. var TOP_PASTE = unsafeCastStringToDOMTopLevelType('paste');
  2381. var TOP_PAUSE = unsafeCastStringToDOMTopLevelType('pause');
  2382. var TOP_PLAY = unsafeCastStringToDOMTopLevelType('play');
  2383. var TOP_PLAYING = unsafeCastStringToDOMTopLevelType('playing');
  2384. var TOP_POINTER_CANCEL = unsafeCastStringToDOMTopLevelType('pointercancel');
  2385. var TOP_POINTER_DOWN = unsafeCastStringToDOMTopLevelType('pointerdown');
  2386. var TOP_POINTER_MOVE = unsafeCastStringToDOMTopLevelType('pointermove');
  2387. var TOP_POINTER_OUT = unsafeCastStringToDOMTopLevelType('pointerout');
  2388. var TOP_POINTER_OVER = unsafeCastStringToDOMTopLevelType('pointerover');
  2389. var TOP_POINTER_UP = unsafeCastStringToDOMTopLevelType('pointerup');
  2390. var TOP_PROGRESS = unsafeCastStringToDOMTopLevelType('progress');
  2391. var TOP_RATE_CHANGE = unsafeCastStringToDOMTopLevelType('ratechange');
  2392. var TOP_RESET = unsafeCastStringToDOMTopLevelType('reset');
  2393. var TOP_SCROLL = unsafeCastStringToDOMTopLevelType('scroll');
  2394. var TOP_SEEKED = unsafeCastStringToDOMTopLevelType('seeked');
  2395. var TOP_SEEKING = unsafeCastStringToDOMTopLevelType('seeking');
  2396. var TOP_SELECTION_CHANGE = unsafeCastStringToDOMTopLevelType('selectionchange');
  2397. var TOP_STALLED = unsafeCastStringToDOMTopLevelType('stalled');
  2398. var TOP_SUBMIT = unsafeCastStringToDOMTopLevelType('submit');
  2399. var TOP_SUSPEND = unsafeCastStringToDOMTopLevelType('suspend');
  2400. var TOP_TEXT_INPUT = unsafeCastStringToDOMTopLevelType('textInput');
  2401. var TOP_TIME_UPDATE = unsafeCastStringToDOMTopLevelType('timeupdate');
  2402. var TOP_TOGGLE = unsafeCastStringToDOMTopLevelType('toggle');
  2403. var TOP_TOUCH_CANCEL = unsafeCastStringToDOMTopLevelType('touchcancel');
  2404. var TOP_TOUCH_END = unsafeCastStringToDOMTopLevelType('touchend');
  2405. var TOP_TOUCH_MOVE = unsafeCastStringToDOMTopLevelType('touchmove');
  2406. var TOP_TOUCH_START = unsafeCastStringToDOMTopLevelType('touchstart');
  2407. var TOP_TRANSITION_END = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('transitionend'));
  2408. var TOP_VOLUME_CHANGE = unsafeCastStringToDOMTopLevelType('volumechange');
  2409. var TOP_WAITING = unsafeCastStringToDOMTopLevelType('waiting');
  2410. var TOP_WHEEL = unsafeCastStringToDOMTopLevelType('wheel'); // List of events that need to be individually attached to media elements.
  2411. // Note that events in this list will *not* be listened to at the top level
  2412. // unless they're explicitly whitelisted in `ReactBrowserEventEmitter.listenTo`.
  2413. var mediaEventTypes = [TOP_ABORT, TOP_CAN_PLAY, TOP_CAN_PLAY_THROUGH, TOP_DURATION_CHANGE, TOP_EMPTIED, TOP_ENCRYPTED, TOP_ENDED, TOP_ERROR, TOP_LOADED_DATA, TOP_LOADED_METADATA, TOP_LOAD_START, TOP_PAUSE, TOP_PLAY, TOP_PLAYING, TOP_PROGRESS, TOP_RATE_CHANGE, TOP_SEEKED, TOP_SEEKING, TOP_STALLED, TOP_SUSPEND, TOP_TIME_UPDATE, TOP_VOLUME_CHANGE, TOP_WAITING];
  2414. function getRawEventName(topLevelType) {
  2415. return unsafeCastDOMTopLevelTypeToString(topLevelType);
  2416. }
  2417. var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; // prettier-ignore
  2418. var elementListenerMap = new PossiblyWeakMap();
  2419. function getListenerMapForElement(element) {
  2420. var listenerMap = elementListenerMap.get(element);
  2421. if (listenerMap === undefined) {
  2422. listenerMap = new Map();
  2423. elementListenerMap.set(element, listenerMap);
  2424. }
  2425. return listenerMap;
  2426. }
  2427. /**
  2428. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  2429. * instance (key) and the internal representation (value). This allows public
  2430. * methods to accept the user facing instance as an argument and map them back
  2431. * to internal methods.
  2432. *
  2433. * Note that this module is currently shared and assumed to be stateless.
  2434. * If this becomes an actual Map, that will break.
  2435. */
  2436. function get(key) {
  2437. return key._reactInternalFiber;
  2438. }
  2439. function has$1(key) {
  2440. return key._reactInternalFiber !== undefined;
  2441. }
  2442. function set(key, value) {
  2443. key._reactInternalFiber = value;
  2444. }
  2445. // Don't change these two values. They're used by React Dev Tools.
  2446. var NoEffect =
  2447. /* */
  2448. 0;
  2449. var PerformedWork =
  2450. /* */
  2451. 1; // You can change the rest (and add more).
  2452. var Placement =
  2453. /* */
  2454. 2;
  2455. var Update =
  2456. /* */
  2457. 4;
  2458. var PlacementAndUpdate =
  2459. /* */
  2460. 6;
  2461. var Deletion =
  2462. /* */
  2463. 8;
  2464. var ContentReset =
  2465. /* */
  2466. 16;
  2467. var Callback =
  2468. /* */
  2469. 32;
  2470. var DidCapture =
  2471. /* */
  2472. 64;
  2473. var Ref =
  2474. /* */
  2475. 128;
  2476. var Snapshot =
  2477. /* */
  2478. 256;
  2479. var Passive =
  2480. /* */
  2481. 512;
  2482. var Hydrating =
  2483. /* */
  2484. 1024;
  2485. var HydratingAndUpdate =
  2486. /* */
  2487. 1028; // Passive & Update & Callback & Ref & Snapshot
  2488. var LifecycleEffectMask =
  2489. /* */
  2490. 932; // Union of all host effects
  2491. var HostEffectMask =
  2492. /* */
  2493. 2047;
  2494. var Incomplete =
  2495. /* */
  2496. 2048;
  2497. var ShouldCapture =
  2498. /* */
  2499. 4096;
  2500. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  2501. function getNearestMountedFiber(fiber) {
  2502. var node = fiber;
  2503. var nearestMounted = fiber;
  2504. if (!fiber.alternate) {
  2505. // If there is no alternate, this might be a new tree that isn't inserted
  2506. // yet. If it is, then it will have a pending insertion effect on it.
  2507. var nextNode = node;
  2508. do {
  2509. node = nextNode;
  2510. if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
  2511. // This is an insertion or in-progress hydration. The nearest possible
  2512. // mounted fiber is the parent but we need to continue to figure out
  2513. // if that one is still mounted.
  2514. nearestMounted = node.return;
  2515. }
  2516. nextNode = node.return;
  2517. } while (nextNode);
  2518. } else {
  2519. while (node.return) {
  2520. node = node.return;
  2521. }
  2522. }
  2523. if (node.tag === HostRoot) {
  2524. // TODO: Check if this was a nested HostRoot when used with
  2525. // renderContainerIntoSubtree.
  2526. return nearestMounted;
  2527. } // If we didn't hit the root, that means that we're in an disconnected tree
  2528. // that has been unmounted.
  2529. return null;
  2530. }
  2531. function getSuspenseInstanceFromFiber(fiber) {
  2532. if (fiber.tag === SuspenseComponent) {
  2533. var suspenseState = fiber.memoizedState;
  2534. if (suspenseState === null) {
  2535. var current = fiber.alternate;
  2536. if (current !== null) {
  2537. suspenseState = current.memoizedState;
  2538. }
  2539. }
  2540. if (suspenseState !== null) {
  2541. return suspenseState.dehydrated;
  2542. }
  2543. }
  2544. return null;
  2545. }
  2546. function getContainerFromFiber(fiber) {
  2547. return fiber.tag === HostRoot ? fiber.stateNode.containerInfo : null;
  2548. }
  2549. function isFiberMounted(fiber) {
  2550. return getNearestMountedFiber(fiber) === fiber;
  2551. }
  2552. function isMounted(component) {
  2553. {
  2554. var owner = ReactCurrentOwner.current;
  2555. if (owner !== null && owner.tag === ClassComponent) {
  2556. var ownerFiber = owner;
  2557. var instance = ownerFiber.stateNode;
  2558. if (!instance._warnedAboutRefsInRender) {
  2559. error('%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber.type) || 'A component');
  2560. }
  2561. instance._warnedAboutRefsInRender = true;
  2562. }
  2563. }
  2564. var fiber = get(component);
  2565. if (!fiber) {
  2566. return false;
  2567. }
  2568. return getNearestMountedFiber(fiber) === fiber;
  2569. }
  2570. function assertIsMounted(fiber) {
  2571. if (!(getNearestMountedFiber(fiber) === fiber)) {
  2572. {
  2573. throw Error( "Unable to find node on an unmounted component." );
  2574. }
  2575. }
  2576. }
  2577. function findCurrentFiberUsingSlowPath(fiber) {
  2578. var alternate = fiber.alternate;
  2579. if (!alternate) {
  2580. // If there is no alternate, then we only need to check if it is mounted.
  2581. var nearestMounted = getNearestMountedFiber(fiber);
  2582. if (!(nearestMounted !== null)) {
  2583. {
  2584. throw Error( "Unable to find node on an unmounted component." );
  2585. }
  2586. }
  2587. if (nearestMounted !== fiber) {
  2588. return null;
  2589. }
  2590. return fiber;
  2591. } // If we have two possible branches, we'll walk backwards up to the root
  2592. // to see what path the root points to. On the way we may hit one of the
  2593. // special cases and we'll deal with them.
  2594. var a = fiber;
  2595. var b = alternate;
  2596. while (true) {
  2597. var parentA = a.return;
  2598. if (parentA === null) {
  2599. // We're at the root.
  2600. break;
  2601. }
  2602. var parentB = parentA.alternate;
  2603. if (parentB === null) {
  2604. // There is no alternate. This is an unusual case. Currently, it only
  2605. // happens when a Suspense component is hidden. An extra fragment fiber
  2606. // is inserted in between the Suspense fiber and its children. Skip
  2607. // over this extra fragment fiber and proceed to the next parent.
  2608. var nextParent = parentA.return;
  2609. if (nextParent !== null) {
  2610. a = b = nextParent;
  2611. continue;
  2612. } // If there's no parent, we're at the root.
  2613. break;
  2614. } // If both copies of the parent fiber point to the same child, we can
  2615. // assume that the child is current. This happens when we bailout on low
  2616. // priority: the bailed out fiber's child reuses the current child.
  2617. if (parentA.child === parentB.child) {
  2618. var child = parentA.child;
  2619. while (child) {
  2620. if (child === a) {
  2621. // We've determined that A is the current branch.
  2622. assertIsMounted(parentA);
  2623. return fiber;
  2624. }
  2625. if (child === b) {
  2626. // We've determined that B is the current branch.
  2627. assertIsMounted(parentA);
  2628. return alternate;
  2629. }
  2630. child = child.sibling;
  2631. } // We should never have an alternate for any mounting node. So the only
  2632. // way this could possibly happen is if this was unmounted, if at all.
  2633. {
  2634. {
  2635. throw Error( "Unable to find node on an unmounted component." );
  2636. }
  2637. }
  2638. }
  2639. if (a.return !== b.return) {
  2640. // The return pointer of A and the return pointer of B point to different
  2641. // fibers. We assume that return pointers never criss-cross, so A must
  2642. // belong to the child set of A.return, and B must belong to the child
  2643. // set of B.return.
  2644. a = parentA;
  2645. b = parentB;
  2646. } else {
  2647. // The return pointers point to the same fiber. We'll have to use the
  2648. // default, slow path: scan the child sets of each parent alternate to see
  2649. // which child belongs to which set.
  2650. //
  2651. // Search parent A's child set
  2652. var didFindChild = false;
  2653. var _child = parentA.child;
  2654. while (_child) {
  2655. if (_child === a) {
  2656. didFindChild = true;
  2657. a = parentA;
  2658. b = parentB;
  2659. break;
  2660. }
  2661. if (_child === b) {
  2662. didFindChild = true;
  2663. b = parentA;
  2664. a = parentB;
  2665. break;
  2666. }
  2667. _child = _child.sibling;
  2668. }
  2669. if (!didFindChild) {
  2670. // Search parent B's child set
  2671. _child = parentB.child;
  2672. while (_child) {
  2673. if (_child === a) {
  2674. didFindChild = true;
  2675. a = parentB;
  2676. b = parentA;
  2677. break;
  2678. }
  2679. if (_child === b) {
  2680. didFindChild = true;
  2681. b = parentB;
  2682. a = parentA;
  2683. break;
  2684. }
  2685. _child = _child.sibling;
  2686. }
  2687. if (!didFindChild) {
  2688. {
  2689. throw Error( "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." );
  2690. }
  2691. }
  2692. }
  2693. }
  2694. if (!(a.alternate === b)) {
  2695. {
  2696. throw Error( "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." );
  2697. }
  2698. }
  2699. } // If the root is not a host container, we're in a disconnected tree. I.e.
  2700. // unmounted.
  2701. if (!(a.tag === HostRoot)) {
  2702. {
  2703. throw Error( "Unable to find node on an unmounted component." );
  2704. }
  2705. }
  2706. if (a.stateNode.current === a) {
  2707. // We've determined that A is the current branch.
  2708. return fiber;
  2709. } // Otherwise B has to be current branch.
  2710. return alternate;
  2711. }
  2712. function findCurrentHostFiber(parent) {
  2713. var currentParent = findCurrentFiberUsingSlowPath(parent);
  2714. if (!currentParent) {
  2715. return null;
  2716. } // Next we'll drill down this component to find the first HostComponent/Text.
  2717. var node = currentParent;
  2718. while (true) {
  2719. if (node.tag === HostComponent || node.tag === HostText) {
  2720. return node;
  2721. } else if (node.child) {
  2722. node.child.return = node;
  2723. node = node.child;
  2724. continue;
  2725. }
  2726. if (node === currentParent) {
  2727. return null;
  2728. }
  2729. while (!node.sibling) {
  2730. if (!node.return || node.return === currentParent) {
  2731. return null;
  2732. }
  2733. node = node.return;
  2734. }
  2735. node.sibling.return = node.return;
  2736. node = node.sibling;
  2737. } // Flow needs the return null here, but ESLint complains about it.
  2738. // eslint-disable-next-line no-unreachable
  2739. return null;
  2740. }
  2741. function findCurrentHostFiberWithNoPortals(parent) {
  2742. var currentParent = findCurrentFiberUsingSlowPath(parent);
  2743. if (!currentParent) {
  2744. return null;
  2745. } // Next we'll drill down this component to find the first HostComponent/Text.
  2746. var node = currentParent;
  2747. while (true) {
  2748. if (node.tag === HostComponent || node.tag === HostText || enableFundamentalAPI ) {
  2749. return node;
  2750. } else if (node.child && node.tag !== HostPortal) {
  2751. node.child.return = node;
  2752. node = node.child;
  2753. continue;
  2754. }
  2755. if (node === currentParent) {
  2756. return null;
  2757. }
  2758. while (!node.sibling) {
  2759. if (!node.return || node.return === currentParent) {
  2760. return null;
  2761. }
  2762. node = node.return;
  2763. }
  2764. node.sibling.return = node.return;
  2765. node = node.sibling;
  2766. } // Flow needs the return null here, but ESLint complains about it.
  2767. // eslint-disable-next-line no-unreachable
  2768. return null;
  2769. }
  2770. /**
  2771. * Accumulates items that must not be null or undefined into the first one. This
  2772. * is used to conserve memory by avoiding array allocations, and thus sacrifices
  2773. * API cleanness. Since `current` can be null before being passed in and not
  2774. * null after this function, make sure to assign it back to `current`:
  2775. *
  2776. * `a = accumulateInto(a, b);`
  2777. *
  2778. * This API should be sparingly used. Try `accumulate` for something cleaner.
  2779. *
  2780. * @return {*|array<*>} An accumulation of items.
  2781. */
  2782. function accumulateInto(current, next) {
  2783. if (!(next != null)) {
  2784. {
  2785. throw Error( "accumulateInto(...): Accumulated items must not be null or undefined." );
  2786. }
  2787. }
  2788. if (current == null) {
  2789. return next;
  2790. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  2791. // certain that x is an Array (x could be a string with concat method).
  2792. if (Array.isArray(current)) {
  2793. if (Array.isArray(next)) {
  2794. current.push.apply(current, next);
  2795. return current;
  2796. }
  2797. current.push(next);
  2798. return current;
  2799. }
  2800. if (Array.isArray(next)) {
  2801. // A bit too dangerous to mutate `next`.
  2802. return [current].concat(next);
  2803. }
  2804. return [current, next];
  2805. }
  2806. /**
  2807. * @param {array} arr an "accumulation" of items which is either an Array or
  2808. * a single item. Useful when paired with the `accumulate` module. This is a
  2809. * simple utility that allows us to reason about a collection of items, but
  2810. * handling the case when there is exactly one item (and we do not need to
  2811. * allocate an array).
  2812. * @param {function} cb Callback invoked with each element or a collection.
  2813. * @param {?} [scope] Scope used as `this` in a callback.
  2814. */
  2815. function forEachAccumulated(arr, cb, scope) {
  2816. if (Array.isArray(arr)) {
  2817. arr.forEach(cb, scope);
  2818. } else if (arr) {
  2819. cb.call(scope, arr);
  2820. }
  2821. }
  2822. /**
  2823. * Internal queue of events that have accumulated their dispatches and are
  2824. * waiting to have their dispatches executed.
  2825. */
  2826. var eventQueue = null;
  2827. /**
  2828. * Dispatches an event and releases it back into the pool, unless persistent.
  2829. *
  2830. * @param {?object} event Synthetic event to be dispatched.
  2831. * @private
  2832. */
  2833. var executeDispatchesAndRelease = function (event) {
  2834. if (event) {
  2835. executeDispatchesInOrder(event);
  2836. if (!event.isPersistent()) {
  2837. event.constructor.release(event);
  2838. }
  2839. }
  2840. };
  2841. var executeDispatchesAndReleaseTopLevel = function (e) {
  2842. return executeDispatchesAndRelease(e);
  2843. };
  2844. function runEventsInBatch(events) {
  2845. if (events !== null) {
  2846. eventQueue = accumulateInto(eventQueue, events);
  2847. } // Set `eventQueue` to null before processing it so that we can tell if more
  2848. // events get enqueued while processing.
  2849. var processingEventQueue = eventQueue;
  2850. eventQueue = null;
  2851. if (!processingEventQueue) {
  2852. return;
  2853. }
  2854. forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
  2855. if (!!eventQueue) {
  2856. {
  2857. throw Error( "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented." );
  2858. }
  2859. } // This would be a good time to rethrow if any of the event handlers threw.
  2860. rethrowCaughtError();
  2861. }
  2862. /**
  2863. * Gets the target node from a native browser event by accounting for
  2864. * inconsistencies in browser DOM APIs.
  2865. *
  2866. * @param {object} nativeEvent Native browser event.
  2867. * @return {DOMEventTarget} Target node.
  2868. */
  2869. function getEventTarget(nativeEvent) {
  2870. // Fallback to nativeEvent.srcElement for IE9
  2871. // https://github.com/facebook/react/issues/12506
  2872. var target = nativeEvent.target || nativeEvent.srcElement || window; // Normalize SVG <use> element events #4963
  2873. if (target.correspondingUseElement) {
  2874. target = target.correspondingUseElement;
  2875. } // Safari may fire events on text nodes (Node.TEXT_NODE is 3).
  2876. // @see http://www.quirksmode.org/js/events_properties.html
  2877. return target.nodeType === TEXT_NODE ? target.parentNode : target;
  2878. }
  2879. /**
  2880. * Checks if an event is supported in the current execution environment.
  2881. *
  2882. * NOTE: This will not work correctly for non-generic events such as `change`,
  2883. * `reset`, `load`, `error`, and `select`.
  2884. *
  2885. * Borrows from Modernizr.
  2886. *
  2887. * @param {string} eventNameSuffix Event name, e.g. "click".
  2888. * @return {boolean} True if the event is supported.
  2889. * @internal
  2890. * @license Modernizr 3.0.0pre (Custom Build) | MIT
  2891. */
  2892. function isEventSupported(eventNameSuffix) {
  2893. if (!canUseDOM) {
  2894. return false;
  2895. }
  2896. var eventName = 'on' + eventNameSuffix;
  2897. var isSupported = eventName in document;
  2898. if (!isSupported) {
  2899. var element = document.createElement('div');
  2900. element.setAttribute(eventName, 'return;');
  2901. isSupported = typeof element[eventName] === 'function';
  2902. }
  2903. return isSupported;
  2904. }
  2905. /**
  2906. * Summary of `DOMEventPluginSystem` event handling:
  2907. *
  2908. * - Top-level delegation is used to trap most native browser events. This
  2909. * may only occur in the main thread and is the responsibility of
  2910. * ReactDOMEventListener, which is injected and can therefore support
  2911. * pluggable event sources. This is the only work that occurs in the main
  2912. * thread.
  2913. *
  2914. * - We normalize and de-duplicate events to account for browser quirks. This
  2915. * may be done in the worker thread.
  2916. *
  2917. * - Forward these native events (with the associated top-level type used to
  2918. * trap it) to `EventPluginRegistry`, which in turn will ask plugins if they want
  2919. * to extract any synthetic events.
  2920. *
  2921. * - The `EventPluginRegistry` will then process each event by annotating them with
  2922. * "dispatches", a sequence of listeners and IDs that care about that event.
  2923. *
  2924. * - The `EventPluginRegistry` then dispatches the events.
  2925. *
  2926. * Overview of React and the event system:
  2927. *
  2928. * +------------+ .
  2929. * | DOM | .
  2930. * +------------+ .
  2931. * | .
  2932. * v .
  2933. * +------------+ .
  2934. * | ReactEvent | .
  2935. * | Listener | .
  2936. * +------------+ . +-----------+
  2937. * | . +--------+|SimpleEvent|
  2938. * | . | |Plugin |
  2939. * +-----|------+ . v +-----------+
  2940. * | | | . +--------------+ +------------+
  2941. * | +-----------.--->|PluginRegistry| | Event |
  2942. * | | . | | +-----------+ | Propagators|
  2943. * | ReactEvent | . | | |TapEvent | |------------|
  2944. * | Emitter | . | |<---+|Plugin | |other plugin|
  2945. * | | . | | +-----------+ | utilities |
  2946. * | +-----------.--->| | +------------+
  2947. * | | | . +--------------+
  2948. * +-----|------+ . ^ +-----------+
  2949. * | . | |Enter/Leave|
  2950. * + . +-------+|Plugin |
  2951. * +-------------+ . +-----------+
  2952. * | application | .
  2953. * |-------------| .
  2954. * | | .
  2955. * | | .
  2956. * +-------------+ .
  2957. * .
  2958. * React Core . General Purpose Event Plugin System
  2959. */
  2960. var CALLBACK_BOOKKEEPING_POOL_SIZE = 10;
  2961. var callbackBookkeepingPool = [];
  2962. function releaseTopLevelCallbackBookKeeping(instance) {
  2963. instance.topLevelType = null;
  2964. instance.nativeEvent = null;
  2965. instance.targetInst = null;
  2966. instance.ancestors.length = 0;
  2967. if (callbackBookkeepingPool.length < CALLBACK_BOOKKEEPING_POOL_SIZE) {
  2968. callbackBookkeepingPool.push(instance);
  2969. }
  2970. } // Used to store ancestor hierarchy in top level callback
  2971. function getTopLevelCallbackBookKeeping(topLevelType, nativeEvent, targetInst, eventSystemFlags) {
  2972. if (callbackBookkeepingPool.length) {
  2973. var instance = callbackBookkeepingPool.pop();
  2974. instance.topLevelType = topLevelType;
  2975. instance.eventSystemFlags = eventSystemFlags;
  2976. instance.nativeEvent = nativeEvent;
  2977. instance.targetInst = targetInst;
  2978. return instance;
  2979. }
  2980. return {
  2981. topLevelType: topLevelType,
  2982. eventSystemFlags: eventSystemFlags,
  2983. nativeEvent: nativeEvent,
  2984. targetInst: targetInst,
  2985. ancestors: []
  2986. };
  2987. }
  2988. /**
  2989. * Find the deepest React component completely containing the root of the
  2990. * passed-in instance (for use when entire React trees are nested within each
  2991. * other). If React trees are not nested, returns null.
  2992. */
  2993. function findRootContainerNode(inst) {
  2994. if (inst.tag === HostRoot) {
  2995. return inst.stateNode.containerInfo;
  2996. } // TODO: It may be a good idea to cache this to prevent unnecessary DOM
  2997. // traversal, but caching is difficult to do correctly without using a
  2998. // mutation observer to listen for all DOM changes.
  2999. while (inst.return) {
  3000. inst = inst.return;
  3001. }
  3002. if (inst.tag !== HostRoot) {
  3003. // This can happen if we're in a detached tree.
  3004. return null;
  3005. }
  3006. return inst.stateNode.containerInfo;
  3007. }
  3008. /**
  3009. * Allows registered plugins an opportunity to extract events from top-level
  3010. * native browser events.
  3011. *
  3012. * @return {*} An accumulation of synthetic events.
  3013. * @internal
  3014. */
  3015. function extractPluginEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags) {
  3016. var events = null;
  3017. for (var i = 0; i < plugins.length; i++) {
  3018. // Not every plugin in the ordering may be loaded at runtime.
  3019. var possiblePlugin = plugins[i];
  3020. if (possiblePlugin) {
  3021. var extractedEvents = possiblePlugin.extractEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags);
  3022. if (extractedEvents) {
  3023. events = accumulateInto(events, extractedEvents);
  3024. }
  3025. }
  3026. }
  3027. return events;
  3028. }
  3029. function runExtractedPluginEventsInBatch(topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags) {
  3030. var events = extractPluginEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags);
  3031. runEventsInBatch(events);
  3032. }
  3033. function handleTopLevel(bookKeeping) {
  3034. var targetInst = bookKeeping.targetInst; // Loop through the hierarchy, in case there's any nested components.
  3035. // It's important that we build the array of ancestors before calling any
  3036. // event handlers, because event handlers can modify the DOM, leading to
  3037. // inconsistencies with ReactMount's node cache. See #1105.
  3038. var ancestor = targetInst;
  3039. do {
  3040. if (!ancestor) {
  3041. var ancestors = bookKeeping.ancestors;
  3042. ancestors.push(ancestor);
  3043. break;
  3044. }
  3045. var root = findRootContainerNode(ancestor);
  3046. if (!root) {
  3047. break;
  3048. }
  3049. var tag = ancestor.tag;
  3050. if (tag === HostComponent || tag === HostText) {
  3051. bookKeeping.ancestors.push(ancestor);
  3052. }
  3053. ancestor = getClosestInstanceFromNode(root);
  3054. } while (ancestor);
  3055. for (var i = 0; i < bookKeeping.ancestors.length; i++) {
  3056. targetInst = bookKeeping.ancestors[i];
  3057. var eventTarget = getEventTarget(bookKeeping.nativeEvent);
  3058. var topLevelType = bookKeeping.topLevelType;
  3059. var nativeEvent = bookKeeping.nativeEvent;
  3060. var eventSystemFlags = bookKeeping.eventSystemFlags; // If this is the first ancestor, we mark it on the system flags
  3061. if (i === 0) {
  3062. eventSystemFlags |= IS_FIRST_ANCESTOR;
  3063. }
  3064. runExtractedPluginEventsInBatch(topLevelType, targetInst, nativeEvent, eventTarget, eventSystemFlags);
  3065. }
  3066. }
  3067. function dispatchEventForLegacyPluginEventSystem(topLevelType, eventSystemFlags, nativeEvent, targetInst) {
  3068. var bookKeeping = getTopLevelCallbackBookKeeping(topLevelType, nativeEvent, targetInst, eventSystemFlags);
  3069. try {
  3070. // Event queue being processed in the same cycle allows
  3071. // `preventDefault`.
  3072. batchedEventUpdates(handleTopLevel, bookKeeping);
  3073. } finally {
  3074. releaseTopLevelCallbackBookKeeping(bookKeeping);
  3075. }
  3076. }
  3077. /**
  3078. * We listen for bubbled touch events on the document object.
  3079. *
  3080. * Firefox v8.01 (and possibly others) exhibited strange behavior when
  3081. * mounting `onmousemove` events at some node that was not the document
  3082. * element. The symptoms were that if your mouse is not moving over something
  3083. * contained within that mount point (for example on the background) the
  3084. * top-level listeners for `onmousemove` won't be called. However, if you
  3085. * register the `mousemove` on the document object, then it will of course
  3086. * catch all `mousemove`s. This along with iOS quirks, justifies restricting
  3087. * top-level listeners to the document object only, at least for these
  3088. * movement types of events and possibly all events.
  3089. *
  3090. * @see http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
  3091. *
  3092. * Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but
  3093. * they bubble to document.
  3094. *
  3095. * @param {string} registrationName Name of listener (e.g. `onClick`).
  3096. * @param {object} mountAt Container where to mount the listener
  3097. */
  3098. function legacyListenToEvent(registrationName, mountAt) {
  3099. var listenerMap = getListenerMapForElement(mountAt);
  3100. var dependencies = registrationNameDependencies[registrationName];
  3101. for (var i = 0; i < dependencies.length; i++) {
  3102. var dependency = dependencies[i];
  3103. legacyListenToTopLevelEvent(dependency, mountAt, listenerMap);
  3104. }
  3105. }
  3106. function legacyListenToTopLevelEvent(topLevelType, mountAt, listenerMap) {
  3107. if (!listenerMap.has(topLevelType)) {
  3108. switch (topLevelType) {
  3109. case TOP_SCROLL:
  3110. trapCapturedEvent(TOP_SCROLL, mountAt);
  3111. break;
  3112. case TOP_FOCUS:
  3113. case TOP_BLUR:
  3114. trapCapturedEvent(TOP_FOCUS, mountAt);
  3115. trapCapturedEvent(TOP_BLUR, mountAt); // We set the flag for a single dependency later in this function,
  3116. // but this ensures we mark both as attached rather than just one.
  3117. listenerMap.set(TOP_BLUR, null);
  3118. listenerMap.set(TOP_FOCUS, null);
  3119. break;
  3120. case TOP_CANCEL:
  3121. case TOP_CLOSE:
  3122. if (isEventSupported(getRawEventName(topLevelType))) {
  3123. trapCapturedEvent(topLevelType, mountAt);
  3124. }
  3125. break;
  3126. case TOP_INVALID:
  3127. case TOP_SUBMIT:
  3128. case TOP_RESET:
  3129. // We listen to them on the target DOM elements.
  3130. // Some of them bubble so we don't want them to fire twice.
  3131. break;
  3132. default:
  3133. // By default, listen on the top level to all non-media events.
  3134. // Media events don't bubble so adding the listener wouldn't do anything.
  3135. var isMediaEvent = mediaEventTypes.indexOf(topLevelType) !== -1;
  3136. if (!isMediaEvent) {
  3137. trapBubbledEvent(topLevelType, mountAt);
  3138. }
  3139. break;
  3140. }
  3141. listenerMap.set(topLevelType, null);
  3142. }
  3143. }
  3144. function isListeningToAllDependencies(registrationName, mountAt) {
  3145. var listenerMap = getListenerMapForElement(mountAt);
  3146. var dependencies = registrationNameDependencies[registrationName];
  3147. for (var i = 0; i < dependencies.length; i++) {
  3148. var dependency = dependencies[i];
  3149. if (!listenerMap.has(dependency)) {
  3150. return false;
  3151. }
  3152. }
  3153. return true;
  3154. }
  3155. var attemptUserBlockingHydration;
  3156. function setAttemptUserBlockingHydration(fn) {
  3157. attemptUserBlockingHydration = fn;
  3158. }
  3159. var attemptContinuousHydration;
  3160. function setAttemptContinuousHydration(fn) {
  3161. attemptContinuousHydration = fn;
  3162. }
  3163. var attemptHydrationAtCurrentPriority;
  3164. function setAttemptHydrationAtCurrentPriority(fn) {
  3165. attemptHydrationAtCurrentPriority = fn;
  3166. } // TODO: Upgrade this definition once we're on a newer version of Flow that
  3167. var hasScheduledReplayAttempt = false; // The queue of discrete events to be replayed.
  3168. var queuedDiscreteEvents = []; // Indicates if any continuous event targets are non-null for early bailout.
  3169. // if the last target was dehydrated.
  3170. var queuedFocus = null;
  3171. var queuedDrag = null;
  3172. var queuedMouse = null; // For pointer events there can be one latest event per pointerId.
  3173. var queuedPointers = new Map();
  3174. var queuedPointerCaptures = new Map(); // We could consider replaying selectionchange and touchmoves too.
  3175. var queuedExplicitHydrationTargets = [];
  3176. function hasQueuedDiscreteEvents() {
  3177. return queuedDiscreteEvents.length > 0;
  3178. }
  3179. var discreteReplayableEvents = [TOP_MOUSE_DOWN, TOP_MOUSE_UP, TOP_TOUCH_CANCEL, TOP_TOUCH_END, TOP_TOUCH_START, TOP_AUX_CLICK, TOP_DOUBLE_CLICK, TOP_POINTER_CANCEL, TOP_POINTER_DOWN, TOP_POINTER_UP, TOP_DRAG_END, TOP_DRAG_START, TOP_DROP, TOP_COMPOSITION_END, TOP_COMPOSITION_START, TOP_KEY_DOWN, TOP_KEY_PRESS, TOP_KEY_UP, TOP_INPUT, TOP_TEXT_INPUT, TOP_CLOSE, TOP_CANCEL, TOP_COPY, TOP_CUT, TOP_PASTE, TOP_CLICK, TOP_CHANGE, TOP_CONTEXT_MENU, TOP_RESET, TOP_SUBMIT];
  3180. var continuousReplayableEvents = [TOP_FOCUS, TOP_BLUR, TOP_DRAG_ENTER, TOP_DRAG_LEAVE, TOP_MOUSE_OVER, TOP_MOUSE_OUT, TOP_POINTER_OVER, TOP_POINTER_OUT, TOP_GOT_POINTER_CAPTURE, TOP_LOST_POINTER_CAPTURE];
  3181. function isReplayableDiscreteEvent(eventType) {
  3182. return discreteReplayableEvents.indexOf(eventType) > -1;
  3183. }
  3184. function trapReplayableEventForDocument(topLevelType, document, listenerMap) {
  3185. legacyListenToTopLevelEvent(topLevelType, document, listenerMap);
  3186. }
  3187. function eagerlyTrapReplayableEvents(container, document) {
  3188. var listenerMapForDoc = getListenerMapForElement(document); // Discrete
  3189. discreteReplayableEvents.forEach(function (topLevelType) {
  3190. trapReplayableEventForDocument(topLevelType, document, listenerMapForDoc);
  3191. }); // Continuous
  3192. continuousReplayableEvents.forEach(function (topLevelType) {
  3193. trapReplayableEventForDocument(topLevelType, document, listenerMapForDoc);
  3194. });
  3195. }
  3196. function createQueuedReplayableEvent(blockedOn, topLevelType, eventSystemFlags, container, nativeEvent) {
  3197. return {
  3198. blockedOn: blockedOn,
  3199. topLevelType: topLevelType,
  3200. eventSystemFlags: eventSystemFlags | IS_REPLAYED,
  3201. nativeEvent: nativeEvent,
  3202. container: container
  3203. };
  3204. }
  3205. function queueDiscreteEvent(blockedOn, topLevelType, eventSystemFlags, container, nativeEvent) {
  3206. var queuedEvent = createQueuedReplayableEvent(blockedOn, topLevelType, eventSystemFlags, container, nativeEvent);
  3207. queuedDiscreteEvents.push(queuedEvent);
  3208. } // Resets the replaying for this type of continuous event to no event.
  3209. function clearIfContinuousEvent(topLevelType, nativeEvent) {
  3210. switch (topLevelType) {
  3211. case TOP_FOCUS:
  3212. case TOP_BLUR:
  3213. queuedFocus = null;
  3214. break;
  3215. case TOP_DRAG_ENTER:
  3216. case TOP_DRAG_LEAVE:
  3217. queuedDrag = null;
  3218. break;
  3219. case TOP_MOUSE_OVER:
  3220. case TOP_MOUSE_OUT:
  3221. queuedMouse = null;
  3222. break;
  3223. case TOP_POINTER_OVER:
  3224. case TOP_POINTER_OUT:
  3225. {
  3226. var pointerId = nativeEvent.pointerId;
  3227. queuedPointers.delete(pointerId);
  3228. break;
  3229. }
  3230. case TOP_GOT_POINTER_CAPTURE:
  3231. case TOP_LOST_POINTER_CAPTURE:
  3232. {
  3233. var _pointerId = nativeEvent.pointerId;
  3234. queuedPointerCaptures.delete(_pointerId);
  3235. break;
  3236. }
  3237. }
  3238. }
  3239. function accumulateOrCreateContinuousQueuedReplayableEvent(existingQueuedEvent, blockedOn, topLevelType, eventSystemFlags, container, nativeEvent) {
  3240. if (existingQueuedEvent === null || existingQueuedEvent.nativeEvent !== nativeEvent) {
  3241. var queuedEvent = createQueuedReplayableEvent(blockedOn, topLevelType, eventSystemFlags, container, nativeEvent);
  3242. if (blockedOn !== null) {
  3243. var _fiber2 = getInstanceFromNode$1(blockedOn);
  3244. if (_fiber2 !== null) {
  3245. // Attempt to increase the priority of this target.
  3246. attemptContinuousHydration(_fiber2);
  3247. }
  3248. }
  3249. return queuedEvent;
  3250. } // If we have already queued this exact event, then it's because
  3251. // the different event systems have different DOM event listeners.
  3252. // We can accumulate the flags and store a single event to be
  3253. // replayed.
  3254. existingQueuedEvent.eventSystemFlags |= eventSystemFlags;
  3255. return existingQueuedEvent;
  3256. }
  3257. function queueIfContinuousEvent(blockedOn, topLevelType, eventSystemFlags, container, nativeEvent) {
  3258. // These set relatedTarget to null because the replayed event will be treated as if we
  3259. // moved from outside the window (no target) onto the target once it hydrates.
  3260. // Instead of mutating we could clone the event.
  3261. switch (topLevelType) {
  3262. case TOP_FOCUS:
  3263. {
  3264. var focusEvent = nativeEvent;
  3265. queuedFocus = accumulateOrCreateContinuousQueuedReplayableEvent(queuedFocus, blockedOn, topLevelType, eventSystemFlags, container, focusEvent);
  3266. return true;
  3267. }
  3268. case TOP_DRAG_ENTER:
  3269. {
  3270. var dragEvent = nativeEvent;
  3271. queuedDrag = accumulateOrCreateContinuousQueuedReplayableEvent(queuedDrag, blockedOn, topLevelType, eventSystemFlags, container, dragEvent);
  3272. return true;
  3273. }
  3274. case TOP_MOUSE_OVER:
  3275. {
  3276. var mouseEvent = nativeEvent;
  3277. queuedMouse = accumulateOrCreateContinuousQueuedReplayableEvent(queuedMouse, blockedOn, topLevelType, eventSystemFlags, container, mouseEvent);
  3278. return true;
  3279. }
  3280. case TOP_POINTER_OVER:
  3281. {
  3282. var pointerEvent = nativeEvent;
  3283. var pointerId = pointerEvent.pointerId;
  3284. queuedPointers.set(pointerId, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointers.get(pointerId) || null, blockedOn, topLevelType, eventSystemFlags, container, pointerEvent));
  3285. return true;
  3286. }
  3287. case TOP_GOT_POINTER_CAPTURE:
  3288. {
  3289. var _pointerEvent = nativeEvent;
  3290. var _pointerId2 = _pointerEvent.pointerId;
  3291. queuedPointerCaptures.set(_pointerId2, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointerCaptures.get(_pointerId2) || null, blockedOn, topLevelType, eventSystemFlags, container, _pointerEvent));
  3292. return true;
  3293. }
  3294. }
  3295. return false;
  3296. } // Check if this target is unblocked. Returns true if it's unblocked.
  3297. function attemptExplicitHydrationTarget(queuedTarget) {
  3298. // TODO: This function shares a lot of logic with attemptToDispatchEvent.
  3299. // Try to unify them. It's a bit tricky since it would require two return
  3300. // values.
  3301. var targetInst = getClosestInstanceFromNode(queuedTarget.target);
  3302. if (targetInst !== null) {
  3303. var nearestMounted = getNearestMountedFiber(targetInst);
  3304. if (nearestMounted !== null) {
  3305. var tag = nearestMounted.tag;
  3306. if (tag === SuspenseComponent) {
  3307. var instance = getSuspenseInstanceFromFiber(nearestMounted);
  3308. if (instance !== null) {
  3309. // We're blocked on hydrating this boundary.
  3310. // Increase its priority.
  3311. queuedTarget.blockedOn = instance;
  3312. unstable_runWithPriority(queuedTarget.priority, function () {
  3313. attemptHydrationAtCurrentPriority(nearestMounted);
  3314. });
  3315. return;
  3316. }
  3317. } else if (tag === HostRoot) {
  3318. var root = nearestMounted.stateNode;
  3319. if (root.hydrate) {
  3320. queuedTarget.blockedOn = getContainerFromFiber(nearestMounted); // We don't currently have a way to increase the priority of
  3321. // a root other than sync.
  3322. return;
  3323. }
  3324. }
  3325. }
  3326. }
  3327. queuedTarget.blockedOn = null;
  3328. }
  3329. function attemptReplayContinuousQueuedEvent(queuedEvent) {
  3330. if (queuedEvent.blockedOn !== null) {
  3331. return false;
  3332. }
  3333. var nextBlockedOn = attemptToDispatchEvent(queuedEvent.topLevelType, queuedEvent.eventSystemFlags, queuedEvent.container, queuedEvent.nativeEvent);
  3334. if (nextBlockedOn !== null) {
  3335. // We're still blocked. Try again later.
  3336. var _fiber3 = getInstanceFromNode$1(nextBlockedOn);
  3337. if (_fiber3 !== null) {
  3338. attemptContinuousHydration(_fiber3);
  3339. }
  3340. queuedEvent.blockedOn = nextBlockedOn;
  3341. return false;
  3342. }
  3343. return true;
  3344. }
  3345. function attemptReplayContinuousQueuedEventInMap(queuedEvent, key, map) {
  3346. if (attemptReplayContinuousQueuedEvent(queuedEvent)) {
  3347. map.delete(key);
  3348. }
  3349. }
  3350. function replayUnblockedEvents() {
  3351. hasScheduledReplayAttempt = false; // First replay discrete events.
  3352. while (queuedDiscreteEvents.length > 0) {
  3353. var nextDiscreteEvent = queuedDiscreteEvents[0];
  3354. if (nextDiscreteEvent.blockedOn !== null) {
  3355. // We're still blocked.
  3356. // Increase the priority of this boundary to unblock
  3357. // the next discrete event.
  3358. var _fiber4 = getInstanceFromNode$1(nextDiscreteEvent.blockedOn);
  3359. if (_fiber4 !== null) {
  3360. attemptUserBlockingHydration(_fiber4);
  3361. }
  3362. break;
  3363. }
  3364. var nextBlockedOn = attemptToDispatchEvent(nextDiscreteEvent.topLevelType, nextDiscreteEvent.eventSystemFlags, nextDiscreteEvent.container, nextDiscreteEvent.nativeEvent);
  3365. if (nextBlockedOn !== null) {
  3366. // We're still blocked. Try again later.
  3367. nextDiscreteEvent.blockedOn = nextBlockedOn;
  3368. } else {
  3369. // We've successfully replayed the first event. Let's try the next one.
  3370. queuedDiscreteEvents.shift();
  3371. }
  3372. } // Next replay any continuous events.
  3373. if (queuedFocus !== null && attemptReplayContinuousQueuedEvent(queuedFocus)) {
  3374. queuedFocus = null;
  3375. }
  3376. if (queuedDrag !== null && attemptReplayContinuousQueuedEvent(queuedDrag)) {
  3377. queuedDrag = null;
  3378. }
  3379. if (queuedMouse !== null && attemptReplayContinuousQueuedEvent(queuedMouse)) {
  3380. queuedMouse = null;
  3381. }
  3382. queuedPointers.forEach(attemptReplayContinuousQueuedEventInMap);
  3383. queuedPointerCaptures.forEach(attemptReplayContinuousQueuedEventInMap);
  3384. }
  3385. function scheduleCallbackIfUnblocked(queuedEvent, unblocked) {
  3386. if (queuedEvent.blockedOn === unblocked) {
  3387. queuedEvent.blockedOn = null;
  3388. if (!hasScheduledReplayAttempt) {
  3389. hasScheduledReplayAttempt = true; // Schedule a callback to attempt replaying as many events as are
  3390. // now unblocked. This first might not actually be unblocked yet.
  3391. // We could check it early to avoid scheduling an unnecessary callback.
  3392. unstable_scheduleCallback(unstable_NormalPriority, replayUnblockedEvents);
  3393. }
  3394. }
  3395. }
  3396. function retryIfBlockedOn(unblocked) {
  3397. // Mark anything that was blocked on this as no longer blocked
  3398. // and eligible for a replay.
  3399. if (queuedDiscreteEvents.length > 0) {
  3400. scheduleCallbackIfUnblocked(queuedDiscreteEvents[0], unblocked); // This is a exponential search for each boundary that commits. I think it's
  3401. // worth it because we expect very few discrete events to queue up and once
  3402. // we are actually fully unblocked it will be fast to replay them.
  3403. for (var i = 1; i < queuedDiscreteEvents.length; i++) {
  3404. var queuedEvent = queuedDiscreteEvents[i];
  3405. if (queuedEvent.blockedOn === unblocked) {
  3406. queuedEvent.blockedOn = null;
  3407. }
  3408. }
  3409. }
  3410. if (queuedFocus !== null) {
  3411. scheduleCallbackIfUnblocked(queuedFocus, unblocked);
  3412. }
  3413. if (queuedDrag !== null) {
  3414. scheduleCallbackIfUnblocked(queuedDrag, unblocked);
  3415. }
  3416. if (queuedMouse !== null) {
  3417. scheduleCallbackIfUnblocked(queuedMouse, unblocked);
  3418. }
  3419. var unblock = function (queuedEvent) {
  3420. return scheduleCallbackIfUnblocked(queuedEvent, unblocked);
  3421. };
  3422. queuedPointers.forEach(unblock);
  3423. queuedPointerCaptures.forEach(unblock);
  3424. for (var _i = 0; _i < queuedExplicitHydrationTargets.length; _i++) {
  3425. var queuedTarget = queuedExplicitHydrationTargets[_i];
  3426. if (queuedTarget.blockedOn === unblocked) {
  3427. queuedTarget.blockedOn = null;
  3428. }
  3429. }
  3430. while (queuedExplicitHydrationTargets.length > 0) {
  3431. var nextExplicitTarget = queuedExplicitHydrationTargets[0];
  3432. if (nextExplicitTarget.blockedOn !== null) {
  3433. // We're still blocked.
  3434. break;
  3435. } else {
  3436. attemptExplicitHydrationTarget(nextExplicitTarget);
  3437. if (nextExplicitTarget.blockedOn === null) {
  3438. // We're unblocked.
  3439. queuedExplicitHydrationTargets.shift();
  3440. }
  3441. }
  3442. }
  3443. }
  3444. function addEventBubbleListener(element, eventType, listener) {
  3445. element.addEventListener(eventType, listener, false);
  3446. }
  3447. function addEventCaptureListener(element, eventType, listener) {
  3448. element.addEventListener(eventType, listener, true);
  3449. }
  3450. // do it in two places, which duplicates logic
  3451. // and increases the bundle size, we do it all
  3452. // here once. If we remove or refactor the
  3453. // SimpleEventPlugin, we should also remove or
  3454. // update the below line.
  3455. var simpleEventPluginEventTypes = {};
  3456. var topLevelEventsToDispatchConfig = new Map();
  3457. var eventPriorities = new Map(); // We store most of the events in this module in pairs of two strings so we can re-use
  3458. // the code required to apply the same logic for event prioritization and that of the
  3459. // SimpleEventPlugin. This complicates things slightly, but the aim is to reduce code
  3460. // duplication (for which there would be quite a bit). For the events that are not needed
  3461. // for the SimpleEventPlugin (otherDiscreteEvents) we process them separately as an
  3462. // array of top level events.
  3463. // Lastly, we ignore prettier so we can keep the formatting sane.
  3464. // prettier-ignore
  3465. var discreteEventPairsForSimpleEventPlugin = [TOP_BLUR, 'blur', TOP_CANCEL, 'cancel', TOP_CLICK, 'click', TOP_CLOSE, 'close', TOP_CONTEXT_MENU, 'contextMenu', TOP_COPY, 'copy', TOP_CUT, 'cut', TOP_AUX_CLICK, 'auxClick', TOP_DOUBLE_CLICK, 'doubleClick', TOP_DRAG_END, 'dragEnd', TOP_DRAG_START, 'dragStart', TOP_DROP, 'drop', TOP_FOCUS, 'focus', TOP_INPUT, 'input', TOP_INVALID, 'invalid', TOP_KEY_DOWN, 'keyDown', TOP_KEY_PRESS, 'keyPress', TOP_KEY_UP, 'keyUp', TOP_MOUSE_DOWN, 'mouseDown', TOP_MOUSE_UP, 'mouseUp', TOP_PASTE, 'paste', TOP_PAUSE, 'pause', TOP_PLAY, 'play', TOP_POINTER_CANCEL, 'pointerCancel', TOP_POINTER_DOWN, 'pointerDown', TOP_POINTER_UP, 'pointerUp', TOP_RATE_CHANGE, 'rateChange', TOP_RESET, 'reset', TOP_SEEKED, 'seeked', TOP_SUBMIT, 'submit', TOP_TOUCH_CANCEL, 'touchCancel', TOP_TOUCH_END, 'touchEnd', TOP_TOUCH_START, 'touchStart', TOP_VOLUME_CHANGE, 'volumeChange'];
  3466. var otherDiscreteEvents = [TOP_CHANGE, TOP_SELECTION_CHANGE, TOP_TEXT_INPUT, TOP_COMPOSITION_START, TOP_COMPOSITION_END, TOP_COMPOSITION_UPDATE]; // prettier-ignore
  3467. var userBlockingPairsForSimpleEventPlugin = [TOP_DRAG, 'drag', TOP_DRAG_ENTER, 'dragEnter', TOP_DRAG_EXIT, 'dragExit', TOP_DRAG_LEAVE, 'dragLeave', TOP_DRAG_OVER, 'dragOver', TOP_MOUSE_MOVE, 'mouseMove', TOP_MOUSE_OUT, 'mouseOut', TOP_MOUSE_OVER, 'mouseOver', TOP_POINTER_MOVE, 'pointerMove', TOP_POINTER_OUT, 'pointerOut', TOP_POINTER_OVER, 'pointerOver', TOP_SCROLL, 'scroll', TOP_TOGGLE, 'toggle', TOP_TOUCH_MOVE, 'touchMove', TOP_WHEEL, 'wheel']; // prettier-ignore
  3468. var continuousPairsForSimpleEventPlugin = [TOP_ABORT, 'abort', TOP_ANIMATION_END, 'animationEnd', TOP_ANIMATION_ITERATION, 'animationIteration', TOP_ANIMATION_START, 'animationStart', TOP_CAN_PLAY, 'canPlay', TOP_CAN_PLAY_THROUGH, 'canPlayThrough', TOP_DURATION_CHANGE, 'durationChange', TOP_EMPTIED, 'emptied', TOP_ENCRYPTED, 'encrypted', TOP_ENDED, 'ended', TOP_ERROR, 'error', TOP_GOT_POINTER_CAPTURE, 'gotPointerCapture', TOP_LOAD, 'load', TOP_LOADED_DATA, 'loadedData', TOP_LOADED_METADATA, 'loadedMetadata', TOP_LOAD_START, 'loadStart', TOP_LOST_POINTER_CAPTURE, 'lostPointerCapture', TOP_PLAYING, 'playing', TOP_PROGRESS, 'progress', TOP_SEEKING, 'seeking', TOP_STALLED, 'stalled', TOP_SUSPEND, 'suspend', TOP_TIME_UPDATE, 'timeUpdate', TOP_TRANSITION_END, 'transitionEnd', TOP_WAITING, 'waiting'];
  3469. /**
  3470. * Turns
  3471. * ['abort', ...]
  3472. * into
  3473. * eventTypes = {
  3474. * 'abort': {
  3475. * phasedRegistrationNames: {
  3476. * bubbled: 'onAbort',
  3477. * captured: 'onAbortCapture',
  3478. * },
  3479. * dependencies: [TOP_ABORT],
  3480. * },
  3481. * ...
  3482. * };
  3483. * topLevelEventsToDispatchConfig = new Map([
  3484. * [TOP_ABORT, { sameConfig }],
  3485. * ]);
  3486. */
  3487. function processSimpleEventPluginPairsByPriority(eventTypes, priority) {
  3488. // As the event types are in pairs of two, we need to iterate
  3489. // through in twos. The events are in pairs of two to save code
  3490. // and improve init perf of processing this array, as it will
  3491. // result in far fewer object allocations and property accesses
  3492. // if we only use three arrays to process all the categories of
  3493. // instead of tuples.
  3494. for (var i = 0; i < eventTypes.length; i += 2) {
  3495. var topEvent = eventTypes[i];
  3496. var event = eventTypes[i + 1];
  3497. var capitalizedEvent = event[0].toUpperCase() + event.slice(1);
  3498. var onEvent = 'on' + capitalizedEvent;
  3499. var config = {
  3500. phasedRegistrationNames: {
  3501. bubbled: onEvent,
  3502. captured: onEvent + 'Capture'
  3503. },
  3504. dependencies: [topEvent],
  3505. eventPriority: priority
  3506. };
  3507. eventPriorities.set(topEvent, priority);
  3508. topLevelEventsToDispatchConfig.set(topEvent, config);
  3509. simpleEventPluginEventTypes[event] = config;
  3510. }
  3511. }
  3512. function processTopEventPairsByPriority(eventTypes, priority) {
  3513. for (var i = 0; i < eventTypes.length; i++) {
  3514. eventPriorities.set(eventTypes[i], priority);
  3515. }
  3516. } // SimpleEventPlugin
  3517. processSimpleEventPluginPairsByPriority(discreteEventPairsForSimpleEventPlugin, DiscreteEvent);
  3518. processSimpleEventPluginPairsByPriority(userBlockingPairsForSimpleEventPlugin, UserBlockingEvent);
  3519. processSimpleEventPluginPairsByPriority(continuousPairsForSimpleEventPlugin, ContinuousEvent); // Not used by SimpleEventPlugin
  3520. processTopEventPairsByPriority(otherDiscreteEvents, DiscreteEvent);
  3521. function getEventPriorityForPluginSystem(topLevelType) {
  3522. var priority = eventPriorities.get(topLevelType); // Default to a ContinuousEvent. Note: we might
  3523. // want to warn if we can't detect the priority
  3524. // for the event.
  3525. return priority === undefined ? ContinuousEvent : priority;
  3526. }
  3527. // Intentionally not named imports because Rollup would use dynamic dispatch for
  3528. var UserBlockingPriority = unstable_UserBlockingPriority,
  3529. runWithPriority = unstable_runWithPriority; // TODO: can we stop exporting these?
  3530. var _enabled = true;
  3531. function setEnabled(enabled) {
  3532. _enabled = !!enabled;
  3533. }
  3534. function isEnabled() {
  3535. return _enabled;
  3536. }
  3537. function trapBubbledEvent(topLevelType, element) {
  3538. trapEventForPluginEventSystem(element, topLevelType, false);
  3539. }
  3540. function trapCapturedEvent(topLevelType, element) {
  3541. trapEventForPluginEventSystem(element, topLevelType, true);
  3542. }
  3543. function trapEventForPluginEventSystem(container, topLevelType, capture) {
  3544. var listener;
  3545. switch (getEventPriorityForPluginSystem(topLevelType)) {
  3546. case DiscreteEvent:
  3547. listener = dispatchDiscreteEvent.bind(null, topLevelType, PLUGIN_EVENT_SYSTEM, container);
  3548. break;
  3549. case UserBlockingEvent:
  3550. listener = dispatchUserBlockingUpdate.bind(null, topLevelType, PLUGIN_EVENT_SYSTEM, container);
  3551. break;
  3552. case ContinuousEvent:
  3553. default:
  3554. listener = dispatchEvent.bind(null, topLevelType, PLUGIN_EVENT_SYSTEM, container);
  3555. break;
  3556. }
  3557. var rawEventName = getRawEventName(topLevelType);
  3558. if (capture) {
  3559. addEventCaptureListener(container, rawEventName, listener);
  3560. } else {
  3561. addEventBubbleListener(container, rawEventName, listener);
  3562. }
  3563. }
  3564. function dispatchDiscreteEvent(topLevelType, eventSystemFlags, container, nativeEvent) {
  3565. flushDiscreteUpdatesIfNeeded(nativeEvent.timeStamp);
  3566. discreteUpdates(dispatchEvent, topLevelType, eventSystemFlags, container, nativeEvent);
  3567. }
  3568. function dispatchUserBlockingUpdate(topLevelType, eventSystemFlags, container, nativeEvent) {
  3569. runWithPriority(UserBlockingPriority, dispatchEvent.bind(null, topLevelType, eventSystemFlags, container, nativeEvent));
  3570. }
  3571. function dispatchEvent(topLevelType, eventSystemFlags, container, nativeEvent) {
  3572. if (!_enabled) {
  3573. return;
  3574. }
  3575. if (hasQueuedDiscreteEvents() && isReplayableDiscreteEvent(topLevelType)) {
  3576. // If we already have a queue of discrete events, and this is another discrete
  3577. // event, then we can't dispatch it regardless of its target, since they
  3578. // need to dispatch in order.
  3579. queueDiscreteEvent(null, // Flags that we're not actually blocked on anything as far as we know.
  3580. topLevelType, eventSystemFlags, container, nativeEvent);
  3581. return;
  3582. }
  3583. var blockedOn = attemptToDispatchEvent(topLevelType, eventSystemFlags, container, nativeEvent);
  3584. if (blockedOn === null) {
  3585. // We successfully dispatched this event.
  3586. clearIfContinuousEvent(topLevelType, nativeEvent);
  3587. return;
  3588. }
  3589. if (isReplayableDiscreteEvent(topLevelType)) {
  3590. // This this to be replayed later once the target is available.
  3591. queueDiscreteEvent(blockedOn, topLevelType, eventSystemFlags, container, nativeEvent);
  3592. return;
  3593. }
  3594. if (queueIfContinuousEvent(blockedOn, topLevelType, eventSystemFlags, container, nativeEvent)) {
  3595. return;
  3596. } // We need to clear only if we didn't queue because
  3597. // queueing is accummulative.
  3598. clearIfContinuousEvent(topLevelType, nativeEvent); // This is not replayable so we'll invoke it but without a target,
  3599. // in case the event system needs to trace it.
  3600. {
  3601. dispatchEventForLegacyPluginEventSystem(topLevelType, eventSystemFlags, nativeEvent, null);
  3602. }
  3603. } // Attempt dispatching an event. Returns a SuspenseInstance or Container if it's blocked.
  3604. function attemptToDispatchEvent(topLevelType, eventSystemFlags, container, nativeEvent) {
  3605. // TODO: Warn if _enabled is false.
  3606. var nativeEventTarget = getEventTarget(nativeEvent);
  3607. var targetInst = getClosestInstanceFromNode(nativeEventTarget);
  3608. if (targetInst !== null) {
  3609. var nearestMounted = getNearestMountedFiber(targetInst);
  3610. if (nearestMounted === null) {
  3611. // This tree has been unmounted already. Dispatch without a target.
  3612. targetInst = null;
  3613. } else {
  3614. var tag = nearestMounted.tag;
  3615. if (tag === SuspenseComponent) {
  3616. var instance = getSuspenseInstanceFromFiber(nearestMounted);
  3617. if (instance !== null) {
  3618. // Queue the event to be replayed later. Abort dispatching since we
  3619. // don't want this event dispatched twice through the event system.
  3620. // TODO: If this is the first discrete event in the queue. Schedule an increased
  3621. // priority for this boundary.
  3622. return instance;
  3623. } // This shouldn't happen, something went wrong but to avoid blocking
  3624. // the whole system, dispatch the event without a target.
  3625. // TODO: Warn.
  3626. targetInst = null;
  3627. } else if (tag === HostRoot) {
  3628. var root = nearestMounted.stateNode;
  3629. if (root.hydrate) {
  3630. // If this happens during a replay something went wrong and it might block
  3631. // the whole system.
  3632. return getContainerFromFiber(nearestMounted);
  3633. }
  3634. targetInst = null;
  3635. } else if (nearestMounted !== targetInst) {
  3636. // If we get an event (ex: img onload) before committing that
  3637. // component's mount, ignore it for now (that is, treat it as if it was an
  3638. // event on a non-React tree). We might also consider queueing events and
  3639. // dispatching them after the mount.
  3640. targetInst = null;
  3641. }
  3642. }
  3643. }
  3644. {
  3645. dispatchEventForLegacyPluginEventSystem(topLevelType, eventSystemFlags, nativeEvent, targetInst);
  3646. } // We're not blocked on anything.
  3647. return null;
  3648. }
  3649. // List derived from Gecko source code:
  3650. // https://github.com/mozilla/gecko-dev/blob/4e638efc71/layout/style/test/property_database.js
  3651. var shorthandToLonghand = {
  3652. animation: ['animationDelay', 'animationDirection', 'animationDuration', 'animationFillMode', 'animationIterationCount', 'animationName', 'animationPlayState', 'animationTimingFunction'],
  3653. background: ['backgroundAttachment', 'backgroundClip', 'backgroundColor', 'backgroundImage', 'backgroundOrigin', 'backgroundPositionX', 'backgroundPositionY', 'backgroundRepeat', 'backgroundSize'],
  3654. backgroundPosition: ['backgroundPositionX', 'backgroundPositionY'],
  3655. border: ['borderBottomColor', 'borderBottomStyle', 'borderBottomWidth', 'borderImageOutset', 'borderImageRepeat', 'borderImageSlice', 'borderImageSource', 'borderImageWidth', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderTopColor', 'borderTopStyle', 'borderTopWidth'],
  3656. borderBlockEnd: ['borderBlockEndColor', 'borderBlockEndStyle', 'borderBlockEndWidth'],
  3657. borderBlockStart: ['borderBlockStartColor', 'borderBlockStartStyle', 'borderBlockStartWidth'],
  3658. borderBottom: ['borderBottomColor', 'borderBottomStyle', 'borderBottomWidth'],
  3659. borderColor: ['borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor'],
  3660. borderImage: ['borderImageOutset', 'borderImageRepeat', 'borderImageSlice', 'borderImageSource', 'borderImageWidth'],
  3661. borderInlineEnd: ['borderInlineEndColor', 'borderInlineEndStyle', 'borderInlineEndWidth'],
  3662. borderInlineStart: ['borderInlineStartColor', 'borderInlineStartStyle', 'borderInlineStartWidth'],
  3663. borderLeft: ['borderLeftColor', 'borderLeftStyle', 'borderLeftWidth'],
  3664. borderRadius: ['borderBottomLeftRadius', 'borderBottomRightRadius', 'borderTopLeftRadius', 'borderTopRightRadius'],
  3665. borderRight: ['borderRightColor', 'borderRightStyle', 'borderRightWidth'],
  3666. borderStyle: ['borderBottomStyle', 'borderLeftStyle', 'borderRightStyle', 'borderTopStyle'],
  3667. borderTop: ['borderTopColor', 'borderTopStyle', 'borderTopWidth'],
  3668. borderWidth: ['borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth'],
  3669. columnRule: ['columnRuleColor', 'columnRuleStyle', 'columnRuleWidth'],
  3670. columns: ['columnCount', 'columnWidth'],
  3671. flex: ['flexBasis', 'flexGrow', 'flexShrink'],
  3672. flexFlow: ['flexDirection', 'flexWrap'],
  3673. font: ['fontFamily', 'fontFeatureSettings', 'fontKerning', 'fontLanguageOverride', 'fontSize', 'fontSizeAdjust', 'fontStretch', 'fontStyle', 'fontVariant', 'fontVariantAlternates', 'fontVariantCaps', 'fontVariantEastAsian', 'fontVariantLigatures', 'fontVariantNumeric', 'fontVariantPosition', 'fontWeight', 'lineHeight'],
  3674. fontVariant: ['fontVariantAlternates', 'fontVariantCaps', 'fontVariantEastAsian', 'fontVariantLigatures', 'fontVariantNumeric', 'fontVariantPosition'],
  3675. gap: ['columnGap', 'rowGap'],
  3676. grid: ['gridAutoColumns', 'gridAutoFlow', 'gridAutoRows', 'gridTemplateAreas', 'gridTemplateColumns', 'gridTemplateRows'],
  3677. gridArea: ['gridColumnEnd', 'gridColumnStart', 'gridRowEnd', 'gridRowStart'],
  3678. gridColumn: ['gridColumnEnd', 'gridColumnStart'],
  3679. gridColumnGap: ['columnGap'],
  3680. gridGap: ['columnGap', 'rowGap'],
  3681. gridRow: ['gridRowEnd', 'gridRowStart'],
  3682. gridRowGap: ['rowGap'],
  3683. gridTemplate: ['gridTemplateAreas', 'gridTemplateColumns', 'gridTemplateRows'],
  3684. listStyle: ['listStyleImage', 'listStylePosition', 'listStyleType'],
  3685. margin: ['marginBottom', 'marginLeft', 'marginRight', 'marginTop'],
  3686. marker: ['markerEnd', 'markerMid', 'markerStart'],
  3687. mask: ['maskClip', 'maskComposite', 'maskImage', 'maskMode', 'maskOrigin', 'maskPositionX', 'maskPositionY', 'maskRepeat', 'maskSize'],
  3688. maskPosition: ['maskPositionX', 'maskPositionY'],
  3689. outline: ['outlineColor', 'outlineStyle', 'outlineWidth'],
  3690. overflow: ['overflowX', 'overflowY'],
  3691. padding: ['paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop'],
  3692. placeContent: ['alignContent', 'justifyContent'],
  3693. placeItems: ['alignItems', 'justifyItems'],
  3694. placeSelf: ['alignSelf', 'justifySelf'],
  3695. textDecoration: ['textDecorationColor', 'textDecorationLine', 'textDecorationStyle'],
  3696. textEmphasis: ['textEmphasisColor', 'textEmphasisStyle'],
  3697. transition: ['transitionDelay', 'transitionDuration', 'transitionProperty', 'transitionTimingFunction'],
  3698. wordWrap: ['overflowWrap']
  3699. };
  3700. /**
  3701. * CSS properties which accept numbers but are not in units of "px".
  3702. */
  3703. var isUnitlessNumber = {
  3704. animationIterationCount: true,
  3705. borderImageOutset: true,
  3706. borderImageSlice: true,
  3707. borderImageWidth: true,
  3708. boxFlex: true,
  3709. boxFlexGroup: true,
  3710. boxOrdinalGroup: true,
  3711. columnCount: true,
  3712. columns: true,
  3713. flex: true,
  3714. flexGrow: true,
  3715. flexPositive: true,
  3716. flexShrink: true,
  3717. flexNegative: true,
  3718. flexOrder: true,
  3719. gridArea: true,
  3720. gridRow: true,
  3721. gridRowEnd: true,
  3722. gridRowSpan: true,
  3723. gridRowStart: true,
  3724. gridColumn: true,
  3725. gridColumnEnd: true,
  3726. gridColumnSpan: true,
  3727. gridColumnStart: true,
  3728. fontWeight: true,
  3729. lineClamp: true,
  3730. lineHeight: true,
  3731. opacity: true,
  3732. order: true,
  3733. orphans: true,
  3734. tabSize: true,
  3735. widows: true,
  3736. zIndex: true,
  3737. zoom: true,
  3738. // SVG-related properties
  3739. fillOpacity: true,
  3740. floodOpacity: true,
  3741. stopOpacity: true,
  3742. strokeDasharray: true,
  3743. strokeDashoffset: true,
  3744. strokeMiterlimit: true,
  3745. strokeOpacity: true,
  3746. strokeWidth: true
  3747. };
  3748. /**
  3749. * @param {string} prefix vendor-specific prefix, eg: Webkit
  3750. * @param {string} key style name, eg: transitionDuration
  3751. * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
  3752. * WebkitTransitionDuration
  3753. */
  3754. function prefixKey(prefix, key) {
  3755. return prefix + key.charAt(0).toUpperCase() + key.substring(1);
  3756. }
  3757. /**
  3758. * Support style names that may come passed in prefixed by adding permutations
  3759. * of vendor prefixes.
  3760. */
  3761. var prefixes = ['Webkit', 'ms', 'Moz', 'O']; // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
  3762. // infinite loop, because it iterates over the newly added props too.
  3763. Object.keys(isUnitlessNumber).forEach(function (prop) {
  3764. prefixes.forEach(function (prefix) {
  3765. isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
  3766. });
  3767. });
  3768. /**
  3769. * Convert a value into the proper css writable value. The style name `name`
  3770. * should be logical (no hyphens), as specified
  3771. * in `CSSProperty.isUnitlessNumber`.
  3772. *
  3773. * @param {string} name CSS property name such as `topMargin`.
  3774. * @param {*} value CSS property value such as `10px`.
  3775. * @return {string} Normalized style value with dimensions applied.
  3776. */
  3777. function dangerousStyleValue(name, value, isCustomProperty) {
  3778. // Note that we've removed escapeTextForBrowser() calls here since the
  3779. // whole string will be escaped when the attribute is injected into
  3780. // the markup. If you provide unsafe user data here they can inject
  3781. // arbitrary CSS which may be problematic (I couldn't repro this):
  3782. // https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
  3783. // http://www.thespanner.co.uk/2007/11/26/ultimate-xss-css-injection/
  3784. // This is not an XSS hole but instead a potential CSS injection issue
  3785. // which has lead to a greater discussion about how we're going to
  3786. // trust URLs moving forward. See #2115901
  3787. var isEmpty = value == null || typeof value === 'boolean' || value === '';
  3788. if (isEmpty) {
  3789. return '';
  3790. }
  3791. if (!isCustomProperty && typeof value === 'number' && value !== 0 && !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])) {
  3792. return value + 'px'; // Presumes implicit 'px' suffix for unitless numbers
  3793. }
  3794. return ('' + value).trim();
  3795. }
  3796. var uppercasePattern = /([A-Z])/g;
  3797. var msPattern = /^ms-/;
  3798. /**
  3799. * Hyphenates a camelcased CSS property name, for example:
  3800. *
  3801. * > hyphenateStyleName('backgroundColor')
  3802. * < "background-color"
  3803. * > hyphenateStyleName('MozTransition')
  3804. * < "-moz-transition"
  3805. * > hyphenateStyleName('msTransition')
  3806. * < "-ms-transition"
  3807. *
  3808. * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
  3809. * is converted to `-ms-`.
  3810. */
  3811. function hyphenateStyleName(name) {
  3812. return name.replace(uppercasePattern, '-$1').toLowerCase().replace(msPattern, '-ms-');
  3813. }
  3814. var warnValidStyle = function () {};
  3815. {
  3816. // 'msTransform' is correct, but the other prefixes should be capitalized
  3817. var badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
  3818. var msPattern$1 = /^-ms-/;
  3819. var hyphenPattern = /-(.)/g; // style values shouldn't contain a semicolon
  3820. var badStyleValueWithSemicolonPattern = /;\s*$/;
  3821. var warnedStyleNames = {};
  3822. var warnedStyleValues = {};
  3823. var warnedForNaNValue = false;
  3824. var warnedForInfinityValue = false;
  3825. var camelize = function (string) {
  3826. return string.replace(hyphenPattern, function (_, character) {
  3827. return character.toUpperCase();
  3828. });
  3829. };
  3830. var warnHyphenatedStyleName = function (name) {
  3831. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  3832. return;
  3833. }
  3834. warnedStyleNames[name] = true;
  3835. error('Unsupported style property %s. Did you mean %s?', name, // As Andi Smith suggests
  3836. // (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix
  3837. // is converted to lowercase `ms`.
  3838. camelize(name.replace(msPattern$1, 'ms-')));
  3839. };
  3840. var warnBadVendoredStyleName = function (name) {
  3841. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  3842. return;
  3843. }
  3844. warnedStyleNames[name] = true;
  3845. error('Unsupported vendor-prefixed style property %s. Did you mean %s?', name, name.charAt(0).toUpperCase() + name.slice(1));
  3846. };
  3847. var warnStyleValueWithSemicolon = function (name, value) {
  3848. if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
  3849. return;
  3850. }
  3851. warnedStyleValues[value] = true;
  3852. error("Style property values shouldn't contain a semicolon. " + 'Try "%s: %s" instead.', name, value.replace(badStyleValueWithSemicolonPattern, ''));
  3853. };
  3854. var warnStyleValueIsNaN = function (name, value) {
  3855. if (warnedForNaNValue) {
  3856. return;
  3857. }
  3858. warnedForNaNValue = true;
  3859. error('`NaN` is an invalid value for the `%s` css style property.', name);
  3860. };
  3861. var warnStyleValueIsInfinity = function (name, value) {
  3862. if (warnedForInfinityValue) {
  3863. return;
  3864. }
  3865. warnedForInfinityValue = true;
  3866. error('`Infinity` is an invalid value for the `%s` css style property.', name);
  3867. };
  3868. warnValidStyle = function (name, value) {
  3869. if (name.indexOf('-') > -1) {
  3870. warnHyphenatedStyleName(name);
  3871. } else if (badVendoredStyleNamePattern.test(name)) {
  3872. warnBadVendoredStyleName(name);
  3873. } else if (badStyleValueWithSemicolonPattern.test(value)) {
  3874. warnStyleValueWithSemicolon(name, value);
  3875. }
  3876. if (typeof value === 'number') {
  3877. if (isNaN(value)) {
  3878. warnStyleValueIsNaN(name, value);
  3879. } else if (!isFinite(value)) {
  3880. warnStyleValueIsInfinity(name, value);
  3881. }
  3882. }
  3883. };
  3884. }
  3885. var warnValidStyle$1 = warnValidStyle;
  3886. /**
  3887. * Operations for dealing with CSS properties.
  3888. */
  3889. /**
  3890. * This creates a string that is expected to be equivalent to the style
  3891. * attribute generated by server-side rendering. It by-passes warnings and
  3892. * security checks so it's not safe to use this value for anything other than
  3893. * comparison. It is only used in DEV for SSR validation.
  3894. */
  3895. function createDangerousStringForStyles(styles) {
  3896. {
  3897. var serialized = '';
  3898. var delimiter = '';
  3899. for (var styleName in styles) {
  3900. if (!styles.hasOwnProperty(styleName)) {
  3901. continue;
  3902. }
  3903. var styleValue = styles[styleName];
  3904. if (styleValue != null) {
  3905. var isCustomProperty = styleName.indexOf('--') === 0;
  3906. serialized += delimiter + (isCustomProperty ? styleName : hyphenateStyleName(styleName)) + ':';
  3907. serialized += dangerousStyleValue(styleName, styleValue, isCustomProperty);
  3908. delimiter = ';';
  3909. }
  3910. }
  3911. return serialized || null;
  3912. }
  3913. }
  3914. /**
  3915. * Sets the value for multiple styles on a node. If a value is specified as
  3916. * '' (empty string), the corresponding style property will be unset.
  3917. *
  3918. * @param {DOMElement} node
  3919. * @param {object} styles
  3920. */
  3921. function setValueForStyles(node, styles) {
  3922. var style = node.style;
  3923. for (var styleName in styles) {
  3924. if (!styles.hasOwnProperty(styleName)) {
  3925. continue;
  3926. }
  3927. var isCustomProperty = styleName.indexOf('--') === 0;
  3928. {
  3929. if (!isCustomProperty) {
  3930. warnValidStyle$1(styleName, styles[styleName]);
  3931. }
  3932. }
  3933. var styleValue = dangerousStyleValue(styleName, styles[styleName], isCustomProperty);
  3934. if (styleName === 'float') {
  3935. styleName = 'cssFloat';
  3936. }
  3937. if (isCustomProperty) {
  3938. style.setProperty(styleName, styleValue);
  3939. } else {
  3940. style[styleName] = styleValue;
  3941. }
  3942. }
  3943. }
  3944. function isValueEmpty(value) {
  3945. return value == null || typeof value === 'boolean' || value === '';
  3946. }
  3947. /**
  3948. * Given {color: 'red', overflow: 'hidden'} returns {
  3949. * color: 'color',
  3950. * overflowX: 'overflow',
  3951. * overflowY: 'overflow',
  3952. * }. This can be read as "the overflowY property was set by the overflow
  3953. * shorthand". That is, the values are the property that each was derived from.
  3954. */
  3955. function expandShorthandMap(styles) {
  3956. var expanded = {};
  3957. for (var key in styles) {
  3958. var longhands = shorthandToLonghand[key] || [key];
  3959. for (var i = 0; i < longhands.length; i++) {
  3960. expanded[longhands[i]] = key;
  3961. }
  3962. }
  3963. return expanded;
  3964. }
  3965. /**
  3966. * When mixing shorthand and longhand property names, we warn during updates if
  3967. * we expect an incorrect result to occur. In particular, we warn for:
  3968. *
  3969. * Updating a shorthand property (longhand gets overwritten):
  3970. * {font: 'foo', fontVariant: 'bar'} -> {font: 'baz', fontVariant: 'bar'}
  3971. * becomes .style.font = 'baz'
  3972. * Removing a shorthand property (longhand gets lost too):
  3973. * {font: 'foo', fontVariant: 'bar'} -> {fontVariant: 'bar'}
  3974. * becomes .style.font = ''
  3975. * Removing a longhand property (should revert to shorthand; doesn't):
  3976. * {font: 'foo', fontVariant: 'bar'} -> {font: 'foo'}
  3977. * becomes .style.fontVariant = ''
  3978. */
  3979. function validateShorthandPropertyCollisionInDev(styleUpdates, nextStyles) {
  3980. {
  3981. if (!nextStyles) {
  3982. return;
  3983. }
  3984. var expandedUpdates = expandShorthandMap(styleUpdates);
  3985. var expandedStyles = expandShorthandMap(nextStyles);
  3986. var warnedAbout = {};
  3987. for (var key in expandedUpdates) {
  3988. var originalKey = expandedUpdates[key];
  3989. var correctOriginalKey = expandedStyles[key];
  3990. if (correctOriginalKey && originalKey !== correctOriginalKey) {
  3991. var warningKey = originalKey + ',' + correctOriginalKey;
  3992. if (warnedAbout[warningKey]) {
  3993. continue;
  3994. }
  3995. warnedAbout[warningKey] = true;
  3996. error('%s a style property during rerender (%s) when a ' + 'conflicting property is set (%s) can lead to styling bugs. To ' + "avoid this, don't mix shorthand and non-shorthand properties " + 'for the same value; instead, replace the shorthand with ' + 'separate values.', isValueEmpty(styleUpdates[originalKey]) ? 'Removing' : 'Updating', originalKey, correctOriginalKey);
  3997. }
  3998. }
  3999. }
  4000. }
  4001. // For HTML, certain tags should omit their close tag. We keep a whitelist for
  4002. // those special-case tags.
  4003. var omittedCloseTags = {
  4004. area: true,
  4005. base: true,
  4006. br: true,
  4007. col: true,
  4008. embed: true,
  4009. hr: true,
  4010. img: true,
  4011. input: true,
  4012. keygen: true,
  4013. link: true,
  4014. meta: true,
  4015. param: true,
  4016. source: true,
  4017. track: true,
  4018. wbr: true // NOTE: menuitem's close tag should be omitted, but that causes problems.
  4019. };
  4020. // `omittedCloseTags` except that `menuitem` should still have its closing tag.
  4021. var voidElementTags = _assign({
  4022. menuitem: true
  4023. }, omittedCloseTags);
  4024. var HTML = '__html';
  4025. var ReactDebugCurrentFrame$3 = null;
  4026. {
  4027. ReactDebugCurrentFrame$3 = ReactSharedInternals.ReactDebugCurrentFrame;
  4028. }
  4029. function assertValidProps(tag, props) {
  4030. if (!props) {
  4031. return;
  4032. } // Note the use of `==` which checks for null or undefined.
  4033. if (voidElementTags[tag]) {
  4034. if (!(props.children == null && props.dangerouslySetInnerHTML == null)) {
  4035. {
  4036. throw Error( tag + " is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`." + ( ReactDebugCurrentFrame$3.getStackAddendum() ) );
  4037. }
  4038. }
  4039. }
  4040. if (props.dangerouslySetInnerHTML != null) {
  4041. if (!(props.children == null)) {
  4042. {
  4043. throw Error( "Can only set one of `children` or `props.dangerouslySetInnerHTML`." );
  4044. }
  4045. }
  4046. if (!(typeof props.dangerouslySetInnerHTML === 'object' && HTML in props.dangerouslySetInnerHTML)) {
  4047. {
  4048. throw Error( "`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. Please visit https://fb.me/react-invariant-dangerously-set-inner-html for more information." );
  4049. }
  4050. }
  4051. }
  4052. {
  4053. if (!props.suppressContentEditableWarning && props.contentEditable && props.children != null) {
  4054. error('A component is `contentEditable` and contains `children` managed by ' + 'React. It is now your responsibility to guarantee that none of ' + 'those nodes are unexpectedly modified or duplicated. This is ' + 'probably not intentional.');
  4055. }
  4056. }
  4057. if (!(props.style == null || typeof props.style === 'object')) {
  4058. {
  4059. throw Error( "The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX." + ( ReactDebugCurrentFrame$3.getStackAddendum() ) );
  4060. }
  4061. }
  4062. }
  4063. function isCustomComponent(tagName, props) {
  4064. if (tagName.indexOf('-') === -1) {
  4065. return typeof props.is === 'string';
  4066. }
  4067. switch (tagName) {
  4068. // These are reserved SVG and MathML elements.
  4069. // We don't mind this whitelist too much because we expect it to never grow.
  4070. // The alternative is to track the namespace in a few places which is convoluted.
  4071. // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
  4072. case 'annotation-xml':
  4073. case 'color-profile':
  4074. case 'font-face':
  4075. case 'font-face-src':
  4076. case 'font-face-uri':
  4077. case 'font-face-format':
  4078. case 'font-face-name':
  4079. case 'missing-glyph':
  4080. return false;
  4081. default:
  4082. return true;
  4083. }
  4084. }
  4085. // When adding attributes to the HTML or SVG whitelist, be sure to
  4086. // also add them to this module to ensure casing and incorrect name
  4087. // warnings.
  4088. var possibleStandardNames = {
  4089. // HTML
  4090. accept: 'accept',
  4091. acceptcharset: 'acceptCharset',
  4092. 'accept-charset': 'acceptCharset',
  4093. accesskey: 'accessKey',
  4094. action: 'action',
  4095. allowfullscreen: 'allowFullScreen',
  4096. alt: 'alt',
  4097. as: 'as',
  4098. async: 'async',
  4099. autocapitalize: 'autoCapitalize',
  4100. autocomplete: 'autoComplete',
  4101. autocorrect: 'autoCorrect',
  4102. autofocus: 'autoFocus',
  4103. autoplay: 'autoPlay',
  4104. autosave: 'autoSave',
  4105. capture: 'capture',
  4106. cellpadding: 'cellPadding',
  4107. cellspacing: 'cellSpacing',
  4108. challenge: 'challenge',
  4109. charset: 'charSet',
  4110. checked: 'checked',
  4111. children: 'children',
  4112. cite: 'cite',
  4113. class: 'className',
  4114. classid: 'classID',
  4115. classname: 'className',
  4116. cols: 'cols',
  4117. colspan: 'colSpan',
  4118. content: 'content',
  4119. contenteditable: 'contentEditable',
  4120. contextmenu: 'contextMenu',
  4121. controls: 'controls',
  4122. controlslist: 'controlsList',
  4123. coords: 'coords',
  4124. crossorigin: 'crossOrigin',
  4125. dangerouslysetinnerhtml: 'dangerouslySetInnerHTML',
  4126. data: 'data',
  4127. datetime: 'dateTime',
  4128. default: 'default',
  4129. defaultchecked: 'defaultChecked',
  4130. defaultvalue: 'defaultValue',
  4131. defer: 'defer',
  4132. dir: 'dir',
  4133. disabled: 'disabled',
  4134. disablepictureinpicture: 'disablePictureInPicture',
  4135. download: 'download',
  4136. draggable: 'draggable',
  4137. enctype: 'encType',
  4138. for: 'htmlFor',
  4139. form: 'form',
  4140. formmethod: 'formMethod',
  4141. formaction: 'formAction',
  4142. formenctype: 'formEncType',
  4143. formnovalidate: 'formNoValidate',
  4144. formtarget: 'formTarget',
  4145. frameborder: 'frameBorder',
  4146. headers: 'headers',
  4147. height: 'height',
  4148. hidden: 'hidden',
  4149. high: 'high',
  4150. href: 'href',
  4151. hreflang: 'hrefLang',
  4152. htmlfor: 'htmlFor',
  4153. httpequiv: 'httpEquiv',
  4154. 'http-equiv': 'httpEquiv',
  4155. icon: 'icon',
  4156. id: 'id',
  4157. innerhtml: 'innerHTML',
  4158. inputmode: 'inputMode',
  4159. integrity: 'integrity',
  4160. is: 'is',
  4161. itemid: 'itemID',
  4162. itemprop: 'itemProp',
  4163. itemref: 'itemRef',
  4164. itemscope: 'itemScope',
  4165. itemtype: 'itemType',
  4166. keyparams: 'keyParams',
  4167. keytype: 'keyType',
  4168. kind: 'kind',
  4169. label: 'label',
  4170. lang: 'lang',
  4171. list: 'list',
  4172. loop: 'loop',
  4173. low: 'low',
  4174. manifest: 'manifest',
  4175. marginwidth: 'marginWidth',
  4176. marginheight: 'marginHeight',
  4177. max: 'max',
  4178. maxlength: 'maxLength',
  4179. media: 'media',
  4180. mediagroup: 'mediaGroup',
  4181. method: 'method',
  4182. min: 'min',
  4183. minlength: 'minLength',
  4184. multiple: 'multiple',
  4185. muted: 'muted',
  4186. name: 'name',
  4187. nomodule: 'noModule',
  4188. nonce: 'nonce',
  4189. novalidate: 'noValidate',
  4190. open: 'open',
  4191. optimum: 'optimum',
  4192. pattern: 'pattern',
  4193. placeholder: 'placeholder',
  4194. playsinline: 'playsInline',
  4195. poster: 'poster',
  4196. preload: 'preload',
  4197. profile: 'profile',
  4198. radiogroup: 'radioGroup',
  4199. readonly: 'readOnly',
  4200. referrerpolicy: 'referrerPolicy',
  4201. rel: 'rel',
  4202. required: 'required',
  4203. reversed: 'reversed',
  4204. role: 'role',
  4205. rows: 'rows',
  4206. rowspan: 'rowSpan',
  4207. sandbox: 'sandbox',
  4208. scope: 'scope',
  4209. scoped: 'scoped',
  4210. scrolling: 'scrolling',
  4211. seamless: 'seamless',
  4212. selected: 'selected',
  4213. shape: 'shape',
  4214. size: 'size',
  4215. sizes: 'sizes',
  4216. span: 'span',
  4217. spellcheck: 'spellCheck',
  4218. src: 'src',
  4219. srcdoc: 'srcDoc',
  4220. srclang: 'srcLang',
  4221. srcset: 'srcSet',
  4222. start: 'start',
  4223. step: 'step',
  4224. style: 'style',
  4225. summary: 'summary',
  4226. tabindex: 'tabIndex',
  4227. target: 'target',
  4228. title: 'title',
  4229. type: 'type',
  4230. usemap: 'useMap',
  4231. value: 'value',
  4232. width: 'width',
  4233. wmode: 'wmode',
  4234. wrap: 'wrap',
  4235. // SVG
  4236. about: 'about',
  4237. accentheight: 'accentHeight',
  4238. 'accent-height': 'accentHeight',
  4239. accumulate: 'accumulate',
  4240. additive: 'additive',
  4241. alignmentbaseline: 'alignmentBaseline',
  4242. 'alignment-baseline': 'alignmentBaseline',
  4243. allowreorder: 'allowReorder',
  4244. alphabetic: 'alphabetic',
  4245. amplitude: 'amplitude',
  4246. arabicform: 'arabicForm',
  4247. 'arabic-form': 'arabicForm',
  4248. ascent: 'ascent',
  4249. attributename: 'attributeName',
  4250. attributetype: 'attributeType',
  4251. autoreverse: 'autoReverse',
  4252. azimuth: 'azimuth',
  4253. basefrequency: 'baseFrequency',
  4254. baselineshift: 'baselineShift',
  4255. 'baseline-shift': 'baselineShift',
  4256. baseprofile: 'baseProfile',
  4257. bbox: 'bbox',
  4258. begin: 'begin',
  4259. bias: 'bias',
  4260. by: 'by',
  4261. calcmode: 'calcMode',
  4262. capheight: 'capHeight',
  4263. 'cap-height': 'capHeight',
  4264. clip: 'clip',
  4265. clippath: 'clipPath',
  4266. 'clip-path': 'clipPath',
  4267. clippathunits: 'clipPathUnits',
  4268. cliprule: 'clipRule',
  4269. 'clip-rule': 'clipRule',
  4270. color: 'color',
  4271. colorinterpolation: 'colorInterpolation',
  4272. 'color-interpolation': 'colorInterpolation',
  4273. colorinterpolationfilters: 'colorInterpolationFilters',
  4274. 'color-interpolation-filters': 'colorInterpolationFilters',
  4275. colorprofile: 'colorProfile',
  4276. 'color-profile': 'colorProfile',
  4277. colorrendering: 'colorRendering',
  4278. 'color-rendering': 'colorRendering',
  4279. contentscripttype: 'contentScriptType',
  4280. contentstyletype: 'contentStyleType',
  4281. cursor: 'cursor',
  4282. cx: 'cx',
  4283. cy: 'cy',
  4284. d: 'd',
  4285. datatype: 'datatype',
  4286. decelerate: 'decelerate',
  4287. descent: 'descent',
  4288. diffuseconstant: 'diffuseConstant',
  4289. direction: 'direction',
  4290. display: 'display',
  4291. divisor: 'divisor',
  4292. dominantbaseline: 'dominantBaseline',
  4293. 'dominant-baseline': 'dominantBaseline',
  4294. dur: 'dur',
  4295. dx: 'dx',
  4296. dy: 'dy',
  4297. edgemode: 'edgeMode',
  4298. elevation: 'elevation',
  4299. enablebackground: 'enableBackground',
  4300. 'enable-background': 'enableBackground',
  4301. end: 'end',
  4302. exponent: 'exponent',
  4303. externalresourcesrequired: 'externalResourcesRequired',
  4304. fill: 'fill',
  4305. fillopacity: 'fillOpacity',
  4306. 'fill-opacity': 'fillOpacity',
  4307. fillrule: 'fillRule',
  4308. 'fill-rule': 'fillRule',
  4309. filter: 'filter',
  4310. filterres: 'filterRes',
  4311. filterunits: 'filterUnits',
  4312. floodopacity: 'floodOpacity',
  4313. 'flood-opacity': 'floodOpacity',
  4314. floodcolor: 'floodColor',
  4315. 'flood-color': 'floodColor',
  4316. focusable: 'focusable',
  4317. fontfamily: 'fontFamily',
  4318. 'font-family': 'fontFamily',
  4319. fontsize: 'fontSize',
  4320. 'font-size': 'fontSize',
  4321. fontsizeadjust: 'fontSizeAdjust',
  4322. 'font-size-adjust': 'fontSizeAdjust',
  4323. fontstretch: 'fontStretch',
  4324. 'font-stretch': 'fontStretch',
  4325. fontstyle: 'fontStyle',
  4326. 'font-style': 'fontStyle',
  4327. fontvariant: 'fontVariant',
  4328. 'font-variant': 'fontVariant',
  4329. fontweight: 'fontWeight',
  4330. 'font-weight': 'fontWeight',
  4331. format: 'format',
  4332. from: 'from',
  4333. fx: 'fx',
  4334. fy: 'fy',
  4335. g1: 'g1',
  4336. g2: 'g2',
  4337. glyphname: 'glyphName',
  4338. 'glyph-name': 'glyphName',
  4339. glyphorientationhorizontal: 'glyphOrientationHorizontal',
  4340. 'glyph-orientation-horizontal': 'glyphOrientationHorizontal',
  4341. glyphorientationvertical: 'glyphOrientationVertical',
  4342. 'glyph-orientation-vertical': 'glyphOrientationVertical',
  4343. glyphref: 'glyphRef',
  4344. gradienttransform: 'gradientTransform',
  4345. gradientunits: 'gradientUnits',
  4346. hanging: 'hanging',
  4347. horizadvx: 'horizAdvX',
  4348. 'horiz-adv-x': 'horizAdvX',
  4349. horizoriginx: 'horizOriginX',
  4350. 'horiz-origin-x': 'horizOriginX',
  4351. ideographic: 'ideographic',
  4352. imagerendering: 'imageRendering',
  4353. 'image-rendering': 'imageRendering',
  4354. in2: 'in2',
  4355. in: 'in',
  4356. inlist: 'inlist',
  4357. intercept: 'intercept',
  4358. k1: 'k1',
  4359. k2: 'k2',
  4360. k3: 'k3',
  4361. k4: 'k4',
  4362. k: 'k',
  4363. kernelmatrix: 'kernelMatrix',
  4364. kernelunitlength: 'kernelUnitLength',
  4365. kerning: 'kerning',
  4366. keypoints: 'keyPoints',
  4367. keysplines: 'keySplines',
  4368. keytimes: 'keyTimes',
  4369. lengthadjust: 'lengthAdjust',
  4370. letterspacing: 'letterSpacing',
  4371. 'letter-spacing': 'letterSpacing',
  4372. lightingcolor: 'lightingColor',
  4373. 'lighting-color': 'lightingColor',
  4374. limitingconeangle: 'limitingConeAngle',
  4375. local: 'local',
  4376. markerend: 'markerEnd',
  4377. 'marker-end': 'markerEnd',
  4378. markerheight: 'markerHeight',
  4379. markermid: 'markerMid',
  4380. 'marker-mid': 'markerMid',
  4381. markerstart: 'markerStart',
  4382. 'marker-start': 'markerStart',
  4383. markerunits: 'markerUnits',
  4384. markerwidth: 'markerWidth',
  4385. mask: 'mask',
  4386. maskcontentunits: 'maskContentUnits',
  4387. maskunits: 'maskUnits',
  4388. mathematical: 'mathematical',
  4389. mode: 'mode',
  4390. numoctaves: 'numOctaves',
  4391. offset: 'offset',
  4392. opacity: 'opacity',
  4393. operator: 'operator',
  4394. order: 'order',
  4395. orient: 'orient',
  4396. orientation: 'orientation',
  4397. origin: 'origin',
  4398. overflow: 'overflow',
  4399. overlineposition: 'overlinePosition',
  4400. 'overline-position': 'overlinePosition',
  4401. overlinethickness: 'overlineThickness',
  4402. 'overline-thickness': 'overlineThickness',
  4403. paintorder: 'paintOrder',
  4404. 'paint-order': 'paintOrder',
  4405. panose1: 'panose1',
  4406. 'panose-1': 'panose1',
  4407. pathlength: 'pathLength',
  4408. patterncontentunits: 'patternContentUnits',
  4409. patterntransform: 'patternTransform',
  4410. patternunits: 'patternUnits',
  4411. pointerevents: 'pointerEvents',
  4412. 'pointer-events': 'pointerEvents',
  4413. points: 'points',
  4414. pointsatx: 'pointsAtX',
  4415. pointsaty: 'pointsAtY',
  4416. pointsatz: 'pointsAtZ',
  4417. prefix: 'prefix',
  4418. preservealpha: 'preserveAlpha',
  4419. preserveaspectratio: 'preserveAspectRatio',
  4420. primitiveunits: 'primitiveUnits',
  4421. property: 'property',
  4422. r: 'r',
  4423. radius: 'radius',
  4424. refx: 'refX',
  4425. refy: 'refY',
  4426. renderingintent: 'renderingIntent',
  4427. 'rendering-intent': 'renderingIntent',
  4428. repeatcount: 'repeatCount',
  4429. repeatdur: 'repeatDur',
  4430. requiredextensions: 'requiredExtensions',
  4431. requiredfeatures: 'requiredFeatures',
  4432. resource: 'resource',
  4433. restart: 'restart',
  4434. result: 'result',
  4435. results: 'results',
  4436. rotate: 'rotate',
  4437. rx: 'rx',
  4438. ry: 'ry',
  4439. scale: 'scale',
  4440. security: 'security',
  4441. seed: 'seed',
  4442. shaperendering: 'shapeRendering',
  4443. 'shape-rendering': 'shapeRendering',
  4444. slope: 'slope',
  4445. spacing: 'spacing',
  4446. specularconstant: 'specularConstant',
  4447. specularexponent: 'specularExponent',
  4448. speed: 'speed',
  4449. spreadmethod: 'spreadMethod',
  4450. startoffset: 'startOffset',
  4451. stddeviation: 'stdDeviation',
  4452. stemh: 'stemh',
  4453. stemv: 'stemv',
  4454. stitchtiles: 'stitchTiles',
  4455. stopcolor: 'stopColor',
  4456. 'stop-color': 'stopColor',
  4457. stopopacity: 'stopOpacity',
  4458. 'stop-opacity': 'stopOpacity',
  4459. strikethroughposition: 'strikethroughPosition',
  4460. 'strikethrough-position': 'strikethroughPosition',
  4461. strikethroughthickness: 'strikethroughThickness',
  4462. 'strikethrough-thickness': 'strikethroughThickness',
  4463. string: 'string',
  4464. stroke: 'stroke',
  4465. strokedasharray: 'strokeDasharray',
  4466. 'stroke-dasharray': 'strokeDasharray',
  4467. strokedashoffset: 'strokeDashoffset',
  4468. 'stroke-dashoffset': 'strokeDashoffset',
  4469. strokelinecap: 'strokeLinecap',
  4470. 'stroke-linecap': 'strokeLinecap',
  4471. strokelinejoin: 'strokeLinejoin',
  4472. 'stroke-linejoin': 'strokeLinejoin',
  4473. strokemiterlimit: 'strokeMiterlimit',
  4474. 'stroke-miterlimit': 'strokeMiterlimit',
  4475. strokewidth: 'strokeWidth',
  4476. 'stroke-width': 'strokeWidth',
  4477. strokeopacity: 'strokeOpacity',
  4478. 'stroke-opacity': 'strokeOpacity',
  4479. suppresscontenteditablewarning: 'suppressContentEditableWarning',
  4480. suppresshydrationwarning: 'suppressHydrationWarning',
  4481. surfacescale: 'surfaceScale',
  4482. systemlanguage: 'systemLanguage',
  4483. tablevalues: 'tableValues',
  4484. targetx: 'targetX',
  4485. targety: 'targetY',
  4486. textanchor: 'textAnchor',
  4487. 'text-anchor': 'textAnchor',
  4488. textdecoration: 'textDecoration',
  4489. 'text-decoration': 'textDecoration',
  4490. textlength: 'textLength',
  4491. textrendering: 'textRendering',
  4492. 'text-rendering': 'textRendering',
  4493. to: 'to',
  4494. transform: 'transform',
  4495. typeof: 'typeof',
  4496. u1: 'u1',
  4497. u2: 'u2',
  4498. underlineposition: 'underlinePosition',
  4499. 'underline-position': 'underlinePosition',
  4500. underlinethickness: 'underlineThickness',
  4501. 'underline-thickness': 'underlineThickness',
  4502. unicode: 'unicode',
  4503. unicodebidi: 'unicodeBidi',
  4504. 'unicode-bidi': 'unicodeBidi',
  4505. unicoderange: 'unicodeRange',
  4506. 'unicode-range': 'unicodeRange',
  4507. unitsperem: 'unitsPerEm',
  4508. 'units-per-em': 'unitsPerEm',
  4509. unselectable: 'unselectable',
  4510. valphabetic: 'vAlphabetic',
  4511. 'v-alphabetic': 'vAlphabetic',
  4512. values: 'values',
  4513. vectoreffect: 'vectorEffect',
  4514. 'vector-effect': 'vectorEffect',
  4515. version: 'version',
  4516. vertadvy: 'vertAdvY',
  4517. 'vert-adv-y': 'vertAdvY',
  4518. vertoriginx: 'vertOriginX',
  4519. 'vert-origin-x': 'vertOriginX',
  4520. vertoriginy: 'vertOriginY',
  4521. 'vert-origin-y': 'vertOriginY',
  4522. vhanging: 'vHanging',
  4523. 'v-hanging': 'vHanging',
  4524. videographic: 'vIdeographic',
  4525. 'v-ideographic': 'vIdeographic',
  4526. viewbox: 'viewBox',
  4527. viewtarget: 'viewTarget',
  4528. visibility: 'visibility',
  4529. vmathematical: 'vMathematical',
  4530. 'v-mathematical': 'vMathematical',
  4531. vocab: 'vocab',
  4532. widths: 'widths',
  4533. wordspacing: 'wordSpacing',
  4534. 'word-spacing': 'wordSpacing',
  4535. writingmode: 'writingMode',
  4536. 'writing-mode': 'writingMode',
  4537. x1: 'x1',
  4538. x2: 'x2',
  4539. x: 'x',
  4540. xchannelselector: 'xChannelSelector',
  4541. xheight: 'xHeight',
  4542. 'x-height': 'xHeight',
  4543. xlinkactuate: 'xlinkActuate',
  4544. 'xlink:actuate': 'xlinkActuate',
  4545. xlinkarcrole: 'xlinkArcrole',
  4546. 'xlink:arcrole': 'xlinkArcrole',
  4547. xlinkhref: 'xlinkHref',
  4548. 'xlink:href': 'xlinkHref',
  4549. xlinkrole: 'xlinkRole',
  4550. 'xlink:role': 'xlinkRole',
  4551. xlinkshow: 'xlinkShow',
  4552. 'xlink:show': 'xlinkShow',
  4553. xlinktitle: 'xlinkTitle',
  4554. 'xlink:title': 'xlinkTitle',
  4555. xlinktype: 'xlinkType',
  4556. 'xlink:type': 'xlinkType',
  4557. xmlbase: 'xmlBase',
  4558. 'xml:base': 'xmlBase',
  4559. xmllang: 'xmlLang',
  4560. 'xml:lang': 'xmlLang',
  4561. xmlns: 'xmlns',
  4562. 'xml:space': 'xmlSpace',
  4563. xmlnsxlink: 'xmlnsXlink',
  4564. 'xmlns:xlink': 'xmlnsXlink',
  4565. xmlspace: 'xmlSpace',
  4566. y1: 'y1',
  4567. y2: 'y2',
  4568. y: 'y',
  4569. ychannelselector: 'yChannelSelector',
  4570. z: 'z',
  4571. zoomandpan: 'zoomAndPan'
  4572. };
  4573. var ariaProperties = {
  4574. 'aria-current': 0,
  4575. // state
  4576. 'aria-details': 0,
  4577. 'aria-disabled': 0,
  4578. // state
  4579. 'aria-hidden': 0,
  4580. // state
  4581. 'aria-invalid': 0,
  4582. // state
  4583. 'aria-keyshortcuts': 0,
  4584. 'aria-label': 0,
  4585. 'aria-roledescription': 0,
  4586. // Widget Attributes
  4587. 'aria-autocomplete': 0,
  4588. 'aria-checked': 0,
  4589. 'aria-expanded': 0,
  4590. 'aria-haspopup': 0,
  4591. 'aria-level': 0,
  4592. 'aria-modal': 0,
  4593. 'aria-multiline': 0,
  4594. 'aria-multiselectable': 0,
  4595. 'aria-orientation': 0,
  4596. 'aria-placeholder': 0,
  4597. 'aria-pressed': 0,
  4598. 'aria-readonly': 0,
  4599. 'aria-required': 0,
  4600. 'aria-selected': 0,
  4601. 'aria-sort': 0,
  4602. 'aria-valuemax': 0,
  4603. 'aria-valuemin': 0,
  4604. 'aria-valuenow': 0,
  4605. 'aria-valuetext': 0,
  4606. // Live Region Attributes
  4607. 'aria-atomic': 0,
  4608. 'aria-busy': 0,
  4609. 'aria-live': 0,
  4610. 'aria-relevant': 0,
  4611. // Drag-and-Drop Attributes
  4612. 'aria-dropeffect': 0,
  4613. 'aria-grabbed': 0,
  4614. // Relationship Attributes
  4615. 'aria-activedescendant': 0,
  4616. 'aria-colcount': 0,
  4617. 'aria-colindex': 0,
  4618. 'aria-colspan': 0,
  4619. 'aria-controls': 0,
  4620. 'aria-describedby': 0,
  4621. 'aria-errormessage': 0,
  4622. 'aria-flowto': 0,
  4623. 'aria-labelledby': 0,
  4624. 'aria-owns': 0,
  4625. 'aria-posinset': 0,
  4626. 'aria-rowcount': 0,
  4627. 'aria-rowindex': 0,
  4628. 'aria-rowspan': 0,
  4629. 'aria-setsize': 0
  4630. };
  4631. var warnedProperties = {};
  4632. var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  4633. var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  4634. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  4635. function validateProperty(tagName, name) {
  4636. {
  4637. if (hasOwnProperty$1.call(warnedProperties, name) && warnedProperties[name]) {
  4638. return true;
  4639. }
  4640. if (rARIACamel.test(name)) {
  4641. var ariaName = 'aria-' + name.slice(4).toLowerCase();
  4642. var correctName = ariaProperties.hasOwnProperty(ariaName) ? ariaName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  4643. // DOM properties, then it is an invalid aria-* attribute.
  4644. if (correctName == null) {
  4645. error('Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.', name);
  4646. warnedProperties[name] = true;
  4647. return true;
  4648. } // aria-* attributes should be lowercase; suggest the lowercase version.
  4649. if (name !== correctName) {
  4650. error('Invalid ARIA attribute `%s`. Did you mean `%s`?', name, correctName);
  4651. warnedProperties[name] = true;
  4652. return true;
  4653. }
  4654. }
  4655. if (rARIA.test(name)) {
  4656. var lowerCasedName = name.toLowerCase();
  4657. var standardName = ariaProperties.hasOwnProperty(lowerCasedName) ? lowerCasedName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  4658. // DOM properties, then it is an invalid aria-* attribute.
  4659. if (standardName == null) {
  4660. warnedProperties[name] = true;
  4661. return false;
  4662. } // aria-* attributes should be lowercase; suggest the lowercase version.
  4663. if (name !== standardName) {
  4664. error('Unknown ARIA attribute `%s`. Did you mean `%s`?', name, standardName);
  4665. warnedProperties[name] = true;
  4666. return true;
  4667. }
  4668. }
  4669. }
  4670. return true;
  4671. }
  4672. function warnInvalidARIAProps(type, props) {
  4673. {
  4674. var invalidProps = [];
  4675. for (var key in props) {
  4676. var isValid = validateProperty(type, key);
  4677. if (!isValid) {
  4678. invalidProps.push(key);
  4679. }
  4680. }
  4681. var unknownPropString = invalidProps.map(function (prop) {
  4682. return '`' + prop + '`';
  4683. }).join(', ');
  4684. if (invalidProps.length === 1) {
  4685. error('Invalid aria prop %s on <%s> tag. ' + 'For details, see https://fb.me/invalid-aria-prop', unknownPropString, type);
  4686. } else if (invalidProps.length > 1) {
  4687. error('Invalid aria props %s on <%s> tag. ' + 'For details, see https://fb.me/invalid-aria-prop', unknownPropString, type);
  4688. }
  4689. }
  4690. }
  4691. function validateProperties(type, props) {
  4692. if (isCustomComponent(type, props)) {
  4693. return;
  4694. }
  4695. warnInvalidARIAProps(type, props);
  4696. }
  4697. var didWarnValueNull = false;
  4698. function validateProperties$1(type, props) {
  4699. {
  4700. if (type !== 'input' && type !== 'textarea' && type !== 'select') {
  4701. return;
  4702. }
  4703. if (props != null && props.value === null && !didWarnValueNull) {
  4704. didWarnValueNull = true;
  4705. if (type === 'select' && props.multiple) {
  4706. error('`value` prop on `%s` should not be null. ' + 'Consider using an empty array when `multiple` is set to `true` ' + 'to clear the component or `undefined` for uncontrolled components.', type);
  4707. } else {
  4708. error('`value` prop on `%s` should not be null. ' + 'Consider using an empty string to clear the component or `undefined` ' + 'for uncontrolled components.', type);
  4709. }
  4710. }
  4711. }
  4712. }
  4713. var validateProperty$1 = function () {};
  4714. {
  4715. var warnedProperties$1 = {};
  4716. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  4717. var EVENT_NAME_REGEX = /^on./;
  4718. var INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
  4719. var rARIA$1 = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  4720. var rARIACamel$1 = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  4721. validateProperty$1 = function (tagName, name, value, canUseEventSystem) {
  4722. if (_hasOwnProperty.call(warnedProperties$1, name) && warnedProperties$1[name]) {
  4723. return true;
  4724. }
  4725. var lowerCasedName = name.toLowerCase();
  4726. if (lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout') {
  4727. error('React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' + 'All React events are normalized to bubble, so onFocusIn and onFocusOut ' + 'are not needed/supported by React.');
  4728. warnedProperties$1[name] = true;
  4729. return true;
  4730. } // We can't rely on the event system being injected on the server.
  4731. if (canUseEventSystem) {
  4732. if (registrationNameModules.hasOwnProperty(name)) {
  4733. return true;
  4734. }
  4735. var registrationName = possibleRegistrationNames.hasOwnProperty(lowerCasedName) ? possibleRegistrationNames[lowerCasedName] : null;
  4736. if (registrationName != null) {
  4737. error('Invalid event handler property `%s`. Did you mean `%s`?', name, registrationName);
  4738. warnedProperties$1[name] = true;
  4739. return true;
  4740. }
  4741. if (EVENT_NAME_REGEX.test(name)) {
  4742. error('Unknown event handler property `%s`. It will be ignored.', name);
  4743. warnedProperties$1[name] = true;
  4744. return true;
  4745. }
  4746. } else if (EVENT_NAME_REGEX.test(name)) {
  4747. // If no event plugins have been injected, we are in a server environment.
  4748. // So we can't tell if the event name is correct for sure, but we can filter
  4749. // out known bad ones like `onclick`. We can't suggest a specific replacement though.
  4750. if (INVALID_EVENT_NAME_REGEX.test(name)) {
  4751. error('Invalid event handler property `%s`. ' + 'React events use the camelCase naming convention, for example `onClick`.', name);
  4752. }
  4753. warnedProperties$1[name] = true;
  4754. return true;
  4755. } // Let the ARIA attribute hook validate ARIA attributes
  4756. if (rARIA$1.test(name) || rARIACamel$1.test(name)) {
  4757. return true;
  4758. }
  4759. if (lowerCasedName === 'innerhtml') {
  4760. error('Directly setting property `innerHTML` is not permitted. ' + 'For more information, lookup documentation on `dangerouslySetInnerHTML`.');
  4761. warnedProperties$1[name] = true;
  4762. return true;
  4763. }
  4764. if (lowerCasedName === 'aria') {
  4765. error('The `aria` attribute is reserved for future use in React. ' + 'Pass individual `aria-` attributes instead.');
  4766. warnedProperties$1[name] = true;
  4767. return true;
  4768. }
  4769. if (lowerCasedName === 'is' && value !== null && value !== undefined && typeof value !== 'string') {
  4770. error('Received a `%s` for a string attribute `is`. If this is expected, cast ' + 'the value to a string.', typeof value);
  4771. warnedProperties$1[name] = true;
  4772. return true;
  4773. }
  4774. if (typeof value === 'number' && isNaN(value)) {
  4775. error('Received NaN for the `%s` attribute. If this is expected, cast ' + 'the value to a string.', name);
  4776. warnedProperties$1[name] = true;
  4777. return true;
  4778. }
  4779. var propertyInfo = getPropertyInfo(name);
  4780. var isReserved = propertyInfo !== null && propertyInfo.type === RESERVED; // Known attributes should match the casing specified in the property config.
  4781. if (possibleStandardNames.hasOwnProperty(lowerCasedName)) {
  4782. var standardName = possibleStandardNames[lowerCasedName];
  4783. if (standardName !== name) {
  4784. error('Invalid DOM property `%s`. Did you mean `%s`?', name, standardName);
  4785. warnedProperties$1[name] = true;
  4786. return true;
  4787. }
  4788. } else if (!isReserved && name !== lowerCasedName) {
  4789. // Unknown attributes should have lowercase casing since that's how they
  4790. // will be cased anyway with server rendering.
  4791. error('React does not recognize the `%s` prop on a DOM element. If you ' + 'intentionally want it to appear in the DOM as a custom ' + 'attribute, spell it as lowercase `%s` instead. ' + 'If you accidentally passed it from a parent component, remove ' + 'it from the DOM element.', name, lowerCasedName);
  4792. warnedProperties$1[name] = true;
  4793. return true;
  4794. }
  4795. if (typeof value === 'boolean' && shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  4796. if (value) {
  4797. error('Received `%s` for a non-boolean attribute `%s`.\n\n' + 'If you want to write it to the DOM, pass a string instead: ' + '%s="%s" or %s={value.toString()}.', value, name, name, value, name);
  4798. } else {
  4799. error('Received `%s` for a non-boolean attribute `%s`.\n\n' + 'If you want to write it to the DOM, pass a string instead: ' + '%s="%s" or %s={value.toString()}.\n\n' + 'If you used to conditionally omit it with %s={condition && value}, ' + 'pass %s={condition ? value : undefined} instead.', value, name, name, value, name, name, name);
  4800. }
  4801. warnedProperties$1[name] = true;
  4802. return true;
  4803. } // Now that we've validated casing, do not validate
  4804. // data types for reserved props
  4805. if (isReserved) {
  4806. return true;
  4807. } // Warn when a known attribute is a bad type
  4808. if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  4809. warnedProperties$1[name] = true;
  4810. return false;
  4811. } // Warn when passing the strings 'false' or 'true' into a boolean prop
  4812. if ((value === 'false' || value === 'true') && propertyInfo !== null && propertyInfo.type === BOOLEAN) {
  4813. error('Received the string `%s` for the boolean attribute `%s`. ' + '%s ' + 'Did you mean %s={%s}?', value, name, value === 'false' ? 'The browser will interpret it as a truthy value.' : 'Although this works, it will not work as expected if you pass the string "false".', name, value);
  4814. warnedProperties$1[name] = true;
  4815. return true;
  4816. }
  4817. return true;
  4818. };
  4819. }
  4820. var warnUnknownProperties = function (type, props, canUseEventSystem) {
  4821. {
  4822. var unknownProps = [];
  4823. for (var key in props) {
  4824. var isValid = validateProperty$1(type, key, props[key], canUseEventSystem);
  4825. if (!isValid) {
  4826. unknownProps.push(key);
  4827. }
  4828. }
  4829. var unknownPropString = unknownProps.map(function (prop) {
  4830. return '`' + prop + '`';
  4831. }).join(', ');
  4832. if (unknownProps.length === 1) {
  4833. error('Invalid value for prop %s on <%s> tag. Either remove it from the element, ' + 'or pass a string or number value to keep it in the DOM. ' + 'For details, see https://fb.me/react-attribute-behavior', unknownPropString, type);
  4834. } else if (unknownProps.length > 1) {
  4835. error('Invalid values for props %s on <%s> tag. Either remove them from the element, ' + 'or pass a string or number value to keep them in the DOM. ' + 'For details, see https://fb.me/react-attribute-behavior', unknownPropString, type);
  4836. }
  4837. }
  4838. };
  4839. function validateProperties$2(type, props, canUseEventSystem) {
  4840. if (isCustomComponent(type, props)) {
  4841. return;
  4842. }
  4843. warnUnknownProperties(type, props, canUseEventSystem);
  4844. }
  4845. var didWarnInvalidHydration = false;
  4846. var DANGEROUSLY_SET_INNER_HTML = 'dangerouslySetInnerHTML';
  4847. var SUPPRESS_CONTENT_EDITABLE_WARNING = 'suppressContentEditableWarning';
  4848. var SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
  4849. var AUTOFOCUS = 'autoFocus';
  4850. var CHILDREN = 'children';
  4851. var STYLE = 'style';
  4852. var HTML$1 = '__html';
  4853. var HTML_NAMESPACE$1 = Namespaces.html;
  4854. var warnedUnknownTags;
  4855. var suppressHydrationWarning;
  4856. var validatePropertiesInDevelopment;
  4857. var warnForTextDifference;
  4858. var warnForPropDifference;
  4859. var warnForExtraAttributes;
  4860. var warnForInvalidEventListener;
  4861. var canDiffStyleForHydrationWarning;
  4862. var normalizeMarkupForTextOrAttribute;
  4863. var normalizeHTML;
  4864. {
  4865. warnedUnknownTags = {
  4866. // Chrome is the only major browser not shipping <time>. But as of July
  4867. // 2017 it intends to ship it due to widespread usage. We intentionally
  4868. // *don't* warn for <time> even if it's unrecognized by Chrome because
  4869. // it soon will be, and many apps have been using it anyway.
  4870. time: true,
  4871. // There are working polyfills for <dialog>. Let people use it.
  4872. dialog: true,
  4873. // Electron ships a custom <webview> tag to display external web content in
  4874. // an isolated frame and process.
  4875. // This tag is not present in non Electron environments such as JSDom which
  4876. // is often used for testing purposes.
  4877. // @see https://electronjs.org/docs/api/webview-tag
  4878. webview: true
  4879. };
  4880. validatePropertiesInDevelopment = function (type, props) {
  4881. validateProperties(type, props);
  4882. validateProperties$1(type, props);
  4883. validateProperties$2(type, props,
  4884. /* canUseEventSystem */
  4885. true);
  4886. }; // IE 11 parses & normalizes the style attribute as opposed to other
  4887. // browsers. It adds spaces and sorts the properties in some
  4888. // non-alphabetical order. Handling that would require sorting CSS
  4889. // properties in the client & server versions or applying
  4890. // `expectedStyle` to a temporary DOM node to read its `style` attribute
  4891. // normalized. Since it only affects IE, we're skipping style warnings
  4892. // in that browser completely in favor of doing all that work.
  4893. // See https://github.com/facebook/react/issues/11807
  4894. canDiffStyleForHydrationWarning = canUseDOM && !document.documentMode; // HTML parsing normalizes CR and CRLF to LF.
  4895. // It also can turn \u0000 into \uFFFD inside attributes.
  4896. // https://www.w3.org/TR/html5/single-page.html#preprocessing-the-input-stream
  4897. // If we have a mismatch, it might be caused by that.
  4898. // We will still patch up in this case but not fire the warning.
  4899. var NORMALIZE_NEWLINES_REGEX = /\r\n?/g;
  4900. var NORMALIZE_NULL_AND_REPLACEMENT_REGEX = /\u0000|\uFFFD/g;
  4901. normalizeMarkupForTextOrAttribute = function (markup) {
  4902. var markupString = typeof markup === 'string' ? markup : '' + markup;
  4903. return markupString.replace(NORMALIZE_NEWLINES_REGEX, '\n').replace(NORMALIZE_NULL_AND_REPLACEMENT_REGEX, '');
  4904. };
  4905. warnForTextDifference = function (serverText, clientText) {
  4906. if (didWarnInvalidHydration) {
  4907. return;
  4908. }
  4909. var normalizedClientText = normalizeMarkupForTextOrAttribute(clientText);
  4910. var normalizedServerText = normalizeMarkupForTextOrAttribute(serverText);
  4911. if (normalizedServerText === normalizedClientText) {
  4912. return;
  4913. }
  4914. didWarnInvalidHydration = true;
  4915. error('Text content did not match. Server: "%s" Client: "%s"', normalizedServerText, normalizedClientText);
  4916. };
  4917. warnForPropDifference = function (propName, serverValue, clientValue) {
  4918. if (didWarnInvalidHydration) {
  4919. return;
  4920. }
  4921. var normalizedClientValue = normalizeMarkupForTextOrAttribute(clientValue);
  4922. var normalizedServerValue = normalizeMarkupForTextOrAttribute(serverValue);
  4923. if (normalizedServerValue === normalizedClientValue) {
  4924. return;
  4925. }
  4926. didWarnInvalidHydration = true;
  4927. error('Prop `%s` did not match. Server: %s Client: %s', propName, JSON.stringify(normalizedServerValue), JSON.stringify(normalizedClientValue));
  4928. };
  4929. warnForExtraAttributes = function (attributeNames) {
  4930. if (didWarnInvalidHydration) {
  4931. return;
  4932. }
  4933. didWarnInvalidHydration = true;
  4934. var names = [];
  4935. attributeNames.forEach(function (name) {
  4936. names.push(name);
  4937. });
  4938. error('Extra attributes from the server: %s', names);
  4939. };
  4940. warnForInvalidEventListener = function (registrationName, listener) {
  4941. if (listener === false) {
  4942. error('Expected `%s` listener to be a function, instead got `false`.\n\n' + 'If you used to conditionally omit it with %s={condition && value}, ' + 'pass %s={condition ? value : undefined} instead.', registrationName, registrationName, registrationName);
  4943. } else {
  4944. error('Expected `%s` listener to be a function, instead got a value of `%s` type.', registrationName, typeof listener);
  4945. }
  4946. }; // Parse the HTML and read it back to normalize the HTML string so that it
  4947. // can be used for comparison.
  4948. normalizeHTML = function (parent, html) {
  4949. // We could have created a separate document here to avoid
  4950. // re-initializing custom elements if they exist. But this breaks
  4951. // how <noscript> is being handled. So we use the same document.
  4952. // See the discussion in https://github.com/facebook/react/pull/11157.
  4953. var testElement = parent.namespaceURI === HTML_NAMESPACE$1 ? parent.ownerDocument.createElement(parent.tagName) : parent.ownerDocument.createElementNS(parent.namespaceURI, parent.tagName);
  4954. testElement.innerHTML = html;
  4955. return testElement.innerHTML;
  4956. };
  4957. }
  4958. function ensureListeningTo(rootContainerElement, registrationName) {
  4959. var isDocumentOrFragment = rootContainerElement.nodeType === DOCUMENT_NODE || rootContainerElement.nodeType === DOCUMENT_FRAGMENT_NODE;
  4960. var doc = isDocumentOrFragment ? rootContainerElement : rootContainerElement.ownerDocument;
  4961. legacyListenToEvent(registrationName, doc);
  4962. }
  4963. function getOwnerDocumentFromRootContainer(rootContainerElement) {
  4964. return rootContainerElement.nodeType === DOCUMENT_NODE ? rootContainerElement : rootContainerElement.ownerDocument;
  4965. }
  4966. function noop() {}
  4967. function trapClickOnNonInteractiveElement(node) {
  4968. // Mobile Safari does not fire properly bubble click events on
  4969. // non-interactive elements, which means delegated click listeners do not
  4970. // fire. The workaround for this bug involves attaching an empty click
  4971. // listener on the target node.
  4972. // http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
  4973. // Just set it using the onclick property so that we don't have to manage any
  4974. // bookkeeping for it. Not sure if we need to clear it when the listener is
  4975. // removed.
  4976. // TODO: Only do this for the relevant Safaris maybe?
  4977. node.onclick = noop;
  4978. }
  4979. function setInitialDOMProperties(tag, domElement, rootContainerElement, nextProps, isCustomComponentTag) {
  4980. for (var propKey in nextProps) {
  4981. if (!nextProps.hasOwnProperty(propKey)) {
  4982. continue;
  4983. }
  4984. var nextProp = nextProps[propKey];
  4985. if (propKey === STYLE) {
  4986. {
  4987. if (nextProp) {
  4988. // Freeze the next style object so that we can assume it won't be
  4989. // mutated. We have already warned for this in the past.
  4990. Object.freeze(nextProp);
  4991. }
  4992. } // Relies on `updateStylesByID` not mutating `styleUpdates`.
  4993. setValueForStyles(domElement, nextProp);
  4994. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  4995. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  4996. if (nextHtml != null) {
  4997. setInnerHTML(domElement, nextHtml);
  4998. }
  4999. } else if (propKey === CHILDREN) {
  5000. if (typeof nextProp === 'string') {
  5001. // Avoid setting initial textContent when the text is empty. In IE11 setting
  5002. // textContent on a <textarea> will cause the placeholder to not
  5003. // show within the <textarea> until it has been focused and blurred again.
  5004. // https://github.com/facebook/react/issues/6731#issuecomment-254874553
  5005. var canSetTextContent = tag !== 'textarea' || nextProp !== '';
  5006. if (canSetTextContent) {
  5007. setTextContent(domElement, nextProp);
  5008. }
  5009. } else if (typeof nextProp === 'number') {
  5010. setTextContent(domElement, '' + nextProp);
  5011. }
  5012. } else if ( propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (propKey === AUTOFOCUS) ; else if (registrationNameModules.hasOwnProperty(propKey)) {
  5013. if (nextProp != null) {
  5014. if ( typeof nextProp !== 'function') {
  5015. warnForInvalidEventListener(propKey, nextProp);
  5016. }
  5017. ensureListeningTo(rootContainerElement, propKey);
  5018. }
  5019. } else if (nextProp != null) {
  5020. setValueForProperty(domElement, propKey, nextProp, isCustomComponentTag);
  5021. }
  5022. }
  5023. }
  5024. function updateDOMProperties(domElement, updatePayload, wasCustomComponentTag, isCustomComponentTag) {
  5025. // TODO: Handle wasCustomComponentTag
  5026. for (var i = 0; i < updatePayload.length; i += 2) {
  5027. var propKey = updatePayload[i];
  5028. var propValue = updatePayload[i + 1];
  5029. if (propKey === STYLE) {
  5030. setValueForStyles(domElement, propValue);
  5031. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  5032. setInnerHTML(domElement, propValue);
  5033. } else if (propKey === CHILDREN) {
  5034. setTextContent(domElement, propValue);
  5035. } else {
  5036. setValueForProperty(domElement, propKey, propValue, isCustomComponentTag);
  5037. }
  5038. }
  5039. }
  5040. function createElement(type, props, rootContainerElement, parentNamespace) {
  5041. var isCustomComponentTag; // We create tags in the namespace of their parent container, except HTML
  5042. // tags get no namespace.
  5043. var ownerDocument = getOwnerDocumentFromRootContainer(rootContainerElement);
  5044. var domElement;
  5045. var namespaceURI = parentNamespace;
  5046. if (namespaceURI === HTML_NAMESPACE$1) {
  5047. namespaceURI = getIntrinsicNamespace(type);
  5048. }
  5049. if (namespaceURI === HTML_NAMESPACE$1) {
  5050. {
  5051. isCustomComponentTag = isCustomComponent(type, props); // Should this check be gated by parent namespace? Not sure we want to
  5052. // allow <SVG> or <mATH>.
  5053. if (!isCustomComponentTag && type !== type.toLowerCase()) {
  5054. error('<%s /> is using incorrect casing. ' + 'Use PascalCase for React components, ' + 'or lowercase for HTML elements.', type);
  5055. }
  5056. }
  5057. if (type === 'script') {
  5058. // Create the script via .innerHTML so its "parser-inserted" flag is
  5059. // set to true and it does not execute
  5060. var div = ownerDocument.createElement('div');
  5061. div.innerHTML = '<script><' + '/script>'; // eslint-disable-line
  5062. // This is guaranteed to yield a script element.
  5063. var firstChild = div.firstChild;
  5064. domElement = div.removeChild(firstChild);
  5065. } else if (typeof props.is === 'string') {
  5066. // $FlowIssue `createElement` should be updated for Web Components
  5067. domElement = ownerDocument.createElement(type, {
  5068. is: props.is
  5069. });
  5070. } else {
  5071. // Separate else branch instead of using `props.is || undefined` above because of a Firefox bug.
  5072. // See discussion in https://github.com/facebook/react/pull/6896
  5073. // and discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1276240
  5074. domElement = ownerDocument.createElement(type); // Normally attributes are assigned in `setInitialDOMProperties`, however the `multiple` and `size`
  5075. // attributes on `select`s needs to be added before `option`s are inserted.
  5076. // This prevents:
  5077. // - a bug where the `select` does not scroll to the correct option because singular
  5078. // `select` elements automatically pick the first item #13222
  5079. // - a bug where the `select` set the first item as selected despite the `size` attribute #14239
  5080. // See https://github.com/facebook/react/issues/13222
  5081. // and https://github.com/facebook/react/issues/14239
  5082. if (type === 'select') {
  5083. var node = domElement;
  5084. if (props.multiple) {
  5085. node.multiple = true;
  5086. } else if (props.size) {
  5087. // Setting a size greater than 1 causes a select to behave like `multiple=true`, where
  5088. // it is possible that no option is selected.
  5089. //
  5090. // This is only necessary when a select in "single selection mode".
  5091. node.size = props.size;
  5092. }
  5093. }
  5094. }
  5095. } else {
  5096. domElement = ownerDocument.createElementNS(namespaceURI, type);
  5097. }
  5098. {
  5099. if (namespaceURI === HTML_NAMESPACE$1) {
  5100. if (!isCustomComponentTag && Object.prototype.toString.call(domElement) === '[object HTMLUnknownElement]' && !Object.prototype.hasOwnProperty.call(warnedUnknownTags, type)) {
  5101. warnedUnknownTags[type] = true;
  5102. error('The tag <%s> is unrecognized in this browser. ' + 'If you meant to render a React component, start its name with ' + 'an uppercase letter.', type);
  5103. }
  5104. }
  5105. }
  5106. return domElement;
  5107. }
  5108. function createTextNode(text, rootContainerElement) {
  5109. return getOwnerDocumentFromRootContainer(rootContainerElement).createTextNode(text);
  5110. }
  5111. function setInitialProperties(domElement, tag, rawProps, rootContainerElement) {
  5112. var isCustomComponentTag = isCustomComponent(tag, rawProps);
  5113. {
  5114. validatePropertiesInDevelopment(tag, rawProps);
  5115. } // TODO: Make sure that we check isMounted before firing any of these events.
  5116. var props;
  5117. switch (tag) {
  5118. case 'iframe':
  5119. case 'object':
  5120. case 'embed':
  5121. trapBubbledEvent(TOP_LOAD, domElement);
  5122. props = rawProps;
  5123. break;
  5124. case 'video':
  5125. case 'audio':
  5126. // Create listener for each media event
  5127. for (var i = 0; i < mediaEventTypes.length; i++) {
  5128. trapBubbledEvent(mediaEventTypes[i], domElement);
  5129. }
  5130. props = rawProps;
  5131. break;
  5132. case 'source':
  5133. trapBubbledEvent(TOP_ERROR, domElement);
  5134. props = rawProps;
  5135. break;
  5136. case 'img':
  5137. case 'image':
  5138. case 'link':
  5139. trapBubbledEvent(TOP_ERROR, domElement);
  5140. trapBubbledEvent(TOP_LOAD, domElement);
  5141. props = rawProps;
  5142. break;
  5143. case 'form':
  5144. trapBubbledEvent(TOP_RESET, domElement);
  5145. trapBubbledEvent(TOP_SUBMIT, domElement);
  5146. props = rawProps;
  5147. break;
  5148. case 'details':
  5149. trapBubbledEvent(TOP_TOGGLE, domElement);
  5150. props = rawProps;
  5151. break;
  5152. case 'input':
  5153. initWrapperState(domElement, rawProps);
  5154. props = getHostProps(domElement, rawProps);
  5155. trapBubbledEvent(TOP_INVALID, domElement); // For controlled components we always need to ensure we're listening
  5156. // to onChange. Even if there is no listener.
  5157. ensureListeningTo(rootContainerElement, 'onChange');
  5158. break;
  5159. case 'option':
  5160. validateProps(domElement, rawProps);
  5161. props = getHostProps$1(domElement, rawProps);
  5162. break;
  5163. case 'select':
  5164. initWrapperState$1(domElement, rawProps);
  5165. props = getHostProps$2(domElement, rawProps);
  5166. trapBubbledEvent(TOP_INVALID, domElement); // For controlled components we always need to ensure we're listening
  5167. // to onChange. Even if there is no listener.
  5168. ensureListeningTo(rootContainerElement, 'onChange');
  5169. break;
  5170. case 'textarea':
  5171. initWrapperState$2(domElement, rawProps);
  5172. props = getHostProps$3(domElement, rawProps);
  5173. trapBubbledEvent(TOP_INVALID, domElement); // For controlled components we always need to ensure we're listening
  5174. // to onChange. Even if there is no listener.
  5175. ensureListeningTo(rootContainerElement, 'onChange');
  5176. break;
  5177. default:
  5178. props = rawProps;
  5179. }
  5180. assertValidProps(tag, props);
  5181. setInitialDOMProperties(tag, domElement, rootContainerElement, props, isCustomComponentTag);
  5182. switch (tag) {
  5183. case 'input':
  5184. // TODO: Make sure we check if this is still unmounted or do any clean
  5185. // up necessary since we never stop tracking anymore.
  5186. track(domElement);
  5187. postMountWrapper(domElement, rawProps, false);
  5188. break;
  5189. case 'textarea':
  5190. // TODO: Make sure we check if this is still unmounted or do any clean
  5191. // up necessary since we never stop tracking anymore.
  5192. track(domElement);
  5193. postMountWrapper$3(domElement);
  5194. break;
  5195. case 'option':
  5196. postMountWrapper$1(domElement, rawProps);
  5197. break;
  5198. case 'select':
  5199. postMountWrapper$2(domElement, rawProps);
  5200. break;
  5201. default:
  5202. if (typeof props.onClick === 'function') {
  5203. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  5204. trapClickOnNonInteractiveElement(domElement);
  5205. }
  5206. break;
  5207. }
  5208. } // Calculate the diff between the two objects.
  5209. function diffProperties(domElement, tag, lastRawProps, nextRawProps, rootContainerElement) {
  5210. {
  5211. validatePropertiesInDevelopment(tag, nextRawProps);
  5212. }
  5213. var updatePayload = null;
  5214. var lastProps;
  5215. var nextProps;
  5216. switch (tag) {
  5217. case 'input':
  5218. lastProps = getHostProps(domElement, lastRawProps);
  5219. nextProps = getHostProps(domElement, nextRawProps);
  5220. updatePayload = [];
  5221. break;
  5222. case 'option':
  5223. lastProps = getHostProps$1(domElement, lastRawProps);
  5224. nextProps = getHostProps$1(domElement, nextRawProps);
  5225. updatePayload = [];
  5226. break;
  5227. case 'select':
  5228. lastProps = getHostProps$2(domElement, lastRawProps);
  5229. nextProps = getHostProps$2(domElement, nextRawProps);
  5230. updatePayload = [];
  5231. break;
  5232. case 'textarea':
  5233. lastProps = getHostProps$3(domElement, lastRawProps);
  5234. nextProps = getHostProps$3(domElement, nextRawProps);
  5235. updatePayload = [];
  5236. break;
  5237. default:
  5238. lastProps = lastRawProps;
  5239. nextProps = nextRawProps;
  5240. if (typeof lastProps.onClick !== 'function' && typeof nextProps.onClick === 'function') {
  5241. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  5242. trapClickOnNonInteractiveElement(domElement);
  5243. }
  5244. break;
  5245. }
  5246. assertValidProps(tag, nextProps);
  5247. var propKey;
  5248. var styleName;
  5249. var styleUpdates = null;
  5250. for (propKey in lastProps) {
  5251. if (nextProps.hasOwnProperty(propKey) || !lastProps.hasOwnProperty(propKey) || lastProps[propKey] == null) {
  5252. continue;
  5253. }
  5254. if (propKey === STYLE) {
  5255. var lastStyle = lastProps[propKey];
  5256. for (styleName in lastStyle) {
  5257. if (lastStyle.hasOwnProperty(styleName)) {
  5258. if (!styleUpdates) {
  5259. styleUpdates = {};
  5260. }
  5261. styleUpdates[styleName] = '';
  5262. }
  5263. }
  5264. } else if (propKey === DANGEROUSLY_SET_INNER_HTML || propKey === CHILDREN) ; else if ( propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (propKey === AUTOFOCUS) ; else if (registrationNameModules.hasOwnProperty(propKey)) {
  5265. // This is a special case. If any listener updates we need to ensure
  5266. // that the "current" fiber pointer gets updated so we need a commit
  5267. // to update this element.
  5268. if (!updatePayload) {
  5269. updatePayload = [];
  5270. }
  5271. } else {
  5272. // For all other deleted properties we add it to the queue. We use
  5273. // the whitelist in the commit phase instead.
  5274. (updatePayload = updatePayload || []).push(propKey, null);
  5275. }
  5276. }
  5277. for (propKey in nextProps) {
  5278. var nextProp = nextProps[propKey];
  5279. var lastProp = lastProps != null ? lastProps[propKey] : undefined;
  5280. if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp || nextProp == null && lastProp == null) {
  5281. continue;
  5282. }
  5283. if (propKey === STYLE) {
  5284. {
  5285. if (nextProp) {
  5286. // Freeze the next style object so that we can assume it won't be
  5287. // mutated. We have already warned for this in the past.
  5288. Object.freeze(nextProp);
  5289. }
  5290. }
  5291. if (lastProp) {
  5292. // Unset styles on `lastProp` but not on `nextProp`.
  5293. for (styleName in lastProp) {
  5294. if (lastProp.hasOwnProperty(styleName) && (!nextProp || !nextProp.hasOwnProperty(styleName))) {
  5295. if (!styleUpdates) {
  5296. styleUpdates = {};
  5297. }
  5298. styleUpdates[styleName] = '';
  5299. }
  5300. } // Update styles that changed since `lastProp`.
  5301. for (styleName in nextProp) {
  5302. if (nextProp.hasOwnProperty(styleName) && lastProp[styleName] !== nextProp[styleName]) {
  5303. if (!styleUpdates) {
  5304. styleUpdates = {};
  5305. }
  5306. styleUpdates[styleName] = nextProp[styleName];
  5307. }
  5308. }
  5309. } else {
  5310. // Relies on `updateStylesByID` not mutating `styleUpdates`.
  5311. if (!styleUpdates) {
  5312. if (!updatePayload) {
  5313. updatePayload = [];
  5314. }
  5315. updatePayload.push(propKey, styleUpdates);
  5316. }
  5317. styleUpdates = nextProp;
  5318. }
  5319. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  5320. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  5321. var lastHtml = lastProp ? lastProp[HTML$1] : undefined;
  5322. if (nextHtml != null) {
  5323. if (lastHtml !== nextHtml) {
  5324. (updatePayload = updatePayload || []).push(propKey, nextHtml);
  5325. }
  5326. }
  5327. } else if (propKey === CHILDREN) {
  5328. if (lastProp !== nextProp && (typeof nextProp === 'string' || typeof nextProp === 'number')) {
  5329. (updatePayload = updatePayload || []).push(propKey, '' + nextProp);
  5330. }
  5331. } else if ( propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (registrationNameModules.hasOwnProperty(propKey)) {
  5332. if (nextProp != null) {
  5333. // We eagerly listen to this even though we haven't committed yet.
  5334. if ( typeof nextProp !== 'function') {
  5335. warnForInvalidEventListener(propKey, nextProp);
  5336. }
  5337. ensureListeningTo(rootContainerElement, propKey);
  5338. }
  5339. if (!updatePayload && lastProp !== nextProp) {
  5340. // This is a special case. If any listener updates we need to ensure
  5341. // that the "current" props pointer gets updated so we need a commit
  5342. // to update this element.
  5343. updatePayload = [];
  5344. }
  5345. } else {
  5346. // For any other property we always add it to the queue and then we
  5347. // filter it out using the whitelist during the commit.
  5348. (updatePayload = updatePayload || []).push(propKey, nextProp);
  5349. }
  5350. }
  5351. if (styleUpdates) {
  5352. {
  5353. validateShorthandPropertyCollisionInDev(styleUpdates, nextProps[STYLE]);
  5354. }
  5355. (updatePayload = updatePayload || []).push(STYLE, styleUpdates);
  5356. }
  5357. return updatePayload;
  5358. } // Apply the diff.
  5359. function updateProperties(domElement, updatePayload, tag, lastRawProps, nextRawProps) {
  5360. // Update checked *before* name.
  5361. // In the middle of an update, it is possible to have multiple checked.
  5362. // When a checked radio tries to change name, browser makes another radio's checked false.
  5363. if (tag === 'input' && nextRawProps.type === 'radio' && nextRawProps.name != null) {
  5364. updateChecked(domElement, nextRawProps);
  5365. }
  5366. var wasCustomComponentTag = isCustomComponent(tag, lastRawProps);
  5367. var isCustomComponentTag = isCustomComponent(tag, nextRawProps); // Apply the diff.
  5368. updateDOMProperties(domElement, updatePayload, wasCustomComponentTag, isCustomComponentTag); // TODO: Ensure that an update gets scheduled if any of the special props
  5369. // changed.
  5370. switch (tag) {
  5371. case 'input':
  5372. // Update the wrapper around inputs *after* updating props. This has to
  5373. // happen after `updateDOMProperties`. Otherwise HTML5 input validations
  5374. // raise warnings and prevent the new value from being assigned.
  5375. updateWrapper(domElement, nextRawProps);
  5376. break;
  5377. case 'textarea':
  5378. updateWrapper$1(domElement, nextRawProps);
  5379. break;
  5380. case 'select':
  5381. // <select> value update needs to occur after <option> children
  5382. // reconciliation
  5383. postUpdateWrapper(domElement, nextRawProps);
  5384. break;
  5385. }
  5386. }
  5387. function getPossibleStandardName(propName) {
  5388. {
  5389. var lowerCasedName = propName.toLowerCase();
  5390. if (!possibleStandardNames.hasOwnProperty(lowerCasedName)) {
  5391. return null;
  5392. }
  5393. return possibleStandardNames[lowerCasedName] || null;
  5394. }
  5395. }
  5396. function diffHydratedProperties(domElement, tag, rawProps, parentNamespace, rootContainerElement) {
  5397. var isCustomComponentTag;
  5398. var extraAttributeNames;
  5399. {
  5400. suppressHydrationWarning = rawProps[SUPPRESS_HYDRATION_WARNING] === true;
  5401. isCustomComponentTag = isCustomComponent(tag, rawProps);
  5402. validatePropertiesInDevelopment(tag, rawProps);
  5403. } // TODO: Make sure that we check isMounted before firing any of these events.
  5404. switch (tag) {
  5405. case 'iframe':
  5406. case 'object':
  5407. case 'embed':
  5408. trapBubbledEvent(TOP_LOAD, domElement);
  5409. break;
  5410. case 'video':
  5411. case 'audio':
  5412. // Create listener for each media event
  5413. for (var i = 0; i < mediaEventTypes.length; i++) {
  5414. trapBubbledEvent(mediaEventTypes[i], domElement);
  5415. }
  5416. break;
  5417. case 'source':
  5418. trapBubbledEvent(TOP_ERROR, domElement);
  5419. break;
  5420. case 'img':
  5421. case 'image':
  5422. case 'link':
  5423. trapBubbledEvent(TOP_ERROR, domElement);
  5424. trapBubbledEvent(TOP_LOAD, domElement);
  5425. break;
  5426. case 'form':
  5427. trapBubbledEvent(TOP_RESET, domElement);
  5428. trapBubbledEvent(TOP_SUBMIT, domElement);
  5429. break;
  5430. case 'details':
  5431. trapBubbledEvent(TOP_TOGGLE, domElement);
  5432. break;
  5433. case 'input':
  5434. initWrapperState(domElement, rawProps);
  5435. trapBubbledEvent(TOP_INVALID, domElement); // For controlled components we always need to ensure we're listening
  5436. // to onChange. Even if there is no listener.
  5437. ensureListeningTo(rootContainerElement, 'onChange');
  5438. break;
  5439. case 'option':
  5440. validateProps(domElement, rawProps);
  5441. break;
  5442. case 'select':
  5443. initWrapperState$1(domElement, rawProps);
  5444. trapBubbledEvent(TOP_INVALID, domElement); // For controlled components we always need to ensure we're listening
  5445. // to onChange. Even if there is no listener.
  5446. ensureListeningTo(rootContainerElement, 'onChange');
  5447. break;
  5448. case 'textarea':
  5449. initWrapperState$2(domElement, rawProps);
  5450. trapBubbledEvent(TOP_INVALID, domElement); // For controlled components we always need to ensure we're listening
  5451. // to onChange. Even if there is no listener.
  5452. ensureListeningTo(rootContainerElement, 'onChange');
  5453. break;
  5454. }
  5455. assertValidProps(tag, rawProps);
  5456. {
  5457. extraAttributeNames = new Set();
  5458. var attributes = domElement.attributes;
  5459. for (var _i = 0; _i < attributes.length; _i++) {
  5460. var name = attributes[_i].name.toLowerCase();
  5461. switch (name) {
  5462. // Built-in SSR attribute is whitelisted
  5463. case 'data-reactroot':
  5464. break;
  5465. // Controlled attributes are not validated
  5466. // TODO: Only ignore them on controlled tags.
  5467. case 'value':
  5468. break;
  5469. case 'checked':
  5470. break;
  5471. case 'selected':
  5472. break;
  5473. default:
  5474. // Intentionally use the original name.
  5475. // See discussion in https://github.com/facebook/react/pull/10676.
  5476. extraAttributeNames.add(attributes[_i].name);
  5477. }
  5478. }
  5479. }
  5480. var updatePayload = null;
  5481. for (var propKey in rawProps) {
  5482. if (!rawProps.hasOwnProperty(propKey)) {
  5483. continue;
  5484. }
  5485. var nextProp = rawProps[propKey];
  5486. if (propKey === CHILDREN) {
  5487. // For text content children we compare against textContent. This
  5488. // might match additional HTML that is hidden when we read it using
  5489. // textContent. E.g. "foo" will match "f<span>oo</span>" but that still
  5490. // satisfies our requirement. Our requirement is not to produce perfect
  5491. // HTML and attributes. Ideally we should preserve structure but it's
  5492. // ok not to if the visible content is still enough to indicate what
  5493. // even listeners these nodes might be wired up to.
  5494. // TODO: Warn if there is more than a single textNode as a child.
  5495. // TODO: Should we use domElement.firstChild.nodeValue to compare?
  5496. if (typeof nextProp === 'string') {
  5497. if (domElement.textContent !== nextProp) {
  5498. if ( !suppressHydrationWarning) {
  5499. warnForTextDifference(domElement.textContent, nextProp);
  5500. }
  5501. updatePayload = [CHILDREN, nextProp];
  5502. }
  5503. } else if (typeof nextProp === 'number') {
  5504. if (domElement.textContent !== '' + nextProp) {
  5505. if ( !suppressHydrationWarning) {
  5506. warnForTextDifference(domElement.textContent, nextProp);
  5507. }
  5508. updatePayload = [CHILDREN, '' + nextProp];
  5509. }
  5510. }
  5511. } else if (registrationNameModules.hasOwnProperty(propKey)) {
  5512. if (nextProp != null) {
  5513. if ( typeof nextProp !== 'function') {
  5514. warnForInvalidEventListener(propKey, nextProp);
  5515. }
  5516. ensureListeningTo(rootContainerElement, propKey);
  5517. }
  5518. } else if ( // Convince Flow we've calculated it (it's DEV-only in this method.)
  5519. typeof isCustomComponentTag === 'boolean') {
  5520. // Validate that the properties correspond to their expected values.
  5521. var serverValue = void 0;
  5522. var propertyInfo = getPropertyInfo(propKey);
  5523. if (suppressHydrationWarning) ; else if ( propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING || // Controlled attributes are not validated
  5524. // TODO: Only ignore them on controlled tags.
  5525. propKey === 'value' || propKey === 'checked' || propKey === 'selected') ; else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  5526. var serverHTML = domElement.innerHTML;
  5527. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  5528. var expectedHTML = normalizeHTML(domElement, nextHtml != null ? nextHtml : '');
  5529. if (expectedHTML !== serverHTML) {
  5530. warnForPropDifference(propKey, serverHTML, expectedHTML);
  5531. }
  5532. } else if (propKey === STYLE) {
  5533. // $FlowFixMe - Should be inferred as not undefined.
  5534. extraAttributeNames.delete(propKey);
  5535. if (canDiffStyleForHydrationWarning) {
  5536. var expectedStyle = createDangerousStringForStyles(nextProp);
  5537. serverValue = domElement.getAttribute('style');
  5538. if (expectedStyle !== serverValue) {
  5539. warnForPropDifference(propKey, serverValue, expectedStyle);
  5540. }
  5541. }
  5542. } else if (isCustomComponentTag) {
  5543. // $FlowFixMe - Should be inferred as not undefined.
  5544. extraAttributeNames.delete(propKey.toLowerCase());
  5545. serverValue = getValueForAttribute(domElement, propKey, nextProp);
  5546. if (nextProp !== serverValue) {
  5547. warnForPropDifference(propKey, serverValue, nextProp);
  5548. }
  5549. } else if (!shouldIgnoreAttribute(propKey, propertyInfo, isCustomComponentTag) && !shouldRemoveAttribute(propKey, nextProp, propertyInfo, isCustomComponentTag)) {
  5550. var isMismatchDueToBadCasing = false;
  5551. if (propertyInfo !== null) {
  5552. // $FlowFixMe - Should be inferred as not undefined.
  5553. extraAttributeNames.delete(propertyInfo.attributeName);
  5554. serverValue = getValueForProperty(domElement, propKey, nextProp, propertyInfo);
  5555. } else {
  5556. var ownNamespace = parentNamespace;
  5557. if (ownNamespace === HTML_NAMESPACE$1) {
  5558. ownNamespace = getIntrinsicNamespace(tag);
  5559. }
  5560. if (ownNamespace === HTML_NAMESPACE$1) {
  5561. // $FlowFixMe - Should be inferred as not undefined.
  5562. extraAttributeNames.delete(propKey.toLowerCase());
  5563. } else {
  5564. var standardName = getPossibleStandardName(propKey);
  5565. if (standardName !== null && standardName !== propKey) {
  5566. // If an SVG prop is supplied with bad casing, it will
  5567. // be successfully parsed from HTML, but will produce a mismatch
  5568. // (and would be incorrectly rendered on the client).
  5569. // However, we already warn about bad casing elsewhere.
  5570. // So we'll skip the misleading extra mismatch warning in this case.
  5571. isMismatchDueToBadCasing = true; // $FlowFixMe - Should be inferred as not undefined.
  5572. extraAttributeNames.delete(standardName);
  5573. } // $FlowFixMe - Should be inferred as not undefined.
  5574. extraAttributeNames.delete(propKey);
  5575. }
  5576. serverValue = getValueForAttribute(domElement, propKey, nextProp);
  5577. }
  5578. if (nextProp !== serverValue && !isMismatchDueToBadCasing) {
  5579. warnForPropDifference(propKey, serverValue, nextProp);
  5580. }
  5581. }
  5582. }
  5583. }
  5584. {
  5585. // $FlowFixMe - Should be inferred as not undefined.
  5586. if (extraAttributeNames.size > 0 && !suppressHydrationWarning) {
  5587. // $FlowFixMe - Should be inferred as not undefined.
  5588. warnForExtraAttributes(extraAttributeNames);
  5589. }
  5590. }
  5591. switch (tag) {
  5592. case 'input':
  5593. // TODO: Make sure we check if this is still unmounted or do any clean
  5594. // up necessary since we never stop tracking anymore.
  5595. track(domElement);
  5596. postMountWrapper(domElement, rawProps, true);
  5597. break;
  5598. case 'textarea':
  5599. // TODO: Make sure we check if this is still unmounted or do any clean
  5600. // up necessary since we never stop tracking anymore.
  5601. track(domElement);
  5602. postMountWrapper$3(domElement);
  5603. break;
  5604. case 'select':
  5605. case 'option':
  5606. // For input and textarea we current always set the value property at
  5607. // post mount to force it to diverge from attributes. However, for
  5608. // option and select we don't quite do the same thing and select
  5609. // is not resilient to the DOM state changing so we don't do that here.
  5610. // TODO: Consider not doing this for input and textarea.
  5611. break;
  5612. default:
  5613. if (typeof rawProps.onClick === 'function') {
  5614. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  5615. trapClickOnNonInteractiveElement(domElement);
  5616. }
  5617. break;
  5618. }
  5619. return updatePayload;
  5620. }
  5621. function diffHydratedText(textNode, text) {
  5622. var isDifferent = textNode.nodeValue !== text;
  5623. return isDifferent;
  5624. }
  5625. function warnForUnmatchedText(textNode, text) {
  5626. {
  5627. warnForTextDifference(textNode.nodeValue, text);
  5628. }
  5629. }
  5630. function warnForDeletedHydratableElement(parentNode, child) {
  5631. {
  5632. if (didWarnInvalidHydration) {
  5633. return;
  5634. }
  5635. didWarnInvalidHydration = true;
  5636. error('Did not expect server HTML to contain a <%s> in <%s>.', child.nodeName.toLowerCase(), parentNode.nodeName.toLowerCase());
  5637. }
  5638. }
  5639. function warnForDeletedHydratableText(parentNode, child) {
  5640. {
  5641. if (didWarnInvalidHydration) {
  5642. return;
  5643. }
  5644. didWarnInvalidHydration = true;
  5645. error('Did not expect server HTML to contain the text node "%s" in <%s>.', child.nodeValue, parentNode.nodeName.toLowerCase());
  5646. }
  5647. }
  5648. function warnForInsertedHydratedElement(parentNode, tag, props) {
  5649. {
  5650. if (didWarnInvalidHydration) {
  5651. return;
  5652. }
  5653. didWarnInvalidHydration = true;
  5654. error('Expected server HTML to contain a matching <%s> in <%s>.', tag, parentNode.nodeName.toLowerCase());
  5655. }
  5656. }
  5657. function warnForInsertedHydratedText(parentNode, text) {
  5658. {
  5659. if (text === '') {
  5660. // We expect to insert empty text nodes since they're not represented in
  5661. // the HTML.
  5662. // TODO: Remove this special case if we can just avoid inserting empty
  5663. // text nodes.
  5664. return;
  5665. }
  5666. if (didWarnInvalidHydration) {
  5667. return;
  5668. }
  5669. didWarnInvalidHydration = true;
  5670. error('Expected server HTML to contain a matching text node for "%s" in <%s>.', text, parentNode.nodeName.toLowerCase());
  5671. }
  5672. }
  5673. function restoreControlledState$3(domElement, tag, props) {
  5674. switch (tag) {
  5675. case 'input':
  5676. restoreControlledState(domElement, props);
  5677. return;
  5678. case 'textarea':
  5679. restoreControlledState$2(domElement, props);
  5680. return;
  5681. case 'select':
  5682. restoreControlledState$1(domElement, props);
  5683. return;
  5684. }
  5685. }
  5686. function getActiveElement(doc) {
  5687. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  5688. if (typeof doc === 'undefined') {
  5689. return null;
  5690. }
  5691. try {
  5692. return doc.activeElement || doc.body;
  5693. } catch (e) {
  5694. return doc.body;
  5695. }
  5696. }
  5697. /**
  5698. * Given any node return the first leaf node without children.
  5699. *
  5700. * @param {DOMElement|DOMTextNode} node
  5701. * @return {DOMElement|DOMTextNode}
  5702. */
  5703. function getLeafNode(node) {
  5704. while (node && node.firstChild) {
  5705. node = node.firstChild;
  5706. }
  5707. return node;
  5708. }
  5709. /**
  5710. * Get the next sibling within a container. This will walk up the
  5711. * DOM if a node's siblings have been exhausted.
  5712. *
  5713. * @param {DOMElement|DOMTextNode} node
  5714. * @return {?DOMElement|DOMTextNode}
  5715. */
  5716. function getSiblingNode(node) {
  5717. while (node) {
  5718. if (node.nextSibling) {
  5719. return node.nextSibling;
  5720. }
  5721. node = node.parentNode;
  5722. }
  5723. }
  5724. /**
  5725. * Get object describing the nodes which contain characters at offset.
  5726. *
  5727. * @param {DOMElement|DOMTextNode} root
  5728. * @param {number} offset
  5729. * @return {?object}
  5730. */
  5731. function getNodeForCharacterOffset(root, offset) {
  5732. var node = getLeafNode(root);
  5733. var nodeStart = 0;
  5734. var nodeEnd = 0;
  5735. while (node) {
  5736. if (node.nodeType === TEXT_NODE) {
  5737. nodeEnd = nodeStart + node.textContent.length;
  5738. if (nodeStart <= offset && nodeEnd >= offset) {
  5739. return {
  5740. node: node,
  5741. offset: offset - nodeStart
  5742. };
  5743. }
  5744. nodeStart = nodeEnd;
  5745. }
  5746. node = getLeafNode(getSiblingNode(node));
  5747. }
  5748. }
  5749. /**
  5750. * @param {DOMElement} outerNode
  5751. * @return {?object}
  5752. */
  5753. function getOffsets(outerNode) {
  5754. var ownerDocument = outerNode.ownerDocument;
  5755. var win = ownerDocument && ownerDocument.defaultView || window;
  5756. var selection = win.getSelection && win.getSelection();
  5757. if (!selection || selection.rangeCount === 0) {
  5758. return null;
  5759. }
  5760. var anchorNode = selection.anchorNode,
  5761. anchorOffset = selection.anchorOffset,
  5762. focusNode = selection.focusNode,
  5763. focusOffset = selection.focusOffset; // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
  5764. // up/down buttons on an <input type="number">. Anonymous divs do not seem to
  5765. // expose properties, triggering a "Permission denied error" if any of its
  5766. // properties are accessed. The only seemingly possible way to avoid erroring
  5767. // is to access a property that typically works for non-anonymous divs and
  5768. // catch any error that may otherwise arise. See
  5769. // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
  5770. try {
  5771. /* eslint-disable no-unused-expressions */
  5772. anchorNode.nodeType;
  5773. focusNode.nodeType;
  5774. /* eslint-enable no-unused-expressions */
  5775. } catch (e) {
  5776. return null;
  5777. }
  5778. return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset);
  5779. }
  5780. /**
  5781. * Returns {start, end} where `start` is the character/codepoint index of
  5782. * (anchorNode, anchorOffset) within the textContent of `outerNode`, and
  5783. * `end` is the index of (focusNode, focusOffset).
  5784. *
  5785. * Returns null if you pass in garbage input but we should probably just crash.
  5786. *
  5787. * Exported only for testing.
  5788. */
  5789. function getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset) {
  5790. var length = 0;
  5791. var start = -1;
  5792. var end = -1;
  5793. var indexWithinAnchor = 0;
  5794. var indexWithinFocus = 0;
  5795. var node = outerNode;
  5796. var parentNode = null;
  5797. outer: while (true) {
  5798. var next = null;
  5799. while (true) {
  5800. if (node === anchorNode && (anchorOffset === 0 || node.nodeType === TEXT_NODE)) {
  5801. start = length + anchorOffset;
  5802. }
  5803. if (node === focusNode && (focusOffset === 0 || node.nodeType === TEXT_NODE)) {
  5804. end = length + focusOffset;
  5805. }
  5806. if (node.nodeType === TEXT_NODE) {
  5807. length += node.nodeValue.length;
  5808. }
  5809. if ((next = node.firstChild) === null) {
  5810. break;
  5811. } // Moving from `node` to its first child `next`.
  5812. parentNode = node;
  5813. node = next;
  5814. }
  5815. while (true) {
  5816. if (node === outerNode) {
  5817. // If `outerNode` has children, this is always the second time visiting
  5818. // it. If it has no children, this is still the first loop, and the only
  5819. // valid selection is anchorNode and focusNode both equal to this node
  5820. // and both offsets 0, in which case we will have handled above.
  5821. break outer;
  5822. }
  5823. if (parentNode === anchorNode && ++indexWithinAnchor === anchorOffset) {
  5824. start = length;
  5825. }
  5826. if (parentNode === focusNode && ++indexWithinFocus === focusOffset) {
  5827. end = length;
  5828. }
  5829. if ((next = node.nextSibling) !== null) {
  5830. break;
  5831. }
  5832. node = parentNode;
  5833. parentNode = node.parentNode;
  5834. } // Moving from `node` to its next sibling `next`.
  5835. node = next;
  5836. }
  5837. if (start === -1 || end === -1) {
  5838. // This should never happen. (Would happen if the anchor/focus nodes aren't
  5839. // actually inside the passed-in node.)
  5840. return null;
  5841. }
  5842. return {
  5843. start: start,
  5844. end: end
  5845. };
  5846. }
  5847. /**
  5848. * In modern non-IE browsers, we can support both forward and backward
  5849. * selections.
  5850. *
  5851. * Note: IE10+ supports the Selection object, but it does not support
  5852. * the `extend` method, which means that even in modern IE, it's not possible
  5853. * to programmatically create a backward selection. Thus, for all IE
  5854. * versions, we use the old IE API to create our selections.
  5855. *
  5856. * @param {DOMElement|DOMTextNode} node
  5857. * @param {object} offsets
  5858. */
  5859. function setOffsets(node, offsets) {
  5860. var doc = node.ownerDocument || document;
  5861. var win = doc && doc.defaultView || window; // Edge fails with "Object expected" in some scenarios.
  5862. // (For instance: TinyMCE editor used in a list component that supports pasting to add more,
  5863. // fails when pasting 100+ items)
  5864. if (!win.getSelection) {
  5865. return;
  5866. }
  5867. var selection = win.getSelection();
  5868. var length = node.textContent.length;
  5869. var start = Math.min(offsets.start, length);
  5870. var end = offsets.end === undefined ? start : Math.min(offsets.end, length); // IE 11 uses modern selection, but doesn't support the extend method.
  5871. // Flip backward selections, so we can set with a single range.
  5872. if (!selection.extend && start > end) {
  5873. var temp = end;
  5874. end = start;
  5875. start = temp;
  5876. }
  5877. var startMarker = getNodeForCharacterOffset(node, start);
  5878. var endMarker = getNodeForCharacterOffset(node, end);
  5879. if (startMarker && endMarker) {
  5880. if (selection.rangeCount === 1 && selection.anchorNode === startMarker.node && selection.anchorOffset === startMarker.offset && selection.focusNode === endMarker.node && selection.focusOffset === endMarker.offset) {
  5881. return;
  5882. }
  5883. var range = doc.createRange();
  5884. range.setStart(startMarker.node, startMarker.offset);
  5885. selection.removeAllRanges();
  5886. if (start > end) {
  5887. selection.addRange(range);
  5888. selection.extend(endMarker.node, endMarker.offset);
  5889. } else {
  5890. range.setEnd(endMarker.node, endMarker.offset);
  5891. selection.addRange(range);
  5892. }
  5893. }
  5894. }
  5895. function isTextNode(node) {
  5896. return node && node.nodeType === TEXT_NODE;
  5897. }
  5898. function containsNode(outerNode, innerNode) {
  5899. if (!outerNode || !innerNode) {
  5900. return false;
  5901. } else if (outerNode === innerNode) {
  5902. return true;
  5903. } else if (isTextNode(outerNode)) {
  5904. return false;
  5905. } else if (isTextNode(innerNode)) {
  5906. return containsNode(outerNode, innerNode.parentNode);
  5907. } else if ('contains' in outerNode) {
  5908. return outerNode.contains(innerNode);
  5909. } else if (outerNode.compareDocumentPosition) {
  5910. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  5911. } else {
  5912. return false;
  5913. }
  5914. }
  5915. function isInDocument(node) {
  5916. return node && node.ownerDocument && containsNode(node.ownerDocument.documentElement, node);
  5917. }
  5918. function isSameOriginFrame(iframe) {
  5919. try {
  5920. // Accessing the contentDocument of a HTMLIframeElement can cause the browser
  5921. // to throw, e.g. if it has a cross-origin src attribute.
  5922. // Safari will show an error in the console when the access results in "Blocked a frame with origin". e.g:
  5923. // iframe.contentDocument.defaultView;
  5924. // A safety way is to access one of the cross origin properties: Window or Location
  5925. // Which might result in "SecurityError" DOM Exception and it is compatible to Safari.
  5926. // https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl
  5927. return typeof iframe.contentWindow.location.href === 'string';
  5928. } catch (err) {
  5929. return false;
  5930. }
  5931. }
  5932. function getActiveElementDeep() {
  5933. var win = window;
  5934. var element = getActiveElement();
  5935. while (element instanceof win.HTMLIFrameElement) {
  5936. if (isSameOriginFrame(element)) {
  5937. win = element.contentWindow;
  5938. } else {
  5939. return element;
  5940. }
  5941. element = getActiveElement(win.document);
  5942. }
  5943. return element;
  5944. }
  5945. /**
  5946. * @ReactInputSelection: React input selection module. Based on Selection.js,
  5947. * but modified to be suitable for react and has a couple of bug fixes (doesn't
  5948. * assume buttons have range selections allowed).
  5949. * Input selection module for React.
  5950. */
  5951. /**
  5952. * @hasSelectionCapabilities: we get the element types that support selection
  5953. * from https://html.spec.whatwg.org/#do-not-apply, looking at `selectionStart`
  5954. * and `selectionEnd` rows.
  5955. */
  5956. function hasSelectionCapabilities(elem) {
  5957. var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
  5958. return nodeName && (nodeName === 'input' && (elem.type === 'text' || elem.type === 'search' || elem.type === 'tel' || elem.type === 'url' || elem.type === 'password') || nodeName === 'textarea' || elem.contentEditable === 'true');
  5959. }
  5960. function getSelectionInformation() {
  5961. var focusedElem = getActiveElementDeep();
  5962. return {
  5963. // Used by Flare
  5964. activeElementDetached: null,
  5965. focusedElem: focusedElem,
  5966. selectionRange: hasSelectionCapabilities(focusedElem) ? getSelection(focusedElem) : null
  5967. };
  5968. }
  5969. /**
  5970. * @restoreSelection: If any selection information was potentially lost,
  5971. * restore it. This is useful when performing operations that could remove dom
  5972. * nodes and place them back in, resulting in focus being lost.
  5973. */
  5974. function restoreSelection(priorSelectionInformation) {
  5975. var curFocusedElem = getActiveElementDeep();
  5976. var priorFocusedElem = priorSelectionInformation.focusedElem;
  5977. var priorSelectionRange = priorSelectionInformation.selectionRange;
  5978. if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) {
  5979. if (priorSelectionRange !== null && hasSelectionCapabilities(priorFocusedElem)) {
  5980. setSelection(priorFocusedElem, priorSelectionRange);
  5981. } // Focusing a node can change the scroll position, which is undesirable
  5982. var ancestors = [];
  5983. var ancestor = priorFocusedElem;
  5984. while (ancestor = ancestor.parentNode) {
  5985. if (ancestor.nodeType === ELEMENT_NODE) {
  5986. ancestors.push({
  5987. element: ancestor,
  5988. left: ancestor.scrollLeft,
  5989. top: ancestor.scrollTop
  5990. });
  5991. }
  5992. }
  5993. if (typeof priorFocusedElem.focus === 'function') {
  5994. priorFocusedElem.focus();
  5995. }
  5996. for (var i = 0; i < ancestors.length; i++) {
  5997. var info = ancestors[i];
  5998. info.element.scrollLeft = info.left;
  5999. info.element.scrollTop = info.top;
  6000. }
  6001. }
  6002. }
  6003. /**
  6004. * @getSelection: Gets the selection bounds of a focused textarea, input or
  6005. * contentEditable node.
  6006. * -@input: Look up selection bounds of this input
  6007. * -@return {start: selectionStart, end: selectionEnd}
  6008. */
  6009. function getSelection(input) {
  6010. var selection;
  6011. if ('selectionStart' in input) {
  6012. // Modern browser with input or textarea.
  6013. selection = {
  6014. start: input.selectionStart,
  6015. end: input.selectionEnd
  6016. };
  6017. } else {
  6018. // Content editable or old IE textarea.
  6019. selection = getOffsets(input);
  6020. }
  6021. return selection || {
  6022. start: 0,
  6023. end: 0
  6024. };
  6025. }
  6026. /**
  6027. * @setSelection: Sets the selection bounds of a textarea or input and focuses
  6028. * the input.
  6029. * -@input Set selection bounds of this input or textarea
  6030. * -@offsets Object of same form that is returned from get*
  6031. */
  6032. function setSelection(input, offsets) {
  6033. var start = offsets.start,
  6034. end = offsets.end;
  6035. if (end === undefined) {
  6036. end = start;
  6037. }
  6038. if ('selectionStart' in input) {
  6039. input.selectionStart = start;
  6040. input.selectionEnd = Math.min(end, input.value.length);
  6041. } else {
  6042. setOffsets(input, offsets);
  6043. }
  6044. }
  6045. var validateDOMNesting = function () {};
  6046. var updatedAncestorInfo = function () {};
  6047. {
  6048. // This validation code was written based on the HTML5 parsing spec:
  6049. // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
  6050. //
  6051. // Note: this does not catch all invalid nesting, nor does it try to (as it's
  6052. // not clear what practical benefit doing so provides); instead, we warn only
  6053. // for cases where the parser will give a parse tree differing from what React
  6054. // intended. For example, <b><div></div></b> is invalid but we don't warn
  6055. // because it still parses correctly; we do warn for other cases like nested
  6056. // <p> tags where the beginning of the second element implicitly closes the
  6057. // first, causing a confusing mess.
  6058. // https://html.spec.whatwg.org/multipage/syntax.html#special
  6059. var specialTags = ['address', 'applet', 'area', 'article', 'aside', 'base', 'basefont', 'bgsound', 'blockquote', 'body', 'br', 'button', 'caption', 'center', 'col', 'colgroup', 'dd', 'details', 'dir', 'div', 'dl', 'dt', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'iframe', 'img', 'input', 'isindex', 'li', 'link', 'listing', 'main', 'marquee', 'menu', 'menuitem', 'meta', 'nav', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'p', 'param', 'plaintext', 'pre', 'script', 'section', 'select', 'source', 'style', 'summary', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul', 'wbr', 'xmp']; // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
  6060. var inScopeTags = ['applet', 'caption', 'html', 'table', 'td', 'th', 'marquee', 'object', 'template', // https://html.spec.whatwg.org/multipage/syntax.html#html-integration-point
  6061. // TODO: Distinguish by namespace here -- for <title>, including it here
  6062. // errs on the side of fewer warnings
  6063. 'foreignObject', 'desc', 'title']; // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-button-scope
  6064. var buttonScopeTags = inScopeTags.concat(['button']); // https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags
  6065. var impliedEndTags = ['dd', 'dt', 'li', 'option', 'optgroup', 'p', 'rp', 'rt'];
  6066. var emptyAncestorInfo = {
  6067. current: null,
  6068. formTag: null,
  6069. aTagInScope: null,
  6070. buttonTagInScope: null,
  6071. nobrTagInScope: null,
  6072. pTagInButtonScope: null,
  6073. listItemTagAutoclosing: null,
  6074. dlItemTagAutoclosing: null
  6075. };
  6076. updatedAncestorInfo = function (oldInfo, tag) {
  6077. var ancestorInfo = _assign({}, oldInfo || emptyAncestorInfo);
  6078. var info = {
  6079. tag: tag
  6080. };
  6081. if (inScopeTags.indexOf(tag) !== -1) {
  6082. ancestorInfo.aTagInScope = null;
  6083. ancestorInfo.buttonTagInScope = null;
  6084. ancestorInfo.nobrTagInScope = null;
  6085. }
  6086. if (buttonScopeTags.indexOf(tag) !== -1) {
  6087. ancestorInfo.pTagInButtonScope = null;
  6088. } // See rules for 'li', 'dd', 'dt' start tags in
  6089. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
  6090. if (specialTags.indexOf(tag) !== -1 && tag !== 'address' && tag !== 'div' && tag !== 'p') {
  6091. ancestorInfo.listItemTagAutoclosing = null;
  6092. ancestorInfo.dlItemTagAutoclosing = null;
  6093. }
  6094. ancestorInfo.current = info;
  6095. if (tag === 'form') {
  6096. ancestorInfo.formTag = info;
  6097. }
  6098. if (tag === 'a') {
  6099. ancestorInfo.aTagInScope = info;
  6100. }
  6101. if (tag === 'button') {
  6102. ancestorInfo.buttonTagInScope = info;
  6103. }
  6104. if (tag === 'nobr') {
  6105. ancestorInfo.nobrTagInScope = info;
  6106. }
  6107. if (tag === 'p') {
  6108. ancestorInfo.pTagInButtonScope = info;
  6109. }
  6110. if (tag === 'li') {
  6111. ancestorInfo.listItemTagAutoclosing = info;
  6112. }
  6113. if (tag === 'dd' || tag === 'dt') {
  6114. ancestorInfo.dlItemTagAutoclosing = info;
  6115. }
  6116. return ancestorInfo;
  6117. };
  6118. /**
  6119. * Returns whether
  6120. */
  6121. var isTagValidWithParent = function (tag, parentTag) {
  6122. // First, let's check if we're in an unusual parsing mode...
  6123. switch (parentTag) {
  6124. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inselect
  6125. case 'select':
  6126. return tag === 'option' || tag === 'optgroup' || tag === '#text';
  6127. case 'optgroup':
  6128. return tag === 'option' || tag === '#text';
  6129. // Strictly speaking, seeing an <option> doesn't mean we're in a <select>
  6130. // but
  6131. case 'option':
  6132. return tag === '#text';
  6133. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd
  6134. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incaption
  6135. // No special behavior since these rules fall back to "in body" mode for
  6136. // all except special table nodes which cause bad parsing behavior anyway.
  6137. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intr
  6138. case 'tr':
  6139. return tag === 'th' || tag === 'td' || tag === 'style' || tag === 'script' || tag === 'template';
  6140. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intbody
  6141. case 'tbody':
  6142. case 'thead':
  6143. case 'tfoot':
  6144. return tag === 'tr' || tag === 'style' || tag === 'script' || tag === 'template';
  6145. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incolgroup
  6146. case 'colgroup':
  6147. return tag === 'col' || tag === 'template';
  6148. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intable
  6149. case 'table':
  6150. return tag === 'caption' || tag === 'colgroup' || tag === 'tbody' || tag === 'tfoot' || tag === 'thead' || tag === 'style' || tag === 'script' || tag === 'template';
  6151. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inhead
  6152. case 'head':
  6153. return tag === 'base' || tag === 'basefont' || tag === 'bgsound' || tag === 'link' || tag === 'meta' || tag === 'title' || tag === 'noscript' || tag === 'noframes' || tag === 'style' || tag === 'script' || tag === 'template';
  6154. // https://html.spec.whatwg.org/multipage/semantics.html#the-html-element
  6155. case 'html':
  6156. return tag === 'head' || tag === 'body' || tag === 'frameset';
  6157. case 'frameset':
  6158. return tag === 'frame';
  6159. case '#document':
  6160. return tag === 'html';
  6161. } // Probably in the "in body" parsing mode, so we outlaw only tag combos
  6162. // where the parsing rules cause implicit opens or closes to be added.
  6163. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
  6164. switch (tag) {
  6165. case 'h1':
  6166. case 'h2':
  6167. case 'h3':
  6168. case 'h4':
  6169. case 'h5':
  6170. case 'h6':
  6171. return parentTag !== 'h1' && parentTag !== 'h2' && parentTag !== 'h3' && parentTag !== 'h4' && parentTag !== 'h5' && parentTag !== 'h6';
  6172. case 'rp':
  6173. case 'rt':
  6174. return impliedEndTags.indexOf(parentTag) === -1;
  6175. case 'body':
  6176. case 'caption':
  6177. case 'col':
  6178. case 'colgroup':
  6179. case 'frameset':
  6180. case 'frame':
  6181. case 'head':
  6182. case 'html':
  6183. case 'tbody':
  6184. case 'td':
  6185. case 'tfoot':
  6186. case 'th':
  6187. case 'thead':
  6188. case 'tr':
  6189. // These tags are only valid with a few parents that have special child
  6190. // parsing rules -- if we're down here, then none of those matched and
  6191. // so we allow it only if we don't know what the parent is, as all other
  6192. // cases are invalid.
  6193. return parentTag == null;
  6194. }
  6195. return true;
  6196. };
  6197. /**
  6198. * Returns whether
  6199. */
  6200. var findInvalidAncestorForTag = function (tag, ancestorInfo) {
  6201. switch (tag) {
  6202. case 'address':
  6203. case 'article':
  6204. case 'aside':
  6205. case 'blockquote':
  6206. case 'center':
  6207. case 'details':
  6208. case 'dialog':
  6209. case 'dir':
  6210. case 'div':
  6211. case 'dl':
  6212. case 'fieldset':
  6213. case 'figcaption':
  6214. case 'figure':
  6215. case 'footer':
  6216. case 'header':
  6217. case 'hgroup':
  6218. case 'main':
  6219. case 'menu':
  6220. case 'nav':
  6221. case 'ol':
  6222. case 'p':
  6223. case 'section':
  6224. case 'summary':
  6225. case 'ul':
  6226. case 'pre':
  6227. case 'listing':
  6228. case 'table':
  6229. case 'hr':
  6230. case 'xmp':
  6231. case 'h1':
  6232. case 'h2':
  6233. case 'h3':
  6234. case 'h4':
  6235. case 'h5':
  6236. case 'h6':
  6237. return ancestorInfo.pTagInButtonScope;
  6238. case 'form':
  6239. return ancestorInfo.formTag || ancestorInfo.pTagInButtonScope;
  6240. case 'li':
  6241. return ancestorInfo.listItemTagAutoclosing;
  6242. case 'dd':
  6243. case 'dt':
  6244. return ancestorInfo.dlItemTagAutoclosing;
  6245. case 'button':
  6246. return ancestorInfo.buttonTagInScope;
  6247. case 'a':
  6248. // Spec says something about storing a list of markers, but it sounds
  6249. // equivalent to this check.
  6250. return ancestorInfo.aTagInScope;
  6251. case 'nobr':
  6252. return ancestorInfo.nobrTagInScope;
  6253. }
  6254. return null;
  6255. };
  6256. var didWarn$1 = {};
  6257. validateDOMNesting = function (childTag, childText, ancestorInfo) {
  6258. ancestorInfo = ancestorInfo || emptyAncestorInfo;
  6259. var parentInfo = ancestorInfo.current;
  6260. var parentTag = parentInfo && parentInfo.tag;
  6261. if (childText != null) {
  6262. if (childTag != null) {
  6263. error('validateDOMNesting: when childText is passed, childTag should be null');
  6264. }
  6265. childTag = '#text';
  6266. }
  6267. var invalidParent = isTagValidWithParent(childTag, parentTag) ? null : parentInfo;
  6268. var invalidAncestor = invalidParent ? null : findInvalidAncestorForTag(childTag, ancestorInfo);
  6269. var invalidParentOrAncestor = invalidParent || invalidAncestor;
  6270. if (!invalidParentOrAncestor) {
  6271. return;
  6272. }
  6273. var ancestorTag = invalidParentOrAncestor.tag;
  6274. var addendum = getCurrentFiberStackInDev();
  6275. var warnKey = !!invalidParent + '|' + childTag + '|' + ancestorTag + '|' + addendum;
  6276. if (didWarn$1[warnKey]) {
  6277. return;
  6278. }
  6279. didWarn$1[warnKey] = true;
  6280. var tagDisplayName = childTag;
  6281. var whitespaceInfo = '';
  6282. if (childTag === '#text') {
  6283. if (/\S/.test(childText)) {
  6284. tagDisplayName = 'Text nodes';
  6285. } else {
  6286. tagDisplayName = 'Whitespace text nodes';
  6287. whitespaceInfo = " Make sure you don't have any extra whitespace between tags on " + 'each line of your source code.';
  6288. }
  6289. } else {
  6290. tagDisplayName = '<' + childTag + '>';
  6291. }
  6292. if (invalidParent) {
  6293. var info = '';
  6294. if (ancestorTag === 'table' && childTag === 'tr') {
  6295. info += ' Add a <tbody>, <thead> or <tfoot> to your code to match the DOM tree generated by ' + 'the browser.';
  6296. }
  6297. error('validateDOMNesting(...): %s cannot appear as a child of <%s>.%s%s', tagDisplayName, ancestorTag, whitespaceInfo, info);
  6298. } else {
  6299. error('validateDOMNesting(...): %s cannot appear as a descendant of ' + '<%s>.', tagDisplayName, ancestorTag);
  6300. }
  6301. };
  6302. }
  6303. var SUPPRESS_HYDRATION_WARNING$1;
  6304. {
  6305. SUPPRESS_HYDRATION_WARNING$1 = 'suppressHydrationWarning';
  6306. }
  6307. var SUSPENSE_START_DATA = '$';
  6308. var SUSPENSE_END_DATA = '/$';
  6309. var SUSPENSE_PENDING_START_DATA = '$?';
  6310. var SUSPENSE_FALLBACK_START_DATA = '$!';
  6311. var STYLE$1 = 'style';
  6312. var eventsEnabled = null;
  6313. var selectionInformation = null;
  6314. function shouldAutoFocusHostComponent(type, props) {
  6315. switch (type) {
  6316. case 'button':
  6317. case 'input':
  6318. case 'select':
  6319. case 'textarea':
  6320. return !!props.autoFocus;
  6321. }
  6322. return false;
  6323. }
  6324. function getRootHostContext(rootContainerInstance) {
  6325. var type;
  6326. var namespace;
  6327. var nodeType = rootContainerInstance.nodeType;
  6328. switch (nodeType) {
  6329. case DOCUMENT_NODE:
  6330. case DOCUMENT_FRAGMENT_NODE:
  6331. {
  6332. type = nodeType === DOCUMENT_NODE ? '#document' : '#fragment';
  6333. var root = rootContainerInstance.documentElement;
  6334. namespace = root ? root.namespaceURI : getChildNamespace(null, '');
  6335. break;
  6336. }
  6337. default:
  6338. {
  6339. var container = nodeType === COMMENT_NODE ? rootContainerInstance.parentNode : rootContainerInstance;
  6340. var ownNamespace = container.namespaceURI || null;
  6341. type = container.tagName;
  6342. namespace = getChildNamespace(ownNamespace, type);
  6343. break;
  6344. }
  6345. }
  6346. {
  6347. var validatedTag = type.toLowerCase();
  6348. var ancestorInfo = updatedAncestorInfo(null, validatedTag);
  6349. return {
  6350. namespace: namespace,
  6351. ancestorInfo: ancestorInfo
  6352. };
  6353. }
  6354. }
  6355. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  6356. {
  6357. var parentHostContextDev = parentHostContext;
  6358. var namespace = getChildNamespace(parentHostContextDev.namespace, type);
  6359. var ancestorInfo = updatedAncestorInfo(parentHostContextDev.ancestorInfo, type);
  6360. return {
  6361. namespace: namespace,
  6362. ancestorInfo: ancestorInfo
  6363. };
  6364. }
  6365. }
  6366. function getPublicInstance(instance) {
  6367. return instance;
  6368. }
  6369. function prepareForCommit(containerInfo) {
  6370. eventsEnabled = isEnabled();
  6371. selectionInformation = getSelectionInformation();
  6372. setEnabled(false);
  6373. }
  6374. function resetAfterCommit(containerInfo) {
  6375. restoreSelection(selectionInformation);
  6376. setEnabled(eventsEnabled);
  6377. eventsEnabled = null;
  6378. selectionInformation = null;
  6379. }
  6380. function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
  6381. var parentNamespace;
  6382. {
  6383. // TODO: take namespace into account when validating.
  6384. var hostContextDev = hostContext;
  6385. validateDOMNesting(type, null, hostContextDev.ancestorInfo);
  6386. if (typeof props.children === 'string' || typeof props.children === 'number') {
  6387. var string = '' + props.children;
  6388. var ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type);
  6389. validateDOMNesting(null, string, ownAncestorInfo);
  6390. }
  6391. parentNamespace = hostContextDev.namespace;
  6392. }
  6393. var domElement = createElement(type, props, rootContainerInstance, parentNamespace);
  6394. precacheFiberNode(internalInstanceHandle, domElement);
  6395. updateFiberProps(domElement, props);
  6396. return domElement;
  6397. }
  6398. function appendInitialChild(parentInstance, child) {
  6399. parentInstance.appendChild(child);
  6400. }
  6401. function finalizeInitialChildren(domElement, type, props, rootContainerInstance, hostContext) {
  6402. setInitialProperties(domElement, type, props, rootContainerInstance);
  6403. return shouldAutoFocusHostComponent(type, props);
  6404. }
  6405. function prepareUpdate(domElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
  6406. {
  6407. var hostContextDev = hostContext;
  6408. if (typeof newProps.children !== typeof oldProps.children && (typeof newProps.children === 'string' || typeof newProps.children === 'number')) {
  6409. var string = '' + newProps.children;
  6410. var ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type);
  6411. validateDOMNesting(null, string, ownAncestorInfo);
  6412. }
  6413. }
  6414. return diffProperties(domElement, type, oldProps, newProps, rootContainerInstance);
  6415. }
  6416. function shouldSetTextContent(type, props) {
  6417. return type === 'textarea' || type === 'option' || type === 'noscript' || typeof props.children === 'string' || typeof props.children === 'number' || typeof props.dangerouslySetInnerHTML === 'object' && props.dangerouslySetInnerHTML !== null && props.dangerouslySetInnerHTML.__html != null;
  6418. }
  6419. function shouldDeprioritizeSubtree(type, props) {
  6420. return !!props.hidden;
  6421. }
  6422. function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
  6423. {
  6424. var hostContextDev = hostContext;
  6425. validateDOMNesting(null, text, hostContextDev.ancestorInfo);
  6426. }
  6427. var textNode = createTextNode(text, rootContainerInstance);
  6428. precacheFiberNode(internalInstanceHandle, textNode);
  6429. return textNode;
  6430. }
  6431. // if a component just imports ReactDOM (e.g. for findDOMNode).
  6432. // Some environments might not have setTimeout or clearTimeout.
  6433. var scheduleTimeout = typeof setTimeout === 'function' ? setTimeout : undefined;
  6434. var cancelTimeout = typeof clearTimeout === 'function' ? clearTimeout : undefined;
  6435. var noTimeout = -1; // -------------------
  6436. function commitMount(domElement, type, newProps, internalInstanceHandle) {
  6437. // Despite the naming that might imply otherwise, this method only
  6438. // fires if there is an `Update` effect scheduled during mounting.
  6439. // This happens if `finalizeInitialChildren` returns `true` (which it
  6440. // does to implement the `autoFocus` attribute on the client). But
  6441. // there are also other cases when this might happen (such as patching
  6442. // up text content during hydration mismatch). So we'll check this again.
  6443. if (shouldAutoFocusHostComponent(type, newProps)) {
  6444. domElement.focus();
  6445. }
  6446. }
  6447. function commitUpdate(domElement, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
  6448. // Update the props handle so that we know which props are the ones with
  6449. // with current event handlers.
  6450. updateFiberProps(domElement, newProps); // Apply the diff to the DOM node.
  6451. updateProperties(domElement, updatePayload, type, oldProps, newProps);
  6452. }
  6453. function resetTextContent(domElement) {
  6454. setTextContent(domElement, '');
  6455. }
  6456. function commitTextUpdate(textInstance, oldText, newText) {
  6457. textInstance.nodeValue = newText;
  6458. }
  6459. function appendChild(parentInstance, child) {
  6460. parentInstance.appendChild(child);
  6461. }
  6462. function appendChildToContainer(container, child) {
  6463. var parentNode;
  6464. if (container.nodeType === COMMENT_NODE) {
  6465. parentNode = container.parentNode;
  6466. parentNode.insertBefore(child, container);
  6467. } else {
  6468. parentNode = container;
  6469. parentNode.appendChild(child);
  6470. } // This container might be used for a portal.
  6471. // If something inside a portal is clicked, that click should bubble
  6472. // through the React tree. However, on Mobile Safari the click would
  6473. // never bubble through the *DOM* tree unless an ancestor with onclick
  6474. // event exists. So we wouldn't see it and dispatch it.
  6475. // This is why we ensure that non React root containers have inline onclick
  6476. // defined.
  6477. // https://github.com/facebook/react/issues/11918
  6478. var reactRootContainer = container._reactRootContainer;
  6479. if ((reactRootContainer === null || reactRootContainer === undefined) && parentNode.onclick === null) {
  6480. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  6481. trapClickOnNonInteractiveElement(parentNode);
  6482. }
  6483. }
  6484. function insertBefore(parentInstance, child, beforeChild) {
  6485. parentInstance.insertBefore(child, beforeChild);
  6486. }
  6487. function insertInContainerBefore(container, child, beforeChild) {
  6488. if (container.nodeType === COMMENT_NODE) {
  6489. container.parentNode.insertBefore(child, beforeChild);
  6490. } else {
  6491. container.insertBefore(child, beforeChild);
  6492. }
  6493. }
  6494. function removeChild(parentInstance, child) {
  6495. parentInstance.removeChild(child);
  6496. }
  6497. function removeChildFromContainer(container, child) {
  6498. if (container.nodeType === COMMENT_NODE) {
  6499. container.parentNode.removeChild(child);
  6500. } else {
  6501. container.removeChild(child);
  6502. }
  6503. }
  6504. function hideInstance(instance) {
  6505. // pass host context to this method?
  6506. instance = instance;
  6507. var style = instance.style;
  6508. if (typeof style.setProperty === 'function') {
  6509. style.setProperty('display', 'none', 'important');
  6510. } else {
  6511. style.display = 'none';
  6512. }
  6513. }
  6514. function hideTextInstance(textInstance) {
  6515. textInstance.nodeValue = '';
  6516. }
  6517. function unhideInstance(instance, props) {
  6518. instance = instance;
  6519. var styleProp = props[STYLE$1];
  6520. var display = styleProp !== undefined && styleProp !== null && styleProp.hasOwnProperty('display') ? styleProp.display : null;
  6521. instance.style.display = dangerousStyleValue('display', display);
  6522. }
  6523. function unhideTextInstance(textInstance, text) {
  6524. textInstance.nodeValue = text;
  6525. } // -------------------
  6526. function canHydrateInstance(instance, type, props) {
  6527. if (instance.nodeType !== ELEMENT_NODE || type.toLowerCase() !== instance.nodeName.toLowerCase()) {
  6528. return null;
  6529. } // This has now been refined to an element node.
  6530. return instance;
  6531. }
  6532. function canHydrateTextInstance(instance, text) {
  6533. if (text === '' || instance.nodeType !== TEXT_NODE) {
  6534. // Empty strings are not parsed by HTML so there won't be a correct match here.
  6535. return null;
  6536. } // This has now been refined to a text node.
  6537. return instance;
  6538. }
  6539. function isSuspenseInstancePending(instance) {
  6540. return instance.data === SUSPENSE_PENDING_START_DATA;
  6541. }
  6542. function isSuspenseInstanceFallback(instance) {
  6543. return instance.data === SUSPENSE_FALLBACK_START_DATA;
  6544. }
  6545. function getNextHydratable(node) {
  6546. // Skip non-hydratable nodes.
  6547. for (; node != null; node = node.nextSibling) {
  6548. var nodeType = node.nodeType;
  6549. if (nodeType === ELEMENT_NODE || nodeType === TEXT_NODE) {
  6550. break;
  6551. }
  6552. }
  6553. return node;
  6554. }
  6555. function getNextHydratableSibling(instance) {
  6556. return getNextHydratable(instance.nextSibling);
  6557. }
  6558. function getFirstHydratableChild(parentInstance) {
  6559. return getNextHydratable(parentInstance.firstChild);
  6560. }
  6561. function hydrateInstance(instance, type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
  6562. precacheFiberNode(internalInstanceHandle, instance); // TODO: Possibly defer this until the commit phase where all the events
  6563. // get attached.
  6564. updateFiberProps(instance, props);
  6565. var parentNamespace;
  6566. {
  6567. var hostContextDev = hostContext;
  6568. parentNamespace = hostContextDev.namespace;
  6569. }
  6570. return diffHydratedProperties(instance, type, props, parentNamespace, rootContainerInstance);
  6571. }
  6572. function hydrateTextInstance(textInstance, text, internalInstanceHandle) {
  6573. precacheFiberNode(internalInstanceHandle, textInstance);
  6574. return diffHydratedText(textInstance, text);
  6575. }
  6576. function getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance) {
  6577. var node = suspenseInstance.nextSibling; // Skip past all nodes within this suspense boundary.
  6578. // There might be nested nodes so we need to keep track of how
  6579. // deep we are and only break out when we're back on top.
  6580. var depth = 0;
  6581. while (node) {
  6582. if (node.nodeType === COMMENT_NODE) {
  6583. var data = node.data;
  6584. if (data === SUSPENSE_END_DATA) {
  6585. if (depth === 0) {
  6586. return getNextHydratableSibling(node);
  6587. } else {
  6588. depth--;
  6589. }
  6590. } else if (data === SUSPENSE_START_DATA || data === SUSPENSE_FALLBACK_START_DATA || data === SUSPENSE_PENDING_START_DATA) {
  6591. depth++;
  6592. }
  6593. }
  6594. node = node.nextSibling;
  6595. } // TODO: Warn, we didn't find the end comment boundary.
  6596. return null;
  6597. } // Returns the SuspenseInstance if this node is a direct child of a
  6598. // SuspenseInstance. I.e. if its previous sibling is a Comment with
  6599. // SUSPENSE_x_START_DATA. Otherwise, null.
  6600. function getParentSuspenseInstance(targetInstance) {
  6601. var node = targetInstance.previousSibling; // Skip past all nodes within this suspense boundary.
  6602. // There might be nested nodes so we need to keep track of how
  6603. // deep we are and only break out when we're back on top.
  6604. var depth = 0;
  6605. while (node) {
  6606. if (node.nodeType === COMMENT_NODE) {
  6607. var data = node.data;
  6608. if (data === SUSPENSE_START_DATA || data === SUSPENSE_FALLBACK_START_DATA || data === SUSPENSE_PENDING_START_DATA) {
  6609. if (depth === 0) {
  6610. return node;
  6611. } else {
  6612. depth--;
  6613. }
  6614. } else if (data === SUSPENSE_END_DATA) {
  6615. depth++;
  6616. }
  6617. }
  6618. node = node.previousSibling;
  6619. }
  6620. return null;
  6621. }
  6622. function commitHydratedContainer(container) {
  6623. // Retry if any event replaying was blocked on this.
  6624. retryIfBlockedOn(container);
  6625. }
  6626. function commitHydratedSuspenseInstance(suspenseInstance) {
  6627. // Retry if any event replaying was blocked on this.
  6628. retryIfBlockedOn(suspenseInstance);
  6629. }
  6630. function didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, text) {
  6631. {
  6632. warnForUnmatchedText(textInstance, text);
  6633. }
  6634. }
  6635. function didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, text) {
  6636. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  6637. warnForUnmatchedText(textInstance, text);
  6638. }
  6639. }
  6640. function didNotHydrateContainerInstance(parentContainer, instance) {
  6641. {
  6642. if (instance.nodeType === ELEMENT_NODE) {
  6643. warnForDeletedHydratableElement(parentContainer, instance);
  6644. } else if (instance.nodeType === COMMENT_NODE) ; else {
  6645. warnForDeletedHydratableText(parentContainer, instance);
  6646. }
  6647. }
  6648. }
  6649. function didNotHydrateInstance(parentType, parentProps, parentInstance, instance) {
  6650. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  6651. if (instance.nodeType === ELEMENT_NODE) {
  6652. warnForDeletedHydratableElement(parentInstance, instance);
  6653. } else if (instance.nodeType === COMMENT_NODE) ; else {
  6654. warnForDeletedHydratableText(parentInstance, instance);
  6655. }
  6656. }
  6657. }
  6658. function didNotFindHydratableContainerInstance(parentContainer, type, props) {
  6659. {
  6660. warnForInsertedHydratedElement(parentContainer, type);
  6661. }
  6662. }
  6663. function didNotFindHydratableContainerTextInstance(parentContainer, text) {
  6664. {
  6665. warnForInsertedHydratedText(parentContainer, text);
  6666. }
  6667. }
  6668. function didNotFindHydratableInstance(parentType, parentProps, parentInstance, type, props) {
  6669. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  6670. warnForInsertedHydratedElement(parentInstance, type);
  6671. }
  6672. }
  6673. function didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, text) {
  6674. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  6675. warnForInsertedHydratedText(parentInstance, text);
  6676. }
  6677. }
  6678. function didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance) {
  6679. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) ;
  6680. }
  6681. var randomKey = Math.random().toString(36).slice(2);
  6682. var internalInstanceKey = '__reactInternalInstance$' + randomKey;
  6683. var internalEventHandlersKey = '__reactEventHandlers$' + randomKey;
  6684. var internalContainerInstanceKey = '__reactContainere$' + randomKey;
  6685. function precacheFiberNode(hostInst, node) {
  6686. node[internalInstanceKey] = hostInst;
  6687. }
  6688. function markContainerAsRoot(hostRoot, node) {
  6689. node[internalContainerInstanceKey] = hostRoot;
  6690. }
  6691. function unmarkContainerAsRoot(node) {
  6692. node[internalContainerInstanceKey] = null;
  6693. }
  6694. function isContainerMarkedAsRoot(node) {
  6695. return !!node[internalContainerInstanceKey];
  6696. } // Given a DOM node, return the closest HostComponent or HostText fiber ancestor.
  6697. // If the target node is part of a hydrated or not yet rendered subtree, then
  6698. // this may also return a SuspenseComponent or HostRoot to indicate that.
  6699. // Conceptually the HostRoot fiber is a child of the Container node. So if you
  6700. // pass the Container node as the targetNode, you will not actually get the
  6701. // HostRoot back. To get to the HostRoot, you need to pass a child of it.
  6702. // The same thing applies to Suspense boundaries.
  6703. function getClosestInstanceFromNode(targetNode) {
  6704. var targetInst = targetNode[internalInstanceKey];
  6705. if (targetInst) {
  6706. // Don't return HostRoot or SuspenseComponent here.
  6707. return targetInst;
  6708. } // If the direct event target isn't a React owned DOM node, we need to look
  6709. // to see if one of its parents is a React owned DOM node.
  6710. var parentNode = targetNode.parentNode;
  6711. while (parentNode) {
  6712. // We'll check if this is a container root that could include
  6713. // React nodes in the future. We need to check this first because
  6714. // if we're a child of a dehydrated container, we need to first
  6715. // find that inner container before moving on to finding the parent
  6716. // instance. Note that we don't check this field on the targetNode
  6717. // itself because the fibers are conceptually between the container
  6718. // node and the first child. It isn't surrounding the container node.
  6719. // If it's not a container, we check if it's an instance.
  6720. targetInst = parentNode[internalContainerInstanceKey] || parentNode[internalInstanceKey];
  6721. if (targetInst) {
  6722. // Since this wasn't the direct target of the event, we might have
  6723. // stepped past dehydrated DOM nodes to get here. However they could
  6724. // also have been non-React nodes. We need to answer which one.
  6725. // If we the instance doesn't have any children, then there can't be
  6726. // a nested suspense boundary within it. So we can use this as a fast
  6727. // bailout. Most of the time, when people add non-React children to
  6728. // the tree, it is using a ref to a child-less DOM node.
  6729. // Normally we'd only need to check one of the fibers because if it
  6730. // has ever gone from having children to deleting them or vice versa
  6731. // it would have deleted the dehydrated boundary nested inside already.
  6732. // However, since the HostRoot starts out with an alternate it might
  6733. // have one on the alternate so we need to check in case this was a
  6734. // root.
  6735. var alternate = targetInst.alternate;
  6736. if (targetInst.child !== null || alternate !== null && alternate.child !== null) {
  6737. // Next we need to figure out if the node that skipped past is
  6738. // nested within a dehydrated boundary and if so, which one.
  6739. var suspenseInstance = getParentSuspenseInstance(targetNode);
  6740. while (suspenseInstance !== null) {
  6741. // We found a suspense instance. That means that we haven't
  6742. // hydrated it yet. Even though we leave the comments in the
  6743. // DOM after hydrating, and there are boundaries in the DOM
  6744. // that could already be hydrated, we wouldn't have found them
  6745. // through this pass since if the target is hydrated it would
  6746. // have had an internalInstanceKey on it.
  6747. // Let's get the fiber associated with the SuspenseComponent
  6748. // as the deepest instance.
  6749. var targetSuspenseInst = suspenseInstance[internalInstanceKey];
  6750. if (targetSuspenseInst) {
  6751. return targetSuspenseInst;
  6752. } // If we don't find a Fiber on the comment, it might be because
  6753. // we haven't gotten to hydrate it yet. There might still be a
  6754. // parent boundary that hasn't above this one so we need to find
  6755. // the outer most that is known.
  6756. suspenseInstance = getParentSuspenseInstance(suspenseInstance); // If we don't find one, then that should mean that the parent
  6757. // host component also hasn't hydrated yet. We can return it
  6758. // below since it will bail out on the isMounted check later.
  6759. }
  6760. }
  6761. return targetInst;
  6762. }
  6763. targetNode = parentNode;
  6764. parentNode = targetNode.parentNode;
  6765. }
  6766. return null;
  6767. }
  6768. /**
  6769. * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent
  6770. * instance, or null if the node was not rendered by this React.
  6771. */
  6772. function getInstanceFromNode$1(node) {
  6773. var inst = node[internalInstanceKey] || node[internalContainerInstanceKey];
  6774. if (inst) {
  6775. if (inst.tag === HostComponent || inst.tag === HostText || inst.tag === SuspenseComponent || inst.tag === HostRoot) {
  6776. return inst;
  6777. } else {
  6778. return null;
  6779. }
  6780. }
  6781. return null;
  6782. }
  6783. /**
  6784. * Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
  6785. * DOM node.
  6786. */
  6787. function getNodeFromInstance$1(inst) {
  6788. if (inst.tag === HostComponent || inst.tag === HostText) {
  6789. // In Fiber this, is just the state node right now. We assume it will be
  6790. // a host component or host text.
  6791. return inst.stateNode;
  6792. } // Without this first invariant, passing a non-DOM-component triggers the next
  6793. // invariant for a missing parent, which is super confusing.
  6794. {
  6795. {
  6796. throw Error( "getNodeFromInstance: Invalid argument." );
  6797. }
  6798. }
  6799. }
  6800. function getFiberCurrentPropsFromNode$1(node) {
  6801. return node[internalEventHandlersKey] || null;
  6802. }
  6803. function updateFiberProps(node, props) {
  6804. node[internalEventHandlersKey] = props;
  6805. }
  6806. function getParent(inst) {
  6807. do {
  6808. inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
  6809. // That is depending on if we want nested subtrees (layers) to bubble
  6810. // events to their parent. We could also go through parentNode on the
  6811. // host node but that wouldn't work for React Native and doesn't let us
  6812. // do the portal feature.
  6813. } while (inst && inst.tag !== HostComponent);
  6814. if (inst) {
  6815. return inst;
  6816. }
  6817. return null;
  6818. }
  6819. /**
  6820. * Return the lowest common ancestor of A and B, or null if they are in
  6821. * different trees.
  6822. */
  6823. function getLowestCommonAncestor(instA, instB) {
  6824. var depthA = 0;
  6825. for (var tempA = instA; tempA; tempA = getParent(tempA)) {
  6826. depthA++;
  6827. }
  6828. var depthB = 0;
  6829. for (var tempB = instB; tempB; tempB = getParent(tempB)) {
  6830. depthB++;
  6831. } // If A is deeper, crawl up.
  6832. while (depthA - depthB > 0) {
  6833. instA = getParent(instA);
  6834. depthA--;
  6835. } // If B is deeper, crawl up.
  6836. while (depthB - depthA > 0) {
  6837. instB = getParent(instB);
  6838. depthB--;
  6839. } // Walk in lockstep until we find a match.
  6840. var depth = depthA;
  6841. while (depth--) {
  6842. if (instA === instB || instA === instB.alternate) {
  6843. return instA;
  6844. }
  6845. instA = getParent(instA);
  6846. instB = getParent(instB);
  6847. }
  6848. return null;
  6849. }
  6850. /**
  6851. * Simulates the traversal of a two-phase, capture/bubble event dispatch.
  6852. */
  6853. function traverseTwoPhase(inst, fn, arg) {
  6854. var path = [];
  6855. while (inst) {
  6856. path.push(inst);
  6857. inst = getParent(inst);
  6858. }
  6859. var i;
  6860. for (i = path.length; i-- > 0;) {
  6861. fn(path[i], 'captured', arg);
  6862. }
  6863. for (i = 0; i < path.length; i++) {
  6864. fn(path[i], 'bubbled', arg);
  6865. }
  6866. }
  6867. /**
  6868. * Traverses the ID hierarchy and invokes the supplied `cb` on any IDs that
  6869. * should would receive a `mouseEnter` or `mouseLeave` event.
  6870. *
  6871. * Does not invoke the callback on the nearest common ancestor because nothing
  6872. * "entered" or "left" that element.
  6873. */
  6874. function traverseEnterLeave(from, to, fn, argFrom, argTo) {
  6875. var common = from && to ? getLowestCommonAncestor(from, to) : null;
  6876. var pathFrom = [];
  6877. while (true) {
  6878. if (!from) {
  6879. break;
  6880. }
  6881. if (from === common) {
  6882. break;
  6883. }
  6884. var alternate = from.alternate;
  6885. if (alternate !== null && alternate === common) {
  6886. break;
  6887. }
  6888. pathFrom.push(from);
  6889. from = getParent(from);
  6890. }
  6891. var pathTo = [];
  6892. while (true) {
  6893. if (!to) {
  6894. break;
  6895. }
  6896. if (to === common) {
  6897. break;
  6898. }
  6899. var _alternate = to.alternate;
  6900. if (_alternate !== null && _alternate === common) {
  6901. break;
  6902. }
  6903. pathTo.push(to);
  6904. to = getParent(to);
  6905. }
  6906. for (var i = 0; i < pathFrom.length; i++) {
  6907. fn(pathFrom[i], 'bubbled', argFrom);
  6908. }
  6909. for (var _i = pathTo.length; _i-- > 0;) {
  6910. fn(pathTo[_i], 'captured', argTo);
  6911. }
  6912. }
  6913. function isInteractive(tag) {
  6914. return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
  6915. }
  6916. function shouldPreventMouseEvent(name, type, props) {
  6917. switch (name) {
  6918. case 'onClick':
  6919. case 'onClickCapture':
  6920. case 'onDoubleClick':
  6921. case 'onDoubleClickCapture':
  6922. case 'onMouseDown':
  6923. case 'onMouseDownCapture':
  6924. case 'onMouseMove':
  6925. case 'onMouseMoveCapture':
  6926. case 'onMouseUp':
  6927. case 'onMouseUpCapture':
  6928. case 'onMouseEnter':
  6929. return !!(props.disabled && isInteractive(type));
  6930. default:
  6931. return false;
  6932. }
  6933. }
  6934. /**
  6935. * @param {object} inst The instance, which is the source of events.
  6936. * @param {string} registrationName Name of listener (e.g. `onClick`).
  6937. * @return {?function} The stored callback.
  6938. */
  6939. function getListener(inst, registrationName) {
  6940. var listener; // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
  6941. // live here; needs to be moved to a better place soon
  6942. var stateNode = inst.stateNode;
  6943. if (!stateNode) {
  6944. // Work in progress (ex: onload events in incremental mode).
  6945. return null;
  6946. }
  6947. var props = getFiberCurrentPropsFromNode(stateNode);
  6948. if (!props) {
  6949. // Work in progress.
  6950. return null;
  6951. }
  6952. listener = props[registrationName];
  6953. if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
  6954. return null;
  6955. }
  6956. if (!(!listener || typeof listener === 'function')) {
  6957. {
  6958. throw Error( "Expected `" + registrationName + "` listener to be a function, instead got a value of `" + typeof listener + "` type." );
  6959. }
  6960. }
  6961. return listener;
  6962. }
  6963. /**
  6964. * Some event types have a notion of different registration names for different
  6965. * "phases" of propagation. This finds listeners by a given phase.
  6966. */
  6967. function listenerAtPhase(inst, event, propagationPhase) {
  6968. var registrationName = event.dispatchConfig.phasedRegistrationNames[propagationPhase];
  6969. return getListener(inst, registrationName);
  6970. }
  6971. /**
  6972. * A small set of propagation patterns, each of which will accept a small amount
  6973. * of information, and generate a set of "dispatch ready event objects" - which
  6974. * are sets of events that have already been annotated with a set of dispatched
  6975. * listener functions/ids. The API is designed this way to discourage these
  6976. * propagation strategies from actually executing the dispatches, since we
  6977. * always want to collect the entire set of dispatches before executing even a
  6978. * single one.
  6979. */
  6980. /**
  6981. * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
  6982. * here, allows us to not have to bind or create functions for each event.
  6983. * Mutating the event's members allows us to not have to create a wrapping
  6984. * "dispatch" object that pairs the event with the listener.
  6985. */
  6986. function accumulateDirectionalDispatches(inst, phase, event) {
  6987. {
  6988. if (!inst) {
  6989. error('Dispatching inst must not be null');
  6990. }
  6991. }
  6992. var listener = listenerAtPhase(inst, event, phase);
  6993. if (listener) {
  6994. event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
  6995. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  6996. }
  6997. }
  6998. /**
  6999. * Collect dispatches (must be entirely collected before dispatching - see unit
  7000. * tests). Lazily allocate the array to conserve memory. We must loop through
  7001. * each event and perform the traversal for each one. We cannot perform a
  7002. * single traversal for the entire collection of events because each event may
  7003. * have a different target.
  7004. */
  7005. function accumulateTwoPhaseDispatchesSingle(event) {
  7006. if (event && event.dispatchConfig.phasedRegistrationNames) {
  7007. traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
  7008. }
  7009. }
  7010. /**
  7011. * Accumulates without regard to direction, does not look for phased
  7012. * registration names. Same as `accumulateDirectDispatchesSingle` but without
  7013. * requiring that the `dispatchMarker` be the same as the dispatched ID.
  7014. */
  7015. function accumulateDispatches(inst, ignoredDirection, event) {
  7016. if (inst && event && event.dispatchConfig.registrationName) {
  7017. var registrationName = event.dispatchConfig.registrationName;
  7018. var listener = getListener(inst, registrationName);
  7019. if (listener) {
  7020. event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
  7021. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  7022. }
  7023. }
  7024. }
  7025. /**
  7026. * Accumulates dispatches on an `SyntheticEvent`, but only for the
  7027. * `dispatchMarker`.
  7028. * @param {SyntheticEvent} event
  7029. */
  7030. function accumulateDirectDispatchesSingle(event) {
  7031. if (event && event.dispatchConfig.registrationName) {
  7032. accumulateDispatches(event._targetInst, null, event);
  7033. }
  7034. }
  7035. function accumulateTwoPhaseDispatches(events) {
  7036. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
  7037. }
  7038. function accumulateEnterLeaveDispatches(leave, enter, from, to) {
  7039. traverseEnterLeave(from, to, accumulateDispatches, leave, enter);
  7040. }
  7041. function accumulateDirectDispatches(events) {
  7042. forEachAccumulated(events, accumulateDirectDispatchesSingle);
  7043. }
  7044. /**
  7045. * These variables store information about text content of a target node,
  7046. * allowing comparison of content before and after a given event.
  7047. *
  7048. * Identify the node where selection currently begins, then observe
  7049. * both its text content and its current position in the DOM. Since the
  7050. * browser may natively replace the target node during composition, we can
  7051. * use its position to find its replacement.
  7052. *
  7053. *
  7054. */
  7055. var root = null;
  7056. var startText = null;
  7057. var fallbackText = null;
  7058. function initialize(nativeEventTarget) {
  7059. root = nativeEventTarget;
  7060. startText = getText();
  7061. return true;
  7062. }
  7063. function reset() {
  7064. root = null;
  7065. startText = null;
  7066. fallbackText = null;
  7067. }
  7068. function getData() {
  7069. if (fallbackText) {
  7070. return fallbackText;
  7071. }
  7072. var start;
  7073. var startValue = startText;
  7074. var startLength = startValue.length;
  7075. var end;
  7076. var endValue = getText();
  7077. var endLength = endValue.length;
  7078. for (start = 0; start < startLength; start++) {
  7079. if (startValue[start] !== endValue[start]) {
  7080. break;
  7081. }
  7082. }
  7083. var minEnd = startLength - start;
  7084. for (end = 1; end <= minEnd; end++) {
  7085. if (startValue[startLength - end] !== endValue[endLength - end]) {
  7086. break;
  7087. }
  7088. }
  7089. var sliceTail = end > 1 ? 1 - end : undefined;
  7090. fallbackText = endValue.slice(start, sliceTail);
  7091. return fallbackText;
  7092. }
  7093. function getText() {
  7094. if ('value' in root) {
  7095. return root.value;
  7096. }
  7097. return root.textContent;
  7098. }
  7099. var EVENT_POOL_SIZE = 10;
  7100. /**
  7101. * @interface Event
  7102. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  7103. */
  7104. var EventInterface = {
  7105. type: null,
  7106. target: null,
  7107. // currentTarget is set when dispatching; no use in copying it here
  7108. currentTarget: function () {
  7109. return null;
  7110. },
  7111. eventPhase: null,
  7112. bubbles: null,
  7113. cancelable: null,
  7114. timeStamp: function (event) {
  7115. return event.timeStamp || Date.now();
  7116. },
  7117. defaultPrevented: null,
  7118. isTrusted: null
  7119. };
  7120. function functionThatReturnsTrue() {
  7121. return true;
  7122. }
  7123. function functionThatReturnsFalse() {
  7124. return false;
  7125. }
  7126. /**
  7127. * Synthetic events are dispatched by event plugins, typically in response to a
  7128. * top-level event delegation handler.
  7129. *
  7130. * These systems should generally use pooling to reduce the frequency of garbage
  7131. * collection. The system should check `isPersistent` to determine whether the
  7132. * event should be released into the pool after being dispatched. Users that
  7133. * need a persisted event should invoke `persist`.
  7134. *
  7135. * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
  7136. * normalizing browser quirks. Subclasses do not necessarily have to implement a
  7137. * DOM interface; custom application-specific events can also subclass this.
  7138. *
  7139. * @param {object} dispatchConfig Configuration used to dispatch this event.
  7140. * @param {*} targetInst Marker identifying the event target.
  7141. * @param {object} nativeEvent Native browser event.
  7142. * @param {DOMEventTarget} nativeEventTarget Target node.
  7143. */
  7144. function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarget) {
  7145. {
  7146. // these have a getter/setter for warnings
  7147. delete this.nativeEvent;
  7148. delete this.preventDefault;
  7149. delete this.stopPropagation;
  7150. delete this.isDefaultPrevented;
  7151. delete this.isPropagationStopped;
  7152. }
  7153. this.dispatchConfig = dispatchConfig;
  7154. this._targetInst = targetInst;
  7155. this.nativeEvent = nativeEvent;
  7156. var Interface = this.constructor.Interface;
  7157. for (var propName in Interface) {
  7158. if (!Interface.hasOwnProperty(propName)) {
  7159. continue;
  7160. }
  7161. {
  7162. delete this[propName]; // this has a getter/setter for warnings
  7163. }
  7164. var normalize = Interface[propName];
  7165. if (normalize) {
  7166. this[propName] = normalize(nativeEvent);
  7167. } else {
  7168. if (propName === 'target') {
  7169. this.target = nativeEventTarget;
  7170. } else {
  7171. this[propName] = nativeEvent[propName];
  7172. }
  7173. }
  7174. }
  7175. var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
  7176. if (defaultPrevented) {
  7177. this.isDefaultPrevented = functionThatReturnsTrue;
  7178. } else {
  7179. this.isDefaultPrevented = functionThatReturnsFalse;
  7180. }
  7181. this.isPropagationStopped = functionThatReturnsFalse;
  7182. return this;
  7183. }
  7184. _assign(SyntheticEvent.prototype, {
  7185. preventDefault: function () {
  7186. this.defaultPrevented = true;
  7187. var event = this.nativeEvent;
  7188. if (!event) {
  7189. return;
  7190. }
  7191. if (event.preventDefault) {
  7192. event.preventDefault();
  7193. } else if (typeof event.returnValue !== 'unknown') {
  7194. event.returnValue = false;
  7195. }
  7196. this.isDefaultPrevented = functionThatReturnsTrue;
  7197. },
  7198. stopPropagation: function () {
  7199. var event = this.nativeEvent;
  7200. if (!event) {
  7201. return;
  7202. }
  7203. if (event.stopPropagation) {
  7204. event.stopPropagation();
  7205. } else if (typeof event.cancelBubble !== 'unknown') {
  7206. // The ChangeEventPlugin registers a "propertychange" event for
  7207. // IE. This event does not support bubbling or cancelling, and
  7208. // any references to cancelBubble throw "Member not found". A
  7209. // typeof check of "unknown" circumvents this issue (and is also
  7210. // IE specific).
  7211. event.cancelBubble = true;
  7212. }
  7213. this.isPropagationStopped = functionThatReturnsTrue;
  7214. },
  7215. /**
  7216. * We release all dispatched `SyntheticEvent`s after each event loop, adding
  7217. * them back into the pool. This allows a way to hold onto a reference that
  7218. * won't be added back into the pool.
  7219. */
  7220. persist: function () {
  7221. this.isPersistent = functionThatReturnsTrue;
  7222. },
  7223. /**
  7224. * Checks if this event should be released back into the pool.
  7225. *
  7226. * @return {boolean} True if this should not be released, false otherwise.
  7227. */
  7228. isPersistent: functionThatReturnsFalse,
  7229. /**
  7230. * `PooledClass` looks for `destructor` on each instance it releases.
  7231. */
  7232. destructor: function () {
  7233. var Interface = this.constructor.Interface;
  7234. for (var propName in Interface) {
  7235. {
  7236. Object.defineProperty(this, propName, getPooledWarningPropertyDefinition(propName, Interface[propName]));
  7237. }
  7238. }
  7239. this.dispatchConfig = null;
  7240. this._targetInst = null;
  7241. this.nativeEvent = null;
  7242. this.isDefaultPrevented = functionThatReturnsFalse;
  7243. this.isPropagationStopped = functionThatReturnsFalse;
  7244. this._dispatchListeners = null;
  7245. this._dispatchInstances = null;
  7246. {
  7247. Object.defineProperty(this, 'nativeEvent', getPooledWarningPropertyDefinition('nativeEvent', null));
  7248. Object.defineProperty(this, 'isDefaultPrevented', getPooledWarningPropertyDefinition('isDefaultPrevented', functionThatReturnsFalse));
  7249. Object.defineProperty(this, 'isPropagationStopped', getPooledWarningPropertyDefinition('isPropagationStopped', functionThatReturnsFalse));
  7250. Object.defineProperty(this, 'preventDefault', getPooledWarningPropertyDefinition('preventDefault', function () {}));
  7251. Object.defineProperty(this, 'stopPropagation', getPooledWarningPropertyDefinition('stopPropagation', function () {}));
  7252. }
  7253. }
  7254. });
  7255. SyntheticEvent.Interface = EventInterface;
  7256. /**
  7257. * Helper to reduce boilerplate when creating subclasses.
  7258. */
  7259. SyntheticEvent.extend = function (Interface) {
  7260. var Super = this;
  7261. var E = function () {};
  7262. E.prototype = Super.prototype;
  7263. var prototype = new E();
  7264. function Class() {
  7265. return Super.apply(this, arguments);
  7266. }
  7267. _assign(prototype, Class.prototype);
  7268. Class.prototype = prototype;
  7269. Class.prototype.constructor = Class;
  7270. Class.Interface = _assign({}, Super.Interface, Interface);
  7271. Class.extend = Super.extend;
  7272. addEventPoolingTo(Class);
  7273. return Class;
  7274. };
  7275. addEventPoolingTo(SyntheticEvent);
  7276. /**
  7277. * Helper to nullify syntheticEvent instance properties when destructing
  7278. *
  7279. * @param {String} propName
  7280. * @param {?object} getVal
  7281. * @return {object} defineProperty object
  7282. */
  7283. function getPooledWarningPropertyDefinition(propName, getVal) {
  7284. var isFunction = typeof getVal === 'function';
  7285. return {
  7286. configurable: true,
  7287. set: set,
  7288. get: get
  7289. };
  7290. function set(val) {
  7291. var action = isFunction ? 'setting the method' : 'setting the property';
  7292. warn(action, 'This is effectively a no-op');
  7293. return val;
  7294. }
  7295. function get() {
  7296. var action = isFunction ? 'accessing the method' : 'accessing the property';
  7297. var result = isFunction ? 'This is a no-op function' : 'This is set to null';
  7298. warn(action, result);
  7299. return getVal;
  7300. }
  7301. function warn(action, result) {
  7302. {
  7303. error("This synthetic event is reused for performance reasons. If you're seeing this, " + "you're %s `%s` on a released/nullified synthetic event. %s. " + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result);
  7304. }
  7305. }
  7306. }
  7307. function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
  7308. var EventConstructor = this;
  7309. if (EventConstructor.eventPool.length) {
  7310. var instance = EventConstructor.eventPool.pop();
  7311. EventConstructor.call(instance, dispatchConfig, targetInst, nativeEvent, nativeInst);
  7312. return instance;
  7313. }
  7314. return new EventConstructor(dispatchConfig, targetInst, nativeEvent, nativeInst);
  7315. }
  7316. function releasePooledEvent(event) {
  7317. var EventConstructor = this;
  7318. if (!(event instanceof EventConstructor)) {
  7319. {
  7320. throw Error( "Trying to release an event instance into a pool of a different type." );
  7321. }
  7322. }
  7323. event.destructor();
  7324. if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
  7325. EventConstructor.eventPool.push(event);
  7326. }
  7327. }
  7328. function addEventPoolingTo(EventConstructor) {
  7329. EventConstructor.eventPool = [];
  7330. EventConstructor.getPooled = getPooledEvent;
  7331. EventConstructor.release = releasePooledEvent;
  7332. }
  7333. /**
  7334. * @interface Event
  7335. * @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
  7336. */
  7337. var SyntheticCompositionEvent = SyntheticEvent.extend({
  7338. data: null
  7339. });
  7340. /**
  7341. * @interface Event
  7342. * @see http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105
  7343. * /#events-inputevents
  7344. */
  7345. var SyntheticInputEvent = SyntheticEvent.extend({
  7346. data: null
  7347. });
  7348. var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
  7349. var START_KEYCODE = 229;
  7350. var canUseCompositionEvent = canUseDOM && 'CompositionEvent' in window;
  7351. var documentMode = null;
  7352. if (canUseDOM && 'documentMode' in document) {
  7353. documentMode = document.documentMode;
  7354. } // Webkit offers a very useful `textInput` event that can be used to
  7355. // directly represent `beforeInput`. The IE `textinput` event is not as
  7356. // useful, so we don't use it.
  7357. var canUseTextInputEvent = canUseDOM && 'TextEvent' in window && !documentMode; // In IE9+, we have access to composition events, but the data supplied
  7358. // by the native compositionend event may be incorrect. Japanese ideographic
  7359. // spaces, for instance (\u3000) are not recorded correctly.
  7360. var useFallbackCompositionData = canUseDOM && (!canUseCompositionEvent || documentMode && documentMode > 8 && documentMode <= 11);
  7361. var SPACEBAR_CODE = 32;
  7362. var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE); // Events and their corresponding property names.
  7363. var eventTypes = {
  7364. beforeInput: {
  7365. phasedRegistrationNames: {
  7366. bubbled: 'onBeforeInput',
  7367. captured: 'onBeforeInputCapture'
  7368. },
  7369. dependencies: [TOP_COMPOSITION_END, TOP_KEY_PRESS, TOP_TEXT_INPUT, TOP_PASTE]
  7370. },
  7371. compositionEnd: {
  7372. phasedRegistrationNames: {
  7373. bubbled: 'onCompositionEnd',
  7374. captured: 'onCompositionEndCapture'
  7375. },
  7376. dependencies: [TOP_BLUR, TOP_COMPOSITION_END, TOP_KEY_DOWN, TOP_KEY_PRESS, TOP_KEY_UP, TOP_MOUSE_DOWN]
  7377. },
  7378. compositionStart: {
  7379. phasedRegistrationNames: {
  7380. bubbled: 'onCompositionStart',
  7381. captured: 'onCompositionStartCapture'
  7382. },
  7383. dependencies: [TOP_BLUR, TOP_COMPOSITION_START, TOP_KEY_DOWN, TOP_KEY_PRESS, TOP_KEY_UP, TOP_MOUSE_DOWN]
  7384. },
  7385. compositionUpdate: {
  7386. phasedRegistrationNames: {
  7387. bubbled: 'onCompositionUpdate',
  7388. captured: 'onCompositionUpdateCapture'
  7389. },
  7390. dependencies: [TOP_BLUR, TOP_COMPOSITION_UPDATE, TOP_KEY_DOWN, TOP_KEY_PRESS, TOP_KEY_UP, TOP_MOUSE_DOWN]
  7391. }
  7392. }; // Track whether we've ever handled a keypress on the space key.
  7393. var hasSpaceKeypress = false;
  7394. /**
  7395. * Return whether a native keypress event is assumed to be a command.
  7396. * This is required because Firefox fires `keypress` events for key commands
  7397. * (cut, copy, select-all, etc.) even though no character is inserted.
  7398. */
  7399. function isKeypressCommand(nativeEvent) {
  7400. return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) && // ctrlKey && altKey is equivalent to AltGr, and is not a command.
  7401. !(nativeEvent.ctrlKey && nativeEvent.altKey);
  7402. }
  7403. /**
  7404. * Translate native top level events into event types.
  7405. *
  7406. * @param {string} topLevelType
  7407. * @return {object}
  7408. */
  7409. function getCompositionEventType(topLevelType) {
  7410. switch (topLevelType) {
  7411. case TOP_COMPOSITION_START:
  7412. return eventTypes.compositionStart;
  7413. case TOP_COMPOSITION_END:
  7414. return eventTypes.compositionEnd;
  7415. case TOP_COMPOSITION_UPDATE:
  7416. return eventTypes.compositionUpdate;
  7417. }
  7418. }
  7419. /**
  7420. * Does our fallback best-guess model think this event signifies that
  7421. * composition has begun?
  7422. *
  7423. * @param {string} topLevelType
  7424. * @param {object} nativeEvent
  7425. * @return {boolean}
  7426. */
  7427. function isFallbackCompositionStart(topLevelType, nativeEvent) {
  7428. return topLevelType === TOP_KEY_DOWN && nativeEvent.keyCode === START_KEYCODE;
  7429. }
  7430. /**
  7431. * Does our fallback mode think that this event is the end of composition?
  7432. *
  7433. * @param {string} topLevelType
  7434. * @param {object} nativeEvent
  7435. * @return {boolean}
  7436. */
  7437. function isFallbackCompositionEnd(topLevelType, nativeEvent) {
  7438. switch (topLevelType) {
  7439. case TOP_KEY_UP:
  7440. // Command keys insert or clear IME input.
  7441. return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1;
  7442. case TOP_KEY_DOWN:
  7443. // Expect IME keyCode on each keydown. If we get any other
  7444. // code we must have exited earlier.
  7445. return nativeEvent.keyCode !== START_KEYCODE;
  7446. case TOP_KEY_PRESS:
  7447. case TOP_MOUSE_DOWN:
  7448. case TOP_BLUR:
  7449. // Events are not possible without cancelling IME.
  7450. return true;
  7451. default:
  7452. return false;
  7453. }
  7454. }
  7455. /**
  7456. * Google Input Tools provides composition data via a CustomEvent,
  7457. * with the `data` property populated in the `detail` object. If this
  7458. * is available on the event object, use it. If not, this is a plain
  7459. * composition event and we have nothing special to extract.
  7460. *
  7461. * @param {object} nativeEvent
  7462. * @return {?string}
  7463. */
  7464. function getDataFromCustomEvent(nativeEvent) {
  7465. var detail = nativeEvent.detail;
  7466. if (typeof detail === 'object' && 'data' in detail) {
  7467. return detail.data;
  7468. }
  7469. return null;
  7470. }
  7471. /**
  7472. * Check if a composition event was triggered by Korean IME.
  7473. * Our fallback mode does not work well with IE's Korean IME,
  7474. * so just use native composition events when Korean IME is used.
  7475. * Although CompositionEvent.locale property is deprecated,
  7476. * it is available in IE, where our fallback mode is enabled.
  7477. *
  7478. * @param {object} nativeEvent
  7479. * @return {boolean}
  7480. */
  7481. function isUsingKoreanIME(nativeEvent) {
  7482. return nativeEvent.locale === 'ko';
  7483. } // Track the current IME composition status, if any.
  7484. var isComposing = false;
  7485. /**
  7486. * @return {?object} A SyntheticCompositionEvent.
  7487. */
  7488. function extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
  7489. var eventType;
  7490. var fallbackData;
  7491. if (canUseCompositionEvent) {
  7492. eventType = getCompositionEventType(topLevelType);
  7493. } else if (!isComposing) {
  7494. if (isFallbackCompositionStart(topLevelType, nativeEvent)) {
  7495. eventType = eventTypes.compositionStart;
  7496. }
  7497. } else if (isFallbackCompositionEnd(topLevelType, nativeEvent)) {
  7498. eventType = eventTypes.compositionEnd;
  7499. }
  7500. if (!eventType) {
  7501. return null;
  7502. }
  7503. if (useFallbackCompositionData && !isUsingKoreanIME(nativeEvent)) {
  7504. // The current composition is stored statically and must not be
  7505. // overwritten while composition continues.
  7506. if (!isComposing && eventType === eventTypes.compositionStart) {
  7507. isComposing = initialize(nativeEventTarget);
  7508. } else if (eventType === eventTypes.compositionEnd) {
  7509. if (isComposing) {
  7510. fallbackData = getData();
  7511. }
  7512. }
  7513. }
  7514. var event = SyntheticCompositionEvent.getPooled(eventType, targetInst, nativeEvent, nativeEventTarget);
  7515. if (fallbackData) {
  7516. // Inject data generated from fallback path into the synthetic event.
  7517. // This matches the property of native CompositionEventInterface.
  7518. event.data = fallbackData;
  7519. } else {
  7520. var customData = getDataFromCustomEvent(nativeEvent);
  7521. if (customData !== null) {
  7522. event.data = customData;
  7523. }
  7524. }
  7525. accumulateTwoPhaseDispatches(event);
  7526. return event;
  7527. }
  7528. /**
  7529. * @param {TopLevelType} topLevelType Number from `TopLevelType`.
  7530. * @param {object} nativeEvent Native browser event.
  7531. * @return {?string} The string corresponding to this `beforeInput` event.
  7532. */
  7533. function getNativeBeforeInputChars(topLevelType, nativeEvent) {
  7534. switch (topLevelType) {
  7535. case TOP_COMPOSITION_END:
  7536. return getDataFromCustomEvent(nativeEvent);
  7537. case TOP_KEY_PRESS:
  7538. /**
  7539. * If native `textInput` events are available, our goal is to make
  7540. * use of them. However, there is a special case: the spacebar key.
  7541. * In Webkit, preventing default on a spacebar `textInput` event
  7542. * cancels character insertion, but it *also* causes the browser
  7543. * to fall back to its default spacebar behavior of scrolling the
  7544. * page.
  7545. *
  7546. * Tracking at:
  7547. * https://code.google.com/p/chromium/issues/detail?id=355103
  7548. *
  7549. * To avoid this issue, use the keypress event as if no `textInput`
  7550. * event is available.
  7551. */
  7552. var which = nativeEvent.which;
  7553. if (which !== SPACEBAR_CODE) {
  7554. return null;
  7555. }
  7556. hasSpaceKeypress = true;
  7557. return SPACEBAR_CHAR;
  7558. case TOP_TEXT_INPUT:
  7559. // Record the characters to be added to the DOM.
  7560. var chars = nativeEvent.data; // If it's a spacebar character, assume that we have already handled
  7561. // it at the keypress level and bail immediately. Android Chrome
  7562. // doesn't give us keycodes, so we need to ignore it.
  7563. if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
  7564. return null;
  7565. }
  7566. return chars;
  7567. default:
  7568. // For other native event types, do nothing.
  7569. return null;
  7570. }
  7571. }
  7572. /**
  7573. * For browsers that do not provide the `textInput` event, extract the
  7574. * appropriate string to use for SyntheticInputEvent.
  7575. *
  7576. * @param {number} topLevelType Number from `TopLevelEventTypes`.
  7577. * @param {object} nativeEvent Native browser event.
  7578. * @return {?string} The fallback string for this `beforeInput` event.
  7579. */
  7580. function getFallbackBeforeInputChars(topLevelType, nativeEvent) {
  7581. // If we are currently composing (IME) and using a fallback to do so,
  7582. // try to extract the composed characters from the fallback object.
  7583. // If composition event is available, we extract a string only at
  7584. // compositionevent, otherwise extract it at fallback events.
  7585. if (isComposing) {
  7586. if (topLevelType === TOP_COMPOSITION_END || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) {
  7587. var chars = getData();
  7588. reset();
  7589. isComposing = false;
  7590. return chars;
  7591. }
  7592. return null;
  7593. }
  7594. switch (topLevelType) {
  7595. case TOP_PASTE:
  7596. // If a paste event occurs after a keypress, throw out the input
  7597. // chars. Paste events should not lead to BeforeInput events.
  7598. return null;
  7599. case TOP_KEY_PRESS:
  7600. /**
  7601. * As of v27, Firefox may fire keypress events even when no character
  7602. * will be inserted. A few possibilities:
  7603. *
  7604. * - `which` is `0`. Arrow keys, Esc key, etc.
  7605. *
  7606. * - `which` is the pressed key code, but no char is available.
  7607. * Ex: 'AltGr + d` in Polish. There is no modified character for
  7608. * this key combination and no character is inserted into the
  7609. * document, but FF fires the keypress for char code `100` anyway.
  7610. * No `input` event will occur.
  7611. *
  7612. * - `which` is the pressed key code, but a command combination is
  7613. * being used. Ex: `Cmd+C`. No character is inserted, and no
  7614. * `input` event will occur.
  7615. */
  7616. if (!isKeypressCommand(nativeEvent)) {
  7617. // IE fires the `keypress` event when a user types an emoji via
  7618. // Touch keyboard of Windows. In such a case, the `char` property
  7619. // holds an emoji character like `\uD83D\uDE0A`. Because its length
  7620. // is 2, the property `which` does not represent an emoji correctly.
  7621. // In such a case, we directly return the `char` property instead of
  7622. // using `which`.
  7623. if (nativeEvent.char && nativeEvent.char.length > 1) {
  7624. return nativeEvent.char;
  7625. } else if (nativeEvent.which) {
  7626. return String.fromCharCode(nativeEvent.which);
  7627. }
  7628. }
  7629. return null;
  7630. case TOP_COMPOSITION_END:
  7631. return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent) ? null : nativeEvent.data;
  7632. default:
  7633. return null;
  7634. }
  7635. }
  7636. /**
  7637. * Extract a SyntheticInputEvent for `beforeInput`, based on either native
  7638. * `textInput` or fallback behavior.
  7639. *
  7640. * @return {?object} A SyntheticInputEvent.
  7641. */
  7642. function extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
  7643. var chars;
  7644. if (canUseTextInputEvent) {
  7645. chars = getNativeBeforeInputChars(topLevelType, nativeEvent);
  7646. } else {
  7647. chars = getFallbackBeforeInputChars(topLevelType, nativeEvent);
  7648. } // If no characters are being inserted, no BeforeInput event should
  7649. // be fired.
  7650. if (!chars) {
  7651. return null;
  7652. }
  7653. var event = SyntheticInputEvent.getPooled(eventTypes.beforeInput, targetInst, nativeEvent, nativeEventTarget);
  7654. event.data = chars;
  7655. accumulateTwoPhaseDispatches(event);
  7656. return event;
  7657. }
  7658. /**
  7659. * Create an `onBeforeInput` event to match
  7660. * http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-inputevents.
  7661. *
  7662. * This event plugin is based on the native `textInput` event
  7663. * available in Chrome, Safari, Opera, and IE. This event fires after
  7664. * `onKeyPress` and `onCompositionEnd`, but before `onInput`.
  7665. *
  7666. * `beforeInput` is spec'd but not implemented in any browsers, and
  7667. * the `input` event does not provide any useful information about what has
  7668. * actually been added, contrary to the spec. Thus, `textInput` is the best
  7669. * available event to identify the characters that have actually been inserted
  7670. * into the target node.
  7671. *
  7672. * This plugin is also responsible for emitting `composition` events, thus
  7673. * allowing us to share composition fallback code for both `beforeInput` and
  7674. * `composition` event types.
  7675. */
  7676. var BeforeInputEventPlugin = {
  7677. eventTypes: eventTypes,
  7678. extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags) {
  7679. var composition = extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget);
  7680. var beforeInput = extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget);
  7681. if (composition === null) {
  7682. return beforeInput;
  7683. }
  7684. if (beforeInput === null) {
  7685. return composition;
  7686. }
  7687. return [composition, beforeInput];
  7688. }
  7689. };
  7690. /**
  7691. * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
  7692. */
  7693. var supportedInputTypes = {
  7694. color: true,
  7695. date: true,
  7696. datetime: true,
  7697. 'datetime-local': true,
  7698. email: true,
  7699. month: true,
  7700. number: true,
  7701. password: true,
  7702. range: true,
  7703. search: true,
  7704. tel: true,
  7705. text: true,
  7706. time: true,
  7707. url: true,
  7708. week: true
  7709. };
  7710. function isTextInputElement(elem) {
  7711. var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
  7712. if (nodeName === 'input') {
  7713. return !!supportedInputTypes[elem.type];
  7714. }
  7715. if (nodeName === 'textarea') {
  7716. return true;
  7717. }
  7718. return false;
  7719. }
  7720. var eventTypes$1 = {
  7721. change: {
  7722. phasedRegistrationNames: {
  7723. bubbled: 'onChange',
  7724. captured: 'onChangeCapture'
  7725. },
  7726. dependencies: [TOP_BLUR, TOP_CHANGE, TOP_CLICK, TOP_FOCUS, TOP_INPUT, TOP_KEY_DOWN, TOP_KEY_UP, TOP_SELECTION_CHANGE]
  7727. }
  7728. };
  7729. function createAndAccumulateChangeEvent(inst, nativeEvent, target) {
  7730. var event = SyntheticEvent.getPooled(eventTypes$1.change, inst, nativeEvent, target);
  7731. event.type = 'change'; // Flag this event loop as needing state restore.
  7732. enqueueStateRestore(target);
  7733. accumulateTwoPhaseDispatches(event);
  7734. return event;
  7735. }
  7736. /**
  7737. * For IE shims
  7738. */
  7739. var activeElement = null;
  7740. var activeElementInst = null;
  7741. /**
  7742. * SECTION: handle `change` event
  7743. */
  7744. function shouldUseChangeEvent(elem) {
  7745. var nodeName = elem.nodeName && elem.nodeName.toLowerCase();
  7746. return nodeName === 'select' || nodeName === 'input' && elem.type === 'file';
  7747. }
  7748. function manualDispatchChangeEvent(nativeEvent) {
  7749. var event = createAndAccumulateChangeEvent(activeElementInst, nativeEvent, getEventTarget(nativeEvent)); // If change and propertychange bubbled, we'd just bind to it like all the
  7750. // other events and have it go through ReactBrowserEventEmitter. Since it
  7751. // doesn't, we manually listen for the events and so we have to enqueue and
  7752. // process the abstract event manually.
  7753. //
  7754. // Batching is necessary here in order to ensure that all event handlers run
  7755. // before the next rerender (including event handlers attached to ancestor
  7756. // elements instead of directly on the input). Without this, controlled
  7757. // components don't work properly in conjunction with event bubbling because
  7758. // the component is rerendered and the value reverted before all the event
  7759. // handlers can run. See https://github.com/facebook/react/issues/708.
  7760. batchedUpdates(runEventInBatch, event);
  7761. }
  7762. function runEventInBatch(event) {
  7763. runEventsInBatch(event);
  7764. }
  7765. function getInstIfValueChanged(targetInst) {
  7766. var targetNode = getNodeFromInstance$1(targetInst);
  7767. if (updateValueIfChanged(targetNode)) {
  7768. return targetInst;
  7769. }
  7770. }
  7771. function getTargetInstForChangeEvent(topLevelType, targetInst) {
  7772. if (topLevelType === TOP_CHANGE) {
  7773. return targetInst;
  7774. }
  7775. }
  7776. /**
  7777. * SECTION: handle `input` event
  7778. */
  7779. var isInputEventSupported = false;
  7780. if (canUseDOM) {
  7781. // IE9 claims to support the input event but fails to trigger it when
  7782. // deleting text, so we ignore its input events.
  7783. isInputEventSupported = isEventSupported('input') && (!document.documentMode || document.documentMode > 9);
  7784. }
  7785. /**
  7786. * (For IE <=9) Starts tracking propertychange events on the passed-in element
  7787. * and override the value property so that we can distinguish user events from
  7788. * value changes in JS.
  7789. */
  7790. function startWatchingForValueChange(target, targetInst) {
  7791. activeElement = target;
  7792. activeElementInst = targetInst;
  7793. activeElement.attachEvent('onpropertychange', handlePropertyChange);
  7794. }
  7795. /**
  7796. * (For IE <=9) Removes the event listeners from the currently-tracked element,
  7797. * if any exists.
  7798. */
  7799. function stopWatchingForValueChange() {
  7800. if (!activeElement) {
  7801. return;
  7802. }
  7803. activeElement.detachEvent('onpropertychange', handlePropertyChange);
  7804. activeElement = null;
  7805. activeElementInst = null;
  7806. }
  7807. /**
  7808. * (For IE <=9) Handles a propertychange event, sending a `change` event if
  7809. * the value of the active element has changed.
  7810. */
  7811. function handlePropertyChange(nativeEvent) {
  7812. if (nativeEvent.propertyName !== 'value') {
  7813. return;
  7814. }
  7815. if (getInstIfValueChanged(activeElementInst)) {
  7816. manualDispatchChangeEvent(nativeEvent);
  7817. }
  7818. }
  7819. function handleEventsForInputEventPolyfill(topLevelType, target, targetInst) {
  7820. if (topLevelType === TOP_FOCUS) {
  7821. // In IE9, propertychange fires for most input events but is buggy and
  7822. // doesn't fire when text is deleted, but conveniently, selectionchange
  7823. // appears to fire in all of the remaining cases so we catch those and
  7824. // forward the event if the value has changed
  7825. // In either case, we don't want to call the event handler if the value
  7826. // is changed from JS so we redefine a setter for `.value` that updates
  7827. // our activeElementValue variable, allowing us to ignore those changes
  7828. //
  7829. // stopWatching() should be a noop here but we call it just in case we
  7830. // missed a blur event somehow.
  7831. stopWatchingForValueChange();
  7832. startWatchingForValueChange(target, targetInst);
  7833. } else if (topLevelType === TOP_BLUR) {
  7834. stopWatchingForValueChange();
  7835. }
  7836. } // For IE8 and IE9.
  7837. function getTargetInstForInputEventPolyfill(topLevelType, targetInst) {
  7838. if (topLevelType === TOP_SELECTION_CHANGE || topLevelType === TOP_KEY_UP || topLevelType === TOP_KEY_DOWN) {
  7839. // On the selectionchange event, the target is just document which isn't
  7840. // helpful for us so just check activeElement instead.
  7841. //
  7842. // 99% of the time, keydown and keyup aren't necessary. IE8 fails to fire
  7843. // propertychange on the first input event after setting `value` from a
  7844. // script and fires only keydown, keypress, keyup. Catching keyup usually
  7845. // gets it and catching keydown lets us fire an event for the first
  7846. // keystroke if user does a key repeat (it'll be a little delayed: right
  7847. // before the second keystroke). Other input methods (e.g., paste) seem to
  7848. // fire selectionchange normally.
  7849. return getInstIfValueChanged(activeElementInst);
  7850. }
  7851. }
  7852. /**
  7853. * SECTION: handle `click` event
  7854. */
  7855. function shouldUseClickEvent(elem) {
  7856. // Use the `click` event to detect changes to checkbox and radio inputs.
  7857. // This approach works across all browsers, whereas `change` does not fire
  7858. // until `blur` in IE8.
  7859. var nodeName = elem.nodeName;
  7860. return nodeName && nodeName.toLowerCase() === 'input' && (elem.type === 'checkbox' || elem.type === 'radio');
  7861. }
  7862. function getTargetInstForClickEvent(topLevelType, targetInst) {
  7863. if (topLevelType === TOP_CLICK) {
  7864. return getInstIfValueChanged(targetInst);
  7865. }
  7866. }
  7867. function getTargetInstForInputOrChangeEvent(topLevelType, targetInst) {
  7868. if (topLevelType === TOP_INPUT || topLevelType === TOP_CHANGE) {
  7869. return getInstIfValueChanged(targetInst);
  7870. }
  7871. }
  7872. function handleControlledInputBlur(node) {
  7873. var state = node._wrapperState;
  7874. if (!state || !state.controlled || node.type !== 'number') {
  7875. return;
  7876. }
  7877. {
  7878. // If controlled, assign the value attribute to the current value on blur
  7879. setDefaultValue(node, 'number', node.value);
  7880. }
  7881. }
  7882. /**
  7883. * This plugin creates an `onChange` event that normalizes change events
  7884. * across form elements. This event fires at a time when it's possible to
  7885. * change the element's value without seeing a flicker.
  7886. *
  7887. * Supported elements are:
  7888. * - input (see `isTextInputElement`)
  7889. * - textarea
  7890. * - select
  7891. */
  7892. var ChangeEventPlugin = {
  7893. eventTypes: eventTypes$1,
  7894. _isInputEventSupported: isInputEventSupported,
  7895. extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags) {
  7896. var targetNode = targetInst ? getNodeFromInstance$1(targetInst) : window;
  7897. var getTargetInstFunc, handleEventFunc;
  7898. if (shouldUseChangeEvent(targetNode)) {
  7899. getTargetInstFunc = getTargetInstForChangeEvent;
  7900. } else if (isTextInputElement(targetNode)) {
  7901. if (isInputEventSupported) {
  7902. getTargetInstFunc = getTargetInstForInputOrChangeEvent;
  7903. } else {
  7904. getTargetInstFunc = getTargetInstForInputEventPolyfill;
  7905. handleEventFunc = handleEventsForInputEventPolyfill;
  7906. }
  7907. } else if (shouldUseClickEvent(targetNode)) {
  7908. getTargetInstFunc = getTargetInstForClickEvent;
  7909. }
  7910. if (getTargetInstFunc) {
  7911. var inst = getTargetInstFunc(topLevelType, targetInst);
  7912. if (inst) {
  7913. var event = createAndAccumulateChangeEvent(inst, nativeEvent, nativeEventTarget);
  7914. return event;
  7915. }
  7916. }
  7917. if (handleEventFunc) {
  7918. handleEventFunc(topLevelType, targetNode, targetInst);
  7919. } // When blurring, set the value attribute for number inputs
  7920. if (topLevelType === TOP_BLUR) {
  7921. handleControlledInputBlur(targetNode);
  7922. }
  7923. }
  7924. };
  7925. var SyntheticUIEvent = SyntheticEvent.extend({
  7926. view: null,
  7927. detail: null
  7928. });
  7929. /**
  7930. * Translation from modifier key to the associated property in the event.
  7931. * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
  7932. */
  7933. var modifierKeyToProp = {
  7934. Alt: 'altKey',
  7935. Control: 'ctrlKey',
  7936. Meta: 'metaKey',
  7937. Shift: 'shiftKey'
  7938. }; // Older browsers (Safari <= 10, iOS Safari <= 10.2) do not support
  7939. // getModifierState. If getModifierState is not supported, we map it to a set of
  7940. // modifier keys exposed by the event. In this case, Lock-keys are not supported.
  7941. function modifierStateGetter(keyArg) {
  7942. var syntheticEvent = this;
  7943. var nativeEvent = syntheticEvent.nativeEvent;
  7944. if (nativeEvent.getModifierState) {
  7945. return nativeEvent.getModifierState(keyArg);
  7946. }
  7947. var keyProp = modifierKeyToProp[keyArg];
  7948. return keyProp ? !!nativeEvent[keyProp] : false;
  7949. }
  7950. function getEventModifierState(nativeEvent) {
  7951. return modifierStateGetter;
  7952. }
  7953. var previousScreenX = 0;
  7954. var previousScreenY = 0; // Use flags to signal movementX/Y has already been set
  7955. var isMovementXSet = false;
  7956. var isMovementYSet = false;
  7957. /**
  7958. * @interface MouseEvent
  7959. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  7960. */
  7961. var SyntheticMouseEvent = SyntheticUIEvent.extend({
  7962. screenX: null,
  7963. screenY: null,
  7964. clientX: null,
  7965. clientY: null,
  7966. pageX: null,
  7967. pageY: null,
  7968. ctrlKey: null,
  7969. shiftKey: null,
  7970. altKey: null,
  7971. metaKey: null,
  7972. getModifierState: getEventModifierState,
  7973. button: null,
  7974. buttons: null,
  7975. relatedTarget: function (event) {
  7976. return event.relatedTarget || (event.fromElement === event.srcElement ? event.toElement : event.fromElement);
  7977. },
  7978. movementX: function (event) {
  7979. if ('movementX' in event) {
  7980. return event.movementX;
  7981. }
  7982. var screenX = previousScreenX;
  7983. previousScreenX = event.screenX;
  7984. if (!isMovementXSet) {
  7985. isMovementXSet = true;
  7986. return 0;
  7987. }
  7988. return event.type === 'mousemove' ? event.screenX - screenX : 0;
  7989. },
  7990. movementY: function (event) {
  7991. if ('movementY' in event) {
  7992. return event.movementY;
  7993. }
  7994. var screenY = previousScreenY;
  7995. previousScreenY = event.screenY;
  7996. if (!isMovementYSet) {
  7997. isMovementYSet = true;
  7998. return 0;
  7999. }
  8000. return event.type === 'mousemove' ? event.screenY - screenY : 0;
  8001. }
  8002. });
  8003. /**
  8004. * @interface PointerEvent
  8005. * @see http://www.w3.org/TR/pointerevents/
  8006. */
  8007. var SyntheticPointerEvent = SyntheticMouseEvent.extend({
  8008. pointerId: null,
  8009. width: null,
  8010. height: null,
  8011. pressure: null,
  8012. tangentialPressure: null,
  8013. tiltX: null,
  8014. tiltY: null,
  8015. twist: null,
  8016. pointerType: null,
  8017. isPrimary: null
  8018. });
  8019. var eventTypes$2 = {
  8020. mouseEnter: {
  8021. registrationName: 'onMouseEnter',
  8022. dependencies: [TOP_MOUSE_OUT, TOP_MOUSE_OVER]
  8023. },
  8024. mouseLeave: {
  8025. registrationName: 'onMouseLeave',
  8026. dependencies: [TOP_MOUSE_OUT, TOP_MOUSE_OVER]
  8027. },
  8028. pointerEnter: {
  8029. registrationName: 'onPointerEnter',
  8030. dependencies: [TOP_POINTER_OUT, TOP_POINTER_OVER]
  8031. },
  8032. pointerLeave: {
  8033. registrationName: 'onPointerLeave',
  8034. dependencies: [TOP_POINTER_OUT, TOP_POINTER_OVER]
  8035. }
  8036. };
  8037. var EnterLeaveEventPlugin = {
  8038. eventTypes: eventTypes$2,
  8039. /**
  8040. * For almost every interaction we care about, there will be both a top-level
  8041. * `mouseover` and `mouseout` event that occurs. Only use `mouseout` so that
  8042. * we do not extract duplicate events. However, moving the mouse into the
  8043. * browser from outside will not fire a `mouseout` event. In this case, we use
  8044. * the `mouseover` top-level event.
  8045. */
  8046. extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags) {
  8047. var isOverEvent = topLevelType === TOP_MOUSE_OVER || topLevelType === TOP_POINTER_OVER;
  8048. var isOutEvent = topLevelType === TOP_MOUSE_OUT || topLevelType === TOP_POINTER_OUT;
  8049. if (isOverEvent && (eventSystemFlags & IS_REPLAYED) === 0 && (nativeEvent.relatedTarget || nativeEvent.fromElement)) {
  8050. // If this is an over event with a target, then we've already dispatched
  8051. // the event in the out event of the other target. If this is replayed,
  8052. // then it's because we couldn't dispatch against this target previously
  8053. // so we have to do it now instead.
  8054. return null;
  8055. }
  8056. if (!isOutEvent && !isOverEvent) {
  8057. // Must not be a mouse or pointer in or out - ignoring.
  8058. return null;
  8059. }
  8060. var win;
  8061. if (nativeEventTarget.window === nativeEventTarget) {
  8062. // `nativeEventTarget` is probably a window object.
  8063. win = nativeEventTarget;
  8064. } else {
  8065. // TODO: Figure out why `ownerDocument` is sometimes undefined in IE8.
  8066. var doc = nativeEventTarget.ownerDocument;
  8067. if (doc) {
  8068. win = doc.defaultView || doc.parentWindow;
  8069. } else {
  8070. win = window;
  8071. }
  8072. }
  8073. var from;
  8074. var to;
  8075. if (isOutEvent) {
  8076. from = targetInst;
  8077. var related = nativeEvent.relatedTarget || nativeEvent.toElement;
  8078. to = related ? getClosestInstanceFromNode(related) : null;
  8079. if (to !== null) {
  8080. var nearestMounted = getNearestMountedFiber(to);
  8081. if (to !== nearestMounted || to.tag !== HostComponent && to.tag !== HostText) {
  8082. to = null;
  8083. }
  8084. }
  8085. } else {
  8086. // Moving to a node from outside the window.
  8087. from = null;
  8088. to = targetInst;
  8089. }
  8090. if (from === to) {
  8091. // Nothing pertains to our managed components.
  8092. return null;
  8093. }
  8094. var eventInterface, leaveEventType, enterEventType, eventTypePrefix;
  8095. if (topLevelType === TOP_MOUSE_OUT || topLevelType === TOP_MOUSE_OVER) {
  8096. eventInterface = SyntheticMouseEvent;
  8097. leaveEventType = eventTypes$2.mouseLeave;
  8098. enterEventType = eventTypes$2.mouseEnter;
  8099. eventTypePrefix = 'mouse';
  8100. } else if (topLevelType === TOP_POINTER_OUT || topLevelType === TOP_POINTER_OVER) {
  8101. eventInterface = SyntheticPointerEvent;
  8102. leaveEventType = eventTypes$2.pointerLeave;
  8103. enterEventType = eventTypes$2.pointerEnter;
  8104. eventTypePrefix = 'pointer';
  8105. }
  8106. var fromNode = from == null ? win : getNodeFromInstance$1(from);
  8107. var toNode = to == null ? win : getNodeFromInstance$1(to);
  8108. var leave = eventInterface.getPooled(leaveEventType, from, nativeEvent, nativeEventTarget);
  8109. leave.type = eventTypePrefix + 'leave';
  8110. leave.target = fromNode;
  8111. leave.relatedTarget = toNode;
  8112. var enter = eventInterface.getPooled(enterEventType, to, nativeEvent, nativeEventTarget);
  8113. enter.type = eventTypePrefix + 'enter';
  8114. enter.target = toNode;
  8115. enter.relatedTarget = fromNode;
  8116. accumulateEnterLeaveDispatches(leave, enter, from, to); // If we are not processing the first ancestor, then we
  8117. // should not process the same nativeEvent again, as we
  8118. // will have already processed it in the first ancestor.
  8119. if ((eventSystemFlags & IS_FIRST_ANCESTOR) === 0) {
  8120. return [leave];
  8121. }
  8122. return [leave, enter];
  8123. }
  8124. };
  8125. /**
  8126. * inlined Object.is polyfill to avoid requiring consumers ship their own
  8127. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  8128. */
  8129. function is(x, y) {
  8130. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  8131. ;
  8132. }
  8133. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  8134. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  8135. /**
  8136. * Performs equality by iterating through keys on an object and returning false
  8137. * when any key has values which are not strictly equal between the arguments.
  8138. * Returns true when the values of all keys are strictly equal.
  8139. */
  8140. function shallowEqual(objA, objB) {
  8141. if (objectIs(objA, objB)) {
  8142. return true;
  8143. }
  8144. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  8145. return false;
  8146. }
  8147. var keysA = Object.keys(objA);
  8148. var keysB = Object.keys(objB);
  8149. if (keysA.length !== keysB.length) {
  8150. return false;
  8151. } // Test for A's keys different from B.
  8152. for (var i = 0; i < keysA.length; i++) {
  8153. if (!hasOwnProperty$2.call(objB, keysA[i]) || !objectIs(objA[keysA[i]], objB[keysA[i]])) {
  8154. return false;
  8155. }
  8156. }
  8157. return true;
  8158. }
  8159. var skipSelectionChangeEvent = canUseDOM && 'documentMode' in document && document.documentMode <= 11;
  8160. var eventTypes$3 = {
  8161. select: {
  8162. phasedRegistrationNames: {
  8163. bubbled: 'onSelect',
  8164. captured: 'onSelectCapture'
  8165. },
  8166. dependencies: [TOP_BLUR, TOP_CONTEXT_MENU, TOP_DRAG_END, TOP_FOCUS, TOP_KEY_DOWN, TOP_KEY_UP, TOP_MOUSE_DOWN, TOP_MOUSE_UP, TOP_SELECTION_CHANGE]
  8167. }
  8168. };
  8169. var activeElement$1 = null;
  8170. var activeElementInst$1 = null;
  8171. var lastSelection = null;
  8172. var mouseDown = false;
  8173. /**
  8174. * Get an object which is a unique representation of the current selection.
  8175. *
  8176. * The return value will not be consistent across nodes or browsers, but
  8177. * two identical selections on the same node will return identical objects.
  8178. *
  8179. * @param {DOMElement} node
  8180. * @return {object}
  8181. */
  8182. function getSelection$1(node) {
  8183. if ('selectionStart' in node && hasSelectionCapabilities(node)) {
  8184. return {
  8185. start: node.selectionStart,
  8186. end: node.selectionEnd
  8187. };
  8188. } else {
  8189. var win = node.ownerDocument && node.ownerDocument.defaultView || window;
  8190. var selection = win.getSelection();
  8191. return {
  8192. anchorNode: selection.anchorNode,
  8193. anchorOffset: selection.anchorOffset,
  8194. focusNode: selection.focusNode,
  8195. focusOffset: selection.focusOffset
  8196. };
  8197. }
  8198. }
  8199. /**
  8200. * Get document associated with the event target.
  8201. *
  8202. * @param {object} nativeEventTarget
  8203. * @return {Document}
  8204. */
  8205. function getEventTargetDocument(eventTarget) {
  8206. return eventTarget.window === eventTarget ? eventTarget.document : eventTarget.nodeType === DOCUMENT_NODE ? eventTarget : eventTarget.ownerDocument;
  8207. }
  8208. /**
  8209. * Poll selection to see whether it's changed.
  8210. *
  8211. * @param {object} nativeEvent
  8212. * @param {object} nativeEventTarget
  8213. * @return {?SyntheticEvent}
  8214. */
  8215. function constructSelectEvent(nativeEvent, nativeEventTarget) {
  8216. // Ensure we have the right element, and that the user is not dragging a
  8217. // selection (this matches native `select` event behavior). In HTML5, select
  8218. // fires only on input and textarea thus if there's no focused element we
  8219. // won't dispatch.
  8220. var doc = getEventTargetDocument(nativeEventTarget);
  8221. if (mouseDown || activeElement$1 == null || activeElement$1 !== getActiveElement(doc)) {
  8222. return null;
  8223. } // Only fire when selection has actually changed.
  8224. var currentSelection = getSelection$1(activeElement$1);
  8225. if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
  8226. lastSelection = currentSelection;
  8227. var syntheticEvent = SyntheticEvent.getPooled(eventTypes$3.select, activeElementInst$1, nativeEvent, nativeEventTarget);
  8228. syntheticEvent.type = 'select';
  8229. syntheticEvent.target = activeElement$1;
  8230. accumulateTwoPhaseDispatches(syntheticEvent);
  8231. return syntheticEvent;
  8232. }
  8233. return null;
  8234. }
  8235. /**
  8236. * This plugin creates an `onSelect` event that normalizes select events
  8237. * across form elements.
  8238. *
  8239. * Supported elements are:
  8240. * - input (see `isTextInputElement`)
  8241. * - textarea
  8242. * - contentEditable
  8243. *
  8244. * This differs from native browser implementations in the following ways:
  8245. * - Fires on contentEditable fields as well as inputs.
  8246. * - Fires for collapsed selection.
  8247. * - Fires after user input.
  8248. */
  8249. var SelectEventPlugin = {
  8250. eventTypes: eventTypes$3,
  8251. extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, container) {
  8252. var containerOrDoc = container || getEventTargetDocument(nativeEventTarget); // Track whether all listeners exists for this plugin. If none exist, we do
  8253. // not extract events. See #3639.
  8254. if (!containerOrDoc || !isListeningToAllDependencies('onSelect', containerOrDoc)) {
  8255. return null;
  8256. }
  8257. var targetNode = targetInst ? getNodeFromInstance$1(targetInst) : window;
  8258. switch (topLevelType) {
  8259. // Track the input node that has focus.
  8260. case TOP_FOCUS:
  8261. if (isTextInputElement(targetNode) || targetNode.contentEditable === 'true') {
  8262. activeElement$1 = targetNode;
  8263. activeElementInst$1 = targetInst;
  8264. lastSelection = null;
  8265. }
  8266. break;
  8267. case TOP_BLUR:
  8268. activeElement$1 = null;
  8269. activeElementInst$1 = null;
  8270. lastSelection = null;
  8271. break;
  8272. // Don't fire the event while the user is dragging. This matches the
  8273. // semantics of the native select event.
  8274. case TOP_MOUSE_DOWN:
  8275. mouseDown = true;
  8276. break;
  8277. case TOP_CONTEXT_MENU:
  8278. case TOP_MOUSE_UP:
  8279. case TOP_DRAG_END:
  8280. mouseDown = false;
  8281. return constructSelectEvent(nativeEvent, nativeEventTarget);
  8282. // Chrome and IE fire non-standard event when selection is changed (and
  8283. // sometimes when it hasn't). IE's event fires out of order with respect
  8284. // to key and input events on deletion, so we discard it.
  8285. //
  8286. // Firefox doesn't support selectionchange, so check selection status
  8287. // after each key entry. The selection changes after keydown and before
  8288. // keyup, but we check on keydown as well in the case of holding down a
  8289. // key, when multiple keydown events are fired but only one keyup is.
  8290. // This is also our approach for IE handling, for the reason above.
  8291. case TOP_SELECTION_CHANGE:
  8292. if (skipSelectionChangeEvent) {
  8293. break;
  8294. }
  8295. // falls through
  8296. case TOP_KEY_DOWN:
  8297. case TOP_KEY_UP:
  8298. return constructSelectEvent(nativeEvent, nativeEventTarget);
  8299. }
  8300. return null;
  8301. }
  8302. };
  8303. /**
  8304. * @interface Event
  8305. * @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
  8306. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
  8307. */
  8308. var SyntheticAnimationEvent = SyntheticEvent.extend({
  8309. animationName: null,
  8310. elapsedTime: null,
  8311. pseudoElement: null
  8312. });
  8313. /**
  8314. * @interface Event
  8315. * @see http://www.w3.org/TR/clipboard-apis/
  8316. */
  8317. var SyntheticClipboardEvent = SyntheticEvent.extend({
  8318. clipboardData: function (event) {
  8319. return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
  8320. }
  8321. });
  8322. /**
  8323. * @interface FocusEvent
  8324. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  8325. */
  8326. var SyntheticFocusEvent = SyntheticUIEvent.extend({
  8327. relatedTarget: null
  8328. });
  8329. /**
  8330. * `charCode` represents the actual "character code" and is safe to use with
  8331. * `String.fromCharCode`. As such, only keys that correspond to printable
  8332. * characters produce a valid `charCode`, the only exception to this is Enter.
  8333. * The Tab-key is considered non-printable and does not have a `charCode`,
  8334. * presumably because it does not produce a tab-character in browsers.
  8335. *
  8336. * @param {object} nativeEvent Native browser event.
  8337. * @return {number} Normalized `charCode` property.
  8338. */
  8339. function getEventCharCode(nativeEvent) {
  8340. var charCode;
  8341. var keyCode = nativeEvent.keyCode;
  8342. if ('charCode' in nativeEvent) {
  8343. charCode = nativeEvent.charCode; // FF does not set `charCode` for the Enter-key, check against `keyCode`.
  8344. if (charCode === 0 && keyCode === 13) {
  8345. charCode = 13;
  8346. }
  8347. } else {
  8348. // IE8 does not implement `charCode`, but `keyCode` has the correct value.
  8349. charCode = keyCode;
  8350. } // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
  8351. // report Enter as charCode 10 when ctrl is pressed.
  8352. if (charCode === 10) {
  8353. charCode = 13;
  8354. } // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
  8355. // Must not discard the (non-)printable Enter-key.
  8356. if (charCode >= 32 || charCode === 13) {
  8357. return charCode;
  8358. }
  8359. return 0;
  8360. }
  8361. /**
  8362. * Normalization of deprecated HTML5 `key` values
  8363. * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
  8364. */
  8365. var normalizeKey = {
  8366. Esc: 'Escape',
  8367. Spacebar: ' ',
  8368. Left: 'ArrowLeft',
  8369. Up: 'ArrowUp',
  8370. Right: 'ArrowRight',
  8371. Down: 'ArrowDown',
  8372. Del: 'Delete',
  8373. Win: 'OS',
  8374. Menu: 'ContextMenu',
  8375. Apps: 'ContextMenu',
  8376. Scroll: 'ScrollLock',
  8377. MozPrintableKey: 'Unidentified'
  8378. };
  8379. /**
  8380. * Translation from legacy `keyCode` to HTML5 `key`
  8381. * Only special keys supported, all others depend on keyboard layout or browser
  8382. * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
  8383. */
  8384. var translateToKey = {
  8385. '8': 'Backspace',
  8386. '9': 'Tab',
  8387. '12': 'Clear',
  8388. '13': 'Enter',
  8389. '16': 'Shift',
  8390. '17': 'Control',
  8391. '18': 'Alt',
  8392. '19': 'Pause',
  8393. '20': 'CapsLock',
  8394. '27': 'Escape',
  8395. '32': ' ',
  8396. '33': 'PageUp',
  8397. '34': 'PageDown',
  8398. '35': 'End',
  8399. '36': 'Home',
  8400. '37': 'ArrowLeft',
  8401. '38': 'ArrowUp',
  8402. '39': 'ArrowRight',
  8403. '40': 'ArrowDown',
  8404. '45': 'Insert',
  8405. '46': 'Delete',
  8406. '112': 'F1',
  8407. '113': 'F2',
  8408. '114': 'F3',
  8409. '115': 'F4',
  8410. '116': 'F5',
  8411. '117': 'F6',
  8412. '118': 'F7',
  8413. '119': 'F8',
  8414. '120': 'F9',
  8415. '121': 'F10',
  8416. '122': 'F11',
  8417. '123': 'F12',
  8418. '144': 'NumLock',
  8419. '145': 'ScrollLock',
  8420. '224': 'Meta'
  8421. };
  8422. /**
  8423. * @param {object} nativeEvent Native browser event.
  8424. * @return {string} Normalized `key` property.
  8425. */
  8426. function getEventKey(nativeEvent) {
  8427. if (nativeEvent.key) {
  8428. // Normalize inconsistent values reported by browsers due to
  8429. // implementations of a working draft specification.
  8430. // FireFox implements `key` but returns `MozPrintableKey` for all
  8431. // printable characters (normalized to `Unidentified`), ignore it.
  8432. var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
  8433. if (key !== 'Unidentified') {
  8434. return key;
  8435. }
  8436. } // Browser does not implement `key`, polyfill as much of it as we can.
  8437. if (nativeEvent.type === 'keypress') {
  8438. var charCode = getEventCharCode(nativeEvent); // The enter-key is technically both printable and non-printable and can
  8439. // thus be captured by `keypress`, no other non-printable key should.
  8440. return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
  8441. }
  8442. if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
  8443. // While user keyboard layout determines the actual meaning of each
  8444. // `keyCode` value, almost all function keys have a universal value.
  8445. return translateToKey[nativeEvent.keyCode] || 'Unidentified';
  8446. }
  8447. return '';
  8448. }
  8449. /**
  8450. * @interface KeyboardEvent
  8451. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  8452. */
  8453. var SyntheticKeyboardEvent = SyntheticUIEvent.extend({
  8454. key: getEventKey,
  8455. location: null,
  8456. ctrlKey: null,
  8457. shiftKey: null,
  8458. altKey: null,
  8459. metaKey: null,
  8460. repeat: null,
  8461. locale: null,
  8462. getModifierState: getEventModifierState,
  8463. // Legacy Interface
  8464. charCode: function (event) {
  8465. // `charCode` is the result of a KeyPress event and represents the value of
  8466. // the actual printable character.
  8467. // KeyPress is deprecated, but its replacement is not yet final and not
  8468. // implemented in any major browser. Only KeyPress has charCode.
  8469. if (event.type === 'keypress') {
  8470. return getEventCharCode(event);
  8471. }
  8472. return 0;
  8473. },
  8474. keyCode: function (event) {
  8475. // `keyCode` is the result of a KeyDown/Up event and represents the value of
  8476. // physical keyboard key.
  8477. // The actual meaning of the value depends on the users' keyboard layout
  8478. // which cannot be detected. Assuming that it is a US keyboard layout
  8479. // provides a surprisingly accurate mapping for US and European users.
  8480. // Due to this, it is left to the user to implement at this time.
  8481. if (event.type === 'keydown' || event.type === 'keyup') {
  8482. return event.keyCode;
  8483. }
  8484. return 0;
  8485. },
  8486. which: function (event) {
  8487. // `which` is an alias for either `keyCode` or `charCode` depending on the
  8488. // type of the event.
  8489. if (event.type === 'keypress') {
  8490. return getEventCharCode(event);
  8491. }
  8492. if (event.type === 'keydown' || event.type === 'keyup') {
  8493. return event.keyCode;
  8494. }
  8495. return 0;
  8496. }
  8497. });
  8498. /**
  8499. * @interface DragEvent
  8500. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  8501. */
  8502. var SyntheticDragEvent = SyntheticMouseEvent.extend({
  8503. dataTransfer: null
  8504. });
  8505. /**
  8506. * @interface TouchEvent
  8507. * @see http://www.w3.org/TR/touch-events/
  8508. */
  8509. var SyntheticTouchEvent = SyntheticUIEvent.extend({
  8510. touches: null,
  8511. targetTouches: null,
  8512. changedTouches: null,
  8513. altKey: null,
  8514. metaKey: null,
  8515. ctrlKey: null,
  8516. shiftKey: null,
  8517. getModifierState: getEventModifierState
  8518. });
  8519. /**
  8520. * @interface Event
  8521. * @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
  8522. * @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
  8523. */
  8524. var SyntheticTransitionEvent = SyntheticEvent.extend({
  8525. propertyName: null,
  8526. elapsedTime: null,
  8527. pseudoElement: null
  8528. });
  8529. /**
  8530. * @interface WheelEvent
  8531. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  8532. */
  8533. var SyntheticWheelEvent = SyntheticMouseEvent.extend({
  8534. deltaX: function (event) {
  8535. return 'deltaX' in event ? event.deltaX : // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
  8536. 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
  8537. },
  8538. deltaY: function (event) {
  8539. return 'deltaY' in event ? event.deltaY : // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
  8540. 'wheelDeltaY' in event ? -event.wheelDeltaY : // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
  8541. 'wheelDelta' in event ? -event.wheelDelta : 0;
  8542. },
  8543. deltaZ: null,
  8544. // Browsers without "deltaMode" is reporting in raw wheel delta where one
  8545. // notch on the scroll is always +/- 120, roughly equivalent to pixels.
  8546. // A good approximation of DOM_DELTA_LINE (1) is 5% of viewport size or
  8547. // ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
  8548. deltaMode: null
  8549. });
  8550. var knownHTMLTopLevelTypes = [TOP_ABORT, TOP_CANCEL, TOP_CAN_PLAY, TOP_CAN_PLAY_THROUGH, TOP_CLOSE, TOP_DURATION_CHANGE, TOP_EMPTIED, TOP_ENCRYPTED, TOP_ENDED, TOP_ERROR, TOP_INPUT, TOP_INVALID, TOP_LOAD, TOP_LOADED_DATA, TOP_LOADED_METADATA, TOP_LOAD_START, TOP_PAUSE, TOP_PLAY, TOP_PLAYING, TOP_PROGRESS, TOP_RATE_CHANGE, TOP_RESET, TOP_SEEKED, TOP_SEEKING, TOP_STALLED, TOP_SUBMIT, TOP_SUSPEND, TOP_TIME_UPDATE, TOP_TOGGLE, TOP_VOLUME_CHANGE, TOP_WAITING];
  8551. var SimpleEventPlugin = {
  8552. // simpleEventPluginEventTypes gets populated from
  8553. // the DOMEventProperties module.
  8554. eventTypes: simpleEventPluginEventTypes,
  8555. extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags) {
  8556. var dispatchConfig = topLevelEventsToDispatchConfig.get(topLevelType);
  8557. if (!dispatchConfig) {
  8558. return null;
  8559. }
  8560. var EventConstructor;
  8561. switch (topLevelType) {
  8562. case TOP_KEY_PRESS:
  8563. // Firefox creates a keypress event for function keys too. This removes
  8564. // the unwanted keypress events. Enter is however both printable and
  8565. // non-printable. One would expect Tab to be as well (but it isn't).
  8566. if (getEventCharCode(nativeEvent) === 0) {
  8567. return null;
  8568. }
  8569. /* falls through */
  8570. case TOP_KEY_DOWN:
  8571. case TOP_KEY_UP:
  8572. EventConstructor = SyntheticKeyboardEvent;
  8573. break;
  8574. case TOP_BLUR:
  8575. case TOP_FOCUS:
  8576. EventConstructor = SyntheticFocusEvent;
  8577. break;
  8578. case TOP_CLICK:
  8579. // Firefox creates a click event on right mouse clicks. This removes the
  8580. // unwanted click events.
  8581. if (nativeEvent.button === 2) {
  8582. return null;
  8583. }
  8584. /* falls through */
  8585. case TOP_AUX_CLICK:
  8586. case TOP_DOUBLE_CLICK:
  8587. case TOP_MOUSE_DOWN:
  8588. case TOP_MOUSE_MOVE:
  8589. case TOP_MOUSE_UP: // TODO: Disabled elements should not respond to mouse events
  8590. /* falls through */
  8591. case TOP_MOUSE_OUT:
  8592. case TOP_MOUSE_OVER:
  8593. case TOP_CONTEXT_MENU:
  8594. EventConstructor = SyntheticMouseEvent;
  8595. break;
  8596. case TOP_DRAG:
  8597. case TOP_DRAG_END:
  8598. case TOP_DRAG_ENTER:
  8599. case TOP_DRAG_EXIT:
  8600. case TOP_DRAG_LEAVE:
  8601. case TOP_DRAG_OVER:
  8602. case TOP_DRAG_START:
  8603. case TOP_DROP:
  8604. EventConstructor = SyntheticDragEvent;
  8605. break;
  8606. case TOP_TOUCH_CANCEL:
  8607. case TOP_TOUCH_END:
  8608. case TOP_TOUCH_MOVE:
  8609. case TOP_TOUCH_START:
  8610. EventConstructor = SyntheticTouchEvent;
  8611. break;
  8612. case TOP_ANIMATION_END:
  8613. case TOP_ANIMATION_ITERATION:
  8614. case TOP_ANIMATION_START:
  8615. EventConstructor = SyntheticAnimationEvent;
  8616. break;
  8617. case TOP_TRANSITION_END:
  8618. EventConstructor = SyntheticTransitionEvent;
  8619. break;
  8620. case TOP_SCROLL:
  8621. EventConstructor = SyntheticUIEvent;
  8622. break;
  8623. case TOP_WHEEL:
  8624. EventConstructor = SyntheticWheelEvent;
  8625. break;
  8626. case TOP_COPY:
  8627. case TOP_CUT:
  8628. case TOP_PASTE:
  8629. EventConstructor = SyntheticClipboardEvent;
  8630. break;
  8631. case TOP_GOT_POINTER_CAPTURE:
  8632. case TOP_LOST_POINTER_CAPTURE:
  8633. case TOP_POINTER_CANCEL:
  8634. case TOP_POINTER_DOWN:
  8635. case TOP_POINTER_MOVE:
  8636. case TOP_POINTER_OUT:
  8637. case TOP_POINTER_OVER:
  8638. case TOP_POINTER_UP:
  8639. EventConstructor = SyntheticPointerEvent;
  8640. break;
  8641. default:
  8642. {
  8643. if (knownHTMLTopLevelTypes.indexOf(topLevelType) === -1) {
  8644. error('SimpleEventPlugin: Unhandled event type, `%s`. This warning ' + 'is likely caused by a bug in React. Please file an issue.', topLevelType);
  8645. }
  8646. } // HTML Events
  8647. // @see http://www.w3.org/TR/html5/index.html#events-0
  8648. EventConstructor = SyntheticEvent;
  8649. break;
  8650. }
  8651. var event = EventConstructor.getPooled(dispatchConfig, targetInst, nativeEvent, nativeEventTarget);
  8652. accumulateTwoPhaseDispatches(event);
  8653. return event;
  8654. }
  8655. };
  8656. /**
  8657. * Specifies a deterministic ordering of `EventPlugin`s. A convenient way to
  8658. * reason about plugins, without having to package every one of them. This
  8659. * is better than having plugins be ordered in the same order that they
  8660. * are injected because that ordering would be influenced by the packaging order.
  8661. * `ResponderEventPlugin` must occur before `SimpleEventPlugin` so that
  8662. * preventing default on events is convenient in `SimpleEventPlugin` handlers.
  8663. */
  8664. var DOMEventPluginOrder = ['ResponderEventPlugin', 'SimpleEventPlugin', 'EnterLeaveEventPlugin', 'ChangeEventPlugin', 'SelectEventPlugin', 'BeforeInputEventPlugin'];
  8665. /**
  8666. * Inject modules for resolving DOM hierarchy and plugin ordering.
  8667. */
  8668. injectEventPluginOrder(DOMEventPluginOrder);
  8669. setComponentTree(getFiberCurrentPropsFromNode$1, getInstanceFromNode$1, getNodeFromInstance$1);
  8670. /**
  8671. * Some important event plugins included by default (without having to require
  8672. * them).
  8673. */
  8674. injectEventPluginsByName({
  8675. SimpleEventPlugin: SimpleEventPlugin,
  8676. EnterLeaveEventPlugin: EnterLeaveEventPlugin,
  8677. ChangeEventPlugin: ChangeEventPlugin,
  8678. SelectEventPlugin: SelectEventPlugin,
  8679. BeforeInputEventPlugin: BeforeInputEventPlugin
  8680. });
  8681. // Prefix measurements so that it's possible to filter them.
  8682. // Longer prefixes are hard to read in DevTools.
  8683. var reactEmoji = "\u269B";
  8684. var warningEmoji = "\u26D4";
  8685. var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function'; // Keep track of current fiber so that we know the path to unwind on pause.
  8686. // TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
  8687. var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
  8688. // Reusing `currentFiber` would be confusing for this because user code fiber
  8689. // can change during commit phase too, but we don't need to unwind it (since
  8690. // lifecycles in the commit phase don't resemble a tree).
  8691. var currentPhase = null;
  8692. var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
  8693. // so we will keep track of it, and include it in the report.
  8694. // Track commits caused by cascading updates.
  8695. var isCommitting = false;
  8696. var hasScheduledUpdateInCurrentCommit = false;
  8697. var hasScheduledUpdateInCurrentPhase = false;
  8698. var commitCountInCurrentWorkLoop = 0;
  8699. var effectCountInCurrentCommit = 0;
  8700. // to avoid stretch the commit phase with measurement overhead.
  8701. var labelsInCurrentCommit = new Set();
  8702. var formatMarkName = function (markName) {
  8703. return reactEmoji + " " + markName;
  8704. };
  8705. var formatLabel = function (label, warning) {
  8706. var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
  8707. var suffix = warning ? " Warning: " + warning : '';
  8708. return "" + prefix + label + suffix;
  8709. };
  8710. var beginMark = function (markName) {
  8711. performance.mark(formatMarkName(markName));
  8712. };
  8713. var clearMark = function (markName) {
  8714. performance.clearMarks(formatMarkName(markName));
  8715. };
  8716. var endMark = function (label, markName, warning) {
  8717. var formattedMarkName = formatMarkName(markName);
  8718. var formattedLabel = formatLabel(label, warning);
  8719. try {
  8720. performance.measure(formattedLabel, formattedMarkName);
  8721. } catch (err) {} // If previous mark was missing for some reason, this will throw.
  8722. // This could only happen if React crashed in an unexpected place earlier.
  8723. // Don't pile on with more errors.
  8724. // Clear marks immediately to avoid growing buffer.
  8725. performance.clearMarks(formattedMarkName);
  8726. performance.clearMeasures(formattedLabel);
  8727. };
  8728. var getFiberMarkName = function (label, debugID) {
  8729. return label + " (#" + debugID + ")";
  8730. };
  8731. var getFiberLabel = function (componentName, isMounted, phase) {
  8732. if (phase === null) {
  8733. // These are composite component total time measurements.
  8734. return componentName + " [" + (isMounted ? 'update' : 'mount') + "]";
  8735. } else {
  8736. // Composite component methods.
  8737. return componentName + "." + phase;
  8738. }
  8739. };
  8740. var beginFiberMark = function (fiber, phase) {
  8741. var componentName = getComponentName(fiber.type) || 'Unknown';
  8742. var debugID = fiber._debugID;
  8743. var isMounted = fiber.alternate !== null;
  8744. var label = getFiberLabel(componentName, isMounted, phase);
  8745. if (isCommitting && labelsInCurrentCommit.has(label)) {
  8746. // During the commit phase, we don't show duplicate labels because
  8747. // there is a fixed overhead for every measurement, and we don't
  8748. // want to stretch the commit phase beyond necessary.
  8749. return false;
  8750. }
  8751. labelsInCurrentCommit.add(label);
  8752. var markName = getFiberMarkName(label, debugID);
  8753. beginMark(markName);
  8754. return true;
  8755. };
  8756. var clearFiberMark = function (fiber, phase) {
  8757. var componentName = getComponentName(fiber.type) || 'Unknown';
  8758. var debugID = fiber._debugID;
  8759. var isMounted = fiber.alternate !== null;
  8760. var label = getFiberLabel(componentName, isMounted, phase);
  8761. var markName = getFiberMarkName(label, debugID);
  8762. clearMark(markName);
  8763. };
  8764. var endFiberMark = function (fiber, phase, warning) {
  8765. var componentName = getComponentName(fiber.type) || 'Unknown';
  8766. var debugID = fiber._debugID;
  8767. var isMounted = fiber.alternate !== null;
  8768. var label = getFiberLabel(componentName, isMounted, phase);
  8769. var markName = getFiberMarkName(label, debugID);
  8770. endMark(label, markName, warning);
  8771. };
  8772. var shouldIgnoreFiber = function (fiber) {
  8773. // Host components should be skipped in the timeline.
  8774. // We could check typeof fiber.type, but does this work with RN?
  8775. switch (fiber.tag) {
  8776. case HostRoot:
  8777. case HostComponent:
  8778. case HostText:
  8779. case HostPortal:
  8780. case Fragment:
  8781. case ContextProvider:
  8782. case ContextConsumer:
  8783. case Mode:
  8784. return true;
  8785. default:
  8786. return false;
  8787. }
  8788. };
  8789. var clearPendingPhaseMeasurement = function () {
  8790. if (currentPhase !== null && currentPhaseFiber !== null) {
  8791. clearFiberMark(currentPhaseFiber, currentPhase);
  8792. }
  8793. currentPhaseFiber = null;
  8794. currentPhase = null;
  8795. hasScheduledUpdateInCurrentPhase = false;
  8796. };
  8797. var pauseTimers = function () {
  8798. // Stops all currently active measurements so that they can be resumed
  8799. // if we continue in a later deferred loop from the same unit of work.
  8800. var fiber = currentFiber;
  8801. while (fiber) {
  8802. if (fiber._debugIsCurrentlyTiming) {
  8803. endFiberMark(fiber, null, null);
  8804. }
  8805. fiber = fiber.return;
  8806. }
  8807. };
  8808. var resumeTimersRecursively = function (fiber) {
  8809. if (fiber.return !== null) {
  8810. resumeTimersRecursively(fiber.return);
  8811. }
  8812. if (fiber._debugIsCurrentlyTiming) {
  8813. beginFiberMark(fiber, null);
  8814. }
  8815. };
  8816. var resumeTimers = function () {
  8817. // Resumes all measurements that were active during the last deferred loop.
  8818. if (currentFiber !== null) {
  8819. resumeTimersRecursively(currentFiber);
  8820. }
  8821. };
  8822. function recordEffect() {
  8823. {
  8824. effectCountInCurrentCommit++;
  8825. }
  8826. }
  8827. function recordScheduleUpdate() {
  8828. {
  8829. if (isCommitting) {
  8830. hasScheduledUpdateInCurrentCommit = true;
  8831. }
  8832. if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
  8833. hasScheduledUpdateInCurrentPhase = true;
  8834. }
  8835. }
  8836. }
  8837. function startWorkTimer(fiber) {
  8838. {
  8839. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  8840. return;
  8841. } // If we pause, this is the fiber to unwind from.
  8842. currentFiber = fiber;
  8843. if (!beginFiberMark(fiber, null)) {
  8844. return;
  8845. }
  8846. fiber._debugIsCurrentlyTiming = true;
  8847. }
  8848. }
  8849. function cancelWorkTimer(fiber) {
  8850. {
  8851. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  8852. return;
  8853. } // Remember we shouldn't complete measurement for this fiber.
  8854. // Otherwise flamechart will be deep even for small updates.
  8855. fiber._debugIsCurrentlyTiming = false;
  8856. clearFiberMark(fiber, null);
  8857. }
  8858. }
  8859. function stopWorkTimer(fiber) {
  8860. {
  8861. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  8862. return;
  8863. } // If we pause, its parent is the fiber to unwind from.
  8864. currentFiber = fiber.return;
  8865. if (!fiber._debugIsCurrentlyTiming) {
  8866. return;
  8867. }
  8868. fiber._debugIsCurrentlyTiming = false;
  8869. endFiberMark(fiber, null, null);
  8870. }
  8871. }
  8872. function stopFailedWorkTimer(fiber) {
  8873. {
  8874. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  8875. return;
  8876. } // If we pause, its parent is the fiber to unwind from.
  8877. currentFiber = fiber.return;
  8878. if (!fiber._debugIsCurrentlyTiming) {
  8879. return;
  8880. }
  8881. fiber._debugIsCurrentlyTiming = false;
  8882. var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
  8883. endFiberMark(fiber, null, warning);
  8884. }
  8885. }
  8886. function startPhaseTimer(fiber, phase) {
  8887. {
  8888. if (!supportsUserTiming) {
  8889. return;
  8890. }
  8891. clearPendingPhaseMeasurement();
  8892. if (!beginFiberMark(fiber, phase)) {
  8893. return;
  8894. }
  8895. currentPhaseFiber = fiber;
  8896. currentPhase = phase;
  8897. }
  8898. }
  8899. function stopPhaseTimer() {
  8900. {
  8901. if (!supportsUserTiming) {
  8902. return;
  8903. }
  8904. if (currentPhase !== null && currentPhaseFiber !== null) {
  8905. var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
  8906. endFiberMark(currentPhaseFiber, currentPhase, warning);
  8907. }
  8908. currentPhase = null;
  8909. currentPhaseFiber = null;
  8910. }
  8911. }
  8912. function startWorkLoopTimer(nextUnitOfWork) {
  8913. {
  8914. currentFiber = nextUnitOfWork;
  8915. if (!supportsUserTiming) {
  8916. return;
  8917. }
  8918. commitCountInCurrentWorkLoop = 0; // This is top level call.
  8919. // Any other measurements are performed within.
  8920. beginMark('(React Tree Reconciliation)'); // Resume any measurements that were in progress during the last loop.
  8921. resumeTimers();
  8922. }
  8923. }
  8924. function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
  8925. {
  8926. if (!supportsUserTiming) {
  8927. return;
  8928. }
  8929. var warning = null;
  8930. if (interruptedBy !== null) {
  8931. if (interruptedBy.tag === HostRoot) {
  8932. warning = 'A top-level update interrupted the previous render';
  8933. } else {
  8934. var componentName = getComponentName(interruptedBy.type) || 'Unknown';
  8935. warning = "An update to " + componentName + " interrupted the previous render";
  8936. }
  8937. } else if (commitCountInCurrentWorkLoop > 1) {
  8938. warning = 'There were cascading updates';
  8939. }
  8940. commitCountInCurrentWorkLoop = 0;
  8941. var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)'; // Pause any measurements until the next loop.
  8942. pauseTimers();
  8943. endMark(label, '(React Tree Reconciliation)', warning);
  8944. }
  8945. }
  8946. function startCommitTimer() {
  8947. {
  8948. if (!supportsUserTiming) {
  8949. return;
  8950. }
  8951. isCommitting = true;
  8952. hasScheduledUpdateInCurrentCommit = false;
  8953. labelsInCurrentCommit.clear();
  8954. beginMark('(Committing Changes)');
  8955. }
  8956. }
  8957. function stopCommitTimer() {
  8958. {
  8959. if (!supportsUserTiming) {
  8960. return;
  8961. }
  8962. var warning = null;
  8963. if (hasScheduledUpdateInCurrentCommit) {
  8964. warning = 'Lifecycle hook scheduled a cascading update';
  8965. } else if (commitCountInCurrentWorkLoop > 0) {
  8966. warning = 'Caused by a cascading update in earlier commit';
  8967. }
  8968. hasScheduledUpdateInCurrentCommit = false;
  8969. commitCountInCurrentWorkLoop++;
  8970. isCommitting = false;
  8971. labelsInCurrentCommit.clear();
  8972. endMark('(Committing Changes)', '(Committing Changes)', warning);
  8973. }
  8974. }
  8975. function startCommitSnapshotEffectsTimer() {
  8976. {
  8977. if (!supportsUserTiming) {
  8978. return;
  8979. }
  8980. effectCountInCurrentCommit = 0;
  8981. beginMark('(Committing Snapshot Effects)');
  8982. }
  8983. }
  8984. function stopCommitSnapshotEffectsTimer() {
  8985. {
  8986. if (!supportsUserTiming) {
  8987. return;
  8988. }
  8989. var count = effectCountInCurrentCommit;
  8990. effectCountInCurrentCommit = 0;
  8991. endMark("(Committing Snapshot Effects: " + count + " Total)", '(Committing Snapshot Effects)', null);
  8992. }
  8993. }
  8994. function startCommitHostEffectsTimer() {
  8995. {
  8996. if (!supportsUserTiming) {
  8997. return;
  8998. }
  8999. effectCountInCurrentCommit = 0;
  9000. beginMark('(Committing Host Effects)');
  9001. }
  9002. }
  9003. function stopCommitHostEffectsTimer() {
  9004. {
  9005. if (!supportsUserTiming) {
  9006. return;
  9007. }
  9008. var count = effectCountInCurrentCommit;
  9009. effectCountInCurrentCommit = 0;
  9010. endMark("(Committing Host Effects: " + count + " Total)", '(Committing Host Effects)', null);
  9011. }
  9012. }
  9013. function startCommitLifeCyclesTimer() {
  9014. {
  9015. if (!supportsUserTiming) {
  9016. return;
  9017. }
  9018. effectCountInCurrentCommit = 0;
  9019. beginMark('(Calling Lifecycle Methods)');
  9020. }
  9021. }
  9022. function stopCommitLifeCyclesTimer() {
  9023. {
  9024. if (!supportsUserTiming) {
  9025. return;
  9026. }
  9027. var count = effectCountInCurrentCommit;
  9028. effectCountInCurrentCommit = 0;
  9029. endMark("(Calling Lifecycle Methods: " + count + " Total)", '(Calling Lifecycle Methods)', null);
  9030. }
  9031. }
  9032. var valueStack = [];
  9033. var fiberStack;
  9034. {
  9035. fiberStack = [];
  9036. }
  9037. var index = -1;
  9038. function createCursor(defaultValue) {
  9039. return {
  9040. current: defaultValue
  9041. };
  9042. }
  9043. function pop(cursor, fiber) {
  9044. if (index < 0) {
  9045. {
  9046. error('Unexpected pop.');
  9047. }
  9048. return;
  9049. }
  9050. {
  9051. if (fiber !== fiberStack[index]) {
  9052. error('Unexpected Fiber popped.');
  9053. }
  9054. }
  9055. cursor.current = valueStack[index];
  9056. valueStack[index] = null;
  9057. {
  9058. fiberStack[index] = null;
  9059. }
  9060. index--;
  9061. }
  9062. function push(cursor, value, fiber) {
  9063. index++;
  9064. valueStack[index] = cursor.current;
  9065. {
  9066. fiberStack[index] = fiber;
  9067. }
  9068. cursor.current = value;
  9069. }
  9070. var warnedAboutMissingGetChildContext;
  9071. {
  9072. warnedAboutMissingGetChildContext = {};
  9073. }
  9074. var emptyContextObject = {};
  9075. {
  9076. Object.freeze(emptyContextObject);
  9077. } // A cursor to the current merged context object on the stack.
  9078. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  9079. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  9080. // We use this to get access to the parent context after we have already
  9081. // pushed the next context provider, and now need to merge their contexts.
  9082. var previousContext = emptyContextObject;
  9083. function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
  9084. {
  9085. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  9086. // If the fiber is a context provider itself, when we read its context
  9087. // we may have already pushed its own child context on the stack. A context
  9088. // provider should not "see" its own child context. Therefore we read the
  9089. // previous (parent) context instead for a context provider.
  9090. return previousContext;
  9091. }
  9092. return contextStackCursor.current;
  9093. }
  9094. }
  9095. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  9096. {
  9097. var instance = workInProgress.stateNode;
  9098. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  9099. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  9100. }
  9101. }
  9102. function getMaskedContext(workInProgress, unmaskedContext) {
  9103. {
  9104. var type = workInProgress.type;
  9105. var contextTypes = type.contextTypes;
  9106. if (!contextTypes) {
  9107. return emptyContextObject;
  9108. } // Avoid recreating masked context unless unmasked context has changed.
  9109. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  9110. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  9111. var instance = workInProgress.stateNode;
  9112. if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
  9113. return instance.__reactInternalMemoizedMaskedChildContext;
  9114. }
  9115. var context = {};
  9116. for (var key in contextTypes) {
  9117. context[key] = unmaskedContext[key];
  9118. }
  9119. {
  9120. var name = getComponentName(type) || 'Unknown';
  9121. checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
  9122. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  9123. // Context is created before the class component is instantiated so check for instance.
  9124. if (instance) {
  9125. cacheContext(workInProgress, unmaskedContext, context);
  9126. }
  9127. return context;
  9128. }
  9129. }
  9130. function hasContextChanged() {
  9131. {
  9132. return didPerformWorkStackCursor.current;
  9133. }
  9134. }
  9135. function isContextProvider(type) {
  9136. {
  9137. var childContextTypes = type.childContextTypes;
  9138. return childContextTypes !== null && childContextTypes !== undefined;
  9139. }
  9140. }
  9141. function popContext(fiber) {
  9142. {
  9143. pop(didPerformWorkStackCursor, fiber);
  9144. pop(contextStackCursor, fiber);
  9145. }
  9146. }
  9147. function popTopLevelContextObject(fiber) {
  9148. {
  9149. pop(didPerformWorkStackCursor, fiber);
  9150. pop(contextStackCursor, fiber);
  9151. }
  9152. }
  9153. function pushTopLevelContextObject(fiber, context, didChange) {
  9154. {
  9155. if (!(contextStackCursor.current === emptyContextObject)) {
  9156. {
  9157. throw Error( "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." );
  9158. }
  9159. }
  9160. push(contextStackCursor, context, fiber);
  9161. push(didPerformWorkStackCursor, didChange, fiber);
  9162. }
  9163. }
  9164. function processChildContext(fiber, type, parentContext) {
  9165. {
  9166. var instance = fiber.stateNode;
  9167. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  9168. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  9169. if (typeof instance.getChildContext !== 'function') {
  9170. {
  9171. var componentName = getComponentName(type) || 'Unknown';
  9172. if (!warnedAboutMissingGetChildContext[componentName]) {
  9173. warnedAboutMissingGetChildContext[componentName] = true;
  9174. error('%s.childContextTypes is specified but there is no getChildContext() method ' + 'on the instance. You can either define getChildContext() on %s or remove ' + 'childContextTypes from it.', componentName, componentName);
  9175. }
  9176. }
  9177. return parentContext;
  9178. }
  9179. var childContext;
  9180. startPhaseTimer(fiber, 'getChildContext');
  9181. childContext = instance.getChildContext();
  9182. stopPhaseTimer();
  9183. for (var contextKey in childContext) {
  9184. if (!(contextKey in childContextTypes)) {
  9185. {
  9186. throw Error( (getComponentName(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes." );
  9187. }
  9188. }
  9189. }
  9190. {
  9191. var name = getComponentName(type) || 'Unknown';
  9192. checkPropTypes_1(childContextTypes, childContext, 'child context', name, // In practice, there is one case in which we won't get a stack. It's when
  9193. // somebody calls unstable_renderSubtreeIntoContainer() and we process
  9194. // context from the parent component instance. The stack will be missing
  9195. // because it's outside of the reconciliation, and so the pointer has not
  9196. // been set. This is rare and doesn't matter. We'll also remove that API.
  9197. getCurrentFiberStackInDev);
  9198. }
  9199. return _assign({}, parentContext, {}, childContext);
  9200. }
  9201. }
  9202. function pushContextProvider(workInProgress) {
  9203. {
  9204. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  9205. // If the instance does not exist yet, we will push null at first,
  9206. // and replace it on the stack later when invalidating the context.
  9207. var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
  9208. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  9209. previousContext = contextStackCursor.current;
  9210. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  9211. push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
  9212. return true;
  9213. }
  9214. }
  9215. function invalidateContextProvider(workInProgress, type, didChange) {
  9216. {
  9217. var instance = workInProgress.stateNode;
  9218. if (!instance) {
  9219. {
  9220. throw Error( "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." );
  9221. }
  9222. }
  9223. if (didChange) {
  9224. // Merge parent and own context.
  9225. // Skip this if we're not updating due to sCU.
  9226. // This avoids unnecessarily recomputing memoized values.
  9227. var mergedContext = processChildContext(workInProgress, type, previousContext);
  9228. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  9229. // It is important to unwind the context in the reverse order.
  9230. pop(didPerformWorkStackCursor, workInProgress);
  9231. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  9232. push(contextStackCursor, mergedContext, workInProgress);
  9233. push(didPerformWorkStackCursor, didChange, workInProgress);
  9234. } else {
  9235. pop(didPerformWorkStackCursor, workInProgress);
  9236. push(didPerformWorkStackCursor, didChange, workInProgress);
  9237. }
  9238. }
  9239. }
  9240. function findCurrentUnmaskedContext(fiber) {
  9241. {
  9242. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  9243. // makes sense elsewhere
  9244. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  9245. {
  9246. throw Error( "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." );
  9247. }
  9248. }
  9249. var node = fiber;
  9250. do {
  9251. switch (node.tag) {
  9252. case HostRoot:
  9253. return node.stateNode.context;
  9254. case ClassComponent:
  9255. {
  9256. var Component = node.type;
  9257. if (isContextProvider(Component)) {
  9258. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  9259. }
  9260. break;
  9261. }
  9262. }
  9263. node = node.return;
  9264. } while (node !== null);
  9265. {
  9266. {
  9267. throw Error( "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." );
  9268. }
  9269. }
  9270. }
  9271. }
  9272. var LegacyRoot = 0;
  9273. var BlockingRoot = 1;
  9274. var ConcurrentRoot = 2;
  9275. var ReactInternals$2 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  9276. var _ReactInternals$Sched$1 = ReactInternals$2.SchedulerTracing,
  9277. __interactionsRef = _ReactInternals$Sched$1.__interactionsRef,
  9278. __subscriberRef = _ReactInternals$Sched$1.__subscriberRef,
  9279. unstable_clear = _ReactInternals$Sched$1.unstable_clear,
  9280. unstable_getCurrent = _ReactInternals$Sched$1.unstable_getCurrent,
  9281. unstable_getThreadID = _ReactInternals$Sched$1.unstable_getThreadID,
  9282. unstable_subscribe = _ReactInternals$Sched$1.unstable_subscribe,
  9283. unstable_trace = _ReactInternals$Sched$1.unstable_trace,
  9284. unstable_unsubscribe = _ReactInternals$Sched$1.unstable_unsubscribe,
  9285. unstable_wrap = _ReactInternals$Sched$1.unstable_wrap;
  9286. var Scheduler_runWithPriority = unstable_runWithPriority,
  9287. Scheduler_scheduleCallback = unstable_scheduleCallback,
  9288. Scheduler_cancelCallback = unstable_cancelCallback,
  9289. Scheduler_shouldYield = unstable_shouldYield,
  9290. Scheduler_requestPaint = unstable_requestPaint,
  9291. Scheduler_now = unstable_now,
  9292. Scheduler_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel,
  9293. Scheduler_ImmediatePriority = unstable_ImmediatePriority,
  9294. Scheduler_UserBlockingPriority = unstable_UserBlockingPriority,
  9295. Scheduler_NormalPriority = unstable_NormalPriority,
  9296. Scheduler_LowPriority = unstable_LowPriority,
  9297. Scheduler_IdlePriority = unstable_IdlePriority;
  9298. {
  9299. // Provide explicit error message when production+profiling bundle of e.g.
  9300. // react-dom is used with production (non-profiling) bundle of
  9301. // scheduler/tracing
  9302. if (!(__interactionsRef != null && __interactionsRef.current != null)) {
  9303. {
  9304. throw Error( "It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `scheduler/tracing` module with `scheduler/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling" );
  9305. }
  9306. }
  9307. }
  9308. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  9309. // ascending numbers so we can compare them like numbers. They start at 90 to
  9310. // avoid clashing with Scheduler's priorities.
  9311. var ImmediatePriority = 99;
  9312. var UserBlockingPriority$1 = 98;
  9313. var NormalPriority = 97;
  9314. var LowPriority = 96;
  9315. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  9316. var NoPriority = 90;
  9317. var shouldYield = Scheduler_shouldYield;
  9318. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  9319. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function () {};
  9320. var syncQueue = null;
  9321. var immediateQueueCallbackNode = null;
  9322. var isFlushingSyncQueue = false;
  9323. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  9324. // This will be the case for modern browsers that support `performance.now`. In
  9325. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  9326. // timestamp. In that case, subtract the module initialization time to simulate
  9327. // the behavior of performance.now and keep our times small enough to fit
  9328. // within 32 bits.
  9329. // TODO: Consider lifting this into Scheduler.
  9330. var now = initialTimeMs < 10000 ? Scheduler_now : function () {
  9331. return Scheduler_now() - initialTimeMs;
  9332. };
  9333. function getCurrentPriorityLevel() {
  9334. switch (Scheduler_getCurrentPriorityLevel()) {
  9335. case Scheduler_ImmediatePriority:
  9336. return ImmediatePriority;
  9337. case Scheduler_UserBlockingPriority:
  9338. return UserBlockingPriority$1;
  9339. case Scheduler_NormalPriority:
  9340. return NormalPriority;
  9341. case Scheduler_LowPriority:
  9342. return LowPriority;
  9343. case Scheduler_IdlePriority:
  9344. return IdlePriority;
  9345. default:
  9346. {
  9347. {
  9348. throw Error( "Unknown priority level." );
  9349. }
  9350. }
  9351. }
  9352. }
  9353. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  9354. switch (reactPriorityLevel) {
  9355. case ImmediatePriority:
  9356. return Scheduler_ImmediatePriority;
  9357. case UserBlockingPriority$1:
  9358. return Scheduler_UserBlockingPriority;
  9359. case NormalPriority:
  9360. return Scheduler_NormalPriority;
  9361. case LowPriority:
  9362. return Scheduler_LowPriority;
  9363. case IdlePriority:
  9364. return Scheduler_IdlePriority;
  9365. default:
  9366. {
  9367. {
  9368. throw Error( "Unknown priority level." );
  9369. }
  9370. }
  9371. }
  9372. }
  9373. function runWithPriority$1(reactPriorityLevel, fn) {
  9374. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  9375. return Scheduler_runWithPriority(priorityLevel, fn);
  9376. }
  9377. function scheduleCallback(reactPriorityLevel, callback, options) {
  9378. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  9379. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  9380. }
  9381. function scheduleSyncCallback(callback) {
  9382. // Push this callback into an internal queue. We'll flush these either in
  9383. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  9384. if (syncQueue === null) {
  9385. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  9386. immediateQueueCallbackNode = Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueueImpl);
  9387. } else {
  9388. // Push onto existing queue. Don't need to schedule a callback because
  9389. // we already scheduled one when we created the queue.
  9390. syncQueue.push(callback);
  9391. }
  9392. return fakeCallbackNode;
  9393. }
  9394. function cancelCallback(callbackNode) {
  9395. if (callbackNode !== fakeCallbackNode) {
  9396. Scheduler_cancelCallback(callbackNode);
  9397. }
  9398. }
  9399. function flushSyncCallbackQueue() {
  9400. if (immediateQueueCallbackNode !== null) {
  9401. var node = immediateQueueCallbackNode;
  9402. immediateQueueCallbackNode = null;
  9403. Scheduler_cancelCallback(node);
  9404. }
  9405. flushSyncCallbackQueueImpl();
  9406. }
  9407. function flushSyncCallbackQueueImpl() {
  9408. if (!isFlushingSyncQueue && syncQueue !== null) {
  9409. // Prevent re-entrancy.
  9410. isFlushingSyncQueue = true;
  9411. var i = 0;
  9412. try {
  9413. var _isSync = true;
  9414. var queue = syncQueue;
  9415. runWithPriority$1(ImmediatePriority, function () {
  9416. for (; i < queue.length; i++) {
  9417. var callback = queue[i];
  9418. do {
  9419. callback = callback(_isSync);
  9420. } while (callback !== null);
  9421. }
  9422. });
  9423. syncQueue = null;
  9424. } catch (error) {
  9425. // If something throws, leave the remaining callbacks on the queue.
  9426. if (syncQueue !== null) {
  9427. syncQueue = syncQueue.slice(i + 1);
  9428. } // Resume flushing in the next tick
  9429. Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueue);
  9430. throw error;
  9431. } finally {
  9432. isFlushingSyncQueue = false;
  9433. }
  9434. }
  9435. }
  9436. var NoMode = 0;
  9437. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  9438. // tag instead
  9439. var BlockingMode = 2;
  9440. var ConcurrentMode = 4;
  9441. var ProfileMode = 8;
  9442. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  9443. // Math.pow(2, 30) - 1
  9444. // 0b111111111111111111111111111111
  9445. var MAX_SIGNED_31_BIT_INT = 1073741823;
  9446. var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
  9447. // Never work can be committed in an inconsistent state without tearing the UI.
  9448. // The main example is offscreen content, like a hidden subtree. So one possible
  9449. // name is Offscreen. However, it also includes dehydrated Suspense boundaries,
  9450. // which are inconsistent in the sense that they haven't finished yet, but
  9451. // aren't visibly inconsistent because the server rendered HTML matches what the
  9452. // hydrated tree would look like.
  9453. var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
  9454. // order to be consistent.
  9455. var Idle = 2; // Continuous Hydration is slightly higher than Idle and is used to increase
  9456. // priority of hover targets.
  9457. var ContinuousHydration = 3;
  9458. var Sync = MAX_SIGNED_31_BIT_INT;
  9459. var Batched = Sync - 1;
  9460. var UNIT_SIZE = 10;
  9461. var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
  9462. function msToExpirationTime(ms) {
  9463. // Always subtract from the offset so that we don't clash with the magic number for NoWork.
  9464. return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
  9465. }
  9466. function expirationTimeToMs(expirationTime) {
  9467. return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
  9468. }
  9469. function ceiling(num, precision) {
  9470. return ((num / precision | 0) + 1) * precision;
  9471. }
  9472. function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
  9473. return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
  9474. } // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
  9475. // the names to reflect.
  9476. var LOW_PRIORITY_EXPIRATION = 5000;
  9477. var LOW_PRIORITY_BATCH_SIZE = 250;
  9478. function computeAsyncExpiration(currentTime) {
  9479. return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
  9480. }
  9481. function computeSuspenseExpiration(currentTime, timeoutMs) {
  9482. // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
  9483. return computeExpirationBucket(currentTime, timeoutMs, LOW_PRIORITY_BATCH_SIZE);
  9484. } // We intentionally set a higher expiration time for interactive updates in
  9485. // dev than in production.
  9486. //
  9487. // If the main thread is being blocked so long that you hit the expiration,
  9488. // it's a problem that could be solved with better scheduling.
  9489. //
  9490. // People will be more likely to notice this and fix it with the long
  9491. // expiration time in development.
  9492. //
  9493. // In production we opt for better UX at the risk of masking scheduling
  9494. // problems, by expiring fast.
  9495. var HIGH_PRIORITY_EXPIRATION = 500 ;
  9496. var HIGH_PRIORITY_BATCH_SIZE = 100;
  9497. function computeInteractiveExpiration(currentTime) {
  9498. return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
  9499. }
  9500. function inferPriorityFromExpirationTime(currentTime, expirationTime) {
  9501. if (expirationTime === Sync) {
  9502. return ImmediatePriority;
  9503. }
  9504. if (expirationTime === Never || expirationTime === Idle) {
  9505. return IdlePriority;
  9506. }
  9507. var msUntil = expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
  9508. if (msUntil <= 0) {
  9509. return ImmediatePriority;
  9510. }
  9511. if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
  9512. return UserBlockingPriority$1;
  9513. }
  9514. if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
  9515. return NormalPriority;
  9516. } // TODO: Handle LowPriority
  9517. // Assume anything lower has idle priority
  9518. return IdlePriority;
  9519. }
  9520. var ReactStrictModeWarnings = {
  9521. recordUnsafeLifecycleWarnings: function (fiber, instance) {},
  9522. flushPendingUnsafeLifecycleWarnings: function () {},
  9523. recordLegacyContextWarning: function (fiber, instance) {},
  9524. flushLegacyContextWarning: function () {},
  9525. discardPendingWarnings: function () {}
  9526. };
  9527. {
  9528. var findStrictRoot = function (fiber) {
  9529. var maybeStrictRoot = null;
  9530. var node = fiber;
  9531. while (node !== null) {
  9532. if (node.mode & StrictMode) {
  9533. maybeStrictRoot = node;
  9534. }
  9535. node = node.return;
  9536. }
  9537. return maybeStrictRoot;
  9538. };
  9539. var setToSortedString = function (set) {
  9540. var array = [];
  9541. set.forEach(function (value) {
  9542. array.push(value);
  9543. });
  9544. return array.sort().join(', ');
  9545. };
  9546. var pendingComponentWillMountWarnings = [];
  9547. var pendingUNSAFE_ComponentWillMountWarnings = [];
  9548. var pendingComponentWillReceivePropsWarnings = [];
  9549. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  9550. var pendingComponentWillUpdateWarnings = [];
  9551. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  9552. var didWarnAboutUnsafeLifecycles = new Set();
  9553. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
  9554. // Dedup strategy: Warn once per component.
  9555. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  9556. return;
  9557. }
  9558. if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
  9559. instance.componentWillMount.__suppressDeprecationWarning !== true) {
  9560. pendingComponentWillMountWarnings.push(fiber);
  9561. }
  9562. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillMount === 'function') {
  9563. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  9564. }
  9565. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  9566. pendingComponentWillReceivePropsWarnings.push(fiber);
  9567. }
  9568. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  9569. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  9570. }
  9571. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  9572. pendingComponentWillUpdateWarnings.push(fiber);
  9573. }
  9574. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
  9575. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  9576. }
  9577. };
  9578. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
  9579. // We do an initial pass to gather component names
  9580. var componentWillMountUniqueNames = new Set();
  9581. if (pendingComponentWillMountWarnings.length > 0) {
  9582. pendingComponentWillMountWarnings.forEach(function (fiber) {
  9583. componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9584. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9585. });
  9586. pendingComponentWillMountWarnings = [];
  9587. }
  9588. var UNSAFE_componentWillMountUniqueNames = new Set();
  9589. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  9590. pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
  9591. UNSAFE_componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9592. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9593. });
  9594. pendingUNSAFE_ComponentWillMountWarnings = [];
  9595. }
  9596. var componentWillReceivePropsUniqueNames = new Set();
  9597. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  9598. pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
  9599. componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9600. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9601. });
  9602. pendingComponentWillReceivePropsWarnings = [];
  9603. }
  9604. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  9605. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  9606. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
  9607. UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9608. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9609. });
  9610. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  9611. }
  9612. var componentWillUpdateUniqueNames = new Set();
  9613. if (pendingComponentWillUpdateWarnings.length > 0) {
  9614. pendingComponentWillUpdateWarnings.forEach(function (fiber) {
  9615. componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9616. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9617. });
  9618. pendingComponentWillUpdateWarnings = [];
  9619. }
  9620. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  9621. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  9622. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
  9623. UNSAFE_componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9624. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9625. });
  9626. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  9627. } // Finally, we flush all the warnings
  9628. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  9629. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  9630. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  9631. error('Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + '\nPlease update the following components: %s', sortedNames);
  9632. }
  9633. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  9634. var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
  9635. error('Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + "* If you're updating state whenever props change, " + 'refactor your code to use memoization techniques or move it to ' + 'static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n' + '\nPlease update the following components: %s', _sortedNames);
  9636. }
  9637. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  9638. var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
  9639. error('Using UNSAFE_componentWillUpdate in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + '\nPlease update the following components: %s', _sortedNames2);
  9640. }
  9641. if (componentWillMountUniqueNames.size > 0) {
  9642. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  9643. warn('componentWillMount has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + '* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' + 'this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames3);
  9644. }
  9645. if (componentWillReceivePropsUniqueNames.size > 0) {
  9646. var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
  9647. warn('componentWillReceiveProps has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + "* If you're updating state whenever props change, refactor your " + 'code to use memoization techniques or move it to ' + 'static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n' + '* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' + 'this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames4);
  9648. }
  9649. if (componentWillUpdateUniqueNames.size > 0) {
  9650. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  9651. warn('componentWillUpdate has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + '* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' + 'this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames5);
  9652. }
  9653. };
  9654. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  9655. var didWarnAboutLegacyContext = new Set();
  9656. ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
  9657. var strictRoot = findStrictRoot(fiber);
  9658. if (strictRoot === null) {
  9659. error('Expected to find a StrictMode component in a strict mode tree. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  9660. return;
  9661. } // Dedup strategy: Warn once per component.
  9662. if (didWarnAboutLegacyContext.has(fiber.type)) {
  9663. return;
  9664. }
  9665. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  9666. if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
  9667. if (warningsForRoot === undefined) {
  9668. warningsForRoot = [];
  9669. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  9670. }
  9671. warningsForRoot.push(fiber);
  9672. }
  9673. };
  9674. ReactStrictModeWarnings.flushLegacyContextWarning = function () {
  9675. pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
  9676. if (fiberArray.length === 0) {
  9677. return;
  9678. }
  9679. var firstFiber = fiberArray[0];
  9680. var uniqueNames = new Set();
  9681. fiberArray.forEach(function (fiber) {
  9682. uniqueNames.add(getComponentName(fiber.type) || 'Component');
  9683. didWarnAboutLegacyContext.add(fiber.type);
  9684. });
  9685. var sortedNames = setToSortedString(uniqueNames);
  9686. var firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
  9687. error('Legacy context API has been detected within a strict-mode tree.' + '\n\nThe old API will be supported in all 16.x releases, but applications ' + 'using it should migrate to the new version.' + '\n\nPlease update the following components: %s' + '\n\nLearn more about this warning here: https://fb.me/react-legacy-context' + '%s', sortedNames, firstComponentStack);
  9688. });
  9689. };
  9690. ReactStrictModeWarnings.discardPendingWarnings = function () {
  9691. pendingComponentWillMountWarnings = [];
  9692. pendingUNSAFE_ComponentWillMountWarnings = [];
  9693. pendingComponentWillReceivePropsWarnings = [];
  9694. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  9695. pendingComponentWillUpdateWarnings = [];
  9696. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  9697. pendingLegacyContextWarning = new Map();
  9698. };
  9699. }
  9700. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  9701. var failedBoundaries = null;
  9702. var setRefreshHandler = function (handler) {
  9703. {
  9704. resolveFamily = handler;
  9705. }
  9706. };
  9707. function resolveFunctionForHotReloading(type) {
  9708. {
  9709. if (resolveFamily === null) {
  9710. // Hot reloading is disabled.
  9711. return type;
  9712. }
  9713. var family = resolveFamily(type);
  9714. if (family === undefined) {
  9715. return type;
  9716. } // Use the latest known implementation.
  9717. return family.current;
  9718. }
  9719. }
  9720. function resolveClassForHotReloading(type) {
  9721. // No implementation differences.
  9722. return resolveFunctionForHotReloading(type);
  9723. }
  9724. function resolveForwardRefForHotReloading(type) {
  9725. {
  9726. if (resolveFamily === null) {
  9727. // Hot reloading is disabled.
  9728. return type;
  9729. }
  9730. var family = resolveFamily(type);
  9731. if (family === undefined) {
  9732. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  9733. if (type !== null && type !== undefined && typeof type.render === 'function') {
  9734. // ForwardRef is special because its resolved .type is an object,
  9735. // but it's possible that we only have its inner render function in the map.
  9736. // If that inner render function is different, we'll build a new forwardRef type.
  9737. var currentRender = resolveFunctionForHotReloading(type.render);
  9738. if (type.render !== currentRender) {
  9739. var syntheticType = {
  9740. $$typeof: REACT_FORWARD_REF_TYPE,
  9741. render: currentRender
  9742. };
  9743. if (type.displayName !== undefined) {
  9744. syntheticType.displayName = type.displayName;
  9745. }
  9746. return syntheticType;
  9747. }
  9748. }
  9749. return type;
  9750. } // Use the latest known implementation.
  9751. return family.current;
  9752. }
  9753. }
  9754. function isCompatibleFamilyForHotReloading(fiber, element) {
  9755. {
  9756. if (resolveFamily === null) {
  9757. // Hot reloading is disabled.
  9758. return false;
  9759. }
  9760. var prevType = fiber.elementType;
  9761. var nextType = element.type; // If we got here, we know types aren't === equal.
  9762. var needsCompareFamilies = false;
  9763. var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
  9764. switch (fiber.tag) {
  9765. case ClassComponent:
  9766. {
  9767. if (typeof nextType === 'function') {
  9768. needsCompareFamilies = true;
  9769. }
  9770. break;
  9771. }
  9772. case FunctionComponent:
  9773. {
  9774. if (typeof nextType === 'function') {
  9775. needsCompareFamilies = true;
  9776. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  9777. // We don't know the inner type yet.
  9778. // We're going to assume that the lazy inner type is stable,
  9779. // and so it is sufficient to avoid reconciling it away.
  9780. // We're not going to unwrap or actually use the new lazy type.
  9781. needsCompareFamilies = true;
  9782. }
  9783. break;
  9784. }
  9785. case ForwardRef:
  9786. {
  9787. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  9788. needsCompareFamilies = true;
  9789. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  9790. needsCompareFamilies = true;
  9791. }
  9792. break;
  9793. }
  9794. case MemoComponent:
  9795. case SimpleMemoComponent:
  9796. {
  9797. if ($$typeofNextType === REACT_MEMO_TYPE) {
  9798. // TODO: if it was but can no longer be simple,
  9799. // we shouldn't set this.
  9800. needsCompareFamilies = true;
  9801. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  9802. needsCompareFamilies = true;
  9803. }
  9804. break;
  9805. }
  9806. default:
  9807. return false;
  9808. } // Check if both types have a family and it's the same one.
  9809. if (needsCompareFamilies) {
  9810. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  9811. // This means both of them need to be registered to preserve state.
  9812. // If we unwrapped and compared the inner types for wrappers instead,
  9813. // then we would risk falsely saying two separate memo(Foo)
  9814. // calls are equivalent because they wrap the same Foo function.
  9815. var prevFamily = resolveFamily(prevType);
  9816. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  9817. return true;
  9818. }
  9819. }
  9820. return false;
  9821. }
  9822. }
  9823. function markFailedErrorBoundaryForHotReloading(fiber) {
  9824. {
  9825. if (resolveFamily === null) {
  9826. // Hot reloading is disabled.
  9827. return;
  9828. }
  9829. if (typeof WeakSet !== 'function') {
  9830. return;
  9831. }
  9832. if (failedBoundaries === null) {
  9833. failedBoundaries = new WeakSet();
  9834. }
  9835. failedBoundaries.add(fiber);
  9836. }
  9837. }
  9838. var scheduleRefresh = function (root, update) {
  9839. {
  9840. if (resolveFamily === null) {
  9841. // Hot reloading is disabled.
  9842. return;
  9843. }
  9844. var staleFamilies = update.staleFamilies,
  9845. updatedFamilies = update.updatedFamilies;
  9846. flushPassiveEffects();
  9847. flushSync(function () {
  9848. scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
  9849. });
  9850. }
  9851. };
  9852. var scheduleRoot = function (root, element) {
  9853. {
  9854. if (root.context !== emptyContextObject) {
  9855. // Super edge case: root has a legacy _renderSubtree context
  9856. // but we don't know the parentComponent so we can't pass it.
  9857. // Just ignore. We'll delete this with _renderSubtree code path later.
  9858. return;
  9859. }
  9860. flushPassiveEffects();
  9861. syncUpdates(function () {
  9862. updateContainer(element, root, null, null);
  9863. });
  9864. }
  9865. };
  9866. function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
  9867. {
  9868. var alternate = fiber.alternate,
  9869. child = fiber.child,
  9870. sibling = fiber.sibling,
  9871. tag = fiber.tag,
  9872. type = fiber.type;
  9873. var candidateType = null;
  9874. switch (tag) {
  9875. case FunctionComponent:
  9876. case SimpleMemoComponent:
  9877. case ClassComponent:
  9878. candidateType = type;
  9879. break;
  9880. case ForwardRef:
  9881. candidateType = type.render;
  9882. break;
  9883. }
  9884. if (resolveFamily === null) {
  9885. throw new Error('Expected resolveFamily to be set during hot reload.');
  9886. }
  9887. var needsRender = false;
  9888. var needsRemount = false;
  9889. if (candidateType !== null) {
  9890. var family = resolveFamily(candidateType);
  9891. if (family !== undefined) {
  9892. if (staleFamilies.has(family)) {
  9893. needsRemount = true;
  9894. } else if (updatedFamilies.has(family)) {
  9895. if (tag === ClassComponent) {
  9896. needsRemount = true;
  9897. } else {
  9898. needsRender = true;
  9899. }
  9900. }
  9901. }
  9902. }
  9903. if (failedBoundaries !== null) {
  9904. if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
  9905. needsRemount = true;
  9906. }
  9907. }
  9908. if (needsRemount) {
  9909. fiber._debugNeedsRemount = true;
  9910. }
  9911. if (needsRemount || needsRender) {
  9912. scheduleWork(fiber, Sync);
  9913. }
  9914. if (child !== null && !needsRemount) {
  9915. scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
  9916. }
  9917. if (sibling !== null) {
  9918. scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
  9919. }
  9920. }
  9921. }
  9922. var findHostInstancesForRefresh = function (root, families) {
  9923. {
  9924. var hostInstances = new Set();
  9925. var types = new Set(families.map(function (family) {
  9926. return family.current;
  9927. }));
  9928. findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
  9929. return hostInstances;
  9930. }
  9931. };
  9932. function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
  9933. {
  9934. var child = fiber.child,
  9935. sibling = fiber.sibling,
  9936. tag = fiber.tag,
  9937. type = fiber.type;
  9938. var candidateType = null;
  9939. switch (tag) {
  9940. case FunctionComponent:
  9941. case SimpleMemoComponent:
  9942. case ClassComponent:
  9943. candidateType = type;
  9944. break;
  9945. case ForwardRef:
  9946. candidateType = type.render;
  9947. break;
  9948. }
  9949. var didMatch = false;
  9950. if (candidateType !== null) {
  9951. if (types.has(candidateType)) {
  9952. didMatch = true;
  9953. }
  9954. }
  9955. if (didMatch) {
  9956. // We have a match. This only drills down to the closest host components.
  9957. // There's no need to search deeper because for the purpose of giving
  9958. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  9959. findHostInstancesForFiberShallowly(fiber, hostInstances);
  9960. } else {
  9961. // If there's no match, maybe there will be one further down in the child tree.
  9962. if (child !== null) {
  9963. findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
  9964. }
  9965. }
  9966. if (sibling !== null) {
  9967. findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
  9968. }
  9969. }
  9970. }
  9971. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  9972. {
  9973. var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
  9974. if (foundHostInstances) {
  9975. return;
  9976. } // If we didn't find any host children, fallback to closest host parent.
  9977. var node = fiber;
  9978. while (true) {
  9979. switch (node.tag) {
  9980. case HostComponent:
  9981. hostInstances.add(node.stateNode);
  9982. return;
  9983. case HostPortal:
  9984. hostInstances.add(node.stateNode.containerInfo);
  9985. return;
  9986. case HostRoot:
  9987. hostInstances.add(node.stateNode.containerInfo);
  9988. return;
  9989. }
  9990. if (node.return === null) {
  9991. throw new Error('Expected to reach root first.');
  9992. }
  9993. node = node.return;
  9994. }
  9995. }
  9996. }
  9997. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  9998. {
  9999. var node = fiber;
  10000. var foundHostInstances = false;
  10001. while (true) {
  10002. if (node.tag === HostComponent) {
  10003. // We got a match.
  10004. foundHostInstances = true;
  10005. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  10006. } else if (node.child !== null) {
  10007. node.child.return = node;
  10008. node = node.child;
  10009. continue;
  10010. }
  10011. if (node === fiber) {
  10012. return foundHostInstances;
  10013. }
  10014. while (node.sibling === null) {
  10015. if (node.return === null || node.return === fiber) {
  10016. return foundHostInstances;
  10017. }
  10018. node = node.return;
  10019. }
  10020. node.sibling.return = node.return;
  10021. node = node.sibling;
  10022. }
  10023. }
  10024. return false;
  10025. }
  10026. function resolveDefaultProps(Component, baseProps) {
  10027. if (Component && Component.defaultProps) {
  10028. // Resolve default props. Taken from ReactElement
  10029. var props = _assign({}, baseProps);
  10030. var defaultProps = Component.defaultProps;
  10031. for (var propName in defaultProps) {
  10032. if (props[propName] === undefined) {
  10033. props[propName] = defaultProps[propName];
  10034. }
  10035. }
  10036. return props;
  10037. }
  10038. return baseProps;
  10039. }
  10040. function readLazyComponentType(lazyComponent) {
  10041. initializeLazyComponentType(lazyComponent);
  10042. if (lazyComponent._status !== Resolved) {
  10043. throw lazyComponent._result;
  10044. }
  10045. return lazyComponent._result;
  10046. }
  10047. var valueCursor = createCursor(null);
  10048. var rendererSigil;
  10049. {
  10050. // Use this to detect multiple renderers using the same context
  10051. rendererSigil = {};
  10052. }
  10053. var currentlyRenderingFiber = null;
  10054. var lastContextDependency = null;
  10055. var lastContextWithAllBitsObserved = null;
  10056. var isDisallowedContextReadInDEV = false;
  10057. function resetContextDependencies() {
  10058. // This is called right before React yields execution, to ensure `readContext`
  10059. // cannot be called outside the render phase.
  10060. currentlyRenderingFiber = null;
  10061. lastContextDependency = null;
  10062. lastContextWithAllBitsObserved = null;
  10063. {
  10064. isDisallowedContextReadInDEV = false;
  10065. }
  10066. }
  10067. function enterDisallowedContextReadInDEV() {
  10068. {
  10069. isDisallowedContextReadInDEV = true;
  10070. }
  10071. }
  10072. function exitDisallowedContextReadInDEV() {
  10073. {
  10074. isDisallowedContextReadInDEV = false;
  10075. }
  10076. }
  10077. function pushProvider(providerFiber, nextValue) {
  10078. var context = providerFiber.type._context;
  10079. {
  10080. push(valueCursor, context._currentValue, providerFiber);
  10081. context._currentValue = nextValue;
  10082. {
  10083. if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
  10084. error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
  10085. }
  10086. context._currentRenderer = rendererSigil;
  10087. }
  10088. }
  10089. }
  10090. function popProvider(providerFiber) {
  10091. var currentValue = valueCursor.current;
  10092. pop(valueCursor, providerFiber);
  10093. var context = providerFiber.type._context;
  10094. {
  10095. context._currentValue = currentValue;
  10096. }
  10097. }
  10098. function calculateChangedBits(context, newValue, oldValue) {
  10099. if (objectIs(oldValue, newValue)) {
  10100. // No change
  10101. return 0;
  10102. } else {
  10103. var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
  10104. {
  10105. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  10106. error('calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits);
  10107. }
  10108. }
  10109. return changedBits | 0;
  10110. }
  10111. }
  10112. function scheduleWorkOnParentPath(parent, renderExpirationTime) {
  10113. // Update the child expiration time of all the ancestors, including
  10114. // the alternates.
  10115. var node = parent;
  10116. while (node !== null) {
  10117. var alternate = node.alternate;
  10118. if (node.childExpirationTime < renderExpirationTime) {
  10119. node.childExpirationTime = renderExpirationTime;
  10120. if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
  10121. alternate.childExpirationTime = renderExpirationTime;
  10122. }
  10123. } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
  10124. alternate.childExpirationTime = renderExpirationTime;
  10125. } else {
  10126. // Neither alternate was updated, which means the rest of the
  10127. // ancestor path already has sufficient priority.
  10128. break;
  10129. }
  10130. node = node.return;
  10131. }
  10132. }
  10133. function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
  10134. var fiber = workInProgress.child;
  10135. if (fiber !== null) {
  10136. // Set the return pointer of the child to the work-in-progress fiber.
  10137. fiber.return = workInProgress;
  10138. }
  10139. while (fiber !== null) {
  10140. var nextFiber = void 0; // Visit this fiber.
  10141. var list = fiber.dependencies;
  10142. if (list !== null) {
  10143. nextFiber = fiber.child;
  10144. var dependency = list.firstContext;
  10145. while (dependency !== null) {
  10146. // Check if the context matches.
  10147. if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
  10148. // Match! Schedule an update on this fiber.
  10149. if (fiber.tag === ClassComponent) {
  10150. // Schedule a force update on the work-in-progress.
  10151. var update = createUpdate(renderExpirationTime, null);
  10152. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  10153. // update to the current fiber, too, which means it will persist even if
  10154. // this render is thrown away. Since it's a race condition, not sure it's
  10155. // worth fixing.
  10156. enqueueUpdate(fiber, update);
  10157. }
  10158. if (fiber.expirationTime < renderExpirationTime) {
  10159. fiber.expirationTime = renderExpirationTime;
  10160. }
  10161. var alternate = fiber.alternate;
  10162. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  10163. alternate.expirationTime = renderExpirationTime;
  10164. }
  10165. scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
  10166. if (list.expirationTime < renderExpirationTime) {
  10167. list.expirationTime = renderExpirationTime;
  10168. } // Since we already found a match, we can stop traversing the
  10169. // dependency list.
  10170. break;
  10171. }
  10172. dependency = dependency.next;
  10173. }
  10174. } else if (fiber.tag === ContextProvider) {
  10175. // Don't scan deeper if this is a matching provider
  10176. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  10177. } else {
  10178. // Traverse down.
  10179. nextFiber = fiber.child;
  10180. }
  10181. if (nextFiber !== null) {
  10182. // Set the return pointer of the child to the work-in-progress fiber.
  10183. nextFiber.return = fiber;
  10184. } else {
  10185. // No child. Traverse to next sibling.
  10186. nextFiber = fiber;
  10187. while (nextFiber !== null) {
  10188. if (nextFiber === workInProgress) {
  10189. // We're back to the root of this subtree. Exit.
  10190. nextFiber = null;
  10191. break;
  10192. }
  10193. var sibling = nextFiber.sibling;
  10194. if (sibling !== null) {
  10195. // Set the return pointer of the sibling to the work-in-progress fiber.
  10196. sibling.return = nextFiber.return;
  10197. nextFiber = sibling;
  10198. break;
  10199. } // No more siblings. Traverse up.
  10200. nextFiber = nextFiber.return;
  10201. }
  10202. }
  10203. fiber = nextFiber;
  10204. }
  10205. }
  10206. function prepareToReadContext(workInProgress, renderExpirationTime) {
  10207. currentlyRenderingFiber = workInProgress;
  10208. lastContextDependency = null;
  10209. lastContextWithAllBitsObserved = null;
  10210. var dependencies = workInProgress.dependencies;
  10211. if (dependencies !== null) {
  10212. var firstContext = dependencies.firstContext;
  10213. if (firstContext !== null) {
  10214. if (dependencies.expirationTime >= renderExpirationTime) {
  10215. // Context list has a pending update. Mark that this fiber performed work.
  10216. markWorkInProgressReceivedUpdate();
  10217. } // Reset the work-in-progress list
  10218. dependencies.firstContext = null;
  10219. }
  10220. }
  10221. }
  10222. function readContext(context, observedBits) {
  10223. {
  10224. // This warning would fire if you read context inside a Hook like useMemo.
  10225. // Unlike the class check below, it's not enforced in production for perf.
  10226. if (isDisallowedContextReadInDEV) {
  10227. error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
  10228. }
  10229. }
  10230. if (lastContextWithAllBitsObserved === context) ; else if (observedBits === false || observedBits === 0) ; else {
  10231. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  10232. if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
  10233. // Observe all updates.
  10234. lastContextWithAllBitsObserved = context;
  10235. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  10236. } else {
  10237. resolvedObservedBits = observedBits;
  10238. }
  10239. var contextItem = {
  10240. context: context,
  10241. observedBits: resolvedObservedBits,
  10242. next: null
  10243. };
  10244. if (lastContextDependency === null) {
  10245. if (!(currentlyRenderingFiber !== null)) {
  10246. {
  10247. throw Error( "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." );
  10248. }
  10249. } // This is the first dependency for this component. Create a new list.
  10250. lastContextDependency = contextItem;
  10251. currentlyRenderingFiber.dependencies = {
  10252. expirationTime: NoWork,
  10253. firstContext: contextItem,
  10254. responders: null
  10255. };
  10256. } else {
  10257. // Append a new context item.
  10258. lastContextDependency = lastContextDependency.next = contextItem;
  10259. }
  10260. }
  10261. return context._currentValue ;
  10262. }
  10263. var UpdateState = 0;
  10264. var ReplaceState = 1;
  10265. var ForceUpdate = 2;
  10266. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  10267. // It should only be read right after calling `processUpdateQueue`, via
  10268. // `checkHasForceUpdateAfterProcessing`.
  10269. var hasForceUpdate = false;
  10270. var didWarnUpdateInsideUpdate;
  10271. var currentlyProcessingQueue;
  10272. {
  10273. didWarnUpdateInsideUpdate = false;
  10274. currentlyProcessingQueue = null;
  10275. }
  10276. function initializeUpdateQueue(fiber) {
  10277. var queue = {
  10278. baseState: fiber.memoizedState,
  10279. baseQueue: null,
  10280. shared: {
  10281. pending: null
  10282. },
  10283. effects: null
  10284. };
  10285. fiber.updateQueue = queue;
  10286. }
  10287. function cloneUpdateQueue(current, workInProgress) {
  10288. // Clone the update queue from current. Unless it's already a clone.
  10289. var queue = workInProgress.updateQueue;
  10290. var currentQueue = current.updateQueue;
  10291. if (queue === currentQueue) {
  10292. var clone = {
  10293. baseState: currentQueue.baseState,
  10294. baseQueue: currentQueue.baseQueue,
  10295. shared: currentQueue.shared,
  10296. effects: currentQueue.effects
  10297. };
  10298. workInProgress.updateQueue = clone;
  10299. }
  10300. }
  10301. function createUpdate(expirationTime, suspenseConfig) {
  10302. var update = {
  10303. expirationTime: expirationTime,
  10304. suspenseConfig: suspenseConfig,
  10305. tag: UpdateState,
  10306. payload: null,
  10307. callback: null,
  10308. next: null
  10309. };
  10310. update.next = update;
  10311. {
  10312. update.priority = getCurrentPriorityLevel();
  10313. }
  10314. return update;
  10315. }
  10316. function enqueueUpdate(fiber, update) {
  10317. var updateQueue = fiber.updateQueue;
  10318. if (updateQueue === null) {
  10319. // Only occurs if the fiber has been unmounted.
  10320. return;
  10321. }
  10322. var sharedQueue = updateQueue.shared;
  10323. var pending = sharedQueue.pending;
  10324. if (pending === null) {
  10325. // This is the first update. Create a circular list.
  10326. update.next = update;
  10327. } else {
  10328. update.next = pending.next;
  10329. pending.next = update;
  10330. }
  10331. sharedQueue.pending = update;
  10332. {
  10333. if (currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate) {
  10334. error('An update (setState, replaceState, or forceUpdate) was scheduled ' + 'from inside an update function. Update functions should be pure, ' + 'with zero side-effects. Consider using componentDidUpdate or a ' + 'callback.');
  10335. didWarnUpdateInsideUpdate = true;
  10336. }
  10337. }
  10338. }
  10339. function enqueueCapturedUpdate(workInProgress, update) {
  10340. var current = workInProgress.alternate;
  10341. if (current !== null) {
  10342. // Ensure the work-in-progress queue is a clone
  10343. cloneUpdateQueue(current, workInProgress);
  10344. } // Captured updates go only on the work-in-progress queue.
  10345. var queue = workInProgress.updateQueue; // Append the update to the end of the list.
  10346. var last = queue.baseQueue;
  10347. if (last === null) {
  10348. queue.baseQueue = update.next = update;
  10349. update.next = update;
  10350. } else {
  10351. update.next = last.next;
  10352. last.next = update;
  10353. }
  10354. }
  10355. function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
  10356. switch (update.tag) {
  10357. case ReplaceState:
  10358. {
  10359. var payload = update.payload;
  10360. if (typeof payload === 'function') {
  10361. // Updater function
  10362. {
  10363. enterDisallowedContextReadInDEV();
  10364. if ( workInProgress.mode & StrictMode) {
  10365. payload.call(instance, prevState, nextProps);
  10366. }
  10367. }
  10368. var nextState = payload.call(instance, prevState, nextProps);
  10369. {
  10370. exitDisallowedContextReadInDEV();
  10371. }
  10372. return nextState;
  10373. } // State object
  10374. return payload;
  10375. }
  10376. case CaptureUpdate:
  10377. {
  10378. workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
  10379. }
  10380. // Intentional fallthrough
  10381. case UpdateState:
  10382. {
  10383. var _payload = update.payload;
  10384. var partialState;
  10385. if (typeof _payload === 'function') {
  10386. // Updater function
  10387. {
  10388. enterDisallowedContextReadInDEV();
  10389. if ( workInProgress.mode & StrictMode) {
  10390. _payload.call(instance, prevState, nextProps);
  10391. }
  10392. }
  10393. partialState = _payload.call(instance, prevState, nextProps);
  10394. {
  10395. exitDisallowedContextReadInDEV();
  10396. }
  10397. } else {
  10398. // Partial state object
  10399. partialState = _payload;
  10400. }
  10401. if (partialState === null || partialState === undefined) {
  10402. // Null and undefined are treated as no-ops.
  10403. return prevState;
  10404. } // Merge the partial state and the previous state.
  10405. return _assign({}, prevState, partialState);
  10406. }
  10407. case ForceUpdate:
  10408. {
  10409. hasForceUpdate = true;
  10410. return prevState;
  10411. }
  10412. }
  10413. return prevState;
  10414. }
  10415. function processUpdateQueue(workInProgress, props, instance, renderExpirationTime) {
  10416. // This is always non-null on a ClassComponent or HostRoot
  10417. var queue = workInProgress.updateQueue;
  10418. hasForceUpdate = false;
  10419. {
  10420. currentlyProcessingQueue = queue.shared;
  10421. } // The last rebase update that is NOT part of the base state.
  10422. var baseQueue = queue.baseQueue; // The last pending update that hasn't been processed yet.
  10423. var pendingQueue = queue.shared.pending;
  10424. if (pendingQueue !== null) {
  10425. // We have new updates that haven't been processed yet.
  10426. // We'll add them to the base queue.
  10427. if (baseQueue !== null) {
  10428. // Merge the pending queue and the base queue.
  10429. var baseFirst = baseQueue.next;
  10430. var pendingFirst = pendingQueue.next;
  10431. baseQueue.next = pendingFirst;
  10432. pendingQueue.next = baseFirst;
  10433. }
  10434. baseQueue = pendingQueue;
  10435. queue.shared.pending = null; // TODO: Pass `current` as argument
  10436. var current = workInProgress.alternate;
  10437. if (current !== null) {
  10438. var currentQueue = current.updateQueue;
  10439. if (currentQueue !== null) {
  10440. currentQueue.baseQueue = pendingQueue;
  10441. }
  10442. }
  10443. } // These values may change as we process the queue.
  10444. if (baseQueue !== null) {
  10445. var first = baseQueue.next; // Iterate through the list of updates to compute the result.
  10446. var newState = queue.baseState;
  10447. var newExpirationTime = NoWork;
  10448. var newBaseState = null;
  10449. var newBaseQueueFirst = null;
  10450. var newBaseQueueLast = null;
  10451. if (first !== null) {
  10452. var update = first;
  10453. do {
  10454. var updateExpirationTime = update.expirationTime;
  10455. if (updateExpirationTime < renderExpirationTime) {
  10456. // Priority is insufficient. Skip this update. If this is the first
  10457. // skipped update, the previous update/state is the new base
  10458. // update/state.
  10459. var clone = {
  10460. expirationTime: update.expirationTime,
  10461. suspenseConfig: update.suspenseConfig,
  10462. tag: update.tag,
  10463. payload: update.payload,
  10464. callback: update.callback,
  10465. next: null
  10466. };
  10467. if (newBaseQueueLast === null) {
  10468. newBaseQueueFirst = newBaseQueueLast = clone;
  10469. newBaseState = newState;
  10470. } else {
  10471. newBaseQueueLast = newBaseQueueLast.next = clone;
  10472. } // Update the remaining priority in the queue.
  10473. if (updateExpirationTime > newExpirationTime) {
  10474. newExpirationTime = updateExpirationTime;
  10475. }
  10476. } else {
  10477. // This update does have sufficient priority.
  10478. if (newBaseQueueLast !== null) {
  10479. var _clone = {
  10480. expirationTime: Sync,
  10481. // This update is going to be committed so we never want uncommit it.
  10482. suspenseConfig: update.suspenseConfig,
  10483. tag: update.tag,
  10484. payload: update.payload,
  10485. callback: update.callback,
  10486. next: null
  10487. };
  10488. newBaseQueueLast = newBaseQueueLast.next = _clone;
  10489. } // Mark the event time of this update as relevant to this render pass.
  10490. // TODO: This should ideally use the true event time of this update rather than
  10491. // its priority which is a derived and not reverseable value.
  10492. // TODO: We should skip this update if it was already committed but currently
  10493. // we have no way of detecting the difference between a committed and suspended
  10494. // update here.
  10495. markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process this update.
  10496. newState = getStateFromUpdate(workInProgress, queue, update, newState, props, instance);
  10497. var callback = update.callback;
  10498. if (callback !== null) {
  10499. workInProgress.effectTag |= Callback;
  10500. var effects = queue.effects;
  10501. if (effects === null) {
  10502. queue.effects = [update];
  10503. } else {
  10504. effects.push(update);
  10505. }
  10506. }
  10507. }
  10508. update = update.next;
  10509. if (update === null || update === first) {
  10510. pendingQueue = queue.shared.pending;
  10511. if (pendingQueue === null) {
  10512. break;
  10513. } else {
  10514. // An update was scheduled from inside a reducer. Add the new
  10515. // pending updates to the end of the list and keep processing.
  10516. update = baseQueue.next = pendingQueue.next;
  10517. pendingQueue.next = first;
  10518. queue.baseQueue = baseQueue = pendingQueue;
  10519. queue.shared.pending = null;
  10520. }
  10521. }
  10522. } while (true);
  10523. }
  10524. if (newBaseQueueLast === null) {
  10525. newBaseState = newState;
  10526. } else {
  10527. newBaseQueueLast.next = newBaseQueueFirst;
  10528. }
  10529. queue.baseState = newBaseState;
  10530. queue.baseQueue = newBaseQueueLast; // Set the remaining expiration time to be whatever is remaining in the queue.
  10531. // This should be fine because the only two other things that contribute to
  10532. // expiration time are props and context. We're already in the middle of the
  10533. // begin phase by the time we start processing the queue, so we've already
  10534. // dealt with the props. Context in components that specify
  10535. // shouldComponentUpdate is tricky; but we'll have to account for
  10536. // that regardless.
  10537. markUnprocessedUpdateTime(newExpirationTime);
  10538. workInProgress.expirationTime = newExpirationTime;
  10539. workInProgress.memoizedState = newState;
  10540. }
  10541. {
  10542. currentlyProcessingQueue = null;
  10543. }
  10544. }
  10545. function callCallback(callback, context) {
  10546. if (!(typeof callback === 'function')) {
  10547. {
  10548. throw Error( "Invalid argument passed as callback. Expected a function. Instead received: " + callback );
  10549. }
  10550. }
  10551. callback.call(context);
  10552. }
  10553. function resetHasForceUpdateBeforeProcessing() {
  10554. hasForceUpdate = false;
  10555. }
  10556. function checkHasForceUpdateAfterProcessing() {
  10557. return hasForceUpdate;
  10558. }
  10559. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  10560. // Commit the effects
  10561. var effects = finishedQueue.effects;
  10562. finishedQueue.effects = null;
  10563. if (effects !== null) {
  10564. for (var i = 0; i < effects.length; i++) {
  10565. var effect = effects[i];
  10566. var callback = effect.callback;
  10567. if (callback !== null) {
  10568. effect.callback = null;
  10569. callCallback(callback, instance);
  10570. }
  10571. }
  10572. }
  10573. }
  10574. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  10575. function requestCurrentSuspenseConfig() {
  10576. return ReactCurrentBatchConfig.suspense;
  10577. }
  10578. var fakeInternalInstance = {};
  10579. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  10580. // We'll use it to determine whether we need to initialize legacy refs.
  10581. var emptyRefsObject = new React.Component().refs;
  10582. var didWarnAboutStateAssignmentForComponent;
  10583. var didWarnAboutUninitializedState;
  10584. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  10585. var didWarnAboutLegacyLifecyclesAndDerivedState;
  10586. var didWarnAboutUndefinedDerivedState;
  10587. var warnOnUndefinedDerivedState;
  10588. var warnOnInvalidCallback;
  10589. var didWarnAboutDirectlyAssigningPropsToState;
  10590. var didWarnAboutContextTypeAndContextTypes;
  10591. var didWarnAboutInvalidateContextType;
  10592. {
  10593. didWarnAboutStateAssignmentForComponent = new Set();
  10594. didWarnAboutUninitializedState = new Set();
  10595. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  10596. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  10597. didWarnAboutDirectlyAssigningPropsToState = new Set();
  10598. didWarnAboutUndefinedDerivedState = new Set();
  10599. didWarnAboutContextTypeAndContextTypes = new Set();
  10600. didWarnAboutInvalidateContextType = new Set();
  10601. var didWarnOnInvalidCallback = new Set();
  10602. warnOnInvalidCallback = function (callback, callerName) {
  10603. if (callback === null || typeof callback === 'function') {
  10604. return;
  10605. }
  10606. var key = callerName + "_" + callback;
  10607. if (!didWarnOnInvalidCallback.has(key)) {
  10608. didWarnOnInvalidCallback.add(key);
  10609. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  10610. }
  10611. };
  10612. warnOnUndefinedDerivedState = function (type, partialState) {
  10613. if (partialState === undefined) {
  10614. var componentName = getComponentName(type) || 'Component';
  10615. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  10616. didWarnAboutUndefinedDerivedState.add(componentName);
  10617. error('%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
  10618. }
  10619. }
  10620. }; // This is so gross but it's at least non-critical and can be removed if
  10621. // it causes problems. This is meant to give a nicer error message for
  10622. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  10623. // ...)) which otherwise throws a "_processChildContext is not a function"
  10624. // exception.
  10625. Object.defineProperty(fakeInternalInstance, '_processChildContext', {
  10626. enumerable: false,
  10627. value: function () {
  10628. {
  10629. {
  10630. throw Error( "_processChildContext is not available in React 16+. This likely means you have multiple copies of React and are attempting to nest a React 15 tree inside a React 16 tree using unstable_renderSubtreeIntoContainer, which isn't supported. Try to make sure you have only one copy of React (and ideally, switch to ReactDOM.createPortal)." );
  10631. }
  10632. }
  10633. }
  10634. });
  10635. Object.freeze(fakeInternalInstance);
  10636. }
  10637. function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
  10638. var prevState = workInProgress.memoizedState;
  10639. {
  10640. if ( workInProgress.mode & StrictMode) {
  10641. // Invoke the function an extra time to help detect side-effects.
  10642. getDerivedStateFromProps(nextProps, prevState);
  10643. }
  10644. }
  10645. var partialState = getDerivedStateFromProps(nextProps, prevState);
  10646. {
  10647. warnOnUndefinedDerivedState(ctor, partialState);
  10648. } // Merge the partial state and the previous state.
  10649. var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
  10650. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  10651. // base state.
  10652. if (workInProgress.expirationTime === NoWork) {
  10653. // Queue is always non-null for classes
  10654. var updateQueue = workInProgress.updateQueue;
  10655. updateQueue.baseState = memoizedState;
  10656. }
  10657. }
  10658. var classComponentUpdater = {
  10659. isMounted: isMounted,
  10660. enqueueSetState: function (inst, payload, callback) {
  10661. var fiber = get(inst);
  10662. var currentTime = requestCurrentTimeForUpdate();
  10663. var suspenseConfig = requestCurrentSuspenseConfig();
  10664. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  10665. var update = createUpdate(expirationTime, suspenseConfig);
  10666. update.payload = payload;
  10667. if (callback !== undefined && callback !== null) {
  10668. {
  10669. warnOnInvalidCallback(callback, 'setState');
  10670. }
  10671. update.callback = callback;
  10672. }
  10673. enqueueUpdate(fiber, update);
  10674. scheduleWork(fiber, expirationTime);
  10675. },
  10676. enqueueReplaceState: function (inst, payload, callback) {
  10677. var fiber = get(inst);
  10678. var currentTime = requestCurrentTimeForUpdate();
  10679. var suspenseConfig = requestCurrentSuspenseConfig();
  10680. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  10681. var update = createUpdate(expirationTime, suspenseConfig);
  10682. update.tag = ReplaceState;
  10683. update.payload = payload;
  10684. if (callback !== undefined && callback !== null) {
  10685. {
  10686. warnOnInvalidCallback(callback, 'replaceState');
  10687. }
  10688. update.callback = callback;
  10689. }
  10690. enqueueUpdate(fiber, update);
  10691. scheduleWork(fiber, expirationTime);
  10692. },
  10693. enqueueForceUpdate: function (inst, callback) {
  10694. var fiber = get(inst);
  10695. var currentTime = requestCurrentTimeForUpdate();
  10696. var suspenseConfig = requestCurrentSuspenseConfig();
  10697. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  10698. var update = createUpdate(expirationTime, suspenseConfig);
  10699. update.tag = ForceUpdate;
  10700. if (callback !== undefined && callback !== null) {
  10701. {
  10702. warnOnInvalidCallback(callback, 'forceUpdate');
  10703. }
  10704. update.callback = callback;
  10705. }
  10706. enqueueUpdate(fiber, update);
  10707. scheduleWork(fiber, expirationTime);
  10708. }
  10709. };
  10710. function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
  10711. var instance = workInProgress.stateNode;
  10712. if (typeof instance.shouldComponentUpdate === 'function') {
  10713. {
  10714. if ( workInProgress.mode & StrictMode) {
  10715. // Invoke the function an extra time to help detect side-effects.
  10716. instance.shouldComponentUpdate(newProps, newState, nextContext);
  10717. }
  10718. }
  10719. startPhaseTimer(workInProgress, 'shouldComponentUpdate');
  10720. var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
  10721. stopPhaseTimer();
  10722. {
  10723. if (shouldUpdate === undefined) {
  10724. error('%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(ctor) || 'Component');
  10725. }
  10726. }
  10727. return shouldUpdate;
  10728. }
  10729. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  10730. return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
  10731. }
  10732. return true;
  10733. }
  10734. function checkClassInstance(workInProgress, ctor, newProps) {
  10735. var instance = workInProgress.stateNode;
  10736. {
  10737. var name = getComponentName(ctor) || 'Component';
  10738. var renderPresent = instance.render;
  10739. if (!renderPresent) {
  10740. if (ctor.prototype && typeof ctor.prototype.render === 'function') {
  10741. error('%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
  10742. } else {
  10743. error('%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
  10744. }
  10745. }
  10746. if (instance.getInitialState && !instance.getInitialState.isReactClassApproved && !instance.state) {
  10747. error('getInitialState was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Did you mean to define a state property instead?', name);
  10748. }
  10749. if (instance.getDefaultProps && !instance.getDefaultProps.isReactClassApproved) {
  10750. error('getDefaultProps was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Use a static property to define defaultProps instead.', name);
  10751. }
  10752. if (instance.propTypes) {
  10753. error('propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name);
  10754. }
  10755. if (instance.contextType) {
  10756. error('contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name);
  10757. }
  10758. {
  10759. if (instance.contextTypes) {
  10760. error('contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name);
  10761. }
  10762. if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
  10763. didWarnAboutContextTypeAndContextTypes.add(ctor);
  10764. error('%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
  10765. }
  10766. }
  10767. if (typeof instance.componentShouldUpdate === 'function') {
  10768. error('%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', name);
  10769. }
  10770. if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
  10771. error('%s has a method called shouldComponentUpdate(). ' + 'shouldComponentUpdate should not be used when extending React.PureComponent. ' + 'Please extend React.Component if shouldComponentUpdate is used.', getComponentName(ctor) || 'A pure component');
  10772. }
  10773. if (typeof instance.componentDidUnmount === 'function') {
  10774. error('%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name);
  10775. }
  10776. if (typeof instance.componentDidReceiveProps === 'function') {
  10777. error('%s has a method called ' + 'componentDidReceiveProps(). But there is no such lifecycle method. ' + 'If you meant to update the state in response to changing props, ' + 'use componentWillReceiveProps(). If you meant to fetch data or ' + 'run side-effects or mutations after React has updated the UI, use componentDidUpdate().', name);
  10778. }
  10779. if (typeof instance.componentWillRecieveProps === 'function') {
  10780. error('%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name);
  10781. }
  10782. if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') {
  10783. error('%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name);
  10784. }
  10785. var hasMutatedProps = instance.props !== newProps;
  10786. if (instance.props !== undefined && hasMutatedProps) {
  10787. error('%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, name);
  10788. }
  10789. if (instance.defaultProps) {
  10790. error('Setting defaultProps as an instance property on %s is not supported and will be ignored.' + ' Instead, define defaultProps as a static property on %s.', name, name);
  10791. }
  10792. if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
  10793. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  10794. error('%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
  10795. }
  10796. if (typeof instance.getDerivedStateFromProps === 'function') {
  10797. error('%s: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  10798. }
  10799. if (typeof instance.getDerivedStateFromError === 'function') {
  10800. error('%s: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  10801. }
  10802. if (typeof ctor.getSnapshotBeforeUpdate === 'function') {
  10803. error('%s: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', name);
  10804. }
  10805. var _state = instance.state;
  10806. if (_state && (typeof _state !== 'object' || isArray(_state))) {
  10807. error('%s.state: must be set to an object or null', name);
  10808. }
  10809. if (typeof instance.getChildContext === 'function' && typeof ctor.childContextTypes !== 'object') {
  10810. error('%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name);
  10811. }
  10812. }
  10813. }
  10814. function adoptClassInstance(workInProgress, instance) {
  10815. instance.updater = classComponentUpdater;
  10816. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  10817. set(instance, workInProgress);
  10818. {
  10819. instance._reactInternalInstance = fakeInternalInstance;
  10820. }
  10821. }
  10822. function constructClassInstance(workInProgress, ctor, props) {
  10823. var isLegacyContextConsumer = false;
  10824. var unmaskedContext = emptyContextObject;
  10825. var context = emptyContextObject;
  10826. var contextType = ctor.contextType;
  10827. {
  10828. if ('contextType' in ctor) {
  10829. var isValid = // Allow null for conditional declaration
  10830. contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
  10831. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  10832. didWarnAboutInvalidateContextType.add(ctor);
  10833. var addendum = '';
  10834. if (contextType === undefined) {
  10835. addendum = ' However, it is set to undefined. ' + 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, so ' + 'try moving the createContext() call to a separate file.';
  10836. } else if (typeof contextType !== 'object') {
  10837. addendum = ' However, it is set to a ' + typeof contextType + '.';
  10838. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  10839. addendum = ' Did you accidentally pass the Context.Provider instead?';
  10840. } else if (contextType._context !== undefined) {
  10841. // <Context.Consumer>
  10842. addendum = ' Did you accidentally pass the Context.Consumer instead?';
  10843. } else {
  10844. addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
  10845. }
  10846. error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
  10847. }
  10848. }
  10849. }
  10850. if (typeof contextType === 'object' && contextType !== null) {
  10851. context = readContext(contextType);
  10852. } else {
  10853. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  10854. var contextTypes = ctor.contextTypes;
  10855. isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
  10856. context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
  10857. } // Instantiate twice to help detect side-effects.
  10858. {
  10859. if ( workInProgress.mode & StrictMode) {
  10860. new ctor(props, context); // eslint-disable-line no-new
  10861. }
  10862. }
  10863. var instance = new ctor(props, context);
  10864. var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
  10865. adoptClassInstance(workInProgress, instance);
  10866. {
  10867. if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
  10868. var componentName = getComponentName(ctor) || 'Component';
  10869. if (!didWarnAboutUninitializedState.has(componentName)) {
  10870. didWarnAboutUninitializedState.add(componentName);
  10871. error('`%s` uses `getDerivedStateFromProps` but its initial state is ' + '%s. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `%s`. ' + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.', componentName, instance.state === null ? 'null' : 'undefined', componentName);
  10872. }
  10873. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  10874. // Warn about these lifecycles if they are present.
  10875. // Don't warn about react-lifecycles-compat polyfilled methods though.
  10876. if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
  10877. var foundWillMountName = null;
  10878. var foundWillReceivePropsName = null;
  10879. var foundWillUpdateName = null;
  10880. if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
  10881. foundWillMountName = 'componentWillMount';
  10882. } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
  10883. foundWillMountName = 'UNSAFE_componentWillMount';
  10884. }
  10885. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  10886. foundWillReceivePropsName = 'componentWillReceiveProps';
  10887. } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  10888. foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
  10889. }
  10890. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  10891. foundWillUpdateName = 'componentWillUpdate';
  10892. } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  10893. foundWillUpdateName = 'UNSAFE_componentWillUpdate';
  10894. }
  10895. if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
  10896. var _componentName = getComponentName(ctor) || 'Component';
  10897. var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
  10898. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  10899. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  10900. error('Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' + '%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', _componentName, newApiName, foundWillMountName !== null ? "\n " + foundWillMountName : '', foundWillReceivePropsName !== null ? "\n " + foundWillReceivePropsName : '', foundWillUpdateName !== null ? "\n " + foundWillUpdateName : '');
  10901. }
  10902. }
  10903. }
  10904. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  10905. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  10906. if (isLegacyContextConsumer) {
  10907. cacheContext(workInProgress, unmaskedContext, context);
  10908. }
  10909. return instance;
  10910. }
  10911. function callComponentWillMount(workInProgress, instance) {
  10912. startPhaseTimer(workInProgress, 'componentWillMount');
  10913. var oldState = instance.state;
  10914. if (typeof instance.componentWillMount === 'function') {
  10915. instance.componentWillMount();
  10916. }
  10917. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  10918. instance.UNSAFE_componentWillMount();
  10919. }
  10920. stopPhaseTimer();
  10921. if (oldState !== instance.state) {
  10922. {
  10923. error('%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + 'constructor). Use setState instead.', getComponentName(workInProgress.type) || 'Component');
  10924. }
  10925. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  10926. }
  10927. }
  10928. function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
  10929. var oldState = instance.state;
  10930. startPhaseTimer(workInProgress, 'componentWillReceiveProps');
  10931. if (typeof instance.componentWillReceiveProps === 'function') {
  10932. instance.componentWillReceiveProps(newProps, nextContext);
  10933. }
  10934. if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  10935. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  10936. }
  10937. stopPhaseTimer();
  10938. if (instance.state !== oldState) {
  10939. {
  10940. var componentName = getComponentName(workInProgress.type) || 'Component';
  10941. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  10942. didWarnAboutStateAssignmentForComponent.add(componentName);
  10943. error('%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
  10944. }
  10945. }
  10946. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  10947. }
  10948. } // Invokes the mount life-cycles on a previously never rendered instance.
  10949. function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
  10950. {
  10951. checkClassInstance(workInProgress, ctor, newProps);
  10952. }
  10953. var instance = workInProgress.stateNode;
  10954. instance.props = newProps;
  10955. instance.state = workInProgress.memoizedState;
  10956. instance.refs = emptyRefsObject;
  10957. initializeUpdateQueue(workInProgress);
  10958. var contextType = ctor.contextType;
  10959. if (typeof contextType === 'object' && contextType !== null) {
  10960. instance.context = readContext(contextType);
  10961. } else {
  10962. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  10963. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  10964. }
  10965. {
  10966. if (instance.state === newProps) {
  10967. var componentName = getComponentName(ctor) || 'Component';
  10968. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  10969. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  10970. error('%s: It is not recommended to assign props directly to state ' + "because updates to props won't be reflected in state. " + 'In most cases, it is better to use props directly.', componentName);
  10971. }
  10972. }
  10973. if (workInProgress.mode & StrictMode) {
  10974. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
  10975. }
  10976. {
  10977. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
  10978. }
  10979. }
  10980. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  10981. instance.state = workInProgress.memoizedState;
  10982. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  10983. if (typeof getDerivedStateFromProps === 'function') {
  10984. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  10985. instance.state = workInProgress.memoizedState;
  10986. } // In order to support react-lifecycles-compat polyfilled components,
  10987. // Unsafe lifecycles should not be invoked for components using the new APIs.
  10988. if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  10989. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  10990. // process them now.
  10991. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  10992. instance.state = workInProgress.memoizedState;
  10993. }
  10994. if (typeof instance.componentDidMount === 'function') {
  10995. workInProgress.effectTag |= Update;
  10996. }
  10997. }
  10998. function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
  10999. var instance = workInProgress.stateNode;
  11000. var oldProps = workInProgress.memoizedProps;
  11001. instance.props = oldProps;
  11002. var oldContext = instance.context;
  11003. var contextType = ctor.contextType;
  11004. var nextContext = emptyContextObject;
  11005. if (typeof contextType === 'object' && contextType !== null) {
  11006. nextContext = readContext(contextType);
  11007. } else {
  11008. var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  11009. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  11010. }
  11011. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  11012. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  11013. // ever the previously attempted to render - not the "current". However,
  11014. // during componentDidUpdate we pass the "current" props.
  11015. // In order to support react-lifecycles-compat polyfilled components,
  11016. // Unsafe lifecycles should not be invoked for components using the new APIs.
  11017. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  11018. if (oldProps !== newProps || oldContext !== nextContext) {
  11019. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  11020. }
  11021. }
  11022. resetHasForceUpdateBeforeProcessing();
  11023. var oldState = workInProgress.memoizedState;
  11024. var newState = instance.state = oldState;
  11025. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  11026. newState = workInProgress.memoizedState;
  11027. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  11028. // If an update was already in progress, we should schedule an Update
  11029. // effect even though we're bailing out, so that cWU/cDU are called.
  11030. if (typeof instance.componentDidMount === 'function') {
  11031. workInProgress.effectTag |= Update;
  11032. }
  11033. return false;
  11034. }
  11035. if (typeof getDerivedStateFromProps === 'function') {
  11036. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  11037. newState = workInProgress.memoizedState;
  11038. }
  11039. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  11040. if (shouldUpdate) {
  11041. // In order to support react-lifecycles-compat polyfilled components,
  11042. // Unsafe lifecycles should not be invoked for components using the new APIs.
  11043. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  11044. startPhaseTimer(workInProgress, 'componentWillMount');
  11045. if (typeof instance.componentWillMount === 'function') {
  11046. instance.componentWillMount();
  11047. }
  11048. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  11049. instance.UNSAFE_componentWillMount();
  11050. }
  11051. stopPhaseTimer();
  11052. }
  11053. if (typeof instance.componentDidMount === 'function') {
  11054. workInProgress.effectTag |= Update;
  11055. }
  11056. } else {
  11057. // If an update was already in progress, we should schedule an Update
  11058. // effect even though we're bailing out, so that cWU/cDU are called.
  11059. if (typeof instance.componentDidMount === 'function') {
  11060. workInProgress.effectTag |= Update;
  11061. } // If shouldComponentUpdate returned false, we should still update the
  11062. // memoized state to indicate that this work can be reused.
  11063. workInProgress.memoizedProps = newProps;
  11064. workInProgress.memoizedState = newState;
  11065. } // Update the existing instance's state, props, and context pointers even
  11066. // if shouldComponentUpdate returns false.
  11067. instance.props = newProps;
  11068. instance.state = newState;
  11069. instance.context = nextContext;
  11070. return shouldUpdate;
  11071. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  11072. function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
  11073. var instance = workInProgress.stateNode;
  11074. cloneUpdateQueue(current, workInProgress);
  11075. var oldProps = workInProgress.memoizedProps;
  11076. instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
  11077. var oldContext = instance.context;
  11078. var contextType = ctor.contextType;
  11079. var nextContext = emptyContextObject;
  11080. if (typeof contextType === 'object' && contextType !== null) {
  11081. nextContext = readContext(contextType);
  11082. } else {
  11083. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  11084. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  11085. }
  11086. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  11087. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  11088. // ever the previously attempted to render - not the "current". However,
  11089. // during componentDidUpdate we pass the "current" props.
  11090. // In order to support react-lifecycles-compat polyfilled components,
  11091. // Unsafe lifecycles should not be invoked for components using the new APIs.
  11092. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  11093. if (oldProps !== newProps || oldContext !== nextContext) {
  11094. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  11095. }
  11096. }
  11097. resetHasForceUpdateBeforeProcessing();
  11098. var oldState = workInProgress.memoizedState;
  11099. var newState = instance.state = oldState;
  11100. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  11101. newState = workInProgress.memoizedState;
  11102. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  11103. // If an update was already in progress, we should schedule an Update
  11104. // effect even though we're bailing out, so that cWU/cDU are called.
  11105. if (typeof instance.componentDidUpdate === 'function') {
  11106. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  11107. workInProgress.effectTag |= Update;
  11108. }
  11109. }
  11110. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  11111. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  11112. workInProgress.effectTag |= Snapshot;
  11113. }
  11114. }
  11115. return false;
  11116. }
  11117. if (typeof getDerivedStateFromProps === 'function') {
  11118. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  11119. newState = workInProgress.memoizedState;
  11120. }
  11121. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  11122. if (shouldUpdate) {
  11123. // In order to support react-lifecycles-compat polyfilled components,
  11124. // Unsafe lifecycles should not be invoked for components using the new APIs.
  11125. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
  11126. startPhaseTimer(workInProgress, 'componentWillUpdate');
  11127. if (typeof instance.componentWillUpdate === 'function') {
  11128. instance.componentWillUpdate(newProps, newState, nextContext);
  11129. }
  11130. if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  11131. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  11132. }
  11133. stopPhaseTimer();
  11134. }
  11135. if (typeof instance.componentDidUpdate === 'function') {
  11136. workInProgress.effectTag |= Update;
  11137. }
  11138. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  11139. workInProgress.effectTag |= Snapshot;
  11140. }
  11141. } else {
  11142. // If an update was already in progress, we should schedule an Update
  11143. // effect even though we're bailing out, so that cWU/cDU are called.
  11144. if (typeof instance.componentDidUpdate === 'function') {
  11145. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  11146. workInProgress.effectTag |= Update;
  11147. }
  11148. }
  11149. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  11150. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  11151. workInProgress.effectTag |= Snapshot;
  11152. }
  11153. } // If shouldComponentUpdate returned false, we should still update the
  11154. // memoized props/state to indicate that this work can be reused.
  11155. workInProgress.memoizedProps = newProps;
  11156. workInProgress.memoizedState = newState;
  11157. } // Update the existing instance's state, props, and context pointers even
  11158. // if shouldComponentUpdate returns false.
  11159. instance.props = newProps;
  11160. instance.state = newState;
  11161. instance.context = nextContext;
  11162. return shouldUpdate;
  11163. }
  11164. var didWarnAboutMaps;
  11165. var didWarnAboutGenerators;
  11166. var didWarnAboutStringRefs;
  11167. var ownerHasKeyUseWarning;
  11168. var ownerHasFunctionTypeWarning;
  11169. var warnForMissingKey = function (child) {};
  11170. {
  11171. didWarnAboutMaps = false;
  11172. didWarnAboutGenerators = false;
  11173. didWarnAboutStringRefs = {};
  11174. /**
  11175. * Warn if there's no key explicitly set on dynamic arrays of children or
  11176. * object keys are not valid. This allows us to keep track of children between
  11177. * updates.
  11178. */
  11179. ownerHasKeyUseWarning = {};
  11180. ownerHasFunctionTypeWarning = {};
  11181. warnForMissingKey = function (child) {
  11182. if (child === null || typeof child !== 'object') {
  11183. return;
  11184. }
  11185. if (!child._store || child._store.validated || child.key != null) {
  11186. return;
  11187. }
  11188. if (!(typeof child._store === 'object')) {
  11189. {
  11190. throw Error( "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue." );
  11191. }
  11192. }
  11193. child._store.validated = true;
  11194. var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
  11195. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  11196. return;
  11197. }
  11198. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  11199. error('Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
  11200. };
  11201. }
  11202. var isArray$1 = Array.isArray;
  11203. function coerceRef(returnFiber, current, element) {
  11204. var mixedRef = element.ref;
  11205. if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
  11206. {
  11207. // TODO: Clean this up once we turn on the string ref warning for
  11208. // everyone, because the strict mode case will no longer be relevant
  11209. if ((returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  11210. // because these cannot be automatically converted to an arrow function
  11211. // using a codemod. Therefore, we don't have to warn about string refs again.
  11212. !(element._owner && element._self && element._owner.stateNode !== element._self)) {
  11213. var componentName = getComponentName(returnFiber.type) || 'Component';
  11214. if (!didWarnAboutStringRefs[componentName]) {
  11215. {
  11216. error('A string ref, "%s", has been found within a strict mode tree. ' + 'String refs are a source of potential bugs and should be avoided. ' + 'We recommend using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://fb.me/react-strict-mode-string-ref%s', mixedRef, getStackByFiberInDevAndProd(returnFiber));
  11217. }
  11218. didWarnAboutStringRefs[componentName] = true;
  11219. }
  11220. }
  11221. }
  11222. if (element._owner) {
  11223. var owner = element._owner;
  11224. var inst;
  11225. if (owner) {
  11226. var ownerFiber = owner;
  11227. if (!(ownerFiber.tag === ClassComponent)) {
  11228. {
  11229. throw Error( "Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref" );
  11230. }
  11231. }
  11232. inst = ownerFiber.stateNode;
  11233. }
  11234. if (!inst) {
  11235. {
  11236. throw Error( "Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue." );
  11237. }
  11238. }
  11239. var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
  11240. if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) {
  11241. return current.ref;
  11242. }
  11243. var ref = function (value) {
  11244. var refs = inst.refs;
  11245. if (refs === emptyRefsObject) {
  11246. // This is a lazy pooled frozen object, so we need to initialize.
  11247. refs = inst.refs = {};
  11248. }
  11249. if (value === null) {
  11250. delete refs[stringRef];
  11251. } else {
  11252. refs[stringRef] = value;
  11253. }
  11254. };
  11255. ref._stringRef = stringRef;
  11256. return ref;
  11257. } else {
  11258. if (!(typeof mixedRef === 'string')) {
  11259. {
  11260. throw Error( "Expected ref to be a function, a string, an object returned by React.createRef(), or null." );
  11261. }
  11262. }
  11263. if (!element._owner) {
  11264. {
  11265. throw Error( "Element ref was specified as a string (" + mixedRef + ") but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a function component\n2. You may be adding a ref to a component that was not created inside a component's render method\n3. You have multiple copies of React loaded\nSee https://fb.me/react-refs-must-have-owner for more information." );
  11266. }
  11267. }
  11268. }
  11269. }
  11270. return mixedRef;
  11271. }
  11272. function throwOnInvalidObjectType(returnFiber, newChild) {
  11273. if (returnFiber.type !== 'textarea') {
  11274. var addendum = '';
  11275. {
  11276. addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
  11277. }
  11278. {
  11279. {
  11280. throw Error( "Objects are not valid as a React child (found: " + (Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild) + ")." + addendum );
  11281. }
  11282. }
  11283. }
  11284. }
  11285. function warnOnFunctionType() {
  11286. {
  11287. var currentComponentErrorInfo = 'Functions are not valid as a React child. This may happen if ' + 'you return a Component instead of <Component /> from render. ' + 'Or maybe you meant to call this function rather than return it.' + getCurrentFiberStackInDev();
  11288. if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
  11289. return;
  11290. }
  11291. ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
  11292. error('Functions are not valid as a React child. This may happen if ' + 'you return a Component instead of <Component /> from render. ' + 'Or maybe you meant to call this function rather than return it.');
  11293. }
  11294. } // This wrapper function exists because I expect to clone the code in each path
  11295. // to be able to optimize each path individually by branching early. This needs
  11296. // a compiler or we can do it manually. Helpers that don't need this branching
  11297. // live outside of this function.
  11298. function ChildReconciler(shouldTrackSideEffects) {
  11299. function deleteChild(returnFiber, childToDelete) {
  11300. if (!shouldTrackSideEffects) {
  11301. // Noop.
  11302. return;
  11303. } // Deletions are added in reversed order so we add it to the front.
  11304. // At this point, the return fiber's effect list is empty except for
  11305. // deletions, so we can just append the deletion to the list. The remaining
  11306. // effects aren't added until the complete phase. Once we implement
  11307. // resuming, this may not be true.
  11308. var last = returnFiber.lastEffect;
  11309. if (last !== null) {
  11310. last.nextEffect = childToDelete;
  11311. returnFiber.lastEffect = childToDelete;
  11312. } else {
  11313. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  11314. }
  11315. childToDelete.nextEffect = null;
  11316. childToDelete.effectTag = Deletion;
  11317. }
  11318. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  11319. if (!shouldTrackSideEffects) {
  11320. // Noop.
  11321. return null;
  11322. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  11323. // assuming that after the first child we've already added everything.
  11324. var childToDelete = currentFirstChild;
  11325. while (childToDelete !== null) {
  11326. deleteChild(returnFiber, childToDelete);
  11327. childToDelete = childToDelete.sibling;
  11328. }
  11329. return null;
  11330. }
  11331. function mapRemainingChildren(returnFiber, currentFirstChild) {
  11332. // Add the remaining children to a temporary map so that we can find them by
  11333. // keys quickly. Implicit (null) keys get added to this set with their index
  11334. // instead.
  11335. var existingChildren = new Map();
  11336. var existingChild = currentFirstChild;
  11337. while (existingChild !== null) {
  11338. if (existingChild.key !== null) {
  11339. existingChildren.set(existingChild.key, existingChild);
  11340. } else {
  11341. existingChildren.set(existingChild.index, existingChild);
  11342. }
  11343. existingChild = existingChild.sibling;
  11344. }
  11345. return existingChildren;
  11346. }
  11347. function useFiber(fiber, pendingProps) {
  11348. // We currently set sibling to null and index to 0 here because it is easy
  11349. // to forget to do before returning it. E.g. for the single child case.
  11350. var clone = createWorkInProgress(fiber, pendingProps);
  11351. clone.index = 0;
  11352. clone.sibling = null;
  11353. return clone;
  11354. }
  11355. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  11356. newFiber.index = newIndex;
  11357. if (!shouldTrackSideEffects) {
  11358. // Noop.
  11359. return lastPlacedIndex;
  11360. }
  11361. var current = newFiber.alternate;
  11362. if (current !== null) {
  11363. var oldIndex = current.index;
  11364. if (oldIndex < lastPlacedIndex) {
  11365. // This is a move.
  11366. newFiber.effectTag = Placement;
  11367. return lastPlacedIndex;
  11368. } else {
  11369. // This item can stay in place.
  11370. return oldIndex;
  11371. }
  11372. } else {
  11373. // This is an insertion.
  11374. newFiber.effectTag = Placement;
  11375. return lastPlacedIndex;
  11376. }
  11377. }
  11378. function placeSingleChild(newFiber) {
  11379. // This is simpler for the single child case. We only need to do a
  11380. // placement for inserting new children.
  11381. if (shouldTrackSideEffects && newFiber.alternate === null) {
  11382. newFiber.effectTag = Placement;
  11383. }
  11384. return newFiber;
  11385. }
  11386. function updateTextNode(returnFiber, current, textContent, expirationTime) {
  11387. if (current === null || current.tag !== HostText) {
  11388. // Insert
  11389. var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
  11390. created.return = returnFiber;
  11391. return created;
  11392. } else {
  11393. // Update
  11394. var existing = useFiber(current, textContent);
  11395. existing.return = returnFiber;
  11396. return existing;
  11397. }
  11398. }
  11399. function updateElement(returnFiber, current, element, expirationTime) {
  11400. if (current !== null) {
  11401. if (current.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  11402. isCompatibleFamilyForHotReloading(current, element) )) {
  11403. // Move based on index
  11404. var existing = useFiber(current, element.props);
  11405. existing.ref = coerceRef(returnFiber, current, element);
  11406. existing.return = returnFiber;
  11407. {
  11408. existing._debugSource = element._source;
  11409. existing._debugOwner = element._owner;
  11410. }
  11411. return existing;
  11412. }
  11413. } // Insert
  11414. var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
  11415. created.ref = coerceRef(returnFiber, current, element);
  11416. created.return = returnFiber;
  11417. return created;
  11418. }
  11419. function updatePortal(returnFiber, current, portal, expirationTime) {
  11420. if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {
  11421. // Insert
  11422. var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
  11423. created.return = returnFiber;
  11424. return created;
  11425. } else {
  11426. // Update
  11427. var existing = useFiber(current, portal.children || []);
  11428. existing.return = returnFiber;
  11429. return existing;
  11430. }
  11431. }
  11432. function updateFragment(returnFiber, current, fragment, expirationTime, key) {
  11433. if (current === null || current.tag !== Fragment) {
  11434. // Insert
  11435. var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
  11436. created.return = returnFiber;
  11437. return created;
  11438. } else {
  11439. // Update
  11440. var existing = useFiber(current, fragment);
  11441. existing.return = returnFiber;
  11442. return existing;
  11443. }
  11444. }
  11445. function createChild(returnFiber, newChild, expirationTime) {
  11446. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11447. // Text nodes don't have keys. If the previous node is implicitly keyed
  11448. // we can continue to replace it without aborting even if it is not a text
  11449. // node.
  11450. var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
  11451. created.return = returnFiber;
  11452. return created;
  11453. }
  11454. if (typeof newChild === 'object' && newChild !== null) {
  11455. switch (newChild.$$typeof) {
  11456. case REACT_ELEMENT_TYPE:
  11457. {
  11458. var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
  11459. _created.ref = coerceRef(returnFiber, null, newChild);
  11460. _created.return = returnFiber;
  11461. return _created;
  11462. }
  11463. case REACT_PORTAL_TYPE:
  11464. {
  11465. var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
  11466. _created2.return = returnFiber;
  11467. return _created2;
  11468. }
  11469. }
  11470. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  11471. var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
  11472. _created3.return = returnFiber;
  11473. return _created3;
  11474. }
  11475. throwOnInvalidObjectType(returnFiber, newChild);
  11476. }
  11477. {
  11478. if (typeof newChild === 'function') {
  11479. warnOnFunctionType();
  11480. }
  11481. }
  11482. return null;
  11483. }
  11484. function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
  11485. // Update the fiber if the keys match, otherwise return null.
  11486. var key = oldFiber !== null ? oldFiber.key : null;
  11487. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11488. // Text nodes don't have keys. If the previous node is implicitly keyed
  11489. // we can continue to replace it without aborting even if it is not a text
  11490. // node.
  11491. if (key !== null) {
  11492. return null;
  11493. }
  11494. return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
  11495. }
  11496. if (typeof newChild === 'object' && newChild !== null) {
  11497. switch (newChild.$$typeof) {
  11498. case REACT_ELEMENT_TYPE:
  11499. {
  11500. if (newChild.key === key) {
  11501. if (newChild.type === REACT_FRAGMENT_TYPE) {
  11502. return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
  11503. }
  11504. return updateElement(returnFiber, oldFiber, newChild, expirationTime);
  11505. } else {
  11506. return null;
  11507. }
  11508. }
  11509. case REACT_PORTAL_TYPE:
  11510. {
  11511. if (newChild.key === key) {
  11512. return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
  11513. } else {
  11514. return null;
  11515. }
  11516. }
  11517. }
  11518. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  11519. if (key !== null) {
  11520. return null;
  11521. }
  11522. return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
  11523. }
  11524. throwOnInvalidObjectType(returnFiber, newChild);
  11525. }
  11526. {
  11527. if (typeof newChild === 'function') {
  11528. warnOnFunctionType();
  11529. }
  11530. }
  11531. return null;
  11532. }
  11533. function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
  11534. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11535. // Text nodes don't have keys, so we neither have to check the old nor
  11536. // new node for the key. If both are text nodes, they match.
  11537. var matchedFiber = existingChildren.get(newIdx) || null;
  11538. return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
  11539. }
  11540. if (typeof newChild === 'object' && newChild !== null) {
  11541. switch (newChild.$$typeof) {
  11542. case REACT_ELEMENT_TYPE:
  11543. {
  11544. var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  11545. if (newChild.type === REACT_FRAGMENT_TYPE) {
  11546. return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
  11547. }
  11548. return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
  11549. }
  11550. case REACT_PORTAL_TYPE:
  11551. {
  11552. var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  11553. return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
  11554. }
  11555. }
  11556. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  11557. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  11558. return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
  11559. }
  11560. throwOnInvalidObjectType(returnFiber, newChild);
  11561. }
  11562. {
  11563. if (typeof newChild === 'function') {
  11564. warnOnFunctionType();
  11565. }
  11566. }
  11567. return null;
  11568. }
  11569. /**
  11570. * Warns if there is a duplicate or missing key
  11571. */
  11572. function warnOnInvalidKey(child, knownKeys) {
  11573. {
  11574. if (typeof child !== 'object' || child === null) {
  11575. return knownKeys;
  11576. }
  11577. switch (child.$$typeof) {
  11578. case REACT_ELEMENT_TYPE:
  11579. case REACT_PORTAL_TYPE:
  11580. warnForMissingKey(child);
  11581. var key = child.key;
  11582. if (typeof key !== 'string') {
  11583. break;
  11584. }
  11585. if (knownKeys === null) {
  11586. knownKeys = new Set();
  11587. knownKeys.add(key);
  11588. break;
  11589. }
  11590. if (!knownKeys.has(key)) {
  11591. knownKeys.add(key);
  11592. break;
  11593. }
  11594. error('Encountered two children with the same key, `%s`. ' + 'Keys should be unique so that components maintain their identity ' + 'across updates. Non-unique keys may cause children to be ' + 'duplicated and/or omitted — the behavior is unsupported and ' + 'could change in a future version.', key);
  11595. break;
  11596. }
  11597. }
  11598. return knownKeys;
  11599. }
  11600. function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
  11601. // This algorithm can't optimize by searching from both ends since we
  11602. // don't have backpointers on fibers. I'm trying to see how far we can get
  11603. // with that model. If it ends up not being worth the tradeoffs, we can
  11604. // add it later.
  11605. // Even with a two ended optimization, we'd want to optimize for the case
  11606. // where there are few changes and brute force the comparison instead of
  11607. // going for the Map. It'd like to explore hitting that path first in
  11608. // forward-only mode and only go for the Map once we notice that we need
  11609. // lots of look ahead. This doesn't handle reversal as well as two ended
  11610. // search but that's unusual. Besides, for the two ended optimization to
  11611. // work on Iterables, we'd need to copy the whole set.
  11612. // In this first iteration, we'll just live with hitting the bad case
  11613. // (adding everything to a Map) in for every insert/move.
  11614. // If you change this code, also update reconcileChildrenIterator() which
  11615. // uses the same algorithm.
  11616. {
  11617. // First, validate keys.
  11618. var knownKeys = null;
  11619. for (var i = 0; i < newChildren.length; i++) {
  11620. var child = newChildren[i];
  11621. knownKeys = warnOnInvalidKey(child, knownKeys);
  11622. }
  11623. }
  11624. var resultingFirstChild = null;
  11625. var previousNewFiber = null;
  11626. var oldFiber = currentFirstChild;
  11627. var lastPlacedIndex = 0;
  11628. var newIdx = 0;
  11629. var nextOldFiber = null;
  11630. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  11631. if (oldFiber.index > newIdx) {
  11632. nextOldFiber = oldFiber;
  11633. oldFiber = null;
  11634. } else {
  11635. nextOldFiber = oldFiber.sibling;
  11636. }
  11637. var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
  11638. if (newFiber === null) {
  11639. // TODO: This breaks on empty slots like null children. That's
  11640. // unfortunate because it triggers the slow path all the time. We need
  11641. // a better way to communicate whether this was a miss or null,
  11642. // boolean, undefined, etc.
  11643. if (oldFiber === null) {
  11644. oldFiber = nextOldFiber;
  11645. }
  11646. break;
  11647. }
  11648. if (shouldTrackSideEffects) {
  11649. if (oldFiber && newFiber.alternate === null) {
  11650. // We matched the slot, but we didn't reuse the existing fiber, so we
  11651. // need to delete the existing child.
  11652. deleteChild(returnFiber, oldFiber);
  11653. }
  11654. }
  11655. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  11656. if (previousNewFiber === null) {
  11657. // TODO: Move out of the loop. This only happens for the first run.
  11658. resultingFirstChild = newFiber;
  11659. } else {
  11660. // TODO: Defer siblings if we're not at the right index for this slot.
  11661. // I.e. if we had null values before, then we want to defer this
  11662. // for each null value. However, we also don't want to call updateSlot
  11663. // with the previous one.
  11664. previousNewFiber.sibling = newFiber;
  11665. }
  11666. previousNewFiber = newFiber;
  11667. oldFiber = nextOldFiber;
  11668. }
  11669. if (newIdx === newChildren.length) {
  11670. // We've reached the end of the new children. We can delete the rest.
  11671. deleteRemainingChildren(returnFiber, oldFiber);
  11672. return resultingFirstChild;
  11673. }
  11674. if (oldFiber === null) {
  11675. // If we don't have any more existing children we can choose a fast path
  11676. // since the rest will all be insertions.
  11677. for (; newIdx < newChildren.length; newIdx++) {
  11678. var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
  11679. if (_newFiber === null) {
  11680. continue;
  11681. }
  11682. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  11683. if (previousNewFiber === null) {
  11684. // TODO: Move out of the loop. This only happens for the first run.
  11685. resultingFirstChild = _newFiber;
  11686. } else {
  11687. previousNewFiber.sibling = _newFiber;
  11688. }
  11689. previousNewFiber = _newFiber;
  11690. }
  11691. return resultingFirstChild;
  11692. } // Add all children to a key map for quick lookups.
  11693. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  11694. for (; newIdx < newChildren.length; newIdx++) {
  11695. var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
  11696. if (_newFiber2 !== null) {
  11697. if (shouldTrackSideEffects) {
  11698. if (_newFiber2.alternate !== null) {
  11699. // The new fiber is a work in progress, but if there exists a
  11700. // current, that means that we reused the fiber. We need to delete
  11701. // it from the child list so that we don't add it to the deletion
  11702. // list.
  11703. existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
  11704. }
  11705. }
  11706. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  11707. if (previousNewFiber === null) {
  11708. resultingFirstChild = _newFiber2;
  11709. } else {
  11710. previousNewFiber.sibling = _newFiber2;
  11711. }
  11712. previousNewFiber = _newFiber2;
  11713. }
  11714. }
  11715. if (shouldTrackSideEffects) {
  11716. // Any existing children that weren't consumed above were deleted. We need
  11717. // to add them to the deletion list.
  11718. existingChildren.forEach(function (child) {
  11719. return deleteChild(returnFiber, child);
  11720. });
  11721. }
  11722. return resultingFirstChild;
  11723. }
  11724. function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
  11725. // This is the same implementation as reconcileChildrenArray(),
  11726. // but using the iterator instead.
  11727. var iteratorFn = getIteratorFn(newChildrenIterable);
  11728. if (!(typeof iteratorFn === 'function')) {
  11729. {
  11730. throw Error( "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue." );
  11731. }
  11732. }
  11733. {
  11734. // We don't support rendering Generators because it's a mutation.
  11735. // See https://github.com/facebook/react/issues/12995
  11736. if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
  11737. newChildrenIterable[Symbol.toStringTag] === 'Generator') {
  11738. if (!didWarnAboutGenerators) {
  11739. error('Using Generators as children is unsupported and will likely yield ' + 'unexpected results because enumerating a generator mutates it. ' + 'You may convert it to an array with `Array.from()` or the ' + '`[...spread]` operator before rendering. Keep in mind ' + 'you might need to polyfill these features for older browsers.');
  11740. }
  11741. didWarnAboutGenerators = true;
  11742. } // Warn about using Maps as children
  11743. if (newChildrenIterable.entries === iteratorFn) {
  11744. if (!didWarnAboutMaps) {
  11745. error('Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.');
  11746. }
  11747. didWarnAboutMaps = true;
  11748. } // First, validate keys.
  11749. // We'll get a different iterator later for the main pass.
  11750. var _newChildren = iteratorFn.call(newChildrenIterable);
  11751. if (_newChildren) {
  11752. var knownKeys = null;
  11753. var _step = _newChildren.next();
  11754. for (; !_step.done; _step = _newChildren.next()) {
  11755. var child = _step.value;
  11756. knownKeys = warnOnInvalidKey(child, knownKeys);
  11757. }
  11758. }
  11759. }
  11760. var newChildren = iteratorFn.call(newChildrenIterable);
  11761. if (!(newChildren != null)) {
  11762. {
  11763. throw Error( "An iterable object provided no iterator." );
  11764. }
  11765. }
  11766. var resultingFirstChild = null;
  11767. var previousNewFiber = null;
  11768. var oldFiber = currentFirstChild;
  11769. var lastPlacedIndex = 0;
  11770. var newIdx = 0;
  11771. var nextOldFiber = null;
  11772. var step = newChildren.next();
  11773. for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
  11774. if (oldFiber.index > newIdx) {
  11775. nextOldFiber = oldFiber;
  11776. oldFiber = null;
  11777. } else {
  11778. nextOldFiber = oldFiber.sibling;
  11779. }
  11780. var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
  11781. if (newFiber === null) {
  11782. // TODO: This breaks on empty slots like null children. That's
  11783. // unfortunate because it triggers the slow path all the time. We need
  11784. // a better way to communicate whether this was a miss or null,
  11785. // boolean, undefined, etc.
  11786. if (oldFiber === null) {
  11787. oldFiber = nextOldFiber;
  11788. }
  11789. break;
  11790. }
  11791. if (shouldTrackSideEffects) {
  11792. if (oldFiber && newFiber.alternate === null) {
  11793. // We matched the slot, but we didn't reuse the existing fiber, so we
  11794. // need to delete the existing child.
  11795. deleteChild(returnFiber, oldFiber);
  11796. }
  11797. }
  11798. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  11799. if (previousNewFiber === null) {
  11800. // TODO: Move out of the loop. This only happens for the first run.
  11801. resultingFirstChild = newFiber;
  11802. } else {
  11803. // TODO: Defer siblings if we're not at the right index for this slot.
  11804. // I.e. if we had null values before, then we want to defer this
  11805. // for each null value. However, we also don't want to call updateSlot
  11806. // with the previous one.
  11807. previousNewFiber.sibling = newFiber;
  11808. }
  11809. previousNewFiber = newFiber;
  11810. oldFiber = nextOldFiber;
  11811. }
  11812. if (step.done) {
  11813. // We've reached the end of the new children. We can delete the rest.
  11814. deleteRemainingChildren(returnFiber, oldFiber);
  11815. return resultingFirstChild;
  11816. }
  11817. if (oldFiber === null) {
  11818. // If we don't have any more existing children we can choose a fast path
  11819. // since the rest will all be insertions.
  11820. for (; !step.done; newIdx++, step = newChildren.next()) {
  11821. var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
  11822. if (_newFiber3 === null) {
  11823. continue;
  11824. }
  11825. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  11826. if (previousNewFiber === null) {
  11827. // TODO: Move out of the loop. This only happens for the first run.
  11828. resultingFirstChild = _newFiber3;
  11829. } else {
  11830. previousNewFiber.sibling = _newFiber3;
  11831. }
  11832. previousNewFiber = _newFiber3;
  11833. }
  11834. return resultingFirstChild;
  11835. } // Add all children to a key map for quick lookups.
  11836. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  11837. for (; !step.done; newIdx++, step = newChildren.next()) {
  11838. var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
  11839. if (_newFiber4 !== null) {
  11840. if (shouldTrackSideEffects) {
  11841. if (_newFiber4.alternate !== null) {
  11842. // The new fiber is a work in progress, but if there exists a
  11843. // current, that means that we reused the fiber. We need to delete
  11844. // it from the child list so that we don't add it to the deletion
  11845. // list.
  11846. existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
  11847. }
  11848. }
  11849. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  11850. if (previousNewFiber === null) {
  11851. resultingFirstChild = _newFiber4;
  11852. } else {
  11853. previousNewFiber.sibling = _newFiber4;
  11854. }
  11855. previousNewFiber = _newFiber4;
  11856. }
  11857. }
  11858. if (shouldTrackSideEffects) {
  11859. // Any existing children that weren't consumed above were deleted. We need
  11860. // to add them to the deletion list.
  11861. existingChildren.forEach(function (child) {
  11862. return deleteChild(returnFiber, child);
  11863. });
  11864. }
  11865. return resultingFirstChild;
  11866. }
  11867. function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
  11868. // There's no need to check for keys on text nodes since we don't have a
  11869. // way to define them.
  11870. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  11871. // We already have an existing node so let's just update it and delete
  11872. // the rest.
  11873. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  11874. var existing = useFiber(currentFirstChild, textContent);
  11875. existing.return = returnFiber;
  11876. return existing;
  11877. } // The existing first child is not a text node so we need to create one
  11878. // and delete the existing ones.
  11879. deleteRemainingChildren(returnFiber, currentFirstChild);
  11880. var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
  11881. created.return = returnFiber;
  11882. return created;
  11883. }
  11884. function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
  11885. var key = element.key;
  11886. var child = currentFirstChild;
  11887. while (child !== null) {
  11888. // TODO: If key === null and child.key === null, then this only applies to
  11889. // the first item in the list.
  11890. if (child.key === key) {
  11891. switch (child.tag) {
  11892. case Fragment:
  11893. {
  11894. if (element.type === REACT_FRAGMENT_TYPE) {
  11895. deleteRemainingChildren(returnFiber, child.sibling);
  11896. var existing = useFiber(child, element.props.children);
  11897. existing.return = returnFiber;
  11898. {
  11899. existing._debugSource = element._source;
  11900. existing._debugOwner = element._owner;
  11901. }
  11902. return existing;
  11903. }
  11904. break;
  11905. }
  11906. case Block:
  11907. // We intentionally fallthrough here if enableBlocksAPI is not on.
  11908. // eslint-disable-next-lined no-fallthrough
  11909. default:
  11910. {
  11911. if (child.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  11912. isCompatibleFamilyForHotReloading(child, element) )) {
  11913. deleteRemainingChildren(returnFiber, child.sibling);
  11914. var _existing3 = useFiber(child, element.props);
  11915. _existing3.ref = coerceRef(returnFiber, child, element);
  11916. _existing3.return = returnFiber;
  11917. {
  11918. _existing3._debugSource = element._source;
  11919. _existing3._debugOwner = element._owner;
  11920. }
  11921. return _existing3;
  11922. }
  11923. break;
  11924. }
  11925. } // Didn't match.
  11926. deleteRemainingChildren(returnFiber, child);
  11927. break;
  11928. } else {
  11929. deleteChild(returnFiber, child);
  11930. }
  11931. child = child.sibling;
  11932. }
  11933. if (element.type === REACT_FRAGMENT_TYPE) {
  11934. var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
  11935. created.return = returnFiber;
  11936. return created;
  11937. } else {
  11938. var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
  11939. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  11940. _created4.return = returnFiber;
  11941. return _created4;
  11942. }
  11943. }
  11944. function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
  11945. var key = portal.key;
  11946. var child = currentFirstChild;
  11947. while (child !== null) {
  11948. // TODO: If key === null and child.key === null, then this only applies to
  11949. // the first item in the list.
  11950. if (child.key === key) {
  11951. if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
  11952. deleteRemainingChildren(returnFiber, child.sibling);
  11953. var existing = useFiber(child, portal.children || []);
  11954. existing.return = returnFiber;
  11955. return existing;
  11956. } else {
  11957. deleteRemainingChildren(returnFiber, child);
  11958. break;
  11959. }
  11960. } else {
  11961. deleteChild(returnFiber, child);
  11962. }
  11963. child = child.sibling;
  11964. }
  11965. var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
  11966. created.return = returnFiber;
  11967. return created;
  11968. } // This API will tag the children with the side-effect of the reconciliation
  11969. // itself. They will be added to the side-effect list as we pass through the
  11970. // children and the parent.
  11971. function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
  11972. // This function is not recursive.
  11973. // If the top level item is an array, we treat it as a set of children,
  11974. // not as a fragment. Nested arrays on the other hand will be treated as
  11975. // fragment nodes. Recursion happens at the normal flow.
  11976. // Handle top level unkeyed fragments as if they were arrays.
  11977. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  11978. // We treat the ambiguous cases above the same.
  11979. var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
  11980. if (isUnkeyedTopLevelFragment) {
  11981. newChild = newChild.props.children;
  11982. } // Handle object types
  11983. var isObject = typeof newChild === 'object' && newChild !== null;
  11984. if (isObject) {
  11985. switch (newChild.$$typeof) {
  11986. case REACT_ELEMENT_TYPE:
  11987. return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
  11988. case REACT_PORTAL_TYPE:
  11989. return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
  11990. }
  11991. }
  11992. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11993. return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
  11994. }
  11995. if (isArray$1(newChild)) {
  11996. return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
  11997. }
  11998. if (getIteratorFn(newChild)) {
  11999. return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
  12000. }
  12001. if (isObject) {
  12002. throwOnInvalidObjectType(returnFiber, newChild);
  12003. }
  12004. {
  12005. if (typeof newChild === 'function') {
  12006. warnOnFunctionType();
  12007. }
  12008. }
  12009. if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
  12010. // If the new child is undefined, and the return fiber is a composite
  12011. // component, throw an error. If Fiber return types are disabled,
  12012. // we already threw above.
  12013. switch (returnFiber.tag) {
  12014. case ClassComponent:
  12015. {
  12016. {
  12017. var instance = returnFiber.stateNode;
  12018. if (instance.render._isMockFunction) {
  12019. // We allow auto-mocks to proceed as if they're returning null.
  12020. break;
  12021. }
  12022. }
  12023. }
  12024. // Intentionally fall through to the next case, which handles both
  12025. // functions and classes
  12026. // eslint-disable-next-lined no-fallthrough
  12027. case FunctionComponent:
  12028. {
  12029. var Component = returnFiber.type;
  12030. {
  12031. {
  12032. throw Error( (Component.displayName || Component.name || 'Component') + "(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null." );
  12033. }
  12034. }
  12035. }
  12036. }
  12037. } // Remaining cases are all treated as empty.
  12038. return deleteRemainingChildren(returnFiber, currentFirstChild);
  12039. }
  12040. return reconcileChildFibers;
  12041. }
  12042. var reconcileChildFibers = ChildReconciler(true);
  12043. var mountChildFibers = ChildReconciler(false);
  12044. function cloneChildFibers(current, workInProgress) {
  12045. if (!(current === null || workInProgress.child === current.child)) {
  12046. {
  12047. throw Error( "Resuming work not yet implemented." );
  12048. }
  12049. }
  12050. if (workInProgress.child === null) {
  12051. return;
  12052. }
  12053. var currentChild = workInProgress.child;
  12054. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  12055. workInProgress.child = newChild;
  12056. newChild.return = workInProgress;
  12057. while (currentChild.sibling !== null) {
  12058. currentChild = currentChild.sibling;
  12059. newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps);
  12060. newChild.return = workInProgress;
  12061. }
  12062. newChild.sibling = null;
  12063. } // Reset a workInProgress child set to prepare it for a second pass.
  12064. function resetChildFibers(workInProgress, renderExpirationTime) {
  12065. var child = workInProgress.child;
  12066. while (child !== null) {
  12067. resetWorkInProgress(child, renderExpirationTime);
  12068. child = child.sibling;
  12069. }
  12070. }
  12071. var NO_CONTEXT = {};
  12072. var contextStackCursor$1 = createCursor(NO_CONTEXT);
  12073. var contextFiberStackCursor = createCursor(NO_CONTEXT);
  12074. var rootInstanceStackCursor = createCursor(NO_CONTEXT);
  12075. function requiredContext(c) {
  12076. if (!(c !== NO_CONTEXT)) {
  12077. {
  12078. throw Error( "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." );
  12079. }
  12080. }
  12081. return c;
  12082. }
  12083. function getRootHostContainer() {
  12084. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  12085. return rootInstance;
  12086. }
  12087. function pushHostContainer(fiber, nextRootInstance) {
  12088. // Push current root instance onto the stack;
  12089. // This allows us to reset root when portals are popped.
  12090. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  12091. // This enables us to pop only Fibers that provide unique contexts.
  12092. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  12093. // However, we can't just call getRootHostContext() and push it because
  12094. // we'd have a different number of entries on the stack depending on
  12095. // whether getRootHostContext() throws somewhere in renderer code or not.
  12096. // So we push an empty value first. This lets us safely unwind on errors.
  12097. push(contextStackCursor$1, NO_CONTEXT, fiber);
  12098. var nextRootContext = getRootHostContext(nextRootInstance); // Now that we know this function doesn't throw, replace it.
  12099. pop(contextStackCursor$1, fiber);
  12100. push(contextStackCursor$1, nextRootContext, fiber);
  12101. }
  12102. function popHostContainer(fiber) {
  12103. pop(contextStackCursor$1, fiber);
  12104. pop(contextFiberStackCursor, fiber);
  12105. pop(rootInstanceStackCursor, fiber);
  12106. }
  12107. function getHostContext() {
  12108. var context = requiredContext(contextStackCursor$1.current);
  12109. return context;
  12110. }
  12111. function pushHostContext(fiber) {
  12112. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  12113. var context = requiredContext(contextStackCursor$1.current);
  12114. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  12115. if (context === nextContext) {
  12116. return;
  12117. } // Track the context and the Fiber that provided it.
  12118. // This enables us to pop only Fibers that provide unique contexts.
  12119. push(contextFiberStackCursor, fiber, fiber);
  12120. push(contextStackCursor$1, nextContext, fiber);
  12121. }
  12122. function popHostContext(fiber) {
  12123. // Do not pop unless this Fiber provided the current context.
  12124. // pushHostContext() only pushes Fibers that provide unique contexts.
  12125. if (contextFiberStackCursor.current !== fiber) {
  12126. return;
  12127. }
  12128. pop(contextStackCursor$1, fiber);
  12129. pop(contextFiberStackCursor, fiber);
  12130. }
  12131. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  12132. // inherited deeply down the subtree. The upper bits only affect
  12133. // this immediate suspense boundary and gets reset each new
  12134. // boundary or suspense list.
  12135. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  12136. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  12137. // boundaries is not currently showing visible main content.
  12138. // Either because it is already showing a fallback or is not mounted at all.
  12139. // We can use this to determine if it is desirable to trigger a fallback at
  12140. // the parent. If not, then we might need to trigger undesirable boundaries
  12141. // and/or suspend the commit to avoid hiding the parent content.
  12142. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  12143. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  12144. // items into their fallback state during one of the render passes.
  12145. var ForceSuspenseFallback = 2;
  12146. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  12147. function hasSuspenseContext(parentContext, flag) {
  12148. return (parentContext & flag) !== 0;
  12149. }
  12150. function setDefaultShallowSuspenseContext(parentContext) {
  12151. return parentContext & SubtreeSuspenseContextMask;
  12152. }
  12153. function setShallowSuspenseContext(parentContext, shallowContext) {
  12154. return parentContext & SubtreeSuspenseContextMask | shallowContext;
  12155. }
  12156. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  12157. return parentContext | subtreeContext;
  12158. }
  12159. function pushSuspenseContext(fiber, newContext) {
  12160. push(suspenseStackCursor, newContext, fiber);
  12161. }
  12162. function popSuspenseContext(fiber) {
  12163. pop(suspenseStackCursor, fiber);
  12164. }
  12165. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  12166. // If it was the primary children that just suspended, capture and render the
  12167. // fallback. Otherwise, don't capture and bubble to the next boundary.
  12168. var nextState = workInProgress.memoizedState;
  12169. if (nextState !== null) {
  12170. if (nextState.dehydrated !== null) {
  12171. // A dehydrated boundary always captures.
  12172. return true;
  12173. }
  12174. return false;
  12175. }
  12176. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  12177. if (props.fallback === undefined) {
  12178. return false;
  12179. } // Regular boundaries always capture.
  12180. if (props.unstable_avoidThisFallback !== true) {
  12181. return true;
  12182. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  12183. // parent boundary if it is currently invisible.
  12184. if (hasInvisibleParent) {
  12185. return false;
  12186. } // If the parent is not able to handle it, we must handle it.
  12187. return true;
  12188. }
  12189. function findFirstSuspended(row) {
  12190. var node = row;
  12191. while (node !== null) {
  12192. if (node.tag === SuspenseComponent) {
  12193. var state = node.memoizedState;
  12194. if (state !== null) {
  12195. var dehydrated = state.dehydrated;
  12196. if (dehydrated === null || isSuspenseInstancePending(dehydrated) || isSuspenseInstanceFallback(dehydrated)) {
  12197. return node;
  12198. }
  12199. }
  12200. } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  12201. // keep track of whether it suspended or not.
  12202. node.memoizedProps.revealOrder !== undefined) {
  12203. var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
  12204. if (didSuspend) {
  12205. return node;
  12206. }
  12207. } else if (node.child !== null) {
  12208. node.child.return = node;
  12209. node = node.child;
  12210. continue;
  12211. }
  12212. if (node === row) {
  12213. return null;
  12214. }
  12215. while (node.sibling === null) {
  12216. if (node.return === null || node.return === row) {
  12217. return null;
  12218. }
  12219. node = node.return;
  12220. }
  12221. node.sibling.return = node.return;
  12222. node = node.sibling;
  12223. }
  12224. return null;
  12225. }
  12226. function createDeprecatedResponderListener(responder, props) {
  12227. var eventResponderListener = {
  12228. responder: responder,
  12229. props: props
  12230. };
  12231. {
  12232. Object.freeze(eventResponderListener);
  12233. }
  12234. return eventResponderListener;
  12235. }
  12236. var HasEffect =
  12237. /* */
  12238. 1; // Represents the phase in which the effect (not the clean-up) fires.
  12239. var Layout =
  12240. /* */
  12241. 2;
  12242. var Passive$1 =
  12243. /* */
  12244. 4;
  12245. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
  12246. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  12247. var didWarnAboutMismatchedHooksForComponent;
  12248. {
  12249. didWarnAboutMismatchedHooksForComponent = new Set();
  12250. }
  12251. // These are set right before calling the component.
  12252. var renderExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
  12253. // the work-in-progress hook.
  12254. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  12255. // current hook list is the list that belongs to the current fiber. The
  12256. // work-in-progress hook list is a new list that will be added to the
  12257. // work-in-progress fiber.
  12258. var currentHook = null;
  12259. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  12260. // does not get reset if we do another render pass; only when we're completely
  12261. // finished evaluating this component. This is an optimization so we know
  12262. // whether we need to clear render phase updates after a throw.
  12263. var didScheduleRenderPhaseUpdate = false;
  12264. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  12265. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  12266. // The list stores the order of hooks used during the initial render (mount).
  12267. // Subsequent renders (updates) reference this list.
  12268. var hookTypesDev = null;
  12269. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  12270. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  12271. // When true, such Hooks will always be "remounted". Only used during hot reload.
  12272. var ignorePreviousDependencies = false;
  12273. function mountHookTypesDev() {
  12274. {
  12275. var hookName = currentHookNameInDev;
  12276. if (hookTypesDev === null) {
  12277. hookTypesDev = [hookName];
  12278. } else {
  12279. hookTypesDev.push(hookName);
  12280. }
  12281. }
  12282. }
  12283. function updateHookTypesDev() {
  12284. {
  12285. var hookName = currentHookNameInDev;
  12286. if (hookTypesDev !== null) {
  12287. hookTypesUpdateIndexDev++;
  12288. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  12289. warnOnHookMismatchInDev(hookName);
  12290. }
  12291. }
  12292. }
  12293. }
  12294. function checkDepsAreArrayDev(deps) {
  12295. {
  12296. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  12297. // Verify deps, but only on mount to avoid extra checks.
  12298. // It's unlikely their type would change as usually you define them inline.
  12299. error('%s received a final argument that is not an array (instead, received `%s`). When ' + 'specified, the final argument must be an array.', currentHookNameInDev, typeof deps);
  12300. }
  12301. }
  12302. }
  12303. function warnOnHookMismatchInDev(currentHookName) {
  12304. {
  12305. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  12306. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  12307. didWarnAboutMismatchedHooksForComponent.add(componentName);
  12308. if (hookTypesDev !== null) {
  12309. var table = '';
  12310. var secondColumnStart = 30;
  12311. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  12312. var oldHookName = hookTypesDev[i];
  12313. var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  12314. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  12315. // lol @ IE not supporting String#repeat
  12316. while (row.length < secondColumnStart) {
  12317. row += ' ';
  12318. }
  12319. row += newHookName + '\n';
  12320. table += row;
  12321. }
  12322. error('React has detected a change in the order of Hooks called by %s. ' + 'This will lead to bugs and errors if not fixed. ' + 'For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n' + ' Previous render Next render\n' + ' ------------------------------------------------------\n' + '%s' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', componentName, table);
  12323. }
  12324. }
  12325. }
  12326. }
  12327. function throwInvalidHookError() {
  12328. {
  12329. {
  12330. throw Error( "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem." );
  12331. }
  12332. }
  12333. }
  12334. function areHookInputsEqual(nextDeps, prevDeps) {
  12335. {
  12336. if (ignorePreviousDependencies) {
  12337. // Only true when this component is being hot reloaded.
  12338. return false;
  12339. }
  12340. }
  12341. if (prevDeps === null) {
  12342. {
  12343. error('%s received a final argument during this render, but not during ' + 'the previous render. Even though the final argument is optional, ' + 'its type cannot change between renders.', currentHookNameInDev);
  12344. }
  12345. return false;
  12346. }
  12347. {
  12348. // Don't bother comparing lengths in prod because these arrays should be
  12349. // passed inline.
  12350. if (nextDeps.length !== prevDeps.length) {
  12351. error('The final argument passed to %s changed size between renders. The ' + 'order and size of this array must remain constant.\n\n' + 'Previous: %s\n' + 'Incoming: %s', currentHookNameInDev, "[" + prevDeps.join(', ') + "]", "[" + nextDeps.join(', ') + "]");
  12352. }
  12353. }
  12354. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  12355. if (objectIs(nextDeps[i], prevDeps[i])) {
  12356. continue;
  12357. }
  12358. return false;
  12359. }
  12360. return true;
  12361. }
  12362. function renderWithHooks(current, workInProgress, Component, props, secondArg, nextRenderExpirationTime) {
  12363. renderExpirationTime = nextRenderExpirationTime;
  12364. currentlyRenderingFiber$1 = workInProgress;
  12365. {
  12366. hookTypesDev = current !== null ? current._debugHookTypes : null;
  12367. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  12368. ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
  12369. }
  12370. workInProgress.memoizedState = null;
  12371. workInProgress.updateQueue = null;
  12372. workInProgress.expirationTime = NoWork; // The following should have already been reset
  12373. // currentHook = null;
  12374. // workInProgressHook = null;
  12375. // didScheduleRenderPhaseUpdate = false;
  12376. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  12377. // Currently we will identify the update render as a mount because memoizedState === null.
  12378. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  12379. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  12380. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  12381. // so memoizedState would be null during updates and mounts.
  12382. {
  12383. if (current !== null && current.memoizedState !== null) {
  12384. ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
  12385. } else if (hookTypesDev !== null) {
  12386. // This dispatcher handles an edge case where a component is updating,
  12387. // but no stateful hooks have been used.
  12388. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  12389. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  12390. // This dispatcher does that.
  12391. ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
  12392. } else {
  12393. ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
  12394. }
  12395. }
  12396. var children = Component(props, secondArg); // Check if there was a render phase update
  12397. if (workInProgress.expirationTime === renderExpirationTime) {
  12398. // Keep rendering in a loop for as long as render phase updates continue to
  12399. // be scheduled. Use a counter to prevent infinite loops.
  12400. var numberOfReRenders = 0;
  12401. do {
  12402. workInProgress.expirationTime = NoWork;
  12403. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  12404. {
  12405. throw Error( "Too many re-renders. React limits the number of renders to prevent an infinite loop." );
  12406. }
  12407. }
  12408. numberOfReRenders += 1;
  12409. {
  12410. // Even when hot reloading, allow dependencies to stabilize
  12411. // after first render to prevent infinite render phase updates.
  12412. ignorePreviousDependencies = false;
  12413. } // Start over from the beginning of the list
  12414. currentHook = null;
  12415. workInProgressHook = null;
  12416. workInProgress.updateQueue = null;
  12417. {
  12418. // Also validate hook order for cascading updates.
  12419. hookTypesUpdateIndexDev = -1;
  12420. }
  12421. ReactCurrentDispatcher.current = HooksDispatcherOnRerenderInDEV ;
  12422. children = Component(props, secondArg);
  12423. } while (workInProgress.expirationTime === renderExpirationTime);
  12424. } // We can assume the previous dispatcher is always this one, since we set it
  12425. // at the beginning of the render phase and there's no re-entrancy.
  12426. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  12427. {
  12428. workInProgress._debugHookTypes = hookTypesDev;
  12429. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  12430. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  12431. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  12432. renderExpirationTime = NoWork;
  12433. currentlyRenderingFiber$1 = null;
  12434. currentHook = null;
  12435. workInProgressHook = null;
  12436. {
  12437. currentHookNameInDev = null;
  12438. hookTypesDev = null;
  12439. hookTypesUpdateIndexDev = -1;
  12440. }
  12441. didScheduleRenderPhaseUpdate = false;
  12442. if (!!didRenderTooFewHooks) {
  12443. {
  12444. throw Error( "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." );
  12445. }
  12446. }
  12447. return children;
  12448. }
  12449. function bailoutHooks(current, workInProgress, expirationTime) {
  12450. workInProgress.updateQueue = current.updateQueue;
  12451. workInProgress.effectTag &= ~(Passive | Update);
  12452. if (current.expirationTime <= expirationTime) {
  12453. current.expirationTime = NoWork;
  12454. }
  12455. }
  12456. function resetHooksAfterThrow() {
  12457. // We can assume the previous dispatcher is always this one, since we set it
  12458. // at the beginning of the render phase and there's no re-entrancy.
  12459. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  12460. if (didScheduleRenderPhaseUpdate) {
  12461. // There were render phase updates. These are only valid for this render
  12462. // phase, which we are now aborting. Remove the updates from the queues so
  12463. // they do not persist to the next render. Do not remove updates from hooks
  12464. // that weren't processed.
  12465. //
  12466. // Only reset the updates from the queue if it has a clone. If it does
  12467. // not have a clone, that means it wasn't processed, and the updates were
  12468. // scheduled before we entered the render phase.
  12469. var hook = currentlyRenderingFiber$1.memoizedState;
  12470. while (hook !== null) {
  12471. var queue = hook.queue;
  12472. if (queue !== null) {
  12473. queue.pending = null;
  12474. }
  12475. hook = hook.next;
  12476. }
  12477. }
  12478. renderExpirationTime = NoWork;
  12479. currentlyRenderingFiber$1 = null;
  12480. currentHook = null;
  12481. workInProgressHook = null;
  12482. {
  12483. hookTypesDev = null;
  12484. hookTypesUpdateIndexDev = -1;
  12485. currentHookNameInDev = null;
  12486. }
  12487. didScheduleRenderPhaseUpdate = false;
  12488. }
  12489. function mountWorkInProgressHook() {
  12490. var hook = {
  12491. memoizedState: null,
  12492. baseState: null,
  12493. baseQueue: null,
  12494. queue: null,
  12495. next: null
  12496. };
  12497. if (workInProgressHook === null) {
  12498. // This is the first hook in the list
  12499. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  12500. } else {
  12501. // Append to the end of the list
  12502. workInProgressHook = workInProgressHook.next = hook;
  12503. }
  12504. return workInProgressHook;
  12505. }
  12506. function updateWorkInProgressHook() {
  12507. // This function is used both for updates and for re-renders triggered by a
  12508. // render phase update. It assumes there is either a current hook we can
  12509. // clone, or a work-in-progress hook from a previous render pass that we can
  12510. // use as a base. When we reach the end of the base list, we must switch to
  12511. // the dispatcher used for mounts.
  12512. var nextCurrentHook;
  12513. if (currentHook === null) {
  12514. var current = currentlyRenderingFiber$1.alternate;
  12515. if (current !== null) {
  12516. nextCurrentHook = current.memoizedState;
  12517. } else {
  12518. nextCurrentHook = null;
  12519. }
  12520. } else {
  12521. nextCurrentHook = currentHook.next;
  12522. }
  12523. var nextWorkInProgressHook;
  12524. if (workInProgressHook === null) {
  12525. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  12526. } else {
  12527. nextWorkInProgressHook = workInProgressHook.next;
  12528. }
  12529. if (nextWorkInProgressHook !== null) {
  12530. // There's already a work-in-progress. Reuse it.
  12531. workInProgressHook = nextWorkInProgressHook;
  12532. nextWorkInProgressHook = workInProgressHook.next;
  12533. currentHook = nextCurrentHook;
  12534. } else {
  12535. // Clone from the current hook.
  12536. if (!(nextCurrentHook !== null)) {
  12537. {
  12538. throw Error( "Rendered more hooks than during the previous render." );
  12539. }
  12540. }
  12541. currentHook = nextCurrentHook;
  12542. var newHook = {
  12543. memoizedState: currentHook.memoizedState,
  12544. baseState: currentHook.baseState,
  12545. baseQueue: currentHook.baseQueue,
  12546. queue: currentHook.queue,
  12547. next: null
  12548. };
  12549. if (workInProgressHook === null) {
  12550. // This is the first hook in the list.
  12551. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  12552. } else {
  12553. // Append to the end of the list.
  12554. workInProgressHook = workInProgressHook.next = newHook;
  12555. }
  12556. }
  12557. return workInProgressHook;
  12558. }
  12559. function createFunctionComponentUpdateQueue() {
  12560. return {
  12561. lastEffect: null
  12562. };
  12563. }
  12564. function basicStateReducer(state, action) {
  12565. // $FlowFixMe: Flow doesn't like mixed types
  12566. return typeof action === 'function' ? action(state) : action;
  12567. }
  12568. function mountReducer(reducer, initialArg, init) {
  12569. var hook = mountWorkInProgressHook();
  12570. var initialState;
  12571. if (init !== undefined) {
  12572. initialState = init(initialArg);
  12573. } else {
  12574. initialState = initialArg;
  12575. }
  12576. hook.memoizedState = hook.baseState = initialState;
  12577. var queue = hook.queue = {
  12578. pending: null,
  12579. dispatch: null,
  12580. lastRenderedReducer: reducer,
  12581. lastRenderedState: initialState
  12582. };
  12583. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  12584. return [hook.memoizedState, dispatch];
  12585. }
  12586. function updateReducer(reducer, initialArg, init) {
  12587. var hook = updateWorkInProgressHook();
  12588. var queue = hook.queue;
  12589. if (!(queue !== null)) {
  12590. {
  12591. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  12592. }
  12593. }
  12594. queue.lastRenderedReducer = reducer;
  12595. var current = currentHook; // The last rebase update that is NOT part of the base state.
  12596. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  12597. var pendingQueue = queue.pending;
  12598. if (pendingQueue !== null) {
  12599. // We have new updates that haven't been processed yet.
  12600. // We'll add them to the base queue.
  12601. if (baseQueue !== null) {
  12602. // Merge the pending queue and the base queue.
  12603. var baseFirst = baseQueue.next;
  12604. var pendingFirst = pendingQueue.next;
  12605. baseQueue.next = pendingFirst;
  12606. pendingQueue.next = baseFirst;
  12607. }
  12608. current.baseQueue = baseQueue = pendingQueue;
  12609. queue.pending = null;
  12610. }
  12611. if (baseQueue !== null) {
  12612. // We have a queue to process.
  12613. var first = baseQueue.next;
  12614. var newState = current.baseState;
  12615. var newBaseState = null;
  12616. var newBaseQueueFirst = null;
  12617. var newBaseQueueLast = null;
  12618. var update = first;
  12619. do {
  12620. var updateExpirationTime = update.expirationTime;
  12621. if (updateExpirationTime < renderExpirationTime) {
  12622. // Priority is insufficient. Skip this update. If this is the first
  12623. // skipped update, the previous update/state is the new base
  12624. // update/state.
  12625. var clone = {
  12626. expirationTime: update.expirationTime,
  12627. suspenseConfig: update.suspenseConfig,
  12628. action: update.action,
  12629. eagerReducer: update.eagerReducer,
  12630. eagerState: update.eagerState,
  12631. next: null
  12632. };
  12633. if (newBaseQueueLast === null) {
  12634. newBaseQueueFirst = newBaseQueueLast = clone;
  12635. newBaseState = newState;
  12636. } else {
  12637. newBaseQueueLast = newBaseQueueLast.next = clone;
  12638. } // Update the remaining priority in the queue.
  12639. if (updateExpirationTime > currentlyRenderingFiber$1.expirationTime) {
  12640. currentlyRenderingFiber$1.expirationTime = updateExpirationTime;
  12641. markUnprocessedUpdateTime(updateExpirationTime);
  12642. }
  12643. } else {
  12644. // This update does have sufficient priority.
  12645. if (newBaseQueueLast !== null) {
  12646. var _clone = {
  12647. expirationTime: Sync,
  12648. // This update is going to be committed so we never want uncommit it.
  12649. suspenseConfig: update.suspenseConfig,
  12650. action: update.action,
  12651. eagerReducer: update.eagerReducer,
  12652. eagerState: update.eagerState,
  12653. next: null
  12654. };
  12655. newBaseQueueLast = newBaseQueueLast.next = _clone;
  12656. } // Mark the event time of this update as relevant to this render pass.
  12657. // TODO: This should ideally use the true event time of this update rather than
  12658. // its priority which is a derived and not reverseable value.
  12659. // TODO: We should skip this update if it was already committed but currently
  12660. // we have no way of detecting the difference between a committed and suspended
  12661. // update here.
  12662. markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process this update.
  12663. if (update.eagerReducer === reducer) {
  12664. // If this update was processed eagerly, and its reducer matches the
  12665. // current reducer, we can use the eagerly computed state.
  12666. newState = update.eagerState;
  12667. } else {
  12668. var action = update.action;
  12669. newState = reducer(newState, action);
  12670. }
  12671. }
  12672. update = update.next;
  12673. } while (update !== null && update !== first);
  12674. if (newBaseQueueLast === null) {
  12675. newBaseState = newState;
  12676. } else {
  12677. newBaseQueueLast.next = newBaseQueueFirst;
  12678. } // Mark that the fiber performed work, but only if the new state is
  12679. // different from the current state.
  12680. if (!objectIs(newState, hook.memoizedState)) {
  12681. markWorkInProgressReceivedUpdate();
  12682. }
  12683. hook.memoizedState = newState;
  12684. hook.baseState = newBaseState;
  12685. hook.baseQueue = newBaseQueueLast;
  12686. queue.lastRenderedState = newState;
  12687. }
  12688. var dispatch = queue.dispatch;
  12689. return [hook.memoizedState, dispatch];
  12690. }
  12691. function rerenderReducer(reducer, initialArg, init) {
  12692. var hook = updateWorkInProgressHook();
  12693. var queue = hook.queue;
  12694. if (!(queue !== null)) {
  12695. {
  12696. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  12697. }
  12698. }
  12699. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  12700. // work-in-progress hook.
  12701. var dispatch = queue.dispatch;
  12702. var lastRenderPhaseUpdate = queue.pending;
  12703. var newState = hook.memoizedState;
  12704. if (lastRenderPhaseUpdate !== null) {
  12705. // The queue doesn't persist past this render pass.
  12706. queue.pending = null;
  12707. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  12708. var update = firstRenderPhaseUpdate;
  12709. do {
  12710. // Process this render phase update. We don't have to check the
  12711. // priority because it will always be the same as the current
  12712. // render's.
  12713. var action = update.action;
  12714. newState = reducer(newState, action);
  12715. update = update.next;
  12716. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  12717. // different from the current state.
  12718. if (!objectIs(newState, hook.memoizedState)) {
  12719. markWorkInProgressReceivedUpdate();
  12720. }
  12721. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  12722. // the base state unless the queue is empty.
  12723. // TODO: Not sure if this is the desired semantics, but it's what we
  12724. // do for gDSFP. I can't remember why.
  12725. if (hook.baseQueue === null) {
  12726. hook.baseState = newState;
  12727. }
  12728. queue.lastRenderedState = newState;
  12729. }
  12730. return [newState, dispatch];
  12731. }
  12732. function mountState(initialState) {
  12733. var hook = mountWorkInProgressHook();
  12734. if (typeof initialState === 'function') {
  12735. // $FlowFixMe: Flow doesn't like mixed types
  12736. initialState = initialState();
  12737. }
  12738. hook.memoizedState = hook.baseState = initialState;
  12739. var queue = hook.queue = {
  12740. pending: null,
  12741. dispatch: null,
  12742. lastRenderedReducer: basicStateReducer,
  12743. lastRenderedState: initialState
  12744. };
  12745. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  12746. return [hook.memoizedState, dispatch];
  12747. }
  12748. function updateState(initialState) {
  12749. return updateReducer(basicStateReducer);
  12750. }
  12751. function rerenderState(initialState) {
  12752. return rerenderReducer(basicStateReducer);
  12753. }
  12754. function pushEffect(tag, create, destroy, deps) {
  12755. var effect = {
  12756. tag: tag,
  12757. create: create,
  12758. destroy: destroy,
  12759. deps: deps,
  12760. // Circular
  12761. next: null
  12762. };
  12763. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  12764. if (componentUpdateQueue === null) {
  12765. componentUpdateQueue = createFunctionComponentUpdateQueue();
  12766. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  12767. componentUpdateQueue.lastEffect = effect.next = effect;
  12768. } else {
  12769. var lastEffect = componentUpdateQueue.lastEffect;
  12770. if (lastEffect === null) {
  12771. componentUpdateQueue.lastEffect = effect.next = effect;
  12772. } else {
  12773. var firstEffect = lastEffect.next;
  12774. lastEffect.next = effect;
  12775. effect.next = firstEffect;
  12776. componentUpdateQueue.lastEffect = effect;
  12777. }
  12778. }
  12779. return effect;
  12780. }
  12781. function mountRef(initialValue) {
  12782. var hook = mountWorkInProgressHook();
  12783. var ref = {
  12784. current: initialValue
  12785. };
  12786. {
  12787. Object.seal(ref);
  12788. }
  12789. hook.memoizedState = ref;
  12790. return ref;
  12791. }
  12792. function updateRef(initialValue) {
  12793. var hook = updateWorkInProgressHook();
  12794. return hook.memoizedState;
  12795. }
  12796. function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  12797. var hook = mountWorkInProgressHook();
  12798. var nextDeps = deps === undefined ? null : deps;
  12799. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  12800. hook.memoizedState = pushEffect(HasEffect | hookEffectTag, create, undefined, nextDeps);
  12801. }
  12802. function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  12803. var hook = updateWorkInProgressHook();
  12804. var nextDeps = deps === undefined ? null : deps;
  12805. var destroy = undefined;
  12806. if (currentHook !== null) {
  12807. var prevEffect = currentHook.memoizedState;
  12808. destroy = prevEffect.destroy;
  12809. if (nextDeps !== null) {
  12810. var prevDeps = prevEffect.deps;
  12811. if (areHookInputsEqual(nextDeps, prevDeps)) {
  12812. pushEffect(hookEffectTag, create, destroy, nextDeps);
  12813. return;
  12814. }
  12815. }
  12816. }
  12817. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  12818. hook.memoizedState = pushEffect(HasEffect | hookEffectTag, create, destroy, nextDeps);
  12819. }
  12820. function mountEffect(create, deps) {
  12821. {
  12822. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  12823. if ('undefined' !== typeof jest) {
  12824. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  12825. }
  12826. }
  12827. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  12828. }
  12829. function updateEffect(create, deps) {
  12830. {
  12831. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  12832. if ('undefined' !== typeof jest) {
  12833. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  12834. }
  12835. }
  12836. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  12837. }
  12838. function mountLayoutEffect(create, deps) {
  12839. return mountEffectImpl(Update, Layout, create, deps);
  12840. }
  12841. function updateLayoutEffect(create, deps) {
  12842. return updateEffectImpl(Update, Layout, create, deps);
  12843. }
  12844. function imperativeHandleEffect(create, ref) {
  12845. if (typeof ref === 'function') {
  12846. var refCallback = ref;
  12847. var _inst = create();
  12848. refCallback(_inst);
  12849. return function () {
  12850. refCallback(null);
  12851. };
  12852. } else if (ref !== null && ref !== undefined) {
  12853. var refObject = ref;
  12854. {
  12855. if (!refObject.hasOwnProperty('current')) {
  12856. error('Expected useImperativeHandle() first argument to either be a ' + 'ref callback or React.createRef() object. Instead received: %s.', 'an object with keys {' + Object.keys(refObject).join(', ') + '}');
  12857. }
  12858. }
  12859. var _inst2 = create();
  12860. refObject.current = _inst2;
  12861. return function () {
  12862. refObject.current = null;
  12863. };
  12864. }
  12865. }
  12866. function mountImperativeHandle(ref, create, deps) {
  12867. {
  12868. if (typeof create !== 'function') {
  12869. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  12870. }
  12871. } // TODO: If deps are provided, should we skip comparing the ref itself?
  12872. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  12873. return mountEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  12874. }
  12875. function updateImperativeHandle(ref, create, deps) {
  12876. {
  12877. if (typeof create !== 'function') {
  12878. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  12879. }
  12880. } // TODO: If deps are provided, should we skip comparing the ref itself?
  12881. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  12882. return updateEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  12883. }
  12884. function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
  12885. // The react-debug-hooks package injects its own implementation
  12886. // so that e.g. DevTools can display custom hook values.
  12887. }
  12888. var updateDebugValue = mountDebugValue;
  12889. function mountCallback(callback, deps) {
  12890. var hook = mountWorkInProgressHook();
  12891. var nextDeps = deps === undefined ? null : deps;
  12892. hook.memoizedState = [callback, nextDeps];
  12893. return callback;
  12894. }
  12895. function updateCallback(callback, deps) {
  12896. var hook = updateWorkInProgressHook();
  12897. var nextDeps = deps === undefined ? null : deps;
  12898. var prevState = hook.memoizedState;
  12899. if (prevState !== null) {
  12900. if (nextDeps !== null) {
  12901. var prevDeps = prevState[1];
  12902. if (areHookInputsEqual(nextDeps, prevDeps)) {
  12903. return prevState[0];
  12904. }
  12905. }
  12906. }
  12907. hook.memoizedState = [callback, nextDeps];
  12908. return callback;
  12909. }
  12910. function mountMemo(nextCreate, deps) {
  12911. var hook = mountWorkInProgressHook();
  12912. var nextDeps = deps === undefined ? null : deps;
  12913. var nextValue = nextCreate();
  12914. hook.memoizedState = [nextValue, nextDeps];
  12915. return nextValue;
  12916. }
  12917. function updateMemo(nextCreate, deps) {
  12918. var hook = updateWorkInProgressHook();
  12919. var nextDeps = deps === undefined ? null : deps;
  12920. var prevState = hook.memoizedState;
  12921. if (prevState !== null) {
  12922. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  12923. if (nextDeps !== null) {
  12924. var prevDeps = prevState[1];
  12925. if (areHookInputsEqual(nextDeps, prevDeps)) {
  12926. return prevState[0];
  12927. }
  12928. }
  12929. }
  12930. var nextValue = nextCreate();
  12931. hook.memoizedState = [nextValue, nextDeps];
  12932. return nextValue;
  12933. }
  12934. function mountDeferredValue(value, config) {
  12935. var _mountState = mountState(value),
  12936. prevValue = _mountState[0],
  12937. setValue = _mountState[1];
  12938. mountEffect(function () {
  12939. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  12940. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  12941. try {
  12942. setValue(value);
  12943. } finally {
  12944. ReactCurrentBatchConfig$1.suspense = previousConfig;
  12945. }
  12946. }, [value, config]);
  12947. return prevValue;
  12948. }
  12949. function updateDeferredValue(value, config) {
  12950. var _updateState = updateState(),
  12951. prevValue = _updateState[0],
  12952. setValue = _updateState[1];
  12953. updateEffect(function () {
  12954. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  12955. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  12956. try {
  12957. setValue(value);
  12958. } finally {
  12959. ReactCurrentBatchConfig$1.suspense = previousConfig;
  12960. }
  12961. }, [value, config]);
  12962. return prevValue;
  12963. }
  12964. function rerenderDeferredValue(value, config) {
  12965. var _rerenderState = rerenderState(),
  12966. prevValue = _rerenderState[0],
  12967. setValue = _rerenderState[1];
  12968. updateEffect(function () {
  12969. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  12970. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  12971. try {
  12972. setValue(value);
  12973. } finally {
  12974. ReactCurrentBatchConfig$1.suspense = previousConfig;
  12975. }
  12976. }, [value, config]);
  12977. return prevValue;
  12978. }
  12979. function startTransition(setPending, config, callback) {
  12980. var priorityLevel = getCurrentPriorityLevel();
  12981. runWithPriority$1(priorityLevel < UserBlockingPriority$1 ? UserBlockingPriority$1 : priorityLevel, function () {
  12982. setPending(true);
  12983. });
  12984. runWithPriority$1(priorityLevel > NormalPriority ? NormalPriority : priorityLevel, function () {
  12985. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  12986. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  12987. try {
  12988. setPending(false);
  12989. callback();
  12990. } finally {
  12991. ReactCurrentBatchConfig$1.suspense = previousConfig;
  12992. }
  12993. });
  12994. }
  12995. function mountTransition(config) {
  12996. var _mountState2 = mountState(false),
  12997. isPending = _mountState2[0],
  12998. setPending = _mountState2[1];
  12999. var start = mountCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  13000. return [start, isPending];
  13001. }
  13002. function updateTransition(config) {
  13003. var _updateState2 = updateState(),
  13004. isPending = _updateState2[0],
  13005. setPending = _updateState2[1];
  13006. var start = updateCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  13007. return [start, isPending];
  13008. }
  13009. function rerenderTransition(config) {
  13010. var _rerenderState2 = rerenderState(),
  13011. isPending = _rerenderState2[0],
  13012. setPending = _rerenderState2[1];
  13013. var start = updateCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  13014. return [start, isPending];
  13015. }
  13016. function dispatchAction(fiber, queue, action) {
  13017. {
  13018. if (typeof arguments[3] === 'function') {
  13019. error("State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + 'rendering, declare it in the component body with useEffect().');
  13020. }
  13021. }
  13022. var currentTime = requestCurrentTimeForUpdate();
  13023. var suspenseConfig = requestCurrentSuspenseConfig();
  13024. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  13025. var update = {
  13026. expirationTime: expirationTime,
  13027. suspenseConfig: suspenseConfig,
  13028. action: action,
  13029. eagerReducer: null,
  13030. eagerState: null,
  13031. next: null
  13032. };
  13033. {
  13034. update.priority = getCurrentPriorityLevel();
  13035. } // Append the update to the end of the list.
  13036. var pending = queue.pending;
  13037. if (pending === null) {
  13038. // This is the first update. Create a circular list.
  13039. update.next = update;
  13040. } else {
  13041. update.next = pending.next;
  13042. pending.next = update;
  13043. }
  13044. queue.pending = update;
  13045. var alternate = fiber.alternate;
  13046. if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
  13047. // This is a render phase update. Stash it in a lazily-created map of
  13048. // queue -> linked list of updates. After this render pass, we'll restart
  13049. // and apply the stashed updates on top of the work-in-progress hook.
  13050. didScheduleRenderPhaseUpdate = true;
  13051. update.expirationTime = renderExpirationTime;
  13052. currentlyRenderingFiber$1.expirationTime = renderExpirationTime;
  13053. } else {
  13054. if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
  13055. // The queue is currently empty, which means we can eagerly compute the
  13056. // next state before entering the render phase. If the new state is the
  13057. // same as the current state, we may be able to bail out entirely.
  13058. var lastRenderedReducer = queue.lastRenderedReducer;
  13059. if (lastRenderedReducer !== null) {
  13060. var prevDispatcher;
  13061. {
  13062. prevDispatcher = ReactCurrentDispatcher.current;
  13063. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13064. }
  13065. try {
  13066. var currentState = queue.lastRenderedState;
  13067. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  13068. // it, on the update object. If the reducer hasn't changed by the
  13069. // time we enter the render phase, then the eager state can be used
  13070. // without calling the reducer again.
  13071. update.eagerReducer = lastRenderedReducer;
  13072. update.eagerState = eagerState;
  13073. if (objectIs(eagerState, currentState)) {
  13074. // Fast path. We can bail out without scheduling React to re-render.
  13075. // It's still possible that we'll need to rebase this update later,
  13076. // if the component re-renders for a different reason and by that
  13077. // time the reducer has changed.
  13078. return;
  13079. }
  13080. } catch (error) {// Suppress the error. It will throw again in the render phase.
  13081. } finally {
  13082. {
  13083. ReactCurrentDispatcher.current = prevDispatcher;
  13084. }
  13085. }
  13086. }
  13087. }
  13088. {
  13089. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  13090. if ('undefined' !== typeof jest) {
  13091. warnIfNotScopedWithMatchingAct(fiber);
  13092. warnIfNotCurrentlyActingUpdatesInDev(fiber);
  13093. }
  13094. }
  13095. scheduleWork(fiber, expirationTime);
  13096. }
  13097. }
  13098. var ContextOnlyDispatcher = {
  13099. readContext: readContext,
  13100. useCallback: throwInvalidHookError,
  13101. useContext: throwInvalidHookError,
  13102. useEffect: throwInvalidHookError,
  13103. useImperativeHandle: throwInvalidHookError,
  13104. useLayoutEffect: throwInvalidHookError,
  13105. useMemo: throwInvalidHookError,
  13106. useReducer: throwInvalidHookError,
  13107. useRef: throwInvalidHookError,
  13108. useState: throwInvalidHookError,
  13109. useDebugValue: throwInvalidHookError,
  13110. useResponder: throwInvalidHookError,
  13111. useDeferredValue: throwInvalidHookError,
  13112. useTransition: throwInvalidHookError
  13113. };
  13114. var HooksDispatcherOnMountInDEV = null;
  13115. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  13116. var HooksDispatcherOnUpdateInDEV = null;
  13117. var HooksDispatcherOnRerenderInDEV = null;
  13118. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  13119. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  13120. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  13121. {
  13122. var warnInvalidContextAccess = function () {
  13123. error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
  13124. };
  13125. var warnInvalidHookAccess = function () {
  13126. error('Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. ' + 'You can only call Hooks at the top level of your React function. ' + 'For more information, see ' + 'https://fb.me/rules-of-hooks');
  13127. };
  13128. HooksDispatcherOnMountInDEV = {
  13129. readContext: function (context, observedBits) {
  13130. return readContext(context, observedBits);
  13131. },
  13132. useCallback: function (callback, deps) {
  13133. currentHookNameInDev = 'useCallback';
  13134. mountHookTypesDev();
  13135. checkDepsAreArrayDev(deps);
  13136. return mountCallback(callback, deps);
  13137. },
  13138. useContext: function (context, observedBits) {
  13139. currentHookNameInDev = 'useContext';
  13140. mountHookTypesDev();
  13141. return readContext(context, observedBits);
  13142. },
  13143. useEffect: function (create, deps) {
  13144. currentHookNameInDev = 'useEffect';
  13145. mountHookTypesDev();
  13146. checkDepsAreArrayDev(deps);
  13147. return mountEffect(create, deps);
  13148. },
  13149. useImperativeHandle: function (ref, create, deps) {
  13150. currentHookNameInDev = 'useImperativeHandle';
  13151. mountHookTypesDev();
  13152. checkDepsAreArrayDev(deps);
  13153. return mountImperativeHandle(ref, create, deps);
  13154. },
  13155. useLayoutEffect: function (create, deps) {
  13156. currentHookNameInDev = 'useLayoutEffect';
  13157. mountHookTypesDev();
  13158. checkDepsAreArrayDev(deps);
  13159. return mountLayoutEffect(create, deps);
  13160. },
  13161. useMemo: function (create, deps) {
  13162. currentHookNameInDev = 'useMemo';
  13163. mountHookTypesDev();
  13164. checkDepsAreArrayDev(deps);
  13165. var prevDispatcher = ReactCurrentDispatcher.current;
  13166. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13167. try {
  13168. return mountMemo(create, deps);
  13169. } finally {
  13170. ReactCurrentDispatcher.current = prevDispatcher;
  13171. }
  13172. },
  13173. useReducer: function (reducer, initialArg, init) {
  13174. currentHookNameInDev = 'useReducer';
  13175. mountHookTypesDev();
  13176. var prevDispatcher = ReactCurrentDispatcher.current;
  13177. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13178. try {
  13179. return mountReducer(reducer, initialArg, init);
  13180. } finally {
  13181. ReactCurrentDispatcher.current = prevDispatcher;
  13182. }
  13183. },
  13184. useRef: function (initialValue) {
  13185. currentHookNameInDev = 'useRef';
  13186. mountHookTypesDev();
  13187. return mountRef(initialValue);
  13188. },
  13189. useState: function (initialState) {
  13190. currentHookNameInDev = 'useState';
  13191. mountHookTypesDev();
  13192. var prevDispatcher = ReactCurrentDispatcher.current;
  13193. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13194. try {
  13195. return mountState(initialState);
  13196. } finally {
  13197. ReactCurrentDispatcher.current = prevDispatcher;
  13198. }
  13199. },
  13200. useDebugValue: function (value, formatterFn) {
  13201. currentHookNameInDev = 'useDebugValue';
  13202. mountHookTypesDev();
  13203. return mountDebugValue();
  13204. },
  13205. useResponder: function (responder, props) {
  13206. currentHookNameInDev = 'useResponder';
  13207. mountHookTypesDev();
  13208. return createDeprecatedResponderListener(responder, props);
  13209. },
  13210. useDeferredValue: function (value, config) {
  13211. currentHookNameInDev = 'useDeferredValue';
  13212. mountHookTypesDev();
  13213. return mountDeferredValue(value, config);
  13214. },
  13215. useTransition: function (config) {
  13216. currentHookNameInDev = 'useTransition';
  13217. mountHookTypesDev();
  13218. return mountTransition(config);
  13219. }
  13220. };
  13221. HooksDispatcherOnMountWithHookTypesInDEV = {
  13222. readContext: function (context, observedBits) {
  13223. return readContext(context, observedBits);
  13224. },
  13225. useCallback: function (callback, deps) {
  13226. currentHookNameInDev = 'useCallback';
  13227. updateHookTypesDev();
  13228. return mountCallback(callback, deps);
  13229. },
  13230. useContext: function (context, observedBits) {
  13231. currentHookNameInDev = 'useContext';
  13232. updateHookTypesDev();
  13233. return readContext(context, observedBits);
  13234. },
  13235. useEffect: function (create, deps) {
  13236. currentHookNameInDev = 'useEffect';
  13237. updateHookTypesDev();
  13238. return mountEffect(create, deps);
  13239. },
  13240. useImperativeHandle: function (ref, create, deps) {
  13241. currentHookNameInDev = 'useImperativeHandle';
  13242. updateHookTypesDev();
  13243. return mountImperativeHandle(ref, create, deps);
  13244. },
  13245. useLayoutEffect: function (create, deps) {
  13246. currentHookNameInDev = 'useLayoutEffect';
  13247. updateHookTypesDev();
  13248. return mountLayoutEffect(create, deps);
  13249. },
  13250. useMemo: function (create, deps) {
  13251. currentHookNameInDev = 'useMemo';
  13252. updateHookTypesDev();
  13253. var prevDispatcher = ReactCurrentDispatcher.current;
  13254. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13255. try {
  13256. return mountMemo(create, deps);
  13257. } finally {
  13258. ReactCurrentDispatcher.current = prevDispatcher;
  13259. }
  13260. },
  13261. useReducer: function (reducer, initialArg, init) {
  13262. currentHookNameInDev = 'useReducer';
  13263. updateHookTypesDev();
  13264. var prevDispatcher = ReactCurrentDispatcher.current;
  13265. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13266. try {
  13267. return mountReducer(reducer, initialArg, init);
  13268. } finally {
  13269. ReactCurrentDispatcher.current = prevDispatcher;
  13270. }
  13271. },
  13272. useRef: function (initialValue) {
  13273. currentHookNameInDev = 'useRef';
  13274. updateHookTypesDev();
  13275. return mountRef(initialValue);
  13276. },
  13277. useState: function (initialState) {
  13278. currentHookNameInDev = 'useState';
  13279. updateHookTypesDev();
  13280. var prevDispatcher = ReactCurrentDispatcher.current;
  13281. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13282. try {
  13283. return mountState(initialState);
  13284. } finally {
  13285. ReactCurrentDispatcher.current = prevDispatcher;
  13286. }
  13287. },
  13288. useDebugValue: function (value, formatterFn) {
  13289. currentHookNameInDev = 'useDebugValue';
  13290. updateHookTypesDev();
  13291. return mountDebugValue();
  13292. },
  13293. useResponder: function (responder, props) {
  13294. currentHookNameInDev = 'useResponder';
  13295. updateHookTypesDev();
  13296. return createDeprecatedResponderListener(responder, props);
  13297. },
  13298. useDeferredValue: function (value, config) {
  13299. currentHookNameInDev = 'useDeferredValue';
  13300. updateHookTypesDev();
  13301. return mountDeferredValue(value, config);
  13302. },
  13303. useTransition: function (config) {
  13304. currentHookNameInDev = 'useTransition';
  13305. updateHookTypesDev();
  13306. return mountTransition(config);
  13307. }
  13308. };
  13309. HooksDispatcherOnUpdateInDEV = {
  13310. readContext: function (context, observedBits) {
  13311. return readContext(context, observedBits);
  13312. },
  13313. useCallback: function (callback, deps) {
  13314. currentHookNameInDev = 'useCallback';
  13315. updateHookTypesDev();
  13316. return updateCallback(callback, deps);
  13317. },
  13318. useContext: function (context, observedBits) {
  13319. currentHookNameInDev = 'useContext';
  13320. updateHookTypesDev();
  13321. return readContext(context, observedBits);
  13322. },
  13323. useEffect: function (create, deps) {
  13324. currentHookNameInDev = 'useEffect';
  13325. updateHookTypesDev();
  13326. return updateEffect(create, deps);
  13327. },
  13328. useImperativeHandle: function (ref, create, deps) {
  13329. currentHookNameInDev = 'useImperativeHandle';
  13330. updateHookTypesDev();
  13331. return updateImperativeHandle(ref, create, deps);
  13332. },
  13333. useLayoutEffect: function (create, deps) {
  13334. currentHookNameInDev = 'useLayoutEffect';
  13335. updateHookTypesDev();
  13336. return updateLayoutEffect(create, deps);
  13337. },
  13338. useMemo: function (create, deps) {
  13339. currentHookNameInDev = 'useMemo';
  13340. updateHookTypesDev();
  13341. var prevDispatcher = ReactCurrentDispatcher.current;
  13342. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13343. try {
  13344. return updateMemo(create, deps);
  13345. } finally {
  13346. ReactCurrentDispatcher.current = prevDispatcher;
  13347. }
  13348. },
  13349. useReducer: function (reducer, initialArg, init) {
  13350. currentHookNameInDev = 'useReducer';
  13351. updateHookTypesDev();
  13352. var prevDispatcher = ReactCurrentDispatcher.current;
  13353. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13354. try {
  13355. return updateReducer(reducer, initialArg, init);
  13356. } finally {
  13357. ReactCurrentDispatcher.current = prevDispatcher;
  13358. }
  13359. },
  13360. useRef: function (initialValue) {
  13361. currentHookNameInDev = 'useRef';
  13362. updateHookTypesDev();
  13363. return updateRef();
  13364. },
  13365. useState: function (initialState) {
  13366. currentHookNameInDev = 'useState';
  13367. updateHookTypesDev();
  13368. var prevDispatcher = ReactCurrentDispatcher.current;
  13369. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13370. try {
  13371. return updateState(initialState);
  13372. } finally {
  13373. ReactCurrentDispatcher.current = prevDispatcher;
  13374. }
  13375. },
  13376. useDebugValue: function (value, formatterFn) {
  13377. currentHookNameInDev = 'useDebugValue';
  13378. updateHookTypesDev();
  13379. return updateDebugValue();
  13380. },
  13381. useResponder: function (responder, props) {
  13382. currentHookNameInDev = 'useResponder';
  13383. updateHookTypesDev();
  13384. return createDeprecatedResponderListener(responder, props);
  13385. },
  13386. useDeferredValue: function (value, config) {
  13387. currentHookNameInDev = 'useDeferredValue';
  13388. updateHookTypesDev();
  13389. return updateDeferredValue(value, config);
  13390. },
  13391. useTransition: function (config) {
  13392. currentHookNameInDev = 'useTransition';
  13393. updateHookTypesDev();
  13394. return updateTransition(config);
  13395. }
  13396. };
  13397. HooksDispatcherOnRerenderInDEV = {
  13398. readContext: function (context, observedBits) {
  13399. return readContext(context, observedBits);
  13400. },
  13401. useCallback: function (callback, deps) {
  13402. currentHookNameInDev = 'useCallback';
  13403. updateHookTypesDev();
  13404. return updateCallback(callback, deps);
  13405. },
  13406. useContext: function (context, observedBits) {
  13407. currentHookNameInDev = 'useContext';
  13408. updateHookTypesDev();
  13409. return readContext(context, observedBits);
  13410. },
  13411. useEffect: function (create, deps) {
  13412. currentHookNameInDev = 'useEffect';
  13413. updateHookTypesDev();
  13414. return updateEffect(create, deps);
  13415. },
  13416. useImperativeHandle: function (ref, create, deps) {
  13417. currentHookNameInDev = 'useImperativeHandle';
  13418. updateHookTypesDev();
  13419. return updateImperativeHandle(ref, create, deps);
  13420. },
  13421. useLayoutEffect: function (create, deps) {
  13422. currentHookNameInDev = 'useLayoutEffect';
  13423. updateHookTypesDev();
  13424. return updateLayoutEffect(create, deps);
  13425. },
  13426. useMemo: function (create, deps) {
  13427. currentHookNameInDev = 'useMemo';
  13428. updateHookTypesDev();
  13429. var prevDispatcher = ReactCurrentDispatcher.current;
  13430. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  13431. try {
  13432. return updateMemo(create, deps);
  13433. } finally {
  13434. ReactCurrentDispatcher.current = prevDispatcher;
  13435. }
  13436. },
  13437. useReducer: function (reducer, initialArg, init) {
  13438. currentHookNameInDev = 'useReducer';
  13439. updateHookTypesDev();
  13440. var prevDispatcher = ReactCurrentDispatcher.current;
  13441. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  13442. try {
  13443. return rerenderReducer(reducer, initialArg, init);
  13444. } finally {
  13445. ReactCurrentDispatcher.current = prevDispatcher;
  13446. }
  13447. },
  13448. useRef: function (initialValue) {
  13449. currentHookNameInDev = 'useRef';
  13450. updateHookTypesDev();
  13451. return updateRef();
  13452. },
  13453. useState: function (initialState) {
  13454. currentHookNameInDev = 'useState';
  13455. updateHookTypesDev();
  13456. var prevDispatcher = ReactCurrentDispatcher.current;
  13457. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  13458. try {
  13459. return rerenderState(initialState);
  13460. } finally {
  13461. ReactCurrentDispatcher.current = prevDispatcher;
  13462. }
  13463. },
  13464. useDebugValue: function (value, formatterFn) {
  13465. currentHookNameInDev = 'useDebugValue';
  13466. updateHookTypesDev();
  13467. return updateDebugValue();
  13468. },
  13469. useResponder: function (responder, props) {
  13470. currentHookNameInDev = 'useResponder';
  13471. updateHookTypesDev();
  13472. return createDeprecatedResponderListener(responder, props);
  13473. },
  13474. useDeferredValue: function (value, config) {
  13475. currentHookNameInDev = 'useDeferredValue';
  13476. updateHookTypesDev();
  13477. return rerenderDeferredValue(value, config);
  13478. },
  13479. useTransition: function (config) {
  13480. currentHookNameInDev = 'useTransition';
  13481. updateHookTypesDev();
  13482. return rerenderTransition(config);
  13483. }
  13484. };
  13485. InvalidNestedHooksDispatcherOnMountInDEV = {
  13486. readContext: function (context, observedBits) {
  13487. warnInvalidContextAccess();
  13488. return readContext(context, observedBits);
  13489. },
  13490. useCallback: function (callback, deps) {
  13491. currentHookNameInDev = 'useCallback';
  13492. warnInvalidHookAccess();
  13493. mountHookTypesDev();
  13494. return mountCallback(callback, deps);
  13495. },
  13496. useContext: function (context, observedBits) {
  13497. currentHookNameInDev = 'useContext';
  13498. warnInvalidHookAccess();
  13499. mountHookTypesDev();
  13500. return readContext(context, observedBits);
  13501. },
  13502. useEffect: function (create, deps) {
  13503. currentHookNameInDev = 'useEffect';
  13504. warnInvalidHookAccess();
  13505. mountHookTypesDev();
  13506. return mountEffect(create, deps);
  13507. },
  13508. useImperativeHandle: function (ref, create, deps) {
  13509. currentHookNameInDev = 'useImperativeHandle';
  13510. warnInvalidHookAccess();
  13511. mountHookTypesDev();
  13512. return mountImperativeHandle(ref, create, deps);
  13513. },
  13514. useLayoutEffect: function (create, deps) {
  13515. currentHookNameInDev = 'useLayoutEffect';
  13516. warnInvalidHookAccess();
  13517. mountHookTypesDev();
  13518. return mountLayoutEffect(create, deps);
  13519. },
  13520. useMemo: function (create, deps) {
  13521. currentHookNameInDev = 'useMemo';
  13522. warnInvalidHookAccess();
  13523. mountHookTypesDev();
  13524. var prevDispatcher = ReactCurrentDispatcher.current;
  13525. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13526. try {
  13527. return mountMemo(create, deps);
  13528. } finally {
  13529. ReactCurrentDispatcher.current = prevDispatcher;
  13530. }
  13531. },
  13532. useReducer: function (reducer, initialArg, init) {
  13533. currentHookNameInDev = 'useReducer';
  13534. warnInvalidHookAccess();
  13535. mountHookTypesDev();
  13536. var prevDispatcher = ReactCurrentDispatcher.current;
  13537. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13538. try {
  13539. return mountReducer(reducer, initialArg, init);
  13540. } finally {
  13541. ReactCurrentDispatcher.current = prevDispatcher;
  13542. }
  13543. },
  13544. useRef: function (initialValue) {
  13545. currentHookNameInDev = 'useRef';
  13546. warnInvalidHookAccess();
  13547. mountHookTypesDev();
  13548. return mountRef(initialValue);
  13549. },
  13550. useState: function (initialState) {
  13551. currentHookNameInDev = 'useState';
  13552. warnInvalidHookAccess();
  13553. mountHookTypesDev();
  13554. var prevDispatcher = ReactCurrentDispatcher.current;
  13555. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13556. try {
  13557. return mountState(initialState);
  13558. } finally {
  13559. ReactCurrentDispatcher.current = prevDispatcher;
  13560. }
  13561. },
  13562. useDebugValue: function (value, formatterFn) {
  13563. currentHookNameInDev = 'useDebugValue';
  13564. warnInvalidHookAccess();
  13565. mountHookTypesDev();
  13566. return mountDebugValue();
  13567. },
  13568. useResponder: function (responder, props) {
  13569. currentHookNameInDev = 'useResponder';
  13570. warnInvalidHookAccess();
  13571. mountHookTypesDev();
  13572. return createDeprecatedResponderListener(responder, props);
  13573. },
  13574. useDeferredValue: function (value, config) {
  13575. currentHookNameInDev = 'useDeferredValue';
  13576. warnInvalidHookAccess();
  13577. mountHookTypesDev();
  13578. return mountDeferredValue(value, config);
  13579. },
  13580. useTransition: function (config) {
  13581. currentHookNameInDev = 'useTransition';
  13582. warnInvalidHookAccess();
  13583. mountHookTypesDev();
  13584. return mountTransition(config);
  13585. }
  13586. };
  13587. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  13588. readContext: function (context, observedBits) {
  13589. warnInvalidContextAccess();
  13590. return readContext(context, observedBits);
  13591. },
  13592. useCallback: function (callback, deps) {
  13593. currentHookNameInDev = 'useCallback';
  13594. warnInvalidHookAccess();
  13595. updateHookTypesDev();
  13596. return updateCallback(callback, deps);
  13597. },
  13598. useContext: function (context, observedBits) {
  13599. currentHookNameInDev = 'useContext';
  13600. warnInvalidHookAccess();
  13601. updateHookTypesDev();
  13602. return readContext(context, observedBits);
  13603. },
  13604. useEffect: function (create, deps) {
  13605. currentHookNameInDev = 'useEffect';
  13606. warnInvalidHookAccess();
  13607. updateHookTypesDev();
  13608. return updateEffect(create, deps);
  13609. },
  13610. useImperativeHandle: function (ref, create, deps) {
  13611. currentHookNameInDev = 'useImperativeHandle';
  13612. warnInvalidHookAccess();
  13613. updateHookTypesDev();
  13614. return updateImperativeHandle(ref, create, deps);
  13615. },
  13616. useLayoutEffect: function (create, deps) {
  13617. currentHookNameInDev = 'useLayoutEffect';
  13618. warnInvalidHookAccess();
  13619. updateHookTypesDev();
  13620. return updateLayoutEffect(create, deps);
  13621. },
  13622. useMemo: function (create, deps) {
  13623. currentHookNameInDev = 'useMemo';
  13624. warnInvalidHookAccess();
  13625. updateHookTypesDev();
  13626. var prevDispatcher = ReactCurrentDispatcher.current;
  13627. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13628. try {
  13629. return updateMemo(create, deps);
  13630. } finally {
  13631. ReactCurrentDispatcher.current = prevDispatcher;
  13632. }
  13633. },
  13634. useReducer: function (reducer, initialArg, init) {
  13635. currentHookNameInDev = 'useReducer';
  13636. warnInvalidHookAccess();
  13637. updateHookTypesDev();
  13638. var prevDispatcher = ReactCurrentDispatcher.current;
  13639. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13640. try {
  13641. return updateReducer(reducer, initialArg, init);
  13642. } finally {
  13643. ReactCurrentDispatcher.current = prevDispatcher;
  13644. }
  13645. },
  13646. useRef: function (initialValue) {
  13647. currentHookNameInDev = 'useRef';
  13648. warnInvalidHookAccess();
  13649. updateHookTypesDev();
  13650. return updateRef();
  13651. },
  13652. useState: function (initialState) {
  13653. currentHookNameInDev = 'useState';
  13654. warnInvalidHookAccess();
  13655. updateHookTypesDev();
  13656. var prevDispatcher = ReactCurrentDispatcher.current;
  13657. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13658. try {
  13659. return updateState(initialState);
  13660. } finally {
  13661. ReactCurrentDispatcher.current = prevDispatcher;
  13662. }
  13663. },
  13664. useDebugValue: function (value, formatterFn) {
  13665. currentHookNameInDev = 'useDebugValue';
  13666. warnInvalidHookAccess();
  13667. updateHookTypesDev();
  13668. return updateDebugValue();
  13669. },
  13670. useResponder: function (responder, props) {
  13671. currentHookNameInDev = 'useResponder';
  13672. warnInvalidHookAccess();
  13673. updateHookTypesDev();
  13674. return createDeprecatedResponderListener(responder, props);
  13675. },
  13676. useDeferredValue: function (value, config) {
  13677. currentHookNameInDev = 'useDeferredValue';
  13678. warnInvalidHookAccess();
  13679. updateHookTypesDev();
  13680. return updateDeferredValue(value, config);
  13681. },
  13682. useTransition: function (config) {
  13683. currentHookNameInDev = 'useTransition';
  13684. warnInvalidHookAccess();
  13685. updateHookTypesDev();
  13686. return updateTransition(config);
  13687. }
  13688. };
  13689. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  13690. readContext: function (context, observedBits) {
  13691. warnInvalidContextAccess();
  13692. return readContext(context, observedBits);
  13693. },
  13694. useCallback: function (callback, deps) {
  13695. currentHookNameInDev = 'useCallback';
  13696. warnInvalidHookAccess();
  13697. updateHookTypesDev();
  13698. return updateCallback(callback, deps);
  13699. },
  13700. useContext: function (context, observedBits) {
  13701. currentHookNameInDev = 'useContext';
  13702. warnInvalidHookAccess();
  13703. updateHookTypesDev();
  13704. return readContext(context, observedBits);
  13705. },
  13706. useEffect: function (create, deps) {
  13707. currentHookNameInDev = 'useEffect';
  13708. warnInvalidHookAccess();
  13709. updateHookTypesDev();
  13710. return updateEffect(create, deps);
  13711. },
  13712. useImperativeHandle: function (ref, create, deps) {
  13713. currentHookNameInDev = 'useImperativeHandle';
  13714. warnInvalidHookAccess();
  13715. updateHookTypesDev();
  13716. return updateImperativeHandle(ref, create, deps);
  13717. },
  13718. useLayoutEffect: function (create, deps) {
  13719. currentHookNameInDev = 'useLayoutEffect';
  13720. warnInvalidHookAccess();
  13721. updateHookTypesDev();
  13722. return updateLayoutEffect(create, deps);
  13723. },
  13724. useMemo: function (create, deps) {
  13725. currentHookNameInDev = 'useMemo';
  13726. warnInvalidHookAccess();
  13727. updateHookTypesDev();
  13728. var prevDispatcher = ReactCurrentDispatcher.current;
  13729. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13730. try {
  13731. return updateMemo(create, deps);
  13732. } finally {
  13733. ReactCurrentDispatcher.current = prevDispatcher;
  13734. }
  13735. },
  13736. useReducer: function (reducer, initialArg, init) {
  13737. currentHookNameInDev = 'useReducer';
  13738. warnInvalidHookAccess();
  13739. updateHookTypesDev();
  13740. var prevDispatcher = ReactCurrentDispatcher.current;
  13741. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13742. try {
  13743. return rerenderReducer(reducer, initialArg, init);
  13744. } finally {
  13745. ReactCurrentDispatcher.current = prevDispatcher;
  13746. }
  13747. },
  13748. useRef: function (initialValue) {
  13749. currentHookNameInDev = 'useRef';
  13750. warnInvalidHookAccess();
  13751. updateHookTypesDev();
  13752. return updateRef();
  13753. },
  13754. useState: function (initialState) {
  13755. currentHookNameInDev = 'useState';
  13756. warnInvalidHookAccess();
  13757. updateHookTypesDev();
  13758. var prevDispatcher = ReactCurrentDispatcher.current;
  13759. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13760. try {
  13761. return rerenderState(initialState);
  13762. } finally {
  13763. ReactCurrentDispatcher.current = prevDispatcher;
  13764. }
  13765. },
  13766. useDebugValue: function (value, formatterFn) {
  13767. currentHookNameInDev = 'useDebugValue';
  13768. warnInvalidHookAccess();
  13769. updateHookTypesDev();
  13770. return updateDebugValue();
  13771. },
  13772. useResponder: function (responder, props) {
  13773. currentHookNameInDev = 'useResponder';
  13774. warnInvalidHookAccess();
  13775. updateHookTypesDev();
  13776. return createDeprecatedResponderListener(responder, props);
  13777. },
  13778. useDeferredValue: function (value, config) {
  13779. currentHookNameInDev = 'useDeferredValue';
  13780. warnInvalidHookAccess();
  13781. updateHookTypesDev();
  13782. return rerenderDeferredValue(value, config);
  13783. },
  13784. useTransition: function (config) {
  13785. currentHookNameInDev = 'useTransition';
  13786. warnInvalidHookAccess();
  13787. updateHookTypesDev();
  13788. return rerenderTransition(config);
  13789. }
  13790. };
  13791. }
  13792. var now$1 = unstable_now;
  13793. var commitTime = 0;
  13794. var profilerStartTime = -1;
  13795. function getCommitTime() {
  13796. return commitTime;
  13797. }
  13798. function recordCommitTime() {
  13799. commitTime = now$1();
  13800. }
  13801. function startProfilerTimer(fiber) {
  13802. profilerStartTime = now$1();
  13803. if (fiber.actualStartTime < 0) {
  13804. fiber.actualStartTime = now$1();
  13805. }
  13806. }
  13807. function stopProfilerTimerIfRunning(fiber) {
  13808. profilerStartTime = -1;
  13809. }
  13810. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  13811. if (profilerStartTime >= 0) {
  13812. var elapsedTime = now$1() - profilerStartTime;
  13813. fiber.actualDuration += elapsedTime;
  13814. if (overrideBaseTime) {
  13815. fiber.selfBaseDuration = elapsedTime;
  13816. }
  13817. profilerStartTime = -1;
  13818. }
  13819. }
  13820. // This may have been an insertion or a hydration.
  13821. var hydrationParentFiber = null;
  13822. var nextHydratableInstance = null;
  13823. var isHydrating = false;
  13824. function enterHydrationState(fiber) {
  13825. var parentInstance = fiber.stateNode.containerInfo;
  13826. nextHydratableInstance = getFirstHydratableChild(parentInstance);
  13827. hydrationParentFiber = fiber;
  13828. isHydrating = true;
  13829. return true;
  13830. }
  13831. function deleteHydratableInstance(returnFiber, instance) {
  13832. {
  13833. switch (returnFiber.tag) {
  13834. case HostRoot:
  13835. didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
  13836. break;
  13837. case HostComponent:
  13838. didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
  13839. break;
  13840. }
  13841. }
  13842. var childToDelete = createFiberFromHostInstanceForDeletion();
  13843. childToDelete.stateNode = instance;
  13844. childToDelete.return = returnFiber;
  13845. childToDelete.effectTag = Deletion; // This might seem like it belongs on progressedFirstDeletion. However,
  13846. // these children are not part of the reconciliation list of children.
  13847. // Even if we abort and rereconcile the children, that will try to hydrate
  13848. // again and the nodes are still in the host tree so these will be
  13849. // recreated.
  13850. if (returnFiber.lastEffect !== null) {
  13851. returnFiber.lastEffect.nextEffect = childToDelete;
  13852. returnFiber.lastEffect = childToDelete;
  13853. } else {
  13854. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  13855. }
  13856. }
  13857. function insertNonHydratedInstance(returnFiber, fiber) {
  13858. fiber.effectTag = fiber.effectTag & ~Hydrating | Placement;
  13859. {
  13860. switch (returnFiber.tag) {
  13861. case HostRoot:
  13862. {
  13863. var parentContainer = returnFiber.stateNode.containerInfo;
  13864. switch (fiber.tag) {
  13865. case HostComponent:
  13866. var type = fiber.type;
  13867. var props = fiber.pendingProps;
  13868. didNotFindHydratableContainerInstance(parentContainer, type);
  13869. break;
  13870. case HostText:
  13871. var text = fiber.pendingProps;
  13872. didNotFindHydratableContainerTextInstance(parentContainer, text);
  13873. break;
  13874. }
  13875. break;
  13876. }
  13877. case HostComponent:
  13878. {
  13879. var parentType = returnFiber.type;
  13880. var parentProps = returnFiber.memoizedProps;
  13881. var parentInstance = returnFiber.stateNode;
  13882. switch (fiber.tag) {
  13883. case HostComponent:
  13884. var _type = fiber.type;
  13885. var _props = fiber.pendingProps;
  13886. didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type);
  13887. break;
  13888. case HostText:
  13889. var _text = fiber.pendingProps;
  13890. didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
  13891. break;
  13892. case SuspenseComponent:
  13893. didNotFindHydratableSuspenseInstance(parentType, parentProps);
  13894. break;
  13895. }
  13896. break;
  13897. }
  13898. default:
  13899. return;
  13900. }
  13901. }
  13902. }
  13903. function tryHydrate(fiber, nextInstance) {
  13904. switch (fiber.tag) {
  13905. case HostComponent:
  13906. {
  13907. var type = fiber.type;
  13908. var props = fiber.pendingProps;
  13909. var instance = canHydrateInstance(nextInstance, type);
  13910. if (instance !== null) {
  13911. fiber.stateNode = instance;
  13912. return true;
  13913. }
  13914. return false;
  13915. }
  13916. case HostText:
  13917. {
  13918. var text = fiber.pendingProps;
  13919. var textInstance = canHydrateTextInstance(nextInstance, text);
  13920. if (textInstance !== null) {
  13921. fiber.stateNode = textInstance;
  13922. return true;
  13923. }
  13924. return false;
  13925. }
  13926. case SuspenseComponent:
  13927. {
  13928. return false;
  13929. }
  13930. default:
  13931. return false;
  13932. }
  13933. }
  13934. function tryToClaimNextHydratableInstance(fiber) {
  13935. if (!isHydrating) {
  13936. return;
  13937. }
  13938. var nextInstance = nextHydratableInstance;
  13939. if (!nextInstance) {
  13940. // Nothing to hydrate. Make it an insertion.
  13941. insertNonHydratedInstance(hydrationParentFiber, fiber);
  13942. isHydrating = false;
  13943. hydrationParentFiber = fiber;
  13944. return;
  13945. }
  13946. var firstAttemptedInstance = nextInstance;
  13947. if (!tryHydrate(fiber, nextInstance)) {
  13948. // If we can't hydrate this instance let's try the next one.
  13949. // We use this as a heuristic. It's based on intuition and not data so it
  13950. // might be flawed or unnecessary.
  13951. nextInstance = getNextHydratableSibling(firstAttemptedInstance);
  13952. if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
  13953. // Nothing to hydrate. Make it an insertion.
  13954. insertNonHydratedInstance(hydrationParentFiber, fiber);
  13955. isHydrating = false;
  13956. hydrationParentFiber = fiber;
  13957. return;
  13958. } // We matched the next one, we'll now assume that the first one was
  13959. // superfluous and we'll delete it. Since we can't eagerly delete it
  13960. // we'll have to schedule a deletion. To do that, this node needs a dummy
  13961. // fiber associated with it.
  13962. deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
  13963. }
  13964. hydrationParentFiber = fiber;
  13965. nextHydratableInstance = getFirstHydratableChild(nextInstance);
  13966. }
  13967. function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
  13968. var instance = fiber.stateNode;
  13969. var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber); // TODO: Type this specific to this type of component.
  13970. fiber.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  13971. // is a new ref we mark this as an update.
  13972. if (updatePayload !== null) {
  13973. return true;
  13974. }
  13975. return false;
  13976. }
  13977. function prepareToHydrateHostTextInstance(fiber) {
  13978. var textInstance = fiber.stateNode;
  13979. var textContent = fiber.memoizedProps;
  13980. var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
  13981. {
  13982. if (shouldUpdate) {
  13983. // We assume that prepareToHydrateHostTextInstance is called in a context where the
  13984. // hydration parent is the parent host component of this host text.
  13985. var returnFiber = hydrationParentFiber;
  13986. if (returnFiber !== null) {
  13987. switch (returnFiber.tag) {
  13988. case HostRoot:
  13989. {
  13990. var parentContainer = returnFiber.stateNode.containerInfo;
  13991. didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
  13992. break;
  13993. }
  13994. case HostComponent:
  13995. {
  13996. var parentType = returnFiber.type;
  13997. var parentProps = returnFiber.memoizedProps;
  13998. var parentInstance = returnFiber.stateNode;
  13999. didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
  14000. break;
  14001. }
  14002. }
  14003. }
  14004. }
  14005. }
  14006. return shouldUpdate;
  14007. }
  14008. function skipPastDehydratedSuspenseInstance(fiber) {
  14009. var suspenseState = fiber.memoizedState;
  14010. var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
  14011. if (!suspenseInstance) {
  14012. {
  14013. throw Error( "Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue." );
  14014. }
  14015. }
  14016. return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
  14017. }
  14018. function popToNextHostParent(fiber) {
  14019. var parent = fiber.return;
  14020. while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== SuspenseComponent) {
  14021. parent = parent.return;
  14022. }
  14023. hydrationParentFiber = parent;
  14024. }
  14025. function popHydrationState(fiber) {
  14026. if (fiber !== hydrationParentFiber) {
  14027. // We're deeper than the current hydration context, inside an inserted
  14028. // tree.
  14029. return false;
  14030. }
  14031. if (!isHydrating) {
  14032. // If we're not currently hydrating but we're in a hydration context, then
  14033. // we were an insertion and now need to pop up reenter hydration of our
  14034. // siblings.
  14035. popToNextHostParent(fiber);
  14036. isHydrating = true;
  14037. return false;
  14038. }
  14039. var type = fiber.type; // If we have any remaining hydratable nodes, we need to delete them now.
  14040. // We only do this deeper than head and body since they tend to have random
  14041. // other nodes in them. We also ignore components with pure text content in
  14042. // side of them.
  14043. // TODO: Better heuristic.
  14044. if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
  14045. var nextInstance = nextHydratableInstance;
  14046. while (nextInstance) {
  14047. deleteHydratableInstance(fiber, nextInstance);
  14048. nextInstance = getNextHydratableSibling(nextInstance);
  14049. }
  14050. }
  14051. popToNextHostParent(fiber);
  14052. if (fiber.tag === SuspenseComponent) {
  14053. nextHydratableInstance = skipPastDehydratedSuspenseInstance(fiber);
  14054. } else {
  14055. nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
  14056. }
  14057. return true;
  14058. }
  14059. function resetHydrationState() {
  14060. hydrationParentFiber = null;
  14061. nextHydratableInstance = null;
  14062. isHydrating = false;
  14063. }
  14064. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  14065. var didReceiveUpdate = false;
  14066. var didWarnAboutBadClass;
  14067. var didWarnAboutModulePatternComponent;
  14068. var didWarnAboutContextTypeOnFunctionComponent;
  14069. var didWarnAboutGetDerivedStateOnFunctionComponent;
  14070. var didWarnAboutFunctionRefs;
  14071. var didWarnAboutReassigningProps;
  14072. var didWarnAboutRevealOrder;
  14073. var didWarnAboutTailOptions;
  14074. {
  14075. didWarnAboutBadClass = {};
  14076. didWarnAboutModulePatternComponent = {};
  14077. didWarnAboutContextTypeOnFunctionComponent = {};
  14078. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  14079. didWarnAboutFunctionRefs = {};
  14080. didWarnAboutReassigningProps = false;
  14081. didWarnAboutRevealOrder = {};
  14082. didWarnAboutTailOptions = {};
  14083. }
  14084. function reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime) {
  14085. if (current === null) {
  14086. // If this is a fresh new component that hasn't been rendered yet, we
  14087. // won't update its child set by applying minimal side-effects. Instead,
  14088. // we will add them all to the child before it gets rendered. That means
  14089. // we can optimize this reconciliation pass by not tracking side-effects.
  14090. workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  14091. } else {
  14092. // If the current child is the same as the work in progress, it means that
  14093. // we haven't yet started any work on these children. Therefore, we use
  14094. // the clone algorithm to create a copy of all the current children.
  14095. // If we had any progressed work already, that is invalid at this point so
  14096. // let's throw it out.
  14097. workInProgress.child = reconcileChildFibers(workInProgress, current.child, nextChildren, renderExpirationTime);
  14098. }
  14099. }
  14100. function forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderExpirationTime) {
  14101. // This function is fork of reconcileChildren. It's used in cases where we
  14102. // want to reconcile without matching against the existing set. This has the
  14103. // effect of all current children being unmounted; even if the type and key
  14104. // are the same, the old child is unmounted and a new child is created.
  14105. //
  14106. // To do this, we're going to go through the reconcile algorithm twice. In
  14107. // the first pass, we schedule a deletion for all the current children by
  14108. // passing null.
  14109. workInProgress.child = reconcileChildFibers(workInProgress, current.child, null, renderExpirationTime); // In the second pass, we mount the new children. The trick here is that we
  14110. // pass null in place of where we usually pass the current child set. This has
  14111. // the effect of remounting all children regardless of whether their
  14112. // identities match.
  14113. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  14114. }
  14115. function updateForwardRef(current, workInProgress, Component, nextProps, renderExpirationTime) {
  14116. // TODO: current can be non-null here even if the component
  14117. // hasn't yet mounted. This happens after the first render suspends.
  14118. // We'll need to figure out if this is fine or can cause issues.
  14119. {
  14120. if (workInProgress.type !== workInProgress.elementType) {
  14121. // Lazy component props can't be validated in createElement
  14122. // because they're only guaranteed to be resolved here.
  14123. var innerPropTypes = Component.propTypes;
  14124. if (innerPropTypes) {
  14125. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  14126. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  14127. }
  14128. }
  14129. }
  14130. var render = Component.render;
  14131. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  14132. var nextChildren;
  14133. prepareToReadContext(workInProgress, renderExpirationTime);
  14134. {
  14135. ReactCurrentOwner$1.current = workInProgress;
  14136. setIsRendering(true);
  14137. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderExpirationTime);
  14138. if ( workInProgress.mode & StrictMode) {
  14139. // Only double-render components with Hooks
  14140. if (workInProgress.memoizedState !== null) {
  14141. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderExpirationTime);
  14142. }
  14143. }
  14144. setIsRendering(false);
  14145. }
  14146. if (current !== null && !didReceiveUpdate) {
  14147. bailoutHooks(current, workInProgress, renderExpirationTime);
  14148. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  14149. } // React DevTools reads this flag.
  14150. workInProgress.effectTag |= PerformedWork;
  14151. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14152. return workInProgress.child;
  14153. }
  14154. function updateMemoComponent(current, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
  14155. if (current === null) {
  14156. var type = Component.type;
  14157. if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  14158. Component.defaultProps === undefined) {
  14159. var resolvedType = type;
  14160. {
  14161. resolvedType = resolveFunctionForHotReloading(type);
  14162. } // If this is a plain function component without default props,
  14163. // and with only the default shallow comparison, we upgrade it
  14164. // to a SimpleMemoComponent to allow fast path updates.
  14165. workInProgress.tag = SimpleMemoComponent;
  14166. workInProgress.type = resolvedType;
  14167. {
  14168. validateFunctionComponentInDev(workInProgress, type);
  14169. }
  14170. return updateSimpleMemoComponent(current, workInProgress, resolvedType, nextProps, updateExpirationTime, renderExpirationTime);
  14171. }
  14172. {
  14173. var innerPropTypes = type.propTypes;
  14174. if (innerPropTypes) {
  14175. // Inner memo component props aren't currently validated in createElement.
  14176. // We could move it there, but we'd still need this for lazy code path.
  14177. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  14178. 'prop', getComponentName(type), getCurrentFiberStackInDev);
  14179. }
  14180. }
  14181. var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
  14182. child.ref = workInProgress.ref;
  14183. child.return = workInProgress;
  14184. workInProgress.child = child;
  14185. return child;
  14186. }
  14187. {
  14188. var _type = Component.type;
  14189. var _innerPropTypes = _type.propTypes;
  14190. if (_innerPropTypes) {
  14191. // Inner memo component props aren't currently validated in createElement.
  14192. // We could move it there, but we'd still need this for lazy code path.
  14193. checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
  14194. 'prop', getComponentName(_type), getCurrentFiberStackInDev);
  14195. }
  14196. }
  14197. var currentChild = current.child; // This is always exactly one child
  14198. if (updateExpirationTime < renderExpirationTime) {
  14199. // This will be the props with resolved defaultProps,
  14200. // unlike current.memoizedProps which will be the unresolved ones.
  14201. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  14202. var compare = Component.compare;
  14203. compare = compare !== null ? compare : shallowEqual;
  14204. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  14205. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  14206. }
  14207. } // React DevTools reads this flag.
  14208. workInProgress.effectTag |= PerformedWork;
  14209. var newChild = createWorkInProgress(currentChild, nextProps);
  14210. newChild.ref = workInProgress.ref;
  14211. newChild.return = workInProgress;
  14212. workInProgress.child = newChild;
  14213. return newChild;
  14214. }
  14215. function updateSimpleMemoComponent(current, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
  14216. // TODO: current can be non-null here even if the component
  14217. // hasn't yet mounted. This happens when the inner render suspends.
  14218. // We'll need to figure out if this is fine or can cause issues.
  14219. {
  14220. if (workInProgress.type !== workInProgress.elementType) {
  14221. // Lazy component props can't be validated in createElement
  14222. // because they're only guaranteed to be resolved here.
  14223. var outerMemoType = workInProgress.elementType;
  14224. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  14225. // We warn when you define propTypes on lazy()
  14226. // so let's just skip over it to find memo() outer wrapper.
  14227. // Inner props for memo are validated later.
  14228. outerMemoType = refineResolvedLazyComponent(outerMemoType);
  14229. }
  14230. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  14231. if (outerPropTypes) {
  14232. checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  14233. 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
  14234. } // Inner propTypes will be validated in the function component path.
  14235. }
  14236. }
  14237. if (current !== null) {
  14238. var prevProps = current.memoizedProps;
  14239. if (shallowEqual(prevProps, nextProps) && current.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload.
  14240. workInProgress.type === current.type )) {
  14241. didReceiveUpdate = false;
  14242. if (updateExpirationTime < renderExpirationTime) {
  14243. // The pending update priority was cleared at the beginning of
  14244. // beginWork. We're about to bail out, but there might be additional
  14245. // updates at a lower priority. Usually, the priority level of the
  14246. // remaining updates is accumlated during the evaluation of the
  14247. // component (i.e. when processing the update queue). But since since
  14248. // we're bailing out early *without* evaluating the component, we need
  14249. // to account for it here, too. Reset to the value of the current fiber.
  14250. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  14251. // because a MemoComponent fiber does not have hooks or an update queue;
  14252. // rather, it wraps around an inner component, which may or may not
  14253. // contains hooks.
  14254. // TODO: Move the reset at in beginWork out of the common path so that
  14255. // this is no longer necessary.
  14256. workInProgress.expirationTime = current.expirationTime;
  14257. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  14258. }
  14259. }
  14260. }
  14261. return updateFunctionComponent(current, workInProgress, Component, nextProps, renderExpirationTime);
  14262. }
  14263. function updateFragment(current, workInProgress, renderExpirationTime) {
  14264. var nextChildren = workInProgress.pendingProps;
  14265. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14266. return workInProgress.child;
  14267. }
  14268. function updateMode(current, workInProgress, renderExpirationTime) {
  14269. var nextChildren = workInProgress.pendingProps.children;
  14270. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14271. return workInProgress.child;
  14272. }
  14273. function updateProfiler(current, workInProgress, renderExpirationTime) {
  14274. {
  14275. workInProgress.effectTag |= Update;
  14276. }
  14277. var nextProps = workInProgress.pendingProps;
  14278. var nextChildren = nextProps.children;
  14279. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14280. return workInProgress.child;
  14281. }
  14282. function markRef(current, workInProgress) {
  14283. var ref = workInProgress.ref;
  14284. if (current === null && ref !== null || current !== null && current.ref !== ref) {
  14285. // Schedule a Ref effect
  14286. workInProgress.effectTag |= Ref;
  14287. }
  14288. }
  14289. function updateFunctionComponent(current, workInProgress, Component, nextProps, renderExpirationTime) {
  14290. {
  14291. if (workInProgress.type !== workInProgress.elementType) {
  14292. // Lazy component props can't be validated in createElement
  14293. // because they're only guaranteed to be resolved here.
  14294. var innerPropTypes = Component.propTypes;
  14295. if (innerPropTypes) {
  14296. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  14297. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  14298. }
  14299. }
  14300. }
  14301. var context;
  14302. {
  14303. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  14304. context = getMaskedContext(workInProgress, unmaskedContext);
  14305. }
  14306. var nextChildren;
  14307. prepareToReadContext(workInProgress, renderExpirationTime);
  14308. {
  14309. ReactCurrentOwner$1.current = workInProgress;
  14310. setIsRendering(true);
  14311. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderExpirationTime);
  14312. if ( workInProgress.mode & StrictMode) {
  14313. // Only double-render components with Hooks
  14314. if (workInProgress.memoizedState !== null) {
  14315. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderExpirationTime);
  14316. }
  14317. }
  14318. setIsRendering(false);
  14319. }
  14320. if (current !== null && !didReceiveUpdate) {
  14321. bailoutHooks(current, workInProgress, renderExpirationTime);
  14322. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  14323. } // React DevTools reads this flag.
  14324. workInProgress.effectTag |= PerformedWork;
  14325. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14326. return workInProgress.child;
  14327. }
  14328. function updateClassComponent(current, workInProgress, Component, nextProps, renderExpirationTime) {
  14329. {
  14330. if (workInProgress.type !== workInProgress.elementType) {
  14331. // Lazy component props can't be validated in createElement
  14332. // because they're only guaranteed to be resolved here.
  14333. var innerPropTypes = Component.propTypes;
  14334. if (innerPropTypes) {
  14335. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  14336. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  14337. }
  14338. }
  14339. } // Push context providers early to prevent context stack mismatches.
  14340. // During mounting we don't know the child context yet as the instance doesn't exist.
  14341. // We will invalidate the child context in finishClassComponent() right after rendering.
  14342. var hasContext;
  14343. if (isContextProvider(Component)) {
  14344. hasContext = true;
  14345. pushContextProvider(workInProgress);
  14346. } else {
  14347. hasContext = false;
  14348. }
  14349. prepareToReadContext(workInProgress, renderExpirationTime);
  14350. var instance = workInProgress.stateNode;
  14351. var shouldUpdate;
  14352. if (instance === null) {
  14353. if (current !== null) {
  14354. // A class component without an instance only mounts if it suspended
  14355. // inside a non-concurrent tree, in an inconsistent state. We want to
  14356. // treat it like a new mount, even though an empty version of it already
  14357. // committed. Disconnect the alternate pointers.
  14358. current.alternate = null;
  14359. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14360. workInProgress.effectTag |= Placement;
  14361. } // In the initial pass we might need to construct the instance.
  14362. constructClassInstance(workInProgress, Component, nextProps);
  14363. mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  14364. shouldUpdate = true;
  14365. } else if (current === null) {
  14366. // In a resume, we'll already have an instance we can reuse.
  14367. shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  14368. } else {
  14369. shouldUpdate = updateClassInstance(current, workInProgress, Component, nextProps, renderExpirationTime);
  14370. }
  14371. var nextUnitOfWork = finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
  14372. {
  14373. var inst = workInProgress.stateNode;
  14374. if (inst.props !== nextProps) {
  14375. if (!didWarnAboutReassigningProps) {
  14376. error('It looks like %s is reassigning its own `this.props` while rendering. ' + 'This is not supported and can lead to confusing bugs.', getComponentName(workInProgress.type) || 'a component');
  14377. }
  14378. didWarnAboutReassigningProps = true;
  14379. }
  14380. }
  14381. return nextUnitOfWork;
  14382. }
  14383. function finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
  14384. // Refs should update even if shouldComponentUpdate returns false
  14385. markRef(current, workInProgress);
  14386. var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
  14387. if (!shouldUpdate && !didCaptureError) {
  14388. // Context providers should defer to sCU for rendering
  14389. if (hasContext) {
  14390. invalidateContextProvider(workInProgress, Component, false);
  14391. }
  14392. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  14393. }
  14394. var instance = workInProgress.stateNode; // Rerender
  14395. ReactCurrentOwner$1.current = workInProgress;
  14396. var nextChildren;
  14397. if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
  14398. // If we captured an error, but getDerivedStateFromError is not defined,
  14399. // unmount all the children. componentDidCatch will schedule an update to
  14400. // re-render a fallback. This is temporary until we migrate everyone to
  14401. // the new API.
  14402. // TODO: Warn in a future release.
  14403. nextChildren = null;
  14404. {
  14405. stopProfilerTimerIfRunning();
  14406. }
  14407. } else {
  14408. {
  14409. setIsRendering(true);
  14410. nextChildren = instance.render();
  14411. if ( workInProgress.mode & StrictMode) {
  14412. instance.render();
  14413. }
  14414. setIsRendering(false);
  14415. }
  14416. } // React DevTools reads this flag.
  14417. workInProgress.effectTag |= PerformedWork;
  14418. if (current !== null && didCaptureError) {
  14419. // If we're recovering from an error, reconcile without reusing any of
  14420. // the existing children. Conceptually, the normal children and the children
  14421. // that are shown on error are two different sets, so we shouldn't reuse
  14422. // normal children even if their identities match.
  14423. forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderExpirationTime);
  14424. } else {
  14425. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14426. } // Memoize state using the values we just used to render.
  14427. // TODO: Restructure so we never read values from the instance.
  14428. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  14429. if (hasContext) {
  14430. invalidateContextProvider(workInProgress, Component, true);
  14431. }
  14432. return workInProgress.child;
  14433. }
  14434. function pushHostRootContext(workInProgress) {
  14435. var root = workInProgress.stateNode;
  14436. if (root.pendingContext) {
  14437. pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
  14438. } else if (root.context) {
  14439. // Should always be set
  14440. pushTopLevelContextObject(workInProgress, root.context, false);
  14441. }
  14442. pushHostContainer(workInProgress, root.containerInfo);
  14443. }
  14444. function updateHostRoot(current, workInProgress, renderExpirationTime) {
  14445. pushHostRootContext(workInProgress);
  14446. var updateQueue = workInProgress.updateQueue;
  14447. if (!(current !== null && updateQueue !== null)) {
  14448. {
  14449. throw Error( "If the root does not have an updateQueue, we should have already bailed out. This error is likely caused by a bug in React. Please file an issue." );
  14450. }
  14451. }
  14452. var nextProps = workInProgress.pendingProps;
  14453. var prevState = workInProgress.memoizedState;
  14454. var prevChildren = prevState !== null ? prevState.element : null;
  14455. cloneUpdateQueue(current, workInProgress);
  14456. processUpdateQueue(workInProgress, nextProps, null, renderExpirationTime);
  14457. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  14458. // being called "element".
  14459. var nextChildren = nextState.element;
  14460. if (nextChildren === prevChildren) {
  14461. // If the state is the same as before, that's a bailout because we had
  14462. // no work that expires at this time.
  14463. resetHydrationState();
  14464. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  14465. }
  14466. var root = workInProgress.stateNode;
  14467. if (root.hydrate && enterHydrationState(workInProgress)) {
  14468. // If we don't have any current children this might be the first pass.
  14469. // We always try to hydrate. If this isn't a hydration pass there won't
  14470. // be any children to hydrate which is effectively the same thing as
  14471. // not hydrating.
  14472. var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  14473. workInProgress.child = child;
  14474. var node = child;
  14475. while (node) {
  14476. // Mark each child as hydrating. This is a fast path to know whether this
  14477. // tree is part of a hydrating tree. This is used to determine if a child
  14478. // node has fully mounted yet, and for scheduling event replaying.
  14479. // Conceptually this is similar to Placement in that a new subtree is
  14480. // inserted into the React tree here. It just happens to not need DOM
  14481. // mutations because it already exists.
  14482. node.effectTag = node.effectTag & ~Placement | Hydrating;
  14483. node = node.sibling;
  14484. }
  14485. } else {
  14486. // Otherwise reset hydration state in case we aborted and resumed another
  14487. // root.
  14488. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14489. resetHydrationState();
  14490. }
  14491. return workInProgress.child;
  14492. }
  14493. function updateHostComponent(current, workInProgress, renderExpirationTime) {
  14494. pushHostContext(workInProgress);
  14495. if (current === null) {
  14496. tryToClaimNextHydratableInstance(workInProgress);
  14497. }
  14498. var type = workInProgress.type;
  14499. var nextProps = workInProgress.pendingProps;
  14500. var prevProps = current !== null ? current.memoizedProps : null;
  14501. var nextChildren = nextProps.children;
  14502. var isDirectTextChild = shouldSetTextContent(type, nextProps);
  14503. if (isDirectTextChild) {
  14504. // We special case a direct text child of a host node. This is a common
  14505. // case. We won't handle it as a reified child. We will instead handle
  14506. // this in the host environment that also has access to this prop. That
  14507. // avoids allocating another HostText fiber and traversing it.
  14508. nextChildren = null;
  14509. } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
  14510. // If we're switching from a direct text child to a normal child, or to
  14511. // empty, we need to schedule the text content to be reset.
  14512. workInProgress.effectTag |= ContentReset;
  14513. }
  14514. markRef(current, workInProgress); // Check the host config to see if the children are offscreen/hidden.
  14515. if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(type, nextProps)) {
  14516. {
  14517. markSpawnedWork(Never);
  14518. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  14519. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  14520. return null;
  14521. }
  14522. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  14523. return workInProgress.child;
  14524. }
  14525. function updateHostText(current, workInProgress) {
  14526. if (current === null) {
  14527. tryToClaimNextHydratableInstance(workInProgress);
  14528. } // Nothing to do here. This is terminal. We'll do the completion step
  14529. // immediately after.
  14530. return null;
  14531. }
  14532. function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
  14533. if (_current !== null) {
  14534. // A lazy component only mounts if it suspended inside a non-
  14535. // concurrent tree, in an inconsistent state. We want to treat it like
  14536. // a new mount, even though an empty version of it already committed.
  14537. // Disconnect the alternate pointers.
  14538. _current.alternate = null;
  14539. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14540. workInProgress.effectTag |= Placement;
  14541. }
  14542. var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
  14543. // Cancel and resume right after we know the tag.
  14544. cancelWorkTimer(workInProgress);
  14545. var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
  14546. workInProgress.type = Component;
  14547. var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
  14548. startWorkTimer(workInProgress);
  14549. var resolvedProps = resolveDefaultProps(Component, props);
  14550. var child;
  14551. switch (resolvedTag) {
  14552. case FunctionComponent:
  14553. {
  14554. {
  14555. validateFunctionComponentInDev(workInProgress, Component);
  14556. workInProgress.type = Component = resolveFunctionForHotReloading(Component);
  14557. }
  14558. child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  14559. return child;
  14560. }
  14561. case ClassComponent:
  14562. {
  14563. {
  14564. workInProgress.type = Component = resolveClassForHotReloading(Component);
  14565. }
  14566. child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  14567. return child;
  14568. }
  14569. case ForwardRef:
  14570. {
  14571. {
  14572. workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
  14573. }
  14574. child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  14575. return child;
  14576. }
  14577. case MemoComponent:
  14578. {
  14579. {
  14580. if (workInProgress.type !== workInProgress.elementType) {
  14581. var outerPropTypes = Component.propTypes;
  14582. if (outerPropTypes) {
  14583. checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
  14584. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  14585. }
  14586. }
  14587. }
  14588. child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  14589. updateExpirationTime, renderExpirationTime);
  14590. return child;
  14591. }
  14592. }
  14593. var hint = '';
  14594. {
  14595. if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
  14596. hint = ' Did you wrap a component in React.lazy() more than once?';
  14597. }
  14598. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  14599. // because the fact that it's a separate type of work is an
  14600. // implementation detail.
  14601. {
  14602. {
  14603. throw Error( "Element type is invalid. Received a promise that resolves to: " + Component + ". Lazy element type must resolve to a class or function." + hint );
  14604. }
  14605. }
  14606. }
  14607. function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
  14608. if (_current !== null) {
  14609. // An incomplete component only mounts if it suspended inside a non-
  14610. // concurrent tree, in an inconsistent state. We want to treat it like
  14611. // a new mount, even though an empty version of it already committed.
  14612. // Disconnect the alternate pointers.
  14613. _current.alternate = null;
  14614. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14615. workInProgress.effectTag |= Placement;
  14616. } // Promote the fiber to a class and try rendering again.
  14617. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  14618. // Push context providers early to prevent context stack mismatches.
  14619. // During mounting we don't know the child context yet as the instance doesn't exist.
  14620. // We will invalidate the child context in finishClassComponent() right after rendering.
  14621. var hasContext;
  14622. if (isContextProvider(Component)) {
  14623. hasContext = true;
  14624. pushContextProvider(workInProgress);
  14625. } else {
  14626. hasContext = false;
  14627. }
  14628. prepareToReadContext(workInProgress, renderExpirationTime);
  14629. constructClassInstance(workInProgress, Component, nextProps);
  14630. mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  14631. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
  14632. }
  14633. function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
  14634. if (_current !== null) {
  14635. // An indeterminate component only mounts if it suspended inside a non-
  14636. // concurrent tree, in an inconsistent state. We want to treat it like
  14637. // a new mount, even though an empty version of it already committed.
  14638. // Disconnect the alternate pointers.
  14639. _current.alternate = null;
  14640. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14641. workInProgress.effectTag |= Placement;
  14642. }
  14643. var props = workInProgress.pendingProps;
  14644. var context;
  14645. {
  14646. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  14647. context = getMaskedContext(workInProgress, unmaskedContext);
  14648. }
  14649. prepareToReadContext(workInProgress, renderExpirationTime);
  14650. var value;
  14651. {
  14652. if (Component.prototype && typeof Component.prototype.render === 'function') {
  14653. var componentName = getComponentName(Component) || 'Unknown';
  14654. if (!didWarnAboutBadClass[componentName]) {
  14655. error("The <%s /> component appears to have a render method, but doesn't extend React.Component. " + 'This is likely to cause errors. Change %s to extend React.Component instead.', componentName, componentName);
  14656. didWarnAboutBadClass[componentName] = true;
  14657. }
  14658. }
  14659. if (workInProgress.mode & StrictMode) {
  14660. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  14661. }
  14662. setIsRendering(true);
  14663. ReactCurrentOwner$1.current = workInProgress;
  14664. value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
  14665. setIsRendering(false);
  14666. } // React DevTools reads this flag.
  14667. workInProgress.effectTag |= PerformedWork;
  14668. if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  14669. {
  14670. var _componentName = getComponentName(Component) || 'Unknown';
  14671. if (!didWarnAboutModulePatternComponent[_componentName]) {
  14672. error('The <%s /> component appears to be a function component that returns a class instance. ' + 'Change %s to a class that extends React.Component instead. ' + "If you can't use a class try assigning the prototype on the function as a workaround. " + "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " + 'cannot be called with `new` by React.', _componentName, _componentName, _componentName);
  14673. didWarnAboutModulePatternComponent[_componentName] = true;
  14674. }
  14675. } // Proceed under the assumption that this is a class instance
  14676. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  14677. workInProgress.memoizedState = null;
  14678. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  14679. // During mounting we don't know the child context yet as the instance doesn't exist.
  14680. // We will invalidate the child context in finishClassComponent() right after rendering.
  14681. var hasContext = false;
  14682. if (isContextProvider(Component)) {
  14683. hasContext = true;
  14684. pushContextProvider(workInProgress);
  14685. } else {
  14686. hasContext = false;
  14687. }
  14688. workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
  14689. initializeUpdateQueue(workInProgress);
  14690. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  14691. if (typeof getDerivedStateFromProps === 'function') {
  14692. applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
  14693. }
  14694. adoptClassInstance(workInProgress, value);
  14695. mountClassInstance(workInProgress, Component, props, renderExpirationTime);
  14696. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
  14697. } else {
  14698. // Proceed under the assumption that this is a function component
  14699. workInProgress.tag = FunctionComponent;
  14700. {
  14701. if ( workInProgress.mode & StrictMode) {
  14702. // Only double-render components with Hooks
  14703. if (workInProgress.memoizedState !== null) {
  14704. value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
  14705. }
  14706. }
  14707. }
  14708. reconcileChildren(null, workInProgress, value, renderExpirationTime);
  14709. {
  14710. validateFunctionComponentInDev(workInProgress, Component);
  14711. }
  14712. return workInProgress.child;
  14713. }
  14714. }
  14715. function validateFunctionComponentInDev(workInProgress, Component) {
  14716. {
  14717. if (Component) {
  14718. if (Component.childContextTypes) {
  14719. error('%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component');
  14720. }
  14721. }
  14722. if (workInProgress.ref !== null) {
  14723. var info = '';
  14724. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  14725. if (ownerName) {
  14726. info += '\n\nCheck the render method of `' + ownerName + '`.';
  14727. }
  14728. var warningKey = ownerName || workInProgress._debugID || '';
  14729. var debugSource = workInProgress._debugSource;
  14730. if (debugSource) {
  14731. warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
  14732. }
  14733. if (!didWarnAboutFunctionRefs[warningKey]) {
  14734. didWarnAboutFunctionRefs[warningKey] = true;
  14735. error('Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
  14736. }
  14737. }
  14738. if (typeof Component.getDerivedStateFromProps === 'function') {
  14739. var _componentName2 = getComponentName(Component) || 'Unknown';
  14740. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
  14741. error('%s: Function components do not support getDerivedStateFromProps.', _componentName2);
  14742. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
  14743. }
  14744. }
  14745. if (typeof Component.contextType === 'object' && Component.contextType !== null) {
  14746. var _componentName3 = getComponentName(Component) || 'Unknown';
  14747. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
  14748. error('%s: Function components do not support contextType.', _componentName3);
  14749. didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
  14750. }
  14751. }
  14752. }
  14753. }
  14754. var SUSPENDED_MARKER = {
  14755. dehydrated: null,
  14756. retryTime: NoWork
  14757. };
  14758. function shouldRemainOnFallback(suspenseContext, current, workInProgress) {
  14759. // If the context is telling us that we should show a fallback, and we're not
  14760. // already showing content, then we should show the fallback instead.
  14761. return hasSuspenseContext(suspenseContext, ForceSuspenseFallback) && (current === null || current.memoizedState !== null);
  14762. }
  14763. function updateSuspenseComponent(current, workInProgress, renderExpirationTime) {
  14764. var mode = workInProgress.mode;
  14765. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  14766. {
  14767. if (shouldSuspend(workInProgress)) {
  14768. workInProgress.effectTag |= DidCapture;
  14769. }
  14770. }
  14771. var suspenseContext = suspenseStackCursor.current;
  14772. var nextDidTimeout = false;
  14773. var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
  14774. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  14775. // Something in this boundary's subtree already suspended. Switch to
  14776. // rendering the fallback children.
  14777. nextDidTimeout = true;
  14778. workInProgress.effectTag &= ~DidCapture;
  14779. } else {
  14780. // Attempting the main content
  14781. if (current === null || current.memoizedState !== null) {
  14782. // This is a new mount or this boundary is already showing a fallback state.
  14783. // Mark this subtree context as having at least one invisible parent that could
  14784. // handle the fallback state.
  14785. // Boundaries without fallbacks or should be avoided are not considered since
  14786. // they cannot handle preferred fallback states.
  14787. if (nextProps.fallback !== undefined && nextProps.unstable_avoidThisFallback !== true) {
  14788. suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
  14789. }
  14790. }
  14791. }
  14792. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  14793. pushSuspenseContext(workInProgress, suspenseContext); // This next part is a bit confusing. If the children timeout, we switch to
  14794. // showing the fallback children in place of the "primary" children.
  14795. // However, we don't want to delete the primary children because then their
  14796. // state will be lost (both the React state and the host state, e.g.
  14797. // uncontrolled form inputs). Instead we keep them mounted and hide them.
  14798. // Both the fallback children AND the primary children are rendered at the
  14799. // same time. Once the primary children are un-suspended, we can delete
  14800. // the fallback children — don't need to preserve their state.
  14801. //
  14802. // The two sets of children are siblings in the host environment, but
  14803. // semantically, for purposes of reconciliation, they are two separate sets.
  14804. // So we store them using two fragment fibers.
  14805. //
  14806. // However, we want to avoid allocating extra fibers for every placeholder.
  14807. // They're only necessary when the children time out, because that's the
  14808. // only time when both sets are mounted.
  14809. //
  14810. // So, the extra fragment fibers are only used if the children time out.
  14811. // Otherwise, we render the primary children directly. This requires some
  14812. // custom reconciliation logic to preserve the state of the primary
  14813. // children. It's essentially a very basic form of re-parenting.
  14814. if (current === null) {
  14815. // If we're currently hydrating, try to hydrate this boundary.
  14816. // But only if this has a fallback.
  14817. if (nextProps.fallback !== undefined) {
  14818. tryToClaimNextHydratableInstance(workInProgress); // This could've been a dehydrated suspense component.
  14819. } // This is the initial mount. This branch is pretty simple because there's
  14820. // no previous state that needs to be preserved.
  14821. if (nextDidTimeout) {
  14822. // Mount separate fragments for primary and fallback children.
  14823. var nextFallbackChildren = nextProps.fallback;
  14824. var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
  14825. primaryChildFragment.return = workInProgress;
  14826. if ((workInProgress.mode & BlockingMode) === NoMode) {
  14827. // Outside of blocking mode, we commit the effects from the
  14828. // partially completed, timed-out tree, too.
  14829. var progressedState = workInProgress.memoizedState;
  14830. var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
  14831. primaryChildFragment.child = progressedPrimaryChild;
  14832. var progressedChild = progressedPrimaryChild;
  14833. while (progressedChild !== null) {
  14834. progressedChild.return = primaryChildFragment;
  14835. progressedChild = progressedChild.sibling;
  14836. }
  14837. }
  14838. var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
  14839. fallbackChildFragment.return = workInProgress;
  14840. primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
  14841. // fallback children.
  14842. workInProgress.memoizedState = SUSPENDED_MARKER;
  14843. workInProgress.child = primaryChildFragment;
  14844. return fallbackChildFragment;
  14845. } else {
  14846. // Mount the primary children without an intermediate fragment fiber.
  14847. var nextPrimaryChildren = nextProps.children;
  14848. workInProgress.memoizedState = null;
  14849. return workInProgress.child = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
  14850. }
  14851. } else {
  14852. // This is an update. This branch is more complicated because we need to
  14853. // ensure the state of the primary children is preserved.
  14854. var prevState = current.memoizedState;
  14855. if (prevState !== null) {
  14856. // wrapped in a fragment fiber.
  14857. var currentPrimaryChildFragment = current.child;
  14858. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  14859. if (nextDidTimeout) {
  14860. // Still timed out. Reuse the current primary children by cloning
  14861. // its fragment. We're going to skip over these entirely.
  14862. var _nextFallbackChildren2 = nextProps.fallback;
  14863. var _primaryChildFragment2 = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps);
  14864. _primaryChildFragment2.return = workInProgress;
  14865. if ((workInProgress.mode & BlockingMode) === NoMode) {
  14866. // Outside of blocking mode, we commit the effects from the
  14867. // partially completed, timed-out tree, too.
  14868. var _progressedState = workInProgress.memoizedState;
  14869. var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
  14870. if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
  14871. _primaryChildFragment2.child = _progressedPrimaryChild;
  14872. var _progressedChild2 = _progressedPrimaryChild;
  14873. while (_progressedChild2 !== null) {
  14874. _progressedChild2.return = _primaryChildFragment2;
  14875. _progressedChild2 = _progressedChild2.sibling;
  14876. }
  14877. }
  14878. } // Because primaryChildFragment is a new fiber that we're inserting as the
  14879. // parent of a new tree, we need to set its treeBaseDuration.
  14880. if ( workInProgress.mode & ProfileMode) {
  14881. // treeBaseDuration is the sum of all the child tree base durations.
  14882. var _treeBaseDuration = 0;
  14883. var _hiddenChild = _primaryChildFragment2.child;
  14884. while (_hiddenChild !== null) {
  14885. _treeBaseDuration += _hiddenChild.treeBaseDuration;
  14886. _hiddenChild = _hiddenChild.sibling;
  14887. }
  14888. _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
  14889. } // Clone the fallback child fragment, too. These we'll continue
  14890. // working on.
  14891. var _fallbackChildFragment2 = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren2);
  14892. _fallbackChildFragment2.return = workInProgress;
  14893. _primaryChildFragment2.sibling = _fallbackChildFragment2;
  14894. _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  14895. // fallback children.
  14896. workInProgress.memoizedState = SUSPENDED_MARKER;
  14897. workInProgress.child = _primaryChildFragment2;
  14898. return _fallbackChildFragment2;
  14899. } else {
  14900. // No longer suspended. Switch back to showing the primary children,
  14901. // and remove the intermediate fragment fiber.
  14902. var _nextPrimaryChildren = nextProps.children;
  14903. var currentPrimaryChild = currentPrimaryChildFragment.child;
  14904. var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime); // If this render doesn't suspend, we need to delete the fallback
  14905. // children. Wait until the complete phase, after we've confirmed the
  14906. // fallback is no longer needed.
  14907. // TODO: Would it be better to store the fallback fragment on
  14908. // the stateNode?
  14909. // Continue rendering the children, like we normally do.
  14910. workInProgress.memoizedState = null;
  14911. return workInProgress.child = primaryChild;
  14912. }
  14913. } else {
  14914. // The current tree has not already timed out. That means the primary
  14915. // children are not wrapped in a fragment fiber.
  14916. var _currentPrimaryChild = current.child;
  14917. if (nextDidTimeout) {
  14918. // Timed out. Wrap the children in a fragment fiber to keep them
  14919. // separate from the fallback children.
  14920. var _nextFallbackChildren3 = nextProps.fallback;
  14921. var _primaryChildFragment3 = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
  14922. // going to render this fragment.
  14923. null, mode, NoWork, null);
  14924. _primaryChildFragment3.return = workInProgress;
  14925. _primaryChildFragment3.child = _currentPrimaryChild;
  14926. if (_currentPrimaryChild !== null) {
  14927. _currentPrimaryChild.return = _primaryChildFragment3;
  14928. } // Even though we're creating a new fiber, there are no new children,
  14929. // because we're reusing an already mounted tree. So we don't need to
  14930. // schedule a placement.
  14931. // primaryChildFragment.effectTag |= Placement;
  14932. if ((workInProgress.mode & BlockingMode) === NoMode) {
  14933. // Outside of blocking mode, we commit the effects from the
  14934. // partially completed, timed-out tree, too.
  14935. var _progressedState2 = workInProgress.memoizedState;
  14936. var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
  14937. _primaryChildFragment3.child = _progressedPrimaryChild2;
  14938. var _progressedChild3 = _progressedPrimaryChild2;
  14939. while (_progressedChild3 !== null) {
  14940. _progressedChild3.return = _primaryChildFragment3;
  14941. _progressedChild3 = _progressedChild3.sibling;
  14942. }
  14943. } // Because primaryChildFragment is a new fiber that we're inserting as the
  14944. // parent of a new tree, we need to set its treeBaseDuration.
  14945. if ( workInProgress.mode & ProfileMode) {
  14946. // treeBaseDuration is the sum of all the child tree base durations.
  14947. var _treeBaseDuration2 = 0;
  14948. var _hiddenChild2 = _primaryChildFragment3.child;
  14949. while (_hiddenChild2 !== null) {
  14950. _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
  14951. _hiddenChild2 = _hiddenChild2.sibling;
  14952. }
  14953. _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
  14954. } // Create a fragment from the fallback children, too.
  14955. var _fallbackChildFragment3 = createFiberFromFragment(_nextFallbackChildren3, mode, renderExpirationTime, null);
  14956. _fallbackChildFragment3.return = workInProgress;
  14957. _primaryChildFragment3.sibling = _fallbackChildFragment3;
  14958. _fallbackChildFragment3.effectTag |= Placement;
  14959. _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  14960. // fallback children.
  14961. workInProgress.memoizedState = SUSPENDED_MARKER;
  14962. workInProgress.child = _primaryChildFragment3;
  14963. return _fallbackChildFragment3;
  14964. } else {
  14965. // Still haven't timed out. Continue rendering the children, like we
  14966. // normally do.
  14967. workInProgress.memoizedState = null;
  14968. var _nextPrimaryChildren2 = nextProps.children;
  14969. return workInProgress.child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
  14970. }
  14971. }
  14972. }
  14973. }
  14974. function scheduleWorkOnFiber(fiber, renderExpirationTime) {
  14975. if (fiber.expirationTime < renderExpirationTime) {
  14976. fiber.expirationTime = renderExpirationTime;
  14977. }
  14978. var alternate = fiber.alternate;
  14979. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  14980. alternate.expirationTime = renderExpirationTime;
  14981. }
  14982. scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
  14983. }
  14984. function propagateSuspenseContextChange(workInProgress, firstChild, renderExpirationTime) {
  14985. // Mark any Suspense boundaries with fallbacks as having work to do.
  14986. // If they were previously forced into fallbacks, they may now be able
  14987. // to unblock.
  14988. var node = firstChild;
  14989. while (node !== null) {
  14990. if (node.tag === SuspenseComponent) {
  14991. var state = node.memoizedState;
  14992. if (state !== null) {
  14993. scheduleWorkOnFiber(node, renderExpirationTime);
  14994. }
  14995. } else if (node.tag === SuspenseListComponent) {
  14996. // If the tail is hidden there might not be an Suspense boundaries
  14997. // to schedule work on. In this case we have to schedule it on the
  14998. // list itself.
  14999. // We don't have to traverse to the children of the list since
  15000. // the list will propagate the change when it rerenders.
  15001. scheduleWorkOnFiber(node, renderExpirationTime);
  15002. } else if (node.child !== null) {
  15003. node.child.return = node;
  15004. node = node.child;
  15005. continue;
  15006. }
  15007. if (node === workInProgress) {
  15008. return;
  15009. }
  15010. while (node.sibling === null) {
  15011. if (node.return === null || node.return === workInProgress) {
  15012. return;
  15013. }
  15014. node = node.return;
  15015. }
  15016. node.sibling.return = node.return;
  15017. node = node.sibling;
  15018. }
  15019. }
  15020. function findLastContentRow(firstChild) {
  15021. // This is going to find the last row among these children that is already
  15022. // showing content on the screen, as opposed to being in fallback state or
  15023. // new. If a row has multiple Suspense boundaries, any of them being in the
  15024. // fallback state, counts as the whole row being in a fallback state.
  15025. // Note that the "rows" will be workInProgress, but any nested children
  15026. // will still be current since we haven't rendered them yet. The mounted
  15027. // order may not be the same as the new order. We use the new order.
  15028. var row = firstChild;
  15029. var lastContentRow = null;
  15030. while (row !== null) {
  15031. var currentRow = row.alternate; // New rows can't be content rows.
  15032. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  15033. lastContentRow = row;
  15034. }
  15035. row = row.sibling;
  15036. }
  15037. return lastContentRow;
  15038. }
  15039. function validateRevealOrder(revealOrder) {
  15040. {
  15041. if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
  15042. didWarnAboutRevealOrder[revealOrder] = true;
  15043. if (typeof revealOrder === 'string') {
  15044. switch (revealOrder.toLowerCase()) {
  15045. case 'together':
  15046. case 'forwards':
  15047. case 'backwards':
  15048. {
  15049. error('"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
  15050. break;
  15051. }
  15052. case 'forward':
  15053. case 'backward':
  15054. {
  15055. error('"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'React uses the -s suffix in the spelling. Use "%ss" instead.', revealOrder, revealOrder.toLowerCase());
  15056. break;
  15057. }
  15058. default:
  15059. error('"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  15060. break;
  15061. }
  15062. } else {
  15063. error('%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  15064. }
  15065. }
  15066. }
  15067. }
  15068. function validateTailOptions(tailMode, revealOrder) {
  15069. {
  15070. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  15071. if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
  15072. didWarnAboutTailOptions[tailMode] = true;
  15073. error('"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
  15074. } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
  15075. didWarnAboutTailOptions[tailMode] = true;
  15076. error('<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
  15077. }
  15078. }
  15079. }
  15080. }
  15081. function validateSuspenseListNestedChild(childSlot, index) {
  15082. {
  15083. var isArray = Array.isArray(childSlot);
  15084. var isIterable = !isArray && typeof getIteratorFn(childSlot) === 'function';
  15085. if (isArray || isIterable) {
  15086. var type = isArray ? 'array' : 'iterable';
  15087. error('A nested %s was passed to row #%s in <SuspenseList />. Wrap it in ' + 'an additional SuspenseList to configure its revealOrder: ' + '<SuspenseList revealOrder=...> ... ' + '<SuspenseList revealOrder=...>{%s}</SuspenseList> ... ' + '</SuspenseList>', type, index, type);
  15088. return false;
  15089. }
  15090. }
  15091. return true;
  15092. }
  15093. function validateSuspenseListChildren(children, revealOrder) {
  15094. {
  15095. if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
  15096. if (Array.isArray(children)) {
  15097. for (var i = 0; i < children.length; i++) {
  15098. if (!validateSuspenseListNestedChild(children[i], i)) {
  15099. return;
  15100. }
  15101. }
  15102. } else {
  15103. var iteratorFn = getIteratorFn(children);
  15104. if (typeof iteratorFn === 'function') {
  15105. var childrenIterator = iteratorFn.call(children);
  15106. if (childrenIterator) {
  15107. var step = childrenIterator.next();
  15108. var _i = 0;
  15109. for (; !step.done; step = childrenIterator.next()) {
  15110. if (!validateSuspenseListNestedChild(step.value, _i)) {
  15111. return;
  15112. }
  15113. _i++;
  15114. }
  15115. }
  15116. } else {
  15117. error('A single row was passed to a <SuspenseList revealOrder="%s" />. ' + 'This is not useful since it needs multiple rows. ' + 'Did you mean to pass multiple children or an array?', revealOrder);
  15118. }
  15119. }
  15120. }
  15121. }
  15122. }
  15123. function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode, lastEffectBeforeRendering) {
  15124. var renderState = workInProgress.memoizedState;
  15125. if (renderState === null) {
  15126. workInProgress.memoizedState = {
  15127. isBackwards: isBackwards,
  15128. rendering: null,
  15129. renderingStartTime: 0,
  15130. last: lastContentRow,
  15131. tail: tail,
  15132. tailExpiration: 0,
  15133. tailMode: tailMode,
  15134. lastEffect: lastEffectBeforeRendering
  15135. };
  15136. } else {
  15137. // We can reuse the existing object from previous renders.
  15138. renderState.isBackwards = isBackwards;
  15139. renderState.rendering = null;
  15140. renderState.renderingStartTime = 0;
  15141. renderState.last = lastContentRow;
  15142. renderState.tail = tail;
  15143. renderState.tailExpiration = 0;
  15144. renderState.tailMode = tailMode;
  15145. renderState.lastEffect = lastEffectBeforeRendering;
  15146. }
  15147. } // This can end up rendering this component multiple passes.
  15148. // The first pass splits the children fibers into two sets. A head and tail.
  15149. // We first render the head. If anything is in fallback state, we do another
  15150. // pass through beginWork to rerender all children (including the tail) with
  15151. // the force suspend context. If the first render didn't have anything in
  15152. // in fallback state. Then we render each row in the tail one-by-one.
  15153. // That happens in the completeWork phase without going back to beginWork.
  15154. function updateSuspenseListComponent(current, workInProgress, renderExpirationTime) {
  15155. var nextProps = workInProgress.pendingProps;
  15156. var revealOrder = nextProps.revealOrder;
  15157. var tailMode = nextProps.tail;
  15158. var newChildren = nextProps.children;
  15159. validateRevealOrder(revealOrder);
  15160. validateTailOptions(tailMode, revealOrder);
  15161. validateSuspenseListChildren(newChildren, revealOrder);
  15162. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  15163. var suspenseContext = suspenseStackCursor.current;
  15164. var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
  15165. if (shouldForceFallback) {
  15166. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  15167. workInProgress.effectTag |= DidCapture;
  15168. } else {
  15169. var didSuspendBefore = current !== null && (current.effectTag & DidCapture) !== NoEffect;
  15170. if (didSuspendBefore) {
  15171. // If we previously forced a fallback, we need to schedule work
  15172. // on any nested boundaries to let them know to try to render
  15173. // again. This is the same as context updating.
  15174. propagateSuspenseContextChange(workInProgress, workInProgress.child, renderExpirationTime);
  15175. }
  15176. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  15177. }
  15178. pushSuspenseContext(workInProgress, suspenseContext);
  15179. if ((workInProgress.mode & BlockingMode) === NoMode) {
  15180. // Outside of blocking mode, SuspenseList doesn't work so we just
  15181. // use make it a noop by treating it as the default revealOrder.
  15182. workInProgress.memoizedState = null;
  15183. } else {
  15184. switch (revealOrder) {
  15185. case 'forwards':
  15186. {
  15187. var lastContentRow = findLastContentRow(workInProgress.child);
  15188. var tail;
  15189. if (lastContentRow === null) {
  15190. // The whole list is part of the tail.
  15191. // TODO: We could fast path by just rendering the tail now.
  15192. tail = workInProgress.child;
  15193. workInProgress.child = null;
  15194. } else {
  15195. // Disconnect the tail rows after the content row.
  15196. // We're going to render them separately later.
  15197. tail = lastContentRow.sibling;
  15198. lastContentRow.sibling = null;
  15199. }
  15200. initSuspenseListRenderState(workInProgress, false, // isBackwards
  15201. tail, lastContentRow, tailMode, workInProgress.lastEffect);
  15202. break;
  15203. }
  15204. case 'backwards':
  15205. {
  15206. // We're going to find the first row that has existing content.
  15207. // At the same time we're going to reverse the list of everything
  15208. // we pass in the meantime. That's going to be our tail in reverse
  15209. // order.
  15210. var _tail = null;
  15211. var row = workInProgress.child;
  15212. workInProgress.child = null;
  15213. while (row !== null) {
  15214. var currentRow = row.alternate; // New rows can't be content rows.
  15215. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  15216. // This is the beginning of the main content.
  15217. workInProgress.child = row;
  15218. break;
  15219. }
  15220. var nextRow = row.sibling;
  15221. row.sibling = _tail;
  15222. _tail = row;
  15223. row = nextRow;
  15224. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  15225. initSuspenseListRenderState(workInProgress, true, // isBackwards
  15226. _tail, null, // last
  15227. tailMode, workInProgress.lastEffect);
  15228. break;
  15229. }
  15230. case 'together':
  15231. {
  15232. initSuspenseListRenderState(workInProgress, false, // isBackwards
  15233. null, // tail
  15234. null, // last
  15235. undefined, workInProgress.lastEffect);
  15236. break;
  15237. }
  15238. default:
  15239. {
  15240. // The default reveal order is the same as not having
  15241. // a boundary.
  15242. workInProgress.memoizedState = null;
  15243. }
  15244. }
  15245. }
  15246. return workInProgress.child;
  15247. }
  15248. function updatePortalComponent(current, workInProgress, renderExpirationTime) {
  15249. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  15250. var nextChildren = workInProgress.pendingProps;
  15251. if (current === null) {
  15252. // Portals are special because we don't append the children during mount
  15253. // but at commit. Therefore we need to track insertions which the normal
  15254. // flow doesn't do during mount. This doesn't happen at the root because
  15255. // the root always starts with a "current" with a null child.
  15256. // TODO: Consider unifying this with how the root works.
  15257. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  15258. } else {
  15259. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  15260. }
  15261. return workInProgress.child;
  15262. }
  15263. function updateContextProvider(current, workInProgress, renderExpirationTime) {
  15264. var providerType = workInProgress.type;
  15265. var context = providerType._context;
  15266. var newProps = workInProgress.pendingProps;
  15267. var oldProps = workInProgress.memoizedProps;
  15268. var newValue = newProps.value;
  15269. {
  15270. var providerPropTypes = workInProgress.type.propTypes;
  15271. if (providerPropTypes) {
  15272. checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
  15273. }
  15274. }
  15275. pushProvider(workInProgress, newValue);
  15276. if (oldProps !== null) {
  15277. var oldValue = oldProps.value;
  15278. var changedBits = calculateChangedBits(context, newValue, oldValue);
  15279. if (changedBits === 0) {
  15280. // No change. Bailout early if children are the same.
  15281. if (oldProps.children === newProps.children && !hasContextChanged()) {
  15282. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  15283. }
  15284. } else {
  15285. // The context value changed. Search for matching consumers and schedule
  15286. // them to update.
  15287. propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
  15288. }
  15289. }
  15290. var newChildren = newProps.children;
  15291. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  15292. return workInProgress.child;
  15293. }
  15294. var hasWarnedAboutUsingContextAsConsumer = false;
  15295. function updateContextConsumer(current, workInProgress, renderExpirationTime) {
  15296. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  15297. // DEV mode, we create a separate object for Context.Consumer that acts
  15298. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  15299. // so we use the old behaviour (Context.Consumer references Context) to
  15300. // reduce size and overhead. The separate object references context via
  15301. // a property called "_context", which also gives us the ability to check
  15302. // in DEV mode if this property exists or not and warn if it does not.
  15303. {
  15304. if (context._context === undefined) {
  15305. // This may be because it's a Context (rather than a Consumer).
  15306. // Or it may be because it's older React where they're the same thing.
  15307. // We only want to warn if we're sure it's a new React.
  15308. if (context !== context.Consumer) {
  15309. if (!hasWarnedAboutUsingContextAsConsumer) {
  15310. hasWarnedAboutUsingContextAsConsumer = true;
  15311. error('Rendering <Context> directly is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
  15312. }
  15313. }
  15314. } else {
  15315. context = context._context;
  15316. }
  15317. }
  15318. var newProps = workInProgress.pendingProps;
  15319. var render = newProps.children;
  15320. {
  15321. if (typeof render !== 'function') {
  15322. error('A context consumer was rendered with multiple children, or a child ' + "that isn't a function. A context consumer expects a single child " + 'that is a function. If you did pass a function, make sure there ' + 'is no trailing or leading whitespace around it.');
  15323. }
  15324. }
  15325. prepareToReadContext(workInProgress, renderExpirationTime);
  15326. var newValue = readContext(context, newProps.unstable_observedBits);
  15327. var newChildren;
  15328. {
  15329. ReactCurrentOwner$1.current = workInProgress;
  15330. setIsRendering(true);
  15331. newChildren = render(newValue);
  15332. setIsRendering(false);
  15333. } // React DevTools reads this flag.
  15334. workInProgress.effectTag |= PerformedWork;
  15335. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  15336. return workInProgress.child;
  15337. }
  15338. function markWorkInProgressReceivedUpdate() {
  15339. didReceiveUpdate = true;
  15340. }
  15341. function bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime) {
  15342. cancelWorkTimer(workInProgress);
  15343. if (current !== null) {
  15344. // Reuse previous dependencies
  15345. workInProgress.dependencies = current.dependencies;
  15346. }
  15347. {
  15348. // Don't update "base" render times for bailouts.
  15349. stopProfilerTimerIfRunning();
  15350. }
  15351. var updateExpirationTime = workInProgress.expirationTime;
  15352. if (updateExpirationTime !== NoWork) {
  15353. markUnprocessedUpdateTime(updateExpirationTime);
  15354. } // Check if the children have any pending work.
  15355. var childExpirationTime = workInProgress.childExpirationTime;
  15356. if (childExpirationTime < renderExpirationTime) {
  15357. // The children don't have any work either. We can skip them.
  15358. // TODO: Once we add back resuming, we should check if the children are
  15359. // a work-in-progress set. If so, we need to transfer their effects.
  15360. return null;
  15361. } else {
  15362. // This fiber doesn't have work, but its subtree does. Clone the child
  15363. // fibers and continue.
  15364. cloneChildFibers(current, workInProgress);
  15365. return workInProgress.child;
  15366. }
  15367. }
  15368. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  15369. {
  15370. var returnFiber = oldWorkInProgress.return;
  15371. if (returnFiber === null) {
  15372. throw new Error('Cannot swap the root fiber.');
  15373. } // Disconnect from the old current.
  15374. // It will get deleted.
  15375. current.alternate = null;
  15376. oldWorkInProgress.alternate = null; // Connect to the new tree.
  15377. newWorkInProgress.index = oldWorkInProgress.index;
  15378. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  15379. newWorkInProgress.return = oldWorkInProgress.return;
  15380. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  15381. if (oldWorkInProgress === returnFiber.child) {
  15382. returnFiber.child = newWorkInProgress;
  15383. } else {
  15384. var prevSibling = returnFiber.child;
  15385. if (prevSibling === null) {
  15386. throw new Error('Expected parent to have a child.');
  15387. }
  15388. while (prevSibling.sibling !== oldWorkInProgress) {
  15389. prevSibling = prevSibling.sibling;
  15390. if (prevSibling === null) {
  15391. throw new Error('Expected to find the previous sibling.');
  15392. }
  15393. }
  15394. prevSibling.sibling = newWorkInProgress;
  15395. } // Delete the old fiber and place the new one.
  15396. // Since the old fiber is disconnected, we have to schedule it manually.
  15397. var last = returnFiber.lastEffect;
  15398. if (last !== null) {
  15399. last.nextEffect = current;
  15400. returnFiber.lastEffect = current;
  15401. } else {
  15402. returnFiber.firstEffect = returnFiber.lastEffect = current;
  15403. }
  15404. current.nextEffect = null;
  15405. current.effectTag = Deletion;
  15406. newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
  15407. return newWorkInProgress;
  15408. }
  15409. }
  15410. function beginWork(current, workInProgress, renderExpirationTime) {
  15411. var updateExpirationTime = workInProgress.expirationTime;
  15412. {
  15413. if (workInProgress._debugNeedsRemount && current !== null) {
  15414. // This will restart the begin phase with a new fiber.
  15415. return remountFiber(current, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.expirationTime));
  15416. }
  15417. }
  15418. if (current !== null) {
  15419. var oldProps = current.memoizedProps;
  15420. var newProps = workInProgress.pendingProps;
  15421. if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
  15422. workInProgress.type !== current.type )) {
  15423. // If props or context changed, mark the fiber as having performed work.
  15424. // This may be unset if the props are determined to be equal later (memo).
  15425. didReceiveUpdate = true;
  15426. } else if (updateExpirationTime < renderExpirationTime) {
  15427. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  15428. // the begin phase. There's still some bookkeeping we that needs to be done
  15429. // in this optimized path, mostly pushing stuff onto the stack.
  15430. switch (workInProgress.tag) {
  15431. case HostRoot:
  15432. pushHostRootContext(workInProgress);
  15433. resetHydrationState();
  15434. break;
  15435. case HostComponent:
  15436. pushHostContext(workInProgress);
  15437. if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(workInProgress.type, newProps)) {
  15438. {
  15439. markSpawnedWork(Never);
  15440. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  15441. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  15442. return null;
  15443. }
  15444. break;
  15445. case ClassComponent:
  15446. {
  15447. var Component = workInProgress.type;
  15448. if (isContextProvider(Component)) {
  15449. pushContextProvider(workInProgress);
  15450. }
  15451. break;
  15452. }
  15453. case HostPortal:
  15454. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  15455. break;
  15456. case ContextProvider:
  15457. {
  15458. var newValue = workInProgress.memoizedProps.value;
  15459. pushProvider(workInProgress, newValue);
  15460. break;
  15461. }
  15462. case Profiler:
  15463. {
  15464. // Profiler should only call onRender when one of its descendants actually rendered.
  15465. var hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
  15466. if (hasChildWork) {
  15467. workInProgress.effectTag |= Update;
  15468. }
  15469. }
  15470. break;
  15471. case SuspenseComponent:
  15472. {
  15473. var state = workInProgress.memoizedState;
  15474. if (state !== null) {
  15475. // whether to retry the primary children, or to skip over it and
  15476. // go straight to the fallback. Check the priority of the primary
  15477. // child fragment.
  15478. var primaryChildFragment = workInProgress.child;
  15479. var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
  15480. if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
  15481. // The primary children have pending work. Use the normal path
  15482. // to attempt to render the primary children again.
  15483. return updateSuspenseComponent(current, workInProgress, renderExpirationTime);
  15484. } else {
  15485. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
  15486. // priority. Bailout.
  15487. var child = bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  15488. if (child !== null) {
  15489. // The fallback children have pending work. Skip over the
  15490. // primary children and work on the fallback.
  15491. return child.sibling;
  15492. } else {
  15493. return null;
  15494. }
  15495. }
  15496. } else {
  15497. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
  15498. }
  15499. break;
  15500. }
  15501. case SuspenseListComponent:
  15502. {
  15503. var didSuspendBefore = (current.effectTag & DidCapture) !== NoEffect;
  15504. var _hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
  15505. if (didSuspendBefore) {
  15506. if (_hasChildWork) {
  15507. // If something was in fallback state last time, and we have all the
  15508. // same children then we're still in progressive loading state.
  15509. // Something might get unblocked by state updates or retries in the
  15510. // tree which will affect the tail. So we need to use the normal
  15511. // path to compute the correct tail.
  15512. return updateSuspenseListComponent(current, workInProgress, renderExpirationTime);
  15513. } // If none of the children had any work, that means that none of
  15514. // them got retried so they'll still be blocked in the same way
  15515. // as before. We can fast bail out.
  15516. workInProgress.effectTag |= DidCapture;
  15517. } // If nothing suspended before and we're rendering the same children,
  15518. // then the tail doesn't matter. Anything new that suspends will work
  15519. // in the "together" mode, so we can continue from the state we had.
  15520. var renderState = workInProgress.memoizedState;
  15521. if (renderState !== null) {
  15522. // Reset to the "together" mode in case we've started a different
  15523. // update in the past but didn't complete it.
  15524. renderState.rendering = null;
  15525. renderState.tail = null;
  15526. }
  15527. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  15528. if (_hasChildWork) {
  15529. break;
  15530. } else {
  15531. // If none of the children had any work, that means that none of
  15532. // them got retried so they'll still be blocked in the same way
  15533. // as before. We can fast bail out.
  15534. return null;
  15535. }
  15536. }
  15537. }
  15538. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  15539. } else {
  15540. // An update was scheduled on this fiber, but there are no new props
  15541. // nor legacy context. Set this to false. If an update queue or context
  15542. // consumer produces a changed value, it will set this to true. Otherwise,
  15543. // the component will assume the children have not changed and bail out.
  15544. didReceiveUpdate = false;
  15545. }
  15546. } else {
  15547. didReceiveUpdate = false;
  15548. } // Before entering the begin phase, clear pending update priority.
  15549. // TODO: This assumes that we're about to evaluate the component and process
  15550. // the update queue. However, there's an exception: SimpleMemoComponent
  15551. // sometimes bails out later in the begin phase. This indicates that we should
  15552. // move this assignment out of the common path and into each branch.
  15553. workInProgress.expirationTime = NoWork;
  15554. switch (workInProgress.tag) {
  15555. case IndeterminateComponent:
  15556. {
  15557. return mountIndeterminateComponent(current, workInProgress, workInProgress.type, renderExpirationTime);
  15558. }
  15559. case LazyComponent:
  15560. {
  15561. var elementType = workInProgress.elementType;
  15562. return mountLazyComponent(current, workInProgress, elementType, updateExpirationTime, renderExpirationTime);
  15563. }
  15564. case FunctionComponent:
  15565. {
  15566. var _Component = workInProgress.type;
  15567. var unresolvedProps = workInProgress.pendingProps;
  15568. var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
  15569. return updateFunctionComponent(current, workInProgress, _Component, resolvedProps, renderExpirationTime);
  15570. }
  15571. case ClassComponent:
  15572. {
  15573. var _Component2 = workInProgress.type;
  15574. var _unresolvedProps = workInProgress.pendingProps;
  15575. var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
  15576. return updateClassComponent(current, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
  15577. }
  15578. case HostRoot:
  15579. return updateHostRoot(current, workInProgress, renderExpirationTime);
  15580. case HostComponent:
  15581. return updateHostComponent(current, workInProgress, renderExpirationTime);
  15582. case HostText:
  15583. return updateHostText(current, workInProgress);
  15584. case SuspenseComponent:
  15585. return updateSuspenseComponent(current, workInProgress, renderExpirationTime);
  15586. case HostPortal:
  15587. return updatePortalComponent(current, workInProgress, renderExpirationTime);
  15588. case ForwardRef:
  15589. {
  15590. var type = workInProgress.type;
  15591. var _unresolvedProps2 = workInProgress.pendingProps;
  15592. var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
  15593. return updateForwardRef(current, workInProgress, type, _resolvedProps2, renderExpirationTime);
  15594. }
  15595. case Fragment:
  15596. return updateFragment(current, workInProgress, renderExpirationTime);
  15597. case Mode:
  15598. return updateMode(current, workInProgress, renderExpirationTime);
  15599. case Profiler:
  15600. return updateProfiler(current, workInProgress, renderExpirationTime);
  15601. case ContextProvider:
  15602. return updateContextProvider(current, workInProgress, renderExpirationTime);
  15603. case ContextConsumer:
  15604. return updateContextConsumer(current, workInProgress, renderExpirationTime);
  15605. case MemoComponent:
  15606. {
  15607. var _type2 = workInProgress.type;
  15608. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  15609. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  15610. {
  15611. if (workInProgress.type !== workInProgress.elementType) {
  15612. var outerPropTypes = _type2.propTypes;
  15613. if (outerPropTypes) {
  15614. checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
  15615. 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
  15616. }
  15617. }
  15618. }
  15619. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  15620. return updateMemoComponent(current, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
  15621. }
  15622. case SimpleMemoComponent:
  15623. {
  15624. return updateSimpleMemoComponent(current, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
  15625. }
  15626. case IncompleteClassComponent:
  15627. {
  15628. var _Component3 = workInProgress.type;
  15629. var _unresolvedProps4 = workInProgress.pendingProps;
  15630. var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
  15631. return mountIncompleteClassComponent(current, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
  15632. }
  15633. case SuspenseListComponent:
  15634. {
  15635. return updateSuspenseListComponent(current, workInProgress, renderExpirationTime);
  15636. }
  15637. }
  15638. {
  15639. {
  15640. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  15641. }
  15642. }
  15643. }
  15644. function markUpdate(workInProgress) {
  15645. // Tag the fiber with an update effect. This turns a Placement into
  15646. // a PlacementAndUpdate.
  15647. workInProgress.effectTag |= Update;
  15648. }
  15649. function markRef$1(workInProgress) {
  15650. workInProgress.effectTag |= Ref;
  15651. }
  15652. var appendAllChildren;
  15653. var updateHostContainer;
  15654. var updateHostComponent$1;
  15655. var updateHostText$1;
  15656. {
  15657. // Mutation mode
  15658. appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
  15659. // We only have the top Fiber that was created but we need recurse down its
  15660. // children to find all the terminal nodes.
  15661. var node = workInProgress.child;
  15662. while (node !== null) {
  15663. if (node.tag === HostComponent || node.tag === HostText) {
  15664. appendInitialChild(parent, node.stateNode);
  15665. } else if (node.tag === HostPortal) ; else if (node.child !== null) {
  15666. node.child.return = node;
  15667. node = node.child;
  15668. continue;
  15669. }
  15670. if (node === workInProgress) {
  15671. return;
  15672. }
  15673. while (node.sibling === null) {
  15674. if (node.return === null || node.return === workInProgress) {
  15675. return;
  15676. }
  15677. node = node.return;
  15678. }
  15679. node.sibling.return = node.return;
  15680. node = node.sibling;
  15681. }
  15682. };
  15683. updateHostContainer = function (workInProgress) {// Noop
  15684. };
  15685. updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
  15686. // If we have an alternate, that means this is an update and we need to
  15687. // schedule a side-effect to do the updates.
  15688. var oldProps = current.memoizedProps;
  15689. if (oldProps === newProps) {
  15690. // In mutation mode, this is sufficient for a bailout because
  15691. // we won't touch this node even if children changed.
  15692. return;
  15693. } // If we get updated because one of our children updated, we don't
  15694. // have newProps so we'll have to reuse them.
  15695. // TODO: Split the update API as separate for the props vs. children.
  15696. // Even better would be if children weren't special cased at all tho.
  15697. var instance = workInProgress.stateNode;
  15698. var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
  15699. // component is hitting the resume path. Figure out why. Possibly
  15700. // related to `hidden`.
  15701. var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext); // TODO: Type this specific to this type of component.
  15702. workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  15703. // is a new ref we mark this as an update. All the work is done in commitWork.
  15704. if (updatePayload) {
  15705. markUpdate(workInProgress);
  15706. }
  15707. };
  15708. updateHostText$1 = function (current, workInProgress, oldText, newText) {
  15709. // If the text differs, mark it as an update. All the work in done in commitWork.
  15710. if (oldText !== newText) {
  15711. markUpdate(workInProgress);
  15712. }
  15713. };
  15714. }
  15715. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  15716. switch (renderState.tailMode) {
  15717. case 'hidden':
  15718. {
  15719. // Any insertions at the end of the tail list after this point
  15720. // should be invisible. If there are already mounted boundaries
  15721. // anything before them are not considered for collapsing.
  15722. // Therefore we need to go through the whole tail to find if
  15723. // there are any.
  15724. var tailNode = renderState.tail;
  15725. var lastTailNode = null;
  15726. while (tailNode !== null) {
  15727. if (tailNode.alternate !== null) {
  15728. lastTailNode = tailNode;
  15729. }
  15730. tailNode = tailNode.sibling;
  15731. } // Next we're simply going to delete all insertions after the
  15732. // last rendered item.
  15733. if (lastTailNode === null) {
  15734. // All remaining items in the tail are insertions.
  15735. renderState.tail = null;
  15736. } else {
  15737. // Detach the insertion after the last node that was already
  15738. // inserted.
  15739. lastTailNode.sibling = null;
  15740. }
  15741. break;
  15742. }
  15743. case 'collapsed':
  15744. {
  15745. // Any insertions at the end of the tail list after this point
  15746. // should be invisible. If there are already mounted boundaries
  15747. // anything before them are not considered for collapsing.
  15748. // Therefore we need to go through the whole tail to find if
  15749. // there are any.
  15750. var _tailNode = renderState.tail;
  15751. var _lastTailNode = null;
  15752. while (_tailNode !== null) {
  15753. if (_tailNode.alternate !== null) {
  15754. _lastTailNode = _tailNode;
  15755. }
  15756. _tailNode = _tailNode.sibling;
  15757. } // Next we're simply going to delete all insertions after the
  15758. // last rendered item.
  15759. if (_lastTailNode === null) {
  15760. // All remaining items in the tail are insertions.
  15761. if (!hasRenderedATailFallback && renderState.tail !== null) {
  15762. // We suspended during the head. We want to show at least one
  15763. // row at the tail. So we'll keep on and cut off the rest.
  15764. renderState.tail.sibling = null;
  15765. } else {
  15766. renderState.tail = null;
  15767. }
  15768. } else {
  15769. // Detach the insertion after the last node that was already
  15770. // inserted.
  15771. _lastTailNode.sibling = null;
  15772. }
  15773. break;
  15774. }
  15775. }
  15776. }
  15777. function completeWork(current, workInProgress, renderExpirationTime) {
  15778. var newProps = workInProgress.pendingProps;
  15779. switch (workInProgress.tag) {
  15780. case IndeterminateComponent:
  15781. case LazyComponent:
  15782. case SimpleMemoComponent:
  15783. case FunctionComponent:
  15784. case ForwardRef:
  15785. case Fragment:
  15786. case Mode:
  15787. case Profiler:
  15788. case ContextConsumer:
  15789. case MemoComponent:
  15790. return null;
  15791. case ClassComponent:
  15792. {
  15793. var Component = workInProgress.type;
  15794. if (isContextProvider(Component)) {
  15795. popContext(workInProgress);
  15796. }
  15797. return null;
  15798. }
  15799. case HostRoot:
  15800. {
  15801. popHostContainer(workInProgress);
  15802. popTopLevelContextObject(workInProgress);
  15803. var fiberRoot = workInProgress.stateNode;
  15804. if (fiberRoot.pendingContext) {
  15805. fiberRoot.context = fiberRoot.pendingContext;
  15806. fiberRoot.pendingContext = null;
  15807. }
  15808. if (current === null || current.child === null) {
  15809. // If we hydrated, pop so that we can delete any remaining children
  15810. // that weren't hydrated.
  15811. var wasHydrated = popHydrationState(workInProgress);
  15812. if (wasHydrated) {
  15813. // If we hydrated, then we'll need to schedule an update for
  15814. // the commit side-effects on the root.
  15815. markUpdate(workInProgress);
  15816. }
  15817. }
  15818. updateHostContainer(workInProgress);
  15819. return null;
  15820. }
  15821. case HostComponent:
  15822. {
  15823. popHostContext(workInProgress);
  15824. var rootContainerInstance = getRootHostContainer();
  15825. var type = workInProgress.type;
  15826. if (current !== null && workInProgress.stateNode != null) {
  15827. updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
  15828. if (current.ref !== workInProgress.ref) {
  15829. markRef$1(workInProgress);
  15830. }
  15831. } else {
  15832. if (!newProps) {
  15833. if (!(workInProgress.stateNode !== null)) {
  15834. {
  15835. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  15836. }
  15837. } // This can happen when we abort work.
  15838. return null;
  15839. }
  15840. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  15841. // "stack" as the parent. Then append children as we go in beginWork
  15842. // or completeWork depending on whether we want to add them top->down or
  15843. // bottom->up. Top->down is faster in IE11.
  15844. var _wasHydrated = popHydrationState(workInProgress);
  15845. if (_wasHydrated) {
  15846. // TODO: Move this and createInstance step into the beginPhase
  15847. // to consolidate.
  15848. if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
  15849. // If changes to the hydrated node need to be applied at the
  15850. // commit-phase we mark this as such.
  15851. markUpdate(workInProgress);
  15852. }
  15853. } else {
  15854. var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
  15855. appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
  15856. workInProgress.stateNode = instance;
  15857. // (eg DOM renderer supports auto-focus for certain elements).
  15858. // Make sure such renderers get scheduled for later work.
  15859. if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance)) {
  15860. markUpdate(workInProgress);
  15861. }
  15862. }
  15863. if (workInProgress.ref !== null) {
  15864. // If there is a ref on a host node we need to schedule a callback
  15865. markRef$1(workInProgress);
  15866. }
  15867. }
  15868. return null;
  15869. }
  15870. case HostText:
  15871. {
  15872. var newText = newProps;
  15873. if (current && workInProgress.stateNode != null) {
  15874. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  15875. // to schedule a side-effect to do the updates.
  15876. updateHostText$1(current, workInProgress, oldText, newText);
  15877. } else {
  15878. if (typeof newText !== 'string') {
  15879. if (!(workInProgress.stateNode !== null)) {
  15880. {
  15881. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  15882. }
  15883. } // This can happen when we abort work.
  15884. }
  15885. var _rootContainerInstance = getRootHostContainer();
  15886. var _currentHostContext = getHostContext();
  15887. var _wasHydrated2 = popHydrationState(workInProgress);
  15888. if (_wasHydrated2) {
  15889. if (prepareToHydrateHostTextInstance(workInProgress)) {
  15890. markUpdate(workInProgress);
  15891. }
  15892. } else {
  15893. workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
  15894. }
  15895. }
  15896. return null;
  15897. }
  15898. case SuspenseComponent:
  15899. {
  15900. popSuspenseContext(workInProgress);
  15901. var nextState = workInProgress.memoizedState;
  15902. if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
  15903. // Something suspended. Re-render with the fallback children.
  15904. workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
  15905. return workInProgress;
  15906. }
  15907. var nextDidTimeout = nextState !== null;
  15908. var prevDidTimeout = false;
  15909. if (current === null) {
  15910. if (workInProgress.memoizedProps.fallback !== undefined) {
  15911. popHydrationState(workInProgress);
  15912. }
  15913. } else {
  15914. var prevState = current.memoizedState;
  15915. prevDidTimeout = prevState !== null;
  15916. if (!nextDidTimeout && prevState !== null) {
  15917. // We just switched from the fallback to the normal children.
  15918. // Delete the fallback.
  15919. // TODO: Would it be better to store the fallback fragment on
  15920. // the stateNode during the begin phase?
  15921. var currentFallbackChild = current.child.sibling;
  15922. if (currentFallbackChild !== null) {
  15923. // Deletions go at the beginning of the return fiber's effect list
  15924. var first = workInProgress.firstEffect;
  15925. if (first !== null) {
  15926. workInProgress.firstEffect = currentFallbackChild;
  15927. currentFallbackChild.nextEffect = first;
  15928. } else {
  15929. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
  15930. currentFallbackChild.nextEffect = null;
  15931. }
  15932. currentFallbackChild.effectTag = Deletion;
  15933. }
  15934. }
  15935. }
  15936. if (nextDidTimeout && !prevDidTimeout) {
  15937. // If this subtreee is running in blocking mode we can suspend,
  15938. // otherwise we won't suspend.
  15939. // TODO: This will still suspend a synchronous tree if anything
  15940. // in the concurrent tree already suspended during this render.
  15941. // This is a known bug.
  15942. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  15943. // TODO: Move this back to throwException because this is too late
  15944. // if this is a large tree which is common for initial loads. We
  15945. // don't know if we should restart a render or not until we get
  15946. // this marker, and this is too late.
  15947. // If this render already had a ping or lower pri updates,
  15948. // and this is the first time we know we're going to suspend we
  15949. // should be able to immediately restart from within throwException.
  15950. var hasInvisibleChildContext = current === null && workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  15951. if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
  15952. // If this was in an invisible tree or a new render, then showing
  15953. // this boundary is ok.
  15954. renderDidSuspend();
  15955. } else {
  15956. // Otherwise, we're going to have to hide content so we should
  15957. // suspend for longer if possible.
  15958. renderDidSuspendDelayIfPossible();
  15959. }
  15960. }
  15961. }
  15962. {
  15963. // TODO: Only schedule updates if these values are non equal, i.e. it changed.
  15964. if (nextDidTimeout || prevDidTimeout) {
  15965. // If this boundary just timed out, schedule an effect to attach a
  15966. // retry listener to the promise. This flag is also used to hide the
  15967. // primary children. In mutation mode, we also need the flag to
  15968. // *unhide* children that were previously hidden, so check if this
  15969. // is currently timed out, too.
  15970. workInProgress.effectTag |= Update;
  15971. }
  15972. }
  15973. return null;
  15974. }
  15975. case HostPortal:
  15976. popHostContainer(workInProgress);
  15977. updateHostContainer(workInProgress);
  15978. return null;
  15979. case ContextProvider:
  15980. // Pop provider fiber
  15981. popProvider(workInProgress);
  15982. return null;
  15983. case IncompleteClassComponent:
  15984. {
  15985. // Same as class component case. I put it down here so that the tags are
  15986. // sequential to ensure this switch is compiled to a jump table.
  15987. var _Component = workInProgress.type;
  15988. if (isContextProvider(_Component)) {
  15989. popContext(workInProgress);
  15990. }
  15991. return null;
  15992. }
  15993. case SuspenseListComponent:
  15994. {
  15995. popSuspenseContext(workInProgress);
  15996. var renderState = workInProgress.memoizedState;
  15997. if (renderState === null) {
  15998. // We're running in the default, "independent" mode.
  15999. // We don't do anything in this mode.
  16000. return null;
  16001. }
  16002. var didSuspendAlready = (workInProgress.effectTag & DidCapture) !== NoEffect;
  16003. var renderedTail = renderState.rendering;
  16004. if (renderedTail === null) {
  16005. // We just rendered the head.
  16006. if (!didSuspendAlready) {
  16007. // This is the first pass. We need to figure out if anything is still
  16008. // suspended in the rendered set.
  16009. // If new content unsuspended, but there's still some content that
  16010. // didn't. Then we need to do a second pass that forces everything
  16011. // to keep showing their fallbacks.
  16012. // We might be suspended if something in this render pass suspended, or
  16013. // something in the previous committed pass suspended. Otherwise,
  16014. // there's no chance so we can skip the expensive call to
  16015. // findFirstSuspended.
  16016. var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.effectTag & DidCapture) === NoEffect);
  16017. if (!cannotBeSuspended) {
  16018. var row = workInProgress.child;
  16019. while (row !== null) {
  16020. var suspended = findFirstSuspended(row);
  16021. if (suspended !== null) {
  16022. didSuspendAlready = true;
  16023. workInProgress.effectTag |= DidCapture;
  16024. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  16025. // part of the second pass. In that case nothing will subscribe to
  16026. // its thennables. Instead, we'll transfer its thennables to the
  16027. // SuspenseList so that it can retry if they resolve.
  16028. // There might be multiple of these in the list but since we're
  16029. // going to wait for all of them anyway, it doesn't really matter
  16030. // which ones gets to ping. In theory we could get clever and keep
  16031. // track of how many dependencies remain but it gets tricky because
  16032. // in the meantime, we can add/remove/change items and dependencies.
  16033. // We might bail out of the loop before finding any but that
  16034. // doesn't matter since that means that the other boundaries that
  16035. // we did find already has their listeners attached.
  16036. var newThennables = suspended.updateQueue;
  16037. if (newThennables !== null) {
  16038. workInProgress.updateQueue = newThennables;
  16039. workInProgress.effectTag |= Update;
  16040. } // Rerender the whole list, but this time, we'll force fallbacks
  16041. // to stay in place.
  16042. // Reset the effect list before doing the second pass since that's now invalid.
  16043. if (renderState.lastEffect === null) {
  16044. workInProgress.firstEffect = null;
  16045. }
  16046. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  16047. resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
  16048. // rerender the children.
  16049. pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback));
  16050. return workInProgress.child;
  16051. }
  16052. row = row.sibling;
  16053. }
  16054. }
  16055. } else {
  16056. cutOffTailIfNeeded(renderState, false);
  16057. } // Next we're going to render the tail.
  16058. } else {
  16059. // Append the rendered row to the child list.
  16060. if (!didSuspendAlready) {
  16061. var _suspended = findFirstSuspended(renderedTail);
  16062. if (_suspended !== null) {
  16063. workInProgress.effectTag |= DidCapture;
  16064. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  16065. // get lost if this row ends up dropped during a second pass.
  16066. var _newThennables = _suspended.updateQueue;
  16067. if (_newThennables !== null) {
  16068. workInProgress.updateQueue = _newThennables;
  16069. workInProgress.effectTag |= Update;
  16070. }
  16071. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  16072. if (renderState.tail === null && renderState.tailMode === 'hidden' && !renderedTail.alternate) {
  16073. // We need to delete the row we just rendered.
  16074. // Reset the effect list to what it was before we rendered this
  16075. // child. The nested children have already appended themselves.
  16076. var lastEffect = workInProgress.lastEffect = renderState.lastEffect; // Remove any effects that were appended after this point.
  16077. if (lastEffect !== null) {
  16078. lastEffect.nextEffect = null;
  16079. } // We're done.
  16080. return null;
  16081. }
  16082. } else if ( // The time it took to render last row is greater than time until
  16083. // the expiration.
  16084. now() * 2 - renderState.renderingStartTime > renderState.tailExpiration && renderExpirationTime > Never) {
  16085. // We have now passed our CPU deadline and we'll just give up further
  16086. // attempts to render the main content and only render fallbacks.
  16087. // The assumption is that this is usually faster.
  16088. workInProgress.effectTag |= DidCapture;
  16089. didSuspendAlready = true;
  16090. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  16091. // to get it started back up to attempt the next item. If we can show
  16092. // them, then they really have the same priority as this render.
  16093. // So we'll pick it back up the very next render pass once we've had
  16094. // an opportunity to yield for paint.
  16095. var nextPriority = renderExpirationTime - 1;
  16096. workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
  16097. {
  16098. markSpawnedWork(nextPriority);
  16099. }
  16100. }
  16101. }
  16102. if (renderState.isBackwards) {
  16103. // The effect list of the backwards tail will have been added
  16104. // to the end. This breaks the guarantee that life-cycles fire in
  16105. // sibling order but that isn't a strong guarantee promised by React.
  16106. // Especially since these might also just pop in during future commits.
  16107. // Append to the beginning of the list.
  16108. renderedTail.sibling = workInProgress.child;
  16109. workInProgress.child = renderedTail;
  16110. } else {
  16111. var previousSibling = renderState.last;
  16112. if (previousSibling !== null) {
  16113. previousSibling.sibling = renderedTail;
  16114. } else {
  16115. workInProgress.child = renderedTail;
  16116. }
  16117. renderState.last = renderedTail;
  16118. }
  16119. }
  16120. if (renderState.tail !== null) {
  16121. // We still have tail rows to render.
  16122. if (renderState.tailExpiration === 0) {
  16123. // Heuristic for how long we're willing to spend rendering rows
  16124. // until we just give up and show what we have so far.
  16125. var TAIL_EXPIRATION_TIMEOUT_MS = 500;
  16126. renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS; // TODO: This is meant to mimic the train model or JND but this
  16127. // is a per component value. It should really be since the start
  16128. // of the total render or last commit. Consider using something like
  16129. // globalMostRecentFallbackTime. That doesn't account for being
  16130. // suspended for part of the time or when it's a new render.
  16131. // It should probably use a global start time value instead.
  16132. } // Pop a row.
  16133. var next = renderState.tail;
  16134. renderState.rendering = next;
  16135. renderState.tail = next.sibling;
  16136. renderState.lastEffect = workInProgress.lastEffect;
  16137. renderState.renderingStartTime = now();
  16138. next.sibling = null; // Restore the context.
  16139. // TODO: We can probably just avoid popping it instead and only
  16140. // setting it the first time we go from not suspended to suspended.
  16141. var suspenseContext = suspenseStackCursor.current;
  16142. if (didSuspendAlready) {
  16143. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  16144. } else {
  16145. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  16146. }
  16147. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  16148. return next;
  16149. }
  16150. return null;
  16151. }
  16152. }
  16153. {
  16154. {
  16155. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  16156. }
  16157. }
  16158. }
  16159. function unwindWork(workInProgress, renderExpirationTime) {
  16160. switch (workInProgress.tag) {
  16161. case ClassComponent:
  16162. {
  16163. var Component = workInProgress.type;
  16164. if (isContextProvider(Component)) {
  16165. popContext(workInProgress);
  16166. }
  16167. var effectTag = workInProgress.effectTag;
  16168. if (effectTag & ShouldCapture) {
  16169. workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
  16170. return workInProgress;
  16171. }
  16172. return null;
  16173. }
  16174. case HostRoot:
  16175. {
  16176. popHostContainer(workInProgress);
  16177. popTopLevelContextObject(workInProgress);
  16178. var _effectTag = workInProgress.effectTag;
  16179. if (!((_effectTag & DidCapture) === NoEffect)) {
  16180. {
  16181. throw Error( "The root failed to unmount after an error. This is likely a bug in React. Please file an issue." );
  16182. }
  16183. }
  16184. workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
  16185. return workInProgress;
  16186. }
  16187. case HostComponent:
  16188. {
  16189. // TODO: popHydrationState
  16190. popHostContext(workInProgress);
  16191. return null;
  16192. }
  16193. case SuspenseComponent:
  16194. {
  16195. popSuspenseContext(workInProgress);
  16196. var _effectTag2 = workInProgress.effectTag;
  16197. if (_effectTag2 & ShouldCapture) {
  16198. workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
  16199. return workInProgress;
  16200. }
  16201. return null;
  16202. }
  16203. case SuspenseListComponent:
  16204. {
  16205. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  16206. // caught by a nested boundary. If not, it should bubble through.
  16207. return null;
  16208. }
  16209. case HostPortal:
  16210. popHostContainer(workInProgress);
  16211. return null;
  16212. case ContextProvider:
  16213. popProvider(workInProgress);
  16214. return null;
  16215. default:
  16216. return null;
  16217. }
  16218. }
  16219. function unwindInterruptedWork(interruptedWork) {
  16220. switch (interruptedWork.tag) {
  16221. case ClassComponent:
  16222. {
  16223. var childContextTypes = interruptedWork.type.childContextTypes;
  16224. if (childContextTypes !== null && childContextTypes !== undefined) {
  16225. popContext(interruptedWork);
  16226. }
  16227. break;
  16228. }
  16229. case HostRoot:
  16230. {
  16231. popHostContainer(interruptedWork);
  16232. popTopLevelContextObject(interruptedWork);
  16233. break;
  16234. }
  16235. case HostComponent:
  16236. {
  16237. popHostContext(interruptedWork);
  16238. break;
  16239. }
  16240. case HostPortal:
  16241. popHostContainer(interruptedWork);
  16242. break;
  16243. case SuspenseComponent:
  16244. popSuspenseContext(interruptedWork);
  16245. break;
  16246. case SuspenseListComponent:
  16247. popSuspenseContext(interruptedWork);
  16248. break;
  16249. case ContextProvider:
  16250. popProvider(interruptedWork);
  16251. break;
  16252. }
  16253. }
  16254. function createCapturedValue(value, source) {
  16255. // If the value is an error, call this function immediately after it is thrown
  16256. // so the stack is accurate.
  16257. return {
  16258. value: value,
  16259. source: source,
  16260. stack: getStackByFiberInDevAndProd(source)
  16261. };
  16262. }
  16263. function logCapturedError(capturedError) {
  16264. var error = capturedError.error;
  16265. {
  16266. var componentName = capturedError.componentName,
  16267. componentStack = capturedError.componentStack,
  16268. errorBoundaryName = capturedError.errorBoundaryName,
  16269. errorBoundaryFound = capturedError.errorBoundaryFound,
  16270. willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
  16271. // `preventDefault()` in window `error` handler.
  16272. // We record this information as an expando on the error.
  16273. if (error != null && error._suppressLogging) {
  16274. if (errorBoundaryFound && willRetry) {
  16275. // The error is recoverable and was silenced.
  16276. // Ignore it and don't print the stack addendum.
  16277. // This is handy for testing error boundaries without noise.
  16278. return;
  16279. } // The error is fatal. Since the silencing might have
  16280. // been accidental, we'll surface it anyway.
  16281. // However, the browser would have silenced the original error
  16282. // so we'll print it first, and then print the stack addendum.
  16283. console['error'](error); // Don't transform to our wrapper
  16284. // For a more detailed description of this block, see:
  16285. // https://github.com/facebook/react/pull/13384
  16286. }
  16287. var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
  16288. var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
  16289. if (errorBoundaryFound && errorBoundaryName) {
  16290. if (willRetry) {
  16291. errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
  16292. } else {
  16293. errorBoundaryMessage = "This error was initially handled by the error boundary " + errorBoundaryName + ".\n" + "Recreating the tree from scratch failed so React will unmount the tree.";
  16294. }
  16295. } else {
  16296. errorBoundaryMessage = 'Consider adding an error boundary to your tree to customize error handling behavior.\n' + 'Visit https://fb.me/react-error-boundaries to learn more about error boundaries.';
  16297. }
  16298. var combinedMessage = "" + componentNameMessage + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  16299. // We don't include the original error message and JS stack because the browser
  16300. // has already printed it. Even if the application swallows the error, it is still
  16301. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  16302. console['error'](combinedMessage); // Don't transform to our wrapper
  16303. }
  16304. }
  16305. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  16306. {
  16307. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  16308. }
  16309. var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
  16310. function logError(boundary, errorInfo) {
  16311. var source = errorInfo.source;
  16312. var stack = errorInfo.stack;
  16313. if (stack === null && source !== null) {
  16314. stack = getStackByFiberInDevAndProd(source);
  16315. }
  16316. var capturedError = {
  16317. componentName: source !== null ? getComponentName(source.type) : null,
  16318. componentStack: stack !== null ? stack : '',
  16319. error: errorInfo.value,
  16320. errorBoundary: null,
  16321. errorBoundaryName: null,
  16322. errorBoundaryFound: false,
  16323. willRetry: false
  16324. };
  16325. if (boundary !== null && boundary.tag === ClassComponent) {
  16326. capturedError.errorBoundary = boundary.stateNode;
  16327. capturedError.errorBoundaryName = getComponentName(boundary.type);
  16328. capturedError.errorBoundaryFound = true;
  16329. capturedError.willRetry = true;
  16330. }
  16331. try {
  16332. logCapturedError(capturedError);
  16333. } catch (e) {
  16334. // This method must not throw, or React internal state will get messed up.
  16335. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  16336. // we want to report this error outside of the normal stack as a last resort.
  16337. // https://github.com/facebook/react/issues/13188
  16338. setTimeout(function () {
  16339. throw e;
  16340. });
  16341. }
  16342. }
  16343. var callComponentWillUnmountWithTimer = function (current, instance) {
  16344. startPhaseTimer(current, 'componentWillUnmount');
  16345. instance.props = current.memoizedProps;
  16346. instance.state = current.memoizedState;
  16347. instance.componentWillUnmount();
  16348. stopPhaseTimer();
  16349. }; // Capture errors so they don't interrupt unmounting.
  16350. function safelyCallComponentWillUnmount(current, instance) {
  16351. {
  16352. invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current, instance);
  16353. if (hasCaughtError()) {
  16354. var unmountError = clearCaughtError();
  16355. captureCommitPhaseError(current, unmountError);
  16356. }
  16357. }
  16358. }
  16359. function safelyDetachRef(current) {
  16360. var ref = current.ref;
  16361. if (ref !== null) {
  16362. if (typeof ref === 'function') {
  16363. {
  16364. invokeGuardedCallback(null, ref, null, null);
  16365. if (hasCaughtError()) {
  16366. var refError = clearCaughtError();
  16367. captureCommitPhaseError(current, refError);
  16368. }
  16369. }
  16370. } else {
  16371. ref.current = null;
  16372. }
  16373. }
  16374. }
  16375. function safelyCallDestroy(current, destroy) {
  16376. {
  16377. invokeGuardedCallback(null, destroy, null);
  16378. if (hasCaughtError()) {
  16379. var error = clearCaughtError();
  16380. captureCommitPhaseError(current, error);
  16381. }
  16382. }
  16383. }
  16384. function commitBeforeMutationLifeCycles(current, finishedWork) {
  16385. switch (finishedWork.tag) {
  16386. case FunctionComponent:
  16387. case ForwardRef:
  16388. case SimpleMemoComponent:
  16389. case Block:
  16390. {
  16391. return;
  16392. }
  16393. case ClassComponent:
  16394. {
  16395. if (finishedWork.effectTag & Snapshot) {
  16396. if (current !== null) {
  16397. var prevProps = current.memoizedProps;
  16398. var prevState = current.memoizedState;
  16399. startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
  16400. var instance = finishedWork.stateNode; // We could update instance props and state here,
  16401. // but instead we rely on them being set during last render.
  16402. // TODO: revisit this when we implement resuming.
  16403. {
  16404. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  16405. if (instance.props !== finishedWork.memoizedProps) {
  16406. error('Expected %s props to match memoized props before ' + 'getSnapshotBeforeUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16407. }
  16408. if (instance.state !== finishedWork.memoizedState) {
  16409. error('Expected %s state to match memoized state before ' + 'getSnapshotBeforeUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16410. }
  16411. }
  16412. }
  16413. var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
  16414. {
  16415. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  16416. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  16417. didWarnSet.add(finishedWork.type);
  16418. error('%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
  16419. }
  16420. }
  16421. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  16422. stopPhaseTimer();
  16423. }
  16424. }
  16425. return;
  16426. }
  16427. case HostRoot:
  16428. case HostComponent:
  16429. case HostText:
  16430. case HostPortal:
  16431. case IncompleteClassComponent:
  16432. // Nothing to do for these component types
  16433. return;
  16434. }
  16435. {
  16436. {
  16437. throw Error( "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." );
  16438. }
  16439. }
  16440. }
  16441. function commitHookEffectListUnmount(tag, finishedWork) {
  16442. var updateQueue = finishedWork.updateQueue;
  16443. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  16444. if (lastEffect !== null) {
  16445. var firstEffect = lastEffect.next;
  16446. var effect = firstEffect;
  16447. do {
  16448. if ((effect.tag & tag) === tag) {
  16449. // Unmount
  16450. var destroy = effect.destroy;
  16451. effect.destroy = undefined;
  16452. if (destroy !== undefined) {
  16453. destroy();
  16454. }
  16455. }
  16456. effect = effect.next;
  16457. } while (effect !== firstEffect);
  16458. }
  16459. }
  16460. function commitHookEffectListMount(tag, finishedWork) {
  16461. var updateQueue = finishedWork.updateQueue;
  16462. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  16463. if (lastEffect !== null) {
  16464. var firstEffect = lastEffect.next;
  16465. var effect = firstEffect;
  16466. do {
  16467. if ((effect.tag & tag) === tag) {
  16468. // Mount
  16469. var create = effect.create;
  16470. effect.destroy = create();
  16471. {
  16472. var destroy = effect.destroy;
  16473. if (destroy !== undefined && typeof destroy !== 'function') {
  16474. var addendum = void 0;
  16475. if (destroy === null) {
  16476. addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
  16477. } else if (typeof destroy.then === 'function') {
  16478. addendum = '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + "}, [someId]); // Or [] if effect doesn't need props or state\n\n" + 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching';
  16479. } else {
  16480. addendum = ' You returned: ' + destroy;
  16481. }
  16482. error('An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
  16483. }
  16484. }
  16485. }
  16486. effect = effect.next;
  16487. } while (effect !== firstEffect);
  16488. }
  16489. }
  16490. function commitPassiveHookEffects(finishedWork) {
  16491. if ((finishedWork.effectTag & Passive) !== NoEffect) {
  16492. switch (finishedWork.tag) {
  16493. case FunctionComponent:
  16494. case ForwardRef:
  16495. case SimpleMemoComponent:
  16496. case Block:
  16497. {
  16498. // TODO (#17945) We should call all passive destroy functions (for all fibers)
  16499. // before calling any create functions. The current approach only serializes
  16500. // these for a single fiber.
  16501. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
  16502. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  16503. break;
  16504. }
  16505. }
  16506. }
  16507. }
  16508. function commitLifeCycles(finishedRoot, current, finishedWork, committedExpirationTime) {
  16509. switch (finishedWork.tag) {
  16510. case FunctionComponent:
  16511. case ForwardRef:
  16512. case SimpleMemoComponent:
  16513. case Block:
  16514. {
  16515. // At this point layout effects have already been destroyed (during mutation phase).
  16516. // This is done to prevent sibling component effects from interfering with each other,
  16517. // e.g. a destroy function in one component should never override a ref set
  16518. // by a create function in another component during the same commit.
  16519. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  16520. return;
  16521. }
  16522. case ClassComponent:
  16523. {
  16524. var instance = finishedWork.stateNode;
  16525. if (finishedWork.effectTag & Update) {
  16526. if (current === null) {
  16527. startPhaseTimer(finishedWork, 'componentDidMount'); // We could update instance props and state here,
  16528. // but instead we rely on them being set during last render.
  16529. // TODO: revisit this when we implement resuming.
  16530. {
  16531. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  16532. if (instance.props !== finishedWork.memoizedProps) {
  16533. error('Expected %s props to match memoized props before ' + 'componentDidMount. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16534. }
  16535. if (instance.state !== finishedWork.memoizedState) {
  16536. error('Expected %s state to match memoized state before ' + 'componentDidMount. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16537. }
  16538. }
  16539. }
  16540. instance.componentDidMount();
  16541. stopPhaseTimer();
  16542. } else {
  16543. var prevProps = finishedWork.elementType === finishedWork.type ? current.memoizedProps : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  16544. var prevState = current.memoizedState;
  16545. startPhaseTimer(finishedWork, 'componentDidUpdate'); // We could update instance props and state here,
  16546. // but instead we rely on them being set during last render.
  16547. // TODO: revisit this when we implement resuming.
  16548. {
  16549. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  16550. if (instance.props !== finishedWork.memoizedProps) {
  16551. error('Expected %s props to match memoized props before ' + 'componentDidUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16552. }
  16553. if (instance.state !== finishedWork.memoizedState) {
  16554. error('Expected %s state to match memoized state before ' + 'componentDidUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16555. }
  16556. }
  16557. }
  16558. instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
  16559. stopPhaseTimer();
  16560. }
  16561. }
  16562. var updateQueue = finishedWork.updateQueue;
  16563. if (updateQueue !== null) {
  16564. {
  16565. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  16566. if (instance.props !== finishedWork.memoizedProps) {
  16567. error('Expected %s props to match memoized props before ' + 'processing the update queue. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16568. }
  16569. if (instance.state !== finishedWork.memoizedState) {
  16570. error('Expected %s state to match memoized state before ' + 'processing the update queue. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  16571. }
  16572. }
  16573. } // We could update instance props and state here,
  16574. // but instead we rely on them being set during last render.
  16575. // TODO: revisit this when we implement resuming.
  16576. commitUpdateQueue(finishedWork, updateQueue, instance);
  16577. }
  16578. return;
  16579. }
  16580. case HostRoot:
  16581. {
  16582. var _updateQueue = finishedWork.updateQueue;
  16583. if (_updateQueue !== null) {
  16584. var _instance = null;
  16585. if (finishedWork.child !== null) {
  16586. switch (finishedWork.child.tag) {
  16587. case HostComponent:
  16588. _instance = getPublicInstance(finishedWork.child.stateNode);
  16589. break;
  16590. case ClassComponent:
  16591. _instance = finishedWork.child.stateNode;
  16592. break;
  16593. }
  16594. }
  16595. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  16596. }
  16597. return;
  16598. }
  16599. case HostComponent:
  16600. {
  16601. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  16602. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  16603. // These effects should only be committed when components are first mounted,
  16604. // aka when there is no current/alternate.
  16605. if (current === null && finishedWork.effectTag & Update) {
  16606. var type = finishedWork.type;
  16607. var props = finishedWork.memoizedProps;
  16608. commitMount(_instance2, type, props);
  16609. }
  16610. return;
  16611. }
  16612. case HostText:
  16613. {
  16614. // We have no life-cycles associated with text.
  16615. return;
  16616. }
  16617. case HostPortal:
  16618. {
  16619. // We have no life-cycles associated with portals.
  16620. return;
  16621. }
  16622. case Profiler:
  16623. {
  16624. {
  16625. var onRender = finishedWork.memoizedProps.onRender;
  16626. if (typeof onRender === 'function') {
  16627. {
  16628. onRender(finishedWork.memoizedProps.id, current === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
  16629. }
  16630. }
  16631. }
  16632. return;
  16633. }
  16634. case SuspenseComponent:
  16635. {
  16636. commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);
  16637. return;
  16638. }
  16639. case SuspenseListComponent:
  16640. case IncompleteClassComponent:
  16641. case FundamentalComponent:
  16642. case ScopeComponent:
  16643. return;
  16644. }
  16645. {
  16646. {
  16647. throw Error( "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." );
  16648. }
  16649. }
  16650. }
  16651. function hideOrUnhideAllChildren(finishedWork, isHidden) {
  16652. {
  16653. // We only have the top Fiber that was inserted but we need to recurse down its
  16654. // children to find all the terminal nodes.
  16655. var node = finishedWork;
  16656. while (true) {
  16657. if (node.tag === HostComponent) {
  16658. var instance = node.stateNode;
  16659. if (isHidden) {
  16660. hideInstance(instance);
  16661. } else {
  16662. unhideInstance(node.stateNode, node.memoizedProps);
  16663. }
  16664. } else if (node.tag === HostText) {
  16665. var _instance3 = node.stateNode;
  16666. if (isHidden) {
  16667. hideTextInstance(_instance3);
  16668. } else {
  16669. unhideTextInstance(_instance3, node.memoizedProps);
  16670. }
  16671. } else if (node.tag === SuspenseComponent && node.memoizedState !== null && node.memoizedState.dehydrated === null) {
  16672. // Found a nested Suspense component that timed out. Skip over the
  16673. // primary child fragment, which should remain hidden.
  16674. var fallbackChildFragment = node.child.sibling;
  16675. fallbackChildFragment.return = node;
  16676. node = fallbackChildFragment;
  16677. continue;
  16678. } else if (node.child !== null) {
  16679. node.child.return = node;
  16680. node = node.child;
  16681. continue;
  16682. }
  16683. if (node === finishedWork) {
  16684. return;
  16685. }
  16686. while (node.sibling === null) {
  16687. if (node.return === null || node.return === finishedWork) {
  16688. return;
  16689. }
  16690. node = node.return;
  16691. }
  16692. node.sibling.return = node.return;
  16693. node = node.sibling;
  16694. }
  16695. }
  16696. }
  16697. function commitAttachRef(finishedWork) {
  16698. var ref = finishedWork.ref;
  16699. if (ref !== null) {
  16700. var instance = finishedWork.stateNode;
  16701. var instanceToUse;
  16702. switch (finishedWork.tag) {
  16703. case HostComponent:
  16704. instanceToUse = getPublicInstance(instance);
  16705. break;
  16706. default:
  16707. instanceToUse = instance;
  16708. } // Moved outside to ensure DCE works with this flag
  16709. if (typeof ref === 'function') {
  16710. ref(instanceToUse);
  16711. } else {
  16712. {
  16713. if (!ref.hasOwnProperty('current')) {
  16714. error('Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
  16715. }
  16716. }
  16717. ref.current = instanceToUse;
  16718. }
  16719. }
  16720. }
  16721. function commitDetachRef(current) {
  16722. var currentRef = current.ref;
  16723. if (currentRef !== null) {
  16724. if (typeof currentRef === 'function') {
  16725. currentRef(null);
  16726. } else {
  16727. currentRef.current = null;
  16728. }
  16729. }
  16730. } // User-originating errors (lifecycles and refs) should not interrupt
  16731. // deletion, so don't let them throw. Host-originating errors should
  16732. // interrupt deletion, so it's okay
  16733. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  16734. onCommitUnmount(current);
  16735. switch (current.tag) {
  16736. case FunctionComponent:
  16737. case ForwardRef:
  16738. case MemoComponent:
  16739. case SimpleMemoComponent:
  16740. case Block:
  16741. {
  16742. var updateQueue = current.updateQueue;
  16743. if (updateQueue !== null) {
  16744. var lastEffect = updateQueue.lastEffect;
  16745. if (lastEffect !== null) {
  16746. var firstEffect = lastEffect.next;
  16747. {
  16748. // When the owner fiber is deleted, the destroy function of a passive
  16749. // effect hook is called during the synchronous commit phase. This is
  16750. // a concession to implementation complexity. Calling it in the
  16751. // passive effect phase (like they usually are, when dependencies
  16752. // change during an update) would require either traversing the
  16753. // children of the deleted fiber again, or including unmount effects
  16754. // as part of the fiber effect list.
  16755. //
  16756. // Because this is during the sync commit phase, we need to change
  16757. // the priority.
  16758. //
  16759. // TODO: Reconsider this implementation trade off.
  16760. var priorityLevel = renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel;
  16761. runWithPriority$1(priorityLevel, function () {
  16762. var effect = firstEffect;
  16763. do {
  16764. var _destroy = effect.destroy;
  16765. if (_destroy !== undefined) {
  16766. safelyCallDestroy(current, _destroy);
  16767. }
  16768. effect = effect.next;
  16769. } while (effect !== firstEffect);
  16770. });
  16771. }
  16772. }
  16773. }
  16774. return;
  16775. }
  16776. case ClassComponent:
  16777. {
  16778. safelyDetachRef(current);
  16779. var instance = current.stateNode;
  16780. if (typeof instance.componentWillUnmount === 'function') {
  16781. safelyCallComponentWillUnmount(current, instance);
  16782. }
  16783. return;
  16784. }
  16785. case HostComponent:
  16786. {
  16787. safelyDetachRef(current);
  16788. return;
  16789. }
  16790. case HostPortal:
  16791. {
  16792. // TODO: this is recursive.
  16793. // We are also not using this parent because
  16794. // the portal will get pushed immediately.
  16795. {
  16796. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  16797. }
  16798. return;
  16799. }
  16800. case FundamentalComponent:
  16801. {
  16802. return;
  16803. }
  16804. case DehydratedFragment:
  16805. {
  16806. return;
  16807. }
  16808. case ScopeComponent:
  16809. {
  16810. return;
  16811. }
  16812. }
  16813. }
  16814. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  16815. // While we're inside a removed host node we don't want to call
  16816. // removeChild on the inner nodes because they're removed by the top
  16817. // call anyway. We also want to call componentWillUnmount on all
  16818. // composites before this host node is removed from the tree. Therefore
  16819. // we do an inner loop while we're still inside the host node.
  16820. var node = root;
  16821. while (true) {
  16822. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
  16823. // Skip portals because commitUnmount() currently visits them recursively.
  16824. if (node.child !== null && ( // If we use mutation we drill down into portals using commitUnmount above.
  16825. // If we don't use mutation we drill down into portals here instead.
  16826. node.tag !== HostPortal)) {
  16827. node.child.return = node;
  16828. node = node.child;
  16829. continue;
  16830. }
  16831. if (node === root) {
  16832. return;
  16833. }
  16834. while (node.sibling === null) {
  16835. if (node.return === null || node.return === root) {
  16836. return;
  16837. }
  16838. node = node.return;
  16839. }
  16840. node.sibling.return = node.return;
  16841. node = node.sibling;
  16842. }
  16843. }
  16844. function detachFiber(current) {
  16845. var alternate = current.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
  16846. // should clear the child pointer of the parent alternate to let this
  16847. // get GC:ed but we don't know which for sure which parent is the current
  16848. // one so we'll settle for GC:ing the subtree of this child. This child
  16849. // itself will be GC:ed when the parent updates the next time.
  16850. current.return = null;
  16851. current.child = null;
  16852. current.memoizedState = null;
  16853. current.updateQueue = null;
  16854. current.dependencies = null;
  16855. current.alternate = null;
  16856. current.firstEffect = null;
  16857. current.lastEffect = null;
  16858. current.pendingProps = null;
  16859. current.memoizedProps = null;
  16860. current.stateNode = null;
  16861. if (alternate !== null) {
  16862. detachFiber(alternate);
  16863. }
  16864. }
  16865. function getHostParentFiber(fiber) {
  16866. var parent = fiber.return;
  16867. while (parent !== null) {
  16868. if (isHostParent(parent)) {
  16869. return parent;
  16870. }
  16871. parent = parent.return;
  16872. }
  16873. {
  16874. {
  16875. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  16876. }
  16877. }
  16878. }
  16879. function isHostParent(fiber) {
  16880. return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
  16881. }
  16882. function getHostSibling(fiber) {
  16883. // We're going to search forward into the tree until we find a sibling host
  16884. // node. Unfortunately, if multiple insertions are done in a row we have to
  16885. // search past them. This leads to exponential search for the next sibling.
  16886. // TODO: Find a more efficient way to do this.
  16887. var node = fiber;
  16888. siblings: while (true) {
  16889. // If we didn't find anything, let's try the next sibling.
  16890. while (node.sibling === null) {
  16891. if (node.return === null || isHostParent(node.return)) {
  16892. // If we pop out of the root or hit the parent the fiber we are the
  16893. // last sibling.
  16894. return null;
  16895. }
  16896. node = node.return;
  16897. }
  16898. node.sibling.return = node.return;
  16899. node = node.sibling;
  16900. while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
  16901. // If it is not host node and, we might have a host node inside it.
  16902. // Try to search down until we find one.
  16903. if (node.effectTag & Placement) {
  16904. // If we don't have a child, try the siblings instead.
  16905. continue siblings;
  16906. } // If we don't have a child, try the siblings instead.
  16907. // We also skip portals because they are not part of this host tree.
  16908. if (node.child === null || node.tag === HostPortal) {
  16909. continue siblings;
  16910. } else {
  16911. node.child.return = node;
  16912. node = node.child;
  16913. }
  16914. } // Check if this host node is stable or about to be placed.
  16915. if (!(node.effectTag & Placement)) {
  16916. // Found it!
  16917. return node.stateNode;
  16918. }
  16919. }
  16920. }
  16921. function commitPlacement(finishedWork) {
  16922. var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
  16923. var parent;
  16924. var isContainer;
  16925. var parentStateNode = parentFiber.stateNode;
  16926. switch (parentFiber.tag) {
  16927. case HostComponent:
  16928. parent = parentStateNode;
  16929. isContainer = false;
  16930. break;
  16931. case HostRoot:
  16932. parent = parentStateNode.containerInfo;
  16933. isContainer = true;
  16934. break;
  16935. case HostPortal:
  16936. parent = parentStateNode.containerInfo;
  16937. isContainer = true;
  16938. break;
  16939. case FundamentalComponent:
  16940. // eslint-disable-next-line-no-fallthrough
  16941. default:
  16942. {
  16943. {
  16944. throw Error( "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." );
  16945. }
  16946. }
  16947. }
  16948. if (parentFiber.effectTag & ContentReset) {
  16949. // Reset the text content of the parent before doing any insertions
  16950. resetTextContent(parent); // Clear ContentReset from the effect tag
  16951. parentFiber.effectTag &= ~ContentReset;
  16952. }
  16953. var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
  16954. // children to find all the terminal nodes.
  16955. if (isContainer) {
  16956. insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
  16957. } else {
  16958. insertOrAppendPlacementNode(finishedWork, before, parent);
  16959. }
  16960. }
  16961. function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
  16962. var tag = node.tag;
  16963. var isHost = tag === HostComponent || tag === HostText;
  16964. if (isHost || enableFundamentalAPI ) {
  16965. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  16966. if (before) {
  16967. insertInContainerBefore(parent, stateNode, before);
  16968. } else {
  16969. appendChildToContainer(parent, stateNode);
  16970. }
  16971. } else if (tag === HostPortal) ; else {
  16972. var child = node.child;
  16973. if (child !== null) {
  16974. insertOrAppendPlacementNodeIntoContainer(child, before, parent);
  16975. var sibling = child.sibling;
  16976. while (sibling !== null) {
  16977. insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
  16978. sibling = sibling.sibling;
  16979. }
  16980. }
  16981. }
  16982. }
  16983. function insertOrAppendPlacementNode(node, before, parent) {
  16984. var tag = node.tag;
  16985. var isHost = tag === HostComponent || tag === HostText;
  16986. if (isHost || enableFundamentalAPI ) {
  16987. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  16988. if (before) {
  16989. insertBefore(parent, stateNode, before);
  16990. } else {
  16991. appendChild(parent, stateNode);
  16992. }
  16993. } else if (tag === HostPortal) ; else {
  16994. var child = node.child;
  16995. if (child !== null) {
  16996. insertOrAppendPlacementNode(child, before, parent);
  16997. var sibling = child.sibling;
  16998. while (sibling !== null) {
  16999. insertOrAppendPlacementNode(sibling, before, parent);
  17000. sibling = sibling.sibling;
  17001. }
  17002. }
  17003. }
  17004. }
  17005. function unmountHostComponents(finishedRoot, current, renderPriorityLevel) {
  17006. // We only have the top Fiber that was deleted but we need to recurse down its
  17007. // children to find all the terminal nodes.
  17008. var node = current; // Each iteration, currentParent is populated with node's host parent if not
  17009. // currentParentIsValid.
  17010. var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
  17011. var currentParent;
  17012. var currentParentIsContainer;
  17013. while (true) {
  17014. if (!currentParentIsValid) {
  17015. var parent = node.return;
  17016. findParent: while (true) {
  17017. if (!(parent !== null)) {
  17018. {
  17019. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  17020. }
  17021. }
  17022. var parentStateNode = parent.stateNode;
  17023. switch (parent.tag) {
  17024. case HostComponent:
  17025. currentParent = parentStateNode;
  17026. currentParentIsContainer = false;
  17027. break findParent;
  17028. case HostRoot:
  17029. currentParent = parentStateNode.containerInfo;
  17030. currentParentIsContainer = true;
  17031. break findParent;
  17032. case HostPortal:
  17033. currentParent = parentStateNode.containerInfo;
  17034. currentParentIsContainer = true;
  17035. break findParent;
  17036. }
  17037. parent = parent.return;
  17038. }
  17039. currentParentIsValid = true;
  17040. }
  17041. if (node.tag === HostComponent || node.tag === HostText) {
  17042. commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
  17043. // node from the tree.
  17044. if (currentParentIsContainer) {
  17045. removeChildFromContainer(currentParent, node.stateNode);
  17046. } else {
  17047. removeChild(currentParent, node.stateNode);
  17048. } // Don't visit children because we already visited them.
  17049. } else if (node.tag === HostPortal) {
  17050. if (node.child !== null) {
  17051. // When we go into a portal, it becomes the parent to remove from.
  17052. // We will reassign it back when we pop the portal on the way up.
  17053. currentParent = node.stateNode.containerInfo;
  17054. currentParentIsContainer = true; // Visit children because portals might contain host components.
  17055. node.child.return = node;
  17056. node = node.child;
  17057. continue;
  17058. }
  17059. } else {
  17060. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
  17061. if (node.child !== null) {
  17062. node.child.return = node;
  17063. node = node.child;
  17064. continue;
  17065. }
  17066. }
  17067. if (node === current) {
  17068. return;
  17069. }
  17070. while (node.sibling === null) {
  17071. if (node.return === null || node.return === current) {
  17072. return;
  17073. }
  17074. node = node.return;
  17075. if (node.tag === HostPortal) {
  17076. // When we go out of the portal, we need to restore the parent.
  17077. // Since we don't keep a stack of them, we will search for it.
  17078. currentParentIsValid = false;
  17079. }
  17080. }
  17081. node.sibling.return = node.return;
  17082. node = node.sibling;
  17083. }
  17084. }
  17085. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  17086. {
  17087. // Recursively delete all host nodes from the parent.
  17088. // Detach refs and call componentWillUnmount() on the whole subtree.
  17089. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  17090. }
  17091. detachFiber(current);
  17092. }
  17093. function commitWork(current, finishedWork) {
  17094. switch (finishedWork.tag) {
  17095. case FunctionComponent:
  17096. case ForwardRef:
  17097. case MemoComponent:
  17098. case SimpleMemoComponent:
  17099. case Block:
  17100. {
  17101. // Layout effects are destroyed during the mutation phase so that all
  17102. // destroy functions for all fibers are called before any create functions.
  17103. // This prevents sibling component effects from interfering with each other,
  17104. // e.g. a destroy function in one component should never override a ref set
  17105. // by a create function in another component during the same commit.
  17106. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  17107. return;
  17108. }
  17109. case ClassComponent:
  17110. {
  17111. return;
  17112. }
  17113. case HostComponent:
  17114. {
  17115. var instance = finishedWork.stateNode;
  17116. if (instance != null) {
  17117. // Commit the work prepared earlier.
  17118. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  17119. // as the newProps. The updatePayload will contain the real change in
  17120. // this case.
  17121. var oldProps = current !== null ? current.memoizedProps : newProps;
  17122. var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
  17123. var updatePayload = finishedWork.updateQueue;
  17124. finishedWork.updateQueue = null;
  17125. if (updatePayload !== null) {
  17126. commitUpdate(instance, updatePayload, type, oldProps, newProps);
  17127. }
  17128. }
  17129. return;
  17130. }
  17131. case HostText:
  17132. {
  17133. if (!(finishedWork.stateNode !== null)) {
  17134. {
  17135. throw Error( "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." );
  17136. }
  17137. }
  17138. var textInstance = finishedWork.stateNode;
  17139. var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  17140. // as the newProps. The updatePayload will contain the real change in
  17141. // this case.
  17142. var oldText = current !== null ? current.memoizedProps : newText;
  17143. commitTextUpdate(textInstance, oldText, newText);
  17144. return;
  17145. }
  17146. case HostRoot:
  17147. {
  17148. {
  17149. var _root = finishedWork.stateNode;
  17150. if (_root.hydrate) {
  17151. // We've just hydrated. No need to hydrate again.
  17152. _root.hydrate = false;
  17153. commitHydratedContainer(_root.containerInfo);
  17154. }
  17155. }
  17156. return;
  17157. }
  17158. case Profiler:
  17159. {
  17160. return;
  17161. }
  17162. case SuspenseComponent:
  17163. {
  17164. commitSuspenseComponent(finishedWork);
  17165. attachSuspenseRetryListeners(finishedWork);
  17166. return;
  17167. }
  17168. case SuspenseListComponent:
  17169. {
  17170. attachSuspenseRetryListeners(finishedWork);
  17171. return;
  17172. }
  17173. case IncompleteClassComponent:
  17174. {
  17175. return;
  17176. }
  17177. }
  17178. {
  17179. {
  17180. throw Error( "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." );
  17181. }
  17182. }
  17183. }
  17184. function commitSuspenseComponent(finishedWork) {
  17185. var newState = finishedWork.memoizedState;
  17186. var newDidTimeout;
  17187. var primaryChildParent = finishedWork;
  17188. if (newState === null) {
  17189. newDidTimeout = false;
  17190. } else {
  17191. newDidTimeout = true;
  17192. primaryChildParent = finishedWork.child;
  17193. markCommitTimeOfFallback();
  17194. }
  17195. if ( primaryChildParent !== null) {
  17196. hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
  17197. }
  17198. }
  17199. function commitSuspenseHydrationCallbacks(finishedRoot, finishedWork) {
  17200. var newState = finishedWork.memoizedState;
  17201. if (newState === null) {
  17202. var current = finishedWork.alternate;
  17203. if (current !== null) {
  17204. var prevState = current.memoizedState;
  17205. if (prevState !== null) {
  17206. var suspenseInstance = prevState.dehydrated;
  17207. if (suspenseInstance !== null) {
  17208. commitHydratedSuspenseInstance(suspenseInstance);
  17209. }
  17210. }
  17211. }
  17212. }
  17213. }
  17214. function attachSuspenseRetryListeners(finishedWork) {
  17215. // If this boundary just timed out, then it will have a set of thenables.
  17216. // For each thenable, attach a listener so that when it resolves, React
  17217. // attempts to re-render the boundary in the primary (pre-timeout) state.
  17218. var thenables = finishedWork.updateQueue;
  17219. if (thenables !== null) {
  17220. finishedWork.updateQueue = null;
  17221. var retryCache = finishedWork.stateNode;
  17222. if (retryCache === null) {
  17223. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  17224. }
  17225. thenables.forEach(function (thenable) {
  17226. // Memoize using the boundary fiber to prevent redundant listeners.
  17227. var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
  17228. if (!retryCache.has(thenable)) {
  17229. {
  17230. if (thenable.__reactDoNotTraceInteractions !== true) {
  17231. retry = unstable_wrap(retry);
  17232. }
  17233. }
  17234. retryCache.add(thenable);
  17235. thenable.then(retry, retry);
  17236. }
  17237. });
  17238. }
  17239. }
  17240. function commitResetTextContent(current) {
  17241. resetTextContent(current.stateNode);
  17242. }
  17243. var PossiblyWeakMap$1 = typeof WeakMap === 'function' ? WeakMap : Map;
  17244. function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
  17245. var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
  17246. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  17247. // being called "element".
  17248. update.payload = {
  17249. element: null
  17250. };
  17251. var error = errorInfo.value;
  17252. update.callback = function () {
  17253. onUncaughtError(error);
  17254. logError(fiber, errorInfo);
  17255. };
  17256. return update;
  17257. }
  17258. function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
  17259. var update = createUpdate(expirationTime, null);
  17260. update.tag = CaptureUpdate;
  17261. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  17262. if (typeof getDerivedStateFromError === 'function') {
  17263. var error$1 = errorInfo.value;
  17264. update.payload = function () {
  17265. logError(fiber, errorInfo);
  17266. return getDerivedStateFromError(error$1);
  17267. };
  17268. }
  17269. var inst = fiber.stateNode;
  17270. if (inst !== null && typeof inst.componentDidCatch === 'function') {
  17271. update.callback = function callback() {
  17272. {
  17273. markFailedErrorBoundaryForHotReloading(fiber);
  17274. }
  17275. if (typeof getDerivedStateFromError !== 'function') {
  17276. // To preserve the preexisting retry behavior of error boundaries,
  17277. // we keep track of which ones already failed during this batch.
  17278. // This gets reset before we yield back to the browser.
  17279. // TODO: Warn in strict mode if getDerivedStateFromError is
  17280. // not defined.
  17281. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  17282. logError(fiber, errorInfo);
  17283. }
  17284. var error$1 = errorInfo.value;
  17285. var stack = errorInfo.stack;
  17286. this.componentDidCatch(error$1, {
  17287. componentStack: stack !== null ? stack : ''
  17288. });
  17289. {
  17290. if (typeof getDerivedStateFromError !== 'function') {
  17291. // If componentDidCatch is the only error boundary method defined,
  17292. // then it needs to call setState to recover from errors.
  17293. // If no state update is scheduled then the boundary will swallow the error.
  17294. if (fiber.expirationTime !== Sync) {
  17295. error('%s: Error boundaries should implement getDerivedStateFromError(). ' + 'In that method, return a state update to display an error message or fallback UI.', getComponentName(fiber.type) || 'Unknown');
  17296. }
  17297. }
  17298. }
  17299. };
  17300. } else {
  17301. update.callback = function () {
  17302. markFailedErrorBoundaryForHotReloading(fiber);
  17303. };
  17304. }
  17305. return update;
  17306. }
  17307. function attachPingListener(root, renderExpirationTime, thenable) {
  17308. // Attach a listener to the promise to "ping" the root and retry. But
  17309. // only if one does not already exist for the current render expiration
  17310. // time (which acts like a "thread ID" here).
  17311. var pingCache = root.pingCache;
  17312. var threadIDs;
  17313. if (pingCache === null) {
  17314. pingCache = root.pingCache = new PossiblyWeakMap$1();
  17315. threadIDs = new Set();
  17316. pingCache.set(thenable, threadIDs);
  17317. } else {
  17318. threadIDs = pingCache.get(thenable);
  17319. if (threadIDs === undefined) {
  17320. threadIDs = new Set();
  17321. pingCache.set(thenable, threadIDs);
  17322. }
  17323. }
  17324. if (!threadIDs.has(renderExpirationTime)) {
  17325. // Memoize using the thread ID to prevent redundant listeners.
  17326. threadIDs.add(renderExpirationTime);
  17327. var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
  17328. thenable.then(ping, ping);
  17329. }
  17330. }
  17331. function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
  17332. // The source fiber did not complete.
  17333. sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
  17334. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  17335. if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
  17336. // This is a thenable.
  17337. var thenable = value;
  17338. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  17339. // Reset the memoizedState to what it was before we attempted
  17340. // to render it.
  17341. var currentSource = sourceFiber.alternate;
  17342. if (currentSource) {
  17343. sourceFiber.updateQueue = currentSource.updateQueue;
  17344. sourceFiber.memoizedState = currentSource.memoizedState;
  17345. sourceFiber.expirationTime = currentSource.expirationTime;
  17346. } else {
  17347. sourceFiber.updateQueue = null;
  17348. sourceFiber.memoizedState = null;
  17349. }
  17350. }
  17351. var hasInvisibleParentBoundary = hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext); // Schedule the nearest Suspense to re-render the timed out view.
  17352. var _workInProgress = returnFiber;
  17353. do {
  17354. if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)) {
  17355. // Found the nearest boundary.
  17356. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  17357. // attach another listener to flip the boundary back to its normal state.
  17358. var thenables = _workInProgress.updateQueue;
  17359. if (thenables === null) {
  17360. var updateQueue = new Set();
  17361. updateQueue.add(thenable);
  17362. _workInProgress.updateQueue = updateQueue;
  17363. } else {
  17364. thenables.add(thenable);
  17365. } // If the boundary is outside of blocking mode, we should *not*
  17366. // suspend the commit. Pretend as if the suspended component rendered
  17367. // null and keep rendering. In the commit phase, we'll schedule a
  17368. // subsequent synchronous update to re-render the Suspense.
  17369. //
  17370. // Note: It doesn't matter whether the component that suspended was
  17371. // inside a blocking mode tree. If the Suspense is outside of it, we
  17372. // should *not* suspend the commit.
  17373. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  17374. _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
  17375. // But we shouldn't call any lifecycle methods or callbacks. Remove
  17376. // all lifecycle effect tags.
  17377. sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
  17378. if (sourceFiber.tag === ClassComponent) {
  17379. var currentSourceFiber = sourceFiber.alternate;
  17380. if (currentSourceFiber === null) {
  17381. // This is a new mount. Change the tag so it's not mistaken for a
  17382. // completed class component. For example, we should not call
  17383. // componentWillUnmount if it is deleted.
  17384. sourceFiber.tag = IncompleteClassComponent;
  17385. } else {
  17386. // When we try rendering again, we should not reuse the current fiber,
  17387. // since it's known to be in an inconsistent state. Use a force update to
  17388. // prevent a bail out.
  17389. var update = createUpdate(Sync, null);
  17390. update.tag = ForceUpdate;
  17391. enqueueUpdate(sourceFiber, update);
  17392. }
  17393. } // The source fiber did not complete. Mark it with Sync priority to
  17394. // indicate that it still has pending work.
  17395. sourceFiber.expirationTime = Sync; // Exit without suspending.
  17396. return;
  17397. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  17398. // with the normal suspend path.
  17399. //
  17400. // After this we'll use a set of heuristics to determine whether this
  17401. // render pass will run to completion or restart or "suspend" the commit.
  17402. // The actual logic for this is spread out in different places.
  17403. //
  17404. // This first principle is that if we're going to suspend when we complete
  17405. // a root, then we should also restart if we get an update or ping that
  17406. // might unsuspend it, and vice versa. The only reason to suspend is
  17407. // because you think you might want to restart before committing. However,
  17408. // it doesn't make sense to restart only while in the period we're suspended.
  17409. //
  17410. // Restarting too aggressively is also not good because it starves out any
  17411. // intermediate loading state. So we use heuristics to determine when.
  17412. // Suspense Heuristics
  17413. //
  17414. // If nothing threw a Promise or all the same fallbacks are already showing,
  17415. // then don't suspend/restart.
  17416. //
  17417. // If this is an initial render of a new tree of Suspense boundaries and
  17418. // those trigger a fallback, then don't suspend/restart. We want to ensure
  17419. // that we can show the initial loading state as quickly as possible.
  17420. //
  17421. // If we hit a "Delayed" case, such as when we'd switch from content back into
  17422. // a fallback, then we should always suspend/restart. SuspenseConfig applies to
  17423. // this case. If none is defined, JND is used instead.
  17424. //
  17425. // If we're already showing a fallback and it gets "retried", allowing us to show
  17426. // another level, but there's still an inner boundary that would show a fallback,
  17427. // then we suspend/restart for 500ms since the last time we showed a fallback
  17428. // anywhere in the tree. This effectively throttles progressive loading into a
  17429. // consistent train of commits. This also gives us an opportunity to restart to
  17430. // get to the completed state slightly earlier.
  17431. //
  17432. // If there's ambiguity due to batching it's resolved in preference of:
  17433. // 1) "delayed", 2) "initial render", 3) "retry".
  17434. //
  17435. // We want to ensure that a "busy" state doesn't get force committed. We want to
  17436. // ensure that new initial loading states can commit as soon as possible.
  17437. attachPingListener(root, renderExpirationTime, thenable);
  17438. _workInProgress.effectTag |= ShouldCapture;
  17439. _workInProgress.expirationTime = renderExpirationTime;
  17440. return;
  17441. } // This boundary already captured during this render. Continue to the next
  17442. // boundary.
  17443. _workInProgress = _workInProgress.return;
  17444. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  17445. // TODO: Use invariant so the message is stripped in prod?
  17446. value = new Error((getComponentName(sourceFiber.type) || 'A React component') + ' suspended while rendering, but no fallback UI was specified.\n' + '\n' + 'Add a <Suspense fallback=...> component higher in the tree to ' + 'provide a loading indicator or placeholder to display.' + getStackByFiberInDevAndProd(sourceFiber));
  17447. } // We didn't find a boundary that could handle this type of exception. Start
  17448. // over and traverse parent path again, this time treating the exception
  17449. // as an error.
  17450. renderDidError();
  17451. value = createCapturedValue(value, sourceFiber);
  17452. var workInProgress = returnFiber;
  17453. do {
  17454. switch (workInProgress.tag) {
  17455. case HostRoot:
  17456. {
  17457. var _errorInfo = value;
  17458. workInProgress.effectTag |= ShouldCapture;
  17459. workInProgress.expirationTime = renderExpirationTime;
  17460. var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
  17461. enqueueCapturedUpdate(workInProgress, _update);
  17462. return;
  17463. }
  17464. case ClassComponent:
  17465. // Capture and retry
  17466. var errorInfo = value;
  17467. var ctor = workInProgress.type;
  17468. var instance = workInProgress.stateNode;
  17469. if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
  17470. workInProgress.effectTag |= ShouldCapture;
  17471. workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
  17472. var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
  17473. enqueueCapturedUpdate(workInProgress, _update2);
  17474. return;
  17475. }
  17476. break;
  17477. }
  17478. workInProgress = workInProgress.return;
  17479. } while (workInProgress !== null);
  17480. }
  17481. var ceil = Math.ceil;
  17482. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  17483. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  17484. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  17485. var NoContext =
  17486. /* */
  17487. 0;
  17488. var BatchedContext =
  17489. /* */
  17490. 1;
  17491. var EventContext =
  17492. /* */
  17493. 2;
  17494. var DiscreteEventContext =
  17495. /* */
  17496. 4;
  17497. var LegacyUnbatchedContext =
  17498. /* */
  17499. 8;
  17500. var RenderContext =
  17501. /* */
  17502. 16;
  17503. var CommitContext =
  17504. /* */
  17505. 32;
  17506. var RootIncomplete = 0;
  17507. var RootFatalErrored = 1;
  17508. var RootErrored = 2;
  17509. var RootSuspended = 3;
  17510. var RootSuspendedWithDelay = 4;
  17511. var RootCompleted = 5;
  17512. // Describes where we are in the React execution stack
  17513. var executionContext = NoContext; // The root we're working on
  17514. var workInProgressRoot = null; // The fiber we're working on
  17515. var workInProgress = null; // The expiration time we're rendering
  17516. var renderExpirationTime$1 = NoWork; // Whether to root completed, errored, suspended, etc.
  17517. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  17518. var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
  17519. // This is conceptually a time stamp but expressed in terms of an ExpirationTime
  17520. // because we deal mostly with expiration times in the hot path, so this avoids
  17521. // the conversion happening in the hot path.
  17522. var workInProgressRootLatestProcessedExpirationTime = Sync;
  17523. var workInProgressRootLatestSuspenseTimeout = Sync;
  17524. var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
  17525. // includes unprocessed updates, not work in bailed out children.
  17526. var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
  17527. // This flag determines if it might be worthwhile to restart if an opportunity
  17528. // happens latere.
  17529. var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
  17530. // model where we don't commit new loading states in too quick succession.
  17531. var globalMostRecentFallbackTime = 0;
  17532. var FALLBACK_THROTTLE_MS = 500;
  17533. var nextEffect = null;
  17534. var hasUncaughtError = false;
  17535. var firstUncaughtError = null;
  17536. var legacyErrorBoundariesThatAlreadyFailed = null;
  17537. var rootDoesHavePassiveEffects = false;
  17538. var rootWithPendingPassiveEffects = null;
  17539. var pendingPassiveEffectsRenderPriority = NoPriority;
  17540. var pendingPassiveEffectsExpirationTime = NoWork;
  17541. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  17542. var NESTED_UPDATE_LIMIT = 50;
  17543. var nestedUpdateCount = 0;
  17544. var rootWithNestedUpdates = null;
  17545. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  17546. var nestedPassiveUpdateCount = 0;
  17547. var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
  17548. // during the commit phase. This enables them to be traced across components
  17549. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  17550. // hydration or SuspenseList.
  17551. var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
  17552. // time). However, if two updates are scheduled within the same event, we
  17553. // should treat their start times as simultaneous, even if the actual clock
  17554. // time has advanced between the first and second call.
  17555. // In other words, because expiration times determine how updates are batched,
  17556. // we want all updates of like priority that occur within the same event to
  17557. // receive the same expiration time. Otherwise we get tearing.
  17558. var currentEventTime = NoWork;
  17559. function requestCurrentTimeForUpdate() {
  17560. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  17561. // We're inside React, so it's fine to read the actual time.
  17562. return msToExpirationTime(now());
  17563. } // We're not inside React, so we may be in the middle of a browser event.
  17564. if (currentEventTime !== NoWork) {
  17565. // Use the same start time for all updates until we enter React again.
  17566. return currentEventTime;
  17567. } // This is the first update since React yielded. Compute a new start time.
  17568. currentEventTime = msToExpirationTime(now());
  17569. return currentEventTime;
  17570. }
  17571. function getCurrentTime() {
  17572. return msToExpirationTime(now());
  17573. }
  17574. function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
  17575. var mode = fiber.mode;
  17576. if ((mode & BlockingMode) === NoMode) {
  17577. return Sync;
  17578. }
  17579. var priorityLevel = getCurrentPriorityLevel();
  17580. if ((mode & ConcurrentMode) === NoMode) {
  17581. return priorityLevel === ImmediatePriority ? Sync : Batched;
  17582. }
  17583. if ((executionContext & RenderContext) !== NoContext) {
  17584. // Use whatever time we're already rendering
  17585. // TODO: Should there be a way to opt out, like with `runWithPriority`?
  17586. return renderExpirationTime$1;
  17587. }
  17588. var expirationTime;
  17589. if (suspenseConfig !== null) {
  17590. // Compute an expiration time based on the Suspense timeout.
  17591. expirationTime = computeSuspenseExpiration(currentTime, suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
  17592. } else {
  17593. // Compute an expiration time based on the Scheduler priority.
  17594. switch (priorityLevel) {
  17595. case ImmediatePriority:
  17596. expirationTime = Sync;
  17597. break;
  17598. case UserBlockingPriority$1:
  17599. // TODO: Rename this to computeUserBlockingExpiration
  17600. expirationTime = computeInteractiveExpiration(currentTime);
  17601. break;
  17602. case NormalPriority:
  17603. case LowPriority:
  17604. // TODO: Handle LowPriority
  17605. // TODO: Rename this to... something better.
  17606. expirationTime = computeAsyncExpiration(currentTime);
  17607. break;
  17608. case IdlePriority:
  17609. expirationTime = Idle;
  17610. break;
  17611. default:
  17612. {
  17613. {
  17614. throw Error( "Expected a valid priority level" );
  17615. }
  17616. }
  17617. }
  17618. } // If we're in the middle of rendering a tree, do not update at the same
  17619. // expiration time that is already rendering.
  17620. // TODO: We shouldn't have to do this if the update is on a different root.
  17621. // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
  17622. // the root when we check for this condition.
  17623. if (workInProgressRoot !== null && expirationTime === renderExpirationTime$1) {
  17624. // This is a trick to move this update into a separate batch
  17625. expirationTime -= 1;
  17626. }
  17627. return expirationTime;
  17628. }
  17629. function scheduleUpdateOnFiber(fiber, expirationTime) {
  17630. checkForNestedUpdates();
  17631. warnAboutRenderPhaseUpdatesInDEV(fiber);
  17632. var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
  17633. if (root === null) {
  17634. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  17635. return;
  17636. }
  17637. checkForInterruption(fiber, expirationTime);
  17638. recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
  17639. // priority as an argument to that function and this one.
  17640. var priorityLevel = getCurrentPriorityLevel();
  17641. if (expirationTime === Sync) {
  17642. if ( // Check if we're inside unbatchedUpdates
  17643. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  17644. (executionContext & (RenderContext | CommitContext)) === NoContext) {
  17645. // Register pending interactions on the root to avoid losing traced interaction data.
  17646. schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  17647. // root inside of batchedUpdates should be synchronous, but layout updates
  17648. // should be deferred until the end of the batch.
  17649. performSyncWorkOnRoot(root);
  17650. } else {
  17651. ensureRootIsScheduled(root);
  17652. schedulePendingInteractions(root, expirationTime);
  17653. if (executionContext === NoContext) {
  17654. // Flush the synchronous work now, unless we're already working or inside
  17655. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  17656. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  17657. // without immediately flushing it. We only do this for user-initiated
  17658. // updates, to preserve historical behavior of legacy mode.
  17659. flushSyncCallbackQueue();
  17660. }
  17661. }
  17662. } else {
  17663. ensureRootIsScheduled(root);
  17664. schedulePendingInteractions(root, expirationTime);
  17665. }
  17666. if ((executionContext & DiscreteEventContext) !== NoContext && ( // Only updates at user-blocking priority or greater are considered
  17667. // discrete, even inside a discrete event.
  17668. priorityLevel === UserBlockingPriority$1 || priorityLevel === ImmediatePriority)) {
  17669. // This is the result of a discrete event. Track the lowest priority
  17670. // discrete update per root so we can flush them early, if needed.
  17671. if (rootsWithPendingDiscreteUpdates === null) {
  17672. rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
  17673. } else {
  17674. var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
  17675. if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
  17676. rootsWithPendingDiscreteUpdates.set(root, expirationTime);
  17677. }
  17678. }
  17679. }
  17680. }
  17681. var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
  17682. // work without treating it as a typical update that originates from an event;
  17683. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  17684. // on a fiber.
  17685. function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
  17686. // Update the source fiber's expiration time
  17687. if (fiber.expirationTime < expirationTime) {
  17688. fiber.expirationTime = expirationTime;
  17689. }
  17690. var alternate = fiber.alternate;
  17691. if (alternate !== null && alternate.expirationTime < expirationTime) {
  17692. alternate.expirationTime = expirationTime;
  17693. } // Walk the parent path to the root and update the child expiration time.
  17694. var node = fiber.return;
  17695. var root = null;
  17696. if (node === null && fiber.tag === HostRoot) {
  17697. root = fiber.stateNode;
  17698. } else {
  17699. while (node !== null) {
  17700. alternate = node.alternate;
  17701. if (node.childExpirationTime < expirationTime) {
  17702. node.childExpirationTime = expirationTime;
  17703. if (alternate !== null && alternate.childExpirationTime < expirationTime) {
  17704. alternate.childExpirationTime = expirationTime;
  17705. }
  17706. } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
  17707. alternate.childExpirationTime = expirationTime;
  17708. }
  17709. if (node.return === null && node.tag === HostRoot) {
  17710. root = node.stateNode;
  17711. break;
  17712. }
  17713. node = node.return;
  17714. }
  17715. }
  17716. if (root !== null) {
  17717. if (workInProgressRoot === root) {
  17718. // Received an update to a tree that's in the middle of rendering. Mark
  17719. // that's unprocessed work on this root.
  17720. markUnprocessedUpdateTime(expirationTime);
  17721. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  17722. // The root already suspended with a delay, which means this render
  17723. // definitely won't finish. Since we have a new update, let's mark it as
  17724. // suspended now, right before marking the incoming update. This has the
  17725. // effect of interrupting the current render and switching to the update.
  17726. // TODO: This happens to work when receiving an update during the render
  17727. // phase, because of the trick inside computeExpirationForFiber to
  17728. // subtract 1 from `renderExpirationTime` to move it into a
  17729. // separate bucket. But we should probably model it with an exception,
  17730. // using the same mechanism we use to force hydration of a subtree.
  17731. // TODO: This does not account for low pri updates that were already
  17732. // scheduled before the root started rendering. Need to track the next
  17733. // pending expiration time (perhaps by backtracking the return path) and
  17734. // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
  17735. markRootSuspendedAtTime(root, renderExpirationTime$1);
  17736. }
  17737. } // Mark that the root has a pending update.
  17738. markRootUpdatedAtTime(root, expirationTime);
  17739. }
  17740. return root;
  17741. }
  17742. function getNextRootExpirationTimeToWorkOn(root) {
  17743. // Determines the next expiration time that the root should render, taking
  17744. // into account levels that may be suspended, or levels that may have
  17745. // received a ping.
  17746. var lastExpiredTime = root.lastExpiredTime;
  17747. if (lastExpiredTime !== NoWork) {
  17748. return lastExpiredTime;
  17749. } // "Pending" refers to any update that hasn't committed yet, including if it
  17750. // suspended. The "suspended" range is therefore a subset.
  17751. var firstPendingTime = root.firstPendingTime;
  17752. if (!isRootSuspendedAtTime(root, firstPendingTime)) {
  17753. // The highest priority pending time is not suspended. Let's work on that.
  17754. return firstPendingTime;
  17755. } // If the first pending time is suspended, check if there's a lower priority
  17756. // pending level that we know about. Or check if we received a ping. Work
  17757. // on whichever is higher priority.
  17758. var lastPingedTime = root.lastPingedTime;
  17759. var nextKnownPendingLevel = root.nextKnownPendingLevel;
  17760. var nextLevel = lastPingedTime > nextKnownPendingLevel ? lastPingedTime : nextKnownPendingLevel;
  17761. if ( nextLevel <= Idle && firstPendingTime !== nextLevel) {
  17762. // Don't work on Idle/Never priority unless everything else is committed.
  17763. return NoWork;
  17764. }
  17765. return nextLevel;
  17766. } // Use this function to schedule a task for a root. There's only one task per
  17767. // root; if a task was already scheduled, we'll check to make sure the
  17768. // expiration time of the existing task is the same as the expiration time of
  17769. // the next level that the root has work on. This function is called on every
  17770. // update, and right before exiting a task.
  17771. function ensureRootIsScheduled(root) {
  17772. var lastExpiredTime = root.lastExpiredTime;
  17773. if (lastExpiredTime !== NoWork) {
  17774. // Special case: Expired work should flush synchronously.
  17775. root.callbackExpirationTime = Sync;
  17776. root.callbackPriority = ImmediatePriority;
  17777. root.callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  17778. return;
  17779. }
  17780. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  17781. var existingCallbackNode = root.callbackNode;
  17782. if (expirationTime === NoWork) {
  17783. // There's nothing to work on.
  17784. if (existingCallbackNode !== null) {
  17785. root.callbackNode = null;
  17786. root.callbackExpirationTime = NoWork;
  17787. root.callbackPriority = NoPriority;
  17788. }
  17789. return;
  17790. } // TODO: If this is an update, we already read the current time. Pass the
  17791. // time as an argument.
  17792. var currentTime = requestCurrentTimeForUpdate();
  17793. var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime); // If there's an existing render task, confirm it has the correct priority and
  17794. // expiration time. Otherwise, we'll cancel it and schedule a new one.
  17795. if (existingCallbackNode !== null) {
  17796. var existingCallbackPriority = root.callbackPriority;
  17797. var existingCallbackExpirationTime = root.callbackExpirationTime;
  17798. if ( // Callback must have the exact same expiration time.
  17799. existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
  17800. existingCallbackPriority >= priorityLevel) {
  17801. // Existing callback is sufficient.
  17802. return;
  17803. } // Need to schedule a new task.
  17804. // TODO: Instead of scheduling a new task, we should be able to change the
  17805. // priority of the existing one.
  17806. cancelCallback(existingCallbackNode);
  17807. }
  17808. root.callbackExpirationTime = expirationTime;
  17809. root.callbackPriority = priorityLevel;
  17810. var callbackNode;
  17811. if (expirationTime === Sync) {
  17812. // Sync React callbacks are scheduled on a special internal queue
  17813. callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  17814. } else {
  17815. callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
  17816. // ordering because tasks are processed in timeout order.
  17817. {
  17818. timeout: expirationTimeToMs(expirationTime) - now()
  17819. });
  17820. }
  17821. root.callbackNode = callbackNode;
  17822. } // This is the entry point for every concurrent task, i.e. anything that
  17823. // goes through Scheduler.
  17824. function performConcurrentWorkOnRoot(root, didTimeout) {
  17825. // Since we know we're in a React event, we can clear the current
  17826. // event time. The next update will compute a new event time.
  17827. currentEventTime = NoWork;
  17828. if (didTimeout) {
  17829. // The render task took too long to complete. Mark the current time as
  17830. // expired to synchronously render all expired work in a single batch.
  17831. var currentTime = requestCurrentTimeForUpdate();
  17832. markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
  17833. ensureRootIsScheduled(root);
  17834. return null;
  17835. } // Determine the next expiration time to work on, using the fields stored
  17836. // on the root.
  17837. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  17838. if (expirationTime !== NoWork) {
  17839. var originalCallbackNode = root.callbackNode;
  17840. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  17841. {
  17842. throw Error( "Should not already be working." );
  17843. }
  17844. }
  17845. flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
  17846. // and prepare a fresh one. Otherwise we'll continue where we left off.
  17847. if (root !== workInProgressRoot || expirationTime !== renderExpirationTime$1) {
  17848. prepareFreshStack(root, expirationTime);
  17849. startWorkOnPendingInteractions(root, expirationTime);
  17850. } // If we have a work-in-progress fiber, it means there's still work to do
  17851. // in this root.
  17852. if (workInProgress !== null) {
  17853. var prevExecutionContext = executionContext;
  17854. executionContext |= RenderContext;
  17855. var prevDispatcher = pushDispatcher();
  17856. var prevInteractions = pushInteractions(root);
  17857. startWorkLoopTimer(workInProgress);
  17858. do {
  17859. try {
  17860. workLoopConcurrent();
  17861. break;
  17862. } catch (thrownValue) {
  17863. handleError(root, thrownValue);
  17864. }
  17865. } while (true);
  17866. resetContextDependencies();
  17867. executionContext = prevExecutionContext;
  17868. popDispatcher(prevDispatcher);
  17869. {
  17870. popInteractions(prevInteractions);
  17871. }
  17872. if (workInProgressRootExitStatus === RootFatalErrored) {
  17873. var fatalError = workInProgressRootFatalError;
  17874. stopInterruptedWorkLoopTimer();
  17875. prepareFreshStack(root, expirationTime);
  17876. markRootSuspendedAtTime(root, expirationTime);
  17877. ensureRootIsScheduled(root);
  17878. throw fatalError;
  17879. }
  17880. if (workInProgress !== null) {
  17881. // There's still work left over. Exit without committing.
  17882. stopInterruptedWorkLoopTimer();
  17883. } else {
  17884. // We now have a consistent tree. The next step is either to commit it,
  17885. // or, if something suspended, wait to commit it after a timeout.
  17886. stopFinishedWorkLoopTimer();
  17887. var finishedWork = root.finishedWork = root.current.alternate;
  17888. root.finishedExpirationTime = expirationTime;
  17889. finishConcurrentRender(root, finishedWork, workInProgressRootExitStatus, expirationTime);
  17890. }
  17891. ensureRootIsScheduled(root);
  17892. if (root.callbackNode === originalCallbackNode) {
  17893. // The task node scheduled for this root is the same one that's
  17894. // currently executed. Need to return a continuation.
  17895. return performConcurrentWorkOnRoot.bind(null, root);
  17896. }
  17897. }
  17898. }
  17899. return null;
  17900. }
  17901. function finishConcurrentRender(root, finishedWork, exitStatus, expirationTime) {
  17902. // Set this to null to indicate there's no in-progress render.
  17903. workInProgressRoot = null;
  17904. switch (exitStatus) {
  17905. case RootIncomplete:
  17906. case RootFatalErrored:
  17907. {
  17908. {
  17909. {
  17910. throw Error( "Root did not complete. This is a bug in React." );
  17911. }
  17912. }
  17913. }
  17914. // Flow knows about invariant, so it complains if I add a break
  17915. // statement, but eslint doesn't know about invariant, so it complains
  17916. // if I do. eslint-disable-next-line no-fallthrough
  17917. case RootErrored:
  17918. {
  17919. // If this was an async render, the error may have happened due to
  17920. // a mutation in a concurrent event. Try rendering one more time,
  17921. // synchronously, to see if the error goes away. If there are
  17922. // lower priority updates, let's include those, too, in case they
  17923. // fix the inconsistency. Render at Idle to include all updates.
  17924. // If it was Idle or Never or some not-yet-invented time, render
  17925. // at that time.
  17926. markRootExpiredAtTime(root, expirationTime > Idle ? Idle : expirationTime); // We assume that this second render pass will be synchronous
  17927. // and therefore not hit this path again.
  17928. break;
  17929. }
  17930. case RootSuspended:
  17931. {
  17932. markRootSuspendedAtTime(root, expirationTime);
  17933. var lastSuspendedTime = root.lastSuspendedTime;
  17934. if (expirationTime === lastSuspendedTime) {
  17935. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  17936. } // We have an acceptable loading state. We need to figure out if we
  17937. // should immediately commit it or wait a bit.
  17938. // If we have processed new updates during this render, we may now
  17939. // have a new loading state ready. We want to ensure that we commit
  17940. // that as soon as possible.
  17941. var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync;
  17942. if (hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
  17943. !( IsThisRendererActing.current)) {
  17944. // If we have not processed any new updates during this pass, then
  17945. // this is either a retry of an existing fallback state or a
  17946. // hidden tree. Hidden trees shouldn't be batched with other work
  17947. // and after that's fixed it can only be a retry. We're going to
  17948. // throttle committing retries so that we don't show too many
  17949. // loading states too quickly.
  17950. var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  17951. if (msUntilTimeout > 10) {
  17952. if (workInProgressRootHasPendingPing) {
  17953. var lastPingedTime = root.lastPingedTime;
  17954. if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
  17955. // This render was pinged but we didn't get to restart
  17956. // earlier so try restarting now instead.
  17957. root.lastPingedTime = expirationTime;
  17958. prepareFreshStack(root, expirationTime);
  17959. break;
  17960. }
  17961. }
  17962. var nextTime = getNextRootExpirationTimeToWorkOn(root);
  17963. if (nextTime !== NoWork && nextTime !== expirationTime) {
  17964. // There's additional work on this root.
  17965. break;
  17966. }
  17967. if (lastSuspendedTime !== NoWork && lastSuspendedTime !== expirationTime) {
  17968. // We should prefer to render the fallback of at the last
  17969. // suspended level. Ping the last suspended level to try
  17970. // rendering it again.
  17971. root.lastPingedTime = lastSuspendedTime;
  17972. break;
  17973. } // The render is suspended, it hasn't timed out, and there's no
  17974. // lower priority work to do. Instead of committing the fallback
  17975. // immediately, wait for more data to arrive.
  17976. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), msUntilTimeout);
  17977. break;
  17978. }
  17979. } // The work expired. Commit immediately.
  17980. commitRoot(root);
  17981. break;
  17982. }
  17983. case RootSuspendedWithDelay:
  17984. {
  17985. markRootSuspendedAtTime(root, expirationTime);
  17986. var _lastSuspendedTime = root.lastSuspendedTime;
  17987. if (expirationTime === _lastSuspendedTime) {
  17988. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  17989. }
  17990. if ( // do not delay if we're inside an act() scope
  17991. !( IsThisRendererActing.current)) {
  17992. // We're suspended in a state that should be avoided. We'll try to
  17993. // avoid committing it for as long as the timeouts let us.
  17994. if (workInProgressRootHasPendingPing) {
  17995. var _lastPingedTime = root.lastPingedTime;
  17996. if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
  17997. // This render was pinged but we didn't get to restart earlier
  17998. // so try restarting now instead.
  17999. root.lastPingedTime = expirationTime;
  18000. prepareFreshStack(root, expirationTime);
  18001. break;
  18002. }
  18003. }
  18004. var _nextTime = getNextRootExpirationTimeToWorkOn(root);
  18005. if (_nextTime !== NoWork && _nextTime !== expirationTime) {
  18006. // There's additional work on this root.
  18007. break;
  18008. }
  18009. if (_lastSuspendedTime !== NoWork && _lastSuspendedTime !== expirationTime) {
  18010. // We should prefer to render the fallback of at the last
  18011. // suspended level. Ping the last suspended level to try
  18012. // rendering it again.
  18013. root.lastPingedTime = _lastSuspendedTime;
  18014. break;
  18015. }
  18016. var _msUntilTimeout;
  18017. if (workInProgressRootLatestSuspenseTimeout !== Sync) {
  18018. // We have processed a suspense config whose expiration time we
  18019. // can use as the timeout.
  18020. _msUntilTimeout = expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
  18021. } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
  18022. // This should never normally happen because only new updates
  18023. // cause delayed states, so we should have processed something.
  18024. // However, this could also happen in an offscreen tree.
  18025. _msUntilTimeout = 0;
  18026. } else {
  18027. // If we don't have a suspense config, we're going to use a
  18028. // heuristic to determine how long we can suspend.
  18029. var eventTimeMs = inferTimeFromExpirationTime(workInProgressRootLatestProcessedExpirationTime);
  18030. var currentTimeMs = now();
  18031. var timeUntilExpirationMs = expirationTimeToMs(expirationTime) - currentTimeMs;
  18032. var timeElapsed = currentTimeMs - eventTimeMs;
  18033. if (timeElapsed < 0) {
  18034. // We get this wrong some time since we estimate the time.
  18035. timeElapsed = 0;
  18036. }
  18037. _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
  18038. // event time is exact instead of inferred from expiration time
  18039. // we don't need this.
  18040. if (timeUntilExpirationMs < _msUntilTimeout) {
  18041. _msUntilTimeout = timeUntilExpirationMs;
  18042. }
  18043. } // Don't bother with a very short suspense time.
  18044. if (_msUntilTimeout > 10) {
  18045. // The render is suspended, it hasn't timed out, and there's no
  18046. // lower priority work to do. Instead of committing the fallback
  18047. // immediately, wait for more data to arrive.
  18048. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout);
  18049. break;
  18050. }
  18051. } // The work expired. Commit immediately.
  18052. commitRoot(root);
  18053. break;
  18054. }
  18055. case RootCompleted:
  18056. {
  18057. // The work completed. Ready to commit.
  18058. if ( // do not delay if we're inside an act() scope
  18059. !( IsThisRendererActing.current) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null) {
  18060. // If we have exceeded the minimum loading delay, which probably
  18061. // means we have shown a spinner already, we might have to suspend
  18062. // a bit longer to ensure that the spinner is shown for
  18063. // enough time.
  18064. var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(workInProgressRootLatestProcessedExpirationTime, expirationTime, workInProgressRootCanSuspendUsingConfig);
  18065. if (_msUntilTimeout2 > 10) {
  18066. markRootSuspendedAtTime(root, expirationTime);
  18067. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout2);
  18068. break;
  18069. }
  18070. }
  18071. commitRoot(root);
  18072. break;
  18073. }
  18074. default:
  18075. {
  18076. {
  18077. {
  18078. throw Error( "Unknown root exit status." );
  18079. }
  18080. }
  18081. }
  18082. }
  18083. } // This is the entry point for synchronous tasks that don't go
  18084. // through Scheduler
  18085. function performSyncWorkOnRoot(root) {
  18086. // Check if there's expired work on this root. Otherwise, render at Sync.
  18087. var lastExpiredTime = root.lastExpiredTime;
  18088. var expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync;
  18089. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  18090. {
  18091. throw Error( "Should not already be working." );
  18092. }
  18093. }
  18094. flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
  18095. // and prepare a fresh one. Otherwise we'll continue where we left off.
  18096. if (root !== workInProgressRoot || expirationTime !== renderExpirationTime$1) {
  18097. prepareFreshStack(root, expirationTime);
  18098. startWorkOnPendingInteractions(root, expirationTime);
  18099. } // If we have a work-in-progress fiber, it means there's still work to do
  18100. // in this root.
  18101. if (workInProgress !== null) {
  18102. var prevExecutionContext = executionContext;
  18103. executionContext |= RenderContext;
  18104. var prevDispatcher = pushDispatcher();
  18105. var prevInteractions = pushInteractions(root);
  18106. startWorkLoopTimer(workInProgress);
  18107. do {
  18108. try {
  18109. workLoopSync();
  18110. break;
  18111. } catch (thrownValue) {
  18112. handleError(root, thrownValue);
  18113. }
  18114. } while (true);
  18115. resetContextDependencies();
  18116. executionContext = prevExecutionContext;
  18117. popDispatcher(prevDispatcher);
  18118. {
  18119. popInteractions(prevInteractions);
  18120. }
  18121. if (workInProgressRootExitStatus === RootFatalErrored) {
  18122. var fatalError = workInProgressRootFatalError;
  18123. stopInterruptedWorkLoopTimer();
  18124. prepareFreshStack(root, expirationTime);
  18125. markRootSuspendedAtTime(root, expirationTime);
  18126. ensureRootIsScheduled(root);
  18127. throw fatalError;
  18128. }
  18129. if (workInProgress !== null) {
  18130. // This is a sync render, so we should have finished the whole tree.
  18131. {
  18132. {
  18133. throw Error( "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." );
  18134. }
  18135. }
  18136. } else {
  18137. // We now have a consistent tree. Because this is a sync render, we
  18138. // will commit it even if something suspended.
  18139. stopFinishedWorkLoopTimer();
  18140. root.finishedWork = root.current.alternate;
  18141. root.finishedExpirationTime = expirationTime;
  18142. finishSyncRender(root);
  18143. } // Before exiting, make sure there's a callback scheduled for the next
  18144. // pending level.
  18145. ensureRootIsScheduled(root);
  18146. }
  18147. return null;
  18148. }
  18149. function finishSyncRender(root) {
  18150. // Set this to null to indicate there's no in-progress render.
  18151. workInProgressRoot = null;
  18152. commitRoot(root);
  18153. }
  18154. function flushDiscreteUpdates() {
  18155. // TODO: Should be able to flush inside batchedUpdates, but not inside `act`.
  18156. // However, `act` uses `batchedUpdates`, so there's no way to distinguish
  18157. // those two cases. Need to fix this before exposing flushDiscreteUpdates
  18158. // as a public API.
  18159. if ((executionContext & (BatchedContext | RenderContext | CommitContext)) !== NoContext) {
  18160. {
  18161. if ((executionContext & RenderContext) !== NoContext) {
  18162. error('unstable_flushDiscreteUpdates: Cannot flush updates when React is ' + 'already rendering.');
  18163. }
  18164. } // We're already rendering, so we can't synchronously flush pending work.
  18165. // This is probably a nested event dispatch triggered by a lifecycle/effect,
  18166. // like `el.focus()`. Exit.
  18167. return;
  18168. }
  18169. flushPendingDiscreteUpdates(); // If the discrete updates scheduled passive effects, flush them now so that
  18170. // they fire before the next serial event.
  18171. flushPassiveEffects();
  18172. }
  18173. function syncUpdates(fn, a, b, c) {
  18174. return runWithPriority$1(ImmediatePriority, fn.bind(null, a, b, c));
  18175. }
  18176. function flushPendingDiscreteUpdates() {
  18177. if (rootsWithPendingDiscreteUpdates !== null) {
  18178. // For each root with pending discrete updates, schedule a callback to
  18179. // immediately flush them.
  18180. var roots = rootsWithPendingDiscreteUpdates;
  18181. rootsWithPendingDiscreteUpdates = null;
  18182. roots.forEach(function (expirationTime, root) {
  18183. markRootExpiredAtTime(root, expirationTime);
  18184. ensureRootIsScheduled(root);
  18185. }); // Now flush the immediate queue.
  18186. flushSyncCallbackQueue();
  18187. }
  18188. }
  18189. function batchedUpdates$1(fn, a) {
  18190. var prevExecutionContext = executionContext;
  18191. executionContext |= BatchedContext;
  18192. try {
  18193. return fn(a);
  18194. } finally {
  18195. executionContext = prevExecutionContext;
  18196. if (executionContext === NoContext) {
  18197. // Flush the immediate callbacks that were scheduled during this batch
  18198. flushSyncCallbackQueue();
  18199. }
  18200. }
  18201. }
  18202. function batchedEventUpdates$1(fn, a) {
  18203. var prevExecutionContext = executionContext;
  18204. executionContext |= EventContext;
  18205. try {
  18206. return fn(a);
  18207. } finally {
  18208. executionContext = prevExecutionContext;
  18209. if (executionContext === NoContext) {
  18210. // Flush the immediate callbacks that were scheduled during this batch
  18211. flushSyncCallbackQueue();
  18212. }
  18213. }
  18214. }
  18215. function discreteUpdates$1(fn, a, b, c, d) {
  18216. var prevExecutionContext = executionContext;
  18217. executionContext |= DiscreteEventContext;
  18218. try {
  18219. // Should this
  18220. return runWithPriority$1(UserBlockingPriority$1, fn.bind(null, a, b, c, d));
  18221. } finally {
  18222. executionContext = prevExecutionContext;
  18223. if (executionContext === NoContext) {
  18224. // Flush the immediate callbacks that were scheduled during this batch
  18225. flushSyncCallbackQueue();
  18226. }
  18227. }
  18228. }
  18229. function unbatchedUpdates(fn, a) {
  18230. var prevExecutionContext = executionContext;
  18231. executionContext &= ~BatchedContext;
  18232. executionContext |= LegacyUnbatchedContext;
  18233. try {
  18234. return fn(a);
  18235. } finally {
  18236. executionContext = prevExecutionContext;
  18237. if (executionContext === NoContext) {
  18238. // Flush the immediate callbacks that were scheduled during this batch
  18239. flushSyncCallbackQueue();
  18240. }
  18241. }
  18242. }
  18243. function flushSync(fn, a) {
  18244. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  18245. {
  18246. {
  18247. throw Error( "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." );
  18248. }
  18249. }
  18250. }
  18251. var prevExecutionContext = executionContext;
  18252. executionContext |= BatchedContext;
  18253. try {
  18254. return runWithPriority$1(ImmediatePriority, fn.bind(null, a));
  18255. } finally {
  18256. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  18257. // Note that this will happen even if batchedUpdates is higher up
  18258. // the stack.
  18259. flushSyncCallbackQueue();
  18260. }
  18261. }
  18262. function prepareFreshStack(root, expirationTime) {
  18263. root.finishedWork = null;
  18264. root.finishedExpirationTime = NoWork;
  18265. var timeoutHandle = root.timeoutHandle;
  18266. if (timeoutHandle !== noTimeout) {
  18267. // The root previous suspended and scheduled a timeout to commit a fallback
  18268. // state. Now that we have additional work, cancel the timeout.
  18269. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  18270. cancelTimeout(timeoutHandle);
  18271. }
  18272. if (workInProgress !== null) {
  18273. var interruptedWork = workInProgress.return;
  18274. while (interruptedWork !== null) {
  18275. unwindInterruptedWork(interruptedWork);
  18276. interruptedWork = interruptedWork.return;
  18277. }
  18278. }
  18279. workInProgressRoot = root;
  18280. workInProgress = createWorkInProgress(root.current, null);
  18281. renderExpirationTime$1 = expirationTime;
  18282. workInProgressRootExitStatus = RootIncomplete;
  18283. workInProgressRootFatalError = null;
  18284. workInProgressRootLatestProcessedExpirationTime = Sync;
  18285. workInProgressRootLatestSuspenseTimeout = Sync;
  18286. workInProgressRootCanSuspendUsingConfig = null;
  18287. workInProgressRootNextUnprocessedUpdateTime = NoWork;
  18288. workInProgressRootHasPendingPing = false;
  18289. {
  18290. spawnedWorkDuringRender = null;
  18291. }
  18292. {
  18293. ReactStrictModeWarnings.discardPendingWarnings();
  18294. }
  18295. }
  18296. function handleError(root, thrownValue) {
  18297. do {
  18298. try {
  18299. // Reset module-level state that was set during the render phase.
  18300. resetContextDependencies();
  18301. resetHooksAfterThrow();
  18302. resetCurrentFiber();
  18303. if (workInProgress === null || workInProgress.return === null) {
  18304. // Expected to be working on a non-root fiber. This is a fatal error
  18305. // because there's no ancestor that can handle it; the root is
  18306. // supposed to capture all errors that weren't caught by an error
  18307. // boundary.
  18308. workInProgressRootExitStatus = RootFatalErrored;
  18309. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  18310. // sibling, or the parent if there are no siblings. But since the root
  18311. // has no siblings nor a parent, we set it to null. Usually this is
  18312. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  18313. // interntionally not calling those, we need set it here.
  18314. // TODO: Consider calling `unwindWork` to pop the contexts.
  18315. workInProgress = null;
  18316. return null;
  18317. }
  18318. if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
  18319. // Record the time spent rendering before an error was thrown. This
  18320. // avoids inaccurate Profiler durations in the case of a
  18321. // suspended render.
  18322. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
  18323. }
  18324. throwException(root, workInProgress.return, workInProgress, thrownValue, renderExpirationTime$1);
  18325. workInProgress = completeUnitOfWork(workInProgress);
  18326. } catch (yetAnotherThrownValue) {
  18327. // Something in the return path also threw.
  18328. thrownValue = yetAnotherThrownValue;
  18329. continue;
  18330. } // Return to the normal work loop.
  18331. return;
  18332. } while (true);
  18333. }
  18334. function pushDispatcher(root) {
  18335. var prevDispatcher = ReactCurrentDispatcher$1.current;
  18336. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  18337. if (prevDispatcher === null) {
  18338. // The React isomorphic package does not include a default dispatcher.
  18339. // Instead the first renderer will lazily attach one, in order to give
  18340. // nicer error messages.
  18341. return ContextOnlyDispatcher;
  18342. } else {
  18343. return prevDispatcher;
  18344. }
  18345. }
  18346. function popDispatcher(prevDispatcher) {
  18347. ReactCurrentDispatcher$1.current = prevDispatcher;
  18348. }
  18349. function pushInteractions(root) {
  18350. {
  18351. var prevInteractions = __interactionsRef.current;
  18352. __interactionsRef.current = root.memoizedInteractions;
  18353. return prevInteractions;
  18354. }
  18355. }
  18356. function popInteractions(prevInteractions) {
  18357. {
  18358. __interactionsRef.current = prevInteractions;
  18359. }
  18360. }
  18361. function markCommitTimeOfFallback() {
  18362. globalMostRecentFallbackTime = now();
  18363. }
  18364. function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
  18365. if (expirationTime < workInProgressRootLatestProcessedExpirationTime && expirationTime > Idle) {
  18366. workInProgressRootLatestProcessedExpirationTime = expirationTime;
  18367. }
  18368. if (suspenseConfig !== null) {
  18369. if (expirationTime < workInProgressRootLatestSuspenseTimeout && expirationTime > Idle) {
  18370. workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
  18371. workInProgressRootCanSuspendUsingConfig = suspenseConfig;
  18372. }
  18373. }
  18374. }
  18375. function markUnprocessedUpdateTime(expirationTime) {
  18376. if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
  18377. workInProgressRootNextUnprocessedUpdateTime = expirationTime;
  18378. }
  18379. }
  18380. function renderDidSuspend() {
  18381. if (workInProgressRootExitStatus === RootIncomplete) {
  18382. workInProgressRootExitStatus = RootSuspended;
  18383. }
  18384. }
  18385. function renderDidSuspendDelayIfPossible() {
  18386. if (workInProgressRootExitStatus === RootIncomplete || workInProgressRootExitStatus === RootSuspended) {
  18387. workInProgressRootExitStatus = RootSuspendedWithDelay;
  18388. } // Check if there's a lower priority update somewhere else in the tree.
  18389. if (workInProgressRootNextUnprocessedUpdateTime !== NoWork && workInProgressRoot !== null) {
  18390. // Mark the current render as suspended, and then mark that there's a
  18391. // pending update.
  18392. // TODO: This should immediately interrupt the current render, instead
  18393. // of waiting until the next time we yield.
  18394. markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime$1);
  18395. markRootUpdatedAtTime(workInProgressRoot, workInProgressRootNextUnprocessedUpdateTime);
  18396. }
  18397. }
  18398. function renderDidError() {
  18399. if (workInProgressRootExitStatus !== RootCompleted) {
  18400. workInProgressRootExitStatus = RootErrored;
  18401. }
  18402. } // Called during render to determine if anything has suspended.
  18403. // Returns false if we're not sure.
  18404. function renderHasNotSuspendedYet() {
  18405. // If something errored or completed, we can't really be sure,
  18406. // so those are false.
  18407. return workInProgressRootExitStatus === RootIncomplete;
  18408. }
  18409. function inferTimeFromExpirationTime(expirationTime) {
  18410. // We don't know exactly when the update was scheduled, but we can infer an
  18411. // approximate start time from the expiration time.
  18412. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  18413. return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
  18414. }
  18415. function inferTimeFromExpirationTimeWithSuspenseConfig(expirationTime, suspenseConfig) {
  18416. // We don't know exactly when the update was scheduled, but we can infer an
  18417. // approximate start time from the expiration time by subtracting the timeout
  18418. // that was added to the event time.
  18419. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  18420. return earliestExpirationTimeMs - (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
  18421. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  18422. /** @noinline */
  18423. function workLoopSync() {
  18424. // Already timed out, so perform work without checking if we need to yield.
  18425. while (workInProgress !== null) {
  18426. workInProgress = performUnitOfWork(workInProgress);
  18427. }
  18428. }
  18429. /** @noinline */
  18430. function workLoopConcurrent() {
  18431. // Perform work until Scheduler asks us to yield
  18432. while (workInProgress !== null && !shouldYield()) {
  18433. workInProgress = performUnitOfWork(workInProgress);
  18434. }
  18435. }
  18436. function performUnitOfWork(unitOfWork) {
  18437. // The current, flushed, state of this fiber is the alternate. Ideally
  18438. // nothing should rely on this, but relying on it here means that we don't
  18439. // need an additional field on the work in progress.
  18440. var current = unitOfWork.alternate;
  18441. startWorkTimer(unitOfWork);
  18442. setCurrentFiber(unitOfWork);
  18443. var next;
  18444. if ( (unitOfWork.mode & ProfileMode) !== NoMode) {
  18445. startProfilerTimer(unitOfWork);
  18446. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  18447. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  18448. } else {
  18449. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  18450. }
  18451. resetCurrentFiber();
  18452. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  18453. if (next === null) {
  18454. // If this doesn't spawn new work, complete the current work.
  18455. next = completeUnitOfWork(unitOfWork);
  18456. }
  18457. ReactCurrentOwner$2.current = null;
  18458. return next;
  18459. }
  18460. function completeUnitOfWork(unitOfWork) {
  18461. // Attempt to complete the current unit of work, then move to the next
  18462. // sibling. If there are no more siblings, return to the parent fiber.
  18463. workInProgress = unitOfWork;
  18464. do {
  18465. // The current, flushed, state of this fiber is the alternate. Ideally
  18466. // nothing should rely on this, but relying on it here means that we don't
  18467. // need an additional field on the work in progress.
  18468. var current = workInProgress.alternate;
  18469. var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
  18470. if ((workInProgress.effectTag & Incomplete) === NoEffect) {
  18471. setCurrentFiber(workInProgress);
  18472. var next = void 0;
  18473. if ( (workInProgress.mode & ProfileMode) === NoMode) {
  18474. next = completeWork(current, workInProgress, renderExpirationTime$1);
  18475. } else {
  18476. startProfilerTimer(workInProgress);
  18477. next = completeWork(current, workInProgress, renderExpirationTime$1); // Update render duration assuming we didn't error.
  18478. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
  18479. }
  18480. stopWorkTimer(workInProgress);
  18481. resetCurrentFiber();
  18482. resetChildExpirationTime(workInProgress);
  18483. if (next !== null) {
  18484. // Completing this fiber spawned new work. Work on that next.
  18485. return next;
  18486. }
  18487. if (returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  18488. (returnFiber.effectTag & Incomplete) === NoEffect) {
  18489. // Append all the effects of the subtree and this fiber onto the effect
  18490. // list of the parent. The completion order of the children affects the
  18491. // side-effect order.
  18492. if (returnFiber.firstEffect === null) {
  18493. returnFiber.firstEffect = workInProgress.firstEffect;
  18494. }
  18495. if (workInProgress.lastEffect !== null) {
  18496. if (returnFiber.lastEffect !== null) {
  18497. returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
  18498. }
  18499. returnFiber.lastEffect = workInProgress.lastEffect;
  18500. } // If this fiber had side-effects, we append it AFTER the children's
  18501. // side-effects. We can perform certain side-effects earlier if needed,
  18502. // by doing multiple passes over the effect list. We don't want to
  18503. // schedule our own side-effect on our own list because if end up
  18504. // reusing children we'll schedule this effect onto itself since we're
  18505. // at the end.
  18506. var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
  18507. // list. PerformedWork effect is read by React DevTools but shouldn't be
  18508. // committed.
  18509. if (effectTag > PerformedWork) {
  18510. if (returnFiber.lastEffect !== null) {
  18511. returnFiber.lastEffect.nextEffect = workInProgress;
  18512. } else {
  18513. returnFiber.firstEffect = workInProgress;
  18514. }
  18515. returnFiber.lastEffect = workInProgress;
  18516. }
  18517. }
  18518. } else {
  18519. // This fiber did not complete because something threw. Pop values off
  18520. // the stack without entering the complete phase. If this is a boundary,
  18521. // capture values if possible.
  18522. var _next = unwindWork(workInProgress); // Because this fiber did not complete, don't reset its expiration time.
  18523. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  18524. // Record the render duration for the fiber that errored.
  18525. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
  18526. var actualDuration = workInProgress.actualDuration;
  18527. var child = workInProgress.child;
  18528. while (child !== null) {
  18529. actualDuration += child.actualDuration;
  18530. child = child.sibling;
  18531. }
  18532. workInProgress.actualDuration = actualDuration;
  18533. }
  18534. if (_next !== null) {
  18535. // If completing this work spawned new work, do that next. We'll come
  18536. // back here again.
  18537. // Since we're restarting, remove anything that is not a host effect
  18538. // from the effect tag.
  18539. // TODO: The name stopFailedWorkTimer is misleading because Suspense
  18540. // also captures and restarts.
  18541. stopFailedWorkTimer(workInProgress);
  18542. _next.effectTag &= HostEffectMask;
  18543. return _next;
  18544. }
  18545. stopWorkTimer(workInProgress);
  18546. if (returnFiber !== null) {
  18547. // Mark the parent fiber as incomplete and clear its effect list.
  18548. returnFiber.firstEffect = returnFiber.lastEffect = null;
  18549. returnFiber.effectTag |= Incomplete;
  18550. }
  18551. }
  18552. var siblingFiber = workInProgress.sibling;
  18553. if (siblingFiber !== null) {
  18554. // If there is more work to do in this returnFiber, do that next.
  18555. return siblingFiber;
  18556. } // Otherwise, return to the parent
  18557. workInProgress = returnFiber;
  18558. } while (workInProgress !== null); // We've reached the root.
  18559. if (workInProgressRootExitStatus === RootIncomplete) {
  18560. workInProgressRootExitStatus = RootCompleted;
  18561. }
  18562. return null;
  18563. }
  18564. function getRemainingExpirationTime(fiber) {
  18565. var updateExpirationTime = fiber.expirationTime;
  18566. var childExpirationTime = fiber.childExpirationTime;
  18567. return updateExpirationTime > childExpirationTime ? updateExpirationTime : childExpirationTime;
  18568. }
  18569. function resetChildExpirationTime(completedWork) {
  18570. if (renderExpirationTime$1 !== Never && completedWork.childExpirationTime === Never) {
  18571. // The children of this component are hidden. Don't bubble their
  18572. // expiration times.
  18573. return;
  18574. }
  18575. var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
  18576. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  18577. // In profiling mode, resetChildExpirationTime is also used to reset
  18578. // profiler durations.
  18579. var actualDuration = completedWork.actualDuration;
  18580. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  18581. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  18582. // When work is done, it should bubble to the parent's actualDuration. If
  18583. // the fiber has not been cloned though, (meaning no work was done), then
  18584. // this value will reflect the amount of time spent working on a previous
  18585. // render. In that case it should not bubble. We determine whether it was
  18586. // cloned by comparing the child pointer.
  18587. var shouldBubbleActualDurations = completedWork.alternate === null || completedWork.child !== completedWork.alternate.child;
  18588. var child = completedWork.child;
  18589. while (child !== null) {
  18590. var childUpdateExpirationTime = child.expirationTime;
  18591. var childChildExpirationTime = child.childExpirationTime;
  18592. if (childUpdateExpirationTime > newChildExpirationTime) {
  18593. newChildExpirationTime = childUpdateExpirationTime;
  18594. }
  18595. if (childChildExpirationTime > newChildExpirationTime) {
  18596. newChildExpirationTime = childChildExpirationTime;
  18597. }
  18598. if (shouldBubbleActualDurations) {
  18599. actualDuration += child.actualDuration;
  18600. }
  18601. treeBaseDuration += child.treeBaseDuration;
  18602. child = child.sibling;
  18603. }
  18604. completedWork.actualDuration = actualDuration;
  18605. completedWork.treeBaseDuration = treeBaseDuration;
  18606. } else {
  18607. var _child = completedWork.child;
  18608. while (_child !== null) {
  18609. var _childUpdateExpirationTime = _child.expirationTime;
  18610. var _childChildExpirationTime = _child.childExpirationTime;
  18611. if (_childUpdateExpirationTime > newChildExpirationTime) {
  18612. newChildExpirationTime = _childUpdateExpirationTime;
  18613. }
  18614. if (_childChildExpirationTime > newChildExpirationTime) {
  18615. newChildExpirationTime = _childChildExpirationTime;
  18616. }
  18617. _child = _child.sibling;
  18618. }
  18619. }
  18620. completedWork.childExpirationTime = newChildExpirationTime;
  18621. }
  18622. function commitRoot(root) {
  18623. var renderPriorityLevel = getCurrentPriorityLevel();
  18624. runWithPriority$1(ImmediatePriority, commitRootImpl.bind(null, root, renderPriorityLevel));
  18625. return null;
  18626. }
  18627. function commitRootImpl(root, renderPriorityLevel) {
  18628. do {
  18629. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  18630. // means `flushPassiveEffects` will sometimes result in additional
  18631. // passive effects. So we need to keep flushing in a loop until there are
  18632. // no more pending effects.
  18633. // TODO: Might be better if `flushPassiveEffects` did not automatically
  18634. // flush synchronous work at the end, to avoid factoring hazards like this.
  18635. flushPassiveEffects();
  18636. } while (rootWithPendingPassiveEffects !== null);
  18637. flushRenderPhaseStrictModeWarningsInDEV();
  18638. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  18639. {
  18640. throw Error( "Should not already be working." );
  18641. }
  18642. }
  18643. var finishedWork = root.finishedWork;
  18644. var expirationTime = root.finishedExpirationTime;
  18645. if (finishedWork === null) {
  18646. return null;
  18647. }
  18648. root.finishedWork = null;
  18649. root.finishedExpirationTime = NoWork;
  18650. if (!(finishedWork !== root.current)) {
  18651. {
  18652. throw Error( "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue." );
  18653. }
  18654. } // commitRoot never returns a continuation; it always finishes synchronously.
  18655. // So we can clear these now to allow a new callback to be scheduled.
  18656. root.callbackNode = null;
  18657. root.callbackExpirationTime = NoWork;
  18658. root.callbackPriority = NoPriority;
  18659. root.nextKnownPendingLevel = NoWork;
  18660. startCommitTimer(); // Update the first and last pending times on this root. The new first
  18661. // pending time is whatever is left on the root fiber.
  18662. var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(finishedWork);
  18663. markRootFinishedAtTime(root, expirationTime, remainingExpirationTimeBeforeCommit);
  18664. if (root === workInProgressRoot) {
  18665. // We can reset these now that they are finished.
  18666. workInProgressRoot = null;
  18667. workInProgress = null;
  18668. renderExpirationTime$1 = NoWork;
  18669. } // This indicates that the last root we worked on is not the same one that
  18670. // we're committing now. This most commonly happens when a suspended root
  18671. // times out.
  18672. // Get the list of effects.
  18673. var firstEffect;
  18674. if (finishedWork.effectTag > PerformedWork) {
  18675. // A fiber's effect list consists only of its children, not itself. So if
  18676. // the root has an effect, we need to add it to the end of the list. The
  18677. // resulting list is the set that would belong to the root's parent, if it
  18678. // had one; that is, all the effects in the tree including the root.
  18679. if (finishedWork.lastEffect !== null) {
  18680. finishedWork.lastEffect.nextEffect = finishedWork;
  18681. firstEffect = finishedWork.firstEffect;
  18682. } else {
  18683. firstEffect = finishedWork;
  18684. }
  18685. } else {
  18686. // There is no effect on the root.
  18687. firstEffect = finishedWork.firstEffect;
  18688. }
  18689. if (firstEffect !== null) {
  18690. var prevExecutionContext = executionContext;
  18691. executionContext |= CommitContext;
  18692. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  18693. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  18694. // of the effect list for each phase: all mutation effects come before all
  18695. // layout effects, and so on.
  18696. // The first phase a "before mutation" phase. We use this phase to read the
  18697. // state of the host tree right before we mutate it. This is where
  18698. // getSnapshotBeforeUpdate is called.
  18699. startCommitSnapshotEffectsTimer();
  18700. prepareForCommit(root.containerInfo);
  18701. nextEffect = firstEffect;
  18702. do {
  18703. {
  18704. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  18705. if (hasCaughtError()) {
  18706. if (!(nextEffect !== null)) {
  18707. {
  18708. throw Error( "Should be working on an effect." );
  18709. }
  18710. }
  18711. var error = clearCaughtError();
  18712. captureCommitPhaseError(nextEffect, error);
  18713. nextEffect = nextEffect.nextEffect;
  18714. }
  18715. }
  18716. } while (nextEffect !== null);
  18717. stopCommitSnapshotEffectsTimer();
  18718. {
  18719. // Mark the current commit time to be shared by all Profilers in this
  18720. // batch. This enables them to be grouped later.
  18721. recordCommitTime();
  18722. } // The next phase is the mutation phase, where we mutate the host tree.
  18723. startCommitHostEffectsTimer();
  18724. nextEffect = firstEffect;
  18725. do {
  18726. {
  18727. invokeGuardedCallback(null, commitMutationEffects, null, root, renderPriorityLevel);
  18728. if (hasCaughtError()) {
  18729. if (!(nextEffect !== null)) {
  18730. {
  18731. throw Error( "Should be working on an effect." );
  18732. }
  18733. }
  18734. var _error = clearCaughtError();
  18735. captureCommitPhaseError(nextEffect, _error);
  18736. nextEffect = nextEffect.nextEffect;
  18737. }
  18738. }
  18739. } while (nextEffect !== null);
  18740. stopCommitHostEffectsTimer();
  18741. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  18742. // the mutation phase, so that the previous tree is still current during
  18743. // componentWillUnmount, but before the layout phase, so that the finished
  18744. // work is current during componentDidMount/Update.
  18745. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  18746. // the host tree after it's been mutated. The idiomatic use case for this is
  18747. // layout, but class component lifecycles also fire here for legacy reasons.
  18748. startCommitLifeCyclesTimer();
  18749. nextEffect = firstEffect;
  18750. do {
  18751. {
  18752. invokeGuardedCallback(null, commitLayoutEffects, null, root, expirationTime);
  18753. if (hasCaughtError()) {
  18754. if (!(nextEffect !== null)) {
  18755. {
  18756. throw Error( "Should be working on an effect." );
  18757. }
  18758. }
  18759. var _error2 = clearCaughtError();
  18760. captureCommitPhaseError(nextEffect, _error2);
  18761. nextEffect = nextEffect.nextEffect;
  18762. }
  18763. }
  18764. } while (nextEffect !== null);
  18765. stopCommitLifeCyclesTimer();
  18766. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  18767. // opportunity to paint.
  18768. requestPaint();
  18769. {
  18770. popInteractions(prevInteractions);
  18771. }
  18772. executionContext = prevExecutionContext;
  18773. } else {
  18774. // No effects.
  18775. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  18776. // no effects.
  18777. // TODO: Maybe there's a better way to report this.
  18778. startCommitSnapshotEffectsTimer();
  18779. stopCommitSnapshotEffectsTimer();
  18780. {
  18781. recordCommitTime();
  18782. }
  18783. startCommitHostEffectsTimer();
  18784. stopCommitHostEffectsTimer();
  18785. startCommitLifeCyclesTimer();
  18786. stopCommitLifeCyclesTimer();
  18787. }
  18788. stopCommitTimer();
  18789. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  18790. if (rootDoesHavePassiveEffects) {
  18791. // This commit has passive effects. Stash a reference to them. But don't
  18792. // schedule a callback until after flushing layout work.
  18793. rootDoesHavePassiveEffects = false;
  18794. rootWithPendingPassiveEffects = root;
  18795. pendingPassiveEffectsExpirationTime = expirationTime;
  18796. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  18797. } else {
  18798. // We are done with the effect chain at this point so let's clear the
  18799. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  18800. // clear this in flushPassiveEffects.
  18801. nextEffect = firstEffect;
  18802. while (nextEffect !== null) {
  18803. var nextNextEffect = nextEffect.nextEffect;
  18804. nextEffect.nextEffect = null;
  18805. nextEffect = nextNextEffect;
  18806. }
  18807. } // Check if there's remaining work on this root
  18808. var remainingExpirationTime = root.firstPendingTime;
  18809. if (remainingExpirationTime !== NoWork) {
  18810. {
  18811. if (spawnedWorkDuringRender !== null) {
  18812. var expirationTimes = spawnedWorkDuringRender;
  18813. spawnedWorkDuringRender = null;
  18814. for (var i = 0; i < expirationTimes.length; i++) {
  18815. scheduleInteractions(root, expirationTimes[i], root.memoizedInteractions);
  18816. }
  18817. }
  18818. schedulePendingInteractions(root, remainingExpirationTime);
  18819. }
  18820. } else {
  18821. // If there's no remaining work, we can clear the set of already failed
  18822. // error boundaries.
  18823. legacyErrorBoundariesThatAlreadyFailed = null;
  18824. }
  18825. {
  18826. if (!rootDidHavePassiveEffects) {
  18827. // If there are no passive effects, then we can complete the pending interactions.
  18828. // Otherwise, we'll wait until after the passive effects are flushed.
  18829. // Wait to do this until after remaining work has been scheduled,
  18830. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  18831. finishPendingInteractions(root, expirationTime);
  18832. }
  18833. }
  18834. if (remainingExpirationTime === Sync) {
  18835. // Count the number of times the root synchronously re-renders without
  18836. // finishing. If there are too many, it indicates an infinite update loop.
  18837. if (root === rootWithNestedUpdates) {
  18838. nestedUpdateCount++;
  18839. } else {
  18840. nestedUpdateCount = 0;
  18841. rootWithNestedUpdates = root;
  18842. }
  18843. } else {
  18844. nestedUpdateCount = 0;
  18845. }
  18846. onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
  18847. // additional work on this root is scheduled.
  18848. ensureRootIsScheduled(root);
  18849. if (hasUncaughtError) {
  18850. hasUncaughtError = false;
  18851. var _error3 = firstUncaughtError;
  18852. firstUncaughtError = null;
  18853. throw _error3;
  18854. }
  18855. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  18856. // This is a legacy edge case. We just committed the initial mount of
  18857. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  18858. // synchronously, but layout updates should be deferred until the end
  18859. // of the batch.
  18860. return null;
  18861. } // If layout work was scheduled, flush it now.
  18862. flushSyncCallbackQueue();
  18863. return null;
  18864. }
  18865. function commitBeforeMutationEffects() {
  18866. while (nextEffect !== null) {
  18867. var effectTag = nextEffect.effectTag;
  18868. if ((effectTag & Snapshot) !== NoEffect) {
  18869. setCurrentFiber(nextEffect);
  18870. recordEffect();
  18871. var current = nextEffect.alternate;
  18872. commitBeforeMutationLifeCycles(current, nextEffect);
  18873. resetCurrentFiber();
  18874. }
  18875. if ((effectTag & Passive) !== NoEffect) {
  18876. // If there are passive effects, schedule a callback to flush at
  18877. // the earliest opportunity.
  18878. if (!rootDoesHavePassiveEffects) {
  18879. rootDoesHavePassiveEffects = true;
  18880. scheduleCallback(NormalPriority, function () {
  18881. flushPassiveEffects();
  18882. return null;
  18883. });
  18884. }
  18885. }
  18886. nextEffect = nextEffect.nextEffect;
  18887. }
  18888. }
  18889. function commitMutationEffects(root, renderPriorityLevel) {
  18890. // TODO: Should probably move the bulk of this function to commitWork.
  18891. while (nextEffect !== null) {
  18892. setCurrentFiber(nextEffect);
  18893. var effectTag = nextEffect.effectTag;
  18894. if (effectTag & ContentReset) {
  18895. commitResetTextContent(nextEffect);
  18896. }
  18897. if (effectTag & Ref) {
  18898. var current = nextEffect.alternate;
  18899. if (current !== null) {
  18900. commitDetachRef(current);
  18901. }
  18902. } // The following switch statement is only concerned about placement,
  18903. // updates, and deletions. To avoid needing to add a case for every possible
  18904. // bitmap value, we remove the secondary effects from the effect tag and
  18905. // switch on that value.
  18906. var primaryEffectTag = effectTag & (Placement | Update | Deletion | Hydrating);
  18907. switch (primaryEffectTag) {
  18908. case Placement:
  18909. {
  18910. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  18911. // inserted, before any life-cycles like componentDidMount gets called.
  18912. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  18913. // and isMounted is deprecated anyway so we should be able to kill this.
  18914. nextEffect.effectTag &= ~Placement;
  18915. break;
  18916. }
  18917. case PlacementAndUpdate:
  18918. {
  18919. // Placement
  18920. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  18921. // inserted, before any life-cycles like componentDidMount gets called.
  18922. nextEffect.effectTag &= ~Placement; // Update
  18923. var _current = nextEffect.alternate;
  18924. commitWork(_current, nextEffect);
  18925. break;
  18926. }
  18927. case Hydrating:
  18928. {
  18929. nextEffect.effectTag &= ~Hydrating;
  18930. break;
  18931. }
  18932. case HydratingAndUpdate:
  18933. {
  18934. nextEffect.effectTag &= ~Hydrating; // Update
  18935. var _current2 = nextEffect.alternate;
  18936. commitWork(_current2, nextEffect);
  18937. break;
  18938. }
  18939. case Update:
  18940. {
  18941. var _current3 = nextEffect.alternate;
  18942. commitWork(_current3, nextEffect);
  18943. break;
  18944. }
  18945. case Deletion:
  18946. {
  18947. commitDeletion(root, nextEffect, renderPriorityLevel);
  18948. break;
  18949. }
  18950. } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
  18951. recordEffect();
  18952. resetCurrentFiber();
  18953. nextEffect = nextEffect.nextEffect;
  18954. }
  18955. }
  18956. function commitLayoutEffects(root, committedExpirationTime) {
  18957. // TODO: Should probably move the bulk of this function to commitWork.
  18958. while (nextEffect !== null) {
  18959. setCurrentFiber(nextEffect);
  18960. var effectTag = nextEffect.effectTag;
  18961. if (effectTag & (Update | Callback)) {
  18962. recordEffect();
  18963. var current = nextEffect.alternate;
  18964. commitLifeCycles(root, current, nextEffect);
  18965. }
  18966. if (effectTag & Ref) {
  18967. recordEffect();
  18968. commitAttachRef(nextEffect);
  18969. }
  18970. resetCurrentFiber();
  18971. nextEffect = nextEffect.nextEffect;
  18972. }
  18973. }
  18974. function flushPassiveEffects() {
  18975. if (pendingPassiveEffectsRenderPriority !== NoPriority) {
  18976. var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority ? NormalPriority : pendingPassiveEffectsRenderPriority;
  18977. pendingPassiveEffectsRenderPriority = NoPriority;
  18978. return runWithPriority$1(priorityLevel, flushPassiveEffectsImpl);
  18979. }
  18980. }
  18981. function flushPassiveEffectsImpl() {
  18982. if (rootWithPendingPassiveEffects === null) {
  18983. return false;
  18984. }
  18985. var root = rootWithPendingPassiveEffects;
  18986. var expirationTime = pendingPassiveEffectsExpirationTime;
  18987. rootWithPendingPassiveEffects = null;
  18988. pendingPassiveEffectsExpirationTime = NoWork;
  18989. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  18990. {
  18991. throw Error( "Cannot flush passive effects while already rendering." );
  18992. }
  18993. }
  18994. var prevExecutionContext = executionContext;
  18995. executionContext |= CommitContext;
  18996. var prevInteractions = pushInteractions(root);
  18997. {
  18998. // Note: This currently assumes there are no passive effects on the root fiber
  18999. // because the root is not part of its own effect list.
  19000. // This could change in the future.
  19001. var _effect2 = root.current.firstEffect;
  19002. while (_effect2 !== null) {
  19003. {
  19004. setCurrentFiber(_effect2);
  19005. invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
  19006. if (hasCaughtError()) {
  19007. if (!(_effect2 !== null)) {
  19008. {
  19009. throw Error( "Should be working on an effect." );
  19010. }
  19011. }
  19012. var _error5 = clearCaughtError();
  19013. captureCommitPhaseError(_effect2, _error5);
  19014. }
  19015. resetCurrentFiber();
  19016. }
  19017. var nextNextEffect = _effect2.nextEffect; // Remove nextEffect pointer to assist GC
  19018. _effect2.nextEffect = null;
  19019. _effect2 = nextNextEffect;
  19020. }
  19021. }
  19022. {
  19023. popInteractions(prevInteractions);
  19024. finishPendingInteractions(root, expirationTime);
  19025. }
  19026. executionContext = prevExecutionContext;
  19027. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  19028. // exceeds the limit, we'll fire a warning.
  19029. nestedPassiveUpdateCount = rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  19030. return true;
  19031. }
  19032. function isAlreadyFailedLegacyErrorBoundary(instance) {
  19033. return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
  19034. }
  19035. function markLegacyErrorBoundaryAsFailed(instance) {
  19036. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  19037. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  19038. } else {
  19039. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  19040. }
  19041. }
  19042. function prepareToThrowUncaughtError(error) {
  19043. if (!hasUncaughtError) {
  19044. hasUncaughtError = true;
  19045. firstUncaughtError = error;
  19046. }
  19047. }
  19048. var onUncaughtError = prepareToThrowUncaughtError;
  19049. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  19050. var errorInfo = createCapturedValue(error, sourceFiber);
  19051. var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
  19052. enqueueUpdate(rootFiber, update);
  19053. var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
  19054. if (root !== null) {
  19055. ensureRootIsScheduled(root);
  19056. schedulePendingInteractions(root, Sync);
  19057. }
  19058. }
  19059. function captureCommitPhaseError(sourceFiber, error) {
  19060. if (sourceFiber.tag === HostRoot) {
  19061. // Error was thrown at the root. There is no parent, so the root
  19062. // itself should capture it.
  19063. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  19064. return;
  19065. }
  19066. var fiber = sourceFiber.return;
  19067. while (fiber !== null) {
  19068. if (fiber.tag === HostRoot) {
  19069. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  19070. return;
  19071. } else if (fiber.tag === ClassComponent) {
  19072. var ctor = fiber.type;
  19073. var instance = fiber.stateNode;
  19074. if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
  19075. var errorInfo = createCapturedValue(error, sourceFiber);
  19076. var update = createClassErrorUpdate(fiber, errorInfo, // TODO: This is always sync
  19077. Sync);
  19078. enqueueUpdate(fiber, update);
  19079. var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
  19080. if (root !== null) {
  19081. ensureRootIsScheduled(root);
  19082. schedulePendingInteractions(root, Sync);
  19083. }
  19084. return;
  19085. }
  19086. }
  19087. fiber = fiber.return;
  19088. }
  19089. }
  19090. function pingSuspendedRoot(root, thenable, suspendedTime) {
  19091. var pingCache = root.pingCache;
  19092. if (pingCache !== null) {
  19093. // The thenable resolved, so we no longer need to memoize, because it will
  19094. // never be thrown again.
  19095. pingCache.delete(thenable);
  19096. }
  19097. if (workInProgressRoot === root && renderExpirationTime$1 === suspendedTime) {
  19098. // Received a ping at the same priority level at which we're currently
  19099. // rendering. We might want to restart this render. This should mirror
  19100. // the logic of whether or not a root suspends once it completes.
  19101. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  19102. // we should probably never restart.
  19103. // If we're suspended with delay, we'll always suspend so we can always
  19104. // restart. If we're suspended without any updates, it might be a retry.
  19105. // If it's early in the retry we can restart. We can't know for sure
  19106. // whether we'll eventually process an update during this render pass,
  19107. // but it's somewhat unlikely that we get to a ping before that, since
  19108. // getting to the root most update is usually very fast.
  19109. if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && workInProgressRootLatestProcessedExpirationTime === Sync && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
  19110. // Restart from the root. Don't need to schedule a ping because
  19111. // we're already working on this tree.
  19112. prepareFreshStack(root, renderExpirationTime$1);
  19113. } else {
  19114. // Even though we can't restart right now, we might get an
  19115. // opportunity later. So we mark this render as having a ping.
  19116. workInProgressRootHasPendingPing = true;
  19117. }
  19118. return;
  19119. }
  19120. if (!isRootSuspendedAtTime(root, suspendedTime)) {
  19121. // The root is no longer suspended at this time.
  19122. return;
  19123. }
  19124. var lastPingedTime = root.lastPingedTime;
  19125. if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
  19126. // There's already a lower priority ping scheduled.
  19127. return;
  19128. } // Mark the time at which this ping was scheduled.
  19129. root.lastPingedTime = suspendedTime;
  19130. ensureRootIsScheduled(root);
  19131. schedulePendingInteractions(root, suspendedTime);
  19132. }
  19133. function retryTimedOutBoundary(boundaryFiber, retryTime) {
  19134. // The boundary fiber (a Suspense component or SuspenseList component)
  19135. // previously was rendered in its fallback state. One of the promises that
  19136. // suspended it has resolved, which means at least part of the tree was
  19137. // likely unblocked. Try rendering again, at a new expiration time.
  19138. if (retryTime === NoWork) {
  19139. var suspenseConfig = null; // Retries don't carry over the already committed update.
  19140. var currentTime = requestCurrentTimeForUpdate();
  19141. retryTime = computeExpirationForFiber(currentTime, boundaryFiber, suspenseConfig);
  19142. } // TODO: Special case idle priority?
  19143. var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
  19144. if (root !== null) {
  19145. ensureRootIsScheduled(root);
  19146. schedulePendingInteractions(root, retryTime);
  19147. }
  19148. }
  19149. function resolveRetryThenable(boundaryFiber, thenable) {
  19150. var retryTime = NoWork; // Default
  19151. var retryCache;
  19152. {
  19153. retryCache = boundaryFiber.stateNode;
  19154. }
  19155. if (retryCache !== null) {
  19156. // The thenable resolved, so we no longer need to memoize, because it will
  19157. // never be thrown again.
  19158. retryCache.delete(thenable);
  19159. }
  19160. retryTimedOutBoundary(boundaryFiber, retryTime);
  19161. } // Computes the next Just Noticeable Difference (JND) boundary.
  19162. // The theory is that a person can't tell the difference between small differences in time.
  19163. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  19164. // difference in the experience. However, waiting for longer might mean that we can avoid
  19165. // showing an intermediate loading state. The longer we have already waited, the harder it
  19166. // is to tell small differences in time. Therefore, the longer we've already waited,
  19167. // the longer we can wait additionally. At some point we have to give up though.
  19168. // We pick a train model where the next boundary commits at a consistent schedule.
  19169. // These particular numbers are vague estimates. We expect to adjust them based on research.
  19170. function jnd(timeElapsed) {
  19171. return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
  19172. }
  19173. function computeMsUntilSuspenseLoadingDelay(mostRecentEventTime, committedExpirationTime, suspenseConfig) {
  19174. var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
  19175. if (busyMinDurationMs <= 0) {
  19176. return 0;
  19177. }
  19178. var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
  19179. var currentTimeMs = now();
  19180. var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(mostRecentEventTime, suspenseConfig);
  19181. var timeElapsed = currentTimeMs - eventTimeMs;
  19182. if (timeElapsed <= busyDelayMs) {
  19183. // If we haven't yet waited longer than the initial delay, we don't
  19184. // have to wait any additional time.
  19185. return 0;
  19186. }
  19187. var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
  19188. return msUntilTimeout;
  19189. }
  19190. function checkForNestedUpdates() {
  19191. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  19192. nestedUpdateCount = 0;
  19193. rootWithNestedUpdates = null;
  19194. {
  19195. {
  19196. throw Error( "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." );
  19197. }
  19198. }
  19199. }
  19200. {
  19201. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  19202. nestedPassiveUpdateCount = 0;
  19203. error('Maximum update depth exceeded. This can happen when a component ' + "calls setState inside useEffect, but useEffect either doesn't " + 'have a dependency array, or one of the dependencies changes on ' + 'every render.');
  19204. }
  19205. }
  19206. }
  19207. function flushRenderPhaseStrictModeWarningsInDEV() {
  19208. {
  19209. ReactStrictModeWarnings.flushLegacyContextWarning();
  19210. {
  19211. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  19212. }
  19213. }
  19214. }
  19215. function stopFinishedWorkLoopTimer() {
  19216. var didCompleteRoot = true;
  19217. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  19218. interruptedBy = null;
  19219. }
  19220. function stopInterruptedWorkLoopTimer() {
  19221. // TODO: Track which fiber caused the interruption.
  19222. var didCompleteRoot = false;
  19223. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  19224. interruptedBy = null;
  19225. }
  19226. function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
  19227. if ( workInProgressRoot !== null && updateExpirationTime > renderExpirationTime$1) {
  19228. interruptedBy = fiberThatReceivedUpdate;
  19229. }
  19230. }
  19231. var didWarnStateUpdateForUnmountedComponent = null;
  19232. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  19233. {
  19234. var tag = fiber.tag;
  19235. if (tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent && tag !== Block) {
  19236. // Only warn for user-defined components, not internal ones like Suspense.
  19237. return;
  19238. }
  19239. // the problematic code almost always lies inside that component.
  19240. var componentName = getComponentName(fiber.type) || 'ReactComponent';
  19241. if (didWarnStateUpdateForUnmountedComponent !== null) {
  19242. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  19243. return;
  19244. }
  19245. didWarnStateUpdateForUnmountedComponent.add(componentName);
  19246. } else {
  19247. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  19248. }
  19249. error("Can't perform a React state update on an unmounted component. This " + 'is a no-op, but it indicates a memory leak in your application. To ' + 'fix, cancel all subscriptions and asynchronous tasks in %s.%s', tag === ClassComponent ? 'the componentWillUnmount method' : 'a useEffect cleanup function', getStackByFiberInDevAndProd(fiber));
  19250. }
  19251. }
  19252. var beginWork$1;
  19253. {
  19254. var dummyFiber = null;
  19255. beginWork$1 = function (current, unitOfWork, expirationTime) {
  19256. // If a component throws an error, we replay it again in a synchronously
  19257. // dispatched event, so that the debugger will treat it as an uncaught
  19258. // error See ReactErrorUtils for more information.
  19259. // Before entering the begin phase, copy the work-in-progress onto a dummy
  19260. // fiber. If beginWork throws, we'll use this to reset the state.
  19261. var originalWorkInProgressCopy = assignFiberPropertiesInDEV(dummyFiber, unitOfWork);
  19262. try {
  19263. return beginWork(current, unitOfWork, expirationTime);
  19264. } catch (originalError) {
  19265. if (originalError !== null && typeof originalError === 'object' && typeof originalError.then === 'function') {
  19266. // Don't replay promises. Treat everything else like an error.
  19267. throw originalError;
  19268. } // Keep this code in sync with handleError; any changes here must have
  19269. // corresponding changes there.
  19270. resetContextDependencies();
  19271. resetHooksAfterThrow(); // Don't reset current debug fiber, since we're about to work on the
  19272. // same fiber again.
  19273. // Unwind the failed stack frame
  19274. unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
  19275. assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
  19276. if ( unitOfWork.mode & ProfileMode) {
  19277. // Reset the profiler timer.
  19278. startProfilerTimer(unitOfWork);
  19279. } // Run beginWork again.
  19280. invokeGuardedCallback(null, beginWork, null, current, unitOfWork, expirationTime);
  19281. if (hasCaughtError()) {
  19282. var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
  19283. // Rethrow this error instead of the original one.
  19284. throw replayError;
  19285. } else {
  19286. // This branch is reachable if the render phase is impure.
  19287. throw originalError;
  19288. }
  19289. }
  19290. };
  19291. }
  19292. var didWarnAboutUpdateInRender = false;
  19293. var didWarnAboutUpdateInRenderForAnotherComponent;
  19294. {
  19295. didWarnAboutUpdateInRenderForAnotherComponent = new Set();
  19296. }
  19297. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  19298. {
  19299. if (isRendering && (executionContext & RenderContext) !== NoContext) {
  19300. switch (fiber.tag) {
  19301. case FunctionComponent:
  19302. case ForwardRef:
  19303. case SimpleMemoComponent:
  19304. {
  19305. var renderingComponentName = workInProgress && getComponentName(workInProgress.type) || 'Unknown'; // Dedupe by the rendering component because it's the one that needs to be fixed.
  19306. var dedupeKey = renderingComponentName;
  19307. if (!didWarnAboutUpdateInRenderForAnotherComponent.has(dedupeKey)) {
  19308. didWarnAboutUpdateInRenderForAnotherComponent.add(dedupeKey);
  19309. var setStateComponentName = getComponentName(fiber.type) || 'Unknown';
  19310. error('Cannot update a component (`%s`) while rendering a ' + 'different component (`%s`). To locate the bad setState() call inside `%s`, ' + 'follow the stack trace as described in https://fb.me/setstate-in-render', setStateComponentName, renderingComponentName, renderingComponentName);
  19311. }
  19312. break;
  19313. }
  19314. case ClassComponent:
  19315. {
  19316. if (!didWarnAboutUpdateInRender) {
  19317. error('Cannot update during an existing state transition (such as ' + 'within `render`). Render methods should be a pure ' + 'function of props and state.');
  19318. didWarnAboutUpdateInRender = true;
  19319. }
  19320. break;
  19321. }
  19322. }
  19323. }
  19324. }
  19325. } // a 'shared' variable that changes when act() opens/closes in tests.
  19326. var IsThisRendererActing = {
  19327. current: false
  19328. };
  19329. function warnIfNotScopedWithMatchingAct(fiber) {
  19330. {
  19331. if ( IsSomeRendererActing.current === true && IsThisRendererActing.current !== true) {
  19332. error("It looks like you're using the wrong act() around your test interactions.\n" + 'Be sure to use the matching version of act() corresponding to your renderer:\n\n' + '// for react-dom:\n' + "import {act} from 'react-dom/test-utils';\n" + '// ...\n' + 'act(() => ...);\n\n' + '// for react-test-renderer:\n' + "import TestRenderer from 'react-test-renderer';\n" + 'const {act} = TestRenderer;\n' + '// ...\n' + 'act(() => ...);' + '%s', getStackByFiberInDevAndProd(fiber));
  19333. }
  19334. }
  19335. }
  19336. function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
  19337. {
  19338. if ( (fiber.mode & StrictMode) !== NoMode && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  19339. error('An update to %s ran an effect, but was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be ' + 'wrapped into act(...):\n\n' + 'act(() => {\n' + ' /* fire events that update state */\n' + '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see " + 'in the browser.' + ' Learn more at https://fb.me/react-wrap-tests-with-act' + '%s', getComponentName(fiber.type), getStackByFiberInDevAndProd(fiber));
  19340. }
  19341. }
  19342. }
  19343. function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
  19344. {
  19345. if ( executionContext === NoContext && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  19346. error('An update to %s inside a test was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be ' + 'wrapped into act(...):\n\n' + 'act(() => {\n' + ' /* fire events that update state */\n' + '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see " + 'in the browser.' + ' Learn more at https://fb.me/react-wrap-tests-with-act' + '%s', getComponentName(fiber.type), getStackByFiberInDevAndProd(fiber));
  19347. }
  19348. }
  19349. }
  19350. var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
  19351. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  19352. // scheduler is the actual recommendation. The alternative could be a testing build,
  19353. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  19354. // to get their tests right.
  19355. function warnIfUnmockedScheduler(fiber) {
  19356. {
  19357. if (didWarnAboutUnmockedScheduler === false && unstable_flushAllWithoutAsserting === undefined) {
  19358. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  19359. didWarnAboutUnmockedScheduler = true;
  19360. error('In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + 'to guarantee consistent behaviour across tests and browsers. ' + 'For example, with jest: \n' + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + 'For more info, visit https://fb.me/react-mock-scheduler');
  19361. }
  19362. }
  19363. }
  19364. }
  19365. function computeThreadID(root, expirationTime) {
  19366. // Interaction threads are unique per root and expiration time.
  19367. return expirationTime * 1000 + root.interactionThreadID;
  19368. }
  19369. function markSpawnedWork(expirationTime) {
  19370. if (spawnedWorkDuringRender === null) {
  19371. spawnedWorkDuringRender = [expirationTime];
  19372. } else {
  19373. spawnedWorkDuringRender.push(expirationTime);
  19374. }
  19375. }
  19376. function scheduleInteractions(root, expirationTime, interactions) {
  19377. if (interactions.size > 0) {
  19378. var pendingInteractionMap = root.pendingInteractionMap;
  19379. var pendingInteractions = pendingInteractionMap.get(expirationTime);
  19380. if (pendingInteractions != null) {
  19381. interactions.forEach(function (interaction) {
  19382. if (!pendingInteractions.has(interaction)) {
  19383. // Update the pending async work count for previously unscheduled interaction.
  19384. interaction.__count++;
  19385. }
  19386. pendingInteractions.add(interaction);
  19387. });
  19388. } else {
  19389. pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
  19390. interactions.forEach(function (interaction) {
  19391. interaction.__count++;
  19392. });
  19393. }
  19394. var subscriber = __subscriberRef.current;
  19395. if (subscriber !== null) {
  19396. var threadID = computeThreadID(root, expirationTime);
  19397. subscriber.onWorkScheduled(interactions, threadID);
  19398. }
  19399. }
  19400. }
  19401. function schedulePendingInteractions(root, expirationTime) {
  19402. scheduleInteractions(root, expirationTime, __interactionsRef.current);
  19403. }
  19404. function startWorkOnPendingInteractions(root, expirationTime) {
  19405. // we can accurately attribute time spent working on it, And so that cascading
  19406. // work triggered during the render phase will be associated with it.
  19407. var interactions = new Set();
  19408. root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
  19409. if (scheduledExpirationTime >= expirationTime) {
  19410. scheduledInteractions.forEach(function (interaction) {
  19411. return interactions.add(interaction);
  19412. });
  19413. }
  19414. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  19415. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  19416. // without having to recalculate it. We will also use it in commitWork() to
  19417. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  19418. // way to access it when the onCommitRoot() hook is called.
  19419. root.memoizedInteractions = interactions;
  19420. if (interactions.size > 0) {
  19421. var subscriber = __subscriberRef.current;
  19422. if (subscriber !== null) {
  19423. var threadID = computeThreadID(root, expirationTime);
  19424. try {
  19425. subscriber.onWorkStarted(interactions, threadID);
  19426. } catch (error) {
  19427. // If the subscriber throws, rethrow it in a separate task
  19428. scheduleCallback(ImmediatePriority, function () {
  19429. throw error;
  19430. });
  19431. }
  19432. }
  19433. }
  19434. }
  19435. function finishPendingInteractions(root, committedExpirationTime) {
  19436. var earliestRemainingTimeAfterCommit = root.firstPendingTime;
  19437. var subscriber;
  19438. try {
  19439. subscriber = __subscriberRef.current;
  19440. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  19441. var threadID = computeThreadID(root, committedExpirationTime);
  19442. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  19443. }
  19444. } catch (error) {
  19445. // If the subscriber throws, rethrow it in a separate task
  19446. scheduleCallback(ImmediatePriority, function () {
  19447. throw error;
  19448. });
  19449. } finally {
  19450. // Clear completed interactions from the pending Map.
  19451. // Unless the render was suspended or cascading work was scheduled,
  19452. // In which case– leave pending interactions until the subsequent render.
  19453. var pendingInteractionMap = root.pendingInteractionMap;
  19454. pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
  19455. // Only decrement the pending interaction count if we're done.
  19456. // If there's still work at the current priority,
  19457. // That indicates that we are waiting for suspense data.
  19458. if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
  19459. pendingInteractionMap.delete(scheduledExpirationTime);
  19460. scheduledInteractions.forEach(function (interaction) {
  19461. interaction.__count--;
  19462. if (subscriber !== null && interaction.__count === 0) {
  19463. try {
  19464. subscriber.onInteractionScheduledWorkCompleted(interaction);
  19465. } catch (error) {
  19466. // If the subscriber throws, rethrow it in a separate task
  19467. scheduleCallback(ImmediatePriority, function () {
  19468. throw error;
  19469. });
  19470. }
  19471. }
  19472. });
  19473. }
  19474. });
  19475. }
  19476. }
  19477. var onScheduleFiberRoot = null;
  19478. var onCommitFiberRoot = null;
  19479. var onCommitFiberUnmount = null;
  19480. var hasLoggedError = false;
  19481. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
  19482. function injectInternals(internals) {
  19483. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
  19484. // No DevTools
  19485. return false;
  19486. }
  19487. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  19488. if (hook.isDisabled) {
  19489. // This isn't a real property on the hook, but it can be set to opt out
  19490. // of DevTools integration and associated warnings and logs.
  19491. // https://github.com/facebook/react/issues/3877
  19492. return true;
  19493. }
  19494. if (!hook.supportsFiber) {
  19495. {
  19496. error('The installed version of React DevTools is too old and will not work ' + 'with the current version of React. Please update React DevTools. ' + 'https://fb.me/react-devtools');
  19497. } // DevTools exists, even though it doesn't support Fiber.
  19498. return true;
  19499. }
  19500. try {
  19501. var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  19502. if (true) {
  19503. // Only used by Fast Refresh
  19504. if (typeof hook.onScheduleFiberRoot === 'function') {
  19505. onScheduleFiberRoot = function (root, children) {
  19506. try {
  19507. hook.onScheduleFiberRoot(rendererID, root, children);
  19508. } catch (err) {
  19509. if (true && !hasLoggedError) {
  19510. hasLoggedError = true;
  19511. error('React instrumentation encountered an error: %s', err);
  19512. }
  19513. }
  19514. };
  19515. }
  19516. }
  19517. onCommitFiberRoot = function (root, expirationTime) {
  19518. try {
  19519. var didError = (root.current.effectTag & DidCapture) === DidCapture;
  19520. if (enableProfilerTimer) {
  19521. var currentTime = getCurrentTime();
  19522. var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime);
  19523. hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  19524. } else {
  19525. hook.onCommitFiberRoot(rendererID, root, undefined, didError);
  19526. }
  19527. } catch (err) {
  19528. if (true) {
  19529. if (!hasLoggedError) {
  19530. hasLoggedError = true;
  19531. error('React instrumentation encountered an error: %s', err);
  19532. }
  19533. }
  19534. }
  19535. };
  19536. onCommitFiberUnmount = function (fiber) {
  19537. try {
  19538. hook.onCommitFiberUnmount(rendererID, fiber);
  19539. } catch (err) {
  19540. if (true) {
  19541. if (!hasLoggedError) {
  19542. hasLoggedError = true;
  19543. error('React instrumentation encountered an error: %s', err);
  19544. }
  19545. }
  19546. }
  19547. };
  19548. } catch (err) {
  19549. // Catch all errors because it is unsafe to throw during initialization.
  19550. {
  19551. error('React instrumentation encountered an error: %s.', err);
  19552. }
  19553. } // DevTools exists
  19554. return true;
  19555. }
  19556. function onScheduleRoot(root, children) {
  19557. if (typeof onScheduleFiberRoot === 'function') {
  19558. onScheduleFiberRoot(root, children);
  19559. }
  19560. }
  19561. function onCommitRoot(root, expirationTime) {
  19562. if (typeof onCommitFiberRoot === 'function') {
  19563. onCommitFiberRoot(root, expirationTime);
  19564. }
  19565. }
  19566. function onCommitUnmount(fiber) {
  19567. if (typeof onCommitFiberUnmount === 'function') {
  19568. onCommitFiberUnmount(fiber);
  19569. }
  19570. }
  19571. var hasBadMapPolyfill;
  19572. {
  19573. hasBadMapPolyfill = false;
  19574. try {
  19575. var nonExtensibleObject = Object.preventExtensions({});
  19576. var testMap = new Map([[nonExtensibleObject, null]]);
  19577. var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
  19578. // https://github.com/rollup/rollup/issues/1771
  19579. // TODO: we can remove these if Rollup fixes the bug.
  19580. testMap.set(0, 0);
  19581. testSet.add(0);
  19582. } catch (e) {
  19583. // TODO: Consider warning about bad polyfills
  19584. hasBadMapPolyfill = true;
  19585. }
  19586. }
  19587. var debugCounter = 1;
  19588. function FiberNode(tag, pendingProps, key, mode) {
  19589. // Instance
  19590. this.tag = tag;
  19591. this.key = key;
  19592. this.elementType = null;
  19593. this.type = null;
  19594. this.stateNode = null; // Fiber
  19595. this.return = null;
  19596. this.child = null;
  19597. this.sibling = null;
  19598. this.index = 0;
  19599. this.ref = null;
  19600. this.pendingProps = pendingProps;
  19601. this.memoizedProps = null;
  19602. this.updateQueue = null;
  19603. this.memoizedState = null;
  19604. this.dependencies = null;
  19605. this.mode = mode; // Effects
  19606. this.effectTag = NoEffect;
  19607. this.nextEffect = null;
  19608. this.firstEffect = null;
  19609. this.lastEffect = null;
  19610. this.expirationTime = NoWork;
  19611. this.childExpirationTime = NoWork;
  19612. this.alternate = null;
  19613. {
  19614. // Note: The following is done to avoid a v8 performance cliff.
  19615. //
  19616. // Initializing the fields below to smis and later updating them with
  19617. // double values will cause Fibers to end up having separate shapes.
  19618. // This behavior/bug has something to do with Object.preventExtension().
  19619. // Fortunately this only impacts DEV builds.
  19620. // Unfortunately it makes React unusably slow for some applications.
  19621. // To work around this, initialize the fields below with doubles.
  19622. //
  19623. // Learn more about this here:
  19624. // https://github.com/facebook/react/issues/14365
  19625. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  19626. this.actualDuration = Number.NaN;
  19627. this.actualStartTime = Number.NaN;
  19628. this.selfBaseDuration = Number.NaN;
  19629. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  19630. // This won't trigger the performance cliff mentioned above,
  19631. // and it simplifies other profiler code (including DevTools).
  19632. this.actualDuration = 0;
  19633. this.actualStartTime = -1;
  19634. this.selfBaseDuration = 0;
  19635. this.treeBaseDuration = 0;
  19636. } // This is normally DEV-only except www when it adds listeners.
  19637. // TODO: remove the User Timing integration in favor of Root Events.
  19638. {
  19639. this._debugID = debugCounter++;
  19640. this._debugIsCurrentlyTiming = false;
  19641. }
  19642. {
  19643. this._debugSource = null;
  19644. this._debugOwner = null;
  19645. this._debugNeedsRemount = false;
  19646. this._debugHookTypes = null;
  19647. if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
  19648. Object.preventExtensions(this);
  19649. }
  19650. }
  19651. } // This is a constructor function, rather than a POJO constructor, still
  19652. // please ensure we do the following:
  19653. // 1) Nobody should add any instance methods on this. Instance methods can be
  19654. // more difficult to predict when they get optimized and they are almost
  19655. // never inlined properly in static compilers.
  19656. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  19657. // always know when it is a fiber.
  19658. // 3) We might want to experiment with using numeric keys since they are easier
  19659. // to optimize in a non-JIT environment.
  19660. // 4) We can easily go from a constructor to a createFiber object literal if that
  19661. // is faster.
  19662. // 5) It should be easy to port this to a C struct and keep a C implementation
  19663. // compatible.
  19664. var createFiber = function (tag, pendingProps, key, mode) {
  19665. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  19666. return new FiberNode(tag, pendingProps, key, mode);
  19667. };
  19668. function shouldConstruct(Component) {
  19669. var prototype = Component.prototype;
  19670. return !!(prototype && prototype.isReactComponent);
  19671. }
  19672. function isSimpleFunctionComponent(type) {
  19673. return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
  19674. }
  19675. function resolveLazyComponentTag(Component) {
  19676. if (typeof Component === 'function') {
  19677. return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
  19678. } else if (Component !== undefined && Component !== null) {
  19679. var $$typeof = Component.$$typeof;
  19680. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  19681. return ForwardRef;
  19682. }
  19683. if ($$typeof === REACT_MEMO_TYPE) {
  19684. return MemoComponent;
  19685. }
  19686. }
  19687. return IndeterminateComponent;
  19688. } // This is used to create an alternate fiber to do work on.
  19689. function createWorkInProgress(current, pendingProps) {
  19690. var workInProgress = current.alternate;
  19691. if (workInProgress === null) {
  19692. // We use a double buffering pooling technique because we know that we'll
  19693. // only ever need at most two versions of a tree. We pool the "other" unused
  19694. // node that we're free to reuse. This is lazily created to avoid allocating
  19695. // extra objects for things that are never updated. It also allow us to
  19696. // reclaim the extra memory if needed.
  19697. workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
  19698. workInProgress.elementType = current.elementType;
  19699. workInProgress.type = current.type;
  19700. workInProgress.stateNode = current.stateNode;
  19701. {
  19702. // DEV-only fields
  19703. {
  19704. workInProgress._debugID = current._debugID;
  19705. }
  19706. workInProgress._debugSource = current._debugSource;
  19707. workInProgress._debugOwner = current._debugOwner;
  19708. workInProgress._debugHookTypes = current._debugHookTypes;
  19709. }
  19710. workInProgress.alternate = current;
  19711. current.alternate = workInProgress;
  19712. } else {
  19713. workInProgress.pendingProps = pendingProps; // We already have an alternate.
  19714. // Reset the effect tag.
  19715. workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
  19716. workInProgress.nextEffect = null;
  19717. workInProgress.firstEffect = null;
  19718. workInProgress.lastEffect = null;
  19719. {
  19720. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  19721. // This prevents time from endlessly accumulating in new commits.
  19722. // This has the downside of resetting values for different priority renders,
  19723. // But works for yielding (the common case) and should support resuming.
  19724. workInProgress.actualDuration = 0;
  19725. workInProgress.actualStartTime = -1;
  19726. }
  19727. }
  19728. workInProgress.childExpirationTime = current.childExpirationTime;
  19729. workInProgress.expirationTime = current.expirationTime;
  19730. workInProgress.child = current.child;
  19731. workInProgress.memoizedProps = current.memoizedProps;
  19732. workInProgress.memoizedState = current.memoizedState;
  19733. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  19734. // it cannot be shared with the current fiber.
  19735. var currentDependencies = current.dependencies;
  19736. workInProgress.dependencies = currentDependencies === null ? null : {
  19737. expirationTime: currentDependencies.expirationTime,
  19738. firstContext: currentDependencies.firstContext,
  19739. responders: currentDependencies.responders
  19740. }; // These will be overridden during the parent's reconciliation
  19741. workInProgress.sibling = current.sibling;
  19742. workInProgress.index = current.index;
  19743. workInProgress.ref = current.ref;
  19744. {
  19745. workInProgress.selfBaseDuration = current.selfBaseDuration;
  19746. workInProgress.treeBaseDuration = current.treeBaseDuration;
  19747. }
  19748. {
  19749. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  19750. switch (workInProgress.tag) {
  19751. case IndeterminateComponent:
  19752. case FunctionComponent:
  19753. case SimpleMemoComponent:
  19754. workInProgress.type = resolveFunctionForHotReloading(current.type);
  19755. break;
  19756. case ClassComponent:
  19757. workInProgress.type = resolveClassForHotReloading(current.type);
  19758. break;
  19759. case ForwardRef:
  19760. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  19761. break;
  19762. }
  19763. }
  19764. return workInProgress;
  19765. } // Used to reuse a Fiber for a second pass.
  19766. function resetWorkInProgress(workInProgress, renderExpirationTime) {
  19767. // This resets the Fiber to what createFiber or createWorkInProgress would
  19768. // have set the values to before during the first pass. Ideally this wouldn't
  19769. // be necessary but unfortunately many code paths reads from the workInProgress
  19770. // when they should be reading from current and writing to workInProgress.
  19771. // We assume pendingProps, index, key, ref, return are still untouched to
  19772. // avoid doing another reconciliation.
  19773. // Reset the effect tag but keep any Placement tags, since that's something
  19774. // that child fiber is setting, not the reconciliation.
  19775. workInProgress.effectTag &= Placement; // The effect list is no longer valid.
  19776. workInProgress.nextEffect = null;
  19777. workInProgress.firstEffect = null;
  19778. workInProgress.lastEffect = null;
  19779. var current = workInProgress.alternate;
  19780. if (current === null) {
  19781. // Reset to createFiber's initial values.
  19782. workInProgress.childExpirationTime = NoWork;
  19783. workInProgress.expirationTime = renderExpirationTime;
  19784. workInProgress.child = null;
  19785. workInProgress.memoizedProps = null;
  19786. workInProgress.memoizedState = null;
  19787. workInProgress.updateQueue = null;
  19788. workInProgress.dependencies = null;
  19789. {
  19790. // Note: We don't reset the actualTime counts. It's useful to accumulate
  19791. // actual time across multiple render passes.
  19792. workInProgress.selfBaseDuration = 0;
  19793. workInProgress.treeBaseDuration = 0;
  19794. }
  19795. } else {
  19796. // Reset to the cloned values that createWorkInProgress would've.
  19797. workInProgress.childExpirationTime = current.childExpirationTime;
  19798. workInProgress.expirationTime = current.expirationTime;
  19799. workInProgress.child = current.child;
  19800. workInProgress.memoizedProps = current.memoizedProps;
  19801. workInProgress.memoizedState = current.memoizedState;
  19802. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  19803. // it cannot be shared with the current fiber.
  19804. var currentDependencies = current.dependencies;
  19805. workInProgress.dependencies = currentDependencies === null ? null : {
  19806. expirationTime: currentDependencies.expirationTime,
  19807. firstContext: currentDependencies.firstContext,
  19808. responders: currentDependencies.responders
  19809. };
  19810. {
  19811. // Note: We don't reset the actualTime counts. It's useful to accumulate
  19812. // actual time across multiple render passes.
  19813. workInProgress.selfBaseDuration = current.selfBaseDuration;
  19814. workInProgress.treeBaseDuration = current.treeBaseDuration;
  19815. }
  19816. }
  19817. return workInProgress;
  19818. }
  19819. function createHostRootFiber(tag) {
  19820. var mode;
  19821. if (tag === ConcurrentRoot) {
  19822. mode = ConcurrentMode | BlockingMode | StrictMode;
  19823. } else if (tag === BlockingRoot) {
  19824. mode = BlockingMode | StrictMode;
  19825. } else {
  19826. mode = NoMode;
  19827. }
  19828. if ( isDevToolsPresent) {
  19829. // Always collect profile timings when DevTools are present.
  19830. // This enables DevTools to start capturing timing at any point–
  19831. // Without some nodes in the tree having empty base times.
  19832. mode |= ProfileMode;
  19833. }
  19834. return createFiber(HostRoot, null, null, mode);
  19835. }
  19836. function createFiberFromTypeAndProps(type, // React$ElementType
  19837. key, pendingProps, owner, mode, expirationTime) {
  19838. var fiber;
  19839. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  19840. var resolvedType = type;
  19841. if (typeof type === 'function') {
  19842. if (shouldConstruct(type)) {
  19843. fiberTag = ClassComponent;
  19844. {
  19845. resolvedType = resolveClassForHotReloading(resolvedType);
  19846. }
  19847. } else {
  19848. {
  19849. resolvedType = resolveFunctionForHotReloading(resolvedType);
  19850. }
  19851. }
  19852. } else if (typeof type === 'string') {
  19853. fiberTag = HostComponent;
  19854. } else {
  19855. getTag: switch (type) {
  19856. case REACT_FRAGMENT_TYPE:
  19857. return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
  19858. case REACT_CONCURRENT_MODE_TYPE:
  19859. fiberTag = Mode;
  19860. mode |= ConcurrentMode | BlockingMode | StrictMode;
  19861. break;
  19862. case REACT_STRICT_MODE_TYPE:
  19863. fiberTag = Mode;
  19864. mode |= StrictMode;
  19865. break;
  19866. case REACT_PROFILER_TYPE:
  19867. return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
  19868. case REACT_SUSPENSE_TYPE:
  19869. return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
  19870. case REACT_SUSPENSE_LIST_TYPE:
  19871. return createFiberFromSuspenseList(pendingProps, mode, expirationTime, key);
  19872. default:
  19873. {
  19874. if (typeof type === 'object' && type !== null) {
  19875. switch (type.$$typeof) {
  19876. case REACT_PROVIDER_TYPE:
  19877. fiberTag = ContextProvider;
  19878. break getTag;
  19879. case REACT_CONTEXT_TYPE:
  19880. // This is a consumer
  19881. fiberTag = ContextConsumer;
  19882. break getTag;
  19883. case REACT_FORWARD_REF_TYPE:
  19884. fiberTag = ForwardRef;
  19885. {
  19886. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  19887. }
  19888. break getTag;
  19889. case REACT_MEMO_TYPE:
  19890. fiberTag = MemoComponent;
  19891. break getTag;
  19892. case REACT_LAZY_TYPE:
  19893. fiberTag = LazyComponent;
  19894. resolvedType = null;
  19895. break getTag;
  19896. case REACT_BLOCK_TYPE:
  19897. fiberTag = Block;
  19898. break getTag;
  19899. }
  19900. }
  19901. var info = '';
  19902. {
  19903. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  19904. info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and " + 'named imports.';
  19905. }
  19906. var ownerName = owner ? getComponentName(owner.type) : null;
  19907. if (ownerName) {
  19908. info += '\n\nCheck the render method of `' + ownerName + '`.';
  19909. }
  19910. }
  19911. {
  19912. {
  19913. throw Error( "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: " + (type == null ? type : typeof type) + "." + info );
  19914. }
  19915. }
  19916. }
  19917. }
  19918. }
  19919. fiber = createFiber(fiberTag, pendingProps, key, mode);
  19920. fiber.elementType = type;
  19921. fiber.type = resolvedType;
  19922. fiber.expirationTime = expirationTime;
  19923. return fiber;
  19924. }
  19925. function createFiberFromElement(element, mode, expirationTime) {
  19926. var owner = null;
  19927. {
  19928. owner = element._owner;
  19929. }
  19930. var type = element.type;
  19931. var key = element.key;
  19932. var pendingProps = element.props;
  19933. var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
  19934. {
  19935. fiber._debugSource = element._source;
  19936. fiber._debugOwner = element._owner;
  19937. }
  19938. return fiber;
  19939. }
  19940. function createFiberFromFragment(elements, mode, expirationTime, key) {
  19941. var fiber = createFiber(Fragment, elements, key, mode);
  19942. fiber.expirationTime = expirationTime;
  19943. return fiber;
  19944. }
  19945. function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
  19946. {
  19947. if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
  19948. error('Profiler must specify an "id" string and "onRender" function as props');
  19949. }
  19950. }
  19951. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  19952. fiber.elementType = REACT_PROFILER_TYPE;
  19953. fiber.type = REACT_PROFILER_TYPE;
  19954. fiber.expirationTime = expirationTime;
  19955. return fiber;
  19956. }
  19957. function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
  19958. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  19959. // This needs to be fixed in getComponentName so that it relies on the tag
  19960. // instead.
  19961. fiber.type = REACT_SUSPENSE_TYPE;
  19962. fiber.elementType = REACT_SUSPENSE_TYPE;
  19963. fiber.expirationTime = expirationTime;
  19964. return fiber;
  19965. }
  19966. function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
  19967. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  19968. {
  19969. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  19970. // This needs to be fixed in getComponentName so that it relies on the tag
  19971. // instead.
  19972. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  19973. }
  19974. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  19975. fiber.expirationTime = expirationTime;
  19976. return fiber;
  19977. }
  19978. function createFiberFromText(content, mode, expirationTime) {
  19979. var fiber = createFiber(HostText, content, null, mode);
  19980. fiber.expirationTime = expirationTime;
  19981. return fiber;
  19982. }
  19983. function createFiberFromHostInstanceForDeletion() {
  19984. var fiber = createFiber(HostComponent, null, null, NoMode); // TODO: These should not need a type.
  19985. fiber.elementType = 'DELETED';
  19986. fiber.type = 'DELETED';
  19987. return fiber;
  19988. }
  19989. function createFiberFromPortal(portal, mode, expirationTime) {
  19990. var pendingProps = portal.children !== null ? portal.children : [];
  19991. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  19992. fiber.expirationTime = expirationTime;
  19993. fiber.stateNode = {
  19994. containerInfo: portal.containerInfo,
  19995. pendingChildren: null,
  19996. // Used by persistent updates
  19997. implementation: portal.implementation
  19998. };
  19999. return fiber;
  20000. } // Used for stashing WIP properties to replay failed work in DEV.
  20001. function assignFiberPropertiesInDEV(target, source) {
  20002. if (target === null) {
  20003. // This Fiber's initial properties will always be overwritten.
  20004. // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
  20005. target = createFiber(IndeterminateComponent, null, null, NoMode);
  20006. } // This is intentionally written as a list of all properties.
  20007. // We tried to use Object.assign() instead but this is called in
  20008. // the hottest path, and Object.assign() was too slow:
  20009. // https://github.com/facebook/react/issues/12502
  20010. // This code is DEV-only so size is not a concern.
  20011. target.tag = source.tag;
  20012. target.key = source.key;
  20013. target.elementType = source.elementType;
  20014. target.type = source.type;
  20015. target.stateNode = source.stateNode;
  20016. target.return = source.return;
  20017. target.child = source.child;
  20018. target.sibling = source.sibling;
  20019. target.index = source.index;
  20020. target.ref = source.ref;
  20021. target.pendingProps = source.pendingProps;
  20022. target.memoizedProps = source.memoizedProps;
  20023. target.updateQueue = source.updateQueue;
  20024. target.memoizedState = source.memoizedState;
  20025. target.dependencies = source.dependencies;
  20026. target.mode = source.mode;
  20027. target.effectTag = source.effectTag;
  20028. target.nextEffect = source.nextEffect;
  20029. target.firstEffect = source.firstEffect;
  20030. target.lastEffect = source.lastEffect;
  20031. target.expirationTime = source.expirationTime;
  20032. target.childExpirationTime = source.childExpirationTime;
  20033. target.alternate = source.alternate;
  20034. {
  20035. target.actualDuration = source.actualDuration;
  20036. target.actualStartTime = source.actualStartTime;
  20037. target.selfBaseDuration = source.selfBaseDuration;
  20038. target.treeBaseDuration = source.treeBaseDuration;
  20039. }
  20040. {
  20041. target._debugID = source._debugID;
  20042. }
  20043. target._debugSource = source._debugSource;
  20044. target._debugOwner = source._debugOwner;
  20045. target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
  20046. target._debugNeedsRemount = source._debugNeedsRemount;
  20047. target._debugHookTypes = source._debugHookTypes;
  20048. return target;
  20049. }
  20050. function FiberRootNode(containerInfo, tag, hydrate) {
  20051. this.tag = tag;
  20052. this.current = null;
  20053. this.containerInfo = containerInfo;
  20054. this.pendingChildren = null;
  20055. this.pingCache = null;
  20056. this.finishedExpirationTime = NoWork;
  20057. this.finishedWork = null;
  20058. this.timeoutHandle = noTimeout;
  20059. this.context = null;
  20060. this.pendingContext = null;
  20061. this.hydrate = hydrate;
  20062. this.callbackNode = null;
  20063. this.callbackPriority = NoPriority;
  20064. this.firstPendingTime = NoWork;
  20065. this.firstSuspendedTime = NoWork;
  20066. this.lastSuspendedTime = NoWork;
  20067. this.nextKnownPendingLevel = NoWork;
  20068. this.lastPingedTime = NoWork;
  20069. this.lastExpiredTime = NoWork;
  20070. {
  20071. this.interactionThreadID = unstable_getThreadID();
  20072. this.memoizedInteractions = new Set();
  20073. this.pendingInteractionMap = new Map();
  20074. }
  20075. }
  20076. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  20077. var root = new FiberRootNode(containerInfo, tag, hydrate);
  20078. // stateNode is any.
  20079. var uninitializedFiber = createHostRootFiber(tag);
  20080. root.current = uninitializedFiber;
  20081. uninitializedFiber.stateNode = root;
  20082. initializeUpdateQueue(uninitializedFiber);
  20083. return root;
  20084. }
  20085. function isRootSuspendedAtTime(root, expirationTime) {
  20086. var firstSuspendedTime = root.firstSuspendedTime;
  20087. var lastSuspendedTime = root.lastSuspendedTime;
  20088. return firstSuspendedTime !== NoWork && firstSuspendedTime >= expirationTime && lastSuspendedTime <= expirationTime;
  20089. }
  20090. function markRootSuspendedAtTime(root, expirationTime) {
  20091. var firstSuspendedTime = root.firstSuspendedTime;
  20092. var lastSuspendedTime = root.lastSuspendedTime;
  20093. if (firstSuspendedTime < expirationTime) {
  20094. root.firstSuspendedTime = expirationTime;
  20095. }
  20096. if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
  20097. root.lastSuspendedTime = expirationTime;
  20098. }
  20099. if (expirationTime <= root.lastPingedTime) {
  20100. root.lastPingedTime = NoWork;
  20101. }
  20102. if (expirationTime <= root.lastExpiredTime) {
  20103. root.lastExpiredTime = NoWork;
  20104. }
  20105. }
  20106. function markRootUpdatedAtTime(root, expirationTime) {
  20107. // Update the range of pending times
  20108. var firstPendingTime = root.firstPendingTime;
  20109. if (expirationTime > firstPendingTime) {
  20110. root.firstPendingTime = expirationTime;
  20111. } // Update the range of suspended times. Treat everything lower priority or
  20112. // equal to this update as unsuspended.
  20113. var firstSuspendedTime = root.firstSuspendedTime;
  20114. if (firstSuspendedTime !== NoWork) {
  20115. if (expirationTime >= firstSuspendedTime) {
  20116. // The entire suspended range is now unsuspended.
  20117. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  20118. } else if (expirationTime >= root.lastSuspendedTime) {
  20119. root.lastSuspendedTime = expirationTime + 1;
  20120. } // This is a pending level. Check if it's higher priority than the next
  20121. // known pending level.
  20122. if (expirationTime > root.nextKnownPendingLevel) {
  20123. root.nextKnownPendingLevel = expirationTime;
  20124. }
  20125. }
  20126. }
  20127. function markRootFinishedAtTime(root, finishedExpirationTime, remainingExpirationTime) {
  20128. // Update the range of pending times
  20129. root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
  20130. // equal to this update as unsuspended.
  20131. if (finishedExpirationTime <= root.lastSuspendedTime) {
  20132. // The entire suspended range is now unsuspended.
  20133. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  20134. } else if (finishedExpirationTime <= root.firstSuspendedTime) {
  20135. // Part of the suspended range is now unsuspended. Narrow the range to
  20136. // include everything between the unsuspended time (non-inclusive) and the
  20137. // last suspended time.
  20138. root.firstSuspendedTime = finishedExpirationTime - 1;
  20139. }
  20140. if (finishedExpirationTime <= root.lastPingedTime) {
  20141. // Clear the pinged time
  20142. root.lastPingedTime = NoWork;
  20143. }
  20144. if (finishedExpirationTime <= root.lastExpiredTime) {
  20145. // Clear the expired time
  20146. root.lastExpiredTime = NoWork;
  20147. }
  20148. }
  20149. function markRootExpiredAtTime(root, expirationTime) {
  20150. var lastExpiredTime = root.lastExpiredTime;
  20151. if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
  20152. root.lastExpiredTime = expirationTime;
  20153. }
  20154. }
  20155. var didWarnAboutNestedUpdates;
  20156. var didWarnAboutFindNodeInStrictMode;
  20157. {
  20158. didWarnAboutNestedUpdates = false;
  20159. didWarnAboutFindNodeInStrictMode = {};
  20160. }
  20161. function getContextForSubtree(parentComponent) {
  20162. if (!parentComponent) {
  20163. return emptyContextObject;
  20164. }
  20165. var fiber = get(parentComponent);
  20166. var parentContext = findCurrentUnmaskedContext(fiber);
  20167. if (fiber.tag === ClassComponent) {
  20168. var Component = fiber.type;
  20169. if (isContextProvider(Component)) {
  20170. return processChildContext(fiber, Component, parentContext);
  20171. }
  20172. }
  20173. return parentContext;
  20174. }
  20175. function findHostInstanceWithWarning(component, methodName) {
  20176. {
  20177. var fiber = get(component);
  20178. if (fiber === undefined) {
  20179. if (typeof component.render === 'function') {
  20180. {
  20181. {
  20182. throw Error( "Unable to find node on an unmounted component." );
  20183. }
  20184. }
  20185. } else {
  20186. {
  20187. {
  20188. throw Error( "Argument appears to not be a ReactComponent. Keys: " + Object.keys(component) );
  20189. }
  20190. }
  20191. }
  20192. }
  20193. var hostFiber = findCurrentHostFiber(fiber);
  20194. if (hostFiber === null) {
  20195. return null;
  20196. }
  20197. if (hostFiber.mode & StrictMode) {
  20198. var componentName = getComponentName(fiber.type) || 'Component';
  20199. if (!didWarnAboutFindNodeInStrictMode[componentName]) {
  20200. didWarnAboutFindNodeInStrictMode[componentName] = true;
  20201. if (fiber.mode & StrictMode) {
  20202. error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which is inside StrictMode. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://fb.me/react-strict-mode-find-node%s', methodName, methodName, componentName, getStackByFiberInDevAndProd(hostFiber));
  20203. } else {
  20204. error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which renders StrictMode children. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://fb.me/react-strict-mode-find-node%s', methodName, methodName, componentName, getStackByFiberInDevAndProd(hostFiber));
  20205. }
  20206. }
  20207. }
  20208. return hostFiber.stateNode;
  20209. }
  20210. }
  20211. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  20212. return createFiberRoot(containerInfo, tag, hydrate);
  20213. }
  20214. function updateContainer(element, container, parentComponent, callback) {
  20215. {
  20216. onScheduleRoot(container, element);
  20217. }
  20218. var current$1 = container.current;
  20219. var currentTime = requestCurrentTimeForUpdate();
  20220. {
  20221. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  20222. if ('undefined' !== typeof jest) {
  20223. warnIfUnmockedScheduler(current$1);
  20224. warnIfNotScopedWithMatchingAct(current$1);
  20225. }
  20226. }
  20227. var suspenseConfig = requestCurrentSuspenseConfig();
  20228. var expirationTime = computeExpirationForFiber(currentTime, current$1, suspenseConfig);
  20229. var context = getContextForSubtree(parentComponent);
  20230. if (container.context === null) {
  20231. container.context = context;
  20232. } else {
  20233. container.pendingContext = context;
  20234. }
  20235. {
  20236. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  20237. didWarnAboutNestedUpdates = true;
  20238. error('Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + 'Check the render method of %s.', getComponentName(current.type) || 'Unknown');
  20239. }
  20240. }
  20241. var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
  20242. // being called "element".
  20243. update.payload = {
  20244. element: element
  20245. };
  20246. callback = callback === undefined ? null : callback;
  20247. if (callback !== null) {
  20248. {
  20249. if (typeof callback !== 'function') {
  20250. error('render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback);
  20251. }
  20252. }
  20253. update.callback = callback;
  20254. }
  20255. enqueueUpdate(current$1, update);
  20256. scheduleWork(current$1, expirationTime);
  20257. return expirationTime;
  20258. }
  20259. function getPublicRootInstance(container) {
  20260. var containerFiber = container.current;
  20261. if (!containerFiber.child) {
  20262. return null;
  20263. }
  20264. switch (containerFiber.child.tag) {
  20265. case HostComponent:
  20266. return getPublicInstance(containerFiber.child.stateNode);
  20267. default:
  20268. return containerFiber.child.stateNode;
  20269. }
  20270. }
  20271. function markRetryTimeImpl(fiber, retryTime) {
  20272. var suspenseState = fiber.memoizedState;
  20273. if (suspenseState !== null && suspenseState.dehydrated !== null) {
  20274. if (suspenseState.retryTime < retryTime) {
  20275. suspenseState.retryTime = retryTime;
  20276. }
  20277. }
  20278. } // Increases the priority of thennables when they resolve within this boundary.
  20279. function markRetryTimeIfNotHydrated(fiber, retryTime) {
  20280. markRetryTimeImpl(fiber, retryTime);
  20281. var alternate = fiber.alternate;
  20282. if (alternate) {
  20283. markRetryTimeImpl(alternate, retryTime);
  20284. }
  20285. }
  20286. function attemptUserBlockingHydration$1(fiber) {
  20287. if (fiber.tag !== SuspenseComponent) {
  20288. // We ignore HostRoots here because we can't increase
  20289. // their priority and they should not suspend on I/O,
  20290. // since you have to wrap anything that might suspend in
  20291. // Suspense.
  20292. return;
  20293. }
  20294. var expTime = computeInteractiveExpiration(requestCurrentTimeForUpdate());
  20295. scheduleWork(fiber, expTime);
  20296. markRetryTimeIfNotHydrated(fiber, expTime);
  20297. }
  20298. function attemptContinuousHydration$1(fiber) {
  20299. if (fiber.tag !== SuspenseComponent) {
  20300. // We ignore HostRoots here because we can't increase
  20301. // their priority and they should not suspend on I/O,
  20302. // since you have to wrap anything that might suspend in
  20303. // Suspense.
  20304. return;
  20305. }
  20306. scheduleWork(fiber, ContinuousHydration);
  20307. markRetryTimeIfNotHydrated(fiber, ContinuousHydration);
  20308. }
  20309. function attemptHydrationAtCurrentPriority$1(fiber) {
  20310. if (fiber.tag !== SuspenseComponent) {
  20311. // We ignore HostRoots here because we can't increase
  20312. // their priority other than synchronously flush it.
  20313. return;
  20314. }
  20315. var currentTime = requestCurrentTimeForUpdate();
  20316. var expTime = computeExpirationForFiber(currentTime, fiber, null);
  20317. scheduleWork(fiber, expTime);
  20318. markRetryTimeIfNotHydrated(fiber, expTime);
  20319. }
  20320. function findHostInstanceWithNoPortals(fiber) {
  20321. var hostFiber = findCurrentHostFiberWithNoPortals(fiber);
  20322. if (hostFiber === null) {
  20323. return null;
  20324. }
  20325. if (hostFiber.tag === FundamentalComponent) {
  20326. return hostFiber.stateNode.instance;
  20327. }
  20328. return hostFiber.stateNode;
  20329. }
  20330. var shouldSuspendImpl = function (fiber) {
  20331. return false;
  20332. };
  20333. function shouldSuspend(fiber) {
  20334. return shouldSuspendImpl(fiber);
  20335. }
  20336. var overrideHookState = null;
  20337. var overrideProps = null;
  20338. var scheduleUpdate = null;
  20339. var setSuspenseHandler = null;
  20340. {
  20341. var copyWithSetImpl = function (obj, path, idx, value) {
  20342. if (idx >= path.length) {
  20343. return value;
  20344. }
  20345. var key = path[idx];
  20346. var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
  20347. updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
  20348. return updated;
  20349. };
  20350. var copyWithSet = function (obj, path, value) {
  20351. return copyWithSetImpl(obj, path, 0, value);
  20352. }; // Support DevTools editable values for useState and useReducer.
  20353. overrideHookState = function (fiber, id, path, value) {
  20354. // For now, the "id" of stateful hooks is just the stateful hook index.
  20355. // This may change in the future with e.g. nested hooks.
  20356. var currentHook = fiber.memoizedState;
  20357. while (currentHook !== null && id > 0) {
  20358. currentHook = currentHook.next;
  20359. id--;
  20360. }
  20361. if (currentHook !== null) {
  20362. var newState = copyWithSet(currentHook.memoizedState, path, value);
  20363. currentHook.memoizedState = newState;
  20364. currentHook.baseState = newState; // We aren't actually adding an update to the queue,
  20365. // because there is no update we can add for useReducer hooks that won't trigger an error.
  20366. // (There's no appropriate action type for DevTools overrides.)
  20367. // As a result though, React will see the scheduled update as a noop and bailout.
  20368. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  20369. fiber.memoizedProps = _assign({}, fiber.memoizedProps);
  20370. scheduleWork(fiber, Sync);
  20371. }
  20372. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  20373. overrideProps = function (fiber, path, value) {
  20374. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  20375. if (fiber.alternate) {
  20376. fiber.alternate.pendingProps = fiber.pendingProps;
  20377. }
  20378. scheduleWork(fiber, Sync);
  20379. };
  20380. scheduleUpdate = function (fiber) {
  20381. scheduleWork(fiber, Sync);
  20382. };
  20383. setSuspenseHandler = function (newShouldSuspendImpl) {
  20384. shouldSuspendImpl = newShouldSuspendImpl;
  20385. };
  20386. }
  20387. function injectIntoDevTools(devToolsConfig) {
  20388. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  20389. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  20390. return injectInternals(_assign({}, devToolsConfig, {
  20391. overrideHookState: overrideHookState,
  20392. overrideProps: overrideProps,
  20393. setSuspenseHandler: setSuspenseHandler,
  20394. scheduleUpdate: scheduleUpdate,
  20395. currentDispatcherRef: ReactCurrentDispatcher,
  20396. findHostInstanceByFiber: function (fiber) {
  20397. var hostFiber = findCurrentHostFiber(fiber);
  20398. if (hostFiber === null) {
  20399. return null;
  20400. }
  20401. return hostFiber.stateNode;
  20402. },
  20403. findFiberByHostInstance: function (instance) {
  20404. if (!findFiberByHostInstance) {
  20405. // Might not be implemented by the renderer.
  20406. return null;
  20407. }
  20408. return findFiberByHostInstance(instance);
  20409. },
  20410. // React Refresh
  20411. findHostInstancesForRefresh: findHostInstancesForRefresh ,
  20412. scheduleRefresh: scheduleRefresh ,
  20413. scheduleRoot: scheduleRoot ,
  20414. setRefreshHandler: setRefreshHandler ,
  20415. // Enables DevTools to append owner stacks to error messages in DEV mode.
  20416. getCurrentFiber: function () {
  20417. return current;
  20418. }
  20419. }));
  20420. }
  20421. var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing;
  20422. function ReactDOMRoot(container, options) {
  20423. this._internalRoot = createRootImpl(container, ConcurrentRoot, options);
  20424. }
  20425. function ReactDOMBlockingRoot(container, tag, options) {
  20426. this._internalRoot = createRootImpl(container, tag, options);
  20427. }
  20428. ReactDOMRoot.prototype.render = ReactDOMBlockingRoot.prototype.render = function (children) {
  20429. var root = this._internalRoot;
  20430. {
  20431. if (typeof arguments[1] === 'function') {
  20432. error('render(...): does not support the second callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().');
  20433. }
  20434. var container = root.containerInfo;
  20435. if (container.nodeType !== COMMENT_NODE) {
  20436. var hostInstance = findHostInstanceWithNoPortals(root.current);
  20437. if (hostInstance) {
  20438. if (hostInstance.parentNode !== container) {
  20439. error('render(...): It looks like the React-rendered content of the ' + 'root container was removed without using React. This is not ' + 'supported and will cause errors. Instead, call ' + "root.unmount() to empty a root's container.");
  20440. }
  20441. }
  20442. }
  20443. }
  20444. updateContainer(children, root, null, null);
  20445. };
  20446. ReactDOMRoot.prototype.unmount = ReactDOMBlockingRoot.prototype.unmount = function () {
  20447. {
  20448. if (typeof arguments[0] === 'function') {
  20449. error('unmount(...): does not support a callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().');
  20450. }
  20451. }
  20452. var root = this._internalRoot;
  20453. var container = root.containerInfo;
  20454. updateContainer(null, root, null, function () {
  20455. unmarkContainerAsRoot(container);
  20456. });
  20457. };
  20458. function createRootImpl(container, tag, options) {
  20459. // Tag is either LegacyRoot or Concurrent Root
  20460. var hydrate = options != null && options.hydrate === true;
  20461. var hydrationCallbacks = options != null && options.hydrationOptions || null;
  20462. var root = createContainer(container, tag, hydrate);
  20463. markContainerAsRoot(root.current, container);
  20464. if (hydrate && tag !== LegacyRoot) {
  20465. var doc = container.nodeType === DOCUMENT_NODE ? container : container.ownerDocument;
  20466. eagerlyTrapReplayableEvents(container, doc);
  20467. }
  20468. return root;
  20469. }
  20470. function createLegacyRoot(container, options) {
  20471. return new ReactDOMBlockingRoot(container, LegacyRoot, options);
  20472. }
  20473. function isValidContainer(node) {
  20474. return !!(node && (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE || node.nodeType === COMMENT_NODE && node.nodeValue === ' react-mount-point-unstable '));
  20475. }
  20476. var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
  20477. var topLevelUpdateWarnings;
  20478. var warnedAboutHydrateAPI = false;
  20479. {
  20480. topLevelUpdateWarnings = function (container) {
  20481. if (container._reactRootContainer && container.nodeType !== COMMENT_NODE) {
  20482. var hostInstance = findHostInstanceWithNoPortals(container._reactRootContainer._internalRoot.current);
  20483. if (hostInstance) {
  20484. if (hostInstance.parentNode !== container) {
  20485. error('render(...): It looks like the React-rendered content of this ' + 'container was removed without using React. This is not ' + 'supported and will cause errors. Instead, call ' + 'ReactDOM.unmountComponentAtNode to empty a container.');
  20486. }
  20487. }
  20488. }
  20489. var isRootRenderedBySomeReact = !!container._reactRootContainer;
  20490. var rootEl = getReactRootElementInContainer(container);
  20491. var hasNonRootReactChild = !!(rootEl && getInstanceFromNode$1(rootEl));
  20492. if (hasNonRootReactChild && !isRootRenderedBySomeReact) {
  20493. error('render(...): Replacing React-rendered children with a new root ' + 'component. If you intended to update the children of this node, ' + 'you should instead have the existing children update their state ' + 'and render the new components instead of calling ReactDOM.render.');
  20494. }
  20495. if (container.nodeType === ELEMENT_NODE && container.tagName && container.tagName.toUpperCase() === 'BODY') {
  20496. error('render(): Rendering components directly into document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + 'reconciliation issues. Try rendering into a container element created ' + 'for your app.');
  20497. }
  20498. };
  20499. }
  20500. function getReactRootElementInContainer(container) {
  20501. if (!container) {
  20502. return null;
  20503. }
  20504. if (container.nodeType === DOCUMENT_NODE) {
  20505. return container.documentElement;
  20506. } else {
  20507. return container.firstChild;
  20508. }
  20509. }
  20510. function shouldHydrateDueToLegacyHeuristic(container) {
  20511. var rootElement = getReactRootElementInContainer(container);
  20512. return !!(rootElement && rootElement.nodeType === ELEMENT_NODE && rootElement.hasAttribute(ROOT_ATTRIBUTE_NAME));
  20513. }
  20514. function legacyCreateRootFromDOMContainer(container, forceHydrate) {
  20515. var shouldHydrate = forceHydrate || shouldHydrateDueToLegacyHeuristic(container); // First clear any existing content.
  20516. if (!shouldHydrate) {
  20517. var warned = false;
  20518. var rootSibling;
  20519. while (rootSibling = container.lastChild) {
  20520. {
  20521. if (!warned && rootSibling.nodeType === ELEMENT_NODE && rootSibling.hasAttribute(ROOT_ATTRIBUTE_NAME)) {
  20522. warned = true;
  20523. error('render(): Target node has markup rendered by React, but there ' + 'are unrelated nodes as well. This is most commonly caused by ' + 'white-space inserted around server-rendered markup.');
  20524. }
  20525. }
  20526. container.removeChild(rootSibling);
  20527. }
  20528. }
  20529. {
  20530. if (shouldHydrate && !forceHydrate && !warnedAboutHydrateAPI) {
  20531. warnedAboutHydrateAPI = true;
  20532. warn('render(): Calling ReactDOM.render() to hydrate server-rendered markup ' + 'will stop working in React v17. Replace the ReactDOM.render() call ' + 'with ReactDOM.hydrate() if you want React to attach to the server HTML.');
  20533. }
  20534. }
  20535. return createLegacyRoot(container, shouldHydrate ? {
  20536. hydrate: true
  20537. } : undefined);
  20538. }
  20539. function warnOnInvalidCallback$1(callback, callerName) {
  20540. {
  20541. if (callback !== null && typeof callback !== 'function') {
  20542. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  20543. }
  20544. }
  20545. }
  20546. function legacyRenderSubtreeIntoContainer(parentComponent, children, container, forceHydrate, callback) {
  20547. {
  20548. topLevelUpdateWarnings(container);
  20549. warnOnInvalidCallback$1(callback === undefined ? null : callback, 'render');
  20550. } // TODO: Without `any` type, Flow says "Property cannot be accessed on any
  20551. // member of intersection type." Whyyyyyy.
  20552. var root = container._reactRootContainer;
  20553. var fiberRoot;
  20554. if (!root) {
  20555. // Initial mount
  20556. root = container._reactRootContainer = legacyCreateRootFromDOMContainer(container, forceHydrate);
  20557. fiberRoot = root._internalRoot;
  20558. if (typeof callback === 'function') {
  20559. var originalCallback = callback;
  20560. callback = function () {
  20561. var instance = getPublicRootInstance(fiberRoot);
  20562. originalCallback.call(instance);
  20563. };
  20564. } // Initial mount should not be batched.
  20565. unbatchedUpdates(function () {
  20566. updateContainer(children, fiberRoot, parentComponent, callback);
  20567. });
  20568. } else {
  20569. fiberRoot = root._internalRoot;
  20570. if (typeof callback === 'function') {
  20571. var _originalCallback = callback;
  20572. callback = function () {
  20573. var instance = getPublicRootInstance(fiberRoot);
  20574. _originalCallback.call(instance);
  20575. };
  20576. } // Update
  20577. updateContainer(children, fiberRoot, parentComponent, callback);
  20578. }
  20579. return getPublicRootInstance(fiberRoot);
  20580. }
  20581. function findDOMNode(componentOrElement) {
  20582. {
  20583. var owner = ReactCurrentOwner$3.current;
  20584. if (owner !== null && owner.stateNode !== null) {
  20585. var warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;
  20586. if (!warnedAboutRefsInRender) {
  20587. error('%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(owner.type) || 'A component');
  20588. }
  20589. owner.stateNode._warnedAboutRefsInRender = true;
  20590. }
  20591. }
  20592. if (componentOrElement == null) {
  20593. return null;
  20594. }
  20595. if (componentOrElement.nodeType === ELEMENT_NODE) {
  20596. return componentOrElement;
  20597. }
  20598. {
  20599. return findHostInstanceWithWarning(componentOrElement, 'findDOMNode');
  20600. }
  20601. }
  20602. function hydrate(element, container, callback) {
  20603. if (!isValidContainer(container)) {
  20604. {
  20605. throw Error( "Target container is not a DOM element." );
  20606. }
  20607. }
  20608. {
  20609. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  20610. if (isModernRoot) {
  20611. error('You are calling ReactDOM.hydrate() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. ' + 'Did you mean to call createRoot(container, {hydrate: true}).render(element)?');
  20612. }
  20613. } // TODO: throw or warn if we couldn't hydrate?
  20614. return legacyRenderSubtreeIntoContainer(null, element, container, true, callback);
  20615. }
  20616. function render(element, container, callback) {
  20617. if (!isValidContainer(container)) {
  20618. {
  20619. throw Error( "Target container is not a DOM element." );
  20620. }
  20621. }
  20622. {
  20623. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  20624. if (isModernRoot) {
  20625. error('You are calling ReactDOM.render() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. ' + 'Did you mean to call root.render(element)?');
  20626. }
  20627. }
  20628. return legacyRenderSubtreeIntoContainer(null, element, container, false, callback);
  20629. }
  20630. function unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
  20631. if (!isValidContainer(containerNode)) {
  20632. {
  20633. throw Error( "Target container is not a DOM element." );
  20634. }
  20635. }
  20636. if (!(parentComponent != null && has$1(parentComponent))) {
  20637. {
  20638. throw Error( "parentComponent must be a valid React Component" );
  20639. }
  20640. }
  20641. return legacyRenderSubtreeIntoContainer(parentComponent, element, containerNode, false, callback);
  20642. }
  20643. function unmountComponentAtNode(container) {
  20644. if (!isValidContainer(container)) {
  20645. {
  20646. throw Error( "unmountComponentAtNode(...): Target container is not a DOM element." );
  20647. }
  20648. }
  20649. {
  20650. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  20651. if (isModernRoot) {
  20652. error('You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?');
  20653. }
  20654. }
  20655. if (container._reactRootContainer) {
  20656. {
  20657. var rootEl = getReactRootElementInContainer(container);
  20658. var renderedByDifferentReact = rootEl && !getInstanceFromNode$1(rootEl);
  20659. if (renderedByDifferentReact) {
  20660. error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by another copy of React.');
  20661. }
  20662. } // Unmount should not be batched.
  20663. unbatchedUpdates(function () {
  20664. legacyRenderSubtreeIntoContainer(null, null, container, false, function () {
  20665. // $FlowFixMe This should probably use `delete container._reactRootContainer`
  20666. container._reactRootContainer = null;
  20667. unmarkContainerAsRoot(container);
  20668. });
  20669. }); // If you call unmountComponentAtNode twice in quick succession, you'll
  20670. // get `true` twice. That's probably fine?
  20671. return true;
  20672. } else {
  20673. {
  20674. var _rootEl = getReactRootElementInContainer(container);
  20675. var hasNonRootReactChild = !!(_rootEl && getInstanceFromNode$1(_rootEl)); // Check if the container itself is a React root node.
  20676. var isContainerReactRoot = container.nodeType === ELEMENT_NODE && isValidContainer(container.parentNode) && !!container.parentNode._reactRootContainer;
  20677. if (hasNonRootReactChild) {
  20678. error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot ? 'You may have accidentally passed in a React root node instead ' + 'of its container.' : 'Instead, have the parent component update its state and ' + 'rerender in order to remove this component.');
  20679. }
  20680. }
  20681. return false;
  20682. }
  20683. }
  20684. function createPortal(children, containerInfo, // TODO: figure out the API for cross-renderer implementation.
  20685. implementation) {
  20686. var key = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  20687. return {
  20688. // This tag allow us to uniquely identify this as a React Portal
  20689. $$typeof: REACT_PORTAL_TYPE,
  20690. key: key == null ? null : '' + key,
  20691. children: children,
  20692. containerInfo: containerInfo,
  20693. implementation: implementation
  20694. };
  20695. }
  20696. var ReactVersion = '16.13.1';
  20697. setAttemptUserBlockingHydration(attemptUserBlockingHydration$1);
  20698. setAttemptContinuousHydration(attemptContinuousHydration$1);
  20699. setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority$1);
  20700. var didWarnAboutUnstableCreatePortal = false;
  20701. {
  20702. if (typeof Map !== 'function' || // $FlowIssue Flow incorrectly thinks Map has no prototype
  20703. Map.prototype == null || typeof Map.prototype.forEach !== 'function' || typeof Set !== 'function' || // $FlowIssue Flow incorrectly thinks Set has no prototype
  20704. Set.prototype == null || typeof Set.prototype.clear !== 'function' || typeof Set.prototype.forEach !== 'function') {
  20705. error('React depends on Map and Set built-in types. Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');
  20706. }
  20707. }
  20708. setRestoreImplementation(restoreControlledState$3);
  20709. setBatchingImplementation(batchedUpdates$1, discreteUpdates$1, flushDiscreteUpdates, batchedEventUpdates$1);
  20710. function createPortal$1(children, container) {
  20711. var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  20712. if (!isValidContainer(container)) {
  20713. {
  20714. throw Error( "Target container is not a DOM element." );
  20715. }
  20716. } // TODO: pass ReactDOM portal implementation as third argument
  20717. // $FlowFixMe The Flow type is opaque but there's no way to actually create it.
  20718. return createPortal(children, container, null, key);
  20719. }
  20720. function renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
  20721. return unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback);
  20722. }
  20723. function unstable_createPortal(children, container) {
  20724. var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  20725. {
  20726. if (!didWarnAboutUnstableCreatePortal) {
  20727. didWarnAboutUnstableCreatePortal = true;
  20728. warn('The ReactDOM.unstable_createPortal() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactDOM.createPortal() instead. It has the exact same API, ' + 'but without the "unstable_" prefix.');
  20729. }
  20730. }
  20731. return createPortal$1(children, container, key);
  20732. }
  20733. var Internals = {
  20734. // Keep in sync with ReactDOMUnstableNativeDependencies.js
  20735. // ReactTestUtils.js, and ReactTestUtilsAct.js. This is an array for better minification.
  20736. Events: [getInstanceFromNode$1, getNodeFromInstance$1, getFiberCurrentPropsFromNode$1, injectEventPluginsByName, eventNameDispatchConfigs, accumulateTwoPhaseDispatches, accumulateDirectDispatches, enqueueStateRestore, restoreStateIfNeeded, dispatchEvent, runEventsInBatch, flushPassiveEffects, IsThisRendererActing]
  20737. };
  20738. var foundDevTools = injectIntoDevTools({
  20739. findFiberByHostInstance: getClosestInstanceFromNode,
  20740. bundleType: 1 ,
  20741. version: ReactVersion,
  20742. rendererPackageName: 'react-dom'
  20743. });
  20744. {
  20745. if (!foundDevTools && canUseDOM && window.top === window.self) {
  20746. // If we're in Chrome or Firefox, provide a download link if not installed.
  20747. if (navigator.userAgent.indexOf('Chrome') > -1 && navigator.userAgent.indexOf('Edge') === -1 || navigator.userAgent.indexOf('Firefox') > -1) {
  20748. var protocol = window.location.protocol; // Don't warn in exotic cases like chrome-extension://.
  20749. if (/^(https?|file):$/.test(protocol)) {
  20750. // eslint-disable-next-line react-internal/no-production-logging
  20751. console.info('%cDownload the React DevTools ' + 'for a better development experience: ' + 'https://fb.me/react-devtools' + (protocol === 'file:' ? '\nYou might need to use a local HTTP server (instead of file://): ' + 'https://fb.me/react-devtools-faq' : ''), 'font-weight:bold');
  20752. }
  20753. }
  20754. }
  20755. }
  20756. exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = Internals;
  20757. exports.createPortal = createPortal$1;
  20758. exports.findDOMNode = findDOMNode;
  20759. exports.flushSync = flushSync;
  20760. exports.hydrate = hydrate;
  20761. exports.render = render;
  20762. exports.unmountComponentAtNode = unmountComponentAtNode;
  20763. exports.unstable_batchedUpdates = batchedUpdates$1;
  20764. exports.unstable_createPortal = unstable_createPortal;
  20765. exports.unstable_renderSubtreeIntoContainer = renderSubtreeIntoContainer;
  20766. exports.version = ReactVersion;
  20767. })));