react-test-renderer.development.js 555 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709
  1. /** @license React v16.13.1
  2. * react-test-renderer.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' ? module.exports = factory(require('react'), require('scheduler/unstable_mock'), require('scheduler')) :
  12. typeof define === 'function' && define.amd ? define(['react', 'scheduler/unstable_mock', 'scheduler'], factory) :
  13. (global = global || self, global.ReactTestRenderer = factory(global.React, global.SchedulerMock, global.Scheduler));
  14. }(this, (function (React, Scheduler, Scheduler$1) { 'use strict';
  15. function _defineProperties(target, props) {
  16. for (var i = 0; i < props.length; i++) {
  17. var descriptor = props[i];
  18. descriptor.enumerable = descriptor.enumerable || false;
  19. descriptor.configurable = true;
  20. if ("value" in descriptor) descriptor.writable = true;
  21. Object.defineProperty(target, descriptor.key, descriptor);
  22. }
  23. }
  24. function _createClass(Constructor, protoProps, staticProps) {
  25. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  26. if (staticProps) _defineProperties(Constructor, staticProps);
  27. return Constructor;
  28. }
  29. function _objectWithoutPropertiesLoose(source, excluded) {
  30. if (source == null) return {};
  31. var target = {};
  32. var sourceKeys = Object.keys(source);
  33. var key, i;
  34. for (i = 0; i < sourceKeys.length; i++) {
  35. key = sourceKeys[i];
  36. if (excluded.indexOf(key) >= 0) continue;
  37. target[key] = source[key];
  38. }
  39. return target;
  40. }
  41. var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  42. var _assign = ReactInternals.assign;
  43. 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.
  44. // Current owner and dispatcher used to share the same ref,
  45. // but PR #14548 split them out to better support the react-debug-tools package.
  46. if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
  47. ReactSharedInternals.ReactCurrentDispatcher = {
  48. current: null
  49. };
  50. }
  51. if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
  52. ReactSharedInternals.ReactCurrentBatchConfig = {
  53. suspense: null
  54. };
  55. }
  56. // by calls to these methods by a Babel plugin.
  57. //
  58. // In PROD (or in packages without access to React internals),
  59. // they are left as they are instead.
  60. function warn(format) {
  61. {
  62. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  63. args[_key - 1] = arguments[_key];
  64. }
  65. printWarning('warn', format, args);
  66. }
  67. }
  68. function error(format) {
  69. {
  70. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  71. args[_key2 - 1] = arguments[_key2];
  72. }
  73. printWarning('error', format, args);
  74. }
  75. }
  76. function printWarning(level, format, args) {
  77. // When changing this logic, you might want to also
  78. // update consoleWithStackDev.www.js as well.
  79. {
  80. var hasExistingStack = args.length > 0 && typeof args[args.length - 1] === 'string' && args[args.length - 1].indexOf('\n in') === 0;
  81. if (!hasExistingStack) {
  82. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  83. var stack = ReactDebugCurrentFrame.getStackAddendum();
  84. if (stack !== '') {
  85. format += '%s';
  86. args = args.concat([stack]);
  87. }
  88. }
  89. var argsWithFormat = args.map(function (item) {
  90. return '' + item;
  91. }); // Careful: RN currently depends on this prefix
  92. argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
  93. // breaks IE9: https://github.com/facebook/react/issues/13610
  94. // eslint-disable-next-line react-internal/no-production-logging
  95. Function.prototype.apply.call(console[level], console, argsWithFormat);
  96. try {
  97. // --- Welcome to debugging React ---
  98. // This error was thrown as a convenience so that you can use this stack
  99. // to find the callsite that caused this warning to fire.
  100. var argIndex = 0;
  101. var message = 'Warning: ' + format.replace(/%s/g, function () {
  102. return args[argIndex++];
  103. });
  104. throw new Error(message);
  105. } catch (x) {}
  106. }
  107. }
  108. var FunctionComponent = 0;
  109. var ClassComponent = 1;
  110. var IndeterminateComponent = 2; // Before we know whether it is function or class
  111. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  112. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  113. var HostComponent = 5;
  114. var HostText = 6;
  115. var Fragment = 7;
  116. var Mode = 8;
  117. var ContextConsumer = 9;
  118. var ContextProvider = 10;
  119. var ForwardRef = 11;
  120. var Profiler = 12;
  121. var SuspenseComponent = 13;
  122. var MemoComponent = 14;
  123. var SimpleMemoComponent = 15;
  124. var LazyComponent = 16;
  125. var IncompleteClassComponent = 17;
  126. var DehydratedFragment = 18;
  127. var SuspenseListComponent = 19;
  128. var FundamentalComponent = 20;
  129. var ScopeComponent = 21;
  130. var Block = 22;
  131. /**
  132. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  133. * instance (key) and the internal representation (value). This allows public
  134. * methods to accept the user facing instance as an argument and map them back
  135. * to internal methods.
  136. *
  137. * Note that this module is currently shared and assumed to be stateless.
  138. * If this becomes an actual Map, that will break.
  139. */
  140. function get(key) {
  141. return key._reactInternalFiber;
  142. }
  143. function set(key, value) {
  144. key._reactInternalFiber = value;
  145. }
  146. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  147. // nor polyfill, then a plain number is used for performance.
  148. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  149. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  150. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
  151. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
  152. var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
  153. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
  154. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
  155. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  156. var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
  157. var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
  158. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
  159. var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
  160. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
  161. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
  162. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
  163. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  164. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  165. function getIteratorFn(maybeIterable) {
  166. if (maybeIterable === null || typeof maybeIterable !== 'object') {
  167. return null;
  168. }
  169. var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
  170. if (typeof maybeIterator === 'function') {
  171. return maybeIterator;
  172. }
  173. return null;
  174. }
  175. var Uninitialized = -1;
  176. var Pending = 0;
  177. var Resolved = 1;
  178. var Rejected = 2;
  179. function refineResolvedLazyComponent(lazyComponent) {
  180. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  181. }
  182. function initializeLazyComponentType(lazyComponent) {
  183. if (lazyComponent._status === Uninitialized) {
  184. lazyComponent._status = Pending;
  185. var ctor = lazyComponent._ctor;
  186. var thenable = ctor();
  187. lazyComponent._result = thenable;
  188. thenable.then(function (moduleObject) {
  189. if (lazyComponent._status === Pending) {
  190. var defaultExport = moduleObject.default;
  191. {
  192. if (defaultExport === undefined) {
  193. 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);
  194. }
  195. }
  196. lazyComponent._status = Resolved;
  197. lazyComponent._result = defaultExport;
  198. }
  199. }, function (error) {
  200. if (lazyComponent._status === Pending) {
  201. lazyComponent._status = Rejected;
  202. lazyComponent._result = error;
  203. }
  204. });
  205. }
  206. }
  207. function getWrappedName(outerType, innerType, wrapperName) {
  208. var functionName = innerType.displayName || innerType.name || '';
  209. return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
  210. }
  211. function getComponentName(type) {
  212. if (type == null) {
  213. // Host root, text node or just invalid type.
  214. return null;
  215. }
  216. {
  217. if (typeof type.tag === 'number') {
  218. error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
  219. }
  220. }
  221. if (typeof type === 'function') {
  222. return type.displayName || type.name || null;
  223. }
  224. if (typeof type === 'string') {
  225. return type;
  226. }
  227. switch (type) {
  228. case REACT_FRAGMENT_TYPE:
  229. return 'Fragment';
  230. case REACT_PORTAL_TYPE:
  231. return 'Portal';
  232. case REACT_PROFILER_TYPE:
  233. return "Profiler";
  234. case REACT_STRICT_MODE_TYPE:
  235. return 'StrictMode';
  236. case REACT_SUSPENSE_TYPE:
  237. return 'Suspense';
  238. case REACT_SUSPENSE_LIST_TYPE:
  239. return 'SuspenseList';
  240. }
  241. if (typeof type === 'object') {
  242. switch (type.$$typeof) {
  243. case REACT_CONTEXT_TYPE:
  244. return 'Context.Consumer';
  245. case REACT_PROVIDER_TYPE:
  246. return 'Context.Provider';
  247. case REACT_FORWARD_REF_TYPE:
  248. return getWrappedName(type, type.render, 'ForwardRef');
  249. case REACT_MEMO_TYPE:
  250. return getComponentName(type.type);
  251. case REACT_BLOCK_TYPE:
  252. return getComponentName(type.render);
  253. case REACT_LAZY_TYPE:
  254. {
  255. var thenable = type;
  256. var resolvedThenable = refineResolvedLazyComponent(thenable);
  257. if (resolvedThenable) {
  258. return getComponentName(resolvedThenable);
  259. }
  260. break;
  261. }
  262. }
  263. }
  264. return null;
  265. }
  266. // Don't change these two values. They're used by React Dev Tools.
  267. var NoEffect =
  268. /* */
  269. 0;
  270. var PerformedWork =
  271. /* */
  272. 1; // You can change the rest (and add more).
  273. var Placement =
  274. /* */
  275. 2;
  276. var Update =
  277. /* */
  278. 4;
  279. var PlacementAndUpdate =
  280. /* */
  281. 6;
  282. var Deletion =
  283. /* */
  284. 8;
  285. var ContentReset =
  286. /* */
  287. 16;
  288. var Callback =
  289. /* */
  290. 32;
  291. var DidCapture =
  292. /* */
  293. 64;
  294. var Ref =
  295. /* */
  296. 128;
  297. var Snapshot =
  298. /* */
  299. 256;
  300. var Passive =
  301. /* */
  302. 512;
  303. var Hydrating =
  304. /* */
  305. 1024;
  306. var HydratingAndUpdate =
  307. /* */
  308. 1028; // Passive & Update & Callback & Ref & Snapshot
  309. var LifecycleEffectMask =
  310. /* */
  311. 932; // Union of all host effects
  312. var HostEffectMask =
  313. /* */
  314. 2047;
  315. var Incomplete =
  316. /* */
  317. 2048;
  318. var ShouldCapture =
  319. /* */
  320. 4096;
  321. var enableProfilerTimer = true;
  322. var enableFundamentalAPI = false;
  323. var warnAboutStringRefs = false;
  324. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  325. function getNearestMountedFiber(fiber) {
  326. var node = fiber;
  327. var nearestMounted = fiber;
  328. if (!fiber.alternate) {
  329. // If there is no alternate, this might be a new tree that isn't inserted
  330. // yet. If it is, then it will have a pending insertion effect on it.
  331. var nextNode = node;
  332. do {
  333. node = nextNode;
  334. if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
  335. // This is an insertion or in-progress hydration. The nearest possible
  336. // mounted fiber is the parent but we need to continue to figure out
  337. // if that one is still mounted.
  338. nearestMounted = node.return;
  339. }
  340. nextNode = node.return;
  341. } while (nextNode);
  342. } else {
  343. while (node.return) {
  344. node = node.return;
  345. }
  346. }
  347. if (node.tag === HostRoot) {
  348. // TODO: Check if this was a nested HostRoot when used with
  349. // renderContainerIntoSubtree.
  350. return nearestMounted;
  351. } // If we didn't hit the root, that means that we're in an disconnected tree
  352. // that has been unmounted.
  353. return null;
  354. }
  355. function isFiberMounted(fiber) {
  356. return getNearestMountedFiber(fiber) === fiber;
  357. }
  358. function isMounted(component) {
  359. {
  360. var owner = ReactCurrentOwner.current;
  361. if (owner !== null && owner.tag === ClassComponent) {
  362. var ownerFiber = owner;
  363. var instance = ownerFiber.stateNode;
  364. if (!instance._warnedAboutRefsInRender) {
  365. 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');
  366. }
  367. instance._warnedAboutRefsInRender = true;
  368. }
  369. }
  370. var fiber = get(component);
  371. if (!fiber) {
  372. return false;
  373. }
  374. return getNearestMountedFiber(fiber) === fiber;
  375. }
  376. function assertIsMounted(fiber) {
  377. if (!(getNearestMountedFiber(fiber) === fiber)) {
  378. {
  379. throw Error( "Unable to find node on an unmounted component." );
  380. }
  381. }
  382. }
  383. function findCurrentFiberUsingSlowPath(fiber) {
  384. var alternate = fiber.alternate;
  385. if (!alternate) {
  386. // If there is no alternate, then we only need to check if it is mounted.
  387. var nearestMounted = getNearestMountedFiber(fiber);
  388. if (!(nearestMounted !== null)) {
  389. {
  390. throw Error( "Unable to find node on an unmounted component." );
  391. }
  392. }
  393. if (nearestMounted !== fiber) {
  394. return null;
  395. }
  396. return fiber;
  397. } // If we have two possible branches, we'll walk backwards up to the root
  398. // to see what path the root points to. On the way we may hit one of the
  399. // special cases and we'll deal with them.
  400. var a = fiber;
  401. var b = alternate;
  402. while (true) {
  403. var parentA = a.return;
  404. if (parentA === null) {
  405. // We're at the root.
  406. break;
  407. }
  408. var parentB = parentA.alternate;
  409. if (parentB === null) {
  410. // There is no alternate. This is an unusual case. Currently, it only
  411. // happens when a Suspense component is hidden. An extra fragment fiber
  412. // is inserted in between the Suspense fiber and its children. Skip
  413. // over this extra fragment fiber and proceed to the next parent.
  414. var nextParent = parentA.return;
  415. if (nextParent !== null) {
  416. a = b = nextParent;
  417. continue;
  418. } // If there's no parent, we're at the root.
  419. break;
  420. } // If both copies of the parent fiber point to the same child, we can
  421. // assume that the child is current. This happens when we bailout on low
  422. // priority: the bailed out fiber's child reuses the current child.
  423. if (parentA.child === parentB.child) {
  424. var child = parentA.child;
  425. while (child) {
  426. if (child === a) {
  427. // We've determined that A is the current branch.
  428. assertIsMounted(parentA);
  429. return fiber;
  430. }
  431. if (child === b) {
  432. // We've determined that B is the current branch.
  433. assertIsMounted(parentA);
  434. return alternate;
  435. }
  436. child = child.sibling;
  437. } // We should never have an alternate for any mounting node. So the only
  438. // way this could possibly happen is if this was unmounted, if at all.
  439. {
  440. {
  441. throw Error( "Unable to find node on an unmounted component." );
  442. }
  443. }
  444. }
  445. if (a.return !== b.return) {
  446. // The return pointer of A and the return pointer of B point to different
  447. // fibers. We assume that return pointers never criss-cross, so A must
  448. // belong to the child set of A.return, and B must belong to the child
  449. // set of B.return.
  450. a = parentA;
  451. b = parentB;
  452. } else {
  453. // The return pointers point to the same fiber. We'll have to use the
  454. // default, slow path: scan the child sets of each parent alternate to see
  455. // which child belongs to which set.
  456. //
  457. // Search parent A's child set
  458. var didFindChild = false;
  459. var _child = parentA.child;
  460. while (_child) {
  461. if (_child === a) {
  462. didFindChild = true;
  463. a = parentA;
  464. b = parentB;
  465. break;
  466. }
  467. if (_child === b) {
  468. didFindChild = true;
  469. b = parentA;
  470. a = parentB;
  471. break;
  472. }
  473. _child = _child.sibling;
  474. }
  475. if (!didFindChild) {
  476. // Search parent B's child set
  477. _child = parentB.child;
  478. while (_child) {
  479. if (_child === a) {
  480. didFindChild = true;
  481. a = parentB;
  482. b = parentA;
  483. break;
  484. }
  485. if (_child === b) {
  486. didFindChild = true;
  487. b = parentB;
  488. a = parentA;
  489. break;
  490. }
  491. _child = _child.sibling;
  492. }
  493. if (!didFindChild) {
  494. {
  495. 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." );
  496. }
  497. }
  498. }
  499. }
  500. if (!(a.alternate === b)) {
  501. {
  502. throw Error( "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." );
  503. }
  504. }
  505. } // If the root is not a host container, we're in a disconnected tree. I.e.
  506. // unmounted.
  507. if (!(a.tag === HostRoot)) {
  508. {
  509. throw Error( "Unable to find node on an unmounted component." );
  510. }
  511. }
  512. if (a.stateNode.current === a) {
  513. // We've determined that A is the current branch.
  514. return fiber;
  515. } // Otherwise B has to be current branch.
  516. return alternate;
  517. }
  518. function findCurrentHostFiber(parent) {
  519. var currentParent = findCurrentFiberUsingSlowPath(parent);
  520. if (!currentParent) {
  521. return null;
  522. } // Next we'll drill down this component to find the first HostComponent/Text.
  523. var node = currentParent;
  524. while (true) {
  525. if (node.tag === HostComponent || node.tag === HostText) {
  526. return node;
  527. } else if (node.child) {
  528. node.child.return = node;
  529. node = node.child;
  530. continue;
  531. }
  532. if (node === currentParent) {
  533. return null;
  534. }
  535. while (!node.sibling) {
  536. if (!node.return || node.return === currentParent) {
  537. return null;
  538. }
  539. node = node.return;
  540. }
  541. node.sibling.return = node.return;
  542. node = node.sibling;
  543. } // Flow needs the return null here, but ESLint complains about it.
  544. // eslint-disable-next-line no-unreachable
  545. return null;
  546. }
  547. // can re-export everything from this module.
  548. function shim() {
  549. {
  550. {
  551. throw Error( "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue." );
  552. }
  553. }
  554. } // Hydration (when unsupported)
  555. var isSuspenseInstancePending = shim;
  556. var isSuspenseInstanceFallback = shim;
  557. var hydrateTextInstance = shim;
  558. var NO_CONTEXT = {};
  559. var UPDATE_SIGNAL = {};
  560. var nodeToInstanceMap = new WeakMap();
  561. {
  562. Object.freeze(NO_CONTEXT);
  563. Object.freeze(UPDATE_SIGNAL);
  564. }
  565. function getPublicInstance(inst) {
  566. switch (inst.tag) {
  567. case 'INSTANCE':
  568. var createNodeMock = inst.rootContainerInstance.createNodeMock;
  569. var mockNode = createNodeMock({
  570. type: inst.type,
  571. props: inst.props
  572. });
  573. if (typeof mockNode === 'object' && mockNode !== null) {
  574. nodeToInstanceMap.set(mockNode, inst);
  575. }
  576. return mockNode;
  577. default:
  578. return inst;
  579. }
  580. }
  581. function appendChild(parentInstance, child) {
  582. {
  583. if (!Array.isArray(parentInstance.children)) {
  584. error('An invalid container has been provided. ' + 'This may indicate that another renderer is being used in addition to the test renderer. ' + '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' + 'This is not supported.');
  585. }
  586. }
  587. var index = parentInstance.children.indexOf(child);
  588. if (index !== -1) {
  589. parentInstance.children.splice(index, 1);
  590. }
  591. parentInstance.children.push(child);
  592. }
  593. function insertBefore(parentInstance, child, beforeChild) {
  594. var index = parentInstance.children.indexOf(child);
  595. if (index !== -1) {
  596. parentInstance.children.splice(index, 1);
  597. }
  598. var beforeIndex = parentInstance.children.indexOf(beforeChild);
  599. parentInstance.children.splice(beforeIndex, 0, child);
  600. }
  601. function removeChild(parentInstance, child) {
  602. var index = parentInstance.children.indexOf(child);
  603. parentInstance.children.splice(index, 1);
  604. }
  605. function getRootHostContext(rootContainerInstance) {
  606. return NO_CONTEXT;
  607. }
  608. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  609. return NO_CONTEXT;
  610. }
  611. function prepareForCommit(containerInfo) {// noop
  612. }
  613. function resetAfterCommit(containerInfo) {// noop
  614. }
  615. function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
  616. var propsToUse = props;
  617. return {
  618. type: type,
  619. props: propsToUse,
  620. isHidden: false,
  621. children: [],
  622. internalInstanceHandle: internalInstanceHandle,
  623. rootContainerInstance: rootContainerInstance,
  624. tag: 'INSTANCE'
  625. };
  626. }
  627. function appendInitialChild(parentInstance, child) {
  628. var index = parentInstance.children.indexOf(child);
  629. if (index !== -1) {
  630. parentInstance.children.splice(index, 1);
  631. }
  632. parentInstance.children.push(child);
  633. }
  634. function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
  635. return UPDATE_SIGNAL;
  636. }
  637. function shouldSetTextContent(type, props) {
  638. return false;
  639. }
  640. function shouldDeprioritizeSubtree(type, props) {
  641. return false;
  642. }
  643. function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
  644. return {
  645. text: text,
  646. isHidden: false,
  647. tag: 'TEXT'
  648. };
  649. }
  650. var scheduleTimeout = setTimeout;
  651. var cancelTimeout = clearTimeout;
  652. var noTimeout = -1; // -------------------
  653. function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
  654. instance.type = type;
  655. instance.props = newProps;
  656. }
  657. function commitTextUpdate(textInstance, oldText, newText) {
  658. textInstance.text = newText;
  659. }
  660. function resetTextContent(testElement) {// noop
  661. }
  662. var appendChildToContainer = appendChild;
  663. var insertInContainerBefore = insertBefore;
  664. var removeChildFromContainer = removeChild;
  665. function hideInstance(instance) {
  666. instance.isHidden = true;
  667. }
  668. function hideTextInstance(textInstance) {
  669. textInstance.isHidden = true;
  670. }
  671. function unhideInstance(instance, props) {
  672. instance.isHidden = false;
  673. }
  674. function unhideTextInstance(textInstance, text) {
  675. textInstance.isHidden = false;
  676. }
  677. /**
  678. * Copyright (c) 2013-present, Facebook, Inc.
  679. *
  680. * This source code is licensed under the MIT license found in the
  681. * LICENSE file in the root directory of this source tree.
  682. */
  683. var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
  684. var ReactPropTypesSecret_1 = ReactPropTypesSecret;
  685. var printWarning$1 = function() {};
  686. {
  687. var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
  688. var loggedTypeFailures = {};
  689. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  690. printWarning$1 = function(text) {
  691. var message = 'Warning: ' + text;
  692. if (typeof console !== 'undefined') {
  693. console.error(message);
  694. }
  695. try {
  696. // --- Welcome to debugging React ---
  697. // This error was thrown as a convenience so that you can use this stack
  698. // to find the callsite that caused this warning to fire.
  699. throw new Error(message);
  700. } catch (x) {}
  701. };
  702. }
  703. /**
  704. * Assert that the values match with the type specs.
  705. * Error messages are memorized and will only be shown once.
  706. *
  707. * @param {object} typeSpecs Map of name to a ReactPropType
  708. * @param {object} values Runtime values that need to be type-checked
  709. * @param {string} location e.g. "prop", "context", "child context"
  710. * @param {string} componentName Name of the component for error messages.
  711. * @param {?Function} getStack Returns the component stack.
  712. * @private
  713. */
  714. function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
  715. {
  716. for (var typeSpecName in typeSpecs) {
  717. if (has(typeSpecs, typeSpecName)) {
  718. var error;
  719. // Prop type validation may throw. In case they do, we don't want to
  720. // fail the render phase where it didn't fail before. So we log it.
  721. // After these have been cleaned up, we'll let them throw.
  722. try {
  723. // This is intentionally an invariant that gets caught. It's the same
  724. // behavior as without this statement except with a better message.
  725. if (typeof typeSpecs[typeSpecName] !== 'function') {
  726. var err = Error(
  727. (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
  728. 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
  729. );
  730. err.name = 'Invariant Violation';
  731. throw err;
  732. }
  733. error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
  734. } catch (ex) {
  735. error = ex;
  736. }
  737. if (error && !(error instanceof Error)) {
  738. printWarning$1(
  739. (componentName || 'React class') + ': type specification of ' +
  740. location + ' `' + typeSpecName + '` is invalid; the type checker ' +
  741. 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
  742. 'You may have forgotten to pass an argument to the type checker ' +
  743. 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
  744. 'shape all require an argument).'
  745. );
  746. }
  747. if (error instanceof Error && !(error.message in loggedTypeFailures)) {
  748. // Only monitor this failure once because there tends to be a lot of the
  749. // same error.
  750. loggedTypeFailures[error.message] = true;
  751. var stack = getStack ? getStack() : '';
  752. printWarning$1(
  753. 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
  754. );
  755. }
  756. }
  757. }
  758. }
  759. }
  760. /**
  761. * Resets warning cache when testing.
  762. *
  763. * @private
  764. */
  765. checkPropTypes.resetWarningCache = function() {
  766. {
  767. loggedTypeFailures = {};
  768. }
  769. };
  770. var checkPropTypes_1 = checkPropTypes;
  771. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  772. function describeComponentFrame (name, source, ownerName) {
  773. var sourceInfo = '';
  774. if (source) {
  775. var path = source.fileName;
  776. var fileName = path.replace(BEFORE_SLASH_RE, '');
  777. {
  778. // In DEV, include code for a common special case:
  779. // prefer "folder/index.js" instead of just "index.js".
  780. if (/^index\./.test(fileName)) {
  781. var match = path.match(BEFORE_SLASH_RE);
  782. if (match) {
  783. var pathBeforeSlash = match[1];
  784. if (pathBeforeSlash) {
  785. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
  786. fileName = folderName + '/' + fileName;
  787. }
  788. }
  789. }
  790. }
  791. sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
  792. } else if (ownerName) {
  793. sourceInfo = ' (created by ' + ownerName + ')';
  794. }
  795. return '\n in ' + (name || 'Unknown') + sourceInfo;
  796. }
  797. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  798. function describeFiber(fiber) {
  799. switch (fiber.tag) {
  800. case HostRoot:
  801. case HostPortal:
  802. case HostText:
  803. case Fragment:
  804. case ContextProvider:
  805. case ContextConsumer:
  806. return '';
  807. default:
  808. var owner = fiber._debugOwner;
  809. var source = fiber._debugSource;
  810. var name = getComponentName(fiber.type);
  811. var ownerName = null;
  812. if (owner) {
  813. ownerName = getComponentName(owner.type);
  814. }
  815. return describeComponentFrame(name, source, ownerName);
  816. }
  817. }
  818. function getStackByFiberInDevAndProd(workInProgress) {
  819. var info = '';
  820. var node = workInProgress;
  821. do {
  822. info += describeFiber(node);
  823. node = node.return;
  824. } while (node);
  825. return info;
  826. }
  827. var current = null;
  828. var isRendering = false;
  829. function getCurrentFiberOwnerNameInDevOrNull() {
  830. {
  831. if (current === null) {
  832. return null;
  833. }
  834. var owner = current._debugOwner;
  835. if (owner !== null && typeof owner !== 'undefined') {
  836. return getComponentName(owner.type);
  837. }
  838. }
  839. return null;
  840. }
  841. function getCurrentFiberStackInDev() {
  842. {
  843. if (current === null) {
  844. return '';
  845. } // Safe because if current fiber exists, we are reconciling,
  846. // and it is guaranteed to be the work-in-progress version.
  847. return getStackByFiberInDevAndProd(current);
  848. }
  849. }
  850. function resetCurrentFiber() {
  851. {
  852. ReactDebugCurrentFrame.getCurrentStack = null;
  853. current = null;
  854. isRendering = false;
  855. }
  856. }
  857. function setCurrentFiber(fiber) {
  858. {
  859. ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
  860. current = fiber;
  861. isRendering = false;
  862. }
  863. }
  864. function setIsRendering(rendering) {
  865. {
  866. isRendering = rendering;
  867. }
  868. }
  869. // Prefix measurements so that it's possible to filter them.
  870. // Longer prefixes are hard to read in DevTools.
  871. var reactEmoji = "\u269B";
  872. var warningEmoji = "\u26D4";
  873. 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.
  874. // TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
  875. var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
  876. // Reusing `currentFiber` would be confusing for this because user code fiber
  877. // can change during commit phase too, but we don't need to unwind it (since
  878. // lifecycles in the commit phase don't resemble a tree).
  879. var currentPhase = null;
  880. var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
  881. // so we will keep track of it, and include it in the report.
  882. // Track commits caused by cascading updates.
  883. var isCommitting = false;
  884. var hasScheduledUpdateInCurrentCommit = false;
  885. var hasScheduledUpdateInCurrentPhase = false;
  886. var commitCountInCurrentWorkLoop = 0;
  887. var effectCountInCurrentCommit = 0;
  888. // to avoid stretch the commit phase with measurement overhead.
  889. var labelsInCurrentCommit = new Set();
  890. var formatMarkName = function (markName) {
  891. return reactEmoji + " " + markName;
  892. };
  893. var formatLabel = function (label, warning) {
  894. var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
  895. var suffix = warning ? " Warning: " + warning : '';
  896. return "" + prefix + label + suffix;
  897. };
  898. var beginMark = function (markName) {
  899. performance.mark(formatMarkName(markName));
  900. };
  901. var clearMark = function (markName) {
  902. performance.clearMarks(formatMarkName(markName));
  903. };
  904. var endMark = function (label, markName, warning) {
  905. var formattedMarkName = formatMarkName(markName);
  906. var formattedLabel = formatLabel(label, warning);
  907. try {
  908. performance.measure(formattedLabel, formattedMarkName);
  909. } catch (err) {} // If previous mark was missing for some reason, this will throw.
  910. // This could only happen if React crashed in an unexpected place earlier.
  911. // Don't pile on with more errors.
  912. // Clear marks immediately to avoid growing buffer.
  913. performance.clearMarks(formattedMarkName);
  914. performance.clearMeasures(formattedLabel);
  915. };
  916. var getFiberMarkName = function (label, debugID) {
  917. return label + " (#" + debugID + ")";
  918. };
  919. var getFiberLabel = function (componentName, isMounted, phase) {
  920. if (phase === null) {
  921. // These are composite component total time measurements.
  922. return componentName + " [" + (isMounted ? 'update' : 'mount') + "]";
  923. } else {
  924. // Composite component methods.
  925. return componentName + "." + phase;
  926. }
  927. };
  928. var beginFiberMark = function (fiber, phase) {
  929. var componentName = getComponentName(fiber.type) || 'Unknown';
  930. var debugID = fiber._debugID;
  931. var isMounted = fiber.alternate !== null;
  932. var label = getFiberLabel(componentName, isMounted, phase);
  933. if (isCommitting && labelsInCurrentCommit.has(label)) {
  934. // During the commit phase, we don't show duplicate labels because
  935. // there is a fixed overhead for every measurement, and we don't
  936. // want to stretch the commit phase beyond necessary.
  937. return false;
  938. }
  939. labelsInCurrentCommit.add(label);
  940. var markName = getFiberMarkName(label, debugID);
  941. beginMark(markName);
  942. return true;
  943. };
  944. var clearFiberMark = function (fiber, phase) {
  945. var componentName = getComponentName(fiber.type) || 'Unknown';
  946. var debugID = fiber._debugID;
  947. var isMounted = fiber.alternate !== null;
  948. var label = getFiberLabel(componentName, isMounted, phase);
  949. var markName = getFiberMarkName(label, debugID);
  950. clearMark(markName);
  951. };
  952. var endFiberMark = function (fiber, phase, warning) {
  953. var componentName = getComponentName(fiber.type) || 'Unknown';
  954. var debugID = fiber._debugID;
  955. var isMounted = fiber.alternate !== null;
  956. var label = getFiberLabel(componentName, isMounted, phase);
  957. var markName = getFiberMarkName(label, debugID);
  958. endMark(label, markName, warning);
  959. };
  960. var shouldIgnoreFiber = function (fiber) {
  961. // Host components should be skipped in the timeline.
  962. // We could check typeof fiber.type, but does this work with RN?
  963. switch (fiber.tag) {
  964. case HostRoot:
  965. case HostComponent:
  966. case HostText:
  967. case HostPortal:
  968. case Fragment:
  969. case ContextProvider:
  970. case ContextConsumer:
  971. case Mode:
  972. return true;
  973. default:
  974. return false;
  975. }
  976. };
  977. var clearPendingPhaseMeasurement = function () {
  978. if (currentPhase !== null && currentPhaseFiber !== null) {
  979. clearFiberMark(currentPhaseFiber, currentPhase);
  980. }
  981. currentPhaseFiber = null;
  982. currentPhase = null;
  983. hasScheduledUpdateInCurrentPhase = false;
  984. };
  985. var pauseTimers = function () {
  986. // Stops all currently active measurements so that they can be resumed
  987. // if we continue in a later deferred loop from the same unit of work.
  988. var fiber = currentFiber;
  989. while (fiber) {
  990. if (fiber._debugIsCurrentlyTiming) {
  991. endFiberMark(fiber, null, null);
  992. }
  993. fiber = fiber.return;
  994. }
  995. };
  996. var resumeTimersRecursively = function (fiber) {
  997. if (fiber.return !== null) {
  998. resumeTimersRecursively(fiber.return);
  999. }
  1000. if (fiber._debugIsCurrentlyTiming) {
  1001. beginFiberMark(fiber, null);
  1002. }
  1003. };
  1004. var resumeTimers = function () {
  1005. // Resumes all measurements that were active during the last deferred loop.
  1006. if (currentFiber !== null) {
  1007. resumeTimersRecursively(currentFiber);
  1008. }
  1009. };
  1010. function recordEffect() {
  1011. {
  1012. effectCountInCurrentCommit++;
  1013. }
  1014. }
  1015. function recordScheduleUpdate() {
  1016. {
  1017. if (isCommitting) {
  1018. hasScheduledUpdateInCurrentCommit = true;
  1019. }
  1020. if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
  1021. hasScheduledUpdateInCurrentPhase = true;
  1022. }
  1023. }
  1024. }
  1025. function startWorkTimer(fiber) {
  1026. {
  1027. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  1028. return;
  1029. } // If we pause, this is the fiber to unwind from.
  1030. currentFiber = fiber;
  1031. if (!beginFiberMark(fiber, null)) {
  1032. return;
  1033. }
  1034. fiber._debugIsCurrentlyTiming = true;
  1035. }
  1036. }
  1037. function cancelWorkTimer(fiber) {
  1038. {
  1039. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  1040. return;
  1041. } // Remember we shouldn't complete measurement for this fiber.
  1042. // Otherwise flamechart will be deep even for small updates.
  1043. fiber._debugIsCurrentlyTiming = false;
  1044. clearFiberMark(fiber, null);
  1045. }
  1046. }
  1047. function stopWorkTimer(fiber) {
  1048. {
  1049. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  1050. return;
  1051. } // If we pause, its parent is the fiber to unwind from.
  1052. currentFiber = fiber.return;
  1053. if (!fiber._debugIsCurrentlyTiming) {
  1054. return;
  1055. }
  1056. fiber._debugIsCurrentlyTiming = false;
  1057. endFiberMark(fiber, null, null);
  1058. }
  1059. }
  1060. function stopFailedWorkTimer(fiber) {
  1061. {
  1062. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  1063. return;
  1064. } // If we pause, its parent is the fiber to unwind from.
  1065. currentFiber = fiber.return;
  1066. if (!fiber._debugIsCurrentlyTiming) {
  1067. return;
  1068. }
  1069. fiber._debugIsCurrentlyTiming = false;
  1070. var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
  1071. endFiberMark(fiber, null, warning);
  1072. }
  1073. }
  1074. function startPhaseTimer(fiber, phase) {
  1075. {
  1076. if (!supportsUserTiming) {
  1077. return;
  1078. }
  1079. clearPendingPhaseMeasurement();
  1080. if (!beginFiberMark(fiber, phase)) {
  1081. return;
  1082. }
  1083. currentPhaseFiber = fiber;
  1084. currentPhase = phase;
  1085. }
  1086. }
  1087. function stopPhaseTimer() {
  1088. {
  1089. if (!supportsUserTiming) {
  1090. return;
  1091. }
  1092. if (currentPhase !== null && currentPhaseFiber !== null) {
  1093. var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
  1094. endFiberMark(currentPhaseFiber, currentPhase, warning);
  1095. }
  1096. currentPhase = null;
  1097. currentPhaseFiber = null;
  1098. }
  1099. }
  1100. function startWorkLoopTimer(nextUnitOfWork) {
  1101. {
  1102. currentFiber = nextUnitOfWork;
  1103. if (!supportsUserTiming) {
  1104. return;
  1105. }
  1106. commitCountInCurrentWorkLoop = 0; // This is top level call.
  1107. // Any other measurements are performed within.
  1108. beginMark('(React Tree Reconciliation)'); // Resume any measurements that were in progress during the last loop.
  1109. resumeTimers();
  1110. }
  1111. }
  1112. function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
  1113. {
  1114. if (!supportsUserTiming) {
  1115. return;
  1116. }
  1117. var warning = null;
  1118. if (interruptedBy !== null) {
  1119. if (interruptedBy.tag === HostRoot) {
  1120. warning = 'A top-level update interrupted the previous render';
  1121. } else {
  1122. var componentName = getComponentName(interruptedBy.type) || 'Unknown';
  1123. warning = "An update to " + componentName + " interrupted the previous render";
  1124. }
  1125. } else if (commitCountInCurrentWorkLoop > 1) {
  1126. warning = 'There were cascading updates';
  1127. }
  1128. commitCountInCurrentWorkLoop = 0;
  1129. var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)'; // Pause any measurements until the next loop.
  1130. pauseTimers();
  1131. endMark(label, '(React Tree Reconciliation)', warning);
  1132. }
  1133. }
  1134. function startCommitTimer() {
  1135. {
  1136. if (!supportsUserTiming) {
  1137. return;
  1138. }
  1139. isCommitting = true;
  1140. hasScheduledUpdateInCurrentCommit = false;
  1141. labelsInCurrentCommit.clear();
  1142. beginMark('(Committing Changes)');
  1143. }
  1144. }
  1145. function stopCommitTimer() {
  1146. {
  1147. if (!supportsUserTiming) {
  1148. return;
  1149. }
  1150. var warning = null;
  1151. if (hasScheduledUpdateInCurrentCommit) {
  1152. warning = 'Lifecycle hook scheduled a cascading update';
  1153. } else if (commitCountInCurrentWorkLoop > 0) {
  1154. warning = 'Caused by a cascading update in earlier commit';
  1155. }
  1156. hasScheduledUpdateInCurrentCommit = false;
  1157. commitCountInCurrentWorkLoop++;
  1158. isCommitting = false;
  1159. labelsInCurrentCommit.clear();
  1160. endMark('(Committing Changes)', '(Committing Changes)', warning);
  1161. }
  1162. }
  1163. function startCommitSnapshotEffectsTimer() {
  1164. {
  1165. if (!supportsUserTiming) {
  1166. return;
  1167. }
  1168. effectCountInCurrentCommit = 0;
  1169. beginMark('(Committing Snapshot Effects)');
  1170. }
  1171. }
  1172. function stopCommitSnapshotEffectsTimer() {
  1173. {
  1174. if (!supportsUserTiming) {
  1175. return;
  1176. }
  1177. var count = effectCountInCurrentCommit;
  1178. effectCountInCurrentCommit = 0;
  1179. endMark("(Committing Snapshot Effects: " + count + " Total)", '(Committing Snapshot Effects)', null);
  1180. }
  1181. }
  1182. function startCommitHostEffectsTimer() {
  1183. {
  1184. if (!supportsUserTiming) {
  1185. return;
  1186. }
  1187. effectCountInCurrentCommit = 0;
  1188. beginMark('(Committing Host Effects)');
  1189. }
  1190. }
  1191. function stopCommitHostEffectsTimer() {
  1192. {
  1193. if (!supportsUserTiming) {
  1194. return;
  1195. }
  1196. var count = effectCountInCurrentCommit;
  1197. effectCountInCurrentCommit = 0;
  1198. endMark("(Committing Host Effects: " + count + " Total)", '(Committing Host Effects)', null);
  1199. }
  1200. }
  1201. function startCommitLifeCyclesTimer() {
  1202. {
  1203. if (!supportsUserTiming) {
  1204. return;
  1205. }
  1206. effectCountInCurrentCommit = 0;
  1207. beginMark('(Calling Lifecycle Methods)');
  1208. }
  1209. }
  1210. function stopCommitLifeCyclesTimer() {
  1211. {
  1212. if (!supportsUserTiming) {
  1213. return;
  1214. }
  1215. var count = effectCountInCurrentCommit;
  1216. effectCountInCurrentCommit = 0;
  1217. endMark("(Calling Lifecycle Methods: " + count + " Total)", '(Calling Lifecycle Methods)', null);
  1218. }
  1219. }
  1220. var valueStack = [];
  1221. var fiberStack;
  1222. {
  1223. fiberStack = [];
  1224. }
  1225. var index = -1;
  1226. function createCursor(defaultValue) {
  1227. return {
  1228. current: defaultValue
  1229. };
  1230. }
  1231. function pop(cursor, fiber) {
  1232. if (index < 0) {
  1233. {
  1234. error('Unexpected pop.');
  1235. }
  1236. return;
  1237. }
  1238. {
  1239. if (fiber !== fiberStack[index]) {
  1240. error('Unexpected Fiber popped.');
  1241. }
  1242. }
  1243. cursor.current = valueStack[index];
  1244. valueStack[index] = null;
  1245. {
  1246. fiberStack[index] = null;
  1247. }
  1248. index--;
  1249. }
  1250. function push(cursor, value, fiber) {
  1251. index++;
  1252. valueStack[index] = cursor.current;
  1253. {
  1254. fiberStack[index] = fiber;
  1255. }
  1256. cursor.current = value;
  1257. }
  1258. var warnedAboutMissingGetChildContext;
  1259. {
  1260. warnedAboutMissingGetChildContext = {};
  1261. }
  1262. var emptyContextObject = {};
  1263. {
  1264. Object.freeze(emptyContextObject);
  1265. } // A cursor to the current merged context object on the stack.
  1266. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  1267. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  1268. // We use this to get access to the parent context after we have already
  1269. // pushed the next context provider, and now need to merge their contexts.
  1270. var previousContext = emptyContextObject;
  1271. function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
  1272. {
  1273. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  1274. // If the fiber is a context provider itself, when we read its context
  1275. // we may have already pushed its own child context on the stack. A context
  1276. // provider should not "see" its own child context. Therefore we read the
  1277. // previous (parent) context instead for a context provider.
  1278. return previousContext;
  1279. }
  1280. return contextStackCursor.current;
  1281. }
  1282. }
  1283. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  1284. {
  1285. var instance = workInProgress.stateNode;
  1286. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  1287. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  1288. }
  1289. }
  1290. function getMaskedContext(workInProgress, unmaskedContext) {
  1291. {
  1292. var type = workInProgress.type;
  1293. var contextTypes = type.contextTypes;
  1294. if (!contextTypes) {
  1295. return emptyContextObject;
  1296. } // Avoid recreating masked context unless unmasked context has changed.
  1297. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  1298. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  1299. var instance = workInProgress.stateNode;
  1300. if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
  1301. return instance.__reactInternalMemoizedMaskedChildContext;
  1302. }
  1303. var context = {};
  1304. for (var key in contextTypes) {
  1305. context[key] = unmaskedContext[key];
  1306. }
  1307. {
  1308. var name = getComponentName(type) || 'Unknown';
  1309. checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
  1310. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  1311. // Context is created before the class component is instantiated so check for instance.
  1312. if (instance) {
  1313. cacheContext(workInProgress, unmaskedContext, context);
  1314. }
  1315. return context;
  1316. }
  1317. }
  1318. function hasContextChanged() {
  1319. {
  1320. return didPerformWorkStackCursor.current;
  1321. }
  1322. }
  1323. function isContextProvider(type) {
  1324. {
  1325. var childContextTypes = type.childContextTypes;
  1326. return childContextTypes !== null && childContextTypes !== undefined;
  1327. }
  1328. }
  1329. function popContext(fiber) {
  1330. {
  1331. pop(didPerformWorkStackCursor, fiber);
  1332. pop(contextStackCursor, fiber);
  1333. }
  1334. }
  1335. function popTopLevelContextObject(fiber) {
  1336. {
  1337. pop(didPerformWorkStackCursor, fiber);
  1338. pop(contextStackCursor, fiber);
  1339. }
  1340. }
  1341. function pushTopLevelContextObject(fiber, context, didChange) {
  1342. {
  1343. if (!(contextStackCursor.current === emptyContextObject)) {
  1344. {
  1345. throw Error( "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." );
  1346. }
  1347. }
  1348. push(contextStackCursor, context, fiber);
  1349. push(didPerformWorkStackCursor, didChange, fiber);
  1350. }
  1351. }
  1352. function processChildContext(fiber, type, parentContext) {
  1353. {
  1354. var instance = fiber.stateNode;
  1355. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  1356. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  1357. if (typeof instance.getChildContext !== 'function') {
  1358. {
  1359. var componentName = getComponentName(type) || 'Unknown';
  1360. if (!warnedAboutMissingGetChildContext[componentName]) {
  1361. warnedAboutMissingGetChildContext[componentName] = true;
  1362. 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);
  1363. }
  1364. }
  1365. return parentContext;
  1366. }
  1367. var childContext;
  1368. startPhaseTimer(fiber, 'getChildContext');
  1369. childContext = instance.getChildContext();
  1370. stopPhaseTimer();
  1371. for (var contextKey in childContext) {
  1372. if (!(contextKey in childContextTypes)) {
  1373. {
  1374. throw Error( (getComponentName(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes." );
  1375. }
  1376. }
  1377. }
  1378. {
  1379. var name = getComponentName(type) || 'Unknown';
  1380. checkPropTypes_1(childContextTypes, childContext, 'child context', name, // In practice, there is one case in which we won't get a stack. It's when
  1381. // somebody calls unstable_renderSubtreeIntoContainer() and we process
  1382. // context from the parent component instance. The stack will be missing
  1383. // because it's outside of the reconciliation, and so the pointer has not
  1384. // been set. This is rare and doesn't matter. We'll also remove that API.
  1385. getCurrentFiberStackInDev);
  1386. }
  1387. return _assign({}, parentContext, {}, childContext);
  1388. }
  1389. }
  1390. function pushContextProvider(workInProgress) {
  1391. {
  1392. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  1393. // If the instance does not exist yet, we will push null at first,
  1394. // and replace it on the stack later when invalidating the context.
  1395. var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
  1396. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  1397. previousContext = contextStackCursor.current;
  1398. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  1399. push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
  1400. return true;
  1401. }
  1402. }
  1403. function invalidateContextProvider(workInProgress, type, didChange) {
  1404. {
  1405. var instance = workInProgress.stateNode;
  1406. if (!instance) {
  1407. {
  1408. throw Error( "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." );
  1409. }
  1410. }
  1411. if (didChange) {
  1412. // Merge parent and own context.
  1413. // Skip this if we're not updating due to sCU.
  1414. // This avoids unnecessarily recomputing memoized values.
  1415. var mergedContext = processChildContext(workInProgress, type, previousContext);
  1416. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  1417. // It is important to unwind the context in the reverse order.
  1418. pop(didPerformWorkStackCursor, workInProgress);
  1419. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  1420. push(contextStackCursor, mergedContext, workInProgress);
  1421. push(didPerformWorkStackCursor, didChange, workInProgress);
  1422. } else {
  1423. pop(didPerformWorkStackCursor, workInProgress);
  1424. push(didPerformWorkStackCursor, didChange, workInProgress);
  1425. }
  1426. }
  1427. }
  1428. function findCurrentUnmaskedContext(fiber) {
  1429. {
  1430. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  1431. // makes sense elsewhere
  1432. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  1433. {
  1434. 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." );
  1435. }
  1436. }
  1437. var node = fiber;
  1438. do {
  1439. switch (node.tag) {
  1440. case HostRoot:
  1441. return node.stateNode.context;
  1442. case ClassComponent:
  1443. {
  1444. var Component = node.type;
  1445. if (isContextProvider(Component)) {
  1446. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  1447. }
  1448. break;
  1449. }
  1450. }
  1451. node = node.return;
  1452. } while (node !== null);
  1453. {
  1454. {
  1455. throw Error( "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." );
  1456. }
  1457. }
  1458. }
  1459. }
  1460. var LegacyRoot = 0;
  1461. var BlockingRoot = 1;
  1462. var ConcurrentRoot = 2;
  1463. var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  1464. var _ReactInternals$Sched = ReactInternals$1.SchedulerTracing,
  1465. __interactionsRef = _ReactInternals$Sched.__interactionsRef,
  1466. __subscriberRef = _ReactInternals$Sched.__subscriberRef,
  1467. unstable_clear = _ReactInternals$Sched.unstable_clear,
  1468. unstable_getCurrent = _ReactInternals$Sched.unstable_getCurrent,
  1469. unstable_getThreadID = _ReactInternals$Sched.unstable_getThreadID,
  1470. unstable_subscribe = _ReactInternals$Sched.unstable_subscribe,
  1471. unstable_trace = _ReactInternals$Sched.unstable_trace,
  1472. unstable_unsubscribe = _ReactInternals$Sched.unstable_unsubscribe,
  1473. unstable_wrap = _ReactInternals$Sched.unstable_wrap;
  1474. var Scheduler_runWithPriority = Scheduler$1.unstable_runWithPriority,
  1475. Scheduler_scheduleCallback = Scheduler$1.unstable_scheduleCallback,
  1476. Scheduler_cancelCallback = Scheduler$1.unstable_cancelCallback,
  1477. Scheduler_shouldYield = Scheduler$1.unstable_shouldYield,
  1478. Scheduler_requestPaint = Scheduler$1.unstable_requestPaint,
  1479. Scheduler_now = Scheduler$1.unstable_now,
  1480. Scheduler_getCurrentPriorityLevel = Scheduler$1.unstable_getCurrentPriorityLevel,
  1481. Scheduler_ImmediatePriority = Scheduler$1.unstable_ImmediatePriority,
  1482. Scheduler_UserBlockingPriority = Scheduler$1.unstable_UserBlockingPriority,
  1483. Scheduler_NormalPriority = Scheduler$1.unstable_NormalPriority,
  1484. Scheduler_LowPriority = Scheduler$1.unstable_LowPriority,
  1485. Scheduler_IdlePriority = Scheduler$1.unstable_IdlePriority;
  1486. {
  1487. // Provide explicit error message when production+profiling bundle of e.g.
  1488. // react-dom is used with production (non-profiling) bundle of
  1489. // scheduler/tracing
  1490. if (!(__interactionsRef != null && __interactionsRef.current != null)) {
  1491. {
  1492. 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" );
  1493. }
  1494. }
  1495. }
  1496. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  1497. // ascending numbers so we can compare them like numbers. They start at 90 to
  1498. // avoid clashing with Scheduler's priorities.
  1499. var ImmediatePriority = 99;
  1500. var UserBlockingPriority = 98;
  1501. var NormalPriority = 97;
  1502. var LowPriority = 96;
  1503. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  1504. var NoPriority = 90;
  1505. var shouldYield = Scheduler_shouldYield;
  1506. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  1507. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function () {};
  1508. var syncQueue = null;
  1509. var immediateQueueCallbackNode = null;
  1510. var isFlushingSyncQueue = false;
  1511. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  1512. // This will be the case for modern browsers that support `performance.now`. In
  1513. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  1514. // timestamp. In that case, subtract the module initialization time to simulate
  1515. // the behavior of performance.now and keep our times small enough to fit
  1516. // within 32 bits.
  1517. // TODO: Consider lifting this into Scheduler.
  1518. var now = initialTimeMs < 10000 ? Scheduler_now : function () {
  1519. return Scheduler_now() - initialTimeMs;
  1520. };
  1521. function getCurrentPriorityLevel() {
  1522. switch (Scheduler_getCurrentPriorityLevel()) {
  1523. case Scheduler_ImmediatePriority:
  1524. return ImmediatePriority;
  1525. case Scheduler_UserBlockingPriority:
  1526. return UserBlockingPriority;
  1527. case Scheduler_NormalPriority:
  1528. return NormalPriority;
  1529. case Scheduler_LowPriority:
  1530. return LowPriority;
  1531. case Scheduler_IdlePriority:
  1532. return IdlePriority;
  1533. default:
  1534. {
  1535. {
  1536. throw Error( "Unknown priority level." );
  1537. }
  1538. }
  1539. }
  1540. }
  1541. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  1542. switch (reactPriorityLevel) {
  1543. case ImmediatePriority:
  1544. return Scheduler_ImmediatePriority;
  1545. case UserBlockingPriority:
  1546. return Scheduler_UserBlockingPriority;
  1547. case NormalPriority:
  1548. return Scheduler_NormalPriority;
  1549. case LowPriority:
  1550. return Scheduler_LowPriority;
  1551. case IdlePriority:
  1552. return Scheduler_IdlePriority;
  1553. default:
  1554. {
  1555. {
  1556. throw Error( "Unknown priority level." );
  1557. }
  1558. }
  1559. }
  1560. }
  1561. function runWithPriority(reactPriorityLevel, fn) {
  1562. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  1563. return Scheduler_runWithPriority(priorityLevel, fn);
  1564. }
  1565. function scheduleCallback(reactPriorityLevel, callback, options) {
  1566. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  1567. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  1568. }
  1569. function scheduleSyncCallback(callback) {
  1570. // Push this callback into an internal queue. We'll flush these either in
  1571. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  1572. if (syncQueue === null) {
  1573. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  1574. immediateQueueCallbackNode = Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueueImpl);
  1575. } else {
  1576. // Push onto existing queue. Don't need to schedule a callback because
  1577. // we already scheduled one when we created the queue.
  1578. syncQueue.push(callback);
  1579. }
  1580. return fakeCallbackNode;
  1581. }
  1582. function cancelCallback(callbackNode) {
  1583. if (callbackNode !== fakeCallbackNode) {
  1584. Scheduler_cancelCallback(callbackNode);
  1585. }
  1586. }
  1587. function flushSyncCallbackQueue() {
  1588. if (immediateQueueCallbackNode !== null) {
  1589. var node = immediateQueueCallbackNode;
  1590. immediateQueueCallbackNode = null;
  1591. Scheduler_cancelCallback(node);
  1592. }
  1593. flushSyncCallbackQueueImpl();
  1594. }
  1595. function flushSyncCallbackQueueImpl() {
  1596. if (!isFlushingSyncQueue && syncQueue !== null) {
  1597. // Prevent re-entrancy.
  1598. isFlushingSyncQueue = true;
  1599. var i = 0;
  1600. try {
  1601. var _isSync = true;
  1602. var queue = syncQueue;
  1603. runWithPriority(ImmediatePriority, function () {
  1604. for (; i < queue.length; i++) {
  1605. var callback = queue[i];
  1606. do {
  1607. callback = callback(_isSync);
  1608. } while (callback !== null);
  1609. }
  1610. });
  1611. syncQueue = null;
  1612. } catch (error) {
  1613. // If something throws, leave the remaining callbacks on the queue.
  1614. if (syncQueue !== null) {
  1615. syncQueue = syncQueue.slice(i + 1);
  1616. } // Resume flushing in the next tick
  1617. Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueue);
  1618. throw error;
  1619. } finally {
  1620. isFlushingSyncQueue = false;
  1621. }
  1622. }
  1623. }
  1624. var NoMode = 0;
  1625. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  1626. // tag instead
  1627. var BlockingMode = 2;
  1628. var ConcurrentMode = 4;
  1629. var ProfileMode = 8;
  1630. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  1631. // Math.pow(2, 30) - 1
  1632. // 0b111111111111111111111111111111
  1633. var MAX_SIGNED_31_BIT_INT = 1073741823;
  1634. var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
  1635. // Never work can be committed in an inconsistent state without tearing the UI.
  1636. // The main example is offscreen content, like a hidden subtree. So one possible
  1637. // name is Offscreen. However, it also includes dehydrated Suspense boundaries,
  1638. // which are inconsistent in the sense that they haven't finished yet, but
  1639. // aren't visibly inconsistent because the server rendered HTML matches what the
  1640. // hydrated tree would look like.
  1641. var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
  1642. // order to be consistent.
  1643. var Idle = 2; // Continuous Hydration is slightly higher than Idle and is used to increase
  1644. var Sync = MAX_SIGNED_31_BIT_INT;
  1645. var Batched = Sync - 1;
  1646. var UNIT_SIZE = 10;
  1647. var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
  1648. function msToExpirationTime(ms) {
  1649. // Always subtract from the offset so that we don't clash with the magic number for NoWork.
  1650. return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
  1651. }
  1652. function expirationTimeToMs(expirationTime) {
  1653. return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
  1654. }
  1655. function ceiling(num, precision) {
  1656. return ((num / precision | 0) + 1) * precision;
  1657. }
  1658. function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
  1659. return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
  1660. } // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
  1661. // the names to reflect.
  1662. var LOW_PRIORITY_EXPIRATION = 5000;
  1663. var LOW_PRIORITY_BATCH_SIZE = 250;
  1664. function computeAsyncExpiration(currentTime) {
  1665. return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
  1666. }
  1667. function computeSuspenseExpiration(currentTime, timeoutMs) {
  1668. // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
  1669. return computeExpirationBucket(currentTime, timeoutMs, LOW_PRIORITY_BATCH_SIZE);
  1670. } // We intentionally set a higher expiration time for interactive updates in
  1671. // dev than in production.
  1672. //
  1673. // If the main thread is being blocked so long that you hit the expiration,
  1674. // it's a problem that could be solved with better scheduling.
  1675. //
  1676. // People will be more likely to notice this and fix it with the long
  1677. // expiration time in development.
  1678. //
  1679. // In production we opt for better UX at the risk of masking scheduling
  1680. // problems, by expiring fast.
  1681. var HIGH_PRIORITY_EXPIRATION = 500 ;
  1682. var HIGH_PRIORITY_BATCH_SIZE = 100;
  1683. function computeInteractiveExpiration(currentTime) {
  1684. return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
  1685. }
  1686. function inferPriorityFromExpirationTime(currentTime, expirationTime) {
  1687. if (expirationTime === Sync) {
  1688. return ImmediatePriority;
  1689. }
  1690. if (expirationTime === Never || expirationTime === Idle) {
  1691. return IdlePriority;
  1692. }
  1693. var msUntil = expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
  1694. if (msUntil <= 0) {
  1695. return ImmediatePriority;
  1696. }
  1697. if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
  1698. return UserBlockingPriority;
  1699. }
  1700. if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
  1701. return NormalPriority;
  1702. } // TODO: Handle LowPriority
  1703. // Assume anything lower has idle priority
  1704. return IdlePriority;
  1705. }
  1706. /**
  1707. * inlined Object.is polyfill to avoid requiring consumers ship their own
  1708. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  1709. */
  1710. function is(x, y) {
  1711. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  1712. ;
  1713. }
  1714. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  1715. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1716. /**
  1717. * Performs equality by iterating through keys on an object and returning false
  1718. * when any key has values which are not strictly equal between the arguments.
  1719. * Returns true when the values of all keys are strictly equal.
  1720. */
  1721. function shallowEqual(objA, objB) {
  1722. if (objectIs(objA, objB)) {
  1723. return true;
  1724. }
  1725. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  1726. return false;
  1727. }
  1728. var keysA = Object.keys(objA);
  1729. var keysB = Object.keys(objB);
  1730. if (keysA.length !== keysB.length) {
  1731. return false;
  1732. } // Test for A's keys different from B.
  1733. for (var i = 0; i < keysA.length; i++) {
  1734. if (!hasOwnProperty.call(objB, keysA[i]) || !objectIs(objA[keysA[i]], objB[keysA[i]])) {
  1735. return false;
  1736. }
  1737. }
  1738. return true;
  1739. }
  1740. var ReactStrictModeWarnings = {
  1741. recordUnsafeLifecycleWarnings: function (fiber, instance) {},
  1742. flushPendingUnsafeLifecycleWarnings: function () {},
  1743. recordLegacyContextWarning: function (fiber, instance) {},
  1744. flushLegacyContextWarning: function () {},
  1745. discardPendingWarnings: function () {}
  1746. };
  1747. {
  1748. var findStrictRoot = function (fiber) {
  1749. var maybeStrictRoot = null;
  1750. var node = fiber;
  1751. while (node !== null) {
  1752. if (node.mode & StrictMode) {
  1753. maybeStrictRoot = node;
  1754. }
  1755. node = node.return;
  1756. }
  1757. return maybeStrictRoot;
  1758. };
  1759. var setToSortedString = function (set) {
  1760. var array = [];
  1761. set.forEach(function (value) {
  1762. array.push(value);
  1763. });
  1764. return array.sort().join(', ');
  1765. };
  1766. var pendingComponentWillMountWarnings = [];
  1767. var pendingUNSAFE_ComponentWillMountWarnings = [];
  1768. var pendingComponentWillReceivePropsWarnings = [];
  1769. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  1770. var pendingComponentWillUpdateWarnings = [];
  1771. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  1772. var didWarnAboutUnsafeLifecycles = new Set();
  1773. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
  1774. // Dedup strategy: Warn once per component.
  1775. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  1776. return;
  1777. }
  1778. if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
  1779. instance.componentWillMount.__suppressDeprecationWarning !== true) {
  1780. pendingComponentWillMountWarnings.push(fiber);
  1781. }
  1782. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillMount === 'function') {
  1783. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  1784. }
  1785. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  1786. pendingComponentWillReceivePropsWarnings.push(fiber);
  1787. }
  1788. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  1789. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  1790. }
  1791. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  1792. pendingComponentWillUpdateWarnings.push(fiber);
  1793. }
  1794. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
  1795. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  1796. }
  1797. };
  1798. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
  1799. // We do an initial pass to gather component names
  1800. var componentWillMountUniqueNames = new Set();
  1801. if (pendingComponentWillMountWarnings.length > 0) {
  1802. pendingComponentWillMountWarnings.forEach(function (fiber) {
  1803. componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1804. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1805. });
  1806. pendingComponentWillMountWarnings = [];
  1807. }
  1808. var UNSAFE_componentWillMountUniqueNames = new Set();
  1809. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  1810. pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
  1811. UNSAFE_componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1812. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1813. });
  1814. pendingUNSAFE_ComponentWillMountWarnings = [];
  1815. }
  1816. var componentWillReceivePropsUniqueNames = new Set();
  1817. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  1818. pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
  1819. componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1820. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1821. });
  1822. pendingComponentWillReceivePropsWarnings = [];
  1823. }
  1824. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  1825. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  1826. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
  1827. UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1828. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1829. });
  1830. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  1831. }
  1832. var componentWillUpdateUniqueNames = new Set();
  1833. if (pendingComponentWillUpdateWarnings.length > 0) {
  1834. pendingComponentWillUpdateWarnings.forEach(function (fiber) {
  1835. componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1836. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1837. });
  1838. pendingComponentWillUpdateWarnings = [];
  1839. }
  1840. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  1841. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  1842. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
  1843. UNSAFE_componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1844. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1845. });
  1846. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  1847. } // Finally, we flush all the warnings
  1848. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  1849. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  1850. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  1851. 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);
  1852. }
  1853. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  1854. var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
  1855. 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);
  1856. }
  1857. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  1858. var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
  1859. 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);
  1860. }
  1861. if (componentWillMountUniqueNames.size > 0) {
  1862. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  1863. 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);
  1864. }
  1865. if (componentWillReceivePropsUniqueNames.size > 0) {
  1866. var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
  1867. 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);
  1868. }
  1869. if (componentWillUpdateUniqueNames.size > 0) {
  1870. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  1871. 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);
  1872. }
  1873. };
  1874. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  1875. var didWarnAboutLegacyContext = new Set();
  1876. ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
  1877. var strictRoot = findStrictRoot(fiber);
  1878. if (strictRoot === null) {
  1879. 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.');
  1880. return;
  1881. } // Dedup strategy: Warn once per component.
  1882. if (didWarnAboutLegacyContext.has(fiber.type)) {
  1883. return;
  1884. }
  1885. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  1886. if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
  1887. if (warningsForRoot === undefined) {
  1888. warningsForRoot = [];
  1889. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  1890. }
  1891. warningsForRoot.push(fiber);
  1892. }
  1893. };
  1894. ReactStrictModeWarnings.flushLegacyContextWarning = function () {
  1895. pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
  1896. if (fiberArray.length === 0) {
  1897. return;
  1898. }
  1899. var firstFiber = fiberArray[0];
  1900. var uniqueNames = new Set();
  1901. fiberArray.forEach(function (fiber) {
  1902. uniqueNames.add(getComponentName(fiber.type) || 'Component');
  1903. didWarnAboutLegacyContext.add(fiber.type);
  1904. });
  1905. var sortedNames = setToSortedString(uniqueNames);
  1906. var firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
  1907. 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);
  1908. });
  1909. };
  1910. ReactStrictModeWarnings.discardPendingWarnings = function () {
  1911. pendingComponentWillMountWarnings = [];
  1912. pendingUNSAFE_ComponentWillMountWarnings = [];
  1913. pendingComponentWillReceivePropsWarnings = [];
  1914. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  1915. pendingComponentWillUpdateWarnings = [];
  1916. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  1917. pendingLegacyContextWarning = new Map();
  1918. };
  1919. }
  1920. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  1921. var failedBoundaries = null;
  1922. var setRefreshHandler = function (handler) {
  1923. {
  1924. resolveFamily = handler;
  1925. }
  1926. };
  1927. function resolveFunctionForHotReloading(type) {
  1928. {
  1929. if (resolveFamily === null) {
  1930. // Hot reloading is disabled.
  1931. return type;
  1932. }
  1933. var family = resolveFamily(type);
  1934. if (family === undefined) {
  1935. return type;
  1936. } // Use the latest known implementation.
  1937. return family.current;
  1938. }
  1939. }
  1940. function resolveClassForHotReloading(type) {
  1941. // No implementation differences.
  1942. return resolveFunctionForHotReloading(type);
  1943. }
  1944. function resolveForwardRefForHotReloading(type) {
  1945. {
  1946. if (resolveFamily === null) {
  1947. // Hot reloading is disabled.
  1948. return type;
  1949. }
  1950. var family = resolveFamily(type);
  1951. if (family === undefined) {
  1952. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  1953. if (type !== null && type !== undefined && typeof type.render === 'function') {
  1954. // ForwardRef is special because its resolved .type is an object,
  1955. // but it's possible that we only have its inner render function in the map.
  1956. // If that inner render function is different, we'll build a new forwardRef type.
  1957. var currentRender = resolveFunctionForHotReloading(type.render);
  1958. if (type.render !== currentRender) {
  1959. var syntheticType = {
  1960. $$typeof: REACT_FORWARD_REF_TYPE,
  1961. render: currentRender
  1962. };
  1963. if (type.displayName !== undefined) {
  1964. syntheticType.displayName = type.displayName;
  1965. }
  1966. return syntheticType;
  1967. }
  1968. }
  1969. return type;
  1970. } // Use the latest known implementation.
  1971. return family.current;
  1972. }
  1973. }
  1974. function isCompatibleFamilyForHotReloading(fiber, element) {
  1975. {
  1976. if (resolveFamily === null) {
  1977. // Hot reloading is disabled.
  1978. return false;
  1979. }
  1980. var prevType = fiber.elementType;
  1981. var nextType = element.type; // If we got here, we know types aren't === equal.
  1982. var needsCompareFamilies = false;
  1983. var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
  1984. switch (fiber.tag) {
  1985. case ClassComponent:
  1986. {
  1987. if (typeof nextType === 'function') {
  1988. needsCompareFamilies = true;
  1989. }
  1990. break;
  1991. }
  1992. case FunctionComponent:
  1993. {
  1994. if (typeof nextType === 'function') {
  1995. needsCompareFamilies = true;
  1996. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  1997. // We don't know the inner type yet.
  1998. // We're going to assume that the lazy inner type is stable,
  1999. // and so it is sufficient to avoid reconciling it away.
  2000. // We're not going to unwrap or actually use the new lazy type.
  2001. needsCompareFamilies = true;
  2002. }
  2003. break;
  2004. }
  2005. case ForwardRef:
  2006. {
  2007. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  2008. needsCompareFamilies = true;
  2009. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  2010. needsCompareFamilies = true;
  2011. }
  2012. break;
  2013. }
  2014. case MemoComponent:
  2015. case SimpleMemoComponent:
  2016. {
  2017. if ($$typeofNextType === REACT_MEMO_TYPE) {
  2018. // TODO: if it was but can no longer be simple,
  2019. // we shouldn't set this.
  2020. needsCompareFamilies = true;
  2021. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  2022. needsCompareFamilies = true;
  2023. }
  2024. break;
  2025. }
  2026. default:
  2027. return false;
  2028. } // Check if both types have a family and it's the same one.
  2029. if (needsCompareFamilies) {
  2030. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  2031. // This means both of them need to be registered to preserve state.
  2032. // If we unwrapped and compared the inner types for wrappers instead,
  2033. // then we would risk falsely saying two separate memo(Foo)
  2034. // calls are equivalent because they wrap the same Foo function.
  2035. var prevFamily = resolveFamily(prevType);
  2036. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  2037. return true;
  2038. }
  2039. }
  2040. return false;
  2041. }
  2042. }
  2043. function markFailedErrorBoundaryForHotReloading(fiber) {
  2044. {
  2045. if (resolveFamily === null) {
  2046. // Hot reloading is disabled.
  2047. return;
  2048. }
  2049. if (typeof WeakSet !== 'function') {
  2050. return;
  2051. }
  2052. if (failedBoundaries === null) {
  2053. failedBoundaries = new WeakSet();
  2054. }
  2055. failedBoundaries.add(fiber);
  2056. }
  2057. }
  2058. var scheduleRefresh = function (root, update) {
  2059. {
  2060. if (resolveFamily === null) {
  2061. // Hot reloading is disabled.
  2062. return;
  2063. }
  2064. var staleFamilies = update.staleFamilies,
  2065. updatedFamilies = update.updatedFamilies;
  2066. flushPassiveEffects();
  2067. flushSync(function () {
  2068. scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
  2069. });
  2070. }
  2071. };
  2072. var scheduleRoot = function (root, element) {
  2073. {
  2074. if (root.context !== emptyContextObject) {
  2075. // Super edge case: root has a legacy _renderSubtree context
  2076. // but we don't know the parentComponent so we can't pass it.
  2077. // Just ignore. We'll delete this with _renderSubtree code path later.
  2078. return;
  2079. }
  2080. flushPassiveEffects();
  2081. syncUpdates(function () {
  2082. updateContainer(element, root, null, null);
  2083. });
  2084. }
  2085. };
  2086. function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
  2087. {
  2088. var alternate = fiber.alternate,
  2089. child = fiber.child,
  2090. sibling = fiber.sibling,
  2091. tag = fiber.tag,
  2092. type = fiber.type;
  2093. var candidateType = null;
  2094. switch (tag) {
  2095. case FunctionComponent:
  2096. case SimpleMemoComponent:
  2097. case ClassComponent:
  2098. candidateType = type;
  2099. break;
  2100. case ForwardRef:
  2101. candidateType = type.render;
  2102. break;
  2103. }
  2104. if (resolveFamily === null) {
  2105. throw new Error('Expected resolveFamily to be set during hot reload.');
  2106. }
  2107. var needsRender = false;
  2108. var needsRemount = false;
  2109. if (candidateType !== null) {
  2110. var family = resolveFamily(candidateType);
  2111. if (family !== undefined) {
  2112. if (staleFamilies.has(family)) {
  2113. needsRemount = true;
  2114. } else if (updatedFamilies.has(family)) {
  2115. if (tag === ClassComponent) {
  2116. needsRemount = true;
  2117. } else {
  2118. needsRender = true;
  2119. }
  2120. }
  2121. }
  2122. }
  2123. if (failedBoundaries !== null) {
  2124. if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
  2125. needsRemount = true;
  2126. }
  2127. }
  2128. if (needsRemount) {
  2129. fiber._debugNeedsRemount = true;
  2130. }
  2131. if (needsRemount || needsRender) {
  2132. scheduleWork(fiber, Sync);
  2133. }
  2134. if (child !== null && !needsRemount) {
  2135. scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
  2136. }
  2137. if (sibling !== null) {
  2138. scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
  2139. }
  2140. }
  2141. }
  2142. var findHostInstancesForRefresh = function (root, families) {
  2143. {
  2144. var hostInstances = new Set();
  2145. var types = new Set(families.map(function (family) {
  2146. return family.current;
  2147. }));
  2148. findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
  2149. return hostInstances;
  2150. }
  2151. };
  2152. function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
  2153. {
  2154. var child = fiber.child,
  2155. sibling = fiber.sibling,
  2156. tag = fiber.tag,
  2157. type = fiber.type;
  2158. var candidateType = null;
  2159. switch (tag) {
  2160. case FunctionComponent:
  2161. case SimpleMemoComponent:
  2162. case ClassComponent:
  2163. candidateType = type;
  2164. break;
  2165. case ForwardRef:
  2166. candidateType = type.render;
  2167. break;
  2168. }
  2169. var didMatch = false;
  2170. if (candidateType !== null) {
  2171. if (types.has(candidateType)) {
  2172. didMatch = true;
  2173. }
  2174. }
  2175. if (didMatch) {
  2176. // We have a match. This only drills down to the closest host components.
  2177. // There's no need to search deeper because for the purpose of giving
  2178. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  2179. findHostInstancesForFiberShallowly(fiber, hostInstances);
  2180. } else {
  2181. // If there's no match, maybe there will be one further down in the child tree.
  2182. if (child !== null) {
  2183. findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
  2184. }
  2185. }
  2186. if (sibling !== null) {
  2187. findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
  2188. }
  2189. }
  2190. }
  2191. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  2192. {
  2193. var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
  2194. if (foundHostInstances) {
  2195. return;
  2196. } // If we didn't find any host children, fallback to closest host parent.
  2197. var node = fiber;
  2198. while (true) {
  2199. switch (node.tag) {
  2200. case HostComponent:
  2201. hostInstances.add(node.stateNode);
  2202. return;
  2203. case HostPortal:
  2204. hostInstances.add(node.stateNode.containerInfo);
  2205. return;
  2206. case HostRoot:
  2207. hostInstances.add(node.stateNode.containerInfo);
  2208. return;
  2209. }
  2210. if (node.return === null) {
  2211. throw new Error('Expected to reach root first.');
  2212. }
  2213. node = node.return;
  2214. }
  2215. }
  2216. }
  2217. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  2218. {
  2219. var node = fiber;
  2220. var foundHostInstances = false;
  2221. while (true) {
  2222. if (node.tag === HostComponent) {
  2223. // We got a match.
  2224. foundHostInstances = true;
  2225. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  2226. } else if (node.child !== null) {
  2227. node.child.return = node;
  2228. node = node.child;
  2229. continue;
  2230. }
  2231. if (node === fiber) {
  2232. return foundHostInstances;
  2233. }
  2234. while (node.sibling === null) {
  2235. if (node.return === null || node.return === fiber) {
  2236. return foundHostInstances;
  2237. }
  2238. node = node.return;
  2239. }
  2240. node.sibling.return = node.return;
  2241. node = node.sibling;
  2242. }
  2243. }
  2244. return false;
  2245. }
  2246. function resolveDefaultProps(Component, baseProps) {
  2247. if (Component && Component.defaultProps) {
  2248. // Resolve default props. Taken from ReactElement
  2249. var props = _assign({}, baseProps);
  2250. var defaultProps = Component.defaultProps;
  2251. for (var propName in defaultProps) {
  2252. if (props[propName] === undefined) {
  2253. props[propName] = defaultProps[propName];
  2254. }
  2255. }
  2256. return props;
  2257. }
  2258. return baseProps;
  2259. }
  2260. function readLazyComponentType(lazyComponent) {
  2261. initializeLazyComponentType(lazyComponent);
  2262. if (lazyComponent._status !== Resolved) {
  2263. throw lazyComponent._result;
  2264. }
  2265. return lazyComponent._result;
  2266. }
  2267. var valueCursor = createCursor(null);
  2268. var rendererSigil;
  2269. {
  2270. // Use this to detect multiple renderers using the same context
  2271. rendererSigil = {};
  2272. }
  2273. var currentlyRenderingFiber = null;
  2274. var lastContextDependency = null;
  2275. var lastContextWithAllBitsObserved = null;
  2276. var isDisallowedContextReadInDEV = false;
  2277. function resetContextDependencies() {
  2278. // This is called right before React yields execution, to ensure `readContext`
  2279. // cannot be called outside the render phase.
  2280. currentlyRenderingFiber = null;
  2281. lastContextDependency = null;
  2282. lastContextWithAllBitsObserved = null;
  2283. {
  2284. isDisallowedContextReadInDEV = false;
  2285. }
  2286. }
  2287. function enterDisallowedContextReadInDEV() {
  2288. {
  2289. isDisallowedContextReadInDEV = true;
  2290. }
  2291. }
  2292. function exitDisallowedContextReadInDEV() {
  2293. {
  2294. isDisallowedContextReadInDEV = false;
  2295. }
  2296. }
  2297. function pushProvider(providerFiber, nextValue) {
  2298. var context = providerFiber.type._context;
  2299. {
  2300. push(valueCursor, context._currentValue2, providerFiber);
  2301. context._currentValue2 = nextValue;
  2302. {
  2303. if (context._currentRenderer2 !== undefined && context._currentRenderer2 !== null && context._currentRenderer2 !== rendererSigil) {
  2304. error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
  2305. }
  2306. context._currentRenderer2 = rendererSigil;
  2307. }
  2308. }
  2309. }
  2310. function popProvider(providerFiber) {
  2311. var currentValue = valueCursor.current;
  2312. pop(valueCursor, providerFiber);
  2313. var context = providerFiber.type._context;
  2314. {
  2315. context._currentValue2 = currentValue;
  2316. }
  2317. }
  2318. function calculateChangedBits(context, newValue, oldValue) {
  2319. if (objectIs(oldValue, newValue)) {
  2320. // No change
  2321. return 0;
  2322. } else {
  2323. var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
  2324. {
  2325. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  2326. error('calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits);
  2327. }
  2328. }
  2329. return changedBits | 0;
  2330. }
  2331. }
  2332. function scheduleWorkOnParentPath(parent, renderExpirationTime) {
  2333. // Update the child expiration time of all the ancestors, including
  2334. // the alternates.
  2335. var node = parent;
  2336. while (node !== null) {
  2337. var alternate = node.alternate;
  2338. if (node.childExpirationTime < renderExpirationTime) {
  2339. node.childExpirationTime = renderExpirationTime;
  2340. if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
  2341. alternate.childExpirationTime = renderExpirationTime;
  2342. }
  2343. } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
  2344. alternate.childExpirationTime = renderExpirationTime;
  2345. } else {
  2346. // Neither alternate was updated, which means the rest of the
  2347. // ancestor path already has sufficient priority.
  2348. break;
  2349. }
  2350. node = node.return;
  2351. }
  2352. }
  2353. function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
  2354. var fiber = workInProgress.child;
  2355. if (fiber !== null) {
  2356. // Set the return pointer of the child to the work-in-progress fiber.
  2357. fiber.return = workInProgress;
  2358. }
  2359. while (fiber !== null) {
  2360. var nextFiber = void 0; // Visit this fiber.
  2361. var list = fiber.dependencies;
  2362. if (list !== null) {
  2363. nextFiber = fiber.child;
  2364. var dependency = list.firstContext;
  2365. while (dependency !== null) {
  2366. // Check if the context matches.
  2367. if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
  2368. // Match! Schedule an update on this fiber.
  2369. if (fiber.tag === ClassComponent) {
  2370. // Schedule a force update on the work-in-progress.
  2371. var update = createUpdate(renderExpirationTime, null);
  2372. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  2373. // update to the current fiber, too, which means it will persist even if
  2374. // this render is thrown away. Since it's a race condition, not sure it's
  2375. // worth fixing.
  2376. enqueueUpdate(fiber, update);
  2377. }
  2378. if (fiber.expirationTime < renderExpirationTime) {
  2379. fiber.expirationTime = renderExpirationTime;
  2380. }
  2381. var alternate = fiber.alternate;
  2382. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  2383. alternate.expirationTime = renderExpirationTime;
  2384. }
  2385. scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
  2386. if (list.expirationTime < renderExpirationTime) {
  2387. list.expirationTime = renderExpirationTime;
  2388. } // Since we already found a match, we can stop traversing the
  2389. // dependency list.
  2390. break;
  2391. }
  2392. dependency = dependency.next;
  2393. }
  2394. } else if (fiber.tag === ContextProvider) {
  2395. // Don't scan deeper if this is a matching provider
  2396. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  2397. } else {
  2398. // Traverse down.
  2399. nextFiber = fiber.child;
  2400. }
  2401. if (nextFiber !== null) {
  2402. // Set the return pointer of the child to the work-in-progress fiber.
  2403. nextFiber.return = fiber;
  2404. } else {
  2405. // No child. Traverse to next sibling.
  2406. nextFiber = fiber;
  2407. while (nextFiber !== null) {
  2408. if (nextFiber === workInProgress) {
  2409. // We're back to the root of this subtree. Exit.
  2410. nextFiber = null;
  2411. break;
  2412. }
  2413. var sibling = nextFiber.sibling;
  2414. if (sibling !== null) {
  2415. // Set the return pointer of the sibling to the work-in-progress fiber.
  2416. sibling.return = nextFiber.return;
  2417. nextFiber = sibling;
  2418. break;
  2419. } // No more siblings. Traverse up.
  2420. nextFiber = nextFiber.return;
  2421. }
  2422. }
  2423. fiber = nextFiber;
  2424. }
  2425. }
  2426. function prepareToReadContext(workInProgress, renderExpirationTime) {
  2427. currentlyRenderingFiber = workInProgress;
  2428. lastContextDependency = null;
  2429. lastContextWithAllBitsObserved = null;
  2430. var dependencies = workInProgress.dependencies;
  2431. if (dependencies !== null) {
  2432. var firstContext = dependencies.firstContext;
  2433. if (firstContext !== null) {
  2434. if (dependencies.expirationTime >= renderExpirationTime) {
  2435. // Context list has a pending update. Mark that this fiber performed work.
  2436. markWorkInProgressReceivedUpdate();
  2437. } // Reset the work-in-progress list
  2438. dependencies.firstContext = null;
  2439. }
  2440. }
  2441. }
  2442. function readContext(context, observedBits) {
  2443. {
  2444. // This warning would fire if you read context inside a Hook like useMemo.
  2445. // Unlike the class check below, it's not enforced in production for perf.
  2446. if (isDisallowedContextReadInDEV) {
  2447. 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().');
  2448. }
  2449. }
  2450. if (lastContextWithAllBitsObserved === context) ; else if (observedBits === false || observedBits === 0) ; else {
  2451. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  2452. if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
  2453. // Observe all updates.
  2454. lastContextWithAllBitsObserved = context;
  2455. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  2456. } else {
  2457. resolvedObservedBits = observedBits;
  2458. }
  2459. var contextItem = {
  2460. context: context,
  2461. observedBits: resolvedObservedBits,
  2462. next: null
  2463. };
  2464. if (lastContextDependency === null) {
  2465. if (!(currentlyRenderingFiber !== null)) {
  2466. {
  2467. 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()." );
  2468. }
  2469. } // This is the first dependency for this component. Create a new list.
  2470. lastContextDependency = contextItem;
  2471. currentlyRenderingFiber.dependencies = {
  2472. expirationTime: NoWork,
  2473. firstContext: contextItem,
  2474. responders: null
  2475. };
  2476. } else {
  2477. // Append a new context item.
  2478. lastContextDependency = lastContextDependency.next = contextItem;
  2479. }
  2480. }
  2481. return context._currentValue2;
  2482. }
  2483. var UpdateState = 0;
  2484. var ReplaceState = 1;
  2485. var ForceUpdate = 2;
  2486. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  2487. // It should only be read right after calling `processUpdateQueue`, via
  2488. // `checkHasForceUpdateAfterProcessing`.
  2489. var hasForceUpdate = false;
  2490. var didWarnUpdateInsideUpdate;
  2491. var currentlyProcessingQueue;
  2492. {
  2493. didWarnUpdateInsideUpdate = false;
  2494. currentlyProcessingQueue = null;
  2495. }
  2496. function initializeUpdateQueue(fiber) {
  2497. var queue = {
  2498. baseState: fiber.memoizedState,
  2499. baseQueue: null,
  2500. shared: {
  2501. pending: null
  2502. },
  2503. effects: null
  2504. };
  2505. fiber.updateQueue = queue;
  2506. }
  2507. function cloneUpdateQueue(current, workInProgress) {
  2508. // Clone the update queue from current. Unless it's already a clone.
  2509. var queue = workInProgress.updateQueue;
  2510. var currentQueue = current.updateQueue;
  2511. if (queue === currentQueue) {
  2512. var clone = {
  2513. baseState: currentQueue.baseState,
  2514. baseQueue: currentQueue.baseQueue,
  2515. shared: currentQueue.shared,
  2516. effects: currentQueue.effects
  2517. };
  2518. workInProgress.updateQueue = clone;
  2519. }
  2520. }
  2521. function createUpdate(expirationTime, suspenseConfig) {
  2522. var update = {
  2523. expirationTime: expirationTime,
  2524. suspenseConfig: suspenseConfig,
  2525. tag: UpdateState,
  2526. payload: null,
  2527. callback: null,
  2528. next: null
  2529. };
  2530. update.next = update;
  2531. {
  2532. update.priority = getCurrentPriorityLevel();
  2533. }
  2534. return update;
  2535. }
  2536. function enqueueUpdate(fiber, update) {
  2537. var updateQueue = fiber.updateQueue;
  2538. if (updateQueue === null) {
  2539. // Only occurs if the fiber has been unmounted.
  2540. return;
  2541. }
  2542. var sharedQueue = updateQueue.shared;
  2543. var pending = sharedQueue.pending;
  2544. if (pending === null) {
  2545. // This is the first update. Create a circular list.
  2546. update.next = update;
  2547. } else {
  2548. update.next = pending.next;
  2549. pending.next = update;
  2550. }
  2551. sharedQueue.pending = update;
  2552. {
  2553. if (currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate) {
  2554. 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.');
  2555. didWarnUpdateInsideUpdate = true;
  2556. }
  2557. }
  2558. }
  2559. function enqueueCapturedUpdate(workInProgress, update) {
  2560. var current = workInProgress.alternate;
  2561. if (current !== null) {
  2562. // Ensure the work-in-progress queue is a clone
  2563. cloneUpdateQueue(current, workInProgress);
  2564. } // Captured updates go only on the work-in-progress queue.
  2565. var queue = workInProgress.updateQueue; // Append the update to the end of the list.
  2566. var last = queue.baseQueue;
  2567. if (last === null) {
  2568. queue.baseQueue = update.next = update;
  2569. update.next = update;
  2570. } else {
  2571. update.next = last.next;
  2572. last.next = update;
  2573. }
  2574. }
  2575. function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
  2576. switch (update.tag) {
  2577. case ReplaceState:
  2578. {
  2579. var payload = update.payload;
  2580. if (typeof payload === 'function') {
  2581. // Updater function
  2582. {
  2583. enterDisallowedContextReadInDEV();
  2584. }
  2585. var nextState = payload.call(instance, prevState, nextProps);
  2586. {
  2587. exitDisallowedContextReadInDEV();
  2588. }
  2589. return nextState;
  2590. } // State object
  2591. return payload;
  2592. }
  2593. case CaptureUpdate:
  2594. {
  2595. workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
  2596. }
  2597. // Intentional fallthrough
  2598. case UpdateState:
  2599. {
  2600. var _payload = update.payload;
  2601. var partialState;
  2602. if (typeof _payload === 'function') {
  2603. // Updater function
  2604. {
  2605. enterDisallowedContextReadInDEV();
  2606. }
  2607. partialState = _payload.call(instance, prevState, nextProps);
  2608. {
  2609. exitDisallowedContextReadInDEV();
  2610. }
  2611. } else {
  2612. // Partial state object
  2613. partialState = _payload;
  2614. }
  2615. if (partialState === null || partialState === undefined) {
  2616. // Null and undefined are treated as no-ops.
  2617. return prevState;
  2618. } // Merge the partial state and the previous state.
  2619. return _assign({}, prevState, partialState);
  2620. }
  2621. case ForceUpdate:
  2622. {
  2623. hasForceUpdate = true;
  2624. return prevState;
  2625. }
  2626. }
  2627. return prevState;
  2628. }
  2629. function processUpdateQueue(workInProgress, props, instance, renderExpirationTime) {
  2630. // This is always non-null on a ClassComponent or HostRoot
  2631. var queue = workInProgress.updateQueue;
  2632. hasForceUpdate = false;
  2633. {
  2634. currentlyProcessingQueue = queue.shared;
  2635. } // The last rebase update that is NOT part of the base state.
  2636. var baseQueue = queue.baseQueue; // The last pending update that hasn't been processed yet.
  2637. var pendingQueue = queue.shared.pending;
  2638. if (pendingQueue !== null) {
  2639. // We have new updates that haven't been processed yet.
  2640. // We'll add them to the base queue.
  2641. if (baseQueue !== null) {
  2642. // Merge the pending queue and the base queue.
  2643. var baseFirst = baseQueue.next;
  2644. var pendingFirst = pendingQueue.next;
  2645. baseQueue.next = pendingFirst;
  2646. pendingQueue.next = baseFirst;
  2647. }
  2648. baseQueue = pendingQueue;
  2649. queue.shared.pending = null; // TODO: Pass `current` as argument
  2650. var current = workInProgress.alternate;
  2651. if (current !== null) {
  2652. var currentQueue = current.updateQueue;
  2653. if (currentQueue !== null) {
  2654. currentQueue.baseQueue = pendingQueue;
  2655. }
  2656. }
  2657. } // These values may change as we process the queue.
  2658. if (baseQueue !== null) {
  2659. var first = baseQueue.next; // Iterate through the list of updates to compute the result.
  2660. var newState = queue.baseState;
  2661. var newExpirationTime = NoWork;
  2662. var newBaseState = null;
  2663. var newBaseQueueFirst = null;
  2664. var newBaseQueueLast = null;
  2665. if (first !== null) {
  2666. var update = first;
  2667. do {
  2668. var updateExpirationTime = update.expirationTime;
  2669. if (updateExpirationTime < renderExpirationTime) {
  2670. // Priority is insufficient. Skip this update. If this is the first
  2671. // skipped update, the previous update/state is the new base
  2672. // update/state.
  2673. var clone = {
  2674. expirationTime: update.expirationTime,
  2675. suspenseConfig: update.suspenseConfig,
  2676. tag: update.tag,
  2677. payload: update.payload,
  2678. callback: update.callback,
  2679. next: null
  2680. };
  2681. if (newBaseQueueLast === null) {
  2682. newBaseQueueFirst = newBaseQueueLast = clone;
  2683. newBaseState = newState;
  2684. } else {
  2685. newBaseQueueLast = newBaseQueueLast.next = clone;
  2686. } // Update the remaining priority in the queue.
  2687. if (updateExpirationTime > newExpirationTime) {
  2688. newExpirationTime = updateExpirationTime;
  2689. }
  2690. } else {
  2691. // This update does have sufficient priority.
  2692. if (newBaseQueueLast !== null) {
  2693. var _clone = {
  2694. expirationTime: Sync,
  2695. // This update is going to be committed so we never want uncommit it.
  2696. suspenseConfig: update.suspenseConfig,
  2697. tag: update.tag,
  2698. payload: update.payload,
  2699. callback: update.callback,
  2700. next: null
  2701. };
  2702. newBaseQueueLast = newBaseQueueLast.next = _clone;
  2703. } // Mark the event time of this update as relevant to this render pass.
  2704. // TODO: This should ideally use the true event time of this update rather than
  2705. // its priority which is a derived and not reverseable value.
  2706. // TODO: We should skip this update if it was already committed but currently
  2707. // we have no way of detecting the difference between a committed and suspended
  2708. // update here.
  2709. markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process this update.
  2710. newState = getStateFromUpdate(workInProgress, queue, update, newState, props, instance);
  2711. var callback = update.callback;
  2712. if (callback !== null) {
  2713. workInProgress.effectTag |= Callback;
  2714. var effects = queue.effects;
  2715. if (effects === null) {
  2716. queue.effects = [update];
  2717. } else {
  2718. effects.push(update);
  2719. }
  2720. }
  2721. }
  2722. update = update.next;
  2723. if (update === null || update === first) {
  2724. pendingQueue = queue.shared.pending;
  2725. if (pendingQueue === null) {
  2726. break;
  2727. } else {
  2728. // An update was scheduled from inside a reducer. Add the new
  2729. // pending updates to the end of the list and keep processing.
  2730. update = baseQueue.next = pendingQueue.next;
  2731. pendingQueue.next = first;
  2732. queue.baseQueue = baseQueue = pendingQueue;
  2733. queue.shared.pending = null;
  2734. }
  2735. }
  2736. } while (true);
  2737. }
  2738. if (newBaseQueueLast === null) {
  2739. newBaseState = newState;
  2740. } else {
  2741. newBaseQueueLast.next = newBaseQueueFirst;
  2742. }
  2743. queue.baseState = newBaseState;
  2744. queue.baseQueue = newBaseQueueLast; // Set the remaining expiration time to be whatever is remaining in the queue.
  2745. // This should be fine because the only two other things that contribute to
  2746. // expiration time are props and context. We're already in the middle of the
  2747. // begin phase by the time we start processing the queue, so we've already
  2748. // dealt with the props. Context in components that specify
  2749. // shouldComponentUpdate is tricky; but we'll have to account for
  2750. // that regardless.
  2751. markUnprocessedUpdateTime(newExpirationTime);
  2752. workInProgress.expirationTime = newExpirationTime;
  2753. workInProgress.memoizedState = newState;
  2754. }
  2755. {
  2756. currentlyProcessingQueue = null;
  2757. }
  2758. }
  2759. function callCallback(callback, context) {
  2760. if (!(typeof callback === 'function')) {
  2761. {
  2762. throw Error( "Invalid argument passed as callback. Expected a function. Instead received: " + callback );
  2763. }
  2764. }
  2765. callback.call(context);
  2766. }
  2767. function resetHasForceUpdateBeforeProcessing() {
  2768. hasForceUpdate = false;
  2769. }
  2770. function checkHasForceUpdateAfterProcessing() {
  2771. return hasForceUpdate;
  2772. }
  2773. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  2774. // Commit the effects
  2775. var effects = finishedQueue.effects;
  2776. finishedQueue.effects = null;
  2777. if (effects !== null) {
  2778. for (var i = 0; i < effects.length; i++) {
  2779. var effect = effects[i];
  2780. var callback = effect.callback;
  2781. if (callback !== null) {
  2782. effect.callback = null;
  2783. callCallback(callback, instance);
  2784. }
  2785. }
  2786. }
  2787. }
  2788. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  2789. function requestCurrentSuspenseConfig() {
  2790. return ReactCurrentBatchConfig.suspense;
  2791. }
  2792. var fakeInternalInstance = {};
  2793. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  2794. // We'll use it to determine whether we need to initialize legacy refs.
  2795. var emptyRefsObject = new React.Component().refs;
  2796. var didWarnAboutStateAssignmentForComponent;
  2797. var didWarnAboutUninitializedState;
  2798. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  2799. var didWarnAboutLegacyLifecyclesAndDerivedState;
  2800. var didWarnAboutUndefinedDerivedState;
  2801. var warnOnUndefinedDerivedState;
  2802. var warnOnInvalidCallback;
  2803. var didWarnAboutDirectlyAssigningPropsToState;
  2804. var didWarnAboutContextTypeAndContextTypes;
  2805. var didWarnAboutInvalidateContextType;
  2806. {
  2807. didWarnAboutStateAssignmentForComponent = new Set();
  2808. didWarnAboutUninitializedState = new Set();
  2809. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  2810. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  2811. didWarnAboutDirectlyAssigningPropsToState = new Set();
  2812. didWarnAboutUndefinedDerivedState = new Set();
  2813. didWarnAboutContextTypeAndContextTypes = new Set();
  2814. didWarnAboutInvalidateContextType = new Set();
  2815. var didWarnOnInvalidCallback = new Set();
  2816. warnOnInvalidCallback = function (callback, callerName) {
  2817. if (callback === null || typeof callback === 'function') {
  2818. return;
  2819. }
  2820. var key = callerName + "_" + callback;
  2821. if (!didWarnOnInvalidCallback.has(key)) {
  2822. didWarnOnInvalidCallback.add(key);
  2823. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  2824. }
  2825. };
  2826. warnOnUndefinedDerivedState = function (type, partialState) {
  2827. if (partialState === undefined) {
  2828. var componentName = getComponentName(type) || 'Component';
  2829. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  2830. didWarnAboutUndefinedDerivedState.add(componentName);
  2831. error('%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
  2832. }
  2833. }
  2834. }; // This is so gross but it's at least non-critical and can be removed if
  2835. // it causes problems. This is meant to give a nicer error message for
  2836. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  2837. // ...)) which otherwise throws a "_processChildContext is not a function"
  2838. // exception.
  2839. Object.defineProperty(fakeInternalInstance, '_processChildContext', {
  2840. enumerable: false,
  2841. value: function () {
  2842. {
  2843. {
  2844. 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)." );
  2845. }
  2846. }
  2847. }
  2848. });
  2849. Object.freeze(fakeInternalInstance);
  2850. }
  2851. function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
  2852. var prevState = workInProgress.memoizedState;
  2853. var partialState = getDerivedStateFromProps(nextProps, prevState);
  2854. {
  2855. warnOnUndefinedDerivedState(ctor, partialState);
  2856. } // Merge the partial state and the previous state.
  2857. var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
  2858. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  2859. // base state.
  2860. if (workInProgress.expirationTime === NoWork) {
  2861. // Queue is always non-null for classes
  2862. var updateQueue = workInProgress.updateQueue;
  2863. updateQueue.baseState = memoizedState;
  2864. }
  2865. }
  2866. var classComponentUpdater = {
  2867. isMounted: isMounted,
  2868. enqueueSetState: function (inst, payload, callback) {
  2869. var fiber = get(inst);
  2870. var currentTime = requestCurrentTimeForUpdate();
  2871. var suspenseConfig = requestCurrentSuspenseConfig();
  2872. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  2873. var update = createUpdate(expirationTime, suspenseConfig);
  2874. update.payload = payload;
  2875. if (callback !== undefined && callback !== null) {
  2876. {
  2877. warnOnInvalidCallback(callback, 'setState');
  2878. }
  2879. update.callback = callback;
  2880. }
  2881. enqueueUpdate(fiber, update);
  2882. scheduleWork(fiber, expirationTime);
  2883. },
  2884. enqueueReplaceState: function (inst, payload, callback) {
  2885. var fiber = get(inst);
  2886. var currentTime = requestCurrentTimeForUpdate();
  2887. var suspenseConfig = requestCurrentSuspenseConfig();
  2888. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  2889. var update = createUpdate(expirationTime, suspenseConfig);
  2890. update.tag = ReplaceState;
  2891. update.payload = payload;
  2892. if (callback !== undefined && callback !== null) {
  2893. {
  2894. warnOnInvalidCallback(callback, 'replaceState');
  2895. }
  2896. update.callback = callback;
  2897. }
  2898. enqueueUpdate(fiber, update);
  2899. scheduleWork(fiber, expirationTime);
  2900. },
  2901. enqueueForceUpdate: function (inst, callback) {
  2902. var fiber = get(inst);
  2903. var currentTime = requestCurrentTimeForUpdate();
  2904. var suspenseConfig = requestCurrentSuspenseConfig();
  2905. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  2906. var update = createUpdate(expirationTime, suspenseConfig);
  2907. update.tag = ForceUpdate;
  2908. if (callback !== undefined && callback !== null) {
  2909. {
  2910. warnOnInvalidCallback(callback, 'forceUpdate');
  2911. }
  2912. update.callback = callback;
  2913. }
  2914. enqueueUpdate(fiber, update);
  2915. scheduleWork(fiber, expirationTime);
  2916. }
  2917. };
  2918. function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
  2919. var instance = workInProgress.stateNode;
  2920. if (typeof instance.shouldComponentUpdate === 'function') {
  2921. startPhaseTimer(workInProgress, 'shouldComponentUpdate');
  2922. var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
  2923. stopPhaseTimer();
  2924. {
  2925. if (shouldUpdate === undefined) {
  2926. error('%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(ctor) || 'Component');
  2927. }
  2928. }
  2929. return shouldUpdate;
  2930. }
  2931. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  2932. return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
  2933. }
  2934. return true;
  2935. }
  2936. function checkClassInstance(workInProgress, ctor, newProps) {
  2937. var instance = workInProgress.stateNode;
  2938. {
  2939. var name = getComponentName(ctor) || 'Component';
  2940. var renderPresent = instance.render;
  2941. if (!renderPresent) {
  2942. if (ctor.prototype && typeof ctor.prototype.render === 'function') {
  2943. error('%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
  2944. } else {
  2945. error('%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
  2946. }
  2947. }
  2948. if (instance.getInitialState && !instance.getInitialState.isReactClassApproved && !instance.state) {
  2949. 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);
  2950. }
  2951. if (instance.getDefaultProps && !instance.getDefaultProps.isReactClassApproved) {
  2952. 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);
  2953. }
  2954. if (instance.propTypes) {
  2955. error('propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name);
  2956. }
  2957. if (instance.contextType) {
  2958. error('contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name);
  2959. }
  2960. {
  2961. if (instance.contextTypes) {
  2962. error('contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name);
  2963. }
  2964. if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
  2965. didWarnAboutContextTypeAndContextTypes.add(ctor);
  2966. error('%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
  2967. }
  2968. }
  2969. if (typeof instance.componentShouldUpdate === 'function') {
  2970. 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);
  2971. }
  2972. if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
  2973. 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');
  2974. }
  2975. if (typeof instance.componentDidUnmount === 'function') {
  2976. error('%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name);
  2977. }
  2978. if (typeof instance.componentDidReceiveProps === 'function') {
  2979. 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);
  2980. }
  2981. if (typeof instance.componentWillRecieveProps === 'function') {
  2982. error('%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name);
  2983. }
  2984. if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') {
  2985. error('%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name);
  2986. }
  2987. var hasMutatedProps = instance.props !== newProps;
  2988. if (instance.props !== undefined && hasMutatedProps) {
  2989. error('%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, name);
  2990. }
  2991. if (instance.defaultProps) {
  2992. 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);
  2993. }
  2994. if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
  2995. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  2996. error('%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
  2997. }
  2998. if (typeof instance.getDerivedStateFromProps === 'function') {
  2999. error('%s: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  3000. }
  3001. if (typeof instance.getDerivedStateFromError === 'function') {
  3002. error('%s: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  3003. }
  3004. if (typeof ctor.getSnapshotBeforeUpdate === 'function') {
  3005. error('%s: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', name);
  3006. }
  3007. var _state = instance.state;
  3008. if (_state && (typeof _state !== 'object' || isArray(_state))) {
  3009. error('%s.state: must be set to an object or null', name);
  3010. }
  3011. if (typeof instance.getChildContext === 'function' && typeof ctor.childContextTypes !== 'object') {
  3012. error('%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name);
  3013. }
  3014. }
  3015. }
  3016. function adoptClassInstance(workInProgress, instance) {
  3017. instance.updater = classComponentUpdater;
  3018. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  3019. set(instance, workInProgress);
  3020. {
  3021. instance._reactInternalInstance = fakeInternalInstance;
  3022. }
  3023. }
  3024. function constructClassInstance(workInProgress, ctor, props) {
  3025. var isLegacyContextConsumer = false;
  3026. var unmaskedContext = emptyContextObject;
  3027. var context = emptyContextObject;
  3028. var contextType = ctor.contextType;
  3029. {
  3030. if ('contextType' in ctor) {
  3031. var isValid = // Allow null for conditional declaration
  3032. contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
  3033. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  3034. didWarnAboutInvalidateContextType.add(ctor);
  3035. var addendum = '';
  3036. if (contextType === undefined) {
  3037. 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.';
  3038. } else if (typeof contextType !== 'object') {
  3039. addendum = ' However, it is set to a ' + typeof contextType + '.';
  3040. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  3041. addendum = ' Did you accidentally pass the Context.Provider instead?';
  3042. } else if (contextType._context !== undefined) {
  3043. // <Context.Consumer>
  3044. addendum = ' Did you accidentally pass the Context.Consumer instead?';
  3045. } else {
  3046. addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
  3047. }
  3048. error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
  3049. }
  3050. }
  3051. }
  3052. if (typeof contextType === 'object' && contextType !== null) {
  3053. context = readContext(contextType);
  3054. } else {
  3055. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  3056. var contextTypes = ctor.contextTypes;
  3057. isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
  3058. context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
  3059. } // Instantiate twice to help detect side-effects.
  3060. var instance = new ctor(props, context);
  3061. var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
  3062. adoptClassInstance(workInProgress, instance);
  3063. {
  3064. if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
  3065. var componentName = getComponentName(ctor) || 'Component';
  3066. if (!didWarnAboutUninitializedState.has(componentName)) {
  3067. didWarnAboutUninitializedState.add(componentName);
  3068. 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);
  3069. }
  3070. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  3071. // Warn about these lifecycles if they are present.
  3072. // Don't warn about react-lifecycles-compat polyfilled methods though.
  3073. if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
  3074. var foundWillMountName = null;
  3075. var foundWillReceivePropsName = null;
  3076. var foundWillUpdateName = null;
  3077. if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
  3078. foundWillMountName = 'componentWillMount';
  3079. } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
  3080. foundWillMountName = 'UNSAFE_componentWillMount';
  3081. }
  3082. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  3083. foundWillReceivePropsName = 'componentWillReceiveProps';
  3084. } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  3085. foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
  3086. }
  3087. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  3088. foundWillUpdateName = 'componentWillUpdate';
  3089. } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  3090. foundWillUpdateName = 'UNSAFE_componentWillUpdate';
  3091. }
  3092. if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
  3093. var _componentName = getComponentName(ctor) || 'Component';
  3094. var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
  3095. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  3096. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  3097. 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 : '');
  3098. }
  3099. }
  3100. }
  3101. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  3102. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  3103. if (isLegacyContextConsumer) {
  3104. cacheContext(workInProgress, unmaskedContext, context);
  3105. }
  3106. return instance;
  3107. }
  3108. function callComponentWillMount(workInProgress, instance) {
  3109. startPhaseTimer(workInProgress, 'componentWillMount');
  3110. var oldState = instance.state;
  3111. if (typeof instance.componentWillMount === 'function') {
  3112. instance.componentWillMount();
  3113. }
  3114. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  3115. instance.UNSAFE_componentWillMount();
  3116. }
  3117. stopPhaseTimer();
  3118. if (oldState !== instance.state) {
  3119. {
  3120. error('%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + 'constructor). Use setState instead.', getComponentName(workInProgress.type) || 'Component');
  3121. }
  3122. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  3123. }
  3124. }
  3125. function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
  3126. var oldState = instance.state;
  3127. startPhaseTimer(workInProgress, 'componentWillReceiveProps');
  3128. if (typeof instance.componentWillReceiveProps === 'function') {
  3129. instance.componentWillReceiveProps(newProps, nextContext);
  3130. }
  3131. if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  3132. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  3133. }
  3134. stopPhaseTimer();
  3135. if (instance.state !== oldState) {
  3136. {
  3137. var componentName = getComponentName(workInProgress.type) || 'Component';
  3138. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  3139. didWarnAboutStateAssignmentForComponent.add(componentName);
  3140. error('%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
  3141. }
  3142. }
  3143. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  3144. }
  3145. } // Invokes the mount life-cycles on a previously never rendered instance.
  3146. function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
  3147. {
  3148. checkClassInstance(workInProgress, ctor, newProps);
  3149. }
  3150. var instance = workInProgress.stateNode;
  3151. instance.props = newProps;
  3152. instance.state = workInProgress.memoizedState;
  3153. instance.refs = emptyRefsObject;
  3154. initializeUpdateQueue(workInProgress);
  3155. var contextType = ctor.contextType;
  3156. if (typeof contextType === 'object' && contextType !== null) {
  3157. instance.context = readContext(contextType);
  3158. } else {
  3159. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  3160. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  3161. }
  3162. {
  3163. if (instance.state === newProps) {
  3164. var componentName = getComponentName(ctor) || 'Component';
  3165. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  3166. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  3167. 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);
  3168. }
  3169. }
  3170. if (workInProgress.mode & StrictMode) {
  3171. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
  3172. }
  3173. {
  3174. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
  3175. }
  3176. }
  3177. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3178. instance.state = workInProgress.memoizedState;
  3179. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  3180. if (typeof getDerivedStateFromProps === 'function') {
  3181. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  3182. instance.state = workInProgress.memoizedState;
  3183. } // In order to support react-lifecycles-compat polyfilled components,
  3184. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3185. if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  3186. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  3187. // process them now.
  3188. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3189. instance.state = workInProgress.memoizedState;
  3190. }
  3191. if (typeof instance.componentDidMount === 'function') {
  3192. workInProgress.effectTag |= Update;
  3193. }
  3194. }
  3195. function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
  3196. var instance = workInProgress.stateNode;
  3197. var oldProps = workInProgress.memoizedProps;
  3198. instance.props = oldProps;
  3199. var oldContext = instance.context;
  3200. var contextType = ctor.contextType;
  3201. var nextContext = emptyContextObject;
  3202. if (typeof contextType === 'object' && contextType !== null) {
  3203. nextContext = readContext(contextType);
  3204. } else {
  3205. var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  3206. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  3207. }
  3208. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  3209. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  3210. // ever the previously attempted to render - not the "current". However,
  3211. // during componentDidUpdate we pass the "current" props.
  3212. // In order to support react-lifecycles-compat polyfilled components,
  3213. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3214. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  3215. if (oldProps !== newProps || oldContext !== nextContext) {
  3216. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  3217. }
  3218. }
  3219. resetHasForceUpdateBeforeProcessing();
  3220. var oldState = workInProgress.memoizedState;
  3221. var newState = instance.state = oldState;
  3222. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3223. newState = workInProgress.memoizedState;
  3224. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  3225. // If an update was already in progress, we should schedule an Update
  3226. // effect even though we're bailing out, so that cWU/cDU are called.
  3227. if (typeof instance.componentDidMount === 'function') {
  3228. workInProgress.effectTag |= Update;
  3229. }
  3230. return false;
  3231. }
  3232. if (typeof getDerivedStateFromProps === 'function') {
  3233. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  3234. newState = workInProgress.memoizedState;
  3235. }
  3236. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  3237. if (shouldUpdate) {
  3238. // In order to support react-lifecycles-compat polyfilled components,
  3239. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3240. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  3241. startPhaseTimer(workInProgress, 'componentWillMount');
  3242. if (typeof instance.componentWillMount === 'function') {
  3243. instance.componentWillMount();
  3244. }
  3245. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  3246. instance.UNSAFE_componentWillMount();
  3247. }
  3248. stopPhaseTimer();
  3249. }
  3250. if (typeof instance.componentDidMount === 'function') {
  3251. workInProgress.effectTag |= Update;
  3252. }
  3253. } else {
  3254. // If an update was already in progress, we should schedule an Update
  3255. // effect even though we're bailing out, so that cWU/cDU are called.
  3256. if (typeof instance.componentDidMount === 'function') {
  3257. workInProgress.effectTag |= Update;
  3258. } // If shouldComponentUpdate returned false, we should still update the
  3259. // memoized state to indicate that this work can be reused.
  3260. workInProgress.memoizedProps = newProps;
  3261. workInProgress.memoizedState = newState;
  3262. } // Update the existing instance's state, props, and context pointers even
  3263. // if shouldComponentUpdate returns false.
  3264. instance.props = newProps;
  3265. instance.state = newState;
  3266. instance.context = nextContext;
  3267. return shouldUpdate;
  3268. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  3269. function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
  3270. var instance = workInProgress.stateNode;
  3271. cloneUpdateQueue(current, workInProgress);
  3272. var oldProps = workInProgress.memoizedProps;
  3273. instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
  3274. var oldContext = instance.context;
  3275. var contextType = ctor.contextType;
  3276. var nextContext = emptyContextObject;
  3277. if (typeof contextType === 'object' && contextType !== null) {
  3278. nextContext = readContext(contextType);
  3279. } else {
  3280. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  3281. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  3282. }
  3283. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  3284. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  3285. // ever the previously attempted to render - not the "current". However,
  3286. // during componentDidUpdate we pass the "current" props.
  3287. // In order to support react-lifecycles-compat polyfilled components,
  3288. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3289. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  3290. if (oldProps !== newProps || oldContext !== nextContext) {
  3291. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  3292. }
  3293. }
  3294. resetHasForceUpdateBeforeProcessing();
  3295. var oldState = workInProgress.memoizedState;
  3296. var newState = instance.state = oldState;
  3297. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3298. newState = workInProgress.memoizedState;
  3299. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  3300. // If an update was already in progress, we should schedule an Update
  3301. // effect even though we're bailing out, so that cWU/cDU are called.
  3302. if (typeof instance.componentDidUpdate === 'function') {
  3303. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3304. workInProgress.effectTag |= Update;
  3305. }
  3306. }
  3307. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  3308. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3309. workInProgress.effectTag |= Snapshot;
  3310. }
  3311. }
  3312. return false;
  3313. }
  3314. if (typeof getDerivedStateFromProps === 'function') {
  3315. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  3316. newState = workInProgress.memoizedState;
  3317. }
  3318. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  3319. if (shouldUpdate) {
  3320. // In order to support react-lifecycles-compat polyfilled components,
  3321. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3322. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
  3323. startPhaseTimer(workInProgress, 'componentWillUpdate');
  3324. if (typeof instance.componentWillUpdate === 'function') {
  3325. instance.componentWillUpdate(newProps, newState, nextContext);
  3326. }
  3327. if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  3328. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  3329. }
  3330. stopPhaseTimer();
  3331. }
  3332. if (typeof instance.componentDidUpdate === 'function') {
  3333. workInProgress.effectTag |= Update;
  3334. }
  3335. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  3336. workInProgress.effectTag |= Snapshot;
  3337. }
  3338. } else {
  3339. // If an update was already in progress, we should schedule an Update
  3340. // effect even though we're bailing out, so that cWU/cDU are called.
  3341. if (typeof instance.componentDidUpdate === 'function') {
  3342. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3343. workInProgress.effectTag |= Update;
  3344. }
  3345. }
  3346. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  3347. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3348. workInProgress.effectTag |= Snapshot;
  3349. }
  3350. } // If shouldComponentUpdate returned false, we should still update the
  3351. // memoized props/state to indicate that this work can be reused.
  3352. workInProgress.memoizedProps = newProps;
  3353. workInProgress.memoizedState = newState;
  3354. } // Update the existing instance's state, props, and context pointers even
  3355. // if shouldComponentUpdate returns false.
  3356. instance.props = newProps;
  3357. instance.state = newState;
  3358. instance.context = nextContext;
  3359. return shouldUpdate;
  3360. }
  3361. var didWarnAboutMaps;
  3362. var didWarnAboutGenerators;
  3363. var didWarnAboutStringRefs;
  3364. var ownerHasKeyUseWarning;
  3365. var ownerHasFunctionTypeWarning;
  3366. var warnForMissingKey = function (child) {};
  3367. {
  3368. didWarnAboutMaps = false;
  3369. didWarnAboutGenerators = false;
  3370. didWarnAboutStringRefs = {};
  3371. /**
  3372. * Warn if there's no key explicitly set on dynamic arrays of children or
  3373. * object keys are not valid. This allows us to keep track of children between
  3374. * updates.
  3375. */
  3376. ownerHasKeyUseWarning = {};
  3377. ownerHasFunctionTypeWarning = {};
  3378. warnForMissingKey = function (child) {
  3379. if (child === null || typeof child !== 'object') {
  3380. return;
  3381. }
  3382. if (!child._store || child._store.validated || child.key != null) {
  3383. return;
  3384. }
  3385. if (!(typeof child._store === 'object')) {
  3386. {
  3387. throw Error( "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue." );
  3388. }
  3389. }
  3390. child._store.validated = true;
  3391. var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
  3392. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  3393. return;
  3394. }
  3395. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  3396. error('Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
  3397. };
  3398. }
  3399. var isArray$1 = Array.isArray;
  3400. function coerceRef(returnFiber, current, element) {
  3401. var mixedRef = element.ref;
  3402. if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
  3403. {
  3404. // TODO: Clean this up once we turn on the string ref warning for
  3405. // everyone, because the strict mode case will no longer be relevant
  3406. if ((returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  3407. // because these cannot be automatically converted to an arrow function
  3408. // using a codemod. Therefore, we don't have to warn about string refs again.
  3409. !(element._owner && element._self && element._owner.stateNode !== element._self)) {
  3410. var componentName = getComponentName(returnFiber.type) || 'Component';
  3411. if (!didWarnAboutStringRefs[componentName]) {
  3412. {
  3413. 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));
  3414. }
  3415. didWarnAboutStringRefs[componentName] = true;
  3416. }
  3417. }
  3418. }
  3419. if (element._owner) {
  3420. var owner = element._owner;
  3421. var inst;
  3422. if (owner) {
  3423. var ownerFiber = owner;
  3424. if (!(ownerFiber.tag === ClassComponent)) {
  3425. {
  3426. 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" );
  3427. }
  3428. }
  3429. inst = ownerFiber.stateNode;
  3430. }
  3431. if (!inst) {
  3432. {
  3433. throw Error( "Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue." );
  3434. }
  3435. }
  3436. var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
  3437. if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) {
  3438. return current.ref;
  3439. }
  3440. var ref = function (value) {
  3441. var refs = inst.refs;
  3442. if (refs === emptyRefsObject) {
  3443. // This is a lazy pooled frozen object, so we need to initialize.
  3444. refs = inst.refs = {};
  3445. }
  3446. if (value === null) {
  3447. delete refs[stringRef];
  3448. } else {
  3449. refs[stringRef] = value;
  3450. }
  3451. };
  3452. ref._stringRef = stringRef;
  3453. return ref;
  3454. } else {
  3455. if (!(typeof mixedRef === 'string')) {
  3456. {
  3457. throw Error( "Expected ref to be a function, a string, an object returned by React.createRef(), or null." );
  3458. }
  3459. }
  3460. if (!element._owner) {
  3461. {
  3462. 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." );
  3463. }
  3464. }
  3465. }
  3466. }
  3467. return mixedRef;
  3468. }
  3469. function throwOnInvalidObjectType(returnFiber, newChild) {
  3470. if (returnFiber.type !== 'textarea') {
  3471. var addendum = '';
  3472. {
  3473. addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
  3474. }
  3475. {
  3476. {
  3477. 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 );
  3478. }
  3479. }
  3480. }
  3481. }
  3482. function warnOnFunctionType() {
  3483. {
  3484. 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();
  3485. if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
  3486. return;
  3487. }
  3488. ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
  3489. 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.');
  3490. }
  3491. } // This wrapper function exists because I expect to clone the code in each path
  3492. // to be able to optimize each path individually by branching early. This needs
  3493. // a compiler or we can do it manually. Helpers that don't need this branching
  3494. // live outside of this function.
  3495. function ChildReconciler(shouldTrackSideEffects) {
  3496. function deleteChild(returnFiber, childToDelete) {
  3497. if (!shouldTrackSideEffects) {
  3498. // Noop.
  3499. return;
  3500. } // Deletions are added in reversed order so we add it to the front.
  3501. // At this point, the return fiber's effect list is empty except for
  3502. // deletions, so we can just append the deletion to the list. The remaining
  3503. // effects aren't added until the complete phase. Once we implement
  3504. // resuming, this may not be true.
  3505. var last = returnFiber.lastEffect;
  3506. if (last !== null) {
  3507. last.nextEffect = childToDelete;
  3508. returnFiber.lastEffect = childToDelete;
  3509. } else {
  3510. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  3511. }
  3512. childToDelete.nextEffect = null;
  3513. childToDelete.effectTag = Deletion;
  3514. }
  3515. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  3516. if (!shouldTrackSideEffects) {
  3517. // Noop.
  3518. return null;
  3519. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  3520. // assuming that after the first child we've already added everything.
  3521. var childToDelete = currentFirstChild;
  3522. while (childToDelete !== null) {
  3523. deleteChild(returnFiber, childToDelete);
  3524. childToDelete = childToDelete.sibling;
  3525. }
  3526. return null;
  3527. }
  3528. function mapRemainingChildren(returnFiber, currentFirstChild) {
  3529. // Add the remaining children to a temporary map so that we can find them by
  3530. // keys quickly. Implicit (null) keys get added to this set with their index
  3531. // instead.
  3532. var existingChildren = new Map();
  3533. var existingChild = currentFirstChild;
  3534. while (existingChild !== null) {
  3535. if (existingChild.key !== null) {
  3536. existingChildren.set(existingChild.key, existingChild);
  3537. } else {
  3538. existingChildren.set(existingChild.index, existingChild);
  3539. }
  3540. existingChild = existingChild.sibling;
  3541. }
  3542. return existingChildren;
  3543. }
  3544. function useFiber(fiber, pendingProps) {
  3545. // We currently set sibling to null and index to 0 here because it is easy
  3546. // to forget to do before returning it. E.g. for the single child case.
  3547. var clone = createWorkInProgress(fiber, pendingProps);
  3548. clone.index = 0;
  3549. clone.sibling = null;
  3550. return clone;
  3551. }
  3552. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  3553. newFiber.index = newIndex;
  3554. if (!shouldTrackSideEffects) {
  3555. // Noop.
  3556. return lastPlacedIndex;
  3557. }
  3558. var current = newFiber.alternate;
  3559. if (current !== null) {
  3560. var oldIndex = current.index;
  3561. if (oldIndex < lastPlacedIndex) {
  3562. // This is a move.
  3563. newFiber.effectTag = Placement;
  3564. return lastPlacedIndex;
  3565. } else {
  3566. // This item can stay in place.
  3567. return oldIndex;
  3568. }
  3569. } else {
  3570. // This is an insertion.
  3571. newFiber.effectTag = Placement;
  3572. return lastPlacedIndex;
  3573. }
  3574. }
  3575. function placeSingleChild(newFiber) {
  3576. // This is simpler for the single child case. We only need to do a
  3577. // placement for inserting new children.
  3578. if (shouldTrackSideEffects && newFiber.alternate === null) {
  3579. newFiber.effectTag = Placement;
  3580. }
  3581. return newFiber;
  3582. }
  3583. function updateTextNode(returnFiber, current, textContent, expirationTime) {
  3584. if (current === null || current.tag !== HostText) {
  3585. // Insert
  3586. var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
  3587. created.return = returnFiber;
  3588. return created;
  3589. } else {
  3590. // Update
  3591. var existing = useFiber(current, textContent);
  3592. existing.return = returnFiber;
  3593. return existing;
  3594. }
  3595. }
  3596. function updateElement(returnFiber, current, element, expirationTime) {
  3597. if (current !== null) {
  3598. if (current.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  3599. isCompatibleFamilyForHotReloading(current, element) )) {
  3600. // Move based on index
  3601. var existing = useFiber(current, element.props);
  3602. existing.ref = coerceRef(returnFiber, current, element);
  3603. existing.return = returnFiber;
  3604. {
  3605. existing._debugSource = element._source;
  3606. existing._debugOwner = element._owner;
  3607. }
  3608. return existing;
  3609. }
  3610. } // Insert
  3611. var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
  3612. created.ref = coerceRef(returnFiber, current, element);
  3613. created.return = returnFiber;
  3614. return created;
  3615. }
  3616. function updatePortal(returnFiber, current, portal, expirationTime) {
  3617. if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {
  3618. // Insert
  3619. var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
  3620. created.return = returnFiber;
  3621. return created;
  3622. } else {
  3623. // Update
  3624. var existing = useFiber(current, portal.children || []);
  3625. existing.return = returnFiber;
  3626. return existing;
  3627. }
  3628. }
  3629. function updateFragment(returnFiber, current, fragment, expirationTime, key) {
  3630. if (current === null || current.tag !== Fragment) {
  3631. // Insert
  3632. var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
  3633. created.return = returnFiber;
  3634. return created;
  3635. } else {
  3636. // Update
  3637. var existing = useFiber(current, fragment);
  3638. existing.return = returnFiber;
  3639. return existing;
  3640. }
  3641. }
  3642. function createChild(returnFiber, newChild, expirationTime) {
  3643. if (typeof newChild === 'string' || typeof newChild === 'number') {
  3644. // Text nodes don't have keys. If the previous node is implicitly keyed
  3645. // we can continue to replace it without aborting even if it is not a text
  3646. // node.
  3647. var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
  3648. created.return = returnFiber;
  3649. return created;
  3650. }
  3651. if (typeof newChild === 'object' && newChild !== null) {
  3652. switch (newChild.$$typeof) {
  3653. case REACT_ELEMENT_TYPE:
  3654. {
  3655. var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
  3656. _created.ref = coerceRef(returnFiber, null, newChild);
  3657. _created.return = returnFiber;
  3658. return _created;
  3659. }
  3660. case REACT_PORTAL_TYPE:
  3661. {
  3662. var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
  3663. _created2.return = returnFiber;
  3664. return _created2;
  3665. }
  3666. }
  3667. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  3668. var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
  3669. _created3.return = returnFiber;
  3670. return _created3;
  3671. }
  3672. throwOnInvalidObjectType(returnFiber, newChild);
  3673. }
  3674. {
  3675. if (typeof newChild === 'function') {
  3676. warnOnFunctionType();
  3677. }
  3678. }
  3679. return null;
  3680. }
  3681. function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
  3682. // Update the fiber if the keys match, otherwise return null.
  3683. var key = oldFiber !== null ? oldFiber.key : null;
  3684. if (typeof newChild === 'string' || typeof newChild === 'number') {
  3685. // Text nodes don't have keys. If the previous node is implicitly keyed
  3686. // we can continue to replace it without aborting even if it is not a text
  3687. // node.
  3688. if (key !== null) {
  3689. return null;
  3690. }
  3691. return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
  3692. }
  3693. if (typeof newChild === 'object' && newChild !== null) {
  3694. switch (newChild.$$typeof) {
  3695. case REACT_ELEMENT_TYPE:
  3696. {
  3697. if (newChild.key === key) {
  3698. if (newChild.type === REACT_FRAGMENT_TYPE) {
  3699. return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
  3700. }
  3701. return updateElement(returnFiber, oldFiber, newChild, expirationTime);
  3702. } else {
  3703. return null;
  3704. }
  3705. }
  3706. case REACT_PORTAL_TYPE:
  3707. {
  3708. if (newChild.key === key) {
  3709. return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
  3710. } else {
  3711. return null;
  3712. }
  3713. }
  3714. }
  3715. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  3716. if (key !== null) {
  3717. return null;
  3718. }
  3719. return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
  3720. }
  3721. throwOnInvalidObjectType(returnFiber, newChild);
  3722. }
  3723. {
  3724. if (typeof newChild === 'function') {
  3725. warnOnFunctionType();
  3726. }
  3727. }
  3728. return null;
  3729. }
  3730. function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
  3731. if (typeof newChild === 'string' || typeof newChild === 'number') {
  3732. // Text nodes don't have keys, so we neither have to check the old nor
  3733. // new node for the key. If both are text nodes, they match.
  3734. var matchedFiber = existingChildren.get(newIdx) || null;
  3735. return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
  3736. }
  3737. if (typeof newChild === 'object' && newChild !== null) {
  3738. switch (newChild.$$typeof) {
  3739. case REACT_ELEMENT_TYPE:
  3740. {
  3741. var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  3742. if (newChild.type === REACT_FRAGMENT_TYPE) {
  3743. return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
  3744. }
  3745. return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
  3746. }
  3747. case REACT_PORTAL_TYPE:
  3748. {
  3749. var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  3750. return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
  3751. }
  3752. }
  3753. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  3754. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  3755. return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
  3756. }
  3757. throwOnInvalidObjectType(returnFiber, newChild);
  3758. }
  3759. {
  3760. if (typeof newChild === 'function') {
  3761. warnOnFunctionType();
  3762. }
  3763. }
  3764. return null;
  3765. }
  3766. /**
  3767. * Warns if there is a duplicate or missing key
  3768. */
  3769. function warnOnInvalidKey(child, knownKeys) {
  3770. {
  3771. if (typeof child !== 'object' || child === null) {
  3772. return knownKeys;
  3773. }
  3774. switch (child.$$typeof) {
  3775. case REACT_ELEMENT_TYPE:
  3776. case REACT_PORTAL_TYPE:
  3777. warnForMissingKey(child);
  3778. var key = child.key;
  3779. if (typeof key !== 'string') {
  3780. break;
  3781. }
  3782. if (knownKeys === null) {
  3783. knownKeys = new Set();
  3784. knownKeys.add(key);
  3785. break;
  3786. }
  3787. if (!knownKeys.has(key)) {
  3788. knownKeys.add(key);
  3789. break;
  3790. }
  3791. 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);
  3792. break;
  3793. }
  3794. }
  3795. return knownKeys;
  3796. }
  3797. function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
  3798. // This algorithm can't optimize by searching from both ends since we
  3799. // don't have backpointers on fibers. I'm trying to see how far we can get
  3800. // with that model. If it ends up not being worth the tradeoffs, we can
  3801. // add it later.
  3802. // Even with a two ended optimization, we'd want to optimize for the case
  3803. // where there are few changes and brute force the comparison instead of
  3804. // going for the Map. It'd like to explore hitting that path first in
  3805. // forward-only mode and only go for the Map once we notice that we need
  3806. // lots of look ahead. This doesn't handle reversal as well as two ended
  3807. // search but that's unusual. Besides, for the two ended optimization to
  3808. // work on Iterables, we'd need to copy the whole set.
  3809. // In this first iteration, we'll just live with hitting the bad case
  3810. // (adding everything to a Map) in for every insert/move.
  3811. // If you change this code, also update reconcileChildrenIterator() which
  3812. // uses the same algorithm.
  3813. {
  3814. // First, validate keys.
  3815. var knownKeys = null;
  3816. for (var i = 0; i < newChildren.length; i++) {
  3817. var child = newChildren[i];
  3818. knownKeys = warnOnInvalidKey(child, knownKeys);
  3819. }
  3820. }
  3821. var resultingFirstChild = null;
  3822. var previousNewFiber = null;
  3823. var oldFiber = currentFirstChild;
  3824. var lastPlacedIndex = 0;
  3825. var newIdx = 0;
  3826. var nextOldFiber = null;
  3827. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  3828. if (oldFiber.index > newIdx) {
  3829. nextOldFiber = oldFiber;
  3830. oldFiber = null;
  3831. } else {
  3832. nextOldFiber = oldFiber.sibling;
  3833. }
  3834. var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
  3835. if (newFiber === null) {
  3836. // TODO: This breaks on empty slots like null children. That's
  3837. // unfortunate because it triggers the slow path all the time. We need
  3838. // a better way to communicate whether this was a miss or null,
  3839. // boolean, undefined, etc.
  3840. if (oldFiber === null) {
  3841. oldFiber = nextOldFiber;
  3842. }
  3843. break;
  3844. }
  3845. if (shouldTrackSideEffects) {
  3846. if (oldFiber && newFiber.alternate === null) {
  3847. // We matched the slot, but we didn't reuse the existing fiber, so we
  3848. // need to delete the existing child.
  3849. deleteChild(returnFiber, oldFiber);
  3850. }
  3851. }
  3852. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  3853. if (previousNewFiber === null) {
  3854. // TODO: Move out of the loop. This only happens for the first run.
  3855. resultingFirstChild = newFiber;
  3856. } else {
  3857. // TODO: Defer siblings if we're not at the right index for this slot.
  3858. // I.e. if we had null values before, then we want to defer this
  3859. // for each null value. However, we also don't want to call updateSlot
  3860. // with the previous one.
  3861. previousNewFiber.sibling = newFiber;
  3862. }
  3863. previousNewFiber = newFiber;
  3864. oldFiber = nextOldFiber;
  3865. }
  3866. if (newIdx === newChildren.length) {
  3867. // We've reached the end of the new children. We can delete the rest.
  3868. deleteRemainingChildren(returnFiber, oldFiber);
  3869. return resultingFirstChild;
  3870. }
  3871. if (oldFiber === null) {
  3872. // If we don't have any more existing children we can choose a fast path
  3873. // since the rest will all be insertions.
  3874. for (; newIdx < newChildren.length; newIdx++) {
  3875. var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
  3876. if (_newFiber === null) {
  3877. continue;
  3878. }
  3879. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  3880. if (previousNewFiber === null) {
  3881. // TODO: Move out of the loop. This only happens for the first run.
  3882. resultingFirstChild = _newFiber;
  3883. } else {
  3884. previousNewFiber.sibling = _newFiber;
  3885. }
  3886. previousNewFiber = _newFiber;
  3887. }
  3888. return resultingFirstChild;
  3889. } // Add all children to a key map for quick lookups.
  3890. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  3891. for (; newIdx < newChildren.length; newIdx++) {
  3892. var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
  3893. if (_newFiber2 !== null) {
  3894. if (shouldTrackSideEffects) {
  3895. if (_newFiber2.alternate !== null) {
  3896. // The new fiber is a work in progress, but if there exists a
  3897. // current, that means that we reused the fiber. We need to delete
  3898. // it from the child list so that we don't add it to the deletion
  3899. // list.
  3900. existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
  3901. }
  3902. }
  3903. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  3904. if (previousNewFiber === null) {
  3905. resultingFirstChild = _newFiber2;
  3906. } else {
  3907. previousNewFiber.sibling = _newFiber2;
  3908. }
  3909. previousNewFiber = _newFiber2;
  3910. }
  3911. }
  3912. if (shouldTrackSideEffects) {
  3913. // Any existing children that weren't consumed above were deleted. We need
  3914. // to add them to the deletion list.
  3915. existingChildren.forEach(function (child) {
  3916. return deleteChild(returnFiber, child);
  3917. });
  3918. }
  3919. return resultingFirstChild;
  3920. }
  3921. function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
  3922. // This is the same implementation as reconcileChildrenArray(),
  3923. // but using the iterator instead.
  3924. var iteratorFn = getIteratorFn(newChildrenIterable);
  3925. if (!(typeof iteratorFn === 'function')) {
  3926. {
  3927. throw Error( "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue." );
  3928. }
  3929. }
  3930. {
  3931. // We don't support rendering Generators because it's a mutation.
  3932. // See https://github.com/facebook/react/issues/12995
  3933. if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
  3934. newChildrenIterable[Symbol.toStringTag] === 'Generator') {
  3935. if (!didWarnAboutGenerators) {
  3936. 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.');
  3937. }
  3938. didWarnAboutGenerators = true;
  3939. } // Warn about using Maps as children
  3940. if (newChildrenIterable.entries === iteratorFn) {
  3941. if (!didWarnAboutMaps) {
  3942. error('Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.');
  3943. }
  3944. didWarnAboutMaps = true;
  3945. } // First, validate keys.
  3946. // We'll get a different iterator later for the main pass.
  3947. var _newChildren = iteratorFn.call(newChildrenIterable);
  3948. if (_newChildren) {
  3949. var knownKeys = null;
  3950. var _step = _newChildren.next();
  3951. for (; !_step.done; _step = _newChildren.next()) {
  3952. var child = _step.value;
  3953. knownKeys = warnOnInvalidKey(child, knownKeys);
  3954. }
  3955. }
  3956. }
  3957. var newChildren = iteratorFn.call(newChildrenIterable);
  3958. if (!(newChildren != null)) {
  3959. {
  3960. throw Error( "An iterable object provided no iterator." );
  3961. }
  3962. }
  3963. var resultingFirstChild = null;
  3964. var previousNewFiber = null;
  3965. var oldFiber = currentFirstChild;
  3966. var lastPlacedIndex = 0;
  3967. var newIdx = 0;
  3968. var nextOldFiber = null;
  3969. var step = newChildren.next();
  3970. for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
  3971. if (oldFiber.index > newIdx) {
  3972. nextOldFiber = oldFiber;
  3973. oldFiber = null;
  3974. } else {
  3975. nextOldFiber = oldFiber.sibling;
  3976. }
  3977. var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
  3978. if (newFiber === null) {
  3979. // TODO: This breaks on empty slots like null children. That's
  3980. // unfortunate because it triggers the slow path all the time. We need
  3981. // a better way to communicate whether this was a miss or null,
  3982. // boolean, undefined, etc.
  3983. if (oldFiber === null) {
  3984. oldFiber = nextOldFiber;
  3985. }
  3986. break;
  3987. }
  3988. if (shouldTrackSideEffects) {
  3989. if (oldFiber && newFiber.alternate === null) {
  3990. // We matched the slot, but we didn't reuse the existing fiber, so we
  3991. // need to delete the existing child.
  3992. deleteChild(returnFiber, oldFiber);
  3993. }
  3994. }
  3995. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  3996. if (previousNewFiber === null) {
  3997. // TODO: Move out of the loop. This only happens for the first run.
  3998. resultingFirstChild = newFiber;
  3999. } else {
  4000. // TODO: Defer siblings if we're not at the right index for this slot.
  4001. // I.e. if we had null values before, then we want to defer this
  4002. // for each null value. However, we also don't want to call updateSlot
  4003. // with the previous one.
  4004. previousNewFiber.sibling = newFiber;
  4005. }
  4006. previousNewFiber = newFiber;
  4007. oldFiber = nextOldFiber;
  4008. }
  4009. if (step.done) {
  4010. // We've reached the end of the new children. We can delete the rest.
  4011. deleteRemainingChildren(returnFiber, oldFiber);
  4012. return resultingFirstChild;
  4013. }
  4014. if (oldFiber === null) {
  4015. // If we don't have any more existing children we can choose a fast path
  4016. // since the rest will all be insertions.
  4017. for (; !step.done; newIdx++, step = newChildren.next()) {
  4018. var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
  4019. if (_newFiber3 === null) {
  4020. continue;
  4021. }
  4022. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  4023. if (previousNewFiber === null) {
  4024. // TODO: Move out of the loop. This only happens for the first run.
  4025. resultingFirstChild = _newFiber3;
  4026. } else {
  4027. previousNewFiber.sibling = _newFiber3;
  4028. }
  4029. previousNewFiber = _newFiber3;
  4030. }
  4031. return resultingFirstChild;
  4032. } // Add all children to a key map for quick lookups.
  4033. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  4034. for (; !step.done; newIdx++, step = newChildren.next()) {
  4035. var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
  4036. if (_newFiber4 !== null) {
  4037. if (shouldTrackSideEffects) {
  4038. if (_newFiber4.alternate !== null) {
  4039. // The new fiber is a work in progress, but if there exists a
  4040. // current, that means that we reused the fiber. We need to delete
  4041. // it from the child list so that we don't add it to the deletion
  4042. // list.
  4043. existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
  4044. }
  4045. }
  4046. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  4047. if (previousNewFiber === null) {
  4048. resultingFirstChild = _newFiber4;
  4049. } else {
  4050. previousNewFiber.sibling = _newFiber4;
  4051. }
  4052. previousNewFiber = _newFiber4;
  4053. }
  4054. }
  4055. if (shouldTrackSideEffects) {
  4056. // Any existing children that weren't consumed above were deleted. We need
  4057. // to add them to the deletion list.
  4058. existingChildren.forEach(function (child) {
  4059. return deleteChild(returnFiber, child);
  4060. });
  4061. }
  4062. return resultingFirstChild;
  4063. }
  4064. function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
  4065. // There's no need to check for keys on text nodes since we don't have a
  4066. // way to define them.
  4067. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  4068. // We already have an existing node so let's just update it and delete
  4069. // the rest.
  4070. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  4071. var existing = useFiber(currentFirstChild, textContent);
  4072. existing.return = returnFiber;
  4073. return existing;
  4074. } // The existing first child is not a text node so we need to create one
  4075. // and delete the existing ones.
  4076. deleteRemainingChildren(returnFiber, currentFirstChild);
  4077. var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
  4078. created.return = returnFiber;
  4079. return created;
  4080. }
  4081. function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
  4082. var key = element.key;
  4083. var child = currentFirstChild;
  4084. while (child !== null) {
  4085. // TODO: If key === null and child.key === null, then this only applies to
  4086. // the first item in the list.
  4087. if (child.key === key) {
  4088. switch (child.tag) {
  4089. case Fragment:
  4090. {
  4091. if (element.type === REACT_FRAGMENT_TYPE) {
  4092. deleteRemainingChildren(returnFiber, child.sibling);
  4093. var existing = useFiber(child, element.props.children);
  4094. existing.return = returnFiber;
  4095. {
  4096. existing._debugSource = element._source;
  4097. existing._debugOwner = element._owner;
  4098. }
  4099. return existing;
  4100. }
  4101. break;
  4102. }
  4103. case Block:
  4104. // We intentionally fallthrough here if enableBlocksAPI is not on.
  4105. // eslint-disable-next-lined no-fallthrough
  4106. default:
  4107. {
  4108. if (child.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  4109. isCompatibleFamilyForHotReloading(child, element) )) {
  4110. deleteRemainingChildren(returnFiber, child.sibling);
  4111. var _existing3 = useFiber(child, element.props);
  4112. _existing3.ref = coerceRef(returnFiber, child, element);
  4113. _existing3.return = returnFiber;
  4114. {
  4115. _existing3._debugSource = element._source;
  4116. _existing3._debugOwner = element._owner;
  4117. }
  4118. return _existing3;
  4119. }
  4120. break;
  4121. }
  4122. } // Didn't match.
  4123. deleteRemainingChildren(returnFiber, child);
  4124. break;
  4125. } else {
  4126. deleteChild(returnFiber, child);
  4127. }
  4128. child = child.sibling;
  4129. }
  4130. if (element.type === REACT_FRAGMENT_TYPE) {
  4131. var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
  4132. created.return = returnFiber;
  4133. return created;
  4134. } else {
  4135. var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
  4136. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  4137. _created4.return = returnFiber;
  4138. return _created4;
  4139. }
  4140. }
  4141. function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
  4142. var key = portal.key;
  4143. var child = currentFirstChild;
  4144. while (child !== null) {
  4145. // TODO: If key === null and child.key === null, then this only applies to
  4146. // the first item in the list.
  4147. if (child.key === key) {
  4148. if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
  4149. deleteRemainingChildren(returnFiber, child.sibling);
  4150. var existing = useFiber(child, portal.children || []);
  4151. existing.return = returnFiber;
  4152. return existing;
  4153. } else {
  4154. deleteRemainingChildren(returnFiber, child);
  4155. break;
  4156. }
  4157. } else {
  4158. deleteChild(returnFiber, child);
  4159. }
  4160. child = child.sibling;
  4161. }
  4162. var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
  4163. created.return = returnFiber;
  4164. return created;
  4165. } // This API will tag the children with the side-effect of the reconciliation
  4166. // itself. They will be added to the side-effect list as we pass through the
  4167. // children and the parent.
  4168. function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
  4169. // This function is not recursive.
  4170. // If the top level item is an array, we treat it as a set of children,
  4171. // not as a fragment. Nested arrays on the other hand will be treated as
  4172. // fragment nodes. Recursion happens at the normal flow.
  4173. // Handle top level unkeyed fragments as if they were arrays.
  4174. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  4175. // We treat the ambiguous cases above the same.
  4176. var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
  4177. if (isUnkeyedTopLevelFragment) {
  4178. newChild = newChild.props.children;
  4179. } // Handle object types
  4180. var isObject = typeof newChild === 'object' && newChild !== null;
  4181. if (isObject) {
  4182. switch (newChild.$$typeof) {
  4183. case REACT_ELEMENT_TYPE:
  4184. return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
  4185. case REACT_PORTAL_TYPE:
  4186. return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
  4187. }
  4188. }
  4189. if (typeof newChild === 'string' || typeof newChild === 'number') {
  4190. return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
  4191. }
  4192. if (isArray$1(newChild)) {
  4193. return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
  4194. }
  4195. if (getIteratorFn(newChild)) {
  4196. return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
  4197. }
  4198. if (isObject) {
  4199. throwOnInvalidObjectType(returnFiber, newChild);
  4200. }
  4201. {
  4202. if (typeof newChild === 'function') {
  4203. warnOnFunctionType();
  4204. }
  4205. }
  4206. if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
  4207. // If the new child is undefined, and the return fiber is a composite
  4208. // component, throw an error. If Fiber return types are disabled,
  4209. // we already threw above.
  4210. switch (returnFiber.tag) {
  4211. case ClassComponent:
  4212. {
  4213. {
  4214. var instance = returnFiber.stateNode;
  4215. if (instance.render._isMockFunction) {
  4216. // We allow auto-mocks to proceed as if they're returning null.
  4217. break;
  4218. }
  4219. }
  4220. }
  4221. // Intentionally fall through to the next case, which handles both
  4222. // functions and classes
  4223. // eslint-disable-next-lined no-fallthrough
  4224. case FunctionComponent:
  4225. {
  4226. var Component = returnFiber.type;
  4227. {
  4228. {
  4229. 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." );
  4230. }
  4231. }
  4232. }
  4233. }
  4234. } // Remaining cases are all treated as empty.
  4235. return deleteRemainingChildren(returnFiber, currentFirstChild);
  4236. }
  4237. return reconcileChildFibers;
  4238. }
  4239. var reconcileChildFibers = ChildReconciler(true);
  4240. var mountChildFibers = ChildReconciler(false);
  4241. function cloneChildFibers(current, workInProgress) {
  4242. if (!(current === null || workInProgress.child === current.child)) {
  4243. {
  4244. throw Error( "Resuming work not yet implemented." );
  4245. }
  4246. }
  4247. if (workInProgress.child === null) {
  4248. return;
  4249. }
  4250. var currentChild = workInProgress.child;
  4251. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  4252. workInProgress.child = newChild;
  4253. newChild.return = workInProgress;
  4254. while (currentChild.sibling !== null) {
  4255. currentChild = currentChild.sibling;
  4256. newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps);
  4257. newChild.return = workInProgress;
  4258. }
  4259. newChild.sibling = null;
  4260. } // Reset a workInProgress child set to prepare it for a second pass.
  4261. function resetChildFibers(workInProgress, renderExpirationTime) {
  4262. var child = workInProgress.child;
  4263. while (child !== null) {
  4264. resetWorkInProgress(child, renderExpirationTime);
  4265. child = child.sibling;
  4266. }
  4267. }
  4268. var NO_CONTEXT$1 = {};
  4269. var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
  4270. var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
  4271. var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
  4272. function requiredContext(c) {
  4273. if (!(c !== NO_CONTEXT$1)) {
  4274. {
  4275. throw Error( "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." );
  4276. }
  4277. }
  4278. return c;
  4279. }
  4280. function getRootHostContainer() {
  4281. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  4282. return rootInstance;
  4283. }
  4284. function pushHostContainer(fiber, nextRootInstance) {
  4285. // Push current root instance onto the stack;
  4286. // This allows us to reset root when portals are popped.
  4287. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  4288. // This enables us to pop only Fibers that provide unique contexts.
  4289. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  4290. // However, we can't just call getRootHostContext() and push it because
  4291. // we'd have a different number of entries on the stack depending on
  4292. // whether getRootHostContext() throws somewhere in renderer code or not.
  4293. // So we push an empty value first. This lets us safely unwind on errors.
  4294. push(contextStackCursor$1, NO_CONTEXT$1, fiber);
  4295. var nextRootContext = getRootHostContext(); // Now that we know this function doesn't throw, replace it.
  4296. pop(contextStackCursor$1, fiber);
  4297. push(contextStackCursor$1, nextRootContext, fiber);
  4298. }
  4299. function popHostContainer(fiber) {
  4300. pop(contextStackCursor$1, fiber);
  4301. pop(contextFiberStackCursor, fiber);
  4302. pop(rootInstanceStackCursor, fiber);
  4303. }
  4304. function getHostContext() {
  4305. var context = requiredContext(contextStackCursor$1.current);
  4306. return context;
  4307. }
  4308. function pushHostContext(fiber) {
  4309. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  4310. var context = requiredContext(contextStackCursor$1.current);
  4311. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  4312. if (context === nextContext) {
  4313. return;
  4314. } // Track the context and the Fiber that provided it.
  4315. // This enables us to pop only Fibers that provide unique contexts.
  4316. push(contextFiberStackCursor, fiber, fiber);
  4317. push(contextStackCursor$1, nextContext, fiber);
  4318. }
  4319. function popHostContext(fiber) {
  4320. // Do not pop unless this Fiber provided the current context.
  4321. // pushHostContext() only pushes Fibers that provide unique contexts.
  4322. if (contextFiberStackCursor.current !== fiber) {
  4323. return;
  4324. }
  4325. pop(contextStackCursor$1, fiber);
  4326. pop(contextFiberStackCursor, fiber);
  4327. }
  4328. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  4329. // inherited deeply down the subtree. The upper bits only affect
  4330. // this immediate suspense boundary and gets reset each new
  4331. // boundary or suspense list.
  4332. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  4333. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  4334. // boundaries is not currently showing visible main content.
  4335. // Either because it is already showing a fallback or is not mounted at all.
  4336. // We can use this to determine if it is desirable to trigger a fallback at
  4337. // the parent. If not, then we might need to trigger undesirable boundaries
  4338. // and/or suspend the commit to avoid hiding the parent content.
  4339. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  4340. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  4341. // items into their fallback state during one of the render passes.
  4342. var ForceSuspenseFallback = 2;
  4343. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  4344. function hasSuspenseContext(parentContext, flag) {
  4345. return (parentContext & flag) !== 0;
  4346. }
  4347. function setDefaultShallowSuspenseContext(parentContext) {
  4348. return parentContext & SubtreeSuspenseContextMask;
  4349. }
  4350. function setShallowSuspenseContext(parentContext, shallowContext) {
  4351. return parentContext & SubtreeSuspenseContextMask | shallowContext;
  4352. }
  4353. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  4354. return parentContext | subtreeContext;
  4355. }
  4356. function pushSuspenseContext(fiber, newContext) {
  4357. push(suspenseStackCursor, newContext, fiber);
  4358. }
  4359. function popSuspenseContext(fiber) {
  4360. pop(suspenseStackCursor, fiber);
  4361. }
  4362. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  4363. // If it was the primary children that just suspended, capture and render the
  4364. // fallback. Otherwise, don't capture and bubble to the next boundary.
  4365. var nextState = workInProgress.memoizedState;
  4366. if (nextState !== null) {
  4367. if (nextState.dehydrated !== null) {
  4368. // A dehydrated boundary always captures.
  4369. return true;
  4370. }
  4371. return false;
  4372. }
  4373. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  4374. if (props.fallback === undefined) {
  4375. return false;
  4376. } // Regular boundaries always capture.
  4377. if (props.unstable_avoidThisFallback !== true) {
  4378. return true;
  4379. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  4380. // parent boundary if it is currently invisible.
  4381. if (hasInvisibleParent) {
  4382. return false;
  4383. } // If the parent is not able to handle it, we must handle it.
  4384. return true;
  4385. }
  4386. function findFirstSuspended(row) {
  4387. var node = row;
  4388. while (node !== null) {
  4389. if (node.tag === SuspenseComponent) {
  4390. var state = node.memoizedState;
  4391. if (state !== null) {
  4392. var dehydrated = state.dehydrated;
  4393. if (dehydrated === null || isSuspenseInstancePending() || isSuspenseInstanceFallback()) {
  4394. return node;
  4395. }
  4396. }
  4397. } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  4398. // keep track of whether it suspended or not.
  4399. node.memoizedProps.revealOrder !== undefined) {
  4400. var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
  4401. if (didSuspend) {
  4402. return node;
  4403. }
  4404. } else if (node.child !== null) {
  4405. node.child.return = node;
  4406. node = node.child;
  4407. continue;
  4408. }
  4409. if (node === row) {
  4410. return null;
  4411. }
  4412. while (node.sibling === null) {
  4413. if (node.return === null || node.return === row) {
  4414. return null;
  4415. }
  4416. node = node.return;
  4417. }
  4418. node.sibling.return = node.return;
  4419. node = node.sibling;
  4420. }
  4421. return null;
  4422. }
  4423. function createDeprecatedResponderListener(responder, props) {
  4424. var eventResponderListener = {
  4425. responder: responder,
  4426. props: props
  4427. };
  4428. {
  4429. Object.freeze(eventResponderListener);
  4430. }
  4431. return eventResponderListener;
  4432. }
  4433. var HasEffect =
  4434. /* */
  4435. 1; // Represents the phase in which the effect (not the clean-up) fires.
  4436. var Layout =
  4437. /* */
  4438. 2;
  4439. var Passive$1 =
  4440. /* */
  4441. 4;
  4442. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
  4443. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  4444. var didWarnAboutMismatchedHooksForComponent;
  4445. {
  4446. didWarnAboutMismatchedHooksForComponent = new Set();
  4447. }
  4448. // These are set right before calling the component.
  4449. var renderExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
  4450. // the work-in-progress hook.
  4451. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  4452. // current hook list is the list that belongs to the current fiber. The
  4453. // work-in-progress hook list is a new list that will be added to the
  4454. // work-in-progress fiber.
  4455. var currentHook = null;
  4456. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  4457. // does not get reset if we do another render pass; only when we're completely
  4458. // finished evaluating this component. This is an optimization so we know
  4459. // whether we need to clear render phase updates after a throw.
  4460. var didScheduleRenderPhaseUpdate = false;
  4461. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  4462. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  4463. // The list stores the order of hooks used during the initial render (mount).
  4464. // Subsequent renders (updates) reference this list.
  4465. var hookTypesDev = null;
  4466. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  4467. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  4468. // When true, such Hooks will always be "remounted". Only used during hot reload.
  4469. var ignorePreviousDependencies = false;
  4470. function mountHookTypesDev() {
  4471. {
  4472. var hookName = currentHookNameInDev;
  4473. if (hookTypesDev === null) {
  4474. hookTypesDev = [hookName];
  4475. } else {
  4476. hookTypesDev.push(hookName);
  4477. }
  4478. }
  4479. }
  4480. function updateHookTypesDev() {
  4481. {
  4482. var hookName = currentHookNameInDev;
  4483. if (hookTypesDev !== null) {
  4484. hookTypesUpdateIndexDev++;
  4485. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  4486. warnOnHookMismatchInDev(hookName);
  4487. }
  4488. }
  4489. }
  4490. }
  4491. function checkDepsAreArrayDev(deps) {
  4492. {
  4493. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  4494. // Verify deps, but only on mount to avoid extra checks.
  4495. // It's unlikely their type would change as usually you define them inline.
  4496. 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);
  4497. }
  4498. }
  4499. }
  4500. function warnOnHookMismatchInDev(currentHookName) {
  4501. {
  4502. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  4503. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  4504. didWarnAboutMismatchedHooksForComponent.add(componentName);
  4505. if (hookTypesDev !== null) {
  4506. var table = '';
  4507. var secondColumnStart = 30;
  4508. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  4509. var oldHookName = hookTypesDev[i];
  4510. var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  4511. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  4512. // lol @ IE not supporting String#repeat
  4513. while (row.length < secondColumnStart) {
  4514. row += ' ';
  4515. }
  4516. row += newHookName + '\n';
  4517. table += row;
  4518. }
  4519. 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);
  4520. }
  4521. }
  4522. }
  4523. }
  4524. function throwInvalidHookError() {
  4525. {
  4526. {
  4527. 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." );
  4528. }
  4529. }
  4530. }
  4531. function areHookInputsEqual(nextDeps, prevDeps) {
  4532. {
  4533. if (ignorePreviousDependencies) {
  4534. // Only true when this component is being hot reloaded.
  4535. return false;
  4536. }
  4537. }
  4538. if (prevDeps === null) {
  4539. {
  4540. 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);
  4541. }
  4542. return false;
  4543. }
  4544. {
  4545. // Don't bother comparing lengths in prod because these arrays should be
  4546. // passed inline.
  4547. if (nextDeps.length !== prevDeps.length) {
  4548. 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(', ') + "]");
  4549. }
  4550. }
  4551. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  4552. if (objectIs(nextDeps[i], prevDeps[i])) {
  4553. continue;
  4554. }
  4555. return false;
  4556. }
  4557. return true;
  4558. }
  4559. function renderWithHooks(current, workInProgress, Component, props, secondArg, nextRenderExpirationTime) {
  4560. renderExpirationTime = nextRenderExpirationTime;
  4561. currentlyRenderingFiber$1 = workInProgress;
  4562. {
  4563. hookTypesDev = current !== null ? current._debugHookTypes : null;
  4564. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  4565. ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
  4566. }
  4567. workInProgress.memoizedState = null;
  4568. workInProgress.updateQueue = null;
  4569. workInProgress.expirationTime = NoWork; // The following should have already been reset
  4570. // currentHook = null;
  4571. // workInProgressHook = null;
  4572. // didScheduleRenderPhaseUpdate = false;
  4573. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  4574. // Currently we will identify the update render as a mount because memoizedState === null.
  4575. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  4576. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  4577. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  4578. // so memoizedState would be null during updates and mounts.
  4579. {
  4580. if (current !== null && current.memoizedState !== null) {
  4581. ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
  4582. } else if (hookTypesDev !== null) {
  4583. // This dispatcher handles an edge case where a component is updating,
  4584. // but no stateful hooks have been used.
  4585. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  4586. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  4587. // This dispatcher does that.
  4588. ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
  4589. } else {
  4590. ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
  4591. }
  4592. }
  4593. var children = Component(props, secondArg); // Check if there was a render phase update
  4594. if (workInProgress.expirationTime === renderExpirationTime) {
  4595. // Keep rendering in a loop for as long as render phase updates continue to
  4596. // be scheduled. Use a counter to prevent infinite loops.
  4597. var numberOfReRenders = 0;
  4598. do {
  4599. workInProgress.expirationTime = NoWork;
  4600. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  4601. {
  4602. throw Error( "Too many re-renders. React limits the number of renders to prevent an infinite loop." );
  4603. }
  4604. }
  4605. numberOfReRenders += 1;
  4606. {
  4607. // Even when hot reloading, allow dependencies to stabilize
  4608. // after first render to prevent infinite render phase updates.
  4609. ignorePreviousDependencies = false;
  4610. } // Start over from the beginning of the list
  4611. currentHook = null;
  4612. workInProgressHook = null;
  4613. workInProgress.updateQueue = null;
  4614. {
  4615. // Also validate hook order for cascading updates.
  4616. hookTypesUpdateIndexDev = -1;
  4617. }
  4618. ReactCurrentDispatcher.current = HooksDispatcherOnRerenderInDEV ;
  4619. children = Component(props, secondArg);
  4620. } while (workInProgress.expirationTime === renderExpirationTime);
  4621. } // We can assume the previous dispatcher is always this one, since we set it
  4622. // at the beginning of the render phase and there's no re-entrancy.
  4623. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  4624. {
  4625. workInProgress._debugHookTypes = hookTypesDev;
  4626. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  4627. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  4628. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  4629. renderExpirationTime = NoWork;
  4630. currentlyRenderingFiber$1 = null;
  4631. currentHook = null;
  4632. workInProgressHook = null;
  4633. {
  4634. currentHookNameInDev = null;
  4635. hookTypesDev = null;
  4636. hookTypesUpdateIndexDev = -1;
  4637. }
  4638. didScheduleRenderPhaseUpdate = false;
  4639. if (!!didRenderTooFewHooks) {
  4640. {
  4641. throw Error( "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." );
  4642. }
  4643. }
  4644. return children;
  4645. }
  4646. function bailoutHooks(current, workInProgress, expirationTime) {
  4647. workInProgress.updateQueue = current.updateQueue;
  4648. workInProgress.effectTag &= ~(Passive | Update);
  4649. if (current.expirationTime <= expirationTime) {
  4650. current.expirationTime = NoWork;
  4651. }
  4652. }
  4653. function resetHooksAfterThrow() {
  4654. // We can assume the previous dispatcher is always this one, since we set it
  4655. // at the beginning of the render phase and there's no re-entrancy.
  4656. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  4657. if (didScheduleRenderPhaseUpdate) {
  4658. // There were render phase updates. These are only valid for this render
  4659. // phase, which we are now aborting. Remove the updates from the queues so
  4660. // they do not persist to the next render. Do not remove updates from hooks
  4661. // that weren't processed.
  4662. //
  4663. // Only reset the updates from the queue if it has a clone. If it does
  4664. // not have a clone, that means it wasn't processed, and the updates were
  4665. // scheduled before we entered the render phase.
  4666. var hook = currentlyRenderingFiber$1.memoizedState;
  4667. while (hook !== null) {
  4668. var queue = hook.queue;
  4669. if (queue !== null) {
  4670. queue.pending = null;
  4671. }
  4672. hook = hook.next;
  4673. }
  4674. }
  4675. renderExpirationTime = NoWork;
  4676. currentlyRenderingFiber$1 = null;
  4677. currentHook = null;
  4678. workInProgressHook = null;
  4679. {
  4680. hookTypesDev = null;
  4681. hookTypesUpdateIndexDev = -1;
  4682. currentHookNameInDev = null;
  4683. }
  4684. didScheduleRenderPhaseUpdate = false;
  4685. }
  4686. function mountWorkInProgressHook() {
  4687. var hook = {
  4688. memoizedState: null,
  4689. baseState: null,
  4690. baseQueue: null,
  4691. queue: null,
  4692. next: null
  4693. };
  4694. if (workInProgressHook === null) {
  4695. // This is the first hook in the list
  4696. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  4697. } else {
  4698. // Append to the end of the list
  4699. workInProgressHook = workInProgressHook.next = hook;
  4700. }
  4701. return workInProgressHook;
  4702. }
  4703. function updateWorkInProgressHook() {
  4704. // This function is used both for updates and for re-renders triggered by a
  4705. // render phase update. It assumes there is either a current hook we can
  4706. // clone, or a work-in-progress hook from a previous render pass that we can
  4707. // use as a base. When we reach the end of the base list, we must switch to
  4708. // the dispatcher used for mounts.
  4709. var nextCurrentHook;
  4710. if (currentHook === null) {
  4711. var current = currentlyRenderingFiber$1.alternate;
  4712. if (current !== null) {
  4713. nextCurrentHook = current.memoizedState;
  4714. } else {
  4715. nextCurrentHook = null;
  4716. }
  4717. } else {
  4718. nextCurrentHook = currentHook.next;
  4719. }
  4720. var nextWorkInProgressHook;
  4721. if (workInProgressHook === null) {
  4722. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  4723. } else {
  4724. nextWorkInProgressHook = workInProgressHook.next;
  4725. }
  4726. if (nextWorkInProgressHook !== null) {
  4727. // There's already a work-in-progress. Reuse it.
  4728. workInProgressHook = nextWorkInProgressHook;
  4729. nextWorkInProgressHook = workInProgressHook.next;
  4730. currentHook = nextCurrentHook;
  4731. } else {
  4732. // Clone from the current hook.
  4733. if (!(nextCurrentHook !== null)) {
  4734. {
  4735. throw Error( "Rendered more hooks than during the previous render." );
  4736. }
  4737. }
  4738. currentHook = nextCurrentHook;
  4739. var newHook = {
  4740. memoizedState: currentHook.memoizedState,
  4741. baseState: currentHook.baseState,
  4742. baseQueue: currentHook.baseQueue,
  4743. queue: currentHook.queue,
  4744. next: null
  4745. };
  4746. if (workInProgressHook === null) {
  4747. // This is the first hook in the list.
  4748. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  4749. } else {
  4750. // Append to the end of the list.
  4751. workInProgressHook = workInProgressHook.next = newHook;
  4752. }
  4753. }
  4754. return workInProgressHook;
  4755. }
  4756. function createFunctionComponentUpdateQueue() {
  4757. return {
  4758. lastEffect: null
  4759. };
  4760. }
  4761. function basicStateReducer(state, action) {
  4762. // $FlowFixMe: Flow doesn't like mixed types
  4763. return typeof action === 'function' ? action(state) : action;
  4764. }
  4765. function mountReducer(reducer, initialArg, init) {
  4766. var hook = mountWorkInProgressHook();
  4767. var initialState;
  4768. if (init !== undefined) {
  4769. initialState = init(initialArg);
  4770. } else {
  4771. initialState = initialArg;
  4772. }
  4773. hook.memoizedState = hook.baseState = initialState;
  4774. var queue = hook.queue = {
  4775. pending: null,
  4776. dispatch: null,
  4777. lastRenderedReducer: reducer,
  4778. lastRenderedState: initialState
  4779. };
  4780. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  4781. return [hook.memoizedState, dispatch];
  4782. }
  4783. function updateReducer(reducer, initialArg, init) {
  4784. var hook = updateWorkInProgressHook();
  4785. var queue = hook.queue;
  4786. if (!(queue !== null)) {
  4787. {
  4788. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  4789. }
  4790. }
  4791. queue.lastRenderedReducer = reducer;
  4792. var current = currentHook; // The last rebase update that is NOT part of the base state.
  4793. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  4794. var pendingQueue = queue.pending;
  4795. if (pendingQueue !== null) {
  4796. // We have new updates that haven't been processed yet.
  4797. // We'll add them to the base queue.
  4798. if (baseQueue !== null) {
  4799. // Merge the pending queue and the base queue.
  4800. var baseFirst = baseQueue.next;
  4801. var pendingFirst = pendingQueue.next;
  4802. baseQueue.next = pendingFirst;
  4803. pendingQueue.next = baseFirst;
  4804. }
  4805. current.baseQueue = baseQueue = pendingQueue;
  4806. queue.pending = null;
  4807. }
  4808. if (baseQueue !== null) {
  4809. // We have a queue to process.
  4810. var first = baseQueue.next;
  4811. var newState = current.baseState;
  4812. var newBaseState = null;
  4813. var newBaseQueueFirst = null;
  4814. var newBaseQueueLast = null;
  4815. var update = first;
  4816. do {
  4817. var updateExpirationTime = update.expirationTime;
  4818. if (updateExpirationTime < renderExpirationTime) {
  4819. // Priority is insufficient. Skip this update. If this is the first
  4820. // skipped update, the previous update/state is the new base
  4821. // update/state.
  4822. var clone = {
  4823. expirationTime: update.expirationTime,
  4824. suspenseConfig: update.suspenseConfig,
  4825. action: update.action,
  4826. eagerReducer: update.eagerReducer,
  4827. eagerState: update.eagerState,
  4828. next: null
  4829. };
  4830. if (newBaseQueueLast === null) {
  4831. newBaseQueueFirst = newBaseQueueLast = clone;
  4832. newBaseState = newState;
  4833. } else {
  4834. newBaseQueueLast = newBaseQueueLast.next = clone;
  4835. } // Update the remaining priority in the queue.
  4836. if (updateExpirationTime > currentlyRenderingFiber$1.expirationTime) {
  4837. currentlyRenderingFiber$1.expirationTime = updateExpirationTime;
  4838. markUnprocessedUpdateTime(updateExpirationTime);
  4839. }
  4840. } else {
  4841. // This update does have sufficient priority.
  4842. if (newBaseQueueLast !== null) {
  4843. var _clone = {
  4844. expirationTime: Sync,
  4845. // This update is going to be committed so we never want uncommit it.
  4846. suspenseConfig: update.suspenseConfig,
  4847. action: update.action,
  4848. eagerReducer: update.eagerReducer,
  4849. eagerState: update.eagerState,
  4850. next: null
  4851. };
  4852. newBaseQueueLast = newBaseQueueLast.next = _clone;
  4853. } // Mark the event time of this update as relevant to this render pass.
  4854. // TODO: This should ideally use the true event time of this update rather than
  4855. // its priority which is a derived and not reverseable value.
  4856. // TODO: We should skip this update if it was already committed but currently
  4857. // we have no way of detecting the difference between a committed and suspended
  4858. // update here.
  4859. markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process this update.
  4860. if (update.eagerReducer === reducer) {
  4861. // If this update was processed eagerly, and its reducer matches the
  4862. // current reducer, we can use the eagerly computed state.
  4863. newState = update.eagerState;
  4864. } else {
  4865. var action = update.action;
  4866. newState = reducer(newState, action);
  4867. }
  4868. }
  4869. update = update.next;
  4870. } while (update !== null && update !== first);
  4871. if (newBaseQueueLast === null) {
  4872. newBaseState = newState;
  4873. } else {
  4874. newBaseQueueLast.next = newBaseQueueFirst;
  4875. } // Mark that the fiber performed work, but only if the new state is
  4876. // different from the current state.
  4877. if (!objectIs(newState, hook.memoizedState)) {
  4878. markWorkInProgressReceivedUpdate();
  4879. }
  4880. hook.memoizedState = newState;
  4881. hook.baseState = newBaseState;
  4882. hook.baseQueue = newBaseQueueLast;
  4883. queue.lastRenderedState = newState;
  4884. }
  4885. var dispatch = queue.dispatch;
  4886. return [hook.memoizedState, dispatch];
  4887. }
  4888. function rerenderReducer(reducer, initialArg, init) {
  4889. var hook = updateWorkInProgressHook();
  4890. var queue = hook.queue;
  4891. if (!(queue !== null)) {
  4892. {
  4893. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  4894. }
  4895. }
  4896. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  4897. // work-in-progress hook.
  4898. var dispatch = queue.dispatch;
  4899. var lastRenderPhaseUpdate = queue.pending;
  4900. var newState = hook.memoizedState;
  4901. if (lastRenderPhaseUpdate !== null) {
  4902. // The queue doesn't persist past this render pass.
  4903. queue.pending = null;
  4904. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  4905. var update = firstRenderPhaseUpdate;
  4906. do {
  4907. // Process this render phase update. We don't have to check the
  4908. // priority because it will always be the same as the current
  4909. // render's.
  4910. var action = update.action;
  4911. newState = reducer(newState, action);
  4912. update = update.next;
  4913. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  4914. // different from the current state.
  4915. if (!objectIs(newState, hook.memoizedState)) {
  4916. markWorkInProgressReceivedUpdate();
  4917. }
  4918. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  4919. // the base state unless the queue is empty.
  4920. // TODO: Not sure if this is the desired semantics, but it's what we
  4921. // do for gDSFP. I can't remember why.
  4922. if (hook.baseQueue === null) {
  4923. hook.baseState = newState;
  4924. }
  4925. queue.lastRenderedState = newState;
  4926. }
  4927. return [newState, dispatch];
  4928. }
  4929. function mountState(initialState) {
  4930. var hook = mountWorkInProgressHook();
  4931. if (typeof initialState === 'function') {
  4932. // $FlowFixMe: Flow doesn't like mixed types
  4933. initialState = initialState();
  4934. }
  4935. hook.memoizedState = hook.baseState = initialState;
  4936. var queue = hook.queue = {
  4937. pending: null,
  4938. dispatch: null,
  4939. lastRenderedReducer: basicStateReducer,
  4940. lastRenderedState: initialState
  4941. };
  4942. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  4943. return [hook.memoizedState, dispatch];
  4944. }
  4945. function updateState(initialState) {
  4946. return updateReducer(basicStateReducer);
  4947. }
  4948. function rerenderState(initialState) {
  4949. return rerenderReducer(basicStateReducer);
  4950. }
  4951. function pushEffect(tag, create, destroy, deps) {
  4952. var effect = {
  4953. tag: tag,
  4954. create: create,
  4955. destroy: destroy,
  4956. deps: deps,
  4957. // Circular
  4958. next: null
  4959. };
  4960. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  4961. if (componentUpdateQueue === null) {
  4962. componentUpdateQueue = createFunctionComponentUpdateQueue();
  4963. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  4964. componentUpdateQueue.lastEffect = effect.next = effect;
  4965. } else {
  4966. var lastEffect = componentUpdateQueue.lastEffect;
  4967. if (lastEffect === null) {
  4968. componentUpdateQueue.lastEffect = effect.next = effect;
  4969. } else {
  4970. var firstEffect = lastEffect.next;
  4971. lastEffect.next = effect;
  4972. effect.next = firstEffect;
  4973. componentUpdateQueue.lastEffect = effect;
  4974. }
  4975. }
  4976. return effect;
  4977. }
  4978. function mountRef(initialValue) {
  4979. var hook = mountWorkInProgressHook();
  4980. var ref = {
  4981. current: initialValue
  4982. };
  4983. {
  4984. Object.seal(ref);
  4985. }
  4986. hook.memoizedState = ref;
  4987. return ref;
  4988. }
  4989. function updateRef(initialValue) {
  4990. var hook = updateWorkInProgressHook();
  4991. return hook.memoizedState;
  4992. }
  4993. function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  4994. var hook = mountWorkInProgressHook();
  4995. var nextDeps = deps === undefined ? null : deps;
  4996. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  4997. hook.memoizedState = pushEffect(HasEffect | hookEffectTag, create, undefined, nextDeps);
  4998. }
  4999. function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  5000. var hook = updateWorkInProgressHook();
  5001. var nextDeps = deps === undefined ? null : deps;
  5002. var destroy = undefined;
  5003. if (currentHook !== null) {
  5004. var prevEffect = currentHook.memoizedState;
  5005. destroy = prevEffect.destroy;
  5006. if (nextDeps !== null) {
  5007. var prevDeps = prevEffect.deps;
  5008. if (areHookInputsEqual(nextDeps, prevDeps)) {
  5009. pushEffect(hookEffectTag, create, destroy, nextDeps);
  5010. return;
  5011. }
  5012. }
  5013. }
  5014. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  5015. hook.memoizedState = pushEffect(HasEffect | hookEffectTag, create, destroy, nextDeps);
  5016. }
  5017. function mountEffect(create, deps) {
  5018. {
  5019. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  5020. if ('undefined' !== typeof jest) {
  5021. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  5022. }
  5023. }
  5024. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  5025. }
  5026. function updateEffect(create, deps) {
  5027. {
  5028. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  5029. if ('undefined' !== typeof jest) {
  5030. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  5031. }
  5032. }
  5033. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  5034. }
  5035. function mountLayoutEffect(create, deps) {
  5036. return mountEffectImpl(Update, Layout, create, deps);
  5037. }
  5038. function updateLayoutEffect(create, deps) {
  5039. return updateEffectImpl(Update, Layout, create, deps);
  5040. }
  5041. function imperativeHandleEffect(create, ref) {
  5042. if (typeof ref === 'function') {
  5043. var refCallback = ref;
  5044. var _inst = create();
  5045. refCallback(_inst);
  5046. return function () {
  5047. refCallback(null);
  5048. };
  5049. } else if (ref !== null && ref !== undefined) {
  5050. var refObject = ref;
  5051. {
  5052. if (!refObject.hasOwnProperty('current')) {
  5053. 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(', ') + '}');
  5054. }
  5055. }
  5056. var _inst2 = create();
  5057. refObject.current = _inst2;
  5058. return function () {
  5059. refObject.current = null;
  5060. };
  5061. }
  5062. }
  5063. function mountImperativeHandle(ref, create, deps) {
  5064. {
  5065. if (typeof create !== 'function') {
  5066. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  5067. }
  5068. } // TODO: If deps are provided, should we skip comparing the ref itself?
  5069. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  5070. return mountEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  5071. }
  5072. function updateImperativeHandle(ref, create, deps) {
  5073. {
  5074. if (typeof create !== 'function') {
  5075. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  5076. }
  5077. } // TODO: If deps are provided, should we skip comparing the ref itself?
  5078. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  5079. return updateEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  5080. }
  5081. function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
  5082. // The react-debug-hooks package injects its own implementation
  5083. // so that e.g. DevTools can display custom hook values.
  5084. }
  5085. var updateDebugValue = mountDebugValue;
  5086. function mountCallback(callback, deps) {
  5087. var hook = mountWorkInProgressHook();
  5088. var nextDeps = deps === undefined ? null : deps;
  5089. hook.memoizedState = [callback, nextDeps];
  5090. return callback;
  5091. }
  5092. function updateCallback(callback, deps) {
  5093. var hook = updateWorkInProgressHook();
  5094. var nextDeps = deps === undefined ? null : deps;
  5095. var prevState = hook.memoizedState;
  5096. if (prevState !== null) {
  5097. if (nextDeps !== null) {
  5098. var prevDeps = prevState[1];
  5099. if (areHookInputsEqual(nextDeps, prevDeps)) {
  5100. return prevState[0];
  5101. }
  5102. }
  5103. }
  5104. hook.memoizedState = [callback, nextDeps];
  5105. return callback;
  5106. }
  5107. function mountMemo(nextCreate, deps) {
  5108. var hook = mountWorkInProgressHook();
  5109. var nextDeps = deps === undefined ? null : deps;
  5110. var nextValue = nextCreate();
  5111. hook.memoizedState = [nextValue, nextDeps];
  5112. return nextValue;
  5113. }
  5114. function updateMemo(nextCreate, deps) {
  5115. var hook = updateWorkInProgressHook();
  5116. var nextDeps = deps === undefined ? null : deps;
  5117. var prevState = hook.memoizedState;
  5118. if (prevState !== null) {
  5119. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  5120. if (nextDeps !== null) {
  5121. var prevDeps = prevState[1];
  5122. if (areHookInputsEqual(nextDeps, prevDeps)) {
  5123. return prevState[0];
  5124. }
  5125. }
  5126. }
  5127. var nextValue = nextCreate();
  5128. hook.memoizedState = [nextValue, nextDeps];
  5129. return nextValue;
  5130. }
  5131. function mountDeferredValue(value, config) {
  5132. var _mountState = mountState(value),
  5133. prevValue = _mountState[0],
  5134. setValue = _mountState[1];
  5135. mountEffect(function () {
  5136. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5137. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5138. try {
  5139. setValue(value);
  5140. } finally {
  5141. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5142. }
  5143. }, [value, config]);
  5144. return prevValue;
  5145. }
  5146. function updateDeferredValue(value, config) {
  5147. var _updateState = updateState(),
  5148. prevValue = _updateState[0],
  5149. setValue = _updateState[1];
  5150. updateEffect(function () {
  5151. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5152. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5153. try {
  5154. setValue(value);
  5155. } finally {
  5156. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5157. }
  5158. }, [value, config]);
  5159. return prevValue;
  5160. }
  5161. function rerenderDeferredValue(value, config) {
  5162. var _rerenderState = rerenderState(),
  5163. prevValue = _rerenderState[0],
  5164. setValue = _rerenderState[1];
  5165. updateEffect(function () {
  5166. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5167. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5168. try {
  5169. setValue(value);
  5170. } finally {
  5171. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5172. }
  5173. }, [value, config]);
  5174. return prevValue;
  5175. }
  5176. function startTransition(setPending, config, callback) {
  5177. var priorityLevel = getCurrentPriorityLevel();
  5178. runWithPriority(priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, function () {
  5179. setPending(true);
  5180. });
  5181. runWithPriority(priorityLevel > NormalPriority ? NormalPriority : priorityLevel, function () {
  5182. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5183. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5184. try {
  5185. setPending(false);
  5186. callback();
  5187. } finally {
  5188. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5189. }
  5190. });
  5191. }
  5192. function mountTransition(config) {
  5193. var _mountState2 = mountState(false),
  5194. isPending = _mountState2[0],
  5195. setPending = _mountState2[1];
  5196. var start = mountCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  5197. return [start, isPending];
  5198. }
  5199. function updateTransition(config) {
  5200. var _updateState2 = updateState(),
  5201. isPending = _updateState2[0],
  5202. setPending = _updateState2[1];
  5203. var start = updateCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  5204. return [start, isPending];
  5205. }
  5206. function rerenderTransition(config) {
  5207. var _rerenderState2 = rerenderState(),
  5208. isPending = _rerenderState2[0],
  5209. setPending = _rerenderState2[1];
  5210. var start = updateCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  5211. return [start, isPending];
  5212. }
  5213. function dispatchAction(fiber, queue, action) {
  5214. {
  5215. if (typeof arguments[3] === 'function') {
  5216. 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().');
  5217. }
  5218. }
  5219. var currentTime = requestCurrentTimeForUpdate();
  5220. var suspenseConfig = requestCurrentSuspenseConfig();
  5221. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  5222. var update = {
  5223. expirationTime: expirationTime,
  5224. suspenseConfig: suspenseConfig,
  5225. action: action,
  5226. eagerReducer: null,
  5227. eagerState: null,
  5228. next: null
  5229. };
  5230. {
  5231. update.priority = getCurrentPriorityLevel();
  5232. } // Append the update to the end of the list.
  5233. var pending = queue.pending;
  5234. if (pending === null) {
  5235. // This is the first update. Create a circular list.
  5236. update.next = update;
  5237. } else {
  5238. update.next = pending.next;
  5239. pending.next = update;
  5240. }
  5241. queue.pending = update;
  5242. var alternate = fiber.alternate;
  5243. if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
  5244. // This is a render phase update. Stash it in a lazily-created map of
  5245. // queue -> linked list of updates. After this render pass, we'll restart
  5246. // and apply the stashed updates on top of the work-in-progress hook.
  5247. didScheduleRenderPhaseUpdate = true;
  5248. update.expirationTime = renderExpirationTime;
  5249. currentlyRenderingFiber$1.expirationTime = renderExpirationTime;
  5250. } else {
  5251. if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
  5252. // The queue is currently empty, which means we can eagerly compute the
  5253. // next state before entering the render phase. If the new state is the
  5254. // same as the current state, we may be able to bail out entirely.
  5255. var lastRenderedReducer = queue.lastRenderedReducer;
  5256. if (lastRenderedReducer !== null) {
  5257. var prevDispatcher;
  5258. {
  5259. prevDispatcher = ReactCurrentDispatcher.current;
  5260. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5261. }
  5262. try {
  5263. var currentState = queue.lastRenderedState;
  5264. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  5265. // it, on the update object. If the reducer hasn't changed by the
  5266. // time we enter the render phase, then the eager state can be used
  5267. // without calling the reducer again.
  5268. update.eagerReducer = lastRenderedReducer;
  5269. update.eagerState = eagerState;
  5270. if (objectIs(eagerState, currentState)) {
  5271. // Fast path. We can bail out without scheduling React to re-render.
  5272. // It's still possible that we'll need to rebase this update later,
  5273. // if the component re-renders for a different reason and by that
  5274. // time the reducer has changed.
  5275. return;
  5276. }
  5277. } catch (error) {// Suppress the error. It will throw again in the render phase.
  5278. } finally {
  5279. {
  5280. ReactCurrentDispatcher.current = prevDispatcher;
  5281. }
  5282. }
  5283. }
  5284. }
  5285. {
  5286. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  5287. if ('undefined' !== typeof jest) {
  5288. warnIfNotScopedWithMatchingAct(fiber);
  5289. warnIfNotCurrentlyActingUpdatesInDev(fiber);
  5290. }
  5291. }
  5292. scheduleWork(fiber, expirationTime);
  5293. }
  5294. }
  5295. var ContextOnlyDispatcher = {
  5296. readContext: readContext,
  5297. useCallback: throwInvalidHookError,
  5298. useContext: throwInvalidHookError,
  5299. useEffect: throwInvalidHookError,
  5300. useImperativeHandle: throwInvalidHookError,
  5301. useLayoutEffect: throwInvalidHookError,
  5302. useMemo: throwInvalidHookError,
  5303. useReducer: throwInvalidHookError,
  5304. useRef: throwInvalidHookError,
  5305. useState: throwInvalidHookError,
  5306. useDebugValue: throwInvalidHookError,
  5307. useResponder: throwInvalidHookError,
  5308. useDeferredValue: throwInvalidHookError,
  5309. useTransition: throwInvalidHookError
  5310. };
  5311. var HooksDispatcherOnMountInDEV = null;
  5312. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  5313. var HooksDispatcherOnUpdateInDEV = null;
  5314. var HooksDispatcherOnRerenderInDEV = null;
  5315. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  5316. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  5317. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  5318. {
  5319. var warnInvalidContextAccess = function () {
  5320. 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().');
  5321. };
  5322. var warnInvalidHookAccess = function () {
  5323. 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');
  5324. };
  5325. HooksDispatcherOnMountInDEV = {
  5326. readContext: function (context, observedBits) {
  5327. return readContext(context, observedBits);
  5328. },
  5329. useCallback: function (callback, deps) {
  5330. currentHookNameInDev = 'useCallback';
  5331. mountHookTypesDev();
  5332. checkDepsAreArrayDev(deps);
  5333. return mountCallback(callback, deps);
  5334. },
  5335. useContext: function (context, observedBits) {
  5336. currentHookNameInDev = 'useContext';
  5337. mountHookTypesDev();
  5338. return readContext(context, observedBits);
  5339. },
  5340. useEffect: function (create, deps) {
  5341. currentHookNameInDev = 'useEffect';
  5342. mountHookTypesDev();
  5343. checkDepsAreArrayDev(deps);
  5344. return mountEffect(create, deps);
  5345. },
  5346. useImperativeHandle: function (ref, create, deps) {
  5347. currentHookNameInDev = 'useImperativeHandle';
  5348. mountHookTypesDev();
  5349. checkDepsAreArrayDev(deps);
  5350. return mountImperativeHandle(ref, create, deps);
  5351. },
  5352. useLayoutEffect: function (create, deps) {
  5353. currentHookNameInDev = 'useLayoutEffect';
  5354. mountHookTypesDev();
  5355. checkDepsAreArrayDev(deps);
  5356. return mountLayoutEffect(create, deps);
  5357. },
  5358. useMemo: function (create, deps) {
  5359. currentHookNameInDev = 'useMemo';
  5360. mountHookTypesDev();
  5361. checkDepsAreArrayDev(deps);
  5362. var prevDispatcher = ReactCurrentDispatcher.current;
  5363. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5364. try {
  5365. return mountMemo(create, deps);
  5366. } finally {
  5367. ReactCurrentDispatcher.current = prevDispatcher;
  5368. }
  5369. },
  5370. useReducer: function (reducer, initialArg, init) {
  5371. currentHookNameInDev = 'useReducer';
  5372. mountHookTypesDev();
  5373. var prevDispatcher = ReactCurrentDispatcher.current;
  5374. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5375. try {
  5376. return mountReducer(reducer, initialArg, init);
  5377. } finally {
  5378. ReactCurrentDispatcher.current = prevDispatcher;
  5379. }
  5380. },
  5381. useRef: function (initialValue) {
  5382. currentHookNameInDev = 'useRef';
  5383. mountHookTypesDev();
  5384. return mountRef(initialValue);
  5385. },
  5386. useState: function (initialState) {
  5387. currentHookNameInDev = 'useState';
  5388. mountHookTypesDev();
  5389. var prevDispatcher = ReactCurrentDispatcher.current;
  5390. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5391. try {
  5392. return mountState(initialState);
  5393. } finally {
  5394. ReactCurrentDispatcher.current = prevDispatcher;
  5395. }
  5396. },
  5397. useDebugValue: function (value, formatterFn) {
  5398. currentHookNameInDev = 'useDebugValue';
  5399. mountHookTypesDev();
  5400. return mountDebugValue();
  5401. },
  5402. useResponder: function (responder, props) {
  5403. currentHookNameInDev = 'useResponder';
  5404. mountHookTypesDev();
  5405. return createDeprecatedResponderListener(responder, props);
  5406. },
  5407. useDeferredValue: function (value, config) {
  5408. currentHookNameInDev = 'useDeferredValue';
  5409. mountHookTypesDev();
  5410. return mountDeferredValue(value, config);
  5411. },
  5412. useTransition: function (config) {
  5413. currentHookNameInDev = 'useTransition';
  5414. mountHookTypesDev();
  5415. return mountTransition(config);
  5416. }
  5417. };
  5418. HooksDispatcherOnMountWithHookTypesInDEV = {
  5419. readContext: function (context, observedBits) {
  5420. return readContext(context, observedBits);
  5421. },
  5422. useCallback: function (callback, deps) {
  5423. currentHookNameInDev = 'useCallback';
  5424. updateHookTypesDev();
  5425. return mountCallback(callback, deps);
  5426. },
  5427. useContext: function (context, observedBits) {
  5428. currentHookNameInDev = 'useContext';
  5429. updateHookTypesDev();
  5430. return readContext(context, observedBits);
  5431. },
  5432. useEffect: function (create, deps) {
  5433. currentHookNameInDev = 'useEffect';
  5434. updateHookTypesDev();
  5435. return mountEffect(create, deps);
  5436. },
  5437. useImperativeHandle: function (ref, create, deps) {
  5438. currentHookNameInDev = 'useImperativeHandle';
  5439. updateHookTypesDev();
  5440. return mountImperativeHandle(ref, create, deps);
  5441. },
  5442. useLayoutEffect: function (create, deps) {
  5443. currentHookNameInDev = 'useLayoutEffect';
  5444. updateHookTypesDev();
  5445. return mountLayoutEffect(create, deps);
  5446. },
  5447. useMemo: function (create, deps) {
  5448. currentHookNameInDev = 'useMemo';
  5449. updateHookTypesDev();
  5450. var prevDispatcher = ReactCurrentDispatcher.current;
  5451. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5452. try {
  5453. return mountMemo(create, deps);
  5454. } finally {
  5455. ReactCurrentDispatcher.current = prevDispatcher;
  5456. }
  5457. },
  5458. useReducer: function (reducer, initialArg, init) {
  5459. currentHookNameInDev = 'useReducer';
  5460. updateHookTypesDev();
  5461. var prevDispatcher = ReactCurrentDispatcher.current;
  5462. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5463. try {
  5464. return mountReducer(reducer, initialArg, init);
  5465. } finally {
  5466. ReactCurrentDispatcher.current = prevDispatcher;
  5467. }
  5468. },
  5469. useRef: function (initialValue) {
  5470. currentHookNameInDev = 'useRef';
  5471. updateHookTypesDev();
  5472. return mountRef(initialValue);
  5473. },
  5474. useState: function (initialState) {
  5475. currentHookNameInDev = 'useState';
  5476. updateHookTypesDev();
  5477. var prevDispatcher = ReactCurrentDispatcher.current;
  5478. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5479. try {
  5480. return mountState(initialState);
  5481. } finally {
  5482. ReactCurrentDispatcher.current = prevDispatcher;
  5483. }
  5484. },
  5485. useDebugValue: function (value, formatterFn) {
  5486. currentHookNameInDev = 'useDebugValue';
  5487. updateHookTypesDev();
  5488. return mountDebugValue();
  5489. },
  5490. useResponder: function (responder, props) {
  5491. currentHookNameInDev = 'useResponder';
  5492. updateHookTypesDev();
  5493. return createDeprecatedResponderListener(responder, props);
  5494. },
  5495. useDeferredValue: function (value, config) {
  5496. currentHookNameInDev = 'useDeferredValue';
  5497. updateHookTypesDev();
  5498. return mountDeferredValue(value, config);
  5499. },
  5500. useTransition: function (config) {
  5501. currentHookNameInDev = 'useTransition';
  5502. updateHookTypesDev();
  5503. return mountTransition(config);
  5504. }
  5505. };
  5506. HooksDispatcherOnUpdateInDEV = {
  5507. readContext: function (context, observedBits) {
  5508. return readContext(context, observedBits);
  5509. },
  5510. useCallback: function (callback, deps) {
  5511. currentHookNameInDev = 'useCallback';
  5512. updateHookTypesDev();
  5513. return updateCallback(callback, deps);
  5514. },
  5515. useContext: function (context, observedBits) {
  5516. currentHookNameInDev = 'useContext';
  5517. updateHookTypesDev();
  5518. return readContext(context, observedBits);
  5519. },
  5520. useEffect: function (create, deps) {
  5521. currentHookNameInDev = 'useEffect';
  5522. updateHookTypesDev();
  5523. return updateEffect(create, deps);
  5524. },
  5525. useImperativeHandle: function (ref, create, deps) {
  5526. currentHookNameInDev = 'useImperativeHandle';
  5527. updateHookTypesDev();
  5528. return updateImperativeHandle(ref, create, deps);
  5529. },
  5530. useLayoutEffect: function (create, deps) {
  5531. currentHookNameInDev = 'useLayoutEffect';
  5532. updateHookTypesDev();
  5533. return updateLayoutEffect(create, deps);
  5534. },
  5535. useMemo: function (create, deps) {
  5536. currentHookNameInDev = 'useMemo';
  5537. updateHookTypesDev();
  5538. var prevDispatcher = ReactCurrentDispatcher.current;
  5539. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5540. try {
  5541. return updateMemo(create, deps);
  5542. } finally {
  5543. ReactCurrentDispatcher.current = prevDispatcher;
  5544. }
  5545. },
  5546. useReducer: function (reducer, initialArg, init) {
  5547. currentHookNameInDev = 'useReducer';
  5548. updateHookTypesDev();
  5549. var prevDispatcher = ReactCurrentDispatcher.current;
  5550. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5551. try {
  5552. return updateReducer(reducer, initialArg, init);
  5553. } finally {
  5554. ReactCurrentDispatcher.current = prevDispatcher;
  5555. }
  5556. },
  5557. useRef: function (initialValue) {
  5558. currentHookNameInDev = 'useRef';
  5559. updateHookTypesDev();
  5560. return updateRef();
  5561. },
  5562. useState: function (initialState) {
  5563. currentHookNameInDev = 'useState';
  5564. updateHookTypesDev();
  5565. var prevDispatcher = ReactCurrentDispatcher.current;
  5566. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5567. try {
  5568. return updateState(initialState);
  5569. } finally {
  5570. ReactCurrentDispatcher.current = prevDispatcher;
  5571. }
  5572. },
  5573. useDebugValue: function (value, formatterFn) {
  5574. currentHookNameInDev = 'useDebugValue';
  5575. updateHookTypesDev();
  5576. return updateDebugValue();
  5577. },
  5578. useResponder: function (responder, props) {
  5579. currentHookNameInDev = 'useResponder';
  5580. updateHookTypesDev();
  5581. return createDeprecatedResponderListener(responder, props);
  5582. },
  5583. useDeferredValue: function (value, config) {
  5584. currentHookNameInDev = 'useDeferredValue';
  5585. updateHookTypesDev();
  5586. return updateDeferredValue(value, config);
  5587. },
  5588. useTransition: function (config) {
  5589. currentHookNameInDev = 'useTransition';
  5590. updateHookTypesDev();
  5591. return updateTransition(config);
  5592. }
  5593. };
  5594. HooksDispatcherOnRerenderInDEV = {
  5595. readContext: function (context, observedBits) {
  5596. return readContext(context, observedBits);
  5597. },
  5598. useCallback: function (callback, deps) {
  5599. currentHookNameInDev = 'useCallback';
  5600. updateHookTypesDev();
  5601. return updateCallback(callback, deps);
  5602. },
  5603. useContext: function (context, observedBits) {
  5604. currentHookNameInDev = 'useContext';
  5605. updateHookTypesDev();
  5606. return readContext(context, observedBits);
  5607. },
  5608. useEffect: function (create, deps) {
  5609. currentHookNameInDev = 'useEffect';
  5610. updateHookTypesDev();
  5611. return updateEffect(create, deps);
  5612. },
  5613. useImperativeHandle: function (ref, create, deps) {
  5614. currentHookNameInDev = 'useImperativeHandle';
  5615. updateHookTypesDev();
  5616. return updateImperativeHandle(ref, create, deps);
  5617. },
  5618. useLayoutEffect: function (create, deps) {
  5619. currentHookNameInDev = 'useLayoutEffect';
  5620. updateHookTypesDev();
  5621. return updateLayoutEffect(create, deps);
  5622. },
  5623. useMemo: function (create, deps) {
  5624. currentHookNameInDev = 'useMemo';
  5625. updateHookTypesDev();
  5626. var prevDispatcher = ReactCurrentDispatcher.current;
  5627. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  5628. try {
  5629. return updateMemo(create, deps);
  5630. } finally {
  5631. ReactCurrentDispatcher.current = prevDispatcher;
  5632. }
  5633. },
  5634. useReducer: function (reducer, initialArg, init) {
  5635. currentHookNameInDev = 'useReducer';
  5636. updateHookTypesDev();
  5637. var prevDispatcher = ReactCurrentDispatcher.current;
  5638. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  5639. try {
  5640. return rerenderReducer(reducer, initialArg, init);
  5641. } finally {
  5642. ReactCurrentDispatcher.current = prevDispatcher;
  5643. }
  5644. },
  5645. useRef: function (initialValue) {
  5646. currentHookNameInDev = 'useRef';
  5647. updateHookTypesDev();
  5648. return updateRef();
  5649. },
  5650. useState: function (initialState) {
  5651. currentHookNameInDev = 'useState';
  5652. updateHookTypesDev();
  5653. var prevDispatcher = ReactCurrentDispatcher.current;
  5654. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  5655. try {
  5656. return rerenderState(initialState);
  5657. } finally {
  5658. ReactCurrentDispatcher.current = prevDispatcher;
  5659. }
  5660. },
  5661. useDebugValue: function (value, formatterFn) {
  5662. currentHookNameInDev = 'useDebugValue';
  5663. updateHookTypesDev();
  5664. return updateDebugValue();
  5665. },
  5666. useResponder: function (responder, props) {
  5667. currentHookNameInDev = 'useResponder';
  5668. updateHookTypesDev();
  5669. return createDeprecatedResponderListener(responder, props);
  5670. },
  5671. useDeferredValue: function (value, config) {
  5672. currentHookNameInDev = 'useDeferredValue';
  5673. updateHookTypesDev();
  5674. return rerenderDeferredValue(value, config);
  5675. },
  5676. useTransition: function (config) {
  5677. currentHookNameInDev = 'useTransition';
  5678. updateHookTypesDev();
  5679. return rerenderTransition(config);
  5680. }
  5681. };
  5682. InvalidNestedHooksDispatcherOnMountInDEV = {
  5683. readContext: function (context, observedBits) {
  5684. warnInvalidContextAccess();
  5685. return readContext(context, observedBits);
  5686. },
  5687. useCallback: function (callback, deps) {
  5688. currentHookNameInDev = 'useCallback';
  5689. warnInvalidHookAccess();
  5690. mountHookTypesDev();
  5691. return mountCallback(callback, deps);
  5692. },
  5693. useContext: function (context, observedBits) {
  5694. currentHookNameInDev = 'useContext';
  5695. warnInvalidHookAccess();
  5696. mountHookTypesDev();
  5697. return readContext(context, observedBits);
  5698. },
  5699. useEffect: function (create, deps) {
  5700. currentHookNameInDev = 'useEffect';
  5701. warnInvalidHookAccess();
  5702. mountHookTypesDev();
  5703. return mountEffect(create, deps);
  5704. },
  5705. useImperativeHandle: function (ref, create, deps) {
  5706. currentHookNameInDev = 'useImperativeHandle';
  5707. warnInvalidHookAccess();
  5708. mountHookTypesDev();
  5709. return mountImperativeHandle(ref, create, deps);
  5710. },
  5711. useLayoutEffect: function (create, deps) {
  5712. currentHookNameInDev = 'useLayoutEffect';
  5713. warnInvalidHookAccess();
  5714. mountHookTypesDev();
  5715. return mountLayoutEffect(create, deps);
  5716. },
  5717. useMemo: function (create, deps) {
  5718. currentHookNameInDev = 'useMemo';
  5719. warnInvalidHookAccess();
  5720. mountHookTypesDev();
  5721. var prevDispatcher = ReactCurrentDispatcher.current;
  5722. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5723. try {
  5724. return mountMemo(create, deps);
  5725. } finally {
  5726. ReactCurrentDispatcher.current = prevDispatcher;
  5727. }
  5728. },
  5729. useReducer: function (reducer, initialArg, init) {
  5730. currentHookNameInDev = 'useReducer';
  5731. warnInvalidHookAccess();
  5732. mountHookTypesDev();
  5733. var prevDispatcher = ReactCurrentDispatcher.current;
  5734. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5735. try {
  5736. return mountReducer(reducer, initialArg, init);
  5737. } finally {
  5738. ReactCurrentDispatcher.current = prevDispatcher;
  5739. }
  5740. },
  5741. useRef: function (initialValue) {
  5742. currentHookNameInDev = 'useRef';
  5743. warnInvalidHookAccess();
  5744. mountHookTypesDev();
  5745. return mountRef(initialValue);
  5746. },
  5747. useState: function (initialState) {
  5748. currentHookNameInDev = 'useState';
  5749. warnInvalidHookAccess();
  5750. mountHookTypesDev();
  5751. var prevDispatcher = ReactCurrentDispatcher.current;
  5752. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5753. try {
  5754. return mountState(initialState);
  5755. } finally {
  5756. ReactCurrentDispatcher.current = prevDispatcher;
  5757. }
  5758. },
  5759. useDebugValue: function (value, formatterFn) {
  5760. currentHookNameInDev = 'useDebugValue';
  5761. warnInvalidHookAccess();
  5762. mountHookTypesDev();
  5763. return mountDebugValue();
  5764. },
  5765. useResponder: function (responder, props) {
  5766. currentHookNameInDev = 'useResponder';
  5767. warnInvalidHookAccess();
  5768. mountHookTypesDev();
  5769. return createDeprecatedResponderListener(responder, props);
  5770. },
  5771. useDeferredValue: function (value, config) {
  5772. currentHookNameInDev = 'useDeferredValue';
  5773. warnInvalidHookAccess();
  5774. mountHookTypesDev();
  5775. return mountDeferredValue(value, config);
  5776. },
  5777. useTransition: function (config) {
  5778. currentHookNameInDev = 'useTransition';
  5779. warnInvalidHookAccess();
  5780. mountHookTypesDev();
  5781. return mountTransition(config);
  5782. }
  5783. };
  5784. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  5785. readContext: function (context, observedBits) {
  5786. warnInvalidContextAccess();
  5787. return readContext(context, observedBits);
  5788. },
  5789. useCallback: function (callback, deps) {
  5790. currentHookNameInDev = 'useCallback';
  5791. warnInvalidHookAccess();
  5792. updateHookTypesDev();
  5793. return updateCallback(callback, deps);
  5794. },
  5795. useContext: function (context, observedBits) {
  5796. currentHookNameInDev = 'useContext';
  5797. warnInvalidHookAccess();
  5798. updateHookTypesDev();
  5799. return readContext(context, observedBits);
  5800. },
  5801. useEffect: function (create, deps) {
  5802. currentHookNameInDev = 'useEffect';
  5803. warnInvalidHookAccess();
  5804. updateHookTypesDev();
  5805. return updateEffect(create, deps);
  5806. },
  5807. useImperativeHandle: function (ref, create, deps) {
  5808. currentHookNameInDev = 'useImperativeHandle';
  5809. warnInvalidHookAccess();
  5810. updateHookTypesDev();
  5811. return updateImperativeHandle(ref, create, deps);
  5812. },
  5813. useLayoutEffect: function (create, deps) {
  5814. currentHookNameInDev = 'useLayoutEffect';
  5815. warnInvalidHookAccess();
  5816. updateHookTypesDev();
  5817. return updateLayoutEffect(create, deps);
  5818. },
  5819. useMemo: function (create, deps) {
  5820. currentHookNameInDev = 'useMemo';
  5821. warnInvalidHookAccess();
  5822. updateHookTypesDev();
  5823. var prevDispatcher = ReactCurrentDispatcher.current;
  5824. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5825. try {
  5826. return updateMemo(create, deps);
  5827. } finally {
  5828. ReactCurrentDispatcher.current = prevDispatcher;
  5829. }
  5830. },
  5831. useReducer: function (reducer, initialArg, init) {
  5832. currentHookNameInDev = 'useReducer';
  5833. warnInvalidHookAccess();
  5834. updateHookTypesDev();
  5835. var prevDispatcher = ReactCurrentDispatcher.current;
  5836. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5837. try {
  5838. return updateReducer(reducer, initialArg, init);
  5839. } finally {
  5840. ReactCurrentDispatcher.current = prevDispatcher;
  5841. }
  5842. },
  5843. useRef: function (initialValue) {
  5844. currentHookNameInDev = 'useRef';
  5845. warnInvalidHookAccess();
  5846. updateHookTypesDev();
  5847. return updateRef();
  5848. },
  5849. useState: function (initialState) {
  5850. currentHookNameInDev = 'useState';
  5851. warnInvalidHookAccess();
  5852. updateHookTypesDev();
  5853. var prevDispatcher = ReactCurrentDispatcher.current;
  5854. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5855. try {
  5856. return updateState(initialState);
  5857. } finally {
  5858. ReactCurrentDispatcher.current = prevDispatcher;
  5859. }
  5860. },
  5861. useDebugValue: function (value, formatterFn) {
  5862. currentHookNameInDev = 'useDebugValue';
  5863. warnInvalidHookAccess();
  5864. updateHookTypesDev();
  5865. return updateDebugValue();
  5866. },
  5867. useResponder: function (responder, props) {
  5868. currentHookNameInDev = 'useResponder';
  5869. warnInvalidHookAccess();
  5870. updateHookTypesDev();
  5871. return createDeprecatedResponderListener(responder, props);
  5872. },
  5873. useDeferredValue: function (value, config) {
  5874. currentHookNameInDev = 'useDeferredValue';
  5875. warnInvalidHookAccess();
  5876. updateHookTypesDev();
  5877. return updateDeferredValue(value, config);
  5878. },
  5879. useTransition: function (config) {
  5880. currentHookNameInDev = 'useTransition';
  5881. warnInvalidHookAccess();
  5882. updateHookTypesDev();
  5883. return updateTransition(config);
  5884. }
  5885. };
  5886. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  5887. readContext: function (context, observedBits) {
  5888. warnInvalidContextAccess();
  5889. return readContext(context, observedBits);
  5890. },
  5891. useCallback: function (callback, deps) {
  5892. currentHookNameInDev = 'useCallback';
  5893. warnInvalidHookAccess();
  5894. updateHookTypesDev();
  5895. return updateCallback(callback, deps);
  5896. },
  5897. useContext: function (context, observedBits) {
  5898. currentHookNameInDev = 'useContext';
  5899. warnInvalidHookAccess();
  5900. updateHookTypesDev();
  5901. return readContext(context, observedBits);
  5902. },
  5903. useEffect: function (create, deps) {
  5904. currentHookNameInDev = 'useEffect';
  5905. warnInvalidHookAccess();
  5906. updateHookTypesDev();
  5907. return updateEffect(create, deps);
  5908. },
  5909. useImperativeHandle: function (ref, create, deps) {
  5910. currentHookNameInDev = 'useImperativeHandle';
  5911. warnInvalidHookAccess();
  5912. updateHookTypesDev();
  5913. return updateImperativeHandle(ref, create, deps);
  5914. },
  5915. useLayoutEffect: function (create, deps) {
  5916. currentHookNameInDev = 'useLayoutEffect';
  5917. warnInvalidHookAccess();
  5918. updateHookTypesDev();
  5919. return updateLayoutEffect(create, deps);
  5920. },
  5921. useMemo: function (create, deps) {
  5922. currentHookNameInDev = 'useMemo';
  5923. warnInvalidHookAccess();
  5924. updateHookTypesDev();
  5925. var prevDispatcher = ReactCurrentDispatcher.current;
  5926. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5927. try {
  5928. return updateMemo(create, deps);
  5929. } finally {
  5930. ReactCurrentDispatcher.current = prevDispatcher;
  5931. }
  5932. },
  5933. useReducer: function (reducer, initialArg, init) {
  5934. currentHookNameInDev = 'useReducer';
  5935. warnInvalidHookAccess();
  5936. updateHookTypesDev();
  5937. var prevDispatcher = ReactCurrentDispatcher.current;
  5938. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5939. try {
  5940. return rerenderReducer(reducer, initialArg, init);
  5941. } finally {
  5942. ReactCurrentDispatcher.current = prevDispatcher;
  5943. }
  5944. },
  5945. useRef: function (initialValue) {
  5946. currentHookNameInDev = 'useRef';
  5947. warnInvalidHookAccess();
  5948. updateHookTypesDev();
  5949. return updateRef();
  5950. },
  5951. useState: function (initialState) {
  5952. currentHookNameInDev = 'useState';
  5953. warnInvalidHookAccess();
  5954. updateHookTypesDev();
  5955. var prevDispatcher = ReactCurrentDispatcher.current;
  5956. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5957. try {
  5958. return rerenderState(initialState);
  5959. } finally {
  5960. ReactCurrentDispatcher.current = prevDispatcher;
  5961. }
  5962. },
  5963. useDebugValue: function (value, formatterFn) {
  5964. currentHookNameInDev = 'useDebugValue';
  5965. warnInvalidHookAccess();
  5966. updateHookTypesDev();
  5967. return updateDebugValue();
  5968. },
  5969. useResponder: function (responder, props) {
  5970. currentHookNameInDev = 'useResponder';
  5971. warnInvalidHookAccess();
  5972. updateHookTypesDev();
  5973. return createDeprecatedResponderListener(responder, props);
  5974. },
  5975. useDeferredValue: function (value, config) {
  5976. currentHookNameInDev = 'useDeferredValue';
  5977. warnInvalidHookAccess();
  5978. updateHookTypesDev();
  5979. return rerenderDeferredValue(value, config);
  5980. },
  5981. useTransition: function (config) {
  5982. currentHookNameInDev = 'useTransition';
  5983. warnInvalidHookAccess();
  5984. updateHookTypesDev();
  5985. return rerenderTransition(config);
  5986. }
  5987. };
  5988. }
  5989. var now$1 = Scheduler$1.unstable_now;
  5990. var commitTime = 0;
  5991. var profilerStartTime = -1;
  5992. function getCommitTime() {
  5993. return commitTime;
  5994. }
  5995. function recordCommitTime() {
  5996. commitTime = now$1();
  5997. }
  5998. function startProfilerTimer(fiber) {
  5999. profilerStartTime = now$1();
  6000. if (fiber.actualStartTime < 0) {
  6001. fiber.actualStartTime = now$1();
  6002. }
  6003. }
  6004. function stopProfilerTimerIfRunning(fiber) {
  6005. profilerStartTime = -1;
  6006. }
  6007. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  6008. if (profilerStartTime >= 0) {
  6009. var elapsedTime = now$1() - profilerStartTime;
  6010. fiber.actualDuration += elapsedTime;
  6011. if (overrideBaseTime) {
  6012. fiber.selfBaseDuration = elapsedTime;
  6013. }
  6014. profilerStartTime = -1;
  6015. }
  6016. }
  6017. function enterHydrationState(fiber) {
  6018. {
  6019. return false;
  6020. }
  6021. }
  6022. function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
  6023. {
  6024. {
  6025. {
  6026. throw Error( "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." );
  6027. }
  6028. }
  6029. }
  6030. }
  6031. function prepareToHydrateHostTextInstance(fiber) {
  6032. {
  6033. {
  6034. {
  6035. throw Error( "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." );
  6036. }
  6037. }
  6038. }
  6039. var shouldUpdate = hydrateTextInstance();
  6040. }
  6041. function popHydrationState(fiber) {
  6042. {
  6043. return false;
  6044. }
  6045. }
  6046. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  6047. var didReceiveUpdate = false;
  6048. var didWarnAboutBadClass;
  6049. var didWarnAboutModulePatternComponent;
  6050. var didWarnAboutContextTypeOnFunctionComponent;
  6051. var didWarnAboutGetDerivedStateOnFunctionComponent;
  6052. var didWarnAboutFunctionRefs;
  6053. var didWarnAboutReassigningProps;
  6054. var didWarnAboutRevealOrder;
  6055. var didWarnAboutTailOptions;
  6056. {
  6057. didWarnAboutBadClass = {};
  6058. didWarnAboutModulePatternComponent = {};
  6059. didWarnAboutContextTypeOnFunctionComponent = {};
  6060. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  6061. didWarnAboutFunctionRefs = {};
  6062. didWarnAboutReassigningProps = false;
  6063. didWarnAboutRevealOrder = {};
  6064. didWarnAboutTailOptions = {};
  6065. }
  6066. function reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime) {
  6067. if (current === null) {
  6068. // If this is a fresh new component that hasn't been rendered yet, we
  6069. // won't update its child set by applying minimal side-effects. Instead,
  6070. // we will add them all to the child before it gets rendered. That means
  6071. // we can optimize this reconciliation pass by not tracking side-effects.
  6072. workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  6073. } else {
  6074. // If the current child is the same as the work in progress, it means that
  6075. // we haven't yet started any work on these children. Therefore, we use
  6076. // the clone algorithm to create a copy of all the current children.
  6077. // If we had any progressed work already, that is invalid at this point so
  6078. // let's throw it out.
  6079. workInProgress.child = reconcileChildFibers(workInProgress, current.child, nextChildren, renderExpirationTime);
  6080. }
  6081. }
  6082. function forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderExpirationTime) {
  6083. // This function is fork of reconcileChildren. It's used in cases where we
  6084. // want to reconcile without matching against the existing set. This has the
  6085. // effect of all current children being unmounted; even if the type and key
  6086. // are the same, the old child is unmounted and a new child is created.
  6087. //
  6088. // To do this, we're going to go through the reconcile algorithm twice. In
  6089. // the first pass, we schedule a deletion for all the current children by
  6090. // passing null.
  6091. workInProgress.child = reconcileChildFibers(workInProgress, current.child, null, renderExpirationTime); // In the second pass, we mount the new children. The trick here is that we
  6092. // pass null in place of where we usually pass the current child set. This has
  6093. // the effect of remounting all children regardless of whether their
  6094. // identities match.
  6095. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  6096. }
  6097. function updateForwardRef(current, workInProgress, Component, nextProps, renderExpirationTime) {
  6098. // TODO: current can be non-null here even if the component
  6099. // hasn't yet mounted. This happens after the first render suspends.
  6100. // We'll need to figure out if this is fine or can cause issues.
  6101. {
  6102. if (workInProgress.type !== workInProgress.elementType) {
  6103. // Lazy component props can't be validated in createElement
  6104. // because they're only guaranteed to be resolved here.
  6105. var innerPropTypes = Component.propTypes;
  6106. if (innerPropTypes) {
  6107. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  6108. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6109. }
  6110. }
  6111. }
  6112. var render = Component.render;
  6113. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  6114. var nextChildren;
  6115. prepareToReadContext(workInProgress, renderExpirationTime);
  6116. {
  6117. ReactCurrentOwner$1.current = workInProgress;
  6118. setIsRendering(true);
  6119. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderExpirationTime);
  6120. setIsRendering(false);
  6121. }
  6122. if (current !== null && !didReceiveUpdate) {
  6123. bailoutHooks(current, workInProgress, renderExpirationTime);
  6124. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6125. } // React DevTools reads this flag.
  6126. workInProgress.effectTag |= PerformedWork;
  6127. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6128. return workInProgress.child;
  6129. }
  6130. function updateMemoComponent(current, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
  6131. if (current === null) {
  6132. var type = Component.type;
  6133. if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  6134. Component.defaultProps === undefined) {
  6135. var resolvedType = type;
  6136. {
  6137. resolvedType = resolveFunctionForHotReloading(type);
  6138. } // If this is a plain function component without default props,
  6139. // and with only the default shallow comparison, we upgrade it
  6140. // to a SimpleMemoComponent to allow fast path updates.
  6141. workInProgress.tag = SimpleMemoComponent;
  6142. workInProgress.type = resolvedType;
  6143. {
  6144. validateFunctionComponentInDev(workInProgress, type);
  6145. }
  6146. return updateSimpleMemoComponent(current, workInProgress, resolvedType, nextProps, updateExpirationTime, renderExpirationTime);
  6147. }
  6148. {
  6149. var innerPropTypes = type.propTypes;
  6150. if (innerPropTypes) {
  6151. // Inner memo component props aren't currently validated in createElement.
  6152. // We could move it there, but we'd still need this for lazy code path.
  6153. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  6154. 'prop', getComponentName(type), getCurrentFiberStackInDev);
  6155. }
  6156. }
  6157. var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
  6158. child.ref = workInProgress.ref;
  6159. child.return = workInProgress;
  6160. workInProgress.child = child;
  6161. return child;
  6162. }
  6163. {
  6164. var _type = Component.type;
  6165. var _innerPropTypes = _type.propTypes;
  6166. if (_innerPropTypes) {
  6167. // Inner memo component props aren't currently validated in createElement.
  6168. // We could move it there, but we'd still need this for lazy code path.
  6169. checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
  6170. 'prop', getComponentName(_type), getCurrentFiberStackInDev);
  6171. }
  6172. }
  6173. var currentChild = current.child; // This is always exactly one child
  6174. if (updateExpirationTime < renderExpirationTime) {
  6175. // This will be the props with resolved defaultProps,
  6176. // unlike current.memoizedProps which will be the unresolved ones.
  6177. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  6178. var compare = Component.compare;
  6179. compare = compare !== null ? compare : shallowEqual;
  6180. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  6181. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6182. }
  6183. } // React DevTools reads this flag.
  6184. workInProgress.effectTag |= PerformedWork;
  6185. var newChild = createWorkInProgress(currentChild, nextProps);
  6186. newChild.ref = workInProgress.ref;
  6187. newChild.return = workInProgress;
  6188. workInProgress.child = newChild;
  6189. return newChild;
  6190. }
  6191. function updateSimpleMemoComponent(current, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
  6192. // TODO: current can be non-null here even if the component
  6193. // hasn't yet mounted. This happens when the inner render suspends.
  6194. // We'll need to figure out if this is fine or can cause issues.
  6195. {
  6196. if (workInProgress.type !== workInProgress.elementType) {
  6197. // Lazy component props can't be validated in createElement
  6198. // because they're only guaranteed to be resolved here.
  6199. var outerMemoType = workInProgress.elementType;
  6200. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  6201. // We warn when you define propTypes on lazy()
  6202. // so let's just skip over it to find memo() outer wrapper.
  6203. // Inner props for memo are validated later.
  6204. outerMemoType = refineResolvedLazyComponent(outerMemoType);
  6205. }
  6206. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  6207. if (outerPropTypes) {
  6208. checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  6209. 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
  6210. } // Inner propTypes will be validated in the function component path.
  6211. }
  6212. }
  6213. if (current !== null) {
  6214. var prevProps = current.memoizedProps;
  6215. if (shallowEqual(prevProps, nextProps) && current.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload.
  6216. workInProgress.type === current.type )) {
  6217. didReceiveUpdate = false;
  6218. if (updateExpirationTime < renderExpirationTime) {
  6219. // The pending update priority was cleared at the beginning of
  6220. // beginWork. We're about to bail out, but there might be additional
  6221. // updates at a lower priority. Usually, the priority level of the
  6222. // remaining updates is accumlated during the evaluation of the
  6223. // component (i.e. when processing the update queue). But since since
  6224. // we're bailing out early *without* evaluating the component, we need
  6225. // to account for it here, too. Reset to the value of the current fiber.
  6226. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  6227. // because a MemoComponent fiber does not have hooks or an update queue;
  6228. // rather, it wraps around an inner component, which may or may not
  6229. // contains hooks.
  6230. // TODO: Move the reset at in beginWork out of the common path so that
  6231. // this is no longer necessary.
  6232. workInProgress.expirationTime = current.expirationTime;
  6233. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6234. }
  6235. }
  6236. }
  6237. return updateFunctionComponent(current, workInProgress, Component, nextProps, renderExpirationTime);
  6238. }
  6239. function updateFragment(current, workInProgress, renderExpirationTime) {
  6240. var nextChildren = workInProgress.pendingProps;
  6241. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6242. return workInProgress.child;
  6243. }
  6244. function updateMode(current, workInProgress, renderExpirationTime) {
  6245. var nextChildren = workInProgress.pendingProps.children;
  6246. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6247. return workInProgress.child;
  6248. }
  6249. function updateProfiler(current, workInProgress, renderExpirationTime) {
  6250. {
  6251. workInProgress.effectTag |= Update;
  6252. }
  6253. var nextProps = workInProgress.pendingProps;
  6254. var nextChildren = nextProps.children;
  6255. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6256. return workInProgress.child;
  6257. }
  6258. function markRef(current, workInProgress) {
  6259. var ref = workInProgress.ref;
  6260. if (current === null && ref !== null || current !== null && current.ref !== ref) {
  6261. // Schedule a Ref effect
  6262. workInProgress.effectTag |= Ref;
  6263. }
  6264. }
  6265. function updateFunctionComponent(current, workInProgress, Component, nextProps, renderExpirationTime) {
  6266. {
  6267. if (workInProgress.type !== workInProgress.elementType) {
  6268. // Lazy component props can't be validated in createElement
  6269. // because they're only guaranteed to be resolved here.
  6270. var innerPropTypes = Component.propTypes;
  6271. if (innerPropTypes) {
  6272. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  6273. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6274. }
  6275. }
  6276. }
  6277. var context;
  6278. {
  6279. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  6280. context = getMaskedContext(workInProgress, unmaskedContext);
  6281. }
  6282. var nextChildren;
  6283. prepareToReadContext(workInProgress, renderExpirationTime);
  6284. {
  6285. ReactCurrentOwner$1.current = workInProgress;
  6286. setIsRendering(true);
  6287. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderExpirationTime);
  6288. setIsRendering(false);
  6289. }
  6290. if (current !== null && !didReceiveUpdate) {
  6291. bailoutHooks(current, workInProgress, renderExpirationTime);
  6292. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6293. } // React DevTools reads this flag.
  6294. workInProgress.effectTag |= PerformedWork;
  6295. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6296. return workInProgress.child;
  6297. }
  6298. function updateClassComponent(current, workInProgress, Component, nextProps, renderExpirationTime) {
  6299. {
  6300. if (workInProgress.type !== workInProgress.elementType) {
  6301. // Lazy component props can't be validated in createElement
  6302. // because they're only guaranteed to be resolved here.
  6303. var innerPropTypes = Component.propTypes;
  6304. if (innerPropTypes) {
  6305. checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
  6306. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6307. }
  6308. }
  6309. } // Push context providers early to prevent context stack mismatches.
  6310. // During mounting we don't know the child context yet as the instance doesn't exist.
  6311. // We will invalidate the child context in finishClassComponent() right after rendering.
  6312. var hasContext;
  6313. if (isContextProvider(Component)) {
  6314. hasContext = true;
  6315. pushContextProvider(workInProgress);
  6316. } else {
  6317. hasContext = false;
  6318. }
  6319. prepareToReadContext(workInProgress, renderExpirationTime);
  6320. var instance = workInProgress.stateNode;
  6321. var shouldUpdate;
  6322. if (instance === null) {
  6323. if (current !== null) {
  6324. // A class component without an instance only mounts if it suspended
  6325. // inside a non-concurrent tree, in an inconsistent state. We want to
  6326. // treat it like a new mount, even though an empty version of it already
  6327. // committed. Disconnect the alternate pointers.
  6328. current.alternate = null;
  6329. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6330. workInProgress.effectTag |= Placement;
  6331. } // In the initial pass we might need to construct the instance.
  6332. constructClassInstance(workInProgress, Component, nextProps);
  6333. mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  6334. shouldUpdate = true;
  6335. } else if (current === null) {
  6336. // In a resume, we'll already have an instance we can reuse.
  6337. shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  6338. } else {
  6339. shouldUpdate = updateClassInstance(current, workInProgress, Component, nextProps, renderExpirationTime);
  6340. }
  6341. var nextUnitOfWork = finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
  6342. {
  6343. var inst = workInProgress.stateNode;
  6344. if (inst.props !== nextProps) {
  6345. if (!didWarnAboutReassigningProps) {
  6346. 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');
  6347. }
  6348. didWarnAboutReassigningProps = true;
  6349. }
  6350. }
  6351. return nextUnitOfWork;
  6352. }
  6353. function finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
  6354. // Refs should update even if shouldComponentUpdate returns false
  6355. markRef(current, workInProgress);
  6356. var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
  6357. if (!shouldUpdate && !didCaptureError) {
  6358. // Context providers should defer to sCU for rendering
  6359. if (hasContext) {
  6360. invalidateContextProvider(workInProgress, Component, false);
  6361. }
  6362. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6363. }
  6364. var instance = workInProgress.stateNode; // Rerender
  6365. ReactCurrentOwner$1.current = workInProgress;
  6366. var nextChildren;
  6367. if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
  6368. // If we captured an error, but getDerivedStateFromError is not defined,
  6369. // unmount all the children. componentDidCatch will schedule an update to
  6370. // re-render a fallback. This is temporary until we migrate everyone to
  6371. // the new API.
  6372. // TODO: Warn in a future release.
  6373. nextChildren = null;
  6374. {
  6375. stopProfilerTimerIfRunning();
  6376. }
  6377. } else {
  6378. {
  6379. setIsRendering(true);
  6380. nextChildren = instance.render();
  6381. setIsRendering(false);
  6382. }
  6383. } // React DevTools reads this flag.
  6384. workInProgress.effectTag |= PerformedWork;
  6385. if (current !== null && didCaptureError) {
  6386. // If we're recovering from an error, reconcile without reusing any of
  6387. // the existing children. Conceptually, the normal children and the children
  6388. // that are shown on error are two different sets, so we shouldn't reuse
  6389. // normal children even if their identities match.
  6390. forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderExpirationTime);
  6391. } else {
  6392. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6393. } // Memoize state using the values we just used to render.
  6394. // TODO: Restructure so we never read values from the instance.
  6395. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  6396. if (hasContext) {
  6397. invalidateContextProvider(workInProgress, Component, true);
  6398. }
  6399. return workInProgress.child;
  6400. }
  6401. function pushHostRootContext(workInProgress) {
  6402. var root = workInProgress.stateNode;
  6403. if (root.pendingContext) {
  6404. pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
  6405. } else if (root.context) {
  6406. // Should always be set
  6407. pushTopLevelContextObject(workInProgress, root.context, false);
  6408. }
  6409. pushHostContainer(workInProgress, root.containerInfo);
  6410. }
  6411. function updateHostRoot(current, workInProgress, renderExpirationTime) {
  6412. pushHostRootContext(workInProgress);
  6413. var updateQueue = workInProgress.updateQueue;
  6414. if (!(current !== null && updateQueue !== null)) {
  6415. {
  6416. 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." );
  6417. }
  6418. }
  6419. var nextProps = workInProgress.pendingProps;
  6420. var prevState = workInProgress.memoizedState;
  6421. var prevChildren = prevState !== null ? prevState.element : null;
  6422. cloneUpdateQueue(current, workInProgress);
  6423. processUpdateQueue(workInProgress, nextProps, null, renderExpirationTime);
  6424. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  6425. // being called "element".
  6426. var nextChildren = nextState.element;
  6427. if (nextChildren === prevChildren) {
  6428. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6429. }
  6430. var root = workInProgress.stateNode;
  6431. if (root.hydrate && enterHydrationState()) {
  6432. // If we don't have any current children this might be the first pass.
  6433. // We always try to hydrate. If this isn't a hydration pass there won't
  6434. // be any children to hydrate which is effectively the same thing as
  6435. // not hydrating.
  6436. var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  6437. workInProgress.child = child;
  6438. var node = child;
  6439. while (node) {
  6440. // Mark each child as hydrating. This is a fast path to know whether this
  6441. // tree is part of a hydrating tree. This is used to determine if a child
  6442. // node has fully mounted yet, and for scheduling event replaying.
  6443. // Conceptually this is similar to Placement in that a new subtree is
  6444. // inserted into the React tree here. It just happens to not need DOM
  6445. // mutations because it already exists.
  6446. node.effectTag = node.effectTag & ~Placement | Hydrating;
  6447. node = node.sibling;
  6448. }
  6449. } else {
  6450. // Otherwise reset hydration state in case we aborted and resumed another
  6451. // root.
  6452. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6453. }
  6454. return workInProgress.child;
  6455. }
  6456. function updateHostComponent(current, workInProgress, renderExpirationTime) {
  6457. pushHostContext(workInProgress);
  6458. var type = workInProgress.type;
  6459. var nextProps = workInProgress.pendingProps;
  6460. var prevProps = current !== null ? current.memoizedProps : null;
  6461. var nextChildren = nextProps.children;
  6462. if (prevProps !== null && shouldSetTextContent()) {
  6463. // If we're switching from a direct text child to a normal child, or to
  6464. // empty, we need to schedule the text content to be reset.
  6465. workInProgress.effectTag |= ContentReset;
  6466. }
  6467. markRef(current, workInProgress); // Check the host config to see if the children are offscreen/hidden.
  6468. if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree()) {
  6469. {
  6470. markSpawnedWork(Never);
  6471. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  6472. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  6473. return null;
  6474. }
  6475. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6476. return workInProgress.child;
  6477. }
  6478. function updateHostText(current, workInProgress) {
  6479. // immediately after.
  6480. return null;
  6481. }
  6482. function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
  6483. if (_current !== null) {
  6484. // A lazy component only mounts if it suspended inside a non-
  6485. // concurrent tree, in an inconsistent state. We want to treat it like
  6486. // a new mount, even though an empty version of it already committed.
  6487. // Disconnect the alternate pointers.
  6488. _current.alternate = null;
  6489. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6490. workInProgress.effectTag |= Placement;
  6491. }
  6492. var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
  6493. // Cancel and resume right after we know the tag.
  6494. cancelWorkTimer(workInProgress);
  6495. var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
  6496. workInProgress.type = Component;
  6497. var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
  6498. startWorkTimer(workInProgress);
  6499. var resolvedProps = resolveDefaultProps(Component, props);
  6500. var child;
  6501. switch (resolvedTag) {
  6502. case FunctionComponent:
  6503. {
  6504. {
  6505. validateFunctionComponentInDev(workInProgress, Component);
  6506. workInProgress.type = Component = resolveFunctionForHotReloading(Component);
  6507. }
  6508. child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  6509. return child;
  6510. }
  6511. case ClassComponent:
  6512. {
  6513. {
  6514. workInProgress.type = Component = resolveClassForHotReloading(Component);
  6515. }
  6516. child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  6517. return child;
  6518. }
  6519. case ForwardRef:
  6520. {
  6521. {
  6522. workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
  6523. }
  6524. child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  6525. return child;
  6526. }
  6527. case MemoComponent:
  6528. {
  6529. {
  6530. if (workInProgress.type !== workInProgress.elementType) {
  6531. var outerPropTypes = Component.propTypes;
  6532. if (outerPropTypes) {
  6533. checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
  6534. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6535. }
  6536. }
  6537. }
  6538. child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  6539. updateExpirationTime, renderExpirationTime);
  6540. return child;
  6541. }
  6542. }
  6543. var hint = '';
  6544. {
  6545. if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
  6546. hint = ' Did you wrap a component in React.lazy() more than once?';
  6547. }
  6548. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  6549. // because the fact that it's a separate type of work is an
  6550. // implementation detail.
  6551. {
  6552. {
  6553. throw Error( "Element type is invalid. Received a promise that resolves to: " + Component + ". Lazy element type must resolve to a class or function." + hint );
  6554. }
  6555. }
  6556. }
  6557. function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
  6558. if (_current !== null) {
  6559. // An incomplete component only mounts if it suspended inside a non-
  6560. // concurrent tree, in an inconsistent state. We want to treat it like
  6561. // a new mount, even though an empty version of it already committed.
  6562. // Disconnect the alternate pointers.
  6563. _current.alternate = null;
  6564. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6565. workInProgress.effectTag |= Placement;
  6566. } // Promote the fiber to a class and try rendering again.
  6567. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  6568. // Push context providers early to prevent context stack mismatches.
  6569. // During mounting we don't know the child context yet as the instance doesn't exist.
  6570. // We will invalidate the child context in finishClassComponent() right after rendering.
  6571. var hasContext;
  6572. if (isContextProvider(Component)) {
  6573. hasContext = true;
  6574. pushContextProvider(workInProgress);
  6575. } else {
  6576. hasContext = false;
  6577. }
  6578. prepareToReadContext(workInProgress, renderExpirationTime);
  6579. constructClassInstance(workInProgress, Component, nextProps);
  6580. mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  6581. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
  6582. }
  6583. function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
  6584. if (_current !== null) {
  6585. // An indeterminate component only mounts if it suspended inside a non-
  6586. // concurrent tree, in an inconsistent state. We want to treat it like
  6587. // a new mount, even though an empty version of it already committed.
  6588. // Disconnect the alternate pointers.
  6589. _current.alternate = null;
  6590. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6591. workInProgress.effectTag |= Placement;
  6592. }
  6593. var props = workInProgress.pendingProps;
  6594. var context;
  6595. {
  6596. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  6597. context = getMaskedContext(workInProgress, unmaskedContext);
  6598. }
  6599. prepareToReadContext(workInProgress, renderExpirationTime);
  6600. var value;
  6601. {
  6602. if (Component.prototype && typeof Component.prototype.render === 'function') {
  6603. var componentName = getComponentName(Component) || 'Unknown';
  6604. if (!didWarnAboutBadClass[componentName]) {
  6605. 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);
  6606. didWarnAboutBadClass[componentName] = true;
  6607. }
  6608. }
  6609. if (workInProgress.mode & StrictMode) {
  6610. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  6611. }
  6612. setIsRendering(true);
  6613. ReactCurrentOwner$1.current = workInProgress;
  6614. value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
  6615. setIsRendering(false);
  6616. } // React DevTools reads this flag.
  6617. workInProgress.effectTag |= PerformedWork;
  6618. if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  6619. {
  6620. var _componentName = getComponentName(Component) || 'Unknown';
  6621. if (!didWarnAboutModulePatternComponent[_componentName]) {
  6622. 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);
  6623. didWarnAboutModulePatternComponent[_componentName] = true;
  6624. }
  6625. } // Proceed under the assumption that this is a class instance
  6626. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  6627. workInProgress.memoizedState = null;
  6628. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  6629. // During mounting we don't know the child context yet as the instance doesn't exist.
  6630. // We will invalidate the child context in finishClassComponent() right after rendering.
  6631. var hasContext = false;
  6632. if (isContextProvider(Component)) {
  6633. hasContext = true;
  6634. pushContextProvider(workInProgress);
  6635. } else {
  6636. hasContext = false;
  6637. }
  6638. workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
  6639. initializeUpdateQueue(workInProgress);
  6640. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  6641. if (typeof getDerivedStateFromProps === 'function') {
  6642. applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
  6643. }
  6644. adoptClassInstance(workInProgress, value);
  6645. mountClassInstance(workInProgress, Component, props, renderExpirationTime);
  6646. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
  6647. } else {
  6648. // Proceed under the assumption that this is a function component
  6649. workInProgress.tag = FunctionComponent;
  6650. reconcileChildren(null, workInProgress, value, renderExpirationTime);
  6651. {
  6652. validateFunctionComponentInDev(workInProgress, Component);
  6653. }
  6654. return workInProgress.child;
  6655. }
  6656. }
  6657. function validateFunctionComponentInDev(workInProgress, Component) {
  6658. {
  6659. if (Component) {
  6660. if (Component.childContextTypes) {
  6661. error('%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component');
  6662. }
  6663. }
  6664. if (workInProgress.ref !== null) {
  6665. var info = '';
  6666. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  6667. if (ownerName) {
  6668. info += '\n\nCheck the render method of `' + ownerName + '`.';
  6669. }
  6670. var warningKey = ownerName || workInProgress._debugID || '';
  6671. var debugSource = workInProgress._debugSource;
  6672. if (debugSource) {
  6673. warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
  6674. }
  6675. if (!didWarnAboutFunctionRefs[warningKey]) {
  6676. didWarnAboutFunctionRefs[warningKey] = true;
  6677. error('Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
  6678. }
  6679. }
  6680. if (typeof Component.getDerivedStateFromProps === 'function') {
  6681. var _componentName2 = getComponentName(Component) || 'Unknown';
  6682. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
  6683. error('%s: Function components do not support getDerivedStateFromProps.', _componentName2);
  6684. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
  6685. }
  6686. }
  6687. if (typeof Component.contextType === 'object' && Component.contextType !== null) {
  6688. var _componentName3 = getComponentName(Component) || 'Unknown';
  6689. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
  6690. error('%s: Function components do not support contextType.', _componentName3);
  6691. didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
  6692. }
  6693. }
  6694. }
  6695. }
  6696. var SUSPENDED_MARKER = {
  6697. dehydrated: null,
  6698. retryTime: NoWork
  6699. };
  6700. function shouldRemainOnFallback(suspenseContext, current, workInProgress) {
  6701. // If the context is telling us that we should show a fallback, and we're not
  6702. // already showing content, then we should show the fallback instead.
  6703. return hasSuspenseContext(suspenseContext, ForceSuspenseFallback) && (current === null || current.memoizedState !== null);
  6704. }
  6705. function updateSuspenseComponent(current, workInProgress, renderExpirationTime) {
  6706. var mode = workInProgress.mode;
  6707. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  6708. {
  6709. if (shouldSuspend(workInProgress)) {
  6710. workInProgress.effectTag |= DidCapture;
  6711. }
  6712. }
  6713. var suspenseContext = suspenseStackCursor.current;
  6714. var nextDidTimeout = false;
  6715. var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
  6716. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  6717. // Something in this boundary's subtree already suspended. Switch to
  6718. // rendering the fallback children.
  6719. nextDidTimeout = true;
  6720. workInProgress.effectTag &= ~DidCapture;
  6721. } else {
  6722. // Attempting the main content
  6723. if (current === null || current.memoizedState !== null) {
  6724. // This is a new mount or this boundary is already showing a fallback state.
  6725. // Mark this subtree context as having at least one invisible parent that could
  6726. // handle the fallback state.
  6727. // Boundaries without fallbacks or should be avoided are not considered since
  6728. // they cannot handle preferred fallback states.
  6729. if (nextProps.fallback !== undefined && nextProps.unstable_avoidThisFallback !== true) {
  6730. suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
  6731. }
  6732. }
  6733. }
  6734. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  6735. pushSuspenseContext(workInProgress, suspenseContext); // This next part is a bit confusing. If the children timeout, we switch to
  6736. // showing the fallback children in place of the "primary" children.
  6737. // However, we don't want to delete the primary children because then their
  6738. // state will be lost (both the React state and the host state, e.g.
  6739. // uncontrolled form inputs). Instead we keep them mounted and hide them.
  6740. // Both the fallback children AND the primary children are rendered at the
  6741. // same time. Once the primary children are un-suspended, we can delete
  6742. // the fallback children — don't need to preserve their state.
  6743. //
  6744. // The two sets of children are siblings in the host environment, but
  6745. // semantically, for purposes of reconciliation, they are two separate sets.
  6746. // So we store them using two fragment fibers.
  6747. //
  6748. // However, we want to avoid allocating extra fibers for every placeholder.
  6749. // They're only necessary when the children time out, because that's the
  6750. // only time when both sets are mounted.
  6751. //
  6752. // So, the extra fragment fibers are only used if the children time out.
  6753. // Otherwise, we render the primary children directly. This requires some
  6754. // custom reconciliation logic to preserve the state of the primary
  6755. // children. It's essentially a very basic form of re-parenting.
  6756. if (current === null) {
  6757. // If we're currently hydrating, try to hydrate this boundary.
  6758. // But only if this has a fallback.
  6759. if (nextProps.fallback !== undefined) ; // This is the initial mount. This branch is pretty simple because there's
  6760. // no previous state that needs to be preserved.
  6761. if (nextDidTimeout) {
  6762. // Mount separate fragments for primary and fallback children.
  6763. var nextFallbackChildren = nextProps.fallback;
  6764. var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
  6765. primaryChildFragment.return = workInProgress;
  6766. if ((workInProgress.mode & BlockingMode) === NoMode) {
  6767. // Outside of blocking mode, we commit the effects from the
  6768. // partially completed, timed-out tree, too.
  6769. var progressedState = workInProgress.memoizedState;
  6770. var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
  6771. primaryChildFragment.child = progressedPrimaryChild;
  6772. var progressedChild = progressedPrimaryChild;
  6773. while (progressedChild !== null) {
  6774. progressedChild.return = primaryChildFragment;
  6775. progressedChild = progressedChild.sibling;
  6776. }
  6777. }
  6778. var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
  6779. fallbackChildFragment.return = workInProgress;
  6780. primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
  6781. // fallback children.
  6782. workInProgress.memoizedState = SUSPENDED_MARKER;
  6783. workInProgress.child = primaryChildFragment;
  6784. return fallbackChildFragment;
  6785. } else {
  6786. // Mount the primary children without an intermediate fragment fiber.
  6787. var nextPrimaryChildren = nextProps.children;
  6788. workInProgress.memoizedState = null;
  6789. return workInProgress.child = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
  6790. }
  6791. } else {
  6792. // This is an update. This branch is more complicated because we need to
  6793. // ensure the state of the primary children is preserved.
  6794. var prevState = current.memoizedState;
  6795. if (prevState !== null) {
  6796. // wrapped in a fragment fiber.
  6797. var currentPrimaryChildFragment = current.child;
  6798. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  6799. if (nextDidTimeout) {
  6800. // Still timed out. Reuse the current primary children by cloning
  6801. // its fragment. We're going to skip over these entirely.
  6802. var _nextFallbackChildren2 = nextProps.fallback;
  6803. var _primaryChildFragment2 = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps);
  6804. _primaryChildFragment2.return = workInProgress;
  6805. if ((workInProgress.mode & BlockingMode) === NoMode) {
  6806. // Outside of blocking mode, we commit the effects from the
  6807. // partially completed, timed-out tree, too.
  6808. var _progressedState = workInProgress.memoizedState;
  6809. var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
  6810. if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
  6811. _primaryChildFragment2.child = _progressedPrimaryChild;
  6812. var _progressedChild2 = _progressedPrimaryChild;
  6813. while (_progressedChild2 !== null) {
  6814. _progressedChild2.return = _primaryChildFragment2;
  6815. _progressedChild2 = _progressedChild2.sibling;
  6816. }
  6817. }
  6818. } // Because primaryChildFragment is a new fiber that we're inserting as the
  6819. // parent of a new tree, we need to set its treeBaseDuration.
  6820. if ( workInProgress.mode & ProfileMode) {
  6821. // treeBaseDuration is the sum of all the child tree base durations.
  6822. var _treeBaseDuration = 0;
  6823. var _hiddenChild = _primaryChildFragment2.child;
  6824. while (_hiddenChild !== null) {
  6825. _treeBaseDuration += _hiddenChild.treeBaseDuration;
  6826. _hiddenChild = _hiddenChild.sibling;
  6827. }
  6828. _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
  6829. } // Clone the fallback child fragment, too. These we'll continue
  6830. // working on.
  6831. var _fallbackChildFragment2 = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren2);
  6832. _fallbackChildFragment2.return = workInProgress;
  6833. _primaryChildFragment2.sibling = _fallbackChildFragment2;
  6834. _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  6835. // fallback children.
  6836. workInProgress.memoizedState = SUSPENDED_MARKER;
  6837. workInProgress.child = _primaryChildFragment2;
  6838. return _fallbackChildFragment2;
  6839. } else {
  6840. // No longer suspended. Switch back to showing the primary children,
  6841. // and remove the intermediate fragment fiber.
  6842. var _nextPrimaryChildren = nextProps.children;
  6843. var currentPrimaryChild = currentPrimaryChildFragment.child;
  6844. var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime); // If this render doesn't suspend, we need to delete the fallback
  6845. // children. Wait until the complete phase, after we've confirmed the
  6846. // fallback is no longer needed.
  6847. // TODO: Would it be better to store the fallback fragment on
  6848. // the stateNode?
  6849. // Continue rendering the children, like we normally do.
  6850. workInProgress.memoizedState = null;
  6851. return workInProgress.child = primaryChild;
  6852. }
  6853. } else {
  6854. // The current tree has not already timed out. That means the primary
  6855. // children are not wrapped in a fragment fiber.
  6856. var _currentPrimaryChild = current.child;
  6857. if (nextDidTimeout) {
  6858. // Timed out. Wrap the children in a fragment fiber to keep them
  6859. // separate from the fallback children.
  6860. var _nextFallbackChildren3 = nextProps.fallback;
  6861. var _primaryChildFragment3 = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
  6862. // going to render this fragment.
  6863. null, mode, NoWork, null);
  6864. _primaryChildFragment3.return = workInProgress;
  6865. _primaryChildFragment3.child = _currentPrimaryChild;
  6866. if (_currentPrimaryChild !== null) {
  6867. _currentPrimaryChild.return = _primaryChildFragment3;
  6868. } // Even though we're creating a new fiber, there are no new children,
  6869. // because we're reusing an already mounted tree. So we don't need to
  6870. // schedule a placement.
  6871. // primaryChildFragment.effectTag |= Placement;
  6872. if ((workInProgress.mode & BlockingMode) === NoMode) {
  6873. // Outside of blocking mode, we commit the effects from the
  6874. // partially completed, timed-out tree, too.
  6875. var _progressedState2 = workInProgress.memoizedState;
  6876. var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
  6877. _primaryChildFragment3.child = _progressedPrimaryChild2;
  6878. var _progressedChild3 = _progressedPrimaryChild2;
  6879. while (_progressedChild3 !== null) {
  6880. _progressedChild3.return = _primaryChildFragment3;
  6881. _progressedChild3 = _progressedChild3.sibling;
  6882. }
  6883. } // Because primaryChildFragment is a new fiber that we're inserting as the
  6884. // parent of a new tree, we need to set its treeBaseDuration.
  6885. if ( workInProgress.mode & ProfileMode) {
  6886. // treeBaseDuration is the sum of all the child tree base durations.
  6887. var _treeBaseDuration2 = 0;
  6888. var _hiddenChild2 = _primaryChildFragment3.child;
  6889. while (_hiddenChild2 !== null) {
  6890. _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
  6891. _hiddenChild2 = _hiddenChild2.sibling;
  6892. }
  6893. _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
  6894. } // Create a fragment from the fallback children, too.
  6895. var _fallbackChildFragment3 = createFiberFromFragment(_nextFallbackChildren3, mode, renderExpirationTime, null);
  6896. _fallbackChildFragment3.return = workInProgress;
  6897. _primaryChildFragment3.sibling = _fallbackChildFragment3;
  6898. _fallbackChildFragment3.effectTag |= Placement;
  6899. _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  6900. // fallback children.
  6901. workInProgress.memoizedState = SUSPENDED_MARKER;
  6902. workInProgress.child = _primaryChildFragment3;
  6903. return _fallbackChildFragment3;
  6904. } else {
  6905. // Still haven't timed out. Continue rendering the children, like we
  6906. // normally do.
  6907. workInProgress.memoizedState = null;
  6908. var _nextPrimaryChildren2 = nextProps.children;
  6909. return workInProgress.child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
  6910. }
  6911. }
  6912. }
  6913. }
  6914. function scheduleWorkOnFiber(fiber, renderExpirationTime) {
  6915. if (fiber.expirationTime < renderExpirationTime) {
  6916. fiber.expirationTime = renderExpirationTime;
  6917. }
  6918. var alternate = fiber.alternate;
  6919. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  6920. alternate.expirationTime = renderExpirationTime;
  6921. }
  6922. scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
  6923. }
  6924. function propagateSuspenseContextChange(workInProgress, firstChild, renderExpirationTime) {
  6925. // Mark any Suspense boundaries with fallbacks as having work to do.
  6926. // If they were previously forced into fallbacks, they may now be able
  6927. // to unblock.
  6928. var node = firstChild;
  6929. while (node !== null) {
  6930. if (node.tag === SuspenseComponent) {
  6931. var state = node.memoizedState;
  6932. if (state !== null) {
  6933. scheduleWorkOnFiber(node, renderExpirationTime);
  6934. }
  6935. } else if (node.tag === SuspenseListComponent) {
  6936. // If the tail is hidden there might not be an Suspense boundaries
  6937. // to schedule work on. In this case we have to schedule it on the
  6938. // list itself.
  6939. // We don't have to traverse to the children of the list since
  6940. // the list will propagate the change when it rerenders.
  6941. scheduleWorkOnFiber(node, renderExpirationTime);
  6942. } else if (node.child !== null) {
  6943. node.child.return = node;
  6944. node = node.child;
  6945. continue;
  6946. }
  6947. if (node === workInProgress) {
  6948. return;
  6949. }
  6950. while (node.sibling === null) {
  6951. if (node.return === null || node.return === workInProgress) {
  6952. return;
  6953. }
  6954. node = node.return;
  6955. }
  6956. node.sibling.return = node.return;
  6957. node = node.sibling;
  6958. }
  6959. }
  6960. function findLastContentRow(firstChild) {
  6961. // This is going to find the last row among these children that is already
  6962. // showing content on the screen, as opposed to being in fallback state or
  6963. // new. If a row has multiple Suspense boundaries, any of them being in the
  6964. // fallback state, counts as the whole row being in a fallback state.
  6965. // Note that the "rows" will be workInProgress, but any nested children
  6966. // will still be current since we haven't rendered them yet. The mounted
  6967. // order may not be the same as the new order. We use the new order.
  6968. var row = firstChild;
  6969. var lastContentRow = null;
  6970. while (row !== null) {
  6971. var currentRow = row.alternate; // New rows can't be content rows.
  6972. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  6973. lastContentRow = row;
  6974. }
  6975. row = row.sibling;
  6976. }
  6977. return lastContentRow;
  6978. }
  6979. function validateRevealOrder(revealOrder) {
  6980. {
  6981. if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
  6982. didWarnAboutRevealOrder[revealOrder] = true;
  6983. if (typeof revealOrder === 'string') {
  6984. switch (revealOrder.toLowerCase()) {
  6985. case 'together':
  6986. case 'forwards':
  6987. case 'backwards':
  6988. {
  6989. error('"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
  6990. break;
  6991. }
  6992. case 'forward':
  6993. case 'backward':
  6994. {
  6995. 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());
  6996. break;
  6997. }
  6998. default:
  6999. error('"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  7000. break;
  7001. }
  7002. } else {
  7003. error('%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  7004. }
  7005. }
  7006. }
  7007. }
  7008. function validateTailOptions(tailMode, revealOrder) {
  7009. {
  7010. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  7011. if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
  7012. didWarnAboutTailOptions[tailMode] = true;
  7013. error('"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
  7014. } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
  7015. didWarnAboutTailOptions[tailMode] = true;
  7016. error('<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
  7017. }
  7018. }
  7019. }
  7020. }
  7021. function validateSuspenseListNestedChild(childSlot, index) {
  7022. {
  7023. var isArray = Array.isArray(childSlot);
  7024. var isIterable = !isArray && typeof getIteratorFn(childSlot) === 'function';
  7025. if (isArray || isIterable) {
  7026. var type = isArray ? 'array' : 'iterable';
  7027. 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);
  7028. return false;
  7029. }
  7030. }
  7031. return true;
  7032. }
  7033. function validateSuspenseListChildren(children, revealOrder) {
  7034. {
  7035. if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
  7036. if (Array.isArray(children)) {
  7037. for (var i = 0; i < children.length; i++) {
  7038. if (!validateSuspenseListNestedChild(children[i], i)) {
  7039. return;
  7040. }
  7041. }
  7042. } else {
  7043. var iteratorFn = getIteratorFn(children);
  7044. if (typeof iteratorFn === 'function') {
  7045. var childrenIterator = iteratorFn.call(children);
  7046. if (childrenIterator) {
  7047. var step = childrenIterator.next();
  7048. var _i = 0;
  7049. for (; !step.done; step = childrenIterator.next()) {
  7050. if (!validateSuspenseListNestedChild(step.value, _i)) {
  7051. return;
  7052. }
  7053. _i++;
  7054. }
  7055. }
  7056. } else {
  7057. 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);
  7058. }
  7059. }
  7060. }
  7061. }
  7062. }
  7063. function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode, lastEffectBeforeRendering) {
  7064. var renderState = workInProgress.memoizedState;
  7065. if (renderState === null) {
  7066. workInProgress.memoizedState = {
  7067. isBackwards: isBackwards,
  7068. rendering: null,
  7069. renderingStartTime: 0,
  7070. last: lastContentRow,
  7071. tail: tail,
  7072. tailExpiration: 0,
  7073. tailMode: tailMode,
  7074. lastEffect: lastEffectBeforeRendering
  7075. };
  7076. } else {
  7077. // We can reuse the existing object from previous renders.
  7078. renderState.isBackwards = isBackwards;
  7079. renderState.rendering = null;
  7080. renderState.renderingStartTime = 0;
  7081. renderState.last = lastContentRow;
  7082. renderState.tail = tail;
  7083. renderState.tailExpiration = 0;
  7084. renderState.tailMode = tailMode;
  7085. renderState.lastEffect = lastEffectBeforeRendering;
  7086. }
  7087. } // This can end up rendering this component multiple passes.
  7088. // The first pass splits the children fibers into two sets. A head and tail.
  7089. // We first render the head. If anything is in fallback state, we do another
  7090. // pass through beginWork to rerender all children (including the tail) with
  7091. // the force suspend context. If the first render didn't have anything in
  7092. // in fallback state. Then we render each row in the tail one-by-one.
  7093. // That happens in the completeWork phase without going back to beginWork.
  7094. function updateSuspenseListComponent(current, workInProgress, renderExpirationTime) {
  7095. var nextProps = workInProgress.pendingProps;
  7096. var revealOrder = nextProps.revealOrder;
  7097. var tailMode = nextProps.tail;
  7098. var newChildren = nextProps.children;
  7099. validateRevealOrder(revealOrder);
  7100. validateTailOptions(tailMode, revealOrder);
  7101. validateSuspenseListChildren(newChildren, revealOrder);
  7102. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  7103. var suspenseContext = suspenseStackCursor.current;
  7104. var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
  7105. if (shouldForceFallback) {
  7106. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  7107. workInProgress.effectTag |= DidCapture;
  7108. } else {
  7109. var didSuspendBefore = current !== null && (current.effectTag & DidCapture) !== NoEffect;
  7110. if (didSuspendBefore) {
  7111. // If we previously forced a fallback, we need to schedule work
  7112. // on any nested boundaries to let them know to try to render
  7113. // again. This is the same as context updating.
  7114. propagateSuspenseContextChange(workInProgress, workInProgress.child, renderExpirationTime);
  7115. }
  7116. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  7117. }
  7118. pushSuspenseContext(workInProgress, suspenseContext);
  7119. if ((workInProgress.mode & BlockingMode) === NoMode) {
  7120. // Outside of blocking mode, SuspenseList doesn't work so we just
  7121. // use make it a noop by treating it as the default revealOrder.
  7122. workInProgress.memoizedState = null;
  7123. } else {
  7124. switch (revealOrder) {
  7125. case 'forwards':
  7126. {
  7127. var lastContentRow = findLastContentRow(workInProgress.child);
  7128. var tail;
  7129. if (lastContentRow === null) {
  7130. // The whole list is part of the tail.
  7131. // TODO: We could fast path by just rendering the tail now.
  7132. tail = workInProgress.child;
  7133. workInProgress.child = null;
  7134. } else {
  7135. // Disconnect the tail rows after the content row.
  7136. // We're going to render them separately later.
  7137. tail = lastContentRow.sibling;
  7138. lastContentRow.sibling = null;
  7139. }
  7140. initSuspenseListRenderState(workInProgress, false, // isBackwards
  7141. tail, lastContentRow, tailMode, workInProgress.lastEffect);
  7142. break;
  7143. }
  7144. case 'backwards':
  7145. {
  7146. // We're going to find the first row that has existing content.
  7147. // At the same time we're going to reverse the list of everything
  7148. // we pass in the meantime. That's going to be our tail in reverse
  7149. // order.
  7150. var _tail = null;
  7151. var row = workInProgress.child;
  7152. workInProgress.child = null;
  7153. while (row !== null) {
  7154. var currentRow = row.alternate; // New rows can't be content rows.
  7155. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  7156. // This is the beginning of the main content.
  7157. workInProgress.child = row;
  7158. break;
  7159. }
  7160. var nextRow = row.sibling;
  7161. row.sibling = _tail;
  7162. _tail = row;
  7163. row = nextRow;
  7164. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  7165. initSuspenseListRenderState(workInProgress, true, // isBackwards
  7166. _tail, null, // last
  7167. tailMode, workInProgress.lastEffect);
  7168. break;
  7169. }
  7170. case 'together':
  7171. {
  7172. initSuspenseListRenderState(workInProgress, false, // isBackwards
  7173. null, // tail
  7174. null, // last
  7175. undefined, workInProgress.lastEffect);
  7176. break;
  7177. }
  7178. default:
  7179. {
  7180. // The default reveal order is the same as not having
  7181. // a boundary.
  7182. workInProgress.memoizedState = null;
  7183. }
  7184. }
  7185. }
  7186. return workInProgress.child;
  7187. }
  7188. function updatePortalComponent(current, workInProgress, renderExpirationTime) {
  7189. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  7190. var nextChildren = workInProgress.pendingProps;
  7191. if (current === null) {
  7192. // Portals are special because we don't append the children during mount
  7193. // but at commit. Therefore we need to track insertions which the normal
  7194. // flow doesn't do during mount. This doesn't happen at the root because
  7195. // the root always starts with a "current" with a null child.
  7196. // TODO: Consider unifying this with how the root works.
  7197. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  7198. } else {
  7199. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  7200. }
  7201. return workInProgress.child;
  7202. }
  7203. function updateContextProvider(current, workInProgress, renderExpirationTime) {
  7204. var providerType = workInProgress.type;
  7205. var context = providerType._context;
  7206. var newProps = workInProgress.pendingProps;
  7207. var oldProps = workInProgress.memoizedProps;
  7208. var newValue = newProps.value;
  7209. {
  7210. var providerPropTypes = workInProgress.type.propTypes;
  7211. if (providerPropTypes) {
  7212. checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
  7213. }
  7214. }
  7215. pushProvider(workInProgress, newValue);
  7216. if (oldProps !== null) {
  7217. var oldValue = oldProps.value;
  7218. var changedBits = calculateChangedBits(context, newValue, oldValue);
  7219. if (changedBits === 0) {
  7220. // No change. Bailout early if children are the same.
  7221. if (oldProps.children === newProps.children && !hasContextChanged()) {
  7222. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  7223. }
  7224. } else {
  7225. // The context value changed. Search for matching consumers and schedule
  7226. // them to update.
  7227. propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
  7228. }
  7229. }
  7230. var newChildren = newProps.children;
  7231. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  7232. return workInProgress.child;
  7233. }
  7234. var hasWarnedAboutUsingContextAsConsumer = false;
  7235. function updateContextConsumer(current, workInProgress, renderExpirationTime) {
  7236. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  7237. // DEV mode, we create a separate object for Context.Consumer that acts
  7238. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  7239. // so we use the old behaviour (Context.Consumer references Context) to
  7240. // reduce size and overhead. The separate object references context via
  7241. // a property called "_context", which also gives us the ability to check
  7242. // in DEV mode if this property exists or not and warn if it does not.
  7243. {
  7244. if (context._context === undefined) {
  7245. // This may be because it's a Context (rather than a Consumer).
  7246. // Or it may be because it's older React where they're the same thing.
  7247. // We only want to warn if we're sure it's a new React.
  7248. if (context !== context.Consumer) {
  7249. if (!hasWarnedAboutUsingContextAsConsumer) {
  7250. hasWarnedAboutUsingContextAsConsumer = true;
  7251. error('Rendering <Context> directly is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
  7252. }
  7253. }
  7254. } else {
  7255. context = context._context;
  7256. }
  7257. }
  7258. var newProps = workInProgress.pendingProps;
  7259. var render = newProps.children;
  7260. {
  7261. if (typeof render !== 'function') {
  7262. 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.');
  7263. }
  7264. }
  7265. prepareToReadContext(workInProgress, renderExpirationTime);
  7266. var newValue = readContext(context, newProps.unstable_observedBits);
  7267. var newChildren;
  7268. {
  7269. ReactCurrentOwner$1.current = workInProgress;
  7270. setIsRendering(true);
  7271. newChildren = render(newValue);
  7272. setIsRendering(false);
  7273. } // React DevTools reads this flag.
  7274. workInProgress.effectTag |= PerformedWork;
  7275. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  7276. return workInProgress.child;
  7277. }
  7278. function markWorkInProgressReceivedUpdate() {
  7279. didReceiveUpdate = true;
  7280. }
  7281. function bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime) {
  7282. cancelWorkTimer(workInProgress);
  7283. if (current !== null) {
  7284. // Reuse previous dependencies
  7285. workInProgress.dependencies = current.dependencies;
  7286. }
  7287. {
  7288. // Don't update "base" render times for bailouts.
  7289. stopProfilerTimerIfRunning();
  7290. }
  7291. var updateExpirationTime = workInProgress.expirationTime;
  7292. if (updateExpirationTime !== NoWork) {
  7293. markUnprocessedUpdateTime(updateExpirationTime);
  7294. } // Check if the children have any pending work.
  7295. var childExpirationTime = workInProgress.childExpirationTime;
  7296. if (childExpirationTime < renderExpirationTime) {
  7297. // The children don't have any work either. We can skip them.
  7298. // TODO: Once we add back resuming, we should check if the children are
  7299. // a work-in-progress set. If so, we need to transfer their effects.
  7300. return null;
  7301. } else {
  7302. // This fiber doesn't have work, but its subtree does. Clone the child
  7303. // fibers and continue.
  7304. cloneChildFibers(current, workInProgress);
  7305. return workInProgress.child;
  7306. }
  7307. }
  7308. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  7309. {
  7310. var returnFiber = oldWorkInProgress.return;
  7311. if (returnFiber === null) {
  7312. throw new Error('Cannot swap the root fiber.');
  7313. } // Disconnect from the old current.
  7314. // It will get deleted.
  7315. current.alternate = null;
  7316. oldWorkInProgress.alternate = null; // Connect to the new tree.
  7317. newWorkInProgress.index = oldWorkInProgress.index;
  7318. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  7319. newWorkInProgress.return = oldWorkInProgress.return;
  7320. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  7321. if (oldWorkInProgress === returnFiber.child) {
  7322. returnFiber.child = newWorkInProgress;
  7323. } else {
  7324. var prevSibling = returnFiber.child;
  7325. if (prevSibling === null) {
  7326. throw new Error('Expected parent to have a child.');
  7327. }
  7328. while (prevSibling.sibling !== oldWorkInProgress) {
  7329. prevSibling = prevSibling.sibling;
  7330. if (prevSibling === null) {
  7331. throw new Error('Expected to find the previous sibling.');
  7332. }
  7333. }
  7334. prevSibling.sibling = newWorkInProgress;
  7335. } // Delete the old fiber and place the new one.
  7336. // Since the old fiber is disconnected, we have to schedule it manually.
  7337. var last = returnFiber.lastEffect;
  7338. if (last !== null) {
  7339. last.nextEffect = current;
  7340. returnFiber.lastEffect = current;
  7341. } else {
  7342. returnFiber.firstEffect = returnFiber.lastEffect = current;
  7343. }
  7344. current.nextEffect = null;
  7345. current.effectTag = Deletion;
  7346. newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
  7347. return newWorkInProgress;
  7348. }
  7349. }
  7350. function beginWork(current, workInProgress, renderExpirationTime) {
  7351. var updateExpirationTime = workInProgress.expirationTime;
  7352. {
  7353. if (workInProgress._debugNeedsRemount && current !== null) {
  7354. // This will restart the begin phase with a new fiber.
  7355. return remountFiber(current, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.expirationTime));
  7356. }
  7357. }
  7358. if (current !== null) {
  7359. var oldProps = current.memoizedProps;
  7360. var newProps = workInProgress.pendingProps;
  7361. if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
  7362. workInProgress.type !== current.type )) {
  7363. // If props or context changed, mark the fiber as having performed work.
  7364. // This may be unset if the props are determined to be equal later (memo).
  7365. didReceiveUpdate = true;
  7366. } else if (updateExpirationTime < renderExpirationTime) {
  7367. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  7368. // the begin phase. There's still some bookkeeping we that needs to be done
  7369. // in this optimized path, mostly pushing stuff onto the stack.
  7370. switch (workInProgress.tag) {
  7371. case HostRoot:
  7372. pushHostRootContext(workInProgress);
  7373. break;
  7374. case HostComponent:
  7375. pushHostContext(workInProgress);
  7376. if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(workInProgress.type)) {
  7377. {
  7378. markSpawnedWork(Never);
  7379. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  7380. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  7381. return null;
  7382. }
  7383. break;
  7384. case ClassComponent:
  7385. {
  7386. var Component = workInProgress.type;
  7387. if (isContextProvider(Component)) {
  7388. pushContextProvider(workInProgress);
  7389. }
  7390. break;
  7391. }
  7392. case HostPortal:
  7393. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  7394. break;
  7395. case ContextProvider:
  7396. {
  7397. var newValue = workInProgress.memoizedProps.value;
  7398. pushProvider(workInProgress, newValue);
  7399. break;
  7400. }
  7401. case Profiler:
  7402. {
  7403. // Profiler should only call onRender when one of its descendants actually rendered.
  7404. var hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
  7405. if (hasChildWork) {
  7406. workInProgress.effectTag |= Update;
  7407. }
  7408. }
  7409. break;
  7410. case SuspenseComponent:
  7411. {
  7412. var state = workInProgress.memoizedState;
  7413. if (state !== null) {
  7414. // whether to retry the primary children, or to skip over it and
  7415. // go straight to the fallback. Check the priority of the primary
  7416. // child fragment.
  7417. var primaryChildFragment = workInProgress.child;
  7418. var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
  7419. if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
  7420. // The primary children have pending work. Use the normal path
  7421. // to attempt to render the primary children again.
  7422. return updateSuspenseComponent(current, workInProgress, renderExpirationTime);
  7423. } else {
  7424. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
  7425. // priority. Bailout.
  7426. var child = bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  7427. if (child !== null) {
  7428. // The fallback children have pending work. Skip over the
  7429. // primary children and work on the fallback.
  7430. return child.sibling;
  7431. } else {
  7432. return null;
  7433. }
  7434. }
  7435. } else {
  7436. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
  7437. }
  7438. break;
  7439. }
  7440. case SuspenseListComponent:
  7441. {
  7442. var didSuspendBefore = (current.effectTag & DidCapture) !== NoEffect;
  7443. var _hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
  7444. if (didSuspendBefore) {
  7445. if (_hasChildWork) {
  7446. // If something was in fallback state last time, and we have all the
  7447. // same children then we're still in progressive loading state.
  7448. // Something might get unblocked by state updates or retries in the
  7449. // tree which will affect the tail. So we need to use the normal
  7450. // path to compute the correct tail.
  7451. return updateSuspenseListComponent(current, workInProgress, renderExpirationTime);
  7452. } // If none of the children had any work, that means that none of
  7453. // them got retried so they'll still be blocked in the same way
  7454. // as before. We can fast bail out.
  7455. workInProgress.effectTag |= DidCapture;
  7456. } // If nothing suspended before and we're rendering the same children,
  7457. // then the tail doesn't matter. Anything new that suspends will work
  7458. // in the "together" mode, so we can continue from the state we had.
  7459. var renderState = workInProgress.memoizedState;
  7460. if (renderState !== null) {
  7461. // Reset to the "together" mode in case we've started a different
  7462. // update in the past but didn't complete it.
  7463. renderState.rendering = null;
  7464. renderState.tail = null;
  7465. }
  7466. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  7467. if (_hasChildWork) {
  7468. break;
  7469. } else {
  7470. // If none of the children had any work, that means that none of
  7471. // them got retried so they'll still be blocked in the same way
  7472. // as before. We can fast bail out.
  7473. return null;
  7474. }
  7475. }
  7476. }
  7477. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  7478. } else {
  7479. // An update was scheduled on this fiber, but there are no new props
  7480. // nor legacy context. Set this to false. If an update queue or context
  7481. // consumer produces a changed value, it will set this to true. Otherwise,
  7482. // the component will assume the children have not changed and bail out.
  7483. didReceiveUpdate = false;
  7484. }
  7485. } else {
  7486. didReceiveUpdate = false;
  7487. } // Before entering the begin phase, clear pending update priority.
  7488. // TODO: This assumes that we're about to evaluate the component and process
  7489. // the update queue. However, there's an exception: SimpleMemoComponent
  7490. // sometimes bails out later in the begin phase. This indicates that we should
  7491. // move this assignment out of the common path and into each branch.
  7492. workInProgress.expirationTime = NoWork;
  7493. switch (workInProgress.tag) {
  7494. case IndeterminateComponent:
  7495. {
  7496. return mountIndeterminateComponent(current, workInProgress, workInProgress.type, renderExpirationTime);
  7497. }
  7498. case LazyComponent:
  7499. {
  7500. var elementType = workInProgress.elementType;
  7501. return mountLazyComponent(current, workInProgress, elementType, updateExpirationTime, renderExpirationTime);
  7502. }
  7503. case FunctionComponent:
  7504. {
  7505. var _Component = workInProgress.type;
  7506. var unresolvedProps = workInProgress.pendingProps;
  7507. var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
  7508. return updateFunctionComponent(current, workInProgress, _Component, resolvedProps, renderExpirationTime);
  7509. }
  7510. case ClassComponent:
  7511. {
  7512. var _Component2 = workInProgress.type;
  7513. var _unresolvedProps = workInProgress.pendingProps;
  7514. var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
  7515. return updateClassComponent(current, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
  7516. }
  7517. case HostRoot:
  7518. return updateHostRoot(current, workInProgress, renderExpirationTime);
  7519. case HostComponent:
  7520. return updateHostComponent(current, workInProgress, renderExpirationTime);
  7521. case HostText:
  7522. return updateHostText();
  7523. case SuspenseComponent:
  7524. return updateSuspenseComponent(current, workInProgress, renderExpirationTime);
  7525. case HostPortal:
  7526. return updatePortalComponent(current, workInProgress, renderExpirationTime);
  7527. case ForwardRef:
  7528. {
  7529. var type = workInProgress.type;
  7530. var _unresolvedProps2 = workInProgress.pendingProps;
  7531. var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
  7532. return updateForwardRef(current, workInProgress, type, _resolvedProps2, renderExpirationTime);
  7533. }
  7534. case Fragment:
  7535. return updateFragment(current, workInProgress, renderExpirationTime);
  7536. case Mode:
  7537. return updateMode(current, workInProgress, renderExpirationTime);
  7538. case Profiler:
  7539. return updateProfiler(current, workInProgress, renderExpirationTime);
  7540. case ContextProvider:
  7541. return updateContextProvider(current, workInProgress, renderExpirationTime);
  7542. case ContextConsumer:
  7543. return updateContextConsumer(current, workInProgress, renderExpirationTime);
  7544. case MemoComponent:
  7545. {
  7546. var _type2 = workInProgress.type;
  7547. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  7548. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  7549. {
  7550. if (workInProgress.type !== workInProgress.elementType) {
  7551. var outerPropTypes = _type2.propTypes;
  7552. if (outerPropTypes) {
  7553. checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
  7554. 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
  7555. }
  7556. }
  7557. }
  7558. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  7559. return updateMemoComponent(current, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
  7560. }
  7561. case SimpleMemoComponent:
  7562. {
  7563. return updateSimpleMemoComponent(current, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
  7564. }
  7565. case IncompleteClassComponent:
  7566. {
  7567. var _Component3 = workInProgress.type;
  7568. var _unresolvedProps4 = workInProgress.pendingProps;
  7569. var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
  7570. return mountIncompleteClassComponent(current, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
  7571. }
  7572. case SuspenseListComponent:
  7573. {
  7574. return updateSuspenseListComponent(current, workInProgress, renderExpirationTime);
  7575. }
  7576. }
  7577. {
  7578. {
  7579. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  7580. }
  7581. }
  7582. }
  7583. function markUpdate(workInProgress) {
  7584. // Tag the fiber with an update effect. This turns a Placement into
  7585. // a PlacementAndUpdate.
  7586. workInProgress.effectTag |= Update;
  7587. }
  7588. function markRef$1(workInProgress) {
  7589. workInProgress.effectTag |= Ref;
  7590. }
  7591. var appendAllChildren;
  7592. var updateHostContainer;
  7593. var updateHostComponent$1;
  7594. var updateHostText$1;
  7595. {
  7596. // Mutation mode
  7597. appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
  7598. // We only have the top Fiber that was created but we need recurse down its
  7599. // children to find all the terminal nodes.
  7600. var node = workInProgress.child;
  7601. while (node !== null) {
  7602. if (node.tag === HostComponent || node.tag === HostText) {
  7603. appendInitialChild(parent, node.stateNode);
  7604. } else if (node.tag === HostPortal) ; else if (node.child !== null) {
  7605. node.child.return = node;
  7606. node = node.child;
  7607. continue;
  7608. }
  7609. if (node === workInProgress) {
  7610. return;
  7611. }
  7612. while (node.sibling === null) {
  7613. if (node.return === null || node.return === workInProgress) {
  7614. return;
  7615. }
  7616. node = node.return;
  7617. }
  7618. node.sibling.return = node.return;
  7619. node = node.sibling;
  7620. }
  7621. };
  7622. updateHostContainer = function (workInProgress) {// Noop
  7623. };
  7624. updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
  7625. // If we have an alternate, that means this is an update and we need to
  7626. // schedule a side-effect to do the updates.
  7627. var oldProps = current.memoizedProps;
  7628. if (oldProps === newProps) {
  7629. // In mutation mode, this is sufficient for a bailout because
  7630. // we won't touch this node even if children changed.
  7631. return;
  7632. } // If we get updated because one of our children updated, we don't
  7633. // have newProps so we'll have to reuse them.
  7634. // TODO: Split the update API as separate for the props vs. children.
  7635. // Even better would be if children weren't special cased at all tho.
  7636. var instance = workInProgress.stateNode;
  7637. var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
  7638. // component is hitting the resume path. Figure out why. Possibly
  7639. // related to `hidden`.
  7640. var updatePayload = prepareUpdate(); // TODO: Type this specific to this type of component.
  7641. workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  7642. // is a new ref we mark this as an update. All the work is done in commitWork.
  7643. if (updatePayload) {
  7644. markUpdate(workInProgress);
  7645. }
  7646. };
  7647. updateHostText$1 = function (current, workInProgress, oldText, newText) {
  7648. // If the text differs, mark it as an update. All the work in done in commitWork.
  7649. if (oldText !== newText) {
  7650. markUpdate(workInProgress);
  7651. }
  7652. };
  7653. }
  7654. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  7655. switch (renderState.tailMode) {
  7656. case 'hidden':
  7657. {
  7658. // Any insertions at the end of the tail list after this point
  7659. // should be invisible. If there are already mounted boundaries
  7660. // anything before them are not considered for collapsing.
  7661. // Therefore we need to go through the whole tail to find if
  7662. // there are any.
  7663. var tailNode = renderState.tail;
  7664. var lastTailNode = null;
  7665. while (tailNode !== null) {
  7666. if (tailNode.alternate !== null) {
  7667. lastTailNode = tailNode;
  7668. }
  7669. tailNode = tailNode.sibling;
  7670. } // Next we're simply going to delete all insertions after the
  7671. // last rendered item.
  7672. if (lastTailNode === null) {
  7673. // All remaining items in the tail are insertions.
  7674. renderState.tail = null;
  7675. } else {
  7676. // Detach the insertion after the last node that was already
  7677. // inserted.
  7678. lastTailNode.sibling = null;
  7679. }
  7680. break;
  7681. }
  7682. case 'collapsed':
  7683. {
  7684. // Any insertions at the end of the tail list after this point
  7685. // should be invisible. If there are already mounted boundaries
  7686. // anything before them are not considered for collapsing.
  7687. // Therefore we need to go through the whole tail to find if
  7688. // there are any.
  7689. var _tailNode = renderState.tail;
  7690. var _lastTailNode = null;
  7691. while (_tailNode !== null) {
  7692. if (_tailNode.alternate !== null) {
  7693. _lastTailNode = _tailNode;
  7694. }
  7695. _tailNode = _tailNode.sibling;
  7696. } // Next we're simply going to delete all insertions after the
  7697. // last rendered item.
  7698. if (_lastTailNode === null) {
  7699. // All remaining items in the tail are insertions.
  7700. if (!hasRenderedATailFallback && renderState.tail !== null) {
  7701. // We suspended during the head. We want to show at least one
  7702. // row at the tail. So we'll keep on and cut off the rest.
  7703. renderState.tail.sibling = null;
  7704. } else {
  7705. renderState.tail = null;
  7706. }
  7707. } else {
  7708. // Detach the insertion after the last node that was already
  7709. // inserted.
  7710. _lastTailNode.sibling = null;
  7711. }
  7712. break;
  7713. }
  7714. }
  7715. }
  7716. function completeWork(current, workInProgress, renderExpirationTime) {
  7717. var newProps = workInProgress.pendingProps;
  7718. switch (workInProgress.tag) {
  7719. case IndeterminateComponent:
  7720. case LazyComponent:
  7721. case SimpleMemoComponent:
  7722. case FunctionComponent:
  7723. case ForwardRef:
  7724. case Fragment:
  7725. case Mode:
  7726. case Profiler:
  7727. case ContextConsumer:
  7728. case MemoComponent:
  7729. return null;
  7730. case ClassComponent:
  7731. {
  7732. var Component = workInProgress.type;
  7733. if (isContextProvider(Component)) {
  7734. popContext(workInProgress);
  7735. }
  7736. return null;
  7737. }
  7738. case HostRoot:
  7739. {
  7740. popHostContainer(workInProgress);
  7741. popTopLevelContextObject(workInProgress);
  7742. var fiberRoot = workInProgress.stateNode;
  7743. if (fiberRoot.pendingContext) {
  7744. fiberRoot.context = fiberRoot.pendingContext;
  7745. fiberRoot.pendingContext = null;
  7746. }
  7747. if (current === null || current.child === null) {
  7748. // If we hydrated, pop so that we can delete any remaining children
  7749. // that weren't hydrated.
  7750. var wasHydrated = popHydrationState();
  7751. if (wasHydrated) {
  7752. // If we hydrated, then we'll need to schedule an update for
  7753. // the commit side-effects on the root.
  7754. markUpdate(workInProgress);
  7755. }
  7756. }
  7757. updateHostContainer(workInProgress);
  7758. return null;
  7759. }
  7760. case HostComponent:
  7761. {
  7762. popHostContext(workInProgress);
  7763. var rootContainerInstance = getRootHostContainer();
  7764. var type = workInProgress.type;
  7765. if (current !== null && workInProgress.stateNode != null) {
  7766. updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
  7767. if (current.ref !== workInProgress.ref) {
  7768. markRef$1(workInProgress);
  7769. }
  7770. } else {
  7771. if (!newProps) {
  7772. if (!(workInProgress.stateNode !== null)) {
  7773. {
  7774. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  7775. }
  7776. } // This can happen when we abort work.
  7777. return null;
  7778. }
  7779. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  7780. // "stack" as the parent. Then append children as we go in beginWork
  7781. // or completeWork depending on whether we want to add them top->down or
  7782. // bottom->up. Top->down is faster in IE11.
  7783. var _wasHydrated = popHydrationState();
  7784. if (_wasHydrated) {
  7785. // TODO: Move this and createInstance step into the beginPhase
  7786. // to consolidate.
  7787. if (prepareToHydrateHostInstance()) {
  7788. // If changes to the hydrated node need to be applied at the
  7789. // commit-phase we mark this as such.
  7790. markUpdate(workInProgress);
  7791. }
  7792. } else {
  7793. var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
  7794. appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
  7795. workInProgress.stateNode = instance;
  7796. }
  7797. if (workInProgress.ref !== null) {
  7798. // If there is a ref on a host node we need to schedule a callback
  7799. markRef$1(workInProgress);
  7800. }
  7801. }
  7802. return null;
  7803. }
  7804. case HostText:
  7805. {
  7806. var newText = newProps;
  7807. if (current && workInProgress.stateNode != null) {
  7808. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  7809. // to schedule a side-effect to do the updates.
  7810. updateHostText$1(current, workInProgress, oldText, newText);
  7811. } else {
  7812. if (typeof newText !== 'string') {
  7813. if (!(workInProgress.stateNode !== null)) {
  7814. {
  7815. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  7816. }
  7817. } // This can happen when we abort work.
  7818. }
  7819. var _rootContainerInstance = getRootHostContainer();
  7820. var _currentHostContext = getHostContext();
  7821. var _wasHydrated2 = popHydrationState();
  7822. if (_wasHydrated2) {
  7823. if (prepareToHydrateHostTextInstance()) {
  7824. markUpdate(workInProgress);
  7825. }
  7826. } else {
  7827. workInProgress.stateNode = createTextInstance(newText);
  7828. }
  7829. }
  7830. return null;
  7831. }
  7832. case SuspenseComponent:
  7833. {
  7834. popSuspenseContext(workInProgress);
  7835. var nextState = workInProgress.memoizedState;
  7836. if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
  7837. // Something suspended. Re-render with the fallback children.
  7838. workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
  7839. return workInProgress;
  7840. }
  7841. var nextDidTimeout = nextState !== null;
  7842. var prevDidTimeout = false;
  7843. if (current === null) {
  7844. if (workInProgress.memoizedProps.fallback !== undefined) ;
  7845. } else {
  7846. var prevState = current.memoizedState;
  7847. prevDidTimeout = prevState !== null;
  7848. if (!nextDidTimeout && prevState !== null) {
  7849. // We just switched from the fallback to the normal children.
  7850. // Delete the fallback.
  7851. // TODO: Would it be better to store the fallback fragment on
  7852. // the stateNode during the begin phase?
  7853. var currentFallbackChild = current.child.sibling;
  7854. if (currentFallbackChild !== null) {
  7855. // Deletions go at the beginning of the return fiber's effect list
  7856. var first = workInProgress.firstEffect;
  7857. if (first !== null) {
  7858. workInProgress.firstEffect = currentFallbackChild;
  7859. currentFallbackChild.nextEffect = first;
  7860. } else {
  7861. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
  7862. currentFallbackChild.nextEffect = null;
  7863. }
  7864. currentFallbackChild.effectTag = Deletion;
  7865. }
  7866. }
  7867. }
  7868. if (nextDidTimeout && !prevDidTimeout) {
  7869. // If this subtreee is running in blocking mode we can suspend,
  7870. // otherwise we won't suspend.
  7871. // TODO: This will still suspend a synchronous tree if anything
  7872. // in the concurrent tree already suspended during this render.
  7873. // This is a known bug.
  7874. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  7875. // TODO: Move this back to throwException because this is too late
  7876. // if this is a large tree which is common for initial loads. We
  7877. // don't know if we should restart a render or not until we get
  7878. // this marker, and this is too late.
  7879. // If this render already had a ping or lower pri updates,
  7880. // and this is the first time we know we're going to suspend we
  7881. // should be able to immediately restart from within throwException.
  7882. var hasInvisibleChildContext = current === null && workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  7883. if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
  7884. // If this was in an invisible tree or a new render, then showing
  7885. // this boundary is ok.
  7886. renderDidSuspend();
  7887. } else {
  7888. // Otherwise, we're going to have to hide content so we should
  7889. // suspend for longer if possible.
  7890. renderDidSuspendDelayIfPossible();
  7891. }
  7892. }
  7893. }
  7894. {
  7895. // TODO: Only schedule updates if these values are non equal, i.e. it changed.
  7896. if (nextDidTimeout || prevDidTimeout) {
  7897. // If this boundary just timed out, schedule an effect to attach a
  7898. // retry listener to the promise. This flag is also used to hide the
  7899. // primary children. In mutation mode, we also need the flag to
  7900. // *unhide* children that were previously hidden, so check if this
  7901. // is currently timed out, too.
  7902. workInProgress.effectTag |= Update;
  7903. }
  7904. }
  7905. return null;
  7906. }
  7907. case HostPortal:
  7908. popHostContainer(workInProgress);
  7909. updateHostContainer(workInProgress);
  7910. return null;
  7911. case ContextProvider:
  7912. // Pop provider fiber
  7913. popProvider(workInProgress);
  7914. return null;
  7915. case IncompleteClassComponent:
  7916. {
  7917. // Same as class component case. I put it down here so that the tags are
  7918. // sequential to ensure this switch is compiled to a jump table.
  7919. var _Component = workInProgress.type;
  7920. if (isContextProvider(_Component)) {
  7921. popContext(workInProgress);
  7922. }
  7923. return null;
  7924. }
  7925. case SuspenseListComponent:
  7926. {
  7927. popSuspenseContext(workInProgress);
  7928. var renderState = workInProgress.memoizedState;
  7929. if (renderState === null) {
  7930. // We're running in the default, "independent" mode.
  7931. // We don't do anything in this mode.
  7932. return null;
  7933. }
  7934. var didSuspendAlready = (workInProgress.effectTag & DidCapture) !== NoEffect;
  7935. var renderedTail = renderState.rendering;
  7936. if (renderedTail === null) {
  7937. // We just rendered the head.
  7938. if (!didSuspendAlready) {
  7939. // This is the first pass. We need to figure out if anything is still
  7940. // suspended in the rendered set.
  7941. // If new content unsuspended, but there's still some content that
  7942. // didn't. Then we need to do a second pass that forces everything
  7943. // to keep showing their fallbacks.
  7944. // We might be suspended if something in this render pass suspended, or
  7945. // something in the previous committed pass suspended. Otherwise,
  7946. // there's no chance so we can skip the expensive call to
  7947. // findFirstSuspended.
  7948. var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.effectTag & DidCapture) === NoEffect);
  7949. if (!cannotBeSuspended) {
  7950. var row = workInProgress.child;
  7951. while (row !== null) {
  7952. var suspended = findFirstSuspended(row);
  7953. if (suspended !== null) {
  7954. didSuspendAlready = true;
  7955. workInProgress.effectTag |= DidCapture;
  7956. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  7957. // part of the second pass. In that case nothing will subscribe to
  7958. // its thennables. Instead, we'll transfer its thennables to the
  7959. // SuspenseList so that it can retry if they resolve.
  7960. // There might be multiple of these in the list but since we're
  7961. // going to wait for all of them anyway, it doesn't really matter
  7962. // which ones gets to ping. In theory we could get clever and keep
  7963. // track of how many dependencies remain but it gets tricky because
  7964. // in the meantime, we can add/remove/change items and dependencies.
  7965. // We might bail out of the loop before finding any but that
  7966. // doesn't matter since that means that the other boundaries that
  7967. // we did find already has their listeners attached.
  7968. var newThennables = suspended.updateQueue;
  7969. if (newThennables !== null) {
  7970. workInProgress.updateQueue = newThennables;
  7971. workInProgress.effectTag |= Update;
  7972. } // Rerender the whole list, but this time, we'll force fallbacks
  7973. // to stay in place.
  7974. // Reset the effect list before doing the second pass since that's now invalid.
  7975. if (renderState.lastEffect === null) {
  7976. workInProgress.firstEffect = null;
  7977. }
  7978. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  7979. resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
  7980. // rerender the children.
  7981. pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback));
  7982. return workInProgress.child;
  7983. }
  7984. row = row.sibling;
  7985. }
  7986. }
  7987. } else {
  7988. cutOffTailIfNeeded(renderState, false);
  7989. } // Next we're going to render the tail.
  7990. } else {
  7991. // Append the rendered row to the child list.
  7992. if (!didSuspendAlready) {
  7993. var _suspended = findFirstSuspended(renderedTail);
  7994. if (_suspended !== null) {
  7995. workInProgress.effectTag |= DidCapture;
  7996. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  7997. // get lost if this row ends up dropped during a second pass.
  7998. var _newThennables = _suspended.updateQueue;
  7999. if (_newThennables !== null) {
  8000. workInProgress.updateQueue = _newThennables;
  8001. workInProgress.effectTag |= Update;
  8002. }
  8003. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  8004. if (renderState.tail === null && renderState.tailMode === 'hidden' && !renderedTail.alternate) {
  8005. // We need to delete the row we just rendered.
  8006. // Reset the effect list to what it was before we rendered this
  8007. // child. The nested children have already appended themselves.
  8008. var lastEffect = workInProgress.lastEffect = renderState.lastEffect; // Remove any effects that were appended after this point.
  8009. if (lastEffect !== null) {
  8010. lastEffect.nextEffect = null;
  8011. } // We're done.
  8012. return null;
  8013. }
  8014. } else if ( // The time it took to render last row is greater than time until
  8015. // the expiration.
  8016. now() * 2 - renderState.renderingStartTime > renderState.tailExpiration && renderExpirationTime > Never) {
  8017. // We have now passed our CPU deadline and we'll just give up further
  8018. // attempts to render the main content and only render fallbacks.
  8019. // The assumption is that this is usually faster.
  8020. workInProgress.effectTag |= DidCapture;
  8021. didSuspendAlready = true;
  8022. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  8023. // to get it started back up to attempt the next item. If we can show
  8024. // them, then they really have the same priority as this render.
  8025. // So we'll pick it back up the very next render pass once we've had
  8026. // an opportunity to yield for paint.
  8027. var nextPriority = renderExpirationTime - 1;
  8028. workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
  8029. {
  8030. markSpawnedWork(nextPriority);
  8031. }
  8032. }
  8033. }
  8034. if (renderState.isBackwards) {
  8035. // The effect list of the backwards tail will have been added
  8036. // to the end. This breaks the guarantee that life-cycles fire in
  8037. // sibling order but that isn't a strong guarantee promised by React.
  8038. // Especially since these might also just pop in during future commits.
  8039. // Append to the beginning of the list.
  8040. renderedTail.sibling = workInProgress.child;
  8041. workInProgress.child = renderedTail;
  8042. } else {
  8043. var previousSibling = renderState.last;
  8044. if (previousSibling !== null) {
  8045. previousSibling.sibling = renderedTail;
  8046. } else {
  8047. workInProgress.child = renderedTail;
  8048. }
  8049. renderState.last = renderedTail;
  8050. }
  8051. }
  8052. if (renderState.tail !== null) {
  8053. // We still have tail rows to render.
  8054. if (renderState.tailExpiration === 0) {
  8055. // Heuristic for how long we're willing to spend rendering rows
  8056. // until we just give up and show what we have so far.
  8057. var TAIL_EXPIRATION_TIMEOUT_MS = 500;
  8058. renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS; // TODO: This is meant to mimic the train model or JND but this
  8059. // is a per component value. It should really be since the start
  8060. // of the total render or last commit. Consider using something like
  8061. // globalMostRecentFallbackTime. That doesn't account for being
  8062. // suspended for part of the time or when it's a new render.
  8063. // It should probably use a global start time value instead.
  8064. } // Pop a row.
  8065. var next = renderState.tail;
  8066. renderState.rendering = next;
  8067. renderState.tail = next.sibling;
  8068. renderState.lastEffect = workInProgress.lastEffect;
  8069. renderState.renderingStartTime = now();
  8070. next.sibling = null; // Restore the context.
  8071. // TODO: We can probably just avoid popping it instead and only
  8072. // setting it the first time we go from not suspended to suspended.
  8073. var suspenseContext = suspenseStackCursor.current;
  8074. if (didSuspendAlready) {
  8075. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  8076. } else {
  8077. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  8078. }
  8079. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  8080. return next;
  8081. }
  8082. return null;
  8083. }
  8084. }
  8085. {
  8086. {
  8087. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  8088. }
  8089. }
  8090. }
  8091. function unwindWork(workInProgress, renderExpirationTime) {
  8092. switch (workInProgress.tag) {
  8093. case ClassComponent:
  8094. {
  8095. var Component = workInProgress.type;
  8096. if (isContextProvider(Component)) {
  8097. popContext(workInProgress);
  8098. }
  8099. var effectTag = workInProgress.effectTag;
  8100. if (effectTag & ShouldCapture) {
  8101. workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
  8102. return workInProgress;
  8103. }
  8104. return null;
  8105. }
  8106. case HostRoot:
  8107. {
  8108. popHostContainer(workInProgress);
  8109. popTopLevelContextObject(workInProgress);
  8110. var _effectTag = workInProgress.effectTag;
  8111. if (!((_effectTag & DidCapture) === NoEffect)) {
  8112. {
  8113. throw Error( "The root failed to unmount after an error. This is likely a bug in React. Please file an issue." );
  8114. }
  8115. }
  8116. workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
  8117. return workInProgress;
  8118. }
  8119. case HostComponent:
  8120. {
  8121. // TODO: popHydrationState
  8122. popHostContext(workInProgress);
  8123. return null;
  8124. }
  8125. case SuspenseComponent:
  8126. {
  8127. popSuspenseContext(workInProgress);
  8128. var _effectTag2 = workInProgress.effectTag;
  8129. if (_effectTag2 & ShouldCapture) {
  8130. workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
  8131. return workInProgress;
  8132. }
  8133. return null;
  8134. }
  8135. case SuspenseListComponent:
  8136. {
  8137. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  8138. // caught by a nested boundary. If not, it should bubble through.
  8139. return null;
  8140. }
  8141. case HostPortal:
  8142. popHostContainer(workInProgress);
  8143. return null;
  8144. case ContextProvider:
  8145. popProvider(workInProgress);
  8146. return null;
  8147. default:
  8148. return null;
  8149. }
  8150. }
  8151. function unwindInterruptedWork(interruptedWork) {
  8152. switch (interruptedWork.tag) {
  8153. case ClassComponent:
  8154. {
  8155. var childContextTypes = interruptedWork.type.childContextTypes;
  8156. if (childContextTypes !== null && childContextTypes !== undefined) {
  8157. popContext(interruptedWork);
  8158. }
  8159. break;
  8160. }
  8161. case HostRoot:
  8162. {
  8163. popHostContainer(interruptedWork);
  8164. popTopLevelContextObject(interruptedWork);
  8165. break;
  8166. }
  8167. case HostComponent:
  8168. {
  8169. popHostContext(interruptedWork);
  8170. break;
  8171. }
  8172. case HostPortal:
  8173. popHostContainer(interruptedWork);
  8174. break;
  8175. case SuspenseComponent:
  8176. popSuspenseContext(interruptedWork);
  8177. break;
  8178. case SuspenseListComponent:
  8179. popSuspenseContext(interruptedWork);
  8180. break;
  8181. case ContextProvider:
  8182. popProvider(interruptedWork);
  8183. break;
  8184. }
  8185. }
  8186. function createCapturedValue(value, source) {
  8187. // If the value is an error, call this function immediately after it is thrown
  8188. // so the stack is accurate.
  8189. return {
  8190. value: value,
  8191. source: source,
  8192. stack: getStackByFiberInDevAndProd(source)
  8193. };
  8194. }
  8195. var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
  8196. var funcArgs = Array.prototype.slice.call(arguments, 3);
  8197. try {
  8198. func.apply(context, funcArgs);
  8199. } catch (error) {
  8200. this.onError(error);
  8201. }
  8202. };
  8203. {
  8204. // In DEV mode, we swap out invokeGuardedCallback for a special version
  8205. // that plays more nicely with the browser's DevTools. The idea is to preserve
  8206. // "Pause on exceptions" behavior. Because React wraps all user-provided
  8207. // functions in invokeGuardedCallback, and the production version of
  8208. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  8209. // like caught exceptions, and the DevTools won't pause unless the developer
  8210. // takes the extra step of enabling pause on caught exceptions. This is
  8211. // unintuitive, though, because even though React has caught the error, from
  8212. // the developer's perspective, the error is uncaught.
  8213. //
  8214. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  8215. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  8216. // DOM node, and call the user-provided callback from inside an event handler
  8217. // for that fake event. If the callback throws, the error is "captured" using
  8218. // a global event handler. But because the error happens in a different
  8219. // event loop context, it does not interrupt the normal program flow.
  8220. // Effectively, this gives us try-catch behavior without actually using
  8221. // try-catch. Neat!
  8222. // Check that the browser supports the APIs we need to implement our special
  8223. // DEV version of invokeGuardedCallback
  8224. if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
  8225. var fakeNode = document.createElement('react');
  8226. var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
  8227. // If document doesn't exist we know for sure we will crash in this method
  8228. // when we call document.createEvent(). However this can cause confusing
  8229. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  8230. // So we preemptively throw with a better message instead.
  8231. if (!(typeof document !== 'undefined')) {
  8232. {
  8233. 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." );
  8234. }
  8235. }
  8236. var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
  8237. // set this to true at the beginning, then set it to false right after
  8238. // calling the function. If the function errors, `didError` will never be
  8239. // set to false. This strategy works even if the browser is flaky and
  8240. // fails to call our global error handler, because it doesn't rely on
  8241. // the error event at all.
  8242. var didError = true; // Keeps track of the value of window.event so that we can reset it
  8243. // during the callback to let user code access window.event in the
  8244. // browsers that support it.
  8245. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  8246. // dispatching: https://github.com/facebook/react/issues/13688
  8247. var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event'); // Create an event handler for our fake event. We will synchronously
  8248. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  8249. // call the user-provided callback.
  8250. var funcArgs = Array.prototype.slice.call(arguments, 3);
  8251. function callCallback() {
  8252. // We immediately remove the callback from event listeners so that
  8253. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  8254. // nested call would trigger the fake event handlers of any call higher
  8255. // in the stack.
  8256. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  8257. // window.event assignment in both IE <= 10 as they throw an error
  8258. // "Member not found" in strict mode, and in Firefox which does not
  8259. // support window.event.
  8260. if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
  8261. window.event = windowEvent;
  8262. }
  8263. func.apply(context, funcArgs);
  8264. didError = false;
  8265. } // Create a global error event handler. We use this to capture the value
  8266. // that was thrown. It's possible that this error handler will fire more
  8267. // than once; for example, if non-React code also calls `dispatchEvent`
  8268. // and a handler for that event throws. We should be resilient to most of
  8269. // those cases. Even if our error event handler fires more than once, the
  8270. // last error event is always used. If the callback actually does error,
  8271. // we know that the last error event is the correct one, because it's not
  8272. // possible for anything else to have happened in between our callback
  8273. // erroring and the code that follows the `dispatchEvent` call below. If
  8274. // the callback doesn't error, but the error event was fired, we know to
  8275. // ignore it because `didError` will be false, as described above.
  8276. var error; // Use this to track whether the error event is ever called.
  8277. var didSetError = false;
  8278. var isCrossOriginError = false;
  8279. function handleWindowError(event) {
  8280. error = event.error;
  8281. didSetError = true;
  8282. if (error === null && event.colno === 0 && event.lineno === 0) {
  8283. isCrossOriginError = true;
  8284. }
  8285. if (event.defaultPrevented) {
  8286. // Some other error handler has prevented default.
  8287. // Browsers silence the error report if this happens.
  8288. // We'll remember this to later decide whether to log it or not.
  8289. if (error != null && typeof error === 'object') {
  8290. try {
  8291. error._suppressLogging = true;
  8292. } catch (inner) {// Ignore.
  8293. }
  8294. }
  8295. }
  8296. } // Create a fake event type.
  8297. var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
  8298. window.addEventListener('error', handleWindowError);
  8299. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  8300. // errors, it will trigger our global error handler.
  8301. evt.initEvent(evtType, false, false);
  8302. fakeNode.dispatchEvent(evt);
  8303. if (windowEventDescriptor) {
  8304. Object.defineProperty(window, 'event', windowEventDescriptor);
  8305. }
  8306. if (didError) {
  8307. if (!didSetError) {
  8308. // The callback errored, but the error event never fired.
  8309. 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.');
  8310. } else if (isCrossOriginError) {
  8311. 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.');
  8312. }
  8313. this.onError(error);
  8314. } // Remove our event listeners
  8315. window.removeEventListener('error', handleWindowError);
  8316. };
  8317. invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
  8318. }
  8319. }
  8320. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  8321. var hasError = false;
  8322. var caughtError = null; // Used by event system to capture/rethrow the first error.
  8323. var reporter = {
  8324. onError: function (error) {
  8325. hasError = true;
  8326. caughtError = error;
  8327. }
  8328. };
  8329. /**
  8330. * Call a function while guarding against errors that happens within it.
  8331. * Returns an error if it throws, otherwise null.
  8332. *
  8333. * In production, this is implemented using a try-catch. The reason we don't
  8334. * use a try-catch directly is so that we can swap out a different
  8335. * implementation in DEV mode.
  8336. *
  8337. * @param {String} name of the guard to use for logging or debugging
  8338. * @param {Function} func The function to invoke
  8339. * @param {*} context The context to use when calling the function
  8340. * @param {...*} args Arguments for function
  8341. */
  8342. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  8343. hasError = false;
  8344. caughtError = null;
  8345. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  8346. }
  8347. function hasCaughtError() {
  8348. return hasError;
  8349. }
  8350. function clearCaughtError() {
  8351. if (hasError) {
  8352. var error = caughtError;
  8353. hasError = false;
  8354. caughtError = null;
  8355. return error;
  8356. } else {
  8357. {
  8358. {
  8359. throw Error( "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue." );
  8360. }
  8361. }
  8362. }
  8363. }
  8364. function logCapturedError(capturedError) {
  8365. var error = capturedError.error;
  8366. {
  8367. var componentName = capturedError.componentName,
  8368. componentStack = capturedError.componentStack,
  8369. errorBoundaryName = capturedError.errorBoundaryName,
  8370. errorBoundaryFound = capturedError.errorBoundaryFound,
  8371. willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
  8372. // `preventDefault()` in window `error` handler.
  8373. // We record this information as an expando on the error.
  8374. if (error != null && error._suppressLogging) {
  8375. if (errorBoundaryFound && willRetry) {
  8376. // The error is recoverable and was silenced.
  8377. // Ignore it and don't print the stack addendum.
  8378. // This is handy for testing error boundaries without noise.
  8379. return;
  8380. } // The error is fatal. Since the silencing might have
  8381. // been accidental, we'll surface it anyway.
  8382. // However, the browser would have silenced the original error
  8383. // so we'll print it first, and then print the stack addendum.
  8384. console['error'](error); // Don't transform to our wrapper
  8385. // For a more detailed description of this block, see:
  8386. // https://github.com/facebook/react/pull/13384
  8387. }
  8388. var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
  8389. var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
  8390. if (errorBoundaryFound && errorBoundaryName) {
  8391. if (willRetry) {
  8392. errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
  8393. } else {
  8394. errorBoundaryMessage = "This error was initially handled by the error boundary " + errorBoundaryName + ".\n" + "Recreating the tree from scratch failed so React will unmount the tree.";
  8395. }
  8396. } else {
  8397. 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.';
  8398. }
  8399. var combinedMessage = "" + componentNameMessage + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  8400. // We don't include the original error message and JS stack because the browser
  8401. // has already printed it. Even if the application swallows the error, it is still
  8402. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  8403. console['error'](combinedMessage); // Don't transform to our wrapper
  8404. }
  8405. }
  8406. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  8407. {
  8408. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  8409. }
  8410. var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
  8411. function logError(boundary, errorInfo) {
  8412. var source = errorInfo.source;
  8413. var stack = errorInfo.stack;
  8414. if (stack === null && source !== null) {
  8415. stack = getStackByFiberInDevAndProd(source);
  8416. }
  8417. var capturedError = {
  8418. componentName: source !== null ? getComponentName(source.type) : null,
  8419. componentStack: stack !== null ? stack : '',
  8420. error: errorInfo.value,
  8421. errorBoundary: null,
  8422. errorBoundaryName: null,
  8423. errorBoundaryFound: false,
  8424. willRetry: false
  8425. };
  8426. if (boundary !== null && boundary.tag === ClassComponent) {
  8427. capturedError.errorBoundary = boundary.stateNode;
  8428. capturedError.errorBoundaryName = getComponentName(boundary.type);
  8429. capturedError.errorBoundaryFound = true;
  8430. capturedError.willRetry = true;
  8431. }
  8432. try {
  8433. logCapturedError(capturedError);
  8434. } catch (e) {
  8435. // This method must not throw, or React internal state will get messed up.
  8436. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  8437. // we want to report this error outside of the normal stack as a last resort.
  8438. // https://github.com/facebook/react/issues/13188
  8439. setTimeout(function () {
  8440. throw e;
  8441. });
  8442. }
  8443. }
  8444. var callComponentWillUnmountWithTimer = function (current, instance) {
  8445. startPhaseTimer(current, 'componentWillUnmount');
  8446. instance.props = current.memoizedProps;
  8447. instance.state = current.memoizedState;
  8448. instance.componentWillUnmount();
  8449. stopPhaseTimer();
  8450. }; // Capture errors so they don't interrupt unmounting.
  8451. function safelyCallComponentWillUnmount(current, instance) {
  8452. {
  8453. invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current, instance);
  8454. if (hasCaughtError()) {
  8455. var unmountError = clearCaughtError();
  8456. captureCommitPhaseError(current, unmountError);
  8457. }
  8458. }
  8459. }
  8460. function safelyDetachRef(current) {
  8461. var ref = current.ref;
  8462. if (ref !== null) {
  8463. if (typeof ref === 'function') {
  8464. {
  8465. invokeGuardedCallback(null, ref, null, null);
  8466. if (hasCaughtError()) {
  8467. var refError = clearCaughtError();
  8468. captureCommitPhaseError(current, refError);
  8469. }
  8470. }
  8471. } else {
  8472. ref.current = null;
  8473. }
  8474. }
  8475. }
  8476. function safelyCallDestroy(current, destroy) {
  8477. {
  8478. invokeGuardedCallback(null, destroy, null);
  8479. if (hasCaughtError()) {
  8480. var error = clearCaughtError();
  8481. captureCommitPhaseError(current, error);
  8482. }
  8483. }
  8484. }
  8485. function commitBeforeMutationLifeCycles(current, finishedWork) {
  8486. switch (finishedWork.tag) {
  8487. case FunctionComponent:
  8488. case ForwardRef:
  8489. case SimpleMemoComponent:
  8490. case Block:
  8491. {
  8492. return;
  8493. }
  8494. case ClassComponent:
  8495. {
  8496. if (finishedWork.effectTag & Snapshot) {
  8497. if (current !== null) {
  8498. var prevProps = current.memoizedProps;
  8499. var prevState = current.memoizedState;
  8500. startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
  8501. var instance = finishedWork.stateNode; // We could update instance props and state here,
  8502. // but instead we rely on them being set during last render.
  8503. // TODO: revisit this when we implement resuming.
  8504. {
  8505. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8506. if (instance.props !== finishedWork.memoizedProps) {
  8507. 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');
  8508. }
  8509. if (instance.state !== finishedWork.memoizedState) {
  8510. 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');
  8511. }
  8512. }
  8513. }
  8514. var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
  8515. {
  8516. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  8517. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  8518. didWarnSet.add(finishedWork.type);
  8519. error('%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
  8520. }
  8521. }
  8522. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  8523. stopPhaseTimer();
  8524. }
  8525. }
  8526. return;
  8527. }
  8528. case HostRoot:
  8529. case HostComponent:
  8530. case HostText:
  8531. case HostPortal:
  8532. case IncompleteClassComponent:
  8533. // Nothing to do for these component types
  8534. return;
  8535. }
  8536. {
  8537. {
  8538. 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." );
  8539. }
  8540. }
  8541. }
  8542. function commitHookEffectListUnmount(tag, finishedWork) {
  8543. var updateQueue = finishedWork.updateQueue;
  8544. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  8545. if (lastEffect !== null) {
  8546. var firstEffect = lastEffect.next;
  8547. var effect = firstEffect;
  8548. do {
  8549. if ((effect.tag & tag) === tag) {
  8550. // Unmount
  8551. var destroy = effect.destroy;
  8552. effect.destroy = undefined;
  8553. if (destroy !== undefined) {
  8554. destroy();
  8555. }
  8556. }
  8557. effect = effect.next;
  8558. } while (effect !== firstEffect);
  8559. }
  8560. }
  8561. function commitHookEffectListMount(tag, finishedWork) {
  8562. var updateQueue = finishedWork.updateQueue;
  8563. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  8564. if (lastEffect !== null) {
  8565. var firstEffect = lastEffect.next;
  8566. var effect = firstEffect;
  8567. do {
  8568. if ((effect.tag & tag) === tag) {
  8569. // Mount
  8570. var create = effect.create;
  8571. effect.destroy = create();
  8572. {
  8573. var destroy = effect.destroy;
  8574. if (destroy !== undefined && typeof destroy !== 'function') {
  8575. var addendum = void 0;
  8576. if (destroy === null) {
  8577. addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
  8578. } else if (typeof destroy.then === 'function') {
  8579. 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';
  8580. } else {
  8581. addendum = ' You returned: ' + destroy;
  8582. }
  8583. error('An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
  8584. }
  8585. }
  8586. }
  8587. effect = effect.next;
  8588. } while (effect !== firstEffect);
  8589. }
  8590. }
  8591. function commitPassiveHookEffects(finishedWork) {
  8592. if ((finishedWork.effectTag & Passive) !== NoEffect) {
  8593. switch (finishedWork.tag) {
  8594. case FunctionComponent:
  8595. case ForwardRef:
  8596. case SimpleMemoComponent:
  8597. case Block:
  8598. {
  8599. // TODO (#17945) We should call all passive destroy functions (for all fibers)
  8600. // before calling any create functions. The current approach only serializes
  8601. // these for a single fiber.
  8602. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
  8603. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  8604. break;
  8605. }
  8606. }
  8607. }
  8608. }
  8609. function commitLifeCycles(finishedRoot, current, finishedWork, committedExpirationTime) {
  8610. switch (finishedWork.tag) {
  8611. case FunctionComponent:
  8612. case ForwardRef:
  8613. case SimpleMemoComponent:
  8614. case Block:
  8615. {
  8616. // At this point layout effects have already been destroyed (during mutation phase).
  8617. // This is done to prevent sibling component effects from interfering with each other,
  8618. // e.g. a destroy function in one component should never override a ref set
  8619. // by a create function in another component during the same commit.
  8620. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  8621. return;
  8622. }
  8623. case ClassComponent:
  8624. {
  8625. var instance = finishedWork.stateNode;
  8626. if (finishedWork.effectTag & Update) {
  8627. if (current === null) {
  8628. startPhaseTimer(finishedWork, 'componentDidMount'); // We could update instance props and state here,
  8629. // but instead we rely on them being set during last render.
  8630. // TODO: revisit this when we implement resuming.
  8631. {
  8632. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8633. if (instance.props !== finishedWork.memoizedProps) {
  8634. 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');
  8635. }
  8636. if (instance.state !== finishedWork.memoizedState) {
  8637. 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');
  8638. }
  8639. }
  8640. }
  8641. instance.componentDidMount();
  8642. stopPhaseTimer();
  8643. } else {
  8644. var prevProps = finishedWork.elementType === finishedWork.type ? current.memoizedProps : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  8645. var prevState = current.memoizedState;
  8646. startPhaseTimer(finishedWork, 'componentDidUpdate'); // We could update instance props and state here,
  8647. // but instead we rely on them being set during last render.
  8648. // TODO: revisit this when we implement resuming.
  8649. {
  8650. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8651. if (instance.props !== finishedWork.memoizedProps) {
  8652. 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');
  8653. }
  8654. if (instance.state !== finishedWork.memoizedState) {
  8655. 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');
  8656. }
  8657. }
  8658. }
  8659. instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
  8660. stopPhaseTimer();
  8661. }
  8662. }
  8663. var updateQueue = finishedWork.updateQueue;
  8664. if (updateQueue !== null) {
  8665. {
  8666. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8667. if (instance.props !== finishedWork.memoizedProps) {
  8668. 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');
  8669. }
  8670. if (instance.state !== finishedWork.memoizedState) {
  8671. 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');
  8672. }
  8673. }
  8674. } // We could update instance props and state here,
  8675. // but instead we rely on them being set during last render.
  8676. // TODO: revisit this when we implement resuming.
  8677. commitUpdateQueue(finishedWork, updateQueue, instance);
  8678. }
  8679. return;
  8680. }
  8681. case HostRoot:
  8682. {
  8683. var _updateQueue = finishedWork.updateQueue;
  8684. if (_updateQueue !== null) {
  8685. var _instance = null;
  8686. if (finishedWork.child !== null) {
  8687. switch (finishedWork.child.tag) {
  8688. case HostComponent:
  8689. _instance = getPublicInstance(finishedWork.child.stateNode);
  8690. break;
  8691. case ClassComponent:
  8692. _instance = finishedWork.child.stateNode;
  8693. break;
  8694. }
  8695. }
  8696. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  8697. }
  8698. return;
  8699. }
  8700. case HostComponent:
  8701. {
  8702. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  8703. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  8704. // These effects should only be committed when components are first mounted,
  8705. // aka when there is no current/alternate.
  8706. if (current === null && finishedWork.effectTag & Update) {
  8707. var type = finishedWork.type;
  8708. var props = finishedWork.memoizedProps;
  8709. }
  8710. return;
  8711. }
  8712. case HostText:
  8713. {
  8714. // We have no life-cycles associated with text.
  8715. return;
  8716. }
  8717. case HostPortal:
  8718. {
  8719. // We have no life-cycles associated with portals.
  8720. return;
  8721. }
  8722. case Profiler:
  8723. {
  8724. {
  8725. var onRender = finishedWork.memoizedProps.onRender;
  8726. if (typeof onRender === 'function') {
  8727. {
  8728. onRender(finishedWork.memoizedProps.id, current === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
  8729. }
  8730. }
  8731. }
  8732. return;
  8733. }
  8734. case SuspenseComponent:
  8735. {
  8736. return;
  8737. }
  8738. case SuspenseListComponent:
  8739. case IncompleteClassComponent:
  8740. case FundamentalComponent:
  8741. case ScopeComponent:
  8742. return;
  8743. }
  8744. {
  8745. {
  8746. 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." );
  8747. }
  8748. }
  8749. }
  8750. function hideOrUnhideAllChildren(finishedWork, isHidden) {
  8751. {
  8752. // We only have the top Fiber that was inserted but we need to recurse down its
  8753. // children to find all the terminal nodes.
  8754. var node = finishedWork;
  8755. while (true) {
  8756. if (node.tag === HostComponent) {
  8757. var instance = node.stateNode;
  8758. if (isHidden) {
  8759. hideInstance(instance);
  8760. } else {
  8761. unhideInstance(node.stateNode, node.memoizedProps);
  8762. }
  8763. } else if (node.tag === HostText) {
  8764. var _instance3 = node.stateNode;
  8765. if (isHidden) {
  8766. hideTextInstance(_instance3);
  8767. } else {
  8768. unhideTextInstance(_instance3, node.memoizedProps);
  8769. }
  8770. } else if (node.tag === SuspenseComponent && node.memoizedState !== null && node.memoizedState.dehydrated === null) {
  8771. // Found a nested Suspense component that timed out. Skip over the
  8772. // primary child fragment, which should remain hidden.
  8773. var fallbackChildFragment = node.child.sibling;
  8774. fallbackChildFragment.return = node;
  8775. node = fallbackChildFragment;
  8776. continue;
  8777. } else if (node.child !== null) {
  8778. node.child.return = node;
  8779. node = node.child;
  8780. continue;
  8781. }
  8782. if (node === finishedWork) {
  8783. return;
  8784. }
  8785. while (node.sibling === null) {
  8786. if (node.return === null || node.return === finishedWork) {
  8787. return;
  8788. }
  8789. node = node.return;
  8790. }
  8791. node.sibling.return = node.return;
  8792. node = node.sibling;
  8793. }
  8794. }
  8795. }
  8796. function commitAttachRef(finishedWork) {
  8797. var ref = finishedWork.ref;
  8798. if (ref !== null) {
  8799. var instance = finishedWork.stateNode;
  8800. var instanceToUse;
  8801. switch (finishedWork.tag) {
  8802. case HostComponent:
  8803. instanceToUse = getPublicInstance(instance);
  8804. break;
  8805. default:
  8806. instanceToUse = instance;
  8807. } // Moved outside to ensure DCE works with this flag
  8808. if (typeof ref === 'function') {
  8809. ref(instanceToUse);
  8810. } else {
  8811. {
  8812. if (!ref.hasOwnProperty('current')) {
  8813. error('Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
  8814. }
  8815. }
  8816. ref.current = instanceToUse;
  8817. }
  8818. }
  8819. }
  8820. function commitDetachRef(current) {
  8821. var currentRef = current.ref;
  8822. if (currentRef !== null) {
  8823. if (typeof currentRef === 'function') {
  8824. currentRef(null);
  8825. } else {
  8826. currentRef.current = null;
  8827. }
  8828. }
  8829. } // User-originating errors (lifecycles and refs) should not interrupt
  8830. // deletion, so don't let them throw. Host-originating errors should
  8831. // interrupt deletion, so it's okay
  8832. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  8833. onCommitUnmount(current);
  8834. switch (current.tag) {
  8835. case FunctionComponent:
  8836. case ForwardRef:
  8837. case MemoComponent:
  8838. case SimpleMemoComponent:
  8839. case Block:
  8840. {
  8841. var updateQueue = current.updateQueue;
  8842. if (updateQueue !== null) {
  8843. var lastEffect = updateQueue.lastEffect;
  8844. if (lastEffect !== null) {
  8845. var firstEffect = lastEffect.next;
  8846. {
  8847. // When the owner fiber is deleted, the destroy function of a passive
  8848. // effect hook is called during the synchronous commit phase. This is
  8849. // a concession to implementation complexity. Calling it in the
  8850. // passive effect phase (like they usually are, when dependencies
  8851. // change during an update) would require either traversing the
  8852. // children of the deleted fiber again, or including unmount effects
  8853. // as part of the fiber effect list.
  8854. //
  8855. // Because this is during the sync commit phase, we need to change
  8856. // the priority.
  8857. //
  8858. // TODO: Reconsider this implementation trade off.
  8859. var priorityLevel = renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel;
  8860. runWithPriority(priorityLevel, function () {
  8861. var effect = firstEffect;
  8862. do {
  8863. var _destroy = effect.destroy;
  8864. if (_destroy !== undefined) {
  8865. safelyCallDestroy(current, _destroy);
  8866. }
  8867. effect = effect.next;
  8868. } while (effect !== firstEffect);
  8869. });
  8870. }
  8871. }
  8872. }
  8873. return;
  8874. }
  8875. case ClassComponent:
  8876. {
  8877. safelyDetachRef(current);
  8878. var instance = current.stateNode;
  8879. if (typeof instance.componentWillUnmount === 'function') {
  8880. safelyCallComponentWillUnmount(current, instance);
  8881. }
  8882. return;
  8883. }
  8884. case HostComponent:
  8885. {
  8886. safelyDetachRef(current);
  8887. return;
  8888. }
  8889. case HostPortal:
  8890. {
  8891. // TODO: this is recursive.
  8892. // We are also not using this parent because
  8893. // the portal will get pushed immediately.
  8894. {
  8895. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  8896. }
  8897. return;
  8898. }
  8899. case FundamentalComponent:
  8900. {
  8901. return;
  8902. }
  8903. case DehydratedFragment:
  8904. {
  8905. return;
  8906. }
  8907. case ScopeComponent:
  8908. {
  8909. return;
  8910. }
  8911. }
  8912. }
  8913. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  8914. // While we're inside a removed host node we don't want to call
  8915. // removeChild on the inner nodes because they're removed by the top
  8916. // call anyway. We also want to call componentWillUnmount on all
  8917. // composites before this host node is removed from the tree. Therefore
  8918. // we do an inner loop while we're still inside the host node.
  8919. var node = root;
  8920. while (true) {
  8921. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
  8922. // Skip portals because commitUnmount() currently visits them recursively.
  8923. if (node.child !== null && ( // If we use mutation we drill down into portals using commitUnmount above.
  8924. // If we don't use mutation we drill down into portals here instead.
  8925. node.tag !== HostPortal)) {
  8926. node.child.return = node;
  8927. node = node.child;
  8928. continue;
  8929. }
  8930. if (node === root) {
  8931. return;
  8932. }
  8933. while (node.sibling === null) {
  8934. if (node.return === null || node.return === root) {
  8935. return;
  8936. }
  8937. node = node.return;
  8938. }
  8939. node.sibling.return = node.return;
  8940. node = node.sibling;
  8941. }
  8942. }
  8943. function detachFiber(current) {
  8944. var alternate = current.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
  8945. // should clear the child pointer of the parent alternate to let this
  8946. // get GC:ed but we don't know which for sure which parent is the current
  8947. // one so we'll settle for GC:ing the subtree of this child. This child
  8948. // itself will be GC:ed when the parent updates the next time.
  8949. current.return = null;
  8950. current.child = null;
  8951. current.memoizedState = null;
  8952. current.updateQueue = null;
  8953. current.dependencies = null;
  8954. current.alternate = null;
  8955. current.firstEffect = null;
  8956. current.lastEffect = null;
  8957. current.pendingProps = null;
  8958. current.memoizedProps = null;
  8959. current.stateNode = null;
  8960. if (alternate !== null) {
  8961. detachFiber(alternate);
  8962. }
  8963. }
  8964. function getHostParentFiber(fiber) {
  8965. var parent = fiber.return;
  8966. while (parent !== null) {
  8967. if (isHostParent(parent)) {
  8968. return parent;
  8969. }
  8970. parent = parent.return;
  8971. }
  8972. {
  8973. {
  8974. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  8975. }
  8976. }
  8977. }
  8978. function isHostParent(fiber) {
  8979. return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
  8980. }
  8981. function getHostSibling(fiber) {
  8982. // We're going to search forward into the tree until we find a sibling host
  8983. // node. Unfortunately, if multiple insertions are done in a row we have to
  8984. // search past them. This leads to exponential search for the next sibling.
  8985. // TODO: Find a more efficient way to do this.
  8986. var node = fiber;
  8987. siblings: while (true) {
  8988. // If we didn't find anything, let's try the next sibling.
  8989. while (node.sibling === null) {
  8990. if (node.return === null || isHostParent(node.return)) {
  8991. // If we pop out of the root or hit the parent the fiber we are the
  8992. // last sibling.
  8993. return null;
  8994. }
  8995. node = node.return;
  8996. }
  8997. node.sibling.return = node.return;
  8998. node = node.sibling;
  8999. while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
  9000. // If it is not host node and, we might have a host node inside it.
  9001. // Try to search down until we find one.
  9002. if (node.effectTag & Placement) {
  9003. // If we don't have a child, try the siblings instead.
  9004. continue siblings;
  9005. } // If we don't have a child, try the siblings instead.
  9006. // We also skip portals because they are not part of this host tree.
  9007. if (node.child === null || node.tag === HostPortal) {
  9008. continue siblings;
  9009. } else {
  9010. node.child.return = node;
  9011. node = node.child;
  9012. }
  9013. } // Check if this host node is stable or about to be placed.
  9014. if (!(node.effectTag & Placement)) {
  9015. // Found it!
  9016. return node.stateNode;
  9017. }
  9018. }
  9019. }
  9020. function commitPlacement(finishedWork) {
  9021. var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
  9022. var parent;
  9023. var isContainer;
  9024. var parentStateNode = parentFiber.stateNode;
  9025. switch (parentFiber.tag) {
  9026. case HostComponent:
  9027. parent = parentStateNode;
  9028. isContainer = false;
  9029. break;
  9030. case HostRoot:
  9031. parent = parentStateNode.containerInfo;
  9032. isContainer = true;
  9033. break;
  9034. case HostPortal:
  9035. parent = parentStateNode.containerInfo;
  9036. isContainer = true;
  9037. break;
  9038. case FundamentalComponent:
  9039. // eslint-disable-next-line-no-fallthrough
  9040. default:
  9041. {
  9042. {
  9043. throw Error( "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." );
  9044. }
  9045. }
  9046. }
  9047. if (parentFiber.effectTag & ContentReset) {
  9048. parentFiber.effectTag &= ~ContentReset;
  9049. }
  9050. var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
  9051. // children to find all the terminal nodes.
  9052. if (isContainer) {
  9053. insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
  9054. } else {
  9055. insertOrAppendPlacementNode(finishedWork, before, parent);
  9056. }
  9057. }
  9058. function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
  9059. var tag = node.tag;
  9060. var isHost = tag === HostComponent || tag === HostText;
  9061. if (isHost || enableFundamentalAPI ) {
  9062. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  9063. if (before) {
  9064. insertInContainerBefore(parent, stateNode, before);
  9065. } else {
  9066. appendChildToContainer(parent, stateNode);
  9067. }
  9068. } else if (tag === HostPortal) ; else {
  9069. var child = node.child;
  9070. if (child !== null) {
  9071. insertOrAppendPlacementNodeIntoContainer(child, before, parent);
  9072. var sibling = child.sibling;
  9073. while (sibling !== null) {
  9074. insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
  9075. sibling = sibling.sibling;
  9076. }
  9077. }
  9078. }
  9079. }
  9080. function insertOrAppendPlacementNode(node, before, parent) {
  9081. var tag = node.tag;
  9082. var isHost = tag === HostComponent || tag === HostText;
  9083. if (isHost || enableFundamentalAPI ) {
  9084. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  9085. if (before) {
  9086. insertBefore(parent, stateNode, before);
  9087. } else {
  9088. appendChild(parent, stateNode);
  9089. }
  9090. } else if (tag === HostPortal) ; else {
  9091. var child = node.child;
  9092. if (child !== null) {
  9093. insertOrAppendPlacementNode(child, before, parent);
  9094. var sibling = child.sibling;
  9095. while (sibling !== null) {
  9096. insertOrAppendPlacementNode(sibling, before, parent);
  9097. sibling = sibling.sibling;
  9098. }
  9099. }
  9100. }
  9101. }
  9102. function unmountHostComponents(finishedRoot, current, renderPriorityLevel) {
  9103. // We only have the top Fiber that was deleted but we need to recurse down its
  9104. // children to find all the terminal nodes.
  9105. var node = current; // Each iteration, currentParent is populated with node's host parent if not
  9106. // currentParentIsValid.
  9107. var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
  9108. var currentParent;
  9109. var currentParentIsContainer;
  9110. while (true) {
  9111. if (!currentParentIsValid) {
  9112. var parent = node.return;
  9113. findParent: while (true) {
  9114. if (!(parent !== null)) {
  9115. {
  9116. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  9117. }
  9118. }
  9119. var parentStateNode = parent.stateNode;
  9120. switch (parent.tag) {
  9121. case HostComponent:
  9122. currentParent = parentStateNode;
  9123. currentParentIsContainer = false;
  9124. break findParent;
  9125. case HostRoot:
  9126. currentParent = parentStateNode.containerInfo;
  9127. currentParentIsContainer = true;
  9128. break findParent;
  9129. case HostPortal:
  9130. currentParent = parentStateNode.containerInfo;
  9131. currentParentIsContainer = true;
  9132. break findParent;
  9133. }
  9134. parent = parent.return;
  9135. }
  9136. currentParentIsValid = true;
  9137. }
  9138. if (node.tag === HostComponent || node.tag === HostText) {
  9139. commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
  9140. // node from the tree.
  9141. if (currentParentIsContainer) {
  9142. removeChildFromContainer(currentParent, node.stateNode);
  9143. } else {
  9144. removeChild(currentParent, node.stateNode);
  9145. } // Don't visit children because we already visited them.
  9146. } else if (node.tag === HostPortal) {
  9147. if (node.child !== null) {
  9148. // When we go into a portal, it becomes the parent to remove from.
  9149. // We will reassign it back when we pop the portal on the way up.
  9150. currentParent = node.stateNode.containerInfo;
  9151. currentParentIsContainer = true; // Visit children because portals might contain host components.
  9152. node.child.return = node;
  9153. node = node.child;
  9154. continue;
  9155. }
  9156. } else {
  9157. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
  9158. if (node.child !== null) {
  9159. node.child.return = node;
  9160. node = node.child;
  9161. continue;
  9162. }
  9163. }
  9164. if (node === current) {
  9165. return;
  9166. }
  9167. while (node.sibling === null) {
  9168. if (node.return === null || node.return === current) {
  9169. return;
  9170. }
  9171. node = node.return;
  9172. if (node.tag === HostPortal) {
  9173. // When we go out of the portal, we need to restore the parent.
  9174. // Since we don't keep a stack of them, we will search for it.
  9175. currentParentIsValid = false;
  9176. }
  9177. }
  9178. node.sibling.return = node.return;
  9179. node = node.sibling;
  9180. }
  9181. }
  9182. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  9183. {
  9184. // Recursively delete all host nodes from the parent.
  9185. // Detach refs and call componentWillUnmount() on the whole subtree.
  9186. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  9187. }
  9188. detachFiber(current);
  9189. }
  9190. function commitWork(current, finishedWork) {
  9191. switch (finishedWork.tag) {
  9192. case FunctionComponent:
  9193. case ForwardRef:
  9194. case MemoComponent:
  9195. case SimpleMemoComponent:
  9196. case Block:
  9197. {
  9198. // Layout effects are destroyed during the mutation phase so that all
  9199. // destroy functions for all fibers are called before any create functions.
  9200. // This prevents sibling component effects from interfering with each other,
  9201. // e.g. a destroy function in one component should never override a ref set
  9202. // by a create function in another component during the same commit.
  9203. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  9204. return;
  9205. }
  9206. case ClassComponent:
  9207. {
  9208. return;
  9209. }
  9210. case HostComponent:
  9211. {
  9212. var instance = finishedWork.stateNode;
  9213. if (instance != null) {
  9214. // Commit the work prepared earlier.
  9215. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  9216. // as the newProps. The updatePayload will contain the real change in
  9217. // this case.
  9218. var oldProps = current !== null ? current.memoizedProps : newProps;
  9219. var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
  9220. var updatePayload = finishedWork.updateQueue;
  9221. finishedWork.updateQueue = null;
  9222. if (updatePayload !== null) {
  9223. commitUpdate(instance, updatePayload, type, oldProps, newProps);
  9224. }
  9225. }
  9226. return;
  9227. }
  9228. case HostText:
  9229. {
  9230. if (!(finishedWork.stateNode !== null)) {
  9231. {
  9232. throw Error( "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." );
  9233. }
  9234. }
  9235. var textInstance = finishedWork.stateNode;
  9236. var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  9237. // as the newProps. The updatePayload will contain the real change in
  9238. // this case.
  9239. var oldText = current !== null ? current.memoizedProps : newText;
  9240. commitTextUpdate(textInstance, oldText, newText);
  9241. return;
  9242. }
  9243. case HostRoot:
  9244. {
  9245. return;
  9246. }
  9247. case Profiler:
  9248. {
  9249. return;
  9250. }
  9251. case SuspenseComponent:
  9252. {
  9253. commitSuspenseComponent(finishedWork);
  9254. attachSuspenseRetryListeners(finishedWork);
  9255. return;
  9256. }
  9257. case SuspenseListComponent:
  9258. {
  9259. attachSuspenseRetryListeners(finishedWork);
  9260. return;
  9261. }
  9262. case IncompleteClassComponent:
  9263. {
  9264. return;
  9265. }
  9266. }
  9267. {
  9268. {
  9269. 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." );
  9270. }
  9271. }
  9272. }
  9273. function commitSuspenseComponent(finishedWork) {
  9274. var newState = finishedWork.memoizedState;
  9275. var newDidTimeout;
  9276. var primaryChildParent = finishedWork;
  9277. if (newState === null) {
  9278. newDidTimeout = false;
  9279. } else {
  9280. newDidTimeout = true;
  9281. primaryChildParent = finishedWork.child;
  9282. markCommitTimeOfFallback();
  9283. }
  9284. if ( primaryChildParent !== null) {
  9285. hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
  9286. }
  9287. }
  9288. function attachSuspenseRetryListeners(finishedWork) {
  9289. // If this boundary just timed out, then it will have a set of thenables.
  9290. // For each thenable, attach a listener so that when it resolves, React
  9291. // attempts to re-render the boundary in the primary (pre-timeout) state.
  9292. var thenables = finishedWork.updateQueue;
  9293. if (thenables !== null) {
  9294. finishedWork.updateQueue = null;
  9295. var retryCache = finishedWork.stateNode;
  9296. if (retryCache === null) {
  9297. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  9298. }
  9299. thenables.forEach(function (thenable) {
  9300. // Memoize using the boundary fiber to prevent redundant listeners.
  9301. var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
  9302. if (!retryCache.has(thenable)) {
  9303. {
  9304. if (thenable.__reactDoNotTraceInteractions !== true) {
  9305. retry = unstable_wrap(retry);
  9306. }
  9307. }
  9308. retryCache.add(thenable);
  9309. thenable.then(retry, retry);
  9310. }
  9311. });
  9312. }
  9313. }
  9314. function commitResetTextContent(current) {
  9315. resetTextContent(current.stateNode);
  9316. }
  9317. var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
  9318. function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
  9319. var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
  9320. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  9321. // being called "element".
  9322. update.payload = {
  9323. element: null
  9324. };
  9325. var error = errorInfo.value;
  9326. update.callback = function () {
  9327. onUncaughtError(error);
  9328. logError(fiber, errorInfo);
  9329. };
  9330. return update;
  9331. }
  9332. function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
  9333. var update = createUpdate(expirationTime, null);
  9334. update.tag = CaptureUpdate;
  9335. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  9336. if (typeof getDerivedStateFromError === 'function') {
  9337. var error$1 = errorInfo.value;
  9338. update.payload = function () {
  9339. logError(fiber, errorInfo);
  9340. return getDerivedStateFromError(error$1);
  9341. };
  9342. }
  9343. var inst = fiber.stateNode;
  9344. if (inst !== null && typeof inst.componentDidCatch === 'function') {
  9345. update.callback = function callback() {
  9346. {
  9347. markFailedErrorBoundaryForHotReloading(fiber);
  9348. }
  9349. if (typeof getDerivedStateFromError !== 'function') {
  9350. // To preserve the preexisting retry behavior of error boundaries,
  9351. // we keep track of which ones already failed during this batch.
  9352. // This gets reset before we yield back to the browser.
  9353. // TODO: Warn in strict mode if getDerivedStateFromError is
  9354. // not defined.
  9355. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  9356. logError(fiber, errorInfo);
  9357. }
  9358. var error$1 = errorInfo.value;
  9359. var stack = errorInfo.stack;
  9360. this.componentDidCatch(error$1, {
  9361. componentStack: stack !== null ? stack : ''
  9362. });
  9363. {
  9364. if (typeof getDerivedStateFromError !== 'function') {
  9365. // If componentDidCatch is the only error boundary method defined,
  9366. // then it needs to call setState to recover from errors.
  9367. // If no state update is scheduled then the boundary will swallow the error.
  9368. if (fiber.expirationTime !== Sync) {
  9369. 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');
  9370. }
  9371. }
  9372. }
  9373. };
  9374. } else {
  9375. update.callback = function () {
  9376. markFailedErrorBoundaryForHotReloading(fiber);
  9377. };
  9378. }
  9379. return update;
  9380. }
  9381. function attachPingListener(root, renderExpirationTime, thenable) {
  9382. // Attach a listener to the promise to "ping" the root and retry. But
  9383. // only if one does not already exist for the current render expiration
  9384. // time (which acts like a "thread ID" here).
  9385. var pingCache = root.pingCache;
  9386. var threadIDs;
  9387. if (pingCache === null) {
  9388. pingCache = root.pingCache = new PossiblyWeakMap();
  9389. threadIDs = new Set();
  9390. pingCache.set(thenable, threadIDs);
  9391. } else {
  9392. threadIDs = pingCache.get(thenable);
  9393. if (threadIDs === undefined) {
  9394. threadIDs = new Set();
  9395. pingCache.set(thenable, threadIDs);
  9396. }
  9397. }
  9398. if (!threadIDs.has(renderExpirationTime)) {
  9399. // Memoize using the thread ID to prevent redundant listeners.
  9400. threadIDs.add(renderExpirationTime);
  9401. var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
  9402. thenable.then(ping, ping);
  9403. }
  9404. }
  9405. function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
  9406. // The source fiber did not complete.
  9407. sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
  9408. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  9409. if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
  9410. // This is a thenable.
  9411. var thenable = value;
  9412. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  9413. // Reset the memoizedState to what it was before we attempted
  9414. // to render it.
  9415. var currentSource = sourceFiber.alternate;
  9416. if (currentSource) {
  9417. sourceFiber.updateQueue = currentSource.updateQueue;
  9418. sourceFiber.memoizedState = currentSource.memoizedState;
  9419. sourceFiber.expirationTime = currentSource.expirationTime;
  9420. } else {
  9421. sourceFiber.updateQueue = null;
  9422. sourceFiber.memoizedState = null;
  9423. }
  9424. }
  9425. var hasInvisibleParentBoundary = hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext); // Schedule the nearest Suspense to re-render the timed out view.
  9426. var _workInProgress = returnFiber;
  9427. do {
  9428. if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)) {
  9429. // Found the nearest boundary.
  9430. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  9431. // attach another listener to flip the boundary back to its normal state.
  9432. var thenables = _workInProgress.updateQueue;
  9433. if (thenables === null) {
  9434. var updateQueue = new Set();
  9435. updateQueue.add(thenable);
  9436. _workInProgress.updateQueue = updateQueue;
  9437. } else {
  9438. thenables.add(thenable);
  9439. } // If the boundary is outside of blocking mode, we should *not*
  9440. // suspend the commit. Pretend as if the suspended component rendered
  9441. // null and keep rendering. In the commit phase, we'll schedule a
  9442. // subsequent synchronous update to re-render the Suspense.
  9443. //
  9444. // Note: It doesn't matter whether the component that suspended was
  9445. // inside a blocking mode tree. If the Suspense is outside of it, we
  9446. // should *not* suspend the commit.
  9447. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  9448. _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
  9449. // But we shouldn't call any lifecycle methods or callbacks. Remove
  9450. // all lifecycle effect tags.
  9451. sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
  9452. if (sourceFiber.tag === ClassComponent) {
  9453. var currentSourceFiber = sourceFiber.alternate;
  9454. if (currentSourceFiber === null) {
  9455. // This is a new mount. Change the tag so it's not mistaken for a
  9456. // completed class component. For example, we should not call
  9457. // componentWillUnmount if it is deleted.
  9458. sourceFiber.tag = IncompleteClassComponent;
  9459. } else {
  9460. // When we try rendering again, we should not reuse the current fiber,
  9461. // since it's known to be in an inconsistent state. Use a force update to
  9462. // prevent a bail out.
  9463. var update = createUpdate(Sync, null);
  9464. update.tag = ForceUpdate;
  9465. enqueueUpdate(sourceFiber, update);
  9466. }
  9467. } // The source fiber did not complete. Mark it with Sync priority to
  9468. // indicate that it still has pending work.
  9469. sourceFiber.expirationTime = Sync; // Exit without suspending.
  9470. return;
  9471. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  9472. // with the normal suspend path.
  9473. //
  9474. // After this we'll use a set of heuristics to determine whether this
  9475. // render pass will run to completion or restart or "suspend" the commit.
  9476. // The actual logic for this is spread out in different places.
  9477. //
  9478. // This first principle is that if we're going to suspend when we complete
  9479. // a root, then we should also restart if we get an update or ping that
  9480. // might unsuspend it, and vice versa. The only reason to suspend is
  9481. // because you think you might want to restart before committing. However,
  9482. // it doesn't make sense to restart only while in the period we're suspended.
  9483. //
  9484. // Restarting too aggressively is also not good because it starves out any
  9485. // intermediate loading state. So we use heuristics to determine when.
  9486. // Suspense Heuristics
  9487. //
  9488. // If nothing threw a Promise or all the same fallbacks are already showing,
  9489. // then don't suspend/restart.
  9490. //
  9491. // If this is an initial render of a new tree of Suspense boundaries and
  9492. // those trigger a fallback, then don't suspend/restart. We want to ensure
  9493. // that we can show the initial loading state as quickly as possible.
  9494. //
  9495. // If we hit a "Delayed" case, such as when we'd switch from content back into
  9496. // a fallback, then we should always suspend/restart. SuspenseConfig applies to
  9497. // this case. If none is defined, JND is used instead.
  9498. //
  9499. // If we're already showing a fallback and it gets "retried", allowing us to show
  9500. // another level, but there's still an inner boundary that would show a fallback,
  9501. // then we suspend/restart for 500ms since the last time we showed a fallback
  9502. // anywhere in the tree. This effectively throttles progressive loading into a
  9503. // consistent train of commits. This also gives us an opportunity to restart to
  9504. // get to the completed state slightly earlier.
  9505. //
  9506. // If there's ambiguity due to batching it's resolved in preference of:
  9507. // 1) "delayed", 2) "initial render", 3) "retry".
  9508. //
  9509. // We want to ensure that a "busy" state doesn't get force committed. We want to
  9510. // ensure that new initial loading states can commit as soon as possible.
  9511. attachPingListener(root, renderExpirationTime, thenable);
  9512. _workInProgress.effectTag |= ShouldCapture;
  9513. _workInProgress.expirationTime = renderExpirationTime;
  9514. return;
  9515. } // This boundary already captured during this render. Continue to the next
  9516. // boundary.
  9517. _workInProgress = _workInProgress.return;
  9518. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  9519. // TODO: Use invariant so the message is stripped in prod?
  9520. 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));
  9521. } // We didn't find a boundary that could handle this type of exception. Start
  9522. // over and traverse parent path again, this time treating the exception
  9523. // as an error.
  9524. renderDidError();
  9525. value = createCapturedValue(value, sourceFiber);
  9526. var workInProgress = returnFiber;
  9527. do {
  9528. switch (workInProgress.tag) {
  9529. case HostRoot:
  9530. {
  9531. var _errorInfo = value;
  9532. workInProgress.effectTag |= ShouldCapture;
  9533. workInProgress.expirationTime = renderExpirationTime;
  9534. var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
  9535. enqueueCapturedUpdate(workInProgress, _update);
  9536. return;
  9537. }
  9538. case ClassComponent:
  9539. // Capture and retry
  9540. var errorInfo = value;
  9541. var ctor = workInProgress.type;
  9542. var instance = workInProgress.stateNode;
  9543. if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
  9544. workInProgress.effectTag |= ShouldCapture;
  9545. workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
  9546. var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
  9547. enqueueCapturedUpdate(workInProgress, _update2);
  9548. return;
  9549. }
  9550. break;
  9551. }
  9552. workInProgress = workInProgress.return;
  9553. } while (workInProgress !== null);
  9554. }
  9555. var ceil = Math.ceil;
  9556. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  9557. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  9558. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  9559. var NoContext =
  9560. /* */
  9561. 0;
  9562. var BatchedContext =
  9563. /* */
  9564. 1;
  9565. var DiscreteEventContext =
  9566. /* */
  9567. 4;
  9568. var LegacyUnbatchedContext =
  9569. /* */
  9570. 8;
  9571. var RenderContext =
  9572. /* */
  9573. 16;
  9574. var CommitContext =
  9575. /* */
  9576. 32;
  9577. var RootIncomplete = 0;
  9578. var RootFatalErrored = 1;
  9579. var RootErrored = 2;
  9580. var RootSuspended = 3;
  9581. var RootSuspendedWithDelay = 4;
  9582. var RootCompleted = 5;
  9583. // Describes where we are in the React execution stack
  9584. var executionContext = NoContext; // The root we're working on
  9585. var workInProgressRoot = null; // The fiber we're working on
  9586. var workInProgress = null; // The expiration time we're rendering
  9587. var renderExpirationTime$1 = NoWork; // Whether to root completed, errored, suspended, etc.
  9588. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  9589. var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
  9590. // This is conceptually a time stamp but expressed in terms of an ExpirationTime
  9591. // because we deal mostly with expiration times in the hot path, so this avoids
  9592. // the conversion happening in the hot path.
  9593. var workInProgressRootLatestProcessedExpirationTime = Sync;
  9594. var workInProgressRootLatestSuspenseTimeout = Sync;
  9595. var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
  9596. // includes unprocessed updates, not work in bailed out children.
  9597. var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
  9598. // This flag determines if it might be worthwhile to restart if an opportunity
  9599. // happens latere.
  9600. var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
  9601. // model where we don't commit new loading states in too quick succession.
  9602. var globalMostRecentFallbackTime = 0;
  9603. var FALLBACK_THROTTLE_MS = 500;
  9604. var nextEffect = null;
  9605. var hasUncaughtError = false;
  9606. var firstUncaughtError = null;
  9607. var legacyErrorBoundariesThatAlreadyFailed = null;
  9608. var rootDoesHavePassiveEffects = false;
  9609. var rootWithPendingPassiveEffects = null;
  9610. var pendingPassiveEffectsRenderPriority = NoPriority;
  9611. var pendingPassiveEffectsExpirationTime = NoWork;
  9612. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  9613. var NESTED_UPDATE_LIMIT = 50;
  9614. var nestedUpdateCount = 0;
  9615. var rootWithNestedUpdates = null;
  9616. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  9617. var nestedPassiveUpdateCount = 0;
  9618. var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
  9619. // during the commit phase. This enables them to be traced across components
  9620. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  9621. // hydration or SuspenseList.
  9622. var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
  9623. // time). However, if two updates are scheduled within the same event, we
  9624. // should treat their start times as simultaneous, even if the actual clock
  9625. // time has advanced between the first and second call.
  9626. // In other words, because expiration times determine how updates are batched,
  9627. // we want all updates of like priority that occur within the same event to
  9628. // receive the same expiration time. Otherwise we get tearing.
  9629. var currentEventTime = NoWork;
  9630. function requestCurrentTimeForUpdate() {
  9631. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  9632. // We're inside React, so it's fine to read the actual time.
  9633. return msToExpirationTime(now());
  9634. } // We're not inside React, so we may be in the middle of a browser event.
  9635. if (currentEventTime !== NoWork) {
  9636. // Use the same start time for all updates until we enter React again.
  9637. return currentEventTime;
  9638. } // This is the first update since React yielded. Compute a new start time.
  9639. currentEventTime = msToExpirationTime(now());
  9640. return currentEventTime;
  9641. }
  9642. function getCurrentTime() {
  9643. return msToExpirationTime(now());
  9644. }
  9645. function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
  9646. var mode = fiber.mode;
  9647. if ((mode & BlockingMode) === NoMode) {
  9648. return Sync;
  9649. }
  9650. var priorityLevel = getCurrentPriorityLevel();
  9651. if ((mode & ConcurrentMode) === NoMode) {
  9652. return priorityLevel === ImmediatePriority ? Sync : Batched;
  9653. }
  9654. if ((executionContext & RenderContext) !== NoContext) {
  9655. // Use whatever time we're already rendering
  9656. // TODO: Should there be a way to opt out, like with `runWithPriority`?
  9657. return renderExpirationTime$1;
  9658. }
  9659. var expirationTime;
  9660. if (suspenseConfig !== null) {
  9661. // Compute an expiration time based on the Suspense timeout.
  9662. expirationTime = computeSuspenseExpiration(currentTime, suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
  9663. } else {
  9664. // Compute an expiration time based on the Scheduler priority.
  9665. switch (priorityLevel) {
  9666. case ImmediatePriority:
  9667. expirationTime = Sync;
  9668. break;
  9669. case UserBlockingPriority:
  9670. // TODO: Rename this to computeUserBlockingExpiration
  9671. expirationTime = computeInteractiveExpiration(currentTime);
  9672. break;
  9673. case NormalPriority:
  9674. case LowPriority:
  9675. // TODO: Handle LowPriority
  9676. // TODO: Rename this to... something better.
  9677. expirationTime = computeAsyncExpiration(currentTime);
  9678. break;
  9679. case IdlePriority:
  9680. expirationTime = Idle;
  9681. break;
  9682. default:
  9683. {
  9684. {
  9685. throw Error( "Expected a valid priority level" );
  9686. }
  9687. }
  9688. }
  9689. } // If we're in the middle of rendering a tree, do not update at the same
  9690. // expiration time that is already rendering.
  9691. // TODO: We shouldn't have to do this if the update is on a different root.
  9692. // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
  9693. // the root when we check for this condition.
  9694. if (workInProgressRoot !== null && expirationTime === renderExpirationTime$1) {
  9695. // This is a trick to move this update into a separate batch
  9696. expirationTime -= 1;
  9697. }
  9698. return expirationTime;
  9699. }
  9700. function scheduleUpdateOnFiber(fiber, expirationTime) {
  9701. checkForNestedUpdates();
  9702. warnAboutRenderPhaseUpdatesInDEV(fiber);
  9703. var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
  9704. if (root === null) {
  9705. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  9706. return;
  9707. }
  9708. checkForInterruption(fiber, expirationTime);
  9709. recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
  9710. // priority as an argument to that function and this one.
  9711. var priorityLevel = getCurrentPriorityLevel();
  9712. if (expirationTime === Sync) {
  9713. if ( // Check if we're inside unbatchedUpdates
  9714. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  9715. (executionContext & (RenderContext | CommitContext)) === NoContext) {
  9716. // Register pending interactions on the root to avoid losing traced interaction data.
  9717. schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  9718. // root inside of batchedUpdates should be synchronous, but layout updates
  9719. // should be deferred until the end of the batch.
  9720. performSyncWorkOnRoot(root);
  9721. } else {
  9722. ensureRootIsScheduled(root);
  9723. schedulePendingInteractions(root, expirationTime);
  9724. if (executionContext === NoContext) {
  9725. // Flush the synchronous work now, unless we're already working or inside
  9726. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  9727. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  9728. // without immediately flushing it. We only do this for user-initiated
  9729. // updates, to preserve historical behavior of legacy mode.
  9730. flushSyncCallbackQueue();
  9731. }
  9732. }
  9733. } else {
  9734. ensureRootIsScheduled(root);
  9735. schedulePendingInteractions(root, expirationTime);
  9736. }
  9737. if ((executionContext & DiscreteEventContext) !== NoContext && ( // Only updates at user-blocking priority or greater are considered
  9738. // discrete, even inside a discrete event.
  9739. priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority)) {
  9740. // This is the result of a discrete event. Track the lowest priority
  9741. // discrete update per root so we can flush them early, if needed.
  9742. if (rootsWithPendingDiscreteUpdates === null) {
  9743. rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
  9744. } else {
  9745. var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
  9746. if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
  9747. rootsWithPendingDiscreteUpdates.set(root, expirationTime);
  9748. }
  9749. }
  9750. }
  9751. }
  9752. var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
  9753. // work without treating it as a typical update that originates from an event;
  9754. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  9755. // on a fiber.
  9756. function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
  9757. // Update the source fiber's expiration time
  9758. if (fiber.expirationTime < expirationTime) {
  9759. fiber.expirationTime = expirationTime;
  9760. }
  9761. var alternate = fiber.alternate;
  9762. if (alternate !== null && alternate.expirationTime < expirationTime) {
  9763. alternate.expirationTime = expirationTime;
  9764. } // Walk the parent path to the root and update the child expiration time.
  9765. var node = fiber.return;
  9766. var root = null;
  9767. if (node === null && fiber.tag === HostRoot) {
  9768. root = fiber.stateNode;
  9769. } else {
  9770. while (node !== null) {
  9771. alternate = node.alternate;
  9772. if (node.childExpirationTime < expirationTime) {
  9773. node.childExpirationTime = expirationTime;
  9774. if (alternate !== null && alternate.childExpirationTime < expirationTime) {
  9775. alternate.childExpirationTime = expirationTime;
  9776. }
  9777. } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
  9778. alternate.childExpirationTime = expirationTime;
  9779. }
  9780. if (node.return === null && node.tag === HostRoot) {
  9781. root = node.stateNode;
  9782. break;
  9783. }
  9784. node = node.return;
  9785. }
  9786. }
  9787. if (root !== null) {
  9788. if (workInProgressRoot === root) {
  9789. // Received an update to a tree that's in the middle of rendering. Mark
  9790. // that's unprocessed work on this root.
  9791. markUnprocessedUpdateTime(expirationTime);
  9792. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  9793. // The root already suspended with a delay, which means this render
  9794. // definitely won't finish. Since we have a new update, let's mark it as
  9795. // suspended now, right before marking the incoming update. This has the
  9796. // effect of interrupting the current render and switching to the update.
  9797. // TODO: This happens to work when receiving an update during the render
  9798. // phase, because of the trick inside computeExpirationForFiber to
  9799. // subtract 1 from `renderExpirationTime` to move it into a
  9800. // separate bucket. But we should probably model it with an exception,
  9801. // using the same mechanism we use to force hydration of a subtree.
  9802. // TODO: This does not account for low pri updates that were already
  9803. // scheduled before the root started rendering. Need to track the next
  9804. // pending expiration time (perhaps by backtracking the return path) and
  9805. // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
  9806. markRootSuspendedAtTime(root, renderExpirationTime$1);
  9807. }
  9808. } // Mark that the root has a pending update.
  9809. markRootUpdatedAtTime(root, expirationTime);
  9810. }
  9811. return root;
  9812. }
  9813. function getNextRootExpirationTimeToWorkOn(root) {
  9814. // Determines the next expiration time that the root should render, taking
  9815. // into account levels that may be suspended, or levels that may have
  9816. // received a ping.
  9817. var lastExpiredTime = root.lastExpiredTime;
  9818. if (lastExpiredTime !== NoWork) {
  9819. return lastExpiredTime;
  9820. } // "Pending" refers to any update that hasn't committed yet, including if it
  9821. // suspended. The "suspended" range is therefore a subset.
  9822. var firstPendingTime = root.firstPendingTime;
  9823. if (!isRootSuspendedAtTime(root, firstPendingTime)) {
  9824. // The highest priority pending time is not suspended. Let's work on that.
  9825. return firstPendingTime;
  9826. } // If the first pending time is suspended, check if there's a lower priority
  9827. // pending level that we know about. Or check if we received a ping. Work
  9828. // on whichever is higher priority.
  9829. var lastPingedTime = root.lastPingedTime;
  9830. var nextKnownPendingLevel = root.nextKnownPendingLevel;
  9831. var nextLevel = lastPingedTime > nextKnownPendingLevel ? lastPingedTime : nextKnownPendingLevel;
  9832. if ( nextLevel <= Idle && firstPendingTime !== nextLevel) {
  9833. // Don't work on Idle/Never priority unless everything else is committed.
  9834. return NoWork;
  9835. }
  9836. return nextLevel;
  9837. } // Use this function to schedule a task for a root. There's only one task per
  9838. // root; if a task was already scheduled, we'll check to make sure the
  9839. // expiration time of the existing task is the same as the expiration time of
  9840. // the next level that the root has work on. This function is called on every
  9841. // update, and right before exiting a task.
  9842. function ensureRootIsScheduled(root) {
  9843. var lastExpiredTime = root.lastExpiredTime;
  9844. if (lastExpiredTime !== NoWork) {
  9845. // Special case: Expired work should flush synchronously.
  9846. root.callbackExpirationTime = Sync;
  9847. root.callbackPriority = ImmediatePriority;
  9848. root.callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  9849. return;
  9850. }
  9851. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  9852. var existingCallbackNode = root.callbackNode;
  9853. if (expirationTime === NoWork) {
  9854. // There's nothing to work on.
  9855. if (existingCallbackNode !== null) {
  9856. root.callbackNode = null;
  9857. root.callbackExpirationTime = NoWork;
  9858. root.callbackPriority = NoPriority;
  9859. }
  9860. return;
  9861. } // TODO: If this is an update, we already read the current time. Pass the
  9862. // time as an argument.
  9863. var currentTime = requestCurrentTimeForUpdate();
  9864. var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime); // If there's an existing render task, confirm it has the correct priority and
  9865. // expiration time. Otherwise, we'll cancel it and schedule a new one.
  9866. if (existingCallbackNode !== null) {
  9867. var existingCallbackPriority = root.callbackPriority;
  9868. var existingCallbackExpirationTime = root.callbackExpirationTime;
  9869. if ( // Callback must have the exact same expiration time.
  9870. existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
  9871. existingCallbackPriority >= priorityLevel) {
  9872. // Existing callback is sufficient.
  9873. return;
  9874. } // Need to schedule a new task.
  9875. // TODO: Instead of scheduling a new task, we should be able to change the
  9876. // priority of the existing one.
  9877. cancelCallback(existingCallbackNode);
  9878. }
  9879. root.callbackExpirationTime = expirationTime;
  9880. root.callbackPriority = priorityLevel;
  9881. var callbackNode;
  9882. if (expirationTime === Sync) {
  9883. // Sync React callbacks are scheduled on a special internal queue
  9884. callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  9885. } else {
  9886. callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
  9887. // ordering because tasks are processed in timeout order.
  9888. {
  9889. timeout: expirationTimeToMs(expirationTime) - now()
  9890. });
  9891. }
  9892. root.callbackNode = callbackNode;
  9893. } // This is the entry point for every concurrent task, i.e. anything that
  9894. // goes through Scheduler.
  9895. function performConcurrentWorkOnRoot(root, didTimeout) {
  9896. // Since we know we're in a React event, we can clear the current
  9897. // event time. The next update will compute a new event time.
  9898. currentEventTime = NoWork;
  9899. if (didTimeout) {
  9900. // The render task took too long to complete. Mark the current time as
  9901. // expired to synchronously render all expired work in a single batch.
  9902. var currentTime = requestCurrentTimeForUpdate();
  9903. markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
  9904. ensureRootIsScheduled(root);
  9905. return null;
  9906. } // Determine the next expiration time to work on, using the fields stored
  9907. // on the root.
  9908. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  9909. if (expirationTime !== NoWork) {
  9910. var originalCallbackNode = root.callbackNode;
  9911. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  9912. {
  9913. throw Error( "Should not already be working." );
  9914. }
  9915. }
  9916. flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
  9917. // and prepare a fresh one. Otherwise we'll continue where we left off.
  9918. if (root !== workInProgressRoot || expirationTime !== renderExpirationTime$1) {
  9919. prepareFreshStack(root, expirationTime);
  9920. startWorkOnPendingInteractions(root, expirationTime);
  9921. } // If we have a work-in-progress fiber, it means there's still work to do
  9922. // in this root.
  9923. if (workInProgress !== null) {
  9924. var prevExecutionContext = executionContext;
  9925. executionContext |= RenderContext;
  9926. var prevDispatcher = pushDispatcher();
  9927. var prevInteractions = pushInteractions(root);
  9928. startWorkLoopTimer(workInProgress);
  9929. do {
  9930. try {
  9931. workLoopConcurrent();
  9932. break;
  9933. } catch (thrownValue) {
  9934. handleError(root, thrownValue);
  9935. }
  9936. } while (true);
  9937. resetContextDependencies();
  9938. executionContext = prevExecutionContext;
  9939. popDispatcher(prevDispatcher);
  9940. {
  9941. popInteractions(prevInteractions);
  9942. }
  9943. if (workInProgressRootExitStatus === RootFatalErrored) {
  9944. var fatalError = workInProgressRootFatalError;
  9945. stopInterruptedWorkLoopTimer();
  9946. prepareFreshStack(root, expirationTime);
  9947. markRootSuspendedAtTime(root, expirationTime);
  9948. ensureRootIsScheduled(root);
  9949. throw fatalError;
  9950. }
  9951. if (workInProgress !== null) {
  9952. // There's still work left over. Exit without committing.
  9953. stopInterruptedWorkLoopTimer();
  9954. } else {
  9955. // We now have a consistent tree. The next step is either to commit it,
  9956. // or, if something suspended, wait to commit it after a timeout.
  9957. stopFinishedWorkLoopTimer();
  9958. var finishedWork = root.finishedWork = root.current.alternate;
  9959. root.finishedExpirationTime = expirationTime;
  9960. finishConcurrentRender(root, finishedWork, workInProgressRootExitStatus, expirationTime);
  9961. }
  9962. ensureRootIsScheduled(root);
  9963. if (root.callbackNode === originalCallbackNode) {
  9964. // The task node scheduled for this root is the same one that's
  9965. // currently executed. Need to return a continuation.
  9966. return performConcurrentWorkOnRoot.bind(null, root);
  9967. }
  9968. }
  9969. }
  9970. return null;
  9971. }
  9972. function finishConcurrentRender(root, finishedWork, exitStatus, expirationTime) {
  9973. // Set this to null to indicate there's no in-progress render.
  9974. workInProgressRoot = null;
  9975. switch (exitStatus) {
  9976. case RootIncomplete:
  9977. case RootFatalErrored:
  9978. {
  9979. {
  9980. {
  9981. throw Error( "Root did not complete. This is a bug in React." );
  9982. }
  9983. }
  9984. }
  9985. // Flow knows about invariant, so it complains if I add a break
  9986. // statement, but eslint doesn't know about invariant, so it complains
  9987. // if I do. eslint-disable-next-line no-fallthrough
  9988. case RootErrored:
  9989. {
  9990. // If this was an async render, the error may have happened due to
  9991. // a mutation in a concurrent event. Try rendering one more time,
  9992. // synchronously, to see if the error goes away. If there are
  9993. // lower priority updates, let's include those, too, in case they
  9994. // fix the inconsistency. Render at Idle to include all updates.
  9995. // If it was Idle or Never or some not-yet-invented time, render
  9996. // at that time.
  9997. markRootExpiredAtTime(root, expirationTime > Idle ? Idle : expirationTime); // We assume that this second render pass will be synchronous
  9998. // and therefore not hit this path again.
  9999. break;
  10000. }
  10001. case RootSuspended:
  10002. {
  10003. markRootSuspendedAtTime(root, expirationTime);
  10004. var lastSuspendedTime = root.lastSuspendedTime;
  10005. if (expirationTime === lastSuspendedTime) {
  10006. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  10007. } // We have an acceptable loading state. We need to figure out if we
  10008. // should immediately commit it or wait a bit.
  10009. // If we have processed new updates during this render, we may now
  10010. // have a new loading state ready. We want to ensure that we commit
  10011. // that as soon as possible.
  10012. var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync;
  10013. if (hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
  10014. !( IsThisRendererActing.current)) {
  10015. // If we have not processed any new updates during this pass, then
  10016. // this is either a retry of an existing fallback state or a
  10017. // hidden tree. Hidden trees shouldn't be batched with other work
  10018. // and after that's fixed it can only be a retry. We're going to
  10019. // throttle committing retries so that we don't show too many
  10020. // loading states too quickly.
  10021. var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  10022. if (msUntilTimeout > 10) {
  10023. if (workInProgressRootHasPendingPing) {
  10024. var lastPingedTime = root.lastPingedTime;
  10025. if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
  10026. // This render was pinged but we didn't get to restart
  10027. // earlier so try restarting now instead.
  10028. root.lastPingedTime = expirationTime;
  10029. prepareFreshStack(root, expirationTime);
  10030. break;
  10031. }
  10032. }
  10033. var nextTime = getNextRootExpirationTimeToWorkOn(root);
  10034. if (nextTime !== NoWork && nextTime !== expirationTime) {
  10035. // There's additional work on this root.
  10036. break;
  10037. }
  10038. if (lastSuspendedTime !== NoWork && lastSuspendedTime !== expirationTime) {
  10039. // We should prefer to render the fallback of at the last
  10040. // suspended level. Ping the last suspended level to try
  10041. // rendering it again.
  10042. root.lastPingedTime = lastSuspendedTime;
  10043. break;
  10044. } // The render is suspended, it hasn't timed out, and there's no
  10045. // lower priority work to do. Instead of committing the fallback
  10046. // immediately, wait for more data to arrive.
  10047. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), msUntilTimeout);
  10048. break;
  10049. }
  10050. } // The work expired. Commit immediately.
  10051. commitRoot(root);
  10052. break;
  10053. }
  10054. case RootSuspendedWithDelay:
  10055. {
  10056. markRootSuspendedAtTime(root, expirationTime);
  10057. var _lastSuspendedTime = root.lastSuspendedTime;
  10058. if (expirationTime === _lastSuspendedTime) {
  10059. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  10060. }
  10061. if ( // do not delay if we're inside an act() scope
  10062. !( IsThisRendererActing.current)) {
  10063. // We're suspended in a state that should be avoided. We'll try to
  10064. // avoid committing it for as long as the timeouts let us.
  10065. if (workInProgressRootHasPendingPing) {
  10066. var _lastPingedTime = root.lastPingedTime;
  10067. if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
  10068. // This render was pinged but we didn't get to restart earlier
  10069. // so try restarting now instead.
  10070. root.lastPingedTime = expirationTime;
  10071. prepareFreshStack(root, expirationTime);
  10072. break;
  10073. }
  10074. }
  10075. var _nextTime = getNextRootExpirationTimeToWorkOn(root);
  10076. if (_nextTime !== NoWork && _nextTime !== expirationTime) {
  10077. // There's additional work on this root.
  10078. break;
  10079. }
  10080. if (_lastSuspendedTime !== NoWork && _lastSuspendedTime !== expirationTime) {
  10081. // We should prefer to render the fallback of at the last
  10082. // suspended level. Ping the last suspended level to try
  10083. // rendering it again.
  10084. root.lastPingedTime = _lastSuspendedTime;
  10085. break;
  10086. }
  10087. var _msUntilTimeout;
  10088. if (workInProgressRootLatestSuspenseTimeout !== Sync) {
  10089. // We have processed a suspense config whose expiration time we
  10090. // can use as the timeout.
  10091. _msUntilTimeout = expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
  10092. } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
  10093. // This should never normally happen because only new updates
  10094. // cause delayed states, so we should have processed something.
  10095. // However, this could also happen in an offscreen tree.
  10096. _msUntilTimeout = 0;
  10097. } else {
  10098. // If we don't have a suspense config, we're going to use a
  10099. // heuristic to determine how long we can suspend.
  10100. var eventTimeMs = inferTimeFromExpirationTime(workInProgressRootLatestProcessedExpirationTime);
  10101. var currentTimeMs = now();
  10102. var timeUntilExpirationMs = expirationTimeToMs(expirationTime) - currentTimeMs;
  10103. var timeElapsed = currentTimeMs - eventTimeMs;
  10104. if (timeElapsed < 0) {
  10105. // We get this wrong some time since we estimate the time.
  10106. timeElapsed = 0;
  10107. }
  10108. _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
  10109. // event time is exact instead of inferred from expiration time
  10110. // we don't need this.
  10111. if (timeUntilExpirationMs < _msUntilTimeout) {
  10112. _msUntilTimeout = timeUntilExpirationMs;
  10113. }
  10114. } // Don't bother with a very short suspense time.
  10115. if (_msUntilTimeout > 10) {
  10116. // The render is suspended, it hasn't timed out, and there's no
  10117. // lower priority work to do. Instead of committing the fallback
  10118. // immediately, wait for more data to arrive.
  10119. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout);
  10120. break;
  10121. }
  10122. } // The work expired. Commit immediately.
  10123. commitRoot(root);
  10124. break;
  10125. }
  10126. case RootCompleted:
  10127. {
  10128. // The work completed. Ready to commit.
  10129. if ( // do not delay if we're inside an act() scope
  10130. !( IsThisRendererActing.current) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null) {
  10131. // If we have exceeded the minimum loading delay, which probably
  10132. // means we have shown a spinner already, we might have to suspend
  10133. // a bit longer to ensure that the spinner is shown for
  10134. // enough time.
  10135. var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(workInProgressRootLatestProcessedExpirationTime, expirationTime, workInProgressRootCanSuspendUsingConfig);
  10136. if (_msUntilTimeout2 > 10) {
  10137. markRootSuspendedAtTime(root, expirationTime);
  10138. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout2);
  10139. break;
  10140. }
  10141. }
  10142. commitRoot(root);
  10143. break;
  10144. }
  10145. default:
  10146. {
  10147. {
  10148. {
  10149. throw Error( "Unknown root exit status." );
  10150. }
  10151. }
  10152. }
  10153. }
  10154. } // This is the entry point for synchronous tasks that don't go
  10155. // through Scheduler
  10156. function performSyncWorkOnRoot(root) {
  10157. // Check if there's expired work on this root. Otherwise, render at Sync.
  10158. var lastExpiredTime = root.lastExpiredTime;
  10159. var expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync;
  10160. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  10161. {
  10162. throw Error( "Should not already be working." );
  10163. }
  10164. }
  10165. flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
  10166. // and prepare a fresh one. Otherwise we'll continue where we left off.
  10167. if (root !== workInProgressRoot || expirationTime !== renderExpirationTime$1) {
  10168. prepareFreshStack(root, expirationTime);
  10169. startWorkOnPendingInteractions(root, expirationTime);
  10170. } // If we have a work-in-progress fiber, it means there's still work to do
  10171. // in this root.
  10172. if (workInProgress !== null) {
  10173. var prevExecutionContext = executionContext;
  10174. executionContext |= RenderContext;
  10175. var prevDispatcher = pushDispatcher();
  10176. var prevInteractions = pushInteractions(root);
  10177. startWorkLoopTimer(workInProgress);
  10178. do {
  10179. try {
  10180. workLoopSync();
  10181. break;
  10182. } catch (thrownValue) {
  10183. handleError(root, thrownValue);
  10184. }
  10185. } while (true);
  10186. resetContextDependencies();
  10187. executionContext = prevExecutionContext;
  10188. popDispatcher(prevDispatcher);
  10189. {
  10190. popInteractions(prevInteractions);
  10191. }
  10192. if (workInProgressRootExitStatus === RootFatalErrored) {
  10193. var fatalError = workInProgressRootFatalError;
  10194. stopInterruptedWorkLoopTimer();
  10195. prepareFreshStack(root, expirationTime);
  10196. markRootSuspendedAtTime(root, expirationTime);
  10197. ensureRootIsScheduled(root);
  10198. throw fatalError;
  10199. }
  10200. if (workInProgress !== null) {
  10201. // This is a sync render, so we should have finished the whole tree.
  10202. {
  10203. {
  10204. throw Error( "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." );
  10205. }
  10206. }
  10207. } else {
  10208. // We now have a consistent tree. Because this is a sync render, we
  10209. // will commit it even if something suspended.
  10210. stopFinishedWorkLoopTimer();
  10211. root.finishedWork = root.current.alternate;
  10212. root.finishedExpirationTime = expirationTime;
  10213. finishSyncRender(root);
  10214. } // Before exiting, make sure there's a callback scheduled for the next
  10215. // pending level.
  10216. ensureRootIsScheduled(root);
  10217. }
  10218. return null;
  10219. }
  10220. function finishSyncRender(root) {
  10221. // Set this to null to indicate there's no in-progress render.
  10222. workInProgressRoot = null;
  10223. commitRoot(root);
  10224. }
  10225. function syncUpdates(fn, a, b, c) {
  10226. return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
  10227. }
  10228. function batchedUpdates(fn, a) {
  10229. var prevExecutionContext = executionContext;
  10230. executionContext |= BatchedContext;
  10231. try {
  10232. return fn(a);
  10233. } finally {
  10234. executionContext = prevExecutionContext;
  10235. if (executionContext === NoContext) {
  10236. // Flush the immediate callbacks that were scheduled during this batch
  10237. flushSyncCallbackQueue();
  10238. }
  10239. }
  10240. }
  10241. function flushSync(fn, a) {
  10242. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  10243. {
  10244. {
  10245. throw Error( "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." );
  10246. }
  10247. }
  10248. }
  10249. var prevExecutionContext = executionContext;
  10250. executionContext |= BatchedContext;
  10251. try {
  10252. return runWithPriority(ImmediatePriority, fn.bind(null, a));
  10253. } finally {
  10254. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  10255. // Note that this will happen even if batchedUpdates is higher up
  10256. // the stack.
  10257. flushSyncCallbackQueue();
  10258. }
  10259. }
  10260. function prepareFreshStack(root, expirationTime) {
  10261. root.finishedWork = null;
  10262. root.finishedExpirationTime = NoWork;
  10263. var timeoutHandle = root.timeoutHandle;
  10264. if (timeoutHandle !== noTimeout) {
  10265. // The root previous suspended and scheduled a timeout to commit a fallback
  10266. // state. Now that we have additional work, cancel the timeout.
  10267. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  10268. cancelTimeout(timeoutHandle);
  10269. }
  10270. if (workInProgress !== null) {
  10271. var interruptedWork = workInProgress.return;
  10272. while (interruptedWork !== null) {
  10273. unwindInterruptedWork(interruptedWork);
  10274. interruptedWork = interruptedWork.return;
  10275. }
  10276. }
  10277. workInProgressRoot = root;
  10278. workInProgress = createWorkInProgress(root.current, null);
  10279. renderExpirationTime$1 = expirationTime;
  10280. workInProgressRootExitStatus = RootIncomplete;
  10281. workInProgressRootFatalError = null;
  10282. workInProgressRootLatestProcessedExpirationTime = Sync;
  10283. workInProgressRootLatestSuspenseTimeout = Sync;
  10284. workInProgressRootCanSuspendUsingConfig = null;
  10285. workInProgressRootNextUnprocessedUpdateTime = NoWork;
  10286. workInProgressRootHasPendingPing = false;
  10287. {
  10288. spawnedWorkDuringRender = null;
  10289. }
  10290. {
  10291. ReactStrictModeWarnings.discardPendingWarnings();
  10292. }
  10293. }
  10294. function handleError(root, thrownValue) {
  10295. do {
  10296. try {
  10297. // Reset module-level state that was set during the render phase.
  10298. resetContextDependencies();
  10299. resetHooksAfterThrow();
  10300. resetCurrentFiber();
  10301. if (workInProgress === null || workInProgress.return === null) {
  10302. // Expected to be working on a non-root fiber. This is a fatal error
  10303. // because there's no ancestor that can handle it; the root is
  10304. // supposed to capture all errors that weren't caught by an error
  10305. // boundary.
  10306. workInProgressRootExitStatus = RootFatalErrored;
  10307. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  10308. // sibling, or the parent if there are no siblings. But since the root
  10309. // has no siblings nor a parent, we set it to null. Usually this is
  10310. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  10311. // interntionally not calling those, we need set it here.
  10312. // TODO: Consider calling `unwindWork` to pop the contexts.
  10313. workInProgress = null;
  10314. return null;
  10315. }
  10316. if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
  10317. // Record the time spent rendering before an error was thrown. This
  10318. // avoids inaccurate Profiler durations in the case of a
  10319. // suspended render.
  10320. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
  10321. }
  10322. throwException(root, workInProgress.return, workInProgress, thrownValue, renderExpirationTime$1);
  10323. workInProgress = completeUnitOfWork(workInProgress);
  10324. } catch (yetAnotherThrownValue) {
  10325. // Something in the return path also threw.
  10326. thrownValue = yetAnotherThrownValue;
  10327. continue;
  10328. } // Return to the normal work loop.
  10329. return;
  10330. } while (true);
  10331. }
  10332. function pushDispatcher(root) {
  10333. var prevDispatcher = ReactCurrentDispatcher$1.current;
  10334. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  10335. if (prevDispatcher === null) {
  10336. // The React isomorphic package does not include a default dispatcher.
  10337. // Instead the first renderer will lazily attach one, in order to give
  10338. // nicer error messages.
  10339. return ContextOnlyDispatcher;
  10340. } else {
  10341. return prevDispatcher;
  10342. }
  10343. }
  10344. function popDispatcher(prevDispatcher) {
  10345. ReactCurrentDispatcher$1.current = prevDispatcher;
  10346. }
  10347. function pushInteractions(root) {
  10348. {
  10349. var prevInteractions = __interactionsRef.current;
  10350. __interactionsRef.current = root.memoizedInteractions;
  10351. return prevInteractions;
  10352. }
  10353. }
  10354. function popInteractions(prevInteractions) {
  10355. {
  10356. __interactionsRef.current = prevInteractions;
  10357. }
  10358. }
  10359. function markCommitTimeOfFallback() {
  10360. globalMostRecentFallbackTime = now();
  10361. }
  10362. function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
  10363. if (expirationTime < workInProgressRootLatestProcessedExpirationTime && expirationTime > Idle) {
  10364. workInProgressRootLatestProcessedExpirationTime = expirationTime;
  10365. }
  10366. if (suspenseConfig !== null) {
  10367. if (expirationTime < workInProgressRootLatestSuspenseTimeout && expirationTime > Idle) {
  10368. workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
  10369. workInProgressRootCanSuspendUsingConfig = suspenseConfig;
  10370. }
  10371. }
  10372. }
  10373. function markUnprocessedUpdateTime(expirationTime) {
  10374. if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
  10375. workInProgressRootNextUnprocessedUpdateTime = expirationTime;
  10376. }
  10377. }
  10378. function renderDidSuspend() {
  10379. if (workInProgressRootExitStatus === RootIncomplete) {
  10380. workInProgressRootExitStatus = RootSuspended;
  10381. }
  10382. }
  10383. function renderDidSuspendDelayIfPossible() {
  10384. if (workInProgressRootExitStatus === RootIncomplete || workInProgressRootExitStatus === RootSuspended) {
  10385. workInProgressRootExitStatus = RootSuspendedWithDelay;
  10386. } // Check if there's a lower priority update somewhere else in the tree.
  10387. if (workInProgressRootNextUnprocessedUpdateTime !== NoWork && workInProgressRoot !== null) {
  10388. // Mark the current render as suspended, and then mark that there's a
  10389. // pending update.
  10390. // TODO: This should immediately interrupt the current render, instead
  10391. // of waiting until the next time we yield.
  10392. markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime$1);
  10393. markRootUpdatedAtTime(workInProgressRoot, workInProgressRootNextUnprocessedUpdateTime);
  10394. }
  10395. }
  10396. function renderDidError() {
  10397. if (workInProgressRootExitStatus !== RootCompleted) {
  10398. workInProgressRootExitStatus = RootErrored;
  10399. }
  10400. } // Called during render to determine if anything has suspended.
  10401. // Returns false if we're not sure.
  10402. function renderHasNotSuspendedYet() {
  10403. // If something errored or completed, we can't really be sure,
  10404. // so those are false.
  10405. return workInProgressRootExitStatus === RootIncomplete;
  10406. }
  10407. function inferTimeFromExpirationTime(expirationTime) {
  10408. // We don't know exactly when the update was scheduled, but we can infer an
  10409. // approximate start time from the expiration time.
  10410. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  10411. return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
  10412. }
  10413. function inferTimeFromExpirationTimeWithSuspenseConfig(expirationTime, suspenseConfig) {
  10414. // We don't know exactly when the update was scheduled, but we can infer an
  10415. // approximate start time from the expiration time by subtracting the timeout
  10416. // that was added to the event time.
  10417. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  10418. return earliestExpirationTimeMs - (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
  10419. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  10420. /** @noinline */
  10421. function workLoopSync() {
  10422. // Already timed out, so perform work without checking if we need to yield.
  10423. while (workInProgress !== null) {
  10424. workInProgress = performUnitOfWork(workInProgress);
  10425. }
  10426. }
  10427. /** @noinline */
  10428. function workLoopConcurrent() {
  10429. // Perform work until Scheduler asks us to yield
  10430. while (workInProgress !== null && !shouldYield()) {
  10431. workInProgress = performUnitOfWork(workInProgress);
  10432. }
  10433. }
  10434. function performUnitOfWork(unitOfWork) {
  10435. // The current, flushed, state of this fiber is the alternate. Ideally
  10436. // nothing should rely on this, but relying on it here means that we don't
  10437. // need an additional field on the work in progress.
  10438. var current = unitOfWork.alternate;
  10439. startWorkTimer(unitOfWork);
  10440. setCurrentFiber(unitOfWork);
  10441. var next;
  10442. if ( (unitOfWork.mode & ProfileMode) !== NoMode) {
  10443. startProfilerTimer(unitOfWork);
  10444. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  10445. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  10446. } else {
  10447. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  10448. }
  10449. resetCurrentFiber();
  10450. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  10451. if (next === null) {
  10452. // If this doesn't spawn new work, complete the current work.
  10453. next = completeUnitOfWork(unitOfWork);
  10454. }
  10455. ReactCurrentOwner$2.current = null;
  10456. return next;
  10457. }
  10458. function completeUnitOfWork(unitOfWork) {
  10459. // Attempt to complete the current unit of work, then move to the next
  10460. // sibling. If there are no more siblings, return to the parent fiber.
  10461. workInProgress = unitOfWork;
  10462. do {
  10463. // The current, flushed, state of this fiber is the alternate. Ideally
  10464. // nothing should rely on this, but relying on it here means that we don't
  10465. // need an additional field on the work in progress.
  10466. var current = workInProgress.alternate;
  10467. var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
  10468. if ((workInProgress.effectTag & Incomplete) === NoEffect) {
  10469. setCurrentFiber(workInProgress);
  10470. var next = void 0;
  10471. if ( (workInProgress.mode & ProfileMode) === NoMode) {
  10472. next = completeWork(current, workInProgress, renderExpirationTime$1);
  10473. } else {
  10474. startProfilerTimer(workInProgress);
  10475. next = completeWork(current, workInProgress, renderExpirationTime$1); // Update render duration assuming we didn't error.
  10476. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
  10477. }
  10478. stopWorkTimer(workInProgress);
  10479. resetCurrentFiber();
  10480. resetChildExpirationTime(workInProgress);
  10481. if (next !== null) {
  10482. // Completing this fiber spawned new work. Work on that next.
  10483. return next;
  10484. }
  10485. if (returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  10486. (returnFiber.effectTag & Incomplete) === NoEffect) {
  10487. // Append all the effects of the subtree and this fiber onto the effect
  10488. // list of the parent. The completion order of the children affects the
  10489. // side-effect order.
  10490. if (returnFiber.firstEffect === null) {
  10491. returnFiber.firstEffect = workInProgress.firstEffect;
  10492. }
  10493. if (workInProgress.lastEffect !== null) {
  10494. if (returnFiber.lastEffect !== null) {
  10495. returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
  10496. }
  10497. returnFiber.lastEffect = workInProgress.lastEffect;
  10498. } // If this fiber had side-effects, we append it AFTER the children's
  10499. // side-effects. We can perform certain side-effects earlier if needed,
  10500. // by doing multiple passes over the effect list. We don't want to
  10501. // schedule our own side-effect on our own list because if end up
  10502. // reusing children we'll schedule this effect onto itself since we're
  10503. // at the end.
  10504. var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
  10505. // list. PerformedWork effect is read by React DevTools but shouldn't be
  10506. // committed.
  10507. if (effectTag > PerformedWork) {
  10508. if (returnFiber.lastEffect !== null) {
  10509. returnFiber.lastEffect.nextEffect = workInProgress;
  10510. } else {
  10511. returnFiber.firstEffect = workInProgress;
  10512. }
  10513. returnFiber.lastEffect = workInProgress;
  10514. }
  10515. }
  10516. } else {
  10517. // This fiber did not complete because something threw. Pop values off
  10518. // the stack without entering the complete phase. If this is a boundary,
  10519. // capture values if possible.
  10520. var _next = unwindWork(workInProgress); // Because this fiber did not complete, don't reset its expiration time.
  10521. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  10522. // Record the render duration for the fiber that errored.
  10523. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
  10524. var actualDuration = workInProgress.actualDuration;
  10525. var child = workInProgress.child;
  10526. while (child !== null) {
  10527. actualDuration += child.actualDuration;
  10528. child = child.sibling;
  10529. }
  10530. workInProgress.actualDuration = actualDuration;
  10531. }
  10532. if (_next !== null) {
  10533. // If completing this work spawned new work, do that next. We'll come
  10534. // back here again.
  10535. // Since we're restarting, remove anything that is not a host effect
  10536. // from the effect tag.
  10537. // TODO: The name stopFailedWorkTimer is misleading because Suspense
  10538. // also captures and restarts.
  10539. stopFailedWorkTimer(workInProgress);
  10540. _next.effectTag &= HostEffectMask;
  10541. return _next;
  10542. }
  10543. stopWorkTimer(workInProgress);
  10544. if (returnFiber !== null) {
  10545. // Mark the parent fiber as incomplete and clear its effect list.
  10546. returnFiber.firstEffect = returnFiber.lastEffect = null;
  10547. returnFiber.effectTag |= Incomplete;
  10548. }
  10549. }
  10550. var siblingFiber = workInProgress.sibling;
  10551. if (siblingFiber !== null) {
  10552. // If there is more work to do in this returnFiber, do that next.
  10553. return siblingFiber;
  10554. } // Otherwise, return to the parent
  10555. workInProgress = returnFiber;
  10556. } while (workInProgress !== null); // We've reached the root.
  10557. if (workInProgressRootExitStatus === RootIncomplete) {
  10558. workInProgressRootExitStatus = RootCompleted;
  10559. }
  10560. return null;
  10561. }
  10562. function getRemainingExpirationTime(fiber) {
  10563. var updateExpirationTime = fiber.expirationTime;
  10564. var childExpirationTime = fiber.childExpirationTime;
  10565. return updateExpirationTime > childExpirationTime ? updateExpirationTime : childExpirationTime;
  10566. }
  10567. function resetChildExpirationTime(completedWork) {
  10568. if (renderExpirationTime$1 !== Never && completedWork.childExpirationTime === Never) {
  10569. // The children of this component are hidden. Don't bubble their
  10570. // expiration times.
  10571. return;
  10572. }
  10573. var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
  10574. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  10575. // In profiling mode, resetChildExpirationTime is also used to reset
  10576. // profiler durations.
  10577. var actualDuration = completedWork.actualDuration;
  10578. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  10579. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  10580. // When work is done, it should bubble to the parent's actualDuration. If
  10581. // the fiber has not been cloned though, (meaning no work was done), then
  10582. // this value will reflect the amount of time spent working on a previous
  10583. // render. In that case it should not bubble. We determine whether it was
  10584. // cloned by comparing the child pointer.
  10585. var shouldBubbleActualDurations = completedWork.alternate === null || completedWork.child !== completedWork.alternate.child;
  10586. var child = completedWork.child;
  10587. while (child !== null) {
  10588. var childUpdateExpirationTime = child.expirationTime;
  10589. var childChildExpirationTime = child.childExpirationTime;
  10590. if (childUpdateExpirationTime > newChildExpirationTime) {
  10591. newChildExpirationTime = childUpdateExpirationTime;
  10592. }
  10593. if (childChildExpirationTime > newChildExpirationTime) {
  10594. newChildExpirationTime = childChildExpirationTime;
  10595. }
  10596. if (shouldBubbleActualDurations) {
  10597. actualDuration += child.actualDuration;
  10598. }
  10599. treeBaseDuration += child.treeBaseDuration;
  10600. child = child.sibling;
  10601. }
  10602. completedWork.actualDuration = actualDuration;
  10603. completedWork.treeBaseDuration = treeBaseDuration;
  10604. } else {
  10605. var _child = completedWork.child;
  10606. while (_child !== null) {
  10607. var _childUpdateExpirationTime = _child.expirationTime;
  10608. var _childChildExpirationTime = _child.childExpirationTime;
  10609. if (_childUpdateExpirationTime > newChildExpirationTime) {
  10610. newChildExpirationTime = _childUpdateExpirationTime;
  10611. }
  10612. if (_childChildExpirationTime > newChildExpirationTime) {
  10613. newChildExpirationTime = _childChildExpirationTime;
  10614. }
  10615. _child = _child.sibling;
  10616. }
  10617. }
  10618. completedWork.childExpirationTime = newChildExpirationTime;
  10619. }
  10620. function commitRoot(root) {
  10621. var renderPriorityLevel = getCurrentPriorityLevel();
  10622. runWithPriority(ImmediatePriority, commitRootImpl.bind(null, root, renderPriorityLevel));
  10623. return null;
  10624. }
  10625. function commitRootImpl(root, renderPriorityLevel) {
  10626. do {
  10627. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  10628. // means `flushPassiveEffects` will sometimes result in additional
  10629. // passive effects. So we need to keep flushing in a loop until there are
  10630. // no more pending effects.
  10631. // TODO: Might be better if `flushPassiveEffects` did not automatically
  10632. // flush synchronous work at the end, to avoid factoring hazards like this.
  10633. flushPassiveEffects();
  10634. } while (rootWithPendingPassiveEffects !== null);
  10635. flushRenderPhaseStrictModeWarningsInDEV();
  10636. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  10637. {
  10638. throw Error( "Should not already be working." );
  10639. }
  10640. }
  10641. var finishedWork = root.finishedWork;
  10642. var expirationTime = root.finishedExpirationTime;
  10643. if (finishedWork === null) {
  10644. return null;
  10645. }
  10646. root.finishedWork = null;
  10647. root.finishedExpirationTime = NoWork;
  10648. if (!(finishedWork !== root.current)) {
  10649. {
  10650. throw Error( "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue." );
  10651. }
  10652. } // commitRoot never returns a continuation; it always finishes synchronously.
  10653. // So we can clear these now to allow a new callback to be scheduled.
  10654. root.callbackNode = null;
  10655. root.callbackExpirationTime = NoWork;
  10656. root.callbackPriority = NoPriority;
  10657. root.nextKnownPendingLevel = NoWork;
  10658. startCommitTimer(); // Update the first and last pending times on this root. The new first
  10659. // pending time is whatever is left on the root fiber.
  10660. var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(finishedWork);
  10661. markRootFinishedAtTime(root, expirationTime, remainingExpirationTimeBeforeCommit);
  10662. if (root === workInProgressRoot) {
  10663. // We can reset these now that they are finished.
  10664. workInProgressRoot = null;
  10665. workInProgress = null;
  10666. renderExpirationTime$1 = NoWork;
  10667. } // This indicates that the last root we worked on is not the same one that
  10668. // we're committing now. This most commonly happens when a suspended root
  10669. // times out.
  10670. // Get the list of effects.
  10671. var firstEffect;
  10672. if (finishedWork.effectTag > PerformedWork) {
  10673. // A fiber's effect list consists only of its children, not itself. So if
  10674. // the root has an effect, we need to add it to the end of the list. The
  10675. // resulting list is the set that would belong to the root's parent, if it
  10676. // had one; that is, all the effects in the tree including the root.
  10677. if (finishedWork.lastEffect !== null) {
  10678. finishedWork.lastEffect.nextEffect = finishedWork;
  10679. firstEffect = finishedWork.firstEffect;
  10680. } else {
  10681. firstEffect = finishedWork;
  10682. }
  10683. } else {
  10684. // There is no effect on the root.
  10685. firstEffect = finishedWork.firstEffect;
  10686. }
  10687. if (firstEffect !== null) {
  10688. var prevExecutionContext = executionContext;
  10689. executionContext |= CommitContext;
  10690. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  10691. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  10692. // of the effect list for each phase: all mutation effects come before all
  10693. // layout effects, and so on.
  10694. // The first phase a "before mutation" phase. We use this phase to read the
  10695. // state of the host tree right before we mutate it. This is where
  10696. // getSnapshotBeforeUpdate is called.
  10697. startCommitSnapshotEffectsTimer();
  10698. prepareForCommit(root.containerInfo);
  10699. nextEffect = firstEffect;
  10700. do {
  10701. {
  10702. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  10703. if (hasCaughtError()) {
  10704. if (!(nextEffect !== null)) {
  10705. {
  10706. throw Error( "Should be working on an effect." );
  10707. }
  10708. }
  10709. var error = clearCaughtError();
  10710. captureCommitPhaseError(nextEffect, error);
  10711. nextEffect = nextEffect.nextEffect;
  10712. }
  10713. }
  10714. } while (nextEffect !== null);
  10715. stopCommitSnapshotEffectsTimer();
  10716. {
  10717. // Mark the current commit time to be shared by all Profilers in this
  10718. // batch. This enables them to be grouped later.
  10719. recordCommitTime();
  10720. } // The next phase is the mutation phase, where we mutate the host tree.
  10721. startCommitHostEffectsTimer();
  10722. nextEffect = firstEffect;
  10723. do {
  10724. {
  10725. invokeGuardedCallback(null, commitMutationEffects, null, root, renderPriorityLevel);
  10726. if (hasCaughtError()) {
  10727. if (!(nextEffect !== null)) {
  10728. {
  10729. throw Error( "Should be working on an effect." );
  10730. }
  10731. }
  10732. var _error = clearCaughtError();
  10733. captureCommitPhaseError(nextEffect, _error);
  10734. nextEffect = nextEffect.nextEffect;
  10735. }
  10736. }
  10737. } while (nextEffect !== null);
  10738. stopCommitHostEffectsTimer();
  10739. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  10740. // the mutation phase, so that the previous tree is still current during
  10741. // componentWillUnmount, but before the layout phase, so that the finished
  10742. // work is current during componentDidMount/Update.
  10743. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  10744. // the host tree after it's been mutated. The idiomatic use case for this is
  10745. // layout, but class component lifecycles also fire here for legacy reasons.
  10746. startCommitLifeCyclesTimer();
  10747. nextEffect = firstEffect;
  10748. do {
  10749. {
  10750. invokeGuardedCallback(null, commitLayoutEffects, null, root, expirationTime);
  10751. if (hasCaughtError()) {
  10752. if (!(nextEffect !== null)) {
  10753. {
  10754. throw Error( "Should be working on an effect." );
  10755. }
  10756. }
  10757. var _error2 = clearCaughtError();
  10758. captureCommitPhaseError(nextEffect, _error2);
  10759. nextEffect = nextEffect.nextEffect;
  10760. }
  10761. }
  10762. } while (nextEffect !== null);
  10763. stopCommitLifeCyclesTimer();
  10764. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  10765. // opportunity to paint.
  10766. requestPaint();
  10767. {
  10768. popInteractions(prevInteractions);
  10769. }
  10770. executionContext = prevExecutionContext;
  10771. } else {
  10772. // No effects.
  10773. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  10774. // no effects.
  10775. // TODO: Maybe there's a better way to report this.
  10776. startCommitSnapshotEffectsTimer();
  10777. stopCommitSnapshotEffectsTimer();
  10778. {
  10779. recordCommitTime();
  10780. }
  10781. startCommitHostEffectsTimer();
  10782. stopCommitHostEffectsTimer();
  10783. startCommitLifeCyclesTimer();
  10784. stopCommitLifeCyclesTimer();
  10785. }
  10786. stopCommitTimer();
  10787. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  10788. if (rootDoesHavePassiveEffects) {
  10789. // This commit has passive effects. Stash a reference to them. But don't
  10790. // schedule a callback until after flushing layout work.
  10791. rootDoesHavePassiveEffects = false;
  10792. rootWithPendingPassiveEffects = root;
  10793. pendingPassiveEffectsExpirationTime = expirationTime;
  10794. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  10795. } else {
  10796. // We are done with the effect chain at this point so let's clear the
  10797. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  10798. // clear this in flushPassiveEffects.
  10799. nextEffect = firstEffect;
  10800. while (nextEffect !== null) {
  10801. var nextNextEffect = nextEffect.nextEffect;
  10802. nextEffect.nextEffect = null;
  10803. nextEffect = nextNextEffect;
  10804. }
  10805. } // Check if there's remaining work on this root
  10806. var remainingExpirationTime = root.firstPendingTime;
  10807. if (remainingExpirationTime !== NoWork) {
  10808. {
  10809. if (spawnedWorkDuringRender !== null) {
  10810. var expirationTimes = spawnedWorkDuringRender;
  10811. spawnedWorkDuringRender = null;
  10812. for (var i = 0; i < expirationTimes.length; i++) {
  10813. scheduleInteractions(root, expirationTimes[i], root.memoizedInteractions);
  10814. }
  10815. }
  10816. schedulePendingInteractions(root, remainingExpirationTime);
  10817. }
  10818. } else {
  10819. // If there's no remaining work, we can clear the set of already failed
  10820. // error boundaries.
  10821. legacyErrorBoundariesThatAlreadyFailed = null;
  10822. }
  10823. {
  10824. if (!rootDidHavePassiveEffects) {
  10825. // If there are no passive effects, then we can complete the pending interactions.
  10826. // Otherwise, we'll wait until after the passive effects are flushed.
  10827. // Wait to do this until after remaining work has been scheduled,
  10828. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  10829. finishPendingInteractions(root, expirationTime);
  10830. }
  10831. }
  10832. if (remainingExpirationTime === Sync) {
  10833. // Count the number of times the root synchronously re-renders without
  10834. // finishing. If there are too many, it indicates an infinite update loop.
  10835. if (root === rootWithNestedUpdates) {
  10836. nestedUpdateCount++;
  10837. } else {
  10838. nestedUpdateCount = 0;
  10839. rootWithNestedUpdates = root;
  10840. }
  10841. } else {
  10842. nestedUpdateCount = 0;
  10843. }
  10844. onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
  10845. // additional work on this root is scheduled.
  10846. ensureRootIsScheduled(root);
  10847. if (hasUncaughtError) {
  10848. hasUncaughtError = false;
  10849. var _error3 = firstUncaughtError;
  10850. firstUncaughtError = null;
  10851. throw _error3;
  10852. }
  10853. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  10854. // This is a legacy edge case. We just committed the initial mount of
  10855. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  10856. // synchronously, but layout updates should be deferred until the end
  10857. // of the batch.
  10858. return null;
  10859. } // If layout work was scheduled, flush it now.
  10860. flushSyncCallbackQueue();
  10861. return null;
  10862. }
  10863. function commitBeforeMutationEffects() {
  10864. while (nextEffect !== null) {
  10865. var effectTag = nextEffect.effectTag;
  10866. if ((effectTag & Snapshot) !== NoEffect) {
  10867. setCurrentFiber(nextEffect);
  10868. recordEffect();
  10869. var current = nextEffect.alternate;
  10870. commitBeforeMutationLifeCycles(current, nextEffect);
  10871. resetCurrentFiber();
  10872. }
  10873. if ((effectTag & Passive) !== NoEffect) {
  10874. // If there are passive effects, schedule a callback to flush at
  10875. // the earliest opportunity.
  10876. if (!rootDoesHavePassiveEffects) {
  10877. rootDoesHavePassiveEffects = true;
  10878. scheduleCallback(NormalPriority, function () {
  10879. flushPassiveEffects();
  10880. return null;
  10881. });
  10882. }
  10883. }
  10884. nextEffect = nextEffect.nextEffect;
  10885. }
  10886. }
  10887. function commitMutationEffects(root, renderPriorityLevel) {
  10888. // TODO: Should probably move the bulk of this function to commitWork.
  10889. while (nextEffect !== null) {
  10890. setCurrentFiber(nextEffect);
  10891. var effectTag = nextEffect.effectTag;
  10892. if (effectTag & ContentReset) {
  10893. commitResetTextContent(nextEffect);
  10894. }
  10895. if (effectTag & Ref) {
  10896. var current = nextEffect.alternate;
  10897. if (current !== null) {
  10898. commitDetachRef(current);
  10899. }
  10900. } // The following switch statement is only concerned about placement,
  10901. // updates, and deletions. To avoid needing to add a case for every possible
  10902. // bitmap value, we remove the secondary effects from the effect tag and
  10903. // switch on that value.
  10904. var primaryEffectTag = effectTag & (Placement | Update | Deletion | Hydrating);
  10905. switch (primaryEffectTag) {
  10906. case Placement:
  10907. {
  10908. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  10909. // inserted, before any life-cycles like componentDidMount gets called.
  10910. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  10911. // and isMounted is deprecated anyway so we should be able to kill this.
  10912. nextEffect.effectTag &= ~Placement;
  10913. break;
  10914. }
  10915. case PlacementAndUpdate:
  10916. {
  10917. // Placement
  10918. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  10919. // inserted, before any life-cycles like componentDidMount gets called.
  10920. nextEffect.effectTag &= ~Placement; // Update
  10921. var _current = nextEffect.alternate;
  10922. commitWork(_current, nextEffect);
  10923. break;
  10924. }
  10925. case Hydrating:
  10926. {
  10927. nextEffect.effectTag &= ~Hydrating;
  10928. break;
  10929. }
  10930. case HydratingAndUpdate:
  10931. {
  10932. nextEffect.effectTag &= ~Hydrating; // Update
  10933. var _current2 = nextEffect.alternate;
  10934. commitWork(_current2, nextEffect);
  10935. break;
  10936. }
  10937. case Update:
  10938. {
  10939. var _current3 = nextEffect.alternate;
  10940. commitWork(_current3, nextEffect);
  10941. break;
  10942. }
  10943. case Deletion:
  10944. {
  10945. commitDeletion(root, nextEffect, renderPriorityLevel);
  10946. break;
  10947. }
  10948. } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
  10949. recordEffect();
  10950. resetCurrentFiber();
  10951. nextEffect = nextEffect.nextEffect;
  10952. }
  10953. }
  10954. function commitLayoutEffects(root, committedExpirationTime) {
  10955. // TODO: Should probably move the bulk of this function to commitWork.
  10956. while (nextEffect !== null) {
  10957. setCurrentFiber(nextEffect);
  10958. var effectTag = nextEffect.effectTag;
  10959. if (effectTag & (Update | Callback)) {
  10960. recordEffect();
  10961. var current = nextEffect.alternate;
  10962. commitLifeCycles(root, current, nextEffect);
  10963. }
  10964. if (effectTag & Ref) {
  10965. recordEffect();
  10966. commitAttachRef(nextEffect);
  10967. }
  10968. resetCurrentFiber();
  10969. nextEffect = nextEffect.nextEffect;
  10970. }
  10971. }
  10972. function flushPassiveEffects() {
  10973. if (pendingPassiveEffectsRenderPriority !== NoPriority) {
  10974. var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority ? NormalPriority : pendingPassiveEffectsRenderPriority;
  10975. pendingPassiveEffectsRenderPriority = NoPriority;
  10976. return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
  10977. }
  10978. }
  10979. function flushPassiveEffectsImpl() {
  10980. if (rootWithPendingPassiveEffects === null) {
  10981. return false;
  10982. }
  10983. var root = rootWithPendingPassiveEffects;
  10984. var expirationTime = pendingPassiveEffectsExpirationTime;
  10985. rootWithPendingPassiveEffects = null;
  10986. pendingPassiveEffectsExpirationTime = NoWork;
  10987. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  10988. {
  10989. throw Error( "Cannot flush passive effects while already rendering." );
  10990. }
  10991. }
  10992. var prevExecutionContext = executionContext;
  10993. executionContext |= CommitContext;
  10994. var prevInteractions = pushInteractions(root);
  10995. {
  10996. // Note: This currently assumes there are no passive effects on the root fiber
  10997. // because the root is not part of its own effect list.
  10998. // This could change in the future.
  10999. var _effect2 = root.current.firstEffect;
  11000. while (_effect2 !== null) {
  11001. {
  11002. setCurrentFiber(_effect2);
  11003. invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
  11004. if (hasCaughtError()) {
  11005. if (!(_effect2 !== null)) {
  11006. {
  11007. throw Error( "Should be working on an effect." );
  11008. }
  11009. }
  11010. var _error5 = clearCaughtError();
  11011. captureCommitPhaseError(_effect2, _error5);
  11012. }
  11013. resetCurrentFiber();
  11014. }
  11015. var nextNextEffect = _effect2.nextEffect; // Remove nextEffect pointer to assist GC
  11016. _effect2.nextEffect = null;
  11017. _effect2 = nextNextEffect;
  11018. }
  11019. }
  11020. {
  11021. popInteractions(prevInteractions);
  11022. finishPendingInteractions(root, expirationTime);
  11023. }
  11024. executionContext = prevExecutionContext;
  11025. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  11026. // exceeds the limit, we'll fire a warning.
  11027. nestedPassiveUpdateCount = rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  11028. return true;
  11029. }
  11030. function isAlreadyFailedLegacyErrorBoundary(instance) {
  11031. return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
  11032. }
  11033. function markLegacyErrorBoundaryAsFailed(instance) {
  11034. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  11035. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  11036. } else {
  11037. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  11038. }
  11039. }
  11040. function prepareToThrowUncaughtError(error) {
  11041. if (!hasUncaughtError) {
  11042. hasUncaughtError = true;
  11043. firstUncaughtError = error;
  11044. }
  11045. }
  11046. var onUncaughtError = prepareToThrowUncaughtError;
  11047. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  11048. var errorInfo = createCapturedValue(error, sourceFiber);
  11049. var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
  11050. enqueueUpdate(rootFiber, update);
  11051. var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
  11052. if (root !== null) {
  11053. ensureRootIsScheduled(root);
  11054. schedulePendingInteractions(root, Sync);
  11055. }
  11056. }
  11057. function captureCommitPhaseError(sourceFiber, error) {
  11058. if (sourceFiber.tag === HostRoot) {
  11059. // Error was thrown at the root. There is no parent, so the root
  11060. // itself should capture it.
  11061. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  11062. return;
  11063. }
  11064. var fiber = sourceFiber.return;
  11065. while (fiber !== null) {
  11066. if (fiber.tag === HostRoot) {
  11067. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  11068. return;
  11069. } else if (fiber.tag === ClassComponent) {
  11070. var ctor = fiber.type;
  11071. var instance = fiber.stateNode;
  11072. if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
  11073. var errorInfo = createCapturedValue(error, sourceFiber);
  11074. var update = createClassErrorUpdate(fiber, errorInfo, // TODO: This is always sync
  11075. Sync);
  11076. enqueueUpdate(fiber, update);
  11077. var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
  11078. if (root !== null) {
  11079. ensureRootIsScheduled(root);
  11080. schedulePendingInteractions(root, Sync);
  11081. }
  11082. return;
  11083. }
  11084. }
  11085. fiber = fiber.return;
  11086. }
  11087. }
  11088. function pingSuspendedRoot(root, thenable, suspendedTime) {
  11089. var pingCache = root.pingCache;
  11090. if (pingCache !== null) {
  11091. // The thenable resolved, so we no longer need to memoize, because it will
  11092. // never be thrown again.
  11093. pingCache.delete(thenable);
  11094. }
  11095. if (workInProgressRoot === root && renderExpirationTime$1 === suspendedTime) {
  11096. // Received a ping at the same priority level at which we're currently
  11097. // rendering. We might want to restart this render. This should mirror
  11098. // the logic of whether or not a root suspends once it completes.
  11099. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  11100. // we should probably never restart.
  11101. // If we're suspended with delay, we'll always suspend so we can always
  11102. // restart. If we're suspended without any updates, it might be a retry.
  11103. // If it's early in the retry we can restart. We can't know for sure
  11104. // whether we'll eventually process an update during this render pass,
  11105. // but it's somewhat unlikely that we get to a ping before that, since
  11106. // getting to the root most update is usually very fast.
  11107. if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && workInProgressRootLatestProcessedExpirationTime === Sync && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
  11108. // Restart from the root. Don't need to schedule a ping because
  11109. // we're already working on this tree.
  11110. prepareFreshStack(root, renderExpirationTime$1);
  11111. } else {
  11112. // Even though we can't restart right now, we might get an
  11113. // opportunity later. So we mark this render as having a ping.
  11114. workInProgressRootHasPendingPing = true;
  11115. }
  11116. return;
  11117. }
  11118. if (!isRootSuspendedAtTime(root, suspendedTime)) {
  11119. // The root is no longer suspended at this time.
  11120. return;
  11121. }
  11122. var lastPingedTime = root.lastPingedTime;
  11123. if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
  11124. // There's already a lower priority ping scheduled.
  11125. return;
  11126. } // Mark the time at which this ping was scheduled.
  11127. root.lastPingedTime = suspendedTime;
  11128. ensureRootIsScheduled(root);
  11129. schedulePendingInteractions(root, suspendedTime);
  11130. }
  11131. function retryTimedOutBoundary(boundaryFiber, retryTime) {
  11132. // The boundary fiber (a Suspense component or SuspenseList component)
  11133. // previously was rendered in its fallback state. One of the promises that
  11134. // suspended it has resolved, which means at least part of the tree was
  11135. // likely unblocked. Try rendering again, at a new expiration time.
  11136. if (retryTime === NoWork) {
  11137. var suspenseConfig = null; // Retries don't carry over the already committed update.
  11138. var currentTime = requestCurrentTimeForUpdate();
  11139. retryTime = computeExpirationForFiber(currentTime, boundaryFiber, suspenseConfig);
  11140. } // TODO: Special case idle priority?
  11141. var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
  11142. if (root !== null) {
  11143. ensureRootIsScheduled(root);
  11144. schedulePendingInteractions(root, retryTime);
  11145. }
  11146. }
  11147. function resolveRetryThenable(boundaryFiber, thenable) {
  11148. var retryTime = NoWork; // Default
  11149. var retryCache;
  11150. {
  11151. retryCache = boundaryFiber.stateNode;
  11152. }
  11153. if (retryCache !== null) {
  11154. // The thenable resolved, so we no longer need to memoize, because it will
  11155. // never be thrown again.
  11156. retryCache.delete(thenable);
  11157. }
  11158. retryTimedOutBoundary(boundaryFiber, retryTime);
  11159. } // Computes the next Just Noticeable Difference (JND) boundary.
  11160. // The theory is that a person can't tell the difference between small differences in time.
  11161. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  11162. // difference in the experience. However, waiting for longer might mean that we can avoid
  11163. // showing an intermediate loading state. The longer we have already waited, the harder it
  11164. // is to tell small differences in time. Therefore, the longer we've already waited,
  11165. // the longer we can wait additionally. At some point we have to give up though.
  11166. // We pick a train model where the next boundary commits at a consistent schedule.
  11167. // These particular numbers are vague estimates. We expect to adjust them based on research.
  11168. function jnd(timeElapsed) {
  11169. return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
  11170. }
  11171. function computeMsUntilSuspenseLoadingDelay(mostRecentEventTime, committedExpirationTime, suspenseConfig) {
  11172. var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
  11173. if (busyMinDurationMs <= 0) {
  11174. return 0;
  11175. }
  11176. var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
  11177. var currentTimeMs = now();
  11178. var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(mostRecentEventTime, suspenseConfig);
  11179. var timeElapsed = currentTimeMs - eventTimeMs;
  11180. if (timeElapsed <= busyDelayMs) {
  11181. // If we haven't yet waited longer than the initial delay, we don't
  11182. // have to wait any additional time.
  11183. return 0;
  11184. }
  11185. var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
  11186. return msUntilTimeout;
  11187. }
  11188. function checkForNestedUpdates() {
  11189. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  11190. nestedUpdateCount = 0;
  11191. rootWithNestedUpdates = null;
  11192. {
  11193. {
  11194. 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." );
  11195. }
  11196. }
  11197. }
  11198. {
  11199. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  11200. nestedPassiveUpdateCount = 0;
  11201. 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.');
  11202. }
  11203. }
  11204. }
  11205. function flushRenderPhaseStrictModeWarningsInDEV() {
  11206. {
  11207. ReactStrictModeWarnings.flushLegacyContextWarning();
  11208. {
  11209. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  11210. }
  11211. }
  11212. }
  11213. function stopFinishedWorkLoopTimer() {
  11214. var didCompleteRoot = true;
  11215. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  11216. interruptedBy = null;
  11217. }
  11218. function stopInterruptedWorkLoopTimer() {
  11219. // TODO: Track which fiber caused the interruption.
  11220. var didCompleteRoot = false;
  11221. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  11222. interruptedBy = null;
  11223. }
  11224. function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
  11225. if ( workInProgressRoot !== null && updateExpirationTime > renderExpirationTime$1) {
  11226. interruptedBy = fiberThatReceivedUpdate;
  11227. }
  11228. }
  11229. var didWarnStateUpdateForUnmountedComponent = null;
  11230. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  11231. {
  11232. var tag = fiber.tag;
  11233. if (tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent && tag !== Block) {
  11234. // Only warn for user-defined components, not internal ones like Suspense.
  11235. return;
  11236. }
  11237. // the problematic code almost always lies inside that component.
  11238. var componentName = getComponentName(fiber.type) || 'ReactComponent';
  11239. if (didWarnStateUpdateForUnmountedComponent !== null) {
  11240. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  11241. return;
  11242. }
  11243. didWarnStateUpdateForUnmountedComponent.add(componentName);
  11244. } else {
  11245. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  11246. }
  11247. 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));
  11248. }
  11249. }
  11250. var beginWork$1;
  11251. {
  11252. beginWork$1 = beginWork;
  11253. }
  11254. var didWarnAboutUpdateInRender = false;
  11255. var didWarnAboutUpdateInRenderForAnotherComponent;
  11256. {
  11257. didWarnAboutUpdateInRenderForAnotherComponent = new Set();
  11258. }
  11259. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  11260. {
  11261. if (isRendering && (executionContext & RenderContext) !== NoContext) {
  11262. switch (fiber.tag) {
  11263. case FunctionComponent:
  11264. case ForwardRef:
  11265. case SimpleMemoComponent:
  11266. {
  11267. var renderingComponentName = workInProgress && getComponentName(workInProgress.type) || 'Unknown'; // Dedupe by the rendering component because it's the one that needs to be fixed.
  11268. var dedupeKey = renderingComponentName;
  11269. if (!didWarnAboutUpdateInRenderForAnotherComponent.has(dedupeKey)) {
  11270. didWarnAboutUpdateInRenderForAnotherComponent.add(dedupeKey);
  11271. var setStateComponentName = getComponentName(fiber.type) || 'Unknown';
  11272. 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);
  11273. }
  11274. break;
  11275. }
  11276. case ClassComponent:
  11277. {
  11278. if (!didWarnAboutUpdateInRender) {
  11279. error('Cannot update during an existing state transition (such as ' + 'within `render`). Render methods should be a pure ' + 'function of props and state.');
  11280. didWarnAboutUpdateInRender = true;
  11281. }
  11282. break;
  11283. }
  11284. }
  11285. }
  11286. }
  11287. } // a 'shared' variable that changes when act() opens/closes in tests.
  11288. var IsThisRendererActing = {
  11289. current: false
  11290. };
  11291. function warnIfNotScopedWithMatchingAct(fiber) {
  11292. {
  11293. if ( IsSomeRendererActing.current === true && IsThisRendererActing.current !== true) {
  11294. 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));
  11295. }
  11296. }
  11297. }
  11298. function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
  11299. {
  11300. if ( (fiber.mode & StrictMode) !== NoMode && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  11301. 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));
  11302. }
  11303. }
  11304. }
  11305. function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
  11306. {
  11307. if ( executionContext === NoContext && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  11308. 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));
  11309. }
  11310. }
  11311. }
  11312. var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
  11313. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  11314. // scheduler is the actual recommendation. The alternative could be a testing build,
  11315. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  11316. // to get their tests right.
  11317. function warnIfUnmockedScheduler(fiber) {
  11318. {
  11319. if (didWarnAboutUnmockedScheduler === false && Scheduler$1.unstable_flushAllWithoutAsserting === undefined) {
  11320. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  11321. didWarnAboutUnmockedScheduler = true;
  11322. 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');
  11323. }
  11324. }
  11325. }
  11326. }
  11327. function computeThreadID(root, expirationTime) {
  11328. // Interaction threads are unique per root and expiration time.
  11329. return expirationTime * 1000 + root.interactionThreadID;
  11330. }
  11331. function markSpawnedWork(expirationTime) {
  11332. if (spawnedWorkDuringRender === null) {
  11333. spawnedWorkDuringRender = [expirationTime];
  11334. } else {
  11335. spawnedWorkDuringRender.push(expirationTime);
  11336. }
  11337. }
  11338. function scheduleInteractions(root, expirationTime, interactions) {
  11339. if (interactions.size > 0) {
  11340. var pendingInteractionMap = root.pendingInteractionMap;
  11341. var pendingInteractions = pendingInteractionMap.get(expirationTime);
  11342. if (pendingInteractions != null) {
  11343. interactions.forEach(function (interaction) {
  11344. if (!pendingInteractions.has(interaction)) {
  11345. // Update the pending async work count for previously unscheduled interaction.
  11346. interaction.__count++;
  11347. }
  11348. pendingInteractions.add(interaction);
  11349. });
  11350. } else {
  11351. pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
  11352. interactions.forEach(function (interaction) {
  11353. interaction.__count++;
  11354. });
  11355. }
  11356. var subscriber = __subscriberRef.current;
  11357. if (subscriber !== null) {
  11358. var threadID = computeThreadID(root, expirationTime);
  11359. subscriber.onWorkScheduled(interactions, threadID);
  11360. }
  11361. }
  11362. }
  11363. function schedulePendingInteractions(root, expirationTime) {
  11364. scheduleInteractions(root, expirationTime, __interactionsRef.current);
  11365. }
  11366. function startWorkOnPendingInteractions(root, expirationTime) {
  11367. // we can accurately attribute time spent working on it, And so that cascading
  11368. // work triggered during the render phase will be associated with it.
  11369. var interactions = new Set();
  11370. root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
  11371. if (scheduledExpirationTime >= expirationTime) {
  11372. scheduledInteractions.forEach(function (interaction) {
  11373. return interactions.add(interaction);
  11374. });
  11375. }
  11376. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  11377. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  11378. // without having to recalculate it. We will also use it in commitWork() to
  11379. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  11380. // way to access it when the onCommitRoot() hook is called.
  11381. root.memoizedInteractions = interactions;
  11382. if (interactions.size > 0) {
  11383. var subscriber = __subscriberRef.current;
  11384. if (subscriber !== null) {
  11385. var threadID = computeThreadID(root, expirationTime);
  11386. try {
  11387. subscriber.onWorkStarted(interactions, threadID);
  11388. } catch (error) {
  11389. // If the subscriber throws, rethrow it in a separate task
  11390. scheduleCallback(ImmediatePriority, function () {
  11391. throw error;
  11392. });
  11393. }
  11394. }
  11395. }
  11396. }
  11397. function finishPendingInteractions(root, committedExpirationTime) {
  11398. var earliestRemainingTimeAfterCommit = root.firstPendingTime;
  11399. var subscriber;
  11400. try {
  11401. subscriber = __subscriberRef.current;
  11402. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  11403. var threadID = computeThreadID(root, committedExpirationTime);
  11404. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  11405. }
  11406. } catch (error) {
  11407. // If the subscriber throws, rethrow it in a separate task
  11408. scheduleCallback(ImmediatePriority, function () {
  11409. throw error;
  11410. });
  11411. } finally {
  11412. // Clear completed interactions from the pending Map.
  11413. // Unless the render was suspended or cascading work was scheduled,
  11414. // In which case– leave pending interactions until the subsequent render.
  11415. var pendingInteractionMap = root.pendingInteractionMap;
  11416. pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
  11417. // Only decrement the pending interaction count if we're done.
  11418. // If there's still work at the current priority,
  11419. // That indicates that we are waiting for suspense data.
  11420. if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
  11421. pendingInteractionMap.delete(scheduledExpirationTime);
  11422. scheduledInteractions.forEach(function (interaction) {
  11423. interaction.__count--;
  11424. if (subscriber !== null && interaction.__count === 0) {
  11425. try {
  11426. subscriber.onInteractionScheduledWorkCompleted(interaction);
  11427. } catch (error) {
  11428. // If the subscriber throws, rethrow it in a separate task
  11429. scheduleCallback(ImmediatePriority, function () {
  11430. throw error;
  11431. });
  11432. }
  11433. }
  11434. });
  11435. }
  11436. });
  11437. }
  11438. }
  11439. var onScheduleFiberRoot = null;
  11440. var onCommitFiberRoot = null;
  11441. var onCommitFiberUnmount = null;
  11442. var hasLoggedError = false;
  11443. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
  11444. function injectInternals(internals) {
  11445. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
  11446. // No DevTools
  11447. return false;
  11448. }
  11449. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  11450. if (hook.isDisabled) {
  11451. // This isn't a real property on the hook, but it can be set to opt out
  11452. // of DevTools integration and associated warnings and logs.
  11453. // https://github.com/facebook/react/issues/3877
  11454. return true;
  11455. }
  11456. if (!hook.supportsFiber) {
  11457. {
  11458. 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');
  11459. } // DevTools exists, even though it doesn't support Fiber.
  11460. return true;
  11461. }
  11462. try {
  11463. var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  11464. if (true) {
  11465. // Only used by Fast Refresh
  11466. if (typeof hook.onScheduleFiberRoot === 'function') {
  11467. onScheduleFiberRoot = function (root, children) {
  11468. try {
  11469. hook.onScheduleFiberRoot(rendererID, root, children);
  11470. } catch (err) {
  11471. if (true && !hasLoggedError) {
  11472. hasLoggedError = true;
  11473. error('React instrumentation encountered an error: %s', err);
  11474. }
  11475. }
  11476. };
  11477. }
  11478. }
  11479. onCommitFiberRoot = function (root, expirationTime) {
  11480. try {
  11481. var didError = (root.current.effectTag & DidCapture) === DidCapture;
  11482. if (enableProfilerTimer) {
  11483. var currentTime = getCurrentTime();
  11484. var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime);
  11485. hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  11486. } else {
  11487. hook.onCommitFiberRoot(rendererID, root, undefined, didError);
  11488. }
  11489. } catch (err) {
  11490. if (true) {
  11491. if (!hasLoggedError) {
  11492. hasLoggedError = true;
  11493. error('React instrumentation encountered an error: %s', err);
  11494. }
  11495. }
  11496. }
  11497. };
  11498. onCommitFiberUnmount = function (fiber) {
  11499. try {
  11500. hook.onCommitFiberUnmount(rendererID, fiber);
  11501. } catch (err) {
  11502. if (true) {
  11503. if (!hasLoggedError) {
  11504. hasLoggedError = true;
  11505. error('React instrumentation encountered an error: %s', err);
  11506. }
  11507. }
  11508. }
  11509. };
  11510. } catch (err) {
  11511. // Catch all errors because it is unsafe to throw during initialization.
  11512. {
  11513. error('React instrumentation encountered an error: %s.', err);
  11514. }
  11515. } // DevTools exists
  11516. return true;
  11517. }
  11518. function onScheduleRoot(root, children) {
  11519. if (typeof onScheduleFiberRoot === 'function') {
  11520. onScheduleFiberRoot(root, children);
  11521. }
  11522. }
  11523. function onCommitRoot(root, expirationTime) {
  11524. if (typeof onCommitFiberRoot === 'function') {
  11525. onCommitFiberRoot(root, expirationTime);
  11526. }
  11527. }
  11528. function onCommitUnmount(fiber) {
  11529. if (typeof onCommitFiberUnmount === 'function') {
  11530. onCommitFiberUnmount(fiber);
  11531. }
  11532. }
  11533. var hasBadMapPolyfill;
  11534. {
  11535. hasBadMapPolyfill = false;
  11536. try {
  11537. var nonExtensibleObject = Object.preventExtensions({});
  11538. var testMap = new Map([[nonExtensibleObject, null]]);
  11539. var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
  11540. // https://github.com/rollup/rollup/issues/1771
  11541. // TODO: we can remove these if Rollup fixes the bug.
  11542. testMap.set(0, 0);
  11543. testSet.add(0);
  11544. } catch (e) {
  11545. // TODO: Consider warning about bad polyfills
  11546. hasBadMapPolyfill = true;
  11547. }
  11548. }
  11549. var debugCounter = 1;
  11550. function FiberNode(tag, pendingProps, key, mode) {
  11551. // Instance
  11552. this.tag = tag;
  11553. this.key = key;
  11554. this.elementType = null;
  11555. this.type = null;
  11556. this.stateNode = null; // Fiber
  11557. this.return = null;
  11558. this.child = null;
  11559. this.sibling = null;
  11560. this.index = 0;
  11561. this.ref = null;
  11562. this.pendingProps = pendingProps;
  11563. this.memoizedProps = null;
  11564. this.updateQueue = null;
  11565. this.memoizedState = null;
  11566. this.dependencies = null;
  11567. this.mode = mode; // Effects
  11568. this.effectTag = NoEffect;
  11569. this.nextEffect = null;
  11570. this.firstEffect = null;
  11571. this.lastEffect = null;
  11572. this.expirationTime = NoWork;
  11573. this.childExpirationTime = NoWork;
  11574. this.alternate = null;
  11575. {
  11576. // Note: The following is done to avoid a v8 performance cliff.
  11577. //
  11578. // Initializing the fields below to smis and later updating them with
  11579. // double values will cause Fibers to end up having separate shapes.
  11580. // This behavior/bug has something to do with Object.preventExtension().
  11581. // Fortunately this only impacts DEV builds.
  11582. // Unfortunately it makes React unusably slow for some applications.
  11583. // To work around this, initialize the fields below with doubles.
  11584. //
  11585. // Learn more about this here:
  11586. // https://github.com/facebook/react/issues/14365
  11587. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  11588. this.actualDuration = Number.NaN;
  11589. this.actualStartTime = Number.NaN;
  11590. this.selfBaseDuration = Number.NaN;
  11591. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  11592. // This won't trigger the performance cliff mentioned above,
  11593. // and it simplifies other profiler code (including DevTools).
  11594. this.actualDuration = 0;
  11595. this.actualStartTime = -1;
  11596. this.selfBaseDuration = 0;
  11597. this.treeBaseDuration = 0;
  11598. } // This is normally DEV-only except www when it adds listeners.
  11599. // TODO: remove the User Timing integration in favor of Root Events.
  11600. {
  11601. this._debugID = debugCounter++;
  11602. this._debugIsCurrentlyTiming = false;
  11603. }
  11604. {
  11605. this._debugSource = null;
  11606. this._debugOwner = null;
  11607. this._debugNeedsRemount = false;
  11608. this._debugHookTypes = null;
  11609. if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
  11610. Object.preventExtensions(this);
  11611. }
  11612. }
  11613. } // This is a constructor function, rather than a POJO constructor, still
  11614. // please ensure we do the following:
  11615. // 1) Nobody should add any instance methods on this. Instance methods can be
  11616. // more difficult to predict when they get optimized and they are almost
  11617. // never inlined properly in static compilers.
  11618. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  11619. // always know when it is a fiber.
  11620. // 3) We might want to experiment with using numeric keys since they are easier
  11621. // to optimize in a non-JIT environment.
  11622. // 4) We can easily go from a constructor to a createFiber object literal if that
  11623. // is faster.
  11624. // 5) It should be easy to port this to a C struct and keep a C implementation
  11625. // compatible.
  11626. var createFiber = function (tag, pendingProps, key, mode) {
  11627. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  11628. return new FiberNode(tag, pendingProps, key, mode);
  11629. };
  11630. function shouldConstruct(Component) {
  11631. var prototype = Component.prototype;
  11632. return !!(prototype && prototype.isReactComponent);
  11633. }
  11634. function isSimpleFunctionComponent(type) {
  11635. return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
  11636. }
  11637. function resolveLazyComponentTag(Component) {
  11638. if (typeof Component === 'function') {
  11639. return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
  11640. } else if (Component !== undefined && Component !== null) {
  11641. var $$typeof = Component.$$typeof;
  11642. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  11643. return ForwardRef;
  11644. }
  11645. if ($$typeof === REACT_MEMO_TYPE) {
  11646. return MemoComponent;
  11647. }
  11648. }
  11649. return IndeterminateComponent;
  11650. } // This is used to create an alternate fiber to do work on.
  11651. function createWorkInProgress(current, pendingProps) {
  11652. var workInProgress = current.alternate;
  11653. if (workInProgress === null) {
  11654. // We use a double buffering pooling technique because we know that we'll
  11655. // only ever need at most two versions of a tree. We pool the "other" unused
  11656. // node that we're free to reuse. This is lazily created to avoid allocating
  11657. // extra objects for things that are never updated. It also allow us to
  11658. // reclaim the extra memory if needed.
  11659. workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
  11660. workInProgress.elementType = current.elementType;
  11661. workInProgress.type = current.type;
  11662. workInProgress.stateNode = current.stateNode;
  11663. {
  11664. // DEV-only fields
  11665. {
  11666. workInProgress._debugID = current._debugID;
  11667. }
  11668. workInProgress._debugSource = current._debugSource;
  11669. workInProgress._debugOwner = current._debugOwner;
  11670. workInProgress._debugHookTypes = current._debugHookTypes;
  11671. }
  11672. workInProgress.alternate = current;
  11673. current.alternate = workInProgress;
  11674. } else {
  11675. workInProgress.pendingProps = pendingProps; // We already have an alternate.
  11676. // Reset the effect tag.
  11677. workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
  11678. workInProgress.nextEffect = null;
  11679. workInProgress.firstEffect = null;
  11680. workInProgress.lastEffect = null;
  11681. {
  11682. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  11683. // This prevents time from endlessly accumulating in new commits.
  11684. // This has the downside of resetting values for different priority renders,
  11685. // But works for yielding (the common case) and should support resuming.
  11686. workInProgress.actualDuration = 0;
  11687. workInProgress.actualStartTime = -1;
  11688. }
  11689. }
  11690. workInProgress.childExpirationTime = current.childExpirationTime;
  11691. workInProgress.expirationTime = current.expirationTime;
  11692. workInProgress.child = current.child;
  11693. workInProgress.memoizedProps = current.memoizedProps;
  11694. workInProgress.memoizedState = current.memoizedState;
  11695. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  11696. // it cannot be shared with the current fiber.
  11697. var currentDependencies = current.dependencies;
  11698. workInProgress.dependencies = currentDependencies === null ? null : {
  11699. expirationTime: currentDependencies.expirationTime,
  11700. firstContext: currentDependencies.firstContext,
  11701. responders: currentDependencies.responders
  11702. }; // These will be overridden during the parent's reconciliation
  11703. workInProgress.sibling = current.sibling;
  11704. workInProgress.index = current.index;
  11705. workInProgress.ref = current.ref;
  11706. {
  11707. workInProgress.selfBaseDuration = current.selfBaseDuration;
  11708. workInProgress.treeBaseDuration = current.treeBaseDuration;
  11709. }
  11710. {
  11711. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  11712. switch (workInProgress.tag) {
  11713. case IndeterminateComponent:
  11714. case FunctionComponent:
  11715. case SimpleMemoComponent:
  11716. workInProgress.type = resolveFunctionForHotReloading(current.type);
  11717. break;
  11718. case ClassComponent:
  11719. workInProgress.type = resolveClassForHotReloading(current.type);
  11720. break;
  11721. case ForwardRef:
  11722. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  11723. break;
  11724. }
  11725. }
  11726. return workInProgress;
  11727. } // Used to reuse a Fiber for a second pass.
  11728. function resetWorkInProgress(workInProgress, renderExpirationTime) {
  11729. // This resets the Fiber to what createFiber or createWorkInProgress would
  11730. // have set the values to before during the first pass. Ideally this wouldn't
  11731. // be necessary but unfortunately many code paths reads from the workInProgress
  11732. // when they should be reading from current and writing to workInProgress.
  11733. // We assume pendingProps, index, key, ref, return are still untouched to
  11734. // avoid doing another reconciliation.
  11735. // Reset the effect tag but keep any Placement tags, since that's something
  11736. // that child fiber is setting, not the reconciliation.
  11737. workInProgress.effectTag &= Placement; // The effect list is no longer valid.
  11738. workInProgress.nextEffect = null;
  11739. workInProgress.firstEffect = null;
  11740. workInProgress.lastEffect = null;
  11741. var current = workInProgress.alternate;
  11742. if (current === null) {
  11743. // Reset to createFiber's initial values.
  11744. workInProgress.childExpirationTime = NoWork;
  11745. workInProgress.expirationTime = renderExpirationTime;
  11746. workInProgress.child = null;
  11747. workInProgress.memoizedProps = null;
  11748. workInProgress.memoizedState = null;
  11749. workInProgress.updateQueue = null;
  11750. workInProgress.dependencies = null;
  11751. {
  11752. // Note: We don't reset the actualTime counts. It's useful to accumulate
  11753. // actual time across multiple render passes.
  11754. workInProgress.selfBaseDuration = 0;
  11755. workInProgress.treeBaseDuration = 0;
  11756. }
  11757. } else {
  11758. // Reset to the cloned values that createWorkInProgress would've.
  11759. workInProgress.childExpirationTime = current.childExpirationTime;
  11760. workInProgress.expirationTime = current.expirationTime;
  11761. workInProgress.child = current.child;
  11762. workInProgress.memoizedProps = current.memoizedProps;
  11763. workInProgress.memoizedState = current.memoizedState;
  11764. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  11765. // it cannot be shared with the current fiber.
  11766. var currentDependencies = current.dependencies;
  11767. workInProgress.dependencies = currentDependencies === null ? null : {
  11768. expirationTime: currentDependencies.expirationTime,
  11769. firstContext: currentDependencies.firstContext,
  11770. responders: currentDependencies.responders
  11771. };
  11772. {
  11773. // Note: We don't reset the actualTime counts. It's useful to accumulate
  11774. // actual time across multiple render passes.
  11775. workInProgress.selfBaseDuration = current.selfBaseDuration;
  11776. workInProgress.treeBaseDuration = current.treeBaseDuration;
  11777. }
  11778. }
  11779. return workInProgress;
  11780. }
  11781. function createHostRootFiber(tag) {
  11782. var mode;
  11783. if (tag === ConcurrentRoot) {
  11784. mode = ConcurrentMode | BlockingMode | StrictMode;
  11785. } else if (tag === BlockingRoot) {
  11786. mode = BlockingMode | StrictMode;
  11787. } else {
  11788. mode = NoMode;
  11789. }
  11790. if ( isDevToolsPresent) {
  11791. // Always collect profile timings when DevTools are present.
  11792. // This enables DevTools to start capturing timing at any point–
  11793. // Without some nodes in the tree having empty base times.
  11794. mode |= ProfileMode;
  11795. }
  11796. return createFiber(HostRoot, null, null, mode);
  11797. }
  11798. function createFiberFromTypeAndProps(type, // React$ElementType
  11799. key, pendingProps, owner, mode, expirationTime) {
  11800. var fiber;
  11801. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  11802. var resolvedType = type;
  11803. if (typeof type === 'function') {
  11804. if (shouldConstruct(type)) {
  11805. fiberTag = ClassComponent;
  11806. {
  11807. resolvedType = resolveClassForHotReloading(resolvedType);
  11808. }
  11809. } else {
  11810. {
  11811. resolvedType = resolveFunctionForHotReloading(resolvedType);
  11812. }
  11813. }
  11814. } else if (typeof type === 'string') {
  11815. fiberTag = HostComponent;
  11816. } else {
  11817. getTag: switch (type) {
  11818. case REACT_FRAGMENT_TYPE:
  11819. return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
  11820. case REACT_CONCURRENT_MODE_TYPE:
  11821. fiberTag = Mode;
  11822. mode |= ConcurrentMode | BlockingMode | StrictMode;
  11823. break;
  11824. case REACT_STRICT_MODE_TYPE:
  11825. fiberTag = Mode;
  11826. mode |= StrictMode;
  11827. break;
  11828. case REACT_PROFILER_TYPE:
  11829. return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
  11830. case REACT_SUSPENSE_TYPE:
  11831. return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
  11832. case REACT_SUSPENSE_LIST_TYPE:
  11833. return createFiberFromSuspenseList(pendingProps, mode, expirationTime, key);
  11834. default:
  11835. {
  11836. if (typeof type === 'object' && type !== null) {
  11837. switch (type.$$typeof) {
  11838. case REACT_PROVIDER_TYPE:
  11839. fiberTag = ContextProvider;
  11840. break getTag;
  11841. case REACT_CONTEXT_TYPE:
  11842. // This is a consumer
  11843. fiberTag = ContextConsumer;
  11844. break getTag;
  11845. case REACT_FORWARD_REF_TYPE:
  11846. fiberTag = ForwardRef;
  11847. {
  11848. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  11849. }
  11850. break getTag;
  11851. case REACT_MEMO_TYPE:
  11852. fiberTag = MemoComponent;
  11853. break getTag;
  11854. case REACT_LAZY_TYPE:
  11855. fiberTag = LazyComponent;
  11856. resolvedType = null;
  11857. break getTag;
  11858. case REACT_BLOCK_TYPE:
  11859. fiberTag = Block;
  11860. break getTag;
  11861. }
  11862. }
  11863. var info = '';
  11864. {
  11865. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  11866. 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.';
  11867. }
  11868. var ownerName = owner ? getComponentName(owner.type) : null;
  11869. if (ownerName) {
  11870. info += '\n\nCheck the render method of `' + ownerName + '`.';
  11871. }
  11872. }
  11873. {
  11874. {
  11875. 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 );
  11876. }
  11877. }
  11878. }
  11879. }
  11880. }
  11881. fiber = createFiber(fiberTag, pendingProps, key, mode);
  11882. fiber.elementType = type;
  11883. fiber.type = resolvedType;
  11884. fiber.expirationTime = expirationTime;
  11885. return fiber;
  11886. }
  11887. function createFiberFromElement(element, mode, expirationTime) {
  11888. var owner = null;
  11889. {
  11890. owner = element._owner;
  11891. }
  11892. var type = element.type;
  11893. var key = element.key;
  11894. var pendingProps = element.props;
  11895. var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
  11896. {
  11897. fiber._debugSource = element._source;
  11898. fiber._debugOwner = element._owner;
  11899. }
  11900. return fiber;
  11901. }
  11902. function createFiberFromFragment(elements, mode, expirationTime, key) {
  11903. var fiber = createFiber(Fragment, elements, key, mode);
  11904. fiber.expirationTime = expirationTime;
  11905. return fiber;
  11906. }
  11907. function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
  11908. {
  11909. if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
  11910. error('Profiler must specify an "id" string and "onRender" function as props');
  11911. }
  11912. }
  11913. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  11914. fiber.elementType = REACT_PROFILER_TYPE;
  11915. fiber.type = REACT_PROFILER_TYPE;
  11916. fiber.expirationTime = expirationTime;
  11917. return fiber;
  11918. }
  11919. function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
  11920. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  11921. // This needs to be fixed in getComponentName so that it relies on the tag
  11922. // instead.
  11923. fiber.type = REACT_SUSPENSE_TYPE;
  11924. fiber.elementType = REACT_SUSPENSE_TYPE;
  11925. fiber.expirationTime = expirationTime;
  11926. return fiber;
  11927. }
  11928. function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
  11929. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  11930. {
  11931. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  11932. // This needs to be fixed in getComponentName so that it relies on the tag
  11933. // instead.
  11934. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  11935. }
  11936. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  11937. fiber.expirationTime = expirationTime;
  11938. return fiber;
  11939. }
  11940. function createFiberFromText(content, mode, expirationTime) {
  11941. var fiber = createFiber(HostText, content, null, mode);
  11942. fiber.expirationTime = expirationTime;
  11943. return fiber;
  11944. }
  11945. function createFiberFromPortal(portal, mode, expirationTime) {
  11946. var pendingProps = portal.children !== null ? portal.children : [];
  11947. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  11948. fiber.expirationTime = expirationTime;
  11949. fiber.stateNode = {
  11950. containerInfo: portal.containerInfo,
  11951. pendingChildren: null,
  11952. // Used by persistent updates
  11953. implementation: portal.implementation
  11954. };
  11955. return fiber;
  11956. } // Used for stashing WIP properties to replay failed work in DEV.
  11957. function FiberRootNode(containerInfo, tag, hydrate) {
  11958. this.tag = tag;
  11959. this.current = null;
  11960. this.containerInfo = containerInfo;
  11961. this.pendingChildren = null;
  11962. this.pingCache = null;
  11963. this.finishedExpirationTime = NoWork;
  11964. this.finishedWork = null;
  11965. this.timeoutHandle = noTimeout;
  11966. this.context = null;
  11967. this.pendingContext = null;
  11968. this.hydrate = hydrate;
  11969. this.callbackNode = null;
  11970. this.callbackPriority = NoPriority;
  11971. this.firstPendingTime = NoWork;
  11972. this.firstSuspendedTime = NoWork;
  11973. this.lastSuspendedTime = NoWork;
  11974. this.nextKnownPendingLevel = NoWork;
  11975. this.lastPingedTime = NoWork;
  11976. this.lastExpiredTime = NoWork;
  11977. {
  11978. this.interactionThreadID = unstable_getThreadID();
  11979. this.memoizedInteractions = new Set();
  11980. this.pendingInteractionMap = new Map();
  11981. }
  11982. }
  11983. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  11984. var root = new FiberRootNode(containerInfo, tag, hydrate);
  11985. // stateNode is any.
  11986. var uninitializedFiber = createHostRootFiber(tag);
  11987. root.current = uninitializedFiber;
  11988. uninitializedFiber.stateNode = root;
  11989. initializeUpdateQueue(uninitializedFiber);
  11990. return root;
  11991. }
  11992. function isRootSuspendedAtTime(root, expirationTime) {
  11993. var firstSuspendedTime = root.firstSuspendedTime;
  11994. var lastSuspendedTime = root.lastSuspendedTime;
  11995. return firstSuspendedTime !== NoWork && firstSuspendedTime >= expirationTime && lastSuspendedTime <= expirationTime;
  11996. }
  11997. function markRootSuspendedAtTime(root, expirationTime) {
  11998. var firstSuspendedTime = root.firstSuspendedTime;
  11999. var lastSuspendedTime = root.lastSuspendedTime;
  12000. if (firstSuspendedTime < expirationTime) {
  12001. root.firstSuspendedTime = expirationTime;
  12002. }
  12003. if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
  12004. root.lastSuspendedTime = expirationTime;
  12005. }
  12006. if (expirationTime <= root.lastPingedTime) {
  12007. root.lastPingedTime = NoWork;
  12008. }
  12009. if (expirationTime <= root.lastExpiredTime) {
  12010. root.lastExpiredTime = NoWork;
  12011. }
  12012. }
  12013. function markRootUpdatedAtTime(root, expirationTime) {
  12014. // Update the range of pending times
  12015. var firstPendingTime = root.firstPendingTime;
  12016. if (expirationTime > firstPendingTime) {
  12017. root.firstPendingTime = expirationTime;
  12018. } // Update the range of suspended times. Treat everything lower priority or
  12019. // equal to this update as unsuspended.
  12020. var firstSuspendedTime = root.firstSuspendedTime;
  12021. if (firstSuspendedTime !== NoWork) {
  12022. if (expirationTime >= firstSuspendedTime) {
  12023. // The entire suspended range is now unsuspended.
  12024. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  12025. } else if (expirationTime >= root.lastSuspendedTime) {
  12026. root.lastSuspendedTime = expirationTime + 1;
  12027. } // This is a pending level. Check if it's higher priority than the next
  12028. // known pending level.
  12029. if (expirationTime > root.nextKnownPendingLevel) {
  12030. root.nextKnownPendingLevel = expirationTime;
  12031. }
  12032. }
  12033. }
  12034. function markRootFinishedAtTime(root, finishedExpirationTime, remainingExpirationTime) {
  12035. // Update the range of pending times
  12036. root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
  12037. // equal to this update as unsuspended.
  12038. if (finishedExpirationTime <= root.lastSuspendedTime) {
  12039. // The entire suspended range is now unsuspended.
  12040. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  12041. } else if (finishedExpirationTime <= root.firstSuspendedTime) {
  12042. // Part of the suspended range is now unsuspended. Narrow the range to
  12043. // include everything between the unsuspended time (non-inclusive) and the
  12044. // last suspended time.
  12045. root.firstSuspendedTime = finishedExpirationTime - 1;
  12046. }
  12047. if (finishedExpirationTime <= root.lastPingedTime) {
  12048. // Clear the pinged time
  12049. root.lastPingedTime = NoWork;
  12050. }
  12051. if (finishedExpirationTime <= root.lastExpiredTime) {
  12052. // Clear the expired time
  12053. root.lastExpiredTime = NoWork;
  12054. }
  12055. }
  12056. function markRootExpiredAtTime(root, expirationTime) {
  12057. var lastExpiredTime = root.lastExpiredTime;
  12058. if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
  12059. root.lastExpiredTime = expirationTime;
  12060. }
  12061. }
  12062. var didWarnAboutMessageChannel = false;
  12063. var enqueueTaskImpl = null;
  12064. function enqueueTask(task) {
  12065. if (enqueueTaskImpl === null) {
  12066. try {
  12067. // read require off the module object to get around the bundlers.
  12068. // we don't want them to detect a require and bundle a Node polyfill.
  12069. var requireString = ('require' + Math.random()).slice(0, 7);
  12070. var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
  12071. // version of setImmediate, bypassing fake timers if any.
  12072. enqueueTaskImpl = nodeRequire('timers').setImmediate;
  12073. } catch (_err) {
  12074. // we're in a browser
  12075. // we can't use regular timers because they may still be faked
  12076. // so we try MessageChannel+postMessage instead
  12077. enqueueTaskImpl = function (callback) {
  12078. {
  12079. if (didWarnAboutMessageChannel === false) {
  12080. didWarnAboutMessageChannel = true;
  12081. if (typeof MessageChannel === 'undefined') {
  12082. error('This browser does not have a MessageChannel implementation, ' + 'so enqueuing tasks via await act(async () => ...) will fail. ' + 'Please file an issue at https://github.com/facebook/react/issues ' + 'if you encounter this warning.');
  12083. }
  12084. }
  12085. }
  12086. var channel = new MessageChannel();
  12087. channel.port1.onmessage = callback;
  12088. channel.port2.postMessage(undefined);
  12089. };
  12090. }
  12091. }
  12092. return enqueueTaskImpl(task);
  12093. }
  12094. var didWarnAboutNestedUpdates;
  12095. {
  12096. didWarnAboutNestedUpdates = false;
  12097. }
  12098. function getContextForSubtree(parentComponent) {
  12099. if (!parentComponent) {
  12100. return emptyContextObject;
  12101. }
  12102. var fiber = get(parentComponent);
  12103. var parentContext = findCurrentUnmaskedContext(fiber);
  12104. if (fiber.tag === ClassComponent) {
  12105. var Component = fiber.type;
  12106. if (isContextProvider(Component)) {
  12107. return processChildContext(fiber, Component, parentContext);
  12108. }
  12109. }
  12110. return parentContext;
  12111. }
  12112. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  12113. return createFiberRoot(containerInfo, tag, hydrate);
  12114. }
  12115. function updateContainer(element, container, parentComponent, callback) {
  12116. {
  12117. onScheduleRoot(container, element);
  12118. }
  12119. var current$1 = container.current;
  12120. var currentTime = requestCurrentTimeForUpdate();
  12121. {
  12122. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  12123. if ('undefined' !== typeof jest) {
  12124. warnIfUnmockedScheduler(current$1);
  12125. warnIfNotScopedWithMatchingAct(current$1);
  12126. }
  12127. }
  12128. var suspenseConfig = requestCurrentSuspenseConfig();
  12129. var expirationTime = computeExpirationForFiber(currentTime, current$1, suspenseConfig);
  12130. var context = getContextForSubtree(parentComponent);
  12131. if (container.context === null) {
  12132. container.context = context;
  12133. } else {
  12134. container.pendingContext = context;
  12135. }
  12136. {
  12137. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  12138. didWarnAboutNestedUpdates = true;
  12139. 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');
  12140. }
  12141. }
  12142. var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
  12143. // being called "element".
  12144. update.payload = {
  12145. element: element
  12146. };
  12147. callback = callback === undefined ? null : callback;
  12148. if (callback !== null) {
  12149. {
  12150. if (typeof callback !== 'function') {
  12151. error('render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback);
  12152. }
  12153. }
  12154. update.callback = callback;
  12155. }
  12156. enqueueUpdate(current$1, update);
  12157. scheduleWork(current$1, expirationTime);
  12158. return expirationTime;
  12159. }
  12160. function getPublicRootInstance(container) {
  12161. var containerFiber = container.current;
  12162. if (!containerFiber.child) {
  12163. return null;
  12164. }
  12165. switch (containerFiber.child.tag) {
  12166. case HostComponent:
  12167. return getPublicInstance(containerFiber.child.stateNode);
  12168. default:
  12169. return containerFiber.child.stateNode;
  12170. }
  12171. }
  12172. var shouldSuspendImpl = function (fiber) {
  12173. return false;
  12174. };
  12175. function shouldSuspend(fiber) {
  12176. return shouldSuspendImpl(fiber);
  12177. }
  12178. var overrideHookState = null;
  12179. var overrideProps = null;
  12180. var scheduleUpdate = null;
  12181. var setSuspenseHandler = null;
  12182. {
  12183. var copyWithSetImpl = function (obj, path, idx, value) {
  12184. if (idx >= path.length) {
  12185. return value;
  12186. }
  12187. var key = path[idx];
  12188. var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
  12189. updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
  12190. return updated;
  12191. };
  12192. var copyWithSet = function (obj, path, value) {
  12193. return copyWithSetImpl(obj, path, 0, value);
  12194. }; // Support DevTools editable values for useState and useReducer.
  12195. overrideHookState = function (fiber, id, path, value) {
  12196. // For now, the "id" of stateful hooks is just the stateful hook index.
  12197. // This may change in the future with e.g. nested hooks.
  12198. var currentHook = fiber.memoizedState;
  12199. while (currentHook !== null && id > 0) {
  12200. currentHook = currentHook.next;
  12201. id--;
  12202. }
  12203. if (currentHook !== null) {
  12204. var newState = copyWithSet(currentHook.memoizedState, path, value);
  12205. currentHook.memoizedState = newState;
  12206. currentHook.baseState = newState; // We aren't actually adding an update to the queue,
  12207. // because there is no update we can add for useReducer hooks that won't trigger an error.
  12208. // (There's no appropriate action type for DevTools overrides.)
  12209. // As a result though, React will see the scheduled update as a noop and bailout.
  12210. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  12211. fiber.memoizedProps = _assign({}, fiber.memoizedProps);
  12212. scheduleWork(fiber, Sync);
  12213. }
  12214. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  12215. overrideProps = function (fiber, path, value) {
  12216. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  12217. if (fiber.alternate) {
  12218. fiber.alternate.pendingProps = fiber.pendingProps;
  12219. }
  12220. scheduleWork(fiber, Sync);
  12221. };
  12222. scheduleUpdate = function (fiber) {
  12223. scheduleWork(fiber, Sync);
  12224. };
  12225. setSuspenseHandler = function (newShouldSuspendImpl) {
  12226. shouldSuspendImpl = newShouldSuspendImpl;
  12227. };
  12228. }
  12229. function injectIntoDevTools(devToolsConfig) {
  12230. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  12231. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  12232. return injectInternals(_assign({}, devToolsConfig, {
  12233. overrideHookState: overrideHookState,
  12234. overrideProps: overrideProps,
  12235. setSuspenseHandler: setSuspenseHandler,
  12236. scheduleUpdate: scheduleUpdate,
  12237. currentDispatcherRef: ReactCurrentDispatcher,
  12238. findHostInstanceByFiber: function (fiber) {
  12239. var hostFiber = findCurrentHostFiber(fiber);
  12240. if (hostFiber === null) {
  12241. return null;
  12242. }
  12243. return hostFiber.stateNode;
  12244. },
  12245. findFiberByHostInstance: function (instance) {
  12246. if (!findFiberByHostInstance) {
  12247. // Might not be implemented by the renderer.
  12248. return null;
  12249. }
  12250. return findFiberByHostInstance(instance);
  12251. },
  12252. // React Refresh
  12253. findHostInstancesForRefresh: findHostInstancesForRefresh ,
  12254. scheduleRefresh: scheduleRefresh ,
  12255. scheduleRoot: scheduleRoot ,
  12256. setRefreshHandler: setRefreshHandler ,
  12257. // Enables DevTools to append owner stacks to error messages in DEV mode.
  12258. getCurrentFiber: function () {
  12259. return current;
  12260. }
  12261. }));
  12262. }
  12263. var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing;
  12264. var isSchedulerMocked = typeof Scheduler$1.unstable_flushAllWithoutAsserting === 'function';
  12265. var flushWork = Scheduler$1.unstable_flushAllWithoutAsserting || function () {
  12266. var didFlushWork = false;
  12267. while (flushPassiveEffects()) {
  12268. didFlushWork = true;
  12269. }
  12270. return didFlushWork;
  12271. };
  12272. function flushWorkAndMicroTasks(onDone) {
  12273. try {
  12274. flushWork();
  12275. enqueueTask(function () {
  12276. if (flushWork()) {
  12277. flushWorkAndMicroTasks(onDone);
  12278. } else {
  12279. onDone();
  12280. }
  12281. });
  12282. } catch (err) {
  12283. onDone(err);
  12284. }
  12285. } // we track the 'depth' of the act() calls with this counter,
  12286. // so we can tell if any async act() calls try to run in parallel.
  12287. var actingUpdatesScopeDepth = 0;
  12288. function act(callback) {
  12289. var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
  12290. var previousIsSomeRendererActing;
  12291. var previousIsThisRendererActing;
  12292. actingUpdatesScopeDepth++;
  12293. previousIsSomeRendererActing = IsSomeRendererActing$1.current;
  12294. previousIsThisRendererActing = IsThisRendererActing.current;
  12295. IsSomeRendererActing$1.current = true;
  12296. IsThisRendererActing.current = true;
  12297. function onDone() {
  12298. actingUpdatesScopeDepth--;
  12299. IsSomeRendererActing$1.current = previousIsSomeRendererActing;
  12300. IsThisRendererActing.current = previousIsThisRendererActing;
  12301. {
  12302. if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
  12303. // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
  12304. error('You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
  12305. }
  12306. }
  12307. }
  12308. var result;
  12309. try {
  12310. result = batchedUpdates(callback);
  12311. } catch (error) {
  12312. // on sync errors, we still want to 'cleanup' and decrement actingUpdatesScopeDepth
  12313. onDone();
  12314. throw error;
  12315. }
  12316. if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
  12317. // setup a boolean that gets set to true only
  12318. // once this act() call is await-ed
  12319. var called = false;
  12320. {
  12321. if (typeof Promise !== 'undefined') {
  12322. //eslint-disable-next-line no-undef
  12323. Promise.resolve().then(function () {}).then(function () {
  12324. if (called === false) {
  12325. error('You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, interleaving multiple act ' + 'calls and mixing their scopes. You should - await act(async () => ...);');
  12326. }
  12327. });
  12328. }
  12329. } // in the async case, the returned thenable runs the callback, flushes
  12330. // effects and microtasks in a loop until flushPassiveEffects() === false,
  12331. // and cleans up
  12332. return {
  12333. then: function (resolve, reject) {
  12334. called = true;
  12335. result.then(function () {
  12336. if (actingUpdatesScopeDepth > 1 || isSchedulerMocked === true && previousIsSomeRendererActing === true) {
  12337. onDone();
  12338. resolve();
  12339. return;
  12340. } // we're about to exit the act() scope,
  12341. // now's the time to flush tasks/effects
  12342. flushWorkAndMicroTasks(function (err) {
  12343. onDone();
  12344. if (err) {
  12345. reject(err);
  12346. } else {
  12347. resolve();
  12348. }
  12349. });
  12350. }, function (err) {
  12351. onDone();
  12352. reject(err);
  12353. });
  12354. }
  12355. };
  12356. } else {
  12357. {
  12358. if (result !== undefined) {
  12359. error('The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result);
  12360. }
  12361. } // flush effects until none remain, and cleanup
  12362. try {
  12363. if (actingUpdatesScopeDepth === 1 && (isSchedulerMocked === false || previousIsSomeRendererActing === false)) {
  12364. // we're about to exit the act() scope,
  12365. // now's the time to flush effects
  12366. flushWork();
  12367. }
  12368. onDone();
  12369. } catch (err) {
  12370. onDone();
  12371. throw err;
  12372. } // in the sync case, the returned thenable only warns *if* await-ed
  12373. return {
  12374. then: function (resolve) {
  12375. {
  12376. error('Do not await the result of calling act(...) with sync logic, it is not a Promise.');
  12377. }
  12378. resolve();
  12379. }
  12380. };
  12381. }
  12382. }
  12383. var ReactVersion = '16.13.1';
  12384. var defaultTestOptions = {
  12385. createNodeMock: function () {
  12386. return null;
  12387. }
  12388. };
  12389. function toJSON(inst) {
  12390. if (inst.isHidden) {
  12391. // Omit timed out children from output entirely. This seems like the least
  12392. // surprising behavior. We could perhaps add a separate API that includes
  12393. // them, if it turns out people need it.
  12394. return null;
  12395. }
  12396. switch (inst.tag) {
  12397. case 'TEXT':
  12398. return inst.text;
  12399. case 'INSTANCE':
  12400. {
  12401. /* eslint-disable no-unused-vars */
  12402. // We don't include the `children` prop in JSON.
  12403. // Instead, we will include the actual rendered children.
  12404. var _inst$props = inst.props,
  12405. children = _inst$props.children,
  12406. props = _objectWithoutPropertiesLoose(_inst$props, ["children"]);
  12407. /* eslint-enable */
  12408. var renderedChildren = null;
  12409. if (inst.children && inst.children.length) {
  12410. for (var i = 0; i < inst.children.length; i++) {
  12411. var renderedChild = toJSON(inst.children[i]);
  12412. if (renderedChild !== null) {
  12413. if (renderedChildren === null) {
  12414. renderedChildren = [renderedChild];
  12415. } else {
  12416. renderedChildren.push(renderedChild);
  12417. }
  12418. }
  12419. }
  12420. }
  12421. var json = {
  12422. type: inst.type,
  12423. props: props,
  12424. children: renderedChildren
  12425. };
  12426. Object.defineProperty(json, '$$typeof', {
  12427. value: Symbol.for('react.test.json')
  12428. });
  12429. return json;
  12430. }
  12431. default:
  12432. throw new Error("Unexpected node type in toJSON: " + inst.tag);
  12433. }
  12434. }
  12435. function childrenToTree(node) {
  12436. if (!node) {
  12437. return null;
  12438. }
  12439. var children = nodeAndSiblingsArray(node);
  12440. if (children.length === 0) {
  12441. return null;
  12442. } else if (children.length === 1) {
  12443. return toTree(children[0]);
  12444. }
  12445. return flatten(children.map(toTree));
  12446. }
  12447. function nodeAndSiblingsArray(nodeWithSibling) {
  12448. var array = [];
  12449. var node = nodeWithSibling;
  12450. while (node != null) {
  12451. array.push(node);
  12452. node = node.sibling;
  12453. }
  12454. return array;
  12455. }
  12456. function flatten(arr) {
  12457. var result = [];
  12458. var stack = [{
  12459. i: 0,
  12460. array: arr
  12461. }];
  12462. while (stack.length) {
  12463. var n = stack.pop();
  12464. while (n.i < n.array.length) {
  12465. var el = n.array[n.i];
  12466. n.i += 1;
  12467. if (Array.isArray(el)) {
  12468. stack.push(n);
  12469. stack.push({
  12470. i: 0,
  12471. array: el
  12472. });
  12473. break;
  12474. }
  12475. result.push(el);
  12476. }
  12477. }
  12478. return result;
  12479. }
  12480. function toTree(node) {
  12481. if (node == null) {
  12482. return null;
  12483. }
  12484. switch (node.tag) {
  12485. case HostRoot:
  12486. return childrenToTree(node.child);
  12487. case HostPortal:
  12488. return childrenToTree(node.child);
  12489. case ClassComponent:
  12490. return {
  12491. nodeType: 'component',
  12492. type: node.type,
  12493. props: _assign({}, node.memoizedProps),
  12494. instance: node.stateNode,
  12495. rendered: childrenToTree(node.child)
  12496. };
  12497. case FunctionComponent:
  12498. case SimpleMemoComponent:
  12499. return {
  12500. nodeType: 'component',
  12501. type: node.type,
  12502. props: _assign({}, node.memoizedProps),
  12503. instance: null,
  12504. rendered: childrenToTree(node.child)
  12505. };
  12506. case Block:
  12507. return {
  12508. nodeType: 'block',
  12509. type: node.type,
  12510. props: _assign({}, node.memoizedProps),
  12511. instance: null,
  12512. rendered: childrenToTree(node.child)
  12513. };
  12514. case HostComponent:
  12515. {
  12516. return {
  12517. nodeType: 'host',
  12518. type: node.type,
  12519. props: _assign({}, node.memoizedProps),
  12520. instance: null,
  12521. // TODO: use createNodeMock here somehow?
  12522. rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
  12523. };
  12524. }
  12525. case HostText:
  12526. return node.stateNode.text;
  12527. case Fragment:
  12528. case ContextProvider:
  12529. case ContextConsumer:
  12530. case Mode:
  12531. case Profiler:
  12532. case ForwardRef:
  12533. case MemoComponent:
  12534. case IncompleteClassComponent:
  12535. case ScopeComponent:
  12536. return childrenToTree(node.child);
  12537. default:
  12538. {
  12539. {
  12540. throw Error( "toTree() does not yet know how to handle nodes with tag=" + node.tag );
  12541. }
  12542. }
  12543. }
  12544. }
  12545. var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent, Block, // Normally skipped, but used when there's more than one root child.
  12546. HostRoot]);
  12547. function getChildren(parent) {
  12548. var children = [];
  12549. var startingNode = parent;
  12550. var node = startingNode;
  12551. if (node.child === null) {
  12552. return children;
  12553. }
  12554. node.child.return = node;
  12555. node = node.child;
  12556. outer: while (true) {
  12557. var descend = false;
  12558. if (validWrapperTypes.has(node.tag)) {
  12559. children.push(wrapFiber(node));
  12560. } else if (node.tag === HostText) {
  12561. children.push('' + node.memoizedProps);
  12562. } else {
  12563. descend = true;
  12564. }
  12565. if (descend && node.child !== null) {
  12566. node.child.return = node;
  12567. node = node.child;
  12568. continue;
  12569. }
  12570. while (node.sibling === null) {
  12571. if (node.return === startingNode) {
  12572. break outer;
  12573. }
  12574. node = node.return;
  12575. }
  12576. node.sibling.return = node.return;
  12577. node = node.sibling;
  12578. }
  12579. return children;
  12580. }
  12581. var ReactTestInstance =
  12582. /*#__PURE__*/
  12583. function () {
  12584. var _proto = ReactTestInstance.prototype;
  12585. _proto._currentFiber = function _currentFiber() {
  12586. // Throws if this component has been unmounted.
  12587. var fiber = findCurrentFiberUsingSlowPath(this._fiber);
  12588. if (!(fiber !== null)) {
  12589. {
  12590. throw Error( "Can't read from currently-mounting component. This error is likely caused by a bug in React. Please file an issue." );
  12591. }
  12592. }
  12593. return fiber;
  12594. };
  12595. function ReactTestInstance(fiber) {
  12596. if (!validWrapperTypes.has(fiber.tag)) {
  12597. {
  12598. throw Error( "Unexpected object passed to ReactTestInstance constructor (tag: " + fiber.tag + "). This is probably a bug in React." );
  12599. }
  12600. }
  12601. this._fiber = fiber;
  12602. }
  12603. // Custom search functions
  12604. _proto.find = function find(predicate) {
  12605. return expectOne(this.findAll(predicate, {
  12606. deep: false
  12607. }), "matching custom predicate: " + predicate.toString());
  12608. };
  12609. _proto.findByType = function findByType(type) {
  12610. return expectOne(this.findAllByType(type, {
  12611. deep: false
  12612. }), "with node type: \"" + (type.displayName || type.name) + "\"");
  12613. };
  12614. _proto.findByProps = function findByProps(props) {
  12615. return expectOne(this.findAllByProps(props, {
  12616. deep: false
  12617. }), "with props: " + JSON.stringify(props));
  12618. };
  12619. _proto.findAll = function findAll(predicate) {
  12620. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12621. return _findAll(this, predicate, options);
  12622. };
  12623. _proto.findAllByType = function findAllByType(type) {
  12624. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12625. return _findAll(this, function (node) {
  12626. return node.type === type;
  12627. }, options);
  12628. };
  12629. _proto.findAllByProps = function findAllByProps(props) {
  12630. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12631. return _findAll(this, function (node) {
  12632. return node.props && propsMatch(node.props, props);
  12633. }, options);
  12634. };
  12635. _createClass(ReactTestInstance, [{
  12636. key: "instance",
  12637. get: function () {
  12638. if (this._fiber.tag === HostComponent) {
  12639. return getPublicInstance(this._fiber.stateNode);
  12640. } else {
  12641. return this._fiber.stateNode;
  12642. }
  12643. }
  12644. }, {
  12645. key: "type",
  12646. get: function () {
  12647. return this._fiber.type;
  12648. }
  12649. }, {
  12650. key: "props",
  12651. get: function () {
  12652. return this._currentFiber().memoizedProps;
  12653. }
  12654. }, {
  12655. key: "parent",
  12656. get: function () {
  12657. var parent = this._fiber.return;
  12658. while (parent !== null) {
  12659. if (validWrapperTypes.has(parent.tag)) {
  12660. if (parent.tag === HostRoot) {
  12661. // Special case: we only "materialize" instances for roots
  12662. // if they have more than a single child. So we'll check that now.
  12663. if (getChildren(parent).length < 2) {
  12664. return null;
  12665. }
  12666. }
  12667. return wrapFiber(parent);
  12668. }
  12669. parent = parent.return;
  12670. }
  12671. return null;
  12672. }
  12673. }, {
  12674. key: "children",
  12675. get: function () {
  12676. return getChildren(this._currentFiber());
  12677. }
  12678. }]);
  12679. return ReactTestInstance;
  12680. }();
  12681. function _findAll(root, predicate, options) {
  12682. var deep = options ? options.deep : true;
  12683. var results = [];
  12684. if (predicate(root)) {
  12685. results.push(root);
  12686. if (!deep) {
  12687. return results;
  12688. }
  12689. }
  12690. root.children.forEach(function (child) {
  12691. if (typeof child === 'string') {
  12692. return;
  12693. }
  12694. results.push.apply(results, _findAll(child, predicate, options));
  12695. });
  12696. return results;
  12697. }
  12698. function expectOne(all, message) {
  12699. if (all.length === 1) {
  12700. return all[0];
  12701. }
  12702. var prefix = all.length === 0 ? 'No instances found ' : "Expected 1 but found " + all.length + " instances ";
  12703. throw new Error(prefix + message);
  12704. }
  12705. function propsMatch(props, filter) {
  12706. for (var key in filter) {
  12707. if (props[key] !== filter[key]) {
  12708. return false;
  12709. }
  12710. }
  12711. return true;
  12712. }
  12713. var ReactTestRendererFiber = {
  12714. _Scheduler: Scheduler,
  12715. create: function (element, options) {
  12716. var createNodeMock = defaultTestOptions.createNodeMock;
  12717. var isConcurrent = false;
  12718. if (typeof options === 'object' && options !== null) {
  12719. if (typeof options.createNodeMock === 'function') {
  12720. createNodeMock = options.createNodeMock;
  12721. }
  12722. if (options.unstable_isConcurrent === true) {
  12723. isConcurrent = true;
  12724. }
  12725. }
  12726. var container = {
  12727. children: [],
  12728. createNodeMock: createNodeMock,
  12729. tag: 'CONTAINER'
  12730. };
  12731. var root = createContainer(container, isConcurrent ? ConcurrentRoot : LegacyRoot, false);
  12732. if (!(root != null)) {
  12733. {
  12734. throw Error( "something went wrong" );
  12735. }
  12736. }
  12737. updateContainer(element, root, null, null);
  12738. var entry = {
  12739. _Scheduler: Scheduler,
  12740. root: undefined,
  12741. // makes flow happy
  12742. // we define a 'getter' for 'root' below using 'Object.defineProperty'
  12743. toJSON: function () {
  12744. if (root == null || root.current == null || container == null) {
  12745. return null;
  12746. }
  12747. if (container.children.length === 0) {
  12748. return null;
  12749. }
  12750. if (container.children.length === 1) {
  12751. return toJSON(container.children[0]);
  12752. }
  12753. if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
  12754. // Omit timed out children from output entirely, including the fact that we
  12755. // temporarily wrap fallback and timed out children in an array.
  12756. return toJSON(container.children[1]);
  12757. }
  12758. var renderedChildren = null;
  12759. if (container.children && container.children.length) {
  12760. for (var i = 0; i < container.children.length; i++) {
  12761. var renderedChild = toJSON(container.children[i]);
  12762. if (renderedChild !== null) {
  12763. if (renderedChildren === null) {
  12764. renderedChildren = [renderedChild];
  12765. } else {
  12766. renderedChildren.push(renderedChild);
  12767. }
  12768. }
  12769. }
  12770. }
  12771. return renderedChildren;
  12772. },
  12773. toTree: function () {
  12774. if (root == null || root.current == null) {
  12775. return null;
  12776. }
  12777. return toTree(root.current);
  12778. },
  12779. update: function (newElement) {
  12780. if (root == null || root.current == null) {
  12781. return;
  12782. }
  12783. updateContainer(newElement, root, null, null);
  12784. },
  12785. unmount: function () {
  12786. if (root == null || root.current == null) {
  12787. return;
  12788. }
  12789. updateContainer(null, root, null, null);
  12790. container = null;
  12791. root = null;
  12792. },
  12793. getInstance: function () {
  12794. if (root == null || root.current == null) {
  12795. return null;
  12796. }
  12797. return getPublicRootInstance(root);
  12798. },
  12799. unstable_flushSync: function (fn) {
  12800. return flushSync(fn);
  12801. }
  12802. };
  12803. Object.defineProperty(entry, 'root', {
  12804. configurable: true,
  12805. enumerable: true,
  12806. get: function () {
  12807. if (root === null) {
  12808. throw new Error("Can't access .root on unmounted test renderer");
  12809. }
  12810. var children = getChildren(root.current);
  12811. if (children.length === 0) {
  12812. throw new Error("Can't access .root on unmounted test renderer");
  12813. } else if (children.length === 1) {
  12814. // Normally, we skip the root and just give you the child.
  12815. return children[0];
  12816. } else {
  12817. // However, we give you the root if there's more than one root child.
  12818. // We could make this the behavior for all cases but it would be a breaking change.
  12819. return wrapFiber(root.current);
  12820. }
  12821. }
  12822. });
  12823. return entry;
  12824. },
  12825. /* eslint-disable-next-line camelcase */
  12826. unstable_batchedUpdates: batchedUpdates,
  12827. act: act
  12828. };
  12829. var fiberToWrapper = new WeakMap();
  12830. function wrapFiber(fiber) {
  12831. var wrapper = fiberToWrapper.get(fiber);
  12832. if (wrapper === undefined && fiber.alternate !== null) {
  12833. wrapper = fiberToWrapper.get(fiber.alternate);
  12834. }
  12835. if (wrapper === undefined) {
  12836. wrapper = new ReactTestInstance(fiber);
  12837. fiberToWrapper.set(fiber, wrapper);
  12838. }
  12839. return wrapper;
  12840. } // Enable ReactTestRenderer to be used to test DevTools integration.
  12841. injectIntoDevTools({
  12842. findFiberByHostInstance: function () {
  12843. throw new Error('TestRenderer does not support findFiberByHostInstance()');
  12844. },
  12845. bundleType: 1 ,
  12846. version: ReactVersion,
  12847. rendererPackageName: 'react-test-renderer'
  12848. });
  12849. // TODO: decide on the top-level export form.
  12850. // This is hacky but makes it work with both Rollup and Jest.
  12851. var reactTestRenderer = ReactTestRendererFiber.default || ReactTestRendererFiber;
  12852. return reactTestRenderer;
  12853. })));