react-test-renderer.development.js 525 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596
  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. if (process.env.NODE_ENV !== "production") {
  11. (function() {
  12. 'use strict';
  13. var _assign = require('object-assign');
  14. var Scheduler = require('scheduler/unstable_mock');
  15. var React = require('react');
  16. var checkPropTypes = require('prop-types/checkPropTypes');
  17. var Scheduler$1 = require('scheduler');
  18. var tracing = require('scheduler/tracing');
  19. function _defineProperties(target, props) {
  20. for (var i = 0; i < props.length; i++) {
  21. var descriptor = props[i];
  22. descriptor.enumerable = descriptor.enumerable || false;
  23. descriptor.configurable = true;
  24. if ("value" in descriptor) descriptor.writable = true;
  25. Object.defineProperty(target, descriptor.key, descriptor);
  26. }
  27. }
  28. function _createClass(Constructor, protoProps, staticProps) {
  29. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30. if (staticProps) _defineProperties(Constructor, staticProps);
  31. return Constructor;
  32. }
  33. function _objectWithoutPropertiesLoose(source, excluded) {
  34. if (source == null) return {};
  35. var target = {};
  36. var sourceKeys = Object.keys(source);
  37. var key, i;
  38. for (i = 0; i < sourceKeys.length; i++) {
  39. key = sourceKeys[i];
  40. if (excluded.indexOf(key) >= 0) continue;
  41. target[key] = source[key];
  42. }
  43. return target;
  44. }
  45. 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.
  46. // Current owner and dispatcher used to share the same ref,
  47. // but PR #14548 split them out to better support the react-debug-tools package.
  48. if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
  49. ReactSharedInternals.ReactCurrentDispatcher = {
  50. current: null
  51. };
  52. }
  53. if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
  54. ReactSharedInternals.ReactCurrentBatchConfig = {
  55. suspense: null
  56. };
  57. }
  58. // by calls to these methods by a Babel plugin.
  59. //
  60. // In PROD (or in packages without access to React internals),
  61. // they are left as they are instead.
  62. function warn(format) {
  63. {
  64. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  65. args[_key - 1] = arguments[_key];
  66. }
  67. printWarning('warn', format, args);
  68. }
  69. }
  70. function error(format) {
  71. {
  72. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  73. args[_key2 - 1] = arguments[_key2];
  74. }
  75. printWarning('error', format, args);
  76. }
  77. }
  78. function printWarning(level, format, args) {
  79. // When changing this logic, you might want to also
  80. // update consoleWithStackDev.www.js as well.
  81. {
  82. var hasExistingStack = args.length > 0 && typeof args[args.length - 1] === 'string' && args[args.length - 1].indexOf('\n in') === 0;
  83. if (!hasExistingStack) {
  84. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  85. var stack = ReactDebugCurrentFrame.getStackAddendum();
  86. if (stack !== '') {
  87. format += '%s';
  88. args = args.concat([stack]);
  89. }
  90. }
  91. var argsWithFormat = args.map(function (item) {
  92. return '' + item;
  93. }); // Careful: RN currently depends on this prefix
  94. argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
  95. // breaks IE9: https://github.com/facebook/react/issues/13610
  96. // eslint-disable-next-line react-internal/no-production-logging
  97. Function.prototype.apply.call(console[level], console, argsWithFormat);
  98. try {
  99. // --- Welcome to debugging React ---
  100. // This error was thrown as a convenience so that you can use this stack
  101. // to find the callsite that caused this warning to fire.
  102. var argIndex = 0;
  103. var message = 'Warning: ' + format.replace(/%s/g, function () {
  104. return args[argIndex++];
  105. });
  106. throw new Error(message);
  107. } catch (x) {}
  108. }
  109. }
  110. var FunctionComponent = 0;
  111. var ClassComponent = 1;
  112. var IndeterminateComponent = 2; // Before we know whether it is function or class
  113. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  114. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  115. var HostComponent = 5;
  116. var HostText = 6;
  117. var Fragment = 7;
  118. var Mode = 8;
  119. var ContextConsumer = 9;
  120. var ContextProvider = 10;
  121. var ForwardRef = 11;
  122. var Profiler = 12;
  123. var SuspenseComponent = 13;
  124. var MemoComponent = 14;
  125. var SimpleMemoComponent = 15;
  126. var LazyComponent = 16;
  127. var IncompleteClassComponent = 17;
  128. var DehydratedFragment = 18;
  129. var SuspenseListComponent = 19;
  130. var FundamentalComponent = 20;
  131. var ScopeComponent = 21;
  132. var Block = 22;
  133. /**
  134. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  135. * instance (key) and the internal representation (value). This allows public
  136. * methods to accept the user facing instance as an argument and map them back
  137. * to internal methods.
  138. *
  139. * Note that this module is currently shared and assumed to be stateless.
  140. * If this becomes an actual Map, that will break.
  141. */
  142. function get(key) {
  143. return key._reactInternalFiber;
  144. }
  145. function set(key, value) {
  146. key._reactInternalFiber = value;
  147. }
  148. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  149. // nor polyfill, then a plain number is used for performance.
  150. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  151. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  152. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
  153. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
  154. var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
  155. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
  156. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
  157. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  158. var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
  159. var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
  160. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
  161. var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
  162. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
  163. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
  164. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
  165. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  166. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  167. function getIteratorFn(maybeIterable) {
  168. if (maybeIterable === null || typeof maybeIterable !== 'object') {
  169. return null;
  170. }
  171. var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
  172. if (typeof maybeIterator === 'function') {
  173. return maybeIterator;
  174. }
  175. return null;
  176. }
  177. var Uninitialized = -1;
  178. var Pending = 0;
  179. var Resolved = 1;
  180. var Rejected = 2;
  181. function refineResolvedLazyComponent(lazyComponent) {
  182. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  183. }
  184. function initializeLazyComponentType(lazyComponent) {
  185. if (lazyComponent._status === Uninitialized) {
  186. lazyComponent._status = Pending;
  187. var ctor = lazyComponent._ctor;
  188. var thenable = ctor();
  189. lazyComponent._result = thenable;
  190. thenable.then(function (moduleObject) {
  191. if (lazyComponent._status === Pending) {
  192. var defaultExport = moduleObject.default;
  193. {
  194. if (defaultExport === undefined) {
  195. 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);
  196. }
  197. }
  198. lazyComponent._status = Resolved;
  199. lazyComponent._result = defaultExport;
  200. }
  201. }, function (error) {
  202. if (lazyComponent._status === Pending) {
  203. lazyComponent._status = Rejected;
  204. lazyComponent._result = error;
  205. }
  206. });
  207. }
  208. }
  209. function getWrappedName(outerType, innerType, wrapperName) {
  210. var functionName = innerType.displayName || innerType.name || '';
  211. return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
  212. }
  213. function getComponentName(type) {
  214. if (type == null) {
  215. // Host root, text node or just invalid type.
  216. return null;
  217. }
  218. {
  219. if (typeof type.tag === 'number') {
  220. error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
  221. }
  222. }
  223. if (typeof type === 'function') {
  224. return type.displayName || type.name || null;
  225. }
  226. if (typeof type === 'string') {
  227. return type;
  228. }
  229. switch (type) {
  230. case REACT_FRAGMENT_TYPE:
  231. return 'Fragment';
  232. case REACT_PORTAL_TYPE:
  233. return 'Portal';
  234. case REACT_PROFILER_TYPE:
  235. return "Profiler";
  236. case REACT_STRICT_MODE_TYPE:
  237. return 'StrictMode';
  238. case REACT_SUSPENSE_TYPE:
  239. return 'Suspense';
  240. case REACT_SUSPENSE_LIST_TYPE:
  241. return 'SuspenseList';
  242. }
  243. if (typeof type === 'object') {
  244. switch (type.$$typeof) {
  245. case REACT_CONTEXT_TYPE:
  246. return 'Context.Consumer';
  247. case REACT_PROVIDER_TYPE:
  248. return 'Context.Provider';
  249. case REACT_FORWARD_REF_TYPE:
  250. return getWrappedName(type, type.render, 'ForwardRef');
  251. case REACT_MEMO_TYPE:
  252. return getComponentName(type.type);
  253. case REACT_BLOCK_TYPE:
  254. return getComponentName(type.render);
  255. case REACT_LAZY_TYPE:
  256. {
  257. var thenable = type;
  258. var resolvedThenable = refineResolvedLazyComponent(thenable);
  259. if (resolvedThenable) {
  260. return getComponentName(resolvedThenable);
  261. }
  262. break;
  263. }
  264. }
  265. }
  266. return null;
  267. }
  268. // Don't change these two values. They're used by React Dev Tools.
  269. var NoEffect =
  270. /* */
  271. 0;
  272. var PerformedWork =
  273. /* */
  274. 1; // You can change the rest (and add more).
  275. var Placement =
  276. /* */
  277. 2;
  278. var Update =
  279. /* */
  280. 4;
  281. var PlacementAndUpdate =
  282. /* */
  283. 6;
  284. var Deletion =
  285. /* */
  286. 8;
  287. var ContentReset =
  288. /* */
  289. 16;
  290. var Callback =
  291. /* */
  292. 32;
  293. var DidCapture =
  294. /* */
  295. 64;
  296. var Ref =
  297. /* */
  298. 128;
  299. var Snapshot =
  300. /* */
  301. 256;
  302. var Passive =
  303. /* */
  304. 512;
  305. var Hydrating =
  306. /* */
  307. 1024;
  308. var HydratingAndUpdate =
  309. /* */
  310. 1028; // Passive & Update & Callback & Ref & Snapshot
  311. var LifecycleEffectMask =
  312. /* */
  313. 932; // Union of all host effects
  314. var HostEffectMask =
  315. /* */
  316. 2047;
  317. var Incomplete =
  318. /* */
  319. 2048;
  320. var ShouldCapture =
  321. /* */
  322. 4096;
  323. var enableProfilerTimer = true;
  324. var enableFundamentalAPI = false;
  325. var warnAboutStringRefs = false;
  326. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  327. function getNearestMountedFiber(fiber) {
  328. var node = fiber;
  329. var nearestMounted = fiber;
  330. if (!fiber.alternate) {
  331. // If there is no alternate, this might be a new tree that isn't inserted
  332. // yet. If it is, then it will have a pending insertion effect on it.
  333. var nextNode = node;
  334. do {
  335. node = nextNode;
  336. if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
  337. // This is an insertion or in-progress hydration. The nearest possible
  338. // mounted fiber is the parent but we need to continue to figure out
  339. // if that one is still mounted.
  340. nearestMounted = node.return;
  341. }
  342. nextNode = node.return;
  343. } while (nextNode);
  344. } else {
  345. while (node.return) {
  346. node = node.return;
  347. }
  348. }
  349. if (node.tag === HostRoot) {
  350. // TODO: Check if this was a nested HostRoot when used with
  351. // renderContainerIntoSubtree.
  352. return nearestMounted;
  353. } // If we didn't hit the root, that means that we're in an disconnected tree
  354. // that has been unmounted.
  355. return null;
  356. }
  357. function isFiberMounted(fiber) {
  358. return getNearestMountedFiber(fiber) === fiber;
  359. }
  360. function isMounted(component) {
  361. {
  362. var owner = ReactCurrentOwner.current;
  363. if (owner !== null && owner.tag === ClassComponent) {
  364. var ownerFiber = owner;
  365. var instance = ownerFiber.stateNode;
  366. if (!instance._warnedAboutRefsInRender) {
  367. 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');
  368. }
  369. instance._warnedAboutRefsInRender = true;
  370. }
  371. }
  372. var fiber = get(component);
  373. if (!fiber) {
  374. return false;
  375. }
  376. return getNearestMountedFiber(fiber) === fiber;
  377. }
  378. function assertIsMounted(fiber) {
  379. if (!(getNearestMountedFiber(fiber) === fiber)) {
  380. {
  381. throw Error( "Unable to find node on an unmounted component." );
  382. }
  383. }
  384. }
  385. function findCurrentFiberUsingSlowPath(fiber) {
  386. var alternate = fiber.alternate;
  387. if (!alternate) {
  388. // If there is no alternate, then we only need to check if it is mounted.
  389. var nearestMounted = getNearestMountedFiber(fiber);
  390. if (!(nearestMounted !== null)) {
  391. {
  392. throw Error( "Unable to find node on an unmounted component." );
  393. }
  394. }
  395. if (nearestMounted !== fiber) {
  396. return null;
  397. }
  398. return fiber;
  399. } // If we have two possible branches, we'll walk backwards up to the root
  400. // to see what path the root points to. On the way we may hit one of the
  401. // special cases and we'll deal with them.
  402. var a = fiber;
  403. var b = alternate;
  404. while (true) {
  405. var parentA = a.return;
  406. if (parentA === null) {
  407. // We're at the root.
  408. break;
  409. }
  410. var parentB = parentA.alternate;
  411. if (parentB === null) {
  412. // There is no alternate. This is an unusual case. Currently, it only
  413. // happens when a Suspense component is hidden. An extra fragment fiber
  414. // is inserted in between the Suspense fiber and its children. Skip
  415. // over this extra fragment fiber and proceed to the next parent.
  416. var nextParent = parentA.return;
  417. if (nextParent !== null) {
  418. a = b = nextParent;
  419. continue;
  420. } // If there's no parent, we're at the root.
  421. break;
  422. } // If both copies of the parent fiber point to the same child, we can
  423. // assume that the child is current. This happens when we bailout on low
  424. // priority: the bailed out fiber's child reuses the current child.
  425. if (parentA.child === parentB.child) {
  426. var child = parentA.child;
  427. while (child) {
  428. if (child === a) {
  429. // We've determined that A is the current branch.
  430. assertIsMounted(parentA);
  431. return fiber;
  432. }
  433. if (child === b) {
  434. // We've determined that B is the current branch.
  435. assertIsMounted(parentA);
  436. return alternate;
  437. }
  438. child = child.sibling;
  439. } // We should never have an alternate for any mounting node. So the only
  440. // way this could possibly happen is if this was unmounted, if at all.
  441. {
  442. {
  443. throw Error( "Unable to find node on an unmounted component." );
  444. }
  445. }
  446. }
  447. if (a.return !== b.return) {
  448. // The return pointer of A and the return pointer of B point to different
  449. // fibers. We assume that return pointers never criss-cross, so A must
  450. // belong to the child set of A.return, and B must belong to the child
  451. // set of B.return.
  452. a = parentA;
  453. b = parentB;
  454. } else {
  455. // The return pointers point to the same fiber. We'll have to use the
  456. // default, slow path: scan the child sets of each parent alternate to see
  457. // which child belongs to which set.
  458. //
  459. // Search parent A's child set
  460. var didFindChild = false;
  461. var _child = parentA.child;
  462. while (_child) {
  463. if (_child === a) {
  464. didFindChild = true;
  465. a = parentA;
  466. b = parentB;
  467. break;
  468. }
  469. if (_child === b) {
  470. didFindChild = true;
  471. b = parentA;
  472. a = parentB;
  473. break;
  474. }
  475. _child = _child.sibling;
  476. }
  477. if (!didFindChild) {
  478. // Search parent B's child set
  479. _child = parentB.child;
  480. while (_child) {
  481. if (_child === a) {
  482. didFindChild = true;
  483. a = parentB;
  484. b = parentA;
  485. break;
  486. }
  487. if (_child === b) {
  488. didFindChild = true;
  489. b = parentB;
  490. a = parentA;
  491. break;
  492. }
  493. _child = _child.sibling;
  494. }
  495. if (!didFindChild) {
  496. {
  497. 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." );
  498. }
  499. }
  500. }
  501. }
  502. if (!(a.alternate === b)) {
  503. {
  504. throw Error( "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." );
  505. }
  506. }
  507. } // If the root is not a host container, we're in a disconnected tree. I.e.
  508. // unmounted.
  509. if (!(a.tag === HostRoot)) {
  510. {
  511. throw Error( "Unable to find node on an unmounted component." );
  512. }
  513. }
  514. if (a.stateNode.current === a) {
  515. // We've determined that A is the current branch.
  516. return fiber;
  517. } // Otherwise B has to be current branch.
  518. return alternate;
  519. }
  520. function findCurrentHostFiber(parent) {
  521. var currentParent = findCurrentFiberUsingSlowPath(parent);
  522. if (!currentParent) {
  523. return null;
  524. } // Next we'll drill down this component to find the first HostComponent/Text.
  525. var node = currentParent;
  526. while (true) {
  527. if (node.tag === HostComponent || node.tag === HostText) {
  528. return node;
  529. } else if (node.child) {
  530. node.child.return = node;
  531. node = node.child;
  532. continue;
  533. }
  534. if (node === currentParent) {
  535. return null;
  536. }
  537. while (!node.sibling) {
  538. if (!node.return || node.return === currentParent) {
  539. return null;
  540. }
  541. node = node.return;
  542. }
  543. node.sibling.return = node.return;
  544. node = node.sibling;
  545. } // Flow needs the return null here, but ESLint complains about it.
  546. // eslint-disable-next-line no-unreachable
  547. return null;
  548. }
  549. // can re-export everything from this module.
  550. function shim() {
  551. {
  552. {
  553. throw Error( "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue." );
  554. }
  555. }
  556. } // Hydration (when unsupported)
  557. var isSuspenseInstancePending = shim;
  558. var isSuspenseInstanceFallback = shim;
  559. var hydrateTextInstance = shim;
  560. var NO_CONTEXT = {};
  561. var UPDATE_SIGNAL = {};
  562. var nodeToInstanceMap = new WeakMap();
  563. {
  564. Object.freeze(NO_CONTEXT);
  565. Object.freeze(UPDATE_SIGNAL);
  566. }
  567. function getPublicInstance(inst) {
  568. switch (inst.tag) {
  569. case 'INSTANCE':
  570. var createNodeMock = inst.rootContainerInstance.createNodeMock;
  571. var mockNode = createNodeMock({
  572. type: inst.type,
  573. props: inst.props
  574. });
  575. if (typeof mockNode === 'object' && mockNode !== null) {
  576. nodeToInstanceMap.set(mockNode, inst);
  577. }
  578. return mockNode;
  579. default:
  580. return inst;
  581. }
  582. }
  583. function appendChild(parentInstance, child) {
  584. {
  585. if (!Array.isArray(parentInstance.children)) {
  586. 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.');
  587. }
  588. }
  589. var index = parentInstance.children.indexOf(child);
  590. if (index !== -1) {
  591. parentInstance.children.splice(index, 1);
  592. }
  593. parentInstance.children.push(child);
  594. }
  595. function insertBefore(parentInstance, child, beforeChild) {
  596. var index = parentInstance.children.indexOf(child);
  597. if (index !== -1) {
  598. parentInstance.children.splice(index, 1);
  599. }
  600. var beforeIndex = parentInstance.children.indexOf(beforeChild);
  601. parentInstance.children.splice(beforeIndex, 0, child);
  602. }
  603. function removeChild(parentInstance, child) {
  604. var index = parentInstance.children.indexOf(child);
  605. parentInstance.children.splice(index, 1);
  606. }
  607. function getRootHostContext(rootContainerInstance) {
  608. return NO_CONTEXT;
  609. }
  610. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  611. return NO_CONTEXT;
  612. }
  613. function prepareForCommit(containerInfo) {// noop
  614. }
  615. function resetAfterCommit(containerInfo) {// noop
  616. }
  617. function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
  618. var propsToUse = props;
  619. return {
  620. type: type,
  621. props: propsToUse,
  622. isHidden: false,
  623. children: [],
  624. internalInstanceHandle: internalInstanceHandle,
  625. rootContainerInstance: rootContainerInstance,
  626. tag: 'INSTANCE'
  627. };
  628. }
  629. function appendInitialChild(parentInstance, child) {
  630. var index = parentInstance.children.indexOf(child);
  631. if (index !== -1) {
  632. parentInstance.children.splice(index, 1);
  633. }
  634. parentInstance.children.push(child);
  635. }
  636. function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
  637. return UPDATE_SIGNAL;
  638. }
  639. function shouldSetTextContent(type, props) {
  640. return false;
  641. }
  642. function shouldDeprioritizeSubtree(type, props) {
  643. return false;
  644. }
  645. function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
  646. return {
  647. text: text,
  648. isHidden: false,
  649. tag: 'TEXT'
  650. };
  651. }
  652. var scheduleTimeout = setTimeout;
  653. var cancelTimeout = clearTimeout;
  654. var noTimeout = -1; // -------------------
  655. function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
  656. instance.type = type;
  657. instance.props = newProps;
  658. }
  659. function commitTextUpdate(textInstance, oldText, newText) {
  660. textInstance.text = newText;
  661. }
  662. function resetTextContent(testElement) {// noop
  663. }
  664. var appendChildToContainer = appendChild;
  665. var insertInContainerBefore = insertBefore;
  666. var removeChildFromContainer = removeChild;
  667. function hideInstance(instance) {
  668. instance.isHidden = true;
  669. }
  670. function hideTextInstance(textInstance) {
  671. textInstance.isHidden = true;
  672. }
  673. function unhideInstance(instance, props) {
  674. instance.isHidden = false;
  675. }
  676. function unhideTextInstance(textInstance, text) {
  677. textInstance.isHidden = false;
  678. }
  679. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  680. function describeComponentFrame (name, source, ownerName) {
  681. var sourceInfo = '';
  682. if (source) {
  683. var path = source.fileName;
  684. var fileName = path.replace(BEFORE_SLASH_RE, '');
  685. {
  686. // In DEV, include code for a common special case:
  687. // prefer "folder/index.js" instead of just "index.js".
  688. if (/^index\./.test(fileName)) {
  689. var match = path.match(BEFORE_SLASH_RE);
  690. if (match) {
  691. var pathBeforeSlash = match[1];
  692. if (pathBeforeSlash) {
  693. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
  694. fileName = folderName + '/' + fileName;
  695. }
  696. }
  697. }
  698. }
  699. sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
  700. } else if (ownerName) {
  701. sourceInfo = ' (created by ' + ownerName + ')';
  702. }
  703. return '\n in ' + (name || 'Unknown') + sourceInfo;
  704. }
  705. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  706. function describeFiber(fiber) {
  707. switch (fiber.tag) {
  708. case HostRoot:
  709. case HostPortal:
  710. case HostText:
  711. case Fragment:
  712. case ContextProvider:
  713. case ContextConsumer:
  714. return '';
  715. default:
  716. var owner = fiber._debugOwner;
  717. var source = fiber._debugSource;
  718. var name = getComponentName(fiber.type);
  719. var ownerName = null;
  720. if (owner) {
  721. ownerName = getComponentName(owner.type);
  722. }
  723. return describeComponentFrame(name, source, ownerName);
  724. }
  725. }
  726. function getStackByFiberInDevAndProd(workInProgress) {
  727. var info = '';
  728. var node = workInProgress;
  729. do {
  730. info += describeFiber(node);
  731. node = node.return;
  732. } while (node);
  733. return info;
  734. }
  735. var current = null;
  736. var isRendering = false;
  737. function getCurrentFiberOwnerNameInDevOrNull() {
  738. {
  739. if (current === null) {
  740. return null;
  741. }
  742. var owner = current._debugOwner;
  743. if (owner !== null && typeof owner !== 'undefined') {
  744. return getComponentName(owner.type);
  745. }
  746. }
  747. return null;
  748. }
  749. function getCurrentFiberStackInDev() {
  750. {
  751. if (current === null) {
  752. return '';
  753. } // Safe because if current fiber exists, we are reconciling,
  754. // and it is guaranteed to be the work-in-progress version.
  755. return getStackByFiberInDevAndProd(current);
  756. }
  757. }
  758. function resetCurrentFiber() {
  759. {
  760. ReactDebugCurrentFrame.getCurrentStack = null;
  761. current = null;
  762. isRendering = false;
  763. }
  764. }
  765. function setCurrentFiber(fiber) {
  766. {
  767. ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
  768. current = fiber;
  769. isRendering = false;
  770. }
  771. }
  772. function setIsRendering(rendering) {
  773. {
  774. isRendering = rendering;
  775. }
  776. }
  777. // Prefix measurements so that it's possible to filter them.
  778. // Longer prefixes are hard to read in DevTools.
  779. var reactEmoji = "\u269B";
  780. var warningEmoji = "\u26D4";
  781. 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.
  782. // TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
  783. var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
  784. // Reusing `currentFiber` would be confusing for this because user code fiber
  785. // can change during commit phase too, but we don't need to unwind it (since
  786. // lifecycles in the commit phase don't resemble a tree).
  787. var currentPhase = null;
  788. var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
  789. // so we will keep track of it, and include it in the report.
  790. // Track commits caused by cascading updates.
  791. var isCommitting = false;
  792. var hasScheduledUpdateInCurrentCommit = false;
  793. var hasScheduledUpdateInCurrentPhase = false;
  794. var commitCountInCurrentWorkLoop = 0;
  795. var effectCountInCurrentCommit = 0;
  796. // to avoid stretch the commit phase with measurement overhead.
  797. var labelsInCurrentCommit = new Set();
  798. var formatMarkName = function (markName) {
  799. return reactEmoji + " " + markName;
  800. };
  801. var formatLabel = function (label, warning) {
  802. var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
  803. var suffix = warning ? " Warning: " + warning : '';
  804. return "" + prefix + label + suffix;
  805. };
  806. var beginMark = function (markName) {
  807. performance.mark(formatMarkName(markName));
  808. };
  809. var clearMark = function (markName) {
  810. performance.clearMarks(formatMarkName(markName));
  811. };
  812. var endMark = function (label, markName, warning) {
  813. var formattedMarkName = formatMarkName(markName);
  814. var formattedLabel = formatLabel(label, warning);
  815. try {
  816. performance.measure(formattedLabel, formattedMarkName);
  817. } catch (err) {} // If previous mark was missing for some reason, this will throw.
  818. // This could only happen if React crashed in an unexpected place earlier.
  819. // Don't pile on with more errors.
  820. // Clear marks immediately to avoid growing buffer.
  821. performance.clearMarks(formattedMarkName);
  822. performance.clearMeasures(formattedLabel);
  823. };
  824. var getFiberMarkName = function (label, debugID) {
  825. return label + " (#" + debugID + ")";
  826. };
  827. var getFiberLabel = function (componentName, isMounted, phase) {
  828. if (phase === null) {
  829. // These are composite component total time measurements.
  830. return componentName + " [" + (isMounted ? 'update' : 'mount') + "]";
  831. } else {
  832. // Composite component methods.
  833. return componentName + "." + phase;
  834. }
  835. };
  836. var beginFiberMark = function (fiber, phase) {
  837. var componentName = getComponentName(fiber.type) || 'Unknown';
  838. var debugID = fiber._debugID;
  839. var isMounted = fiber.alternate !== null;
  840. var label = getFiberLabel(componentName, isMounted, phase);
  841. if (isCommitting && labelsInCurrentCommit.has(label)) {
  842. // During the commit phase, we don't show duplicate labels because
  843. // there is a fixed overhead for every measurement, and we don't
  844. // want to stretch the commit phase beyond necessary.
  845. return false;
  846. }
  847. labelsInCurrentCommit.add(label);
  848. var markName = getFiberMarkName(label, debugID);
  849. beginMark(markName);
  850. return true;
  851. };
  852. var clearFiberMark = function (fiber, phase) {
  853. var componentName = getComponentName(fiber.type) || 'Unknown';
  854. var debugID = fiber._debugID;
  855. var isMounted = fiber.alternate !== null;
  856. var label = getFiberLabel(componentName, isMounted, phase);
  857. var markName = getFiberMarkName(label, debugID);
  858. clearMark(markName);
  859. };
  860. var endFiberMark = function (fiber, phase, warning) {
  861. var componentName = getComponentName(fiber.type) || 'Unknown';
  862. var debugID = fiber._debugID;
  863. var isMounted = fiber.alternate !== null;
  864. var label = getFiberLabel(componentName, isMounted, phase);
  865. var markName = getFiberMarkName(label, debugID);
  866. endMark(label, markName, warning);
  867. };
  868. var shouldIgnoreFiber = function (fiber) {
  869. // Host components should be skipped in the timeline.
  870. // We could check typeof fiber.type, but does this work with RN?
  871. switch (fiber.tag) {
  872. case HostRoot:
  873. case HostComponent:
  874. case HostText:
  875. case HostPortal:
  876. case Fragment:
  877. case ContextProvider:
  878. case ContextConsumer:
  879. case Mode:
  880. return true;
  881. default:
  882. return false;
  883. }
  884. };
  885. var clearPendingPhaseMeasurement = function () {
  886. if (currentPhase !== null && currentPhaseFiber !== null) {
  887. clearFiberMark(currentPhaseFiber, currentPhase);
  888. }
  889. currentPhaseFiber = null;
  890. currentPhase = null;
  891. hasScheduledUpdateInCurrentPhase = false;
  892. };
  893. var pauseTimers = function () {
  894. // Stops all currently active measurements so that they can be resumed
  895. // if we continue in a later deferred loop from the same unit of work.
  896. var fiber = currentFiber;
  897. while (fiber) {
  898. if (fiber._debugIsCurrentlyTiming) {
  899. endFiberMark(fiber, null, null);
  900. }
  901. fiber = fiber.return;
  902. }
  903. };
  904. var resumeTimersRecursively = function (fiber) {
  905. if (fiber.return !== null) {
  906. resumeTimersRecursively(fiber.return);
  907. }
  908. if (fiber._debugIsCurrentlyTiming) {
  909. beginFiberMark(fiber, null);
  910. }
  911. };
  912. var resumeTimers = function () {
  913. // Resumes all measurements that were active during the last deferred loop.
  914. if (currentFiber !== null) {
  915. resumeTimersRecursively(currentFiber);
  916. }
  917. };
  918. function recordEffect() {
  919. {
  920. effectCountInCurrentCommit++;
  921. }
  922. }
  923. function recordScheduleUpdate() {
  924. {
  925. if (isCommitting) {
  926. hasScheduledUpdateInCurrentCommit = true;
  927. }
  928. if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
  929. hasScheduledUpdateInCurrentPhase = true;
  930. }
  931. }
  932. }
  933. function startWorkTimer(fiber) {
  934. {
  935. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  936. return;
  937. } // If we pause, this is the fiber to unwind from.
  938. currentFiber = fiber;
  939. if (!beginFiberMark(fiber, null)) {
  940. return;
  941. }
  942. fiber._debugIsCurrentlyTiming = true;
  943. }
  944. }
  945. function cancelWorkTimer(fiber) {
  946. {
  947. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  948. return;
  949. } // Remember we shouldn't complete measurement for this fiber.
  950. // Otherwise flamechart will be deep even for small updates.
  951. fiber._debugIsCurrentlyTiming = false;
  952. clearFiberMark(fiber, null);
  953. }
  954. }
  955. function stopWorkTimer(fiber) {
  956. {
  957. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  958. return;
  959. } // If we pause, its parent is the fiber to unwind from.
  960. currentFiber = fiber.return;
  961. if (!fiber._debugIsCurrentlyTiming) {
  962. return;
  963. }
  964. fiber._debugIsCurrentlyTiming = false;
  965. endFiberMark(fiber, null, null);
  966. }
  967. }
  968. function stopFailedWorkTimer(fiber) {
  969. {
  970. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  971. return;
  972. } // If we pause, its parent is the fiber to unwind from.
  973. currentFiber = fiber.return;
  974. if (!fiber._debugIsCurrentlyTiming) {
  975. return;
  976. }
  977. fiber._debugIsCurrentlyTiming = false;
  978. var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
  979. endFiberMark(fiber, null, warning);
  980. }
  981. }
  982. function startPhaseTimer(fiber, phase) {
  983. {
  984. if (!supportsUserTiming) {
  985. return;
  986. }
  987. clearPendingPhaseMeasurement();
  988. if (!beginFiberMark(fiber, phase)) {
  989. return;
  990. }
  991. currentPhaseFiber = fiber;
  992. currentPhase = phase;
  993. }
  994. }
  995. function stopPhaseTimer() {
  996. {
  997. if (!supportsUserTiming) {
  998. return;
  999. }
  1000. if (currentPhase !== null && currentPhaseFiber !== null) {
  1001. var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
  1002. endFiberMark(currentPhaseFiber, currentPhase, warning);
  1003. }
  1004. currentPhase = null;
  1005. currentPhaseFiber = null;
  1006. }
  1007. }
  1008. function startWorkLoopTimer(nextUnitOfWork) {
  1009. {
  1010. currentFiber = nextUnitOfWork;
  1011. if (!supportsUserTiming) {
  1012. return;
  1013. }
  1014. commitCountInCurrentWorkLoop = 0; // This is top level call.
  1015. // Any other measurements are performed within.
  1016. beginMark('(React Tree Reconciliation)'); // Resume any measurements that were in progress during the last loop.
  1017. resumeTimers();
  1018. }
  1019. }
  1020. function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
  1021. {
  1022. if (!supportsUserTiming) {
  1023. return;
  1024. }
  1025. var warning = null;
  1026. if (interruptedBy !== null) {
  1027. if (interruptedBy.tag === HostRoot) {
  1028. warning = 'A top-level update interrupted the previous render';
  1029. } else {
  1030. var componentName = getComponentName(interruptedBy.type) || 'Unknown';
  1031. warning = "An update to " + componentName + " interrupted the previous render";
  1032. }
  1033. } else if (commitCountInCurrentWorkLoop > 1) {
  1034. warning = 'There were cascading updates';
  1035. }
  1036. commitCountInCurrentWorkLoop = 0;
  1037. var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)'; // Pause any measurements until the next loop.
  1038. pauseTimers();
  1039. endMark(label, '(React Tree Reconciliation)', warning);
  1040. }
  1041. }
  1042. function startCommitTimer() {
  1043. {
  1044. if (!supportsUserTiming) {
  1045. return;
  1046. }
  1047. isCommitting = true;
  1048. hasScheduledUpdateInCurrentCommit = false;
  1049. labelsInCurrentCommit.clear();
  1050. beginMark('(Committing Changes)');
  1051. }
  1052. }
  1053. function stopCommitTimer() {
  1054. {
  1055. if (!supportsUserTiming) {
  1056. return;
  1057. }
  1058. var warning = null;
  1059. if (hasScheduledUpdateInCurrentCommit) {
  1060. warning = 'Lifecycle hook scheduled a cascading update';
  1061. } else if (commitCountInCurrentWorkLoop > 0) {
  1062. warning = 'Caused by a cascading update in earlier commit';
  1063. }
  1064. hasScheduledUpdateInCurrentCommit = false;
  1065. commitCountInCurrentWorkLoop++;
  1066. isCommitting = false;
  1067. labelsInCurrentCommit.clear();
  1068. endMark('(Committing Changes)', '(Committing Changes)', warning);
  1069. }
  1070. }
  1071. function startCommitSnapshotEffectsTimer() {
  1072. {
  1073. if (!supportsUserTiming) {
  1074. return;
  1075. }
  1076. effectCountInCurrentCommit = 0;
  1077. beginMark('(Committing Snapshot Effects)');
  1078. }
  1079. }
  1080. function stopCommitSnapshotEffectsTimer() {
  1081. {
  1082. if (!supportsUserTiming) {
  1083. return;
  1084. }
  1085. var count = effectCountInCurrentCommit;
  1086. effectCountInCurrentCommit = 0;
  1087. endMark("(Committing Snapshot Effects: " + count + " Total)", '(Committing Snapshot Effects)', null);
  1088. }
  1089. }
  1090. function startCommitHostEffectsTimer() {
  1091. {
  1092. if (!supportsUserTiming) {
  1093. return;
  1094. }
  1095. effectCountInCurrentCommit = 0;
  1096. beginMark('(Committing Host Effects)');
  1097. }
  1098. }
  1099. function stopCommitHostEffectsTimer() {
  1100. {
  1101. if (!supportsUserTiming) {
  1102. return;
  1103. }
  1104. var count = effectCountInCurrentCommit;
  1105. effectCountInCurrentCommit = 0;
  1106. endMark("(Committing Host Effects: " + count + " Total)", '(Committing Host Effects)', null);
  1107. }
  1108. }
  1109. function startCommitLifeCyclesTimer() {
  1110. {
  1111. if (!supportsUserTiming) {
  1112. return;
  1113. }
  1114. effectCountInCurrentCommit = 0;
  1115. beginMark('(Calling Lifecycle Methods)');
  1116. }
  1117. }
  1118. function stopCommitLifeCyclesTimer() {
  1119. {
  1120. if (!supportsUserTiming) {
  1121. return;
  1122. }
  1123. var count = effectCountInCurrentCommit;
  1124. effectCountInCurrentCommit = 0;
  1125. endMark("(Calling Lifecycle Methods: " + count + " Total)", '(Calling Lifecycle Methods)', null);
  1126. }
  1127. }
  1128. var valueStack = [];
  1129. var fiberStack;
  1130. {
  1131. fiberStack = [];
  1132. }
  1133. var index = -1;
  1134. function createCursor(defaultValue) {
  1135. return {
  1136. current: defaultValue
  1137. };
  1138. }
  1139. function pop(cursor, fiber) {
  1140. if (index < 0) {
  1141. {
  1142. error('Unexpected pop.');
  1143. }
  1144. return;
  1145. }
  1146. {
  1147. if (fiber !== fiberStack[index]) {
  1148. error('Unexpected Fiber popped.');
  1149. }
  1150. }
  1151. cursor.current = valueStack[index];
  1152. valueStack[index] = null;
  1153. {
  1154. fiberStack[index] = null;
  1155. }
  1156. index--;
  1157. }
  1158. function push(cursor, value, fiber) {
  1159. index++;
  1160. valueStack[index] = cursor.current;
  1161. {
  1162. fiberStack[index] = fiber;
  1163. }
  1164. cursor.current = value;
  1165. }
  1166. var warnedAboutMissingGetChildContext;
  1167. {
  1168. warnedAboutMissingGetChildContext = {};
  1169. }
  1170. var emptyContextObject = {};
  1171. {
  1172. Object.freeze(emptyContextObject);
  1173. } // A cursor to the current merged context object on the stack.
  1174. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  1175. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  1176. // We use this to get access to the parent context after we have already
  1177. // pushed the next context provider, and now need to merge their contexts.
  1178. var previousContext = emptyContextObject;
  1179. function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
  1180. {
  1181. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  1182. // If the fiber is a context provider itself, when we read its context
  1183. // we may have already pushed its own child context on the stack. A context
  1184. // provider should not "see" its own child context. Therefore we read the
  1185. // previous (parent) context instead for a context provider.
  1186. return previousContext;
  1187. }
  1188. return contextStackCursor.current;
  1189. }
  1190. }
  1191. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  1192. {
  1193. var instance = workInProgress.stateNode;
  1194. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  1195. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  1196. }
  1197. }
  1198. function getMaskedContext(workInProgress, unmaskedContext) {
  1199. {
  1200. var type = workInProgress.type;
  1201. var contextTypes = type.contextTypes;
  1202. if (!contextTypes) {
  1203. return emptyContextObject;
  1204. } // Avoid recreating masked context unless unmasked context has changed.
  1205. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  1206. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  1207. var instance = workInProgress.stateNode;
  1208. if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
  1209. return instance.__reactInternalMemoizedMaskedChildContext;
  1210. }
  1211. var context = {};
  1212. for (var key in contextTypes) {
  1213. context[key] = unmaskedContext[key];
  1214. }
  1215. {
  1216. var name = getComponentName(type) || 'Unknown';
  1217. checkPropTypes(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
  1218. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  1219. // Context is created before the class component is instantiated so check for instance.
  1220. if (instance) {
  1221. cacheContext(workInProgress, unmaskedContext, context);
  1222. }
  1223. return context;
  1224. }
  1225. }
  1226. function hasContextChanged() {
  1227. {
  1228. return didPerformWorkStackCursor.current;
  1229. }
  1230. }
  1231. function isContextProvider(type) {
  1232. {
  1233. var childContextTypes = type.childContextTypes;
  1234. return childContextTypes !== null && childContextTypes !== undefined;
  1235. }
  1236. }
  1237. function popContext(fiber) {
  1238. {
  1239. pop(didPerformWorkStackCursor, fiber);
  1240. pop(contextStackCursor, fiber);
  1241. }
  1242. }
  1243. function popTopLevelContextObject(fiber) {
  1244. {
  1245. pop(didPerformWorkStackCursor, fiber);
  1246. pop(contextStackCursor, fiber);
  1247. }
  1248. }
  1249. function pushTopLevelContextObject(fiber, context, didChange) {
  1250. {
  1251. if (!(contextStackCursor.current === emptyContextObject)) {
  1252. {
  1253. throw Error( "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." );
  1254. }
  1255. }
  1256. push(contextStackCursor, context, fiber);
  1257. push(didPerformWorkStackCursor, didChange, fiber);
  1258. }
  1259. }
  1260. function processChildContext(fiber, type, parentContext) {
  1261. {
  1262. var instance = fiber.stateNode;
  1263. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  1264. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  1265. if (typeof instance.getChildContext !== 'function') {
  1266. {
  1267. var componentName = getComponentName(type) || 'Unknown';
  1268. if (!warnedAboutMissingGetChildContext[componentName]) {
  1269. warnedAboutMissingGetChildContext[componentName] = true;
  1270. 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);
  1271. }
  1272. }
  1273. return parentContext;
  1274. }
  1275. var childContext;
  1276. startPhaseTimer(fiber, 'getChildContext');
  1277. childContext = instance.getChildContext();
  1278. stopPhaseTimer();
  1279. for (var contextKey in childContext) {
  1280. if (!(contextKey in childContextTypes)) {
  1281. {
  1282. throw Error( (getComponentName(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes." );
  1283. }
  1284. }
  1285. }
  1286. {
  1287. var name = getComponentName(type) || 'Unknown';
  1288. checkPropTypes(childContextTypes, childContext, 'child context', name, // In practice, there is one case in which we won't get a stack. It's when
  1289. // somebody calls unstable_renderSubtreeIntoContainer() and we process
  1290. // context from the parent component instance. The stack will be missing
  1291. // because it's outside of the reconciliation, and so the pointer has not
  1292. // been set. This is rare and doesn't matter. We'll also remove that API.
  1293. getCurrentFiberStackInDev);
  1294. }
  1295. return _assign({}, parentContext, {}, childContext);
  1296. }
  1297. }
  1298. function pushContextProvider(workInProgress) {
  1299. {
  1300. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  1301. // If the instance does not exist yet, we will push null at first,
  1302. // and replace it on the stack later when invalidating the context.
  1303. var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
  1304. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  1305. previousContext = contextStackCursor.current;
  1306. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  1307. push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
  1308. return true;
  1309. }
  1310. }
  1311. function invalidateContextProvider(workInProgress, type, didChange) {
  1312. {
  1313. var instance = workInProgress.stateNode;
  1314. if (!instance) {
  1315. {
  1316. throw Error( "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." );
  1317. }
  1318. }
  1319. if (didChange) {
  1320. // Merge parent and own context.
  1321. // Skip this if we're not updating due to sCU.
  1322. // This avoids unnecessarily recomputing memoized values.
  1323. var mergedContext = processChildContext(workInProgress, type, previousContext);
  1324. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  1325. // It is important to unwind the context in the reverse order.
  1326. pop(didPerformWorkStackCursor, workInProgress);
  1327. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  1328. push(contextStackCursor, mergedContext, workInProgress);
  1329. push(didPerformWorkStackCursor, didChange, workInProgress);
  1330. } else {
  1331. pop(didPerformWorkStackCursor, workInProgress);
  1332. push(didPerformWorkStackCursor, didChange, workInProgress);
  1333. }
  1334. }
  1335. }
  1336. function findCurrentUnmaskedContext(fiber) {
  1337. {
  1338. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  1339. // makes sense elsewhere
  1340. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  1341. {
  1342. 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." );
  1343. }
  1344. }
  1345. var node = fiber;
  1346. do {
  1347. switch (node.tag) {
  1348. case HostRoot:
  1349. return node.stateNode.context;
  1350. case ClassComponent:
  1351. {
  1352. var Component = node.type;
  1353. if (isContextProvider(Component)) {
  1354. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  1355. }
  1356. break;
  1357. }
  1358. }
  1359. node = node.return;
  1360. } while (node !== null);
  1361. {
  1362. {
  1363. throw Error( "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." );
  1364. }
  1365. }
  1366. }
  1367. }
  1368. var LegacyRoot = 0;
  1369. var BlockingRoot = 1;
  1370. var ConcurrentRoot = 2;
  1371. var Scheduler_runWithPriority = Scheduler$1.unstable_runWithPriority,
  1372. Scheduler_scheduleCallback = Scheduler$1.unstable_scheduleCallback,
  1373. Scheduler_cancelCallback = Scheduler$1.unstable_cancelCallback,
  1374. Scheduler_shouldYield = Scheduler$1.unstable_shouldYield,
  1375. Scheduler_requestPaint = Scheduler$1.unstable_requestPaint,
  1376. Scheduler_now = Scheduler$1.unstable_now,
  1377. Scheduler_getCurrentPriorityLevel = Scheduler$1.unstable_getCurrentPriorityLevel,
  1378. Scheduler_ImmediatePriority = Scheduler$1.unstable_ImmediatePriority,
  1379. Scheduler_UserBlockingPriority = Scheduler$1.unstable_UserBlockingPriority,
  1380. Scheduler_NormalPriority = Scheduler$1.unstable_NormalPriority,
  1381. Scheduler_LowPriority = Scheduler$1.unstable_LowPriority,
  1382. Scheduler_IdlePriority = Scheduler$1.unstable_IdlePriority;
  1383. {
  1384. // Provide explicit error message when production+profiling bundle of e.g.
  1385. // react-dom is used with production (non-profiling) bundle of
  1386. // scheduler/tracing
  1387. if (!(tracing.__interactionsRef != null && tracing.__interactionsRef.current != null)) {
  1388. {
  1389. 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" );
  1390. }
  1391. }
  1392. }
  1393. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  1394. // ascending numbers so we can compare them like numbers. They start at 90 to
  1395. // avoid clashing with Scheduler's priorities.
  1396. var ImmediatePriority = 99;
  1397. var UserBlockingPriority = 98;
  1398. var NormalPriority = 97;
  1399. var LowPriority = 96;
  1400. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  1401. var NoPriority = 90;
  1402. var shouldYield = Scheduler_shouldYield;
  1403. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  1404. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function () {};
  1405. var syncQueue = null;
  1406. var immediateQueueCallbackNode = null;
  1407. var isFlushingSyncQueue = false;
  1408. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  1409. // This will be the case for modern browsers that support `performance.now`. In
  1410. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  1411. // timestamp. In that case, subtract the module initialization time to simulate
  1412. // the behavior of performance.now and keep our times small enough to fit
  1413. // within 32 bits.
  1414. // TODO: Consider lifting this into Scheduler.
  1415. var now = initialTimeMs < 10000 ? Scheduler_now : function () {
  1416. return Scheduler_now() - initialTimeMs;
  1417. };
  1418. function getCurrentPriorityLevel() {
  1419. switch (Scheduler_getCurrentPriorityLevel()) {
  1420. case Scheduler_ImmediatePriority:
  1421. return ImmediatePriority;
  1422. case Scheduler_UserBlockingPriority:
  1423. return UserBlockingPriority;
  1424. case Scheduler_NormalPriority:
  1425. return NormalPriority;
  1426. case Scheduler_LowPriority:
  1427. return LowPriority;
  1428. case Scheduler_IdlePriority:
  1429. return IdlePriority;
  1430. default:
  1431. {
  1432. {
  1433. throw Error( "Unknown priority level." );
  1434. }
  1435. }
  1436. }
  1437. }
  1438. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  1439. switch (reactPriorityLevel) {
  1440. case ImmediatePriority:
  1441. return Scheduler_ImmediatePriority;
  1442. case UserBlockingPriority:
  1443. return Scheduler_UserBlockingPriority;
  1444. case NormalPriority:
  1445. return Scheduler_NormalPriority;
  1446. case LowPriority:
  1447. return Scheduler_LowPriority;
  1448. case IdlePriority:
  1449. return Scheduler_IdlePriority;
  1450. default:
  1451. {
  1452. {
  1453. throw Error( "Unknown priority level." );
  1454. }
  1455. }
  1456. }
  1457. }
  1458. function runWithPriority(reactPriorityLevel, fn) {
  1459. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  1460. return Scheduler_runWithPriority(priorityLevel, fn);
  1461. }
  1462. function scheduleCallback(reactPriorityLevel, callback, options) {
  1463. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  1464. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  1465. }
  1466. function scheduleSyncCallback(callback) {
  1467. // Push this callback into an internal queue. We'll flush these either in
  1468. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  1469. if (syncQueue === null) {
  1470. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  1471. immediateQueueCallbackNode = Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueueImpl);
  1472. } else {
  1473. // Push onto existing queue. Don't need to schedule a callback because
  1474. // we already scheduled one when we created the queue.
  1475. syncQueue.push(callback);
  1476. }
  1477. return fakeCallbackNode;
  1478. }
  1479. function cancelCallback(callbackNode) {
  1480. if (callbackNode !== fakeCallbackNode) {
  1481. Scheduler_cancelCallback(callbackNode);
  1482. }
  1483. }
  1484. function flushSyncCallbackQueue() {
  1485. if (immediateQueueCallbackNode !== null) {
  1486. var node = immediateQueueCallbackNode;
  1487. immediateQueueCallbackNode = null;
  1488. Scheduler_cancelCallback(node);
  1489. }
  1490. flushSyncCallbackQueueImpl();
  1491. }
  1492. function flushSyncCallbackQueueImpl() {
  1493. if (!isFlushingSyncQueue && syncQueue !== null) {
  1494. // Prevent re-entrancy.
  1495. isFlushingSyncQueue = true;
  1496. var i = 0;
  1497. try {
  1498. var _isSync = true;
  1499. var queue = syncQueue;
  1500. runWithPriority(ImmediatePriority, function () {
  1501. for (; i < queue.length; i++) {
  1502. var callback = queue[i];
  1503. do {
  1504. callback = callback(_isSync);
  1505. } while (callback !== null);
  1506. }
  1507. });
  1508. syncQueue = null;
  1509. } catch (error) {
  1510. // If something throws, leave the remaining callbacks on the queue.
  1511. if (syncQueue !== null) {
  1512. syncQueue = syncQueue.slice(i + 1);
  1513. } // Resume flushing in the next tick
  1514. Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueue);
  1515. throw error;
  1516. } finally {
  1517. isFlushingSyncQueue = false;
  1518. }
  1519. }
  1520. }
  1521. var NoMode = 0;
  1522. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  1523. // tag instead
  1524. var BlockingMode = 2;
  1525. var ConcurrentMode = 4;
  1526. var ProfileMode = 8;
  1527. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  1528. // Math.pow(2, 30) - 1
  1529. // 0b111111111111111111111111111111
  1530. var MAX_SIGNED_31_BIT_INT = 1073741823;
  1531. var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
  1532. // Never work can be committed in an inconsistent state without tearing the UI.
  1533. // The main example is offscreen content, like a hidden subtree. So one possible
  1534. // name is Offscreen. However, it also includes dehydrated Suspense boundaries,
  1535. // which are inconsistent in the sense that they haven't finished yet, but
  1536. // aren't visibly inconsistent because the server rendered HTML matches what the
  1537. // hydrated tree would look like.
  1538. var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
  1539. // order to be consistent.
  1540. var Idle = 2; // Continuous Hydration is slightly higher than Idle and is used to increase
  1541. var Sync = MAX_SIGNED_31_BIT_INT;
  1542. var Batched = Sync - 1;
  1543. var UNIT_SIZE = 10;
  1544. var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
  1545. function msToExpirationTime(ms) {
  1546. // Always subtract from the offset so that we don't clash with the magic number for NoWork.
  1547. return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
  1548. }
  1549. function expirationTimeToMs(expirationTime) {
  1550. return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
  1551. }
  1552. function ceiling(num, precision) {
  1553. return ((num / precision | 0) + 1) * precision;
  1554. }
  1555. function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
  1556. return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
  1557. } // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
  1558. // the names to reflect.
  1559. var LOW_PRIORITY_EXPIRATION = 5000;
  1560. var LOW_PRIORITY_BATCH_SIZE = 250;
  1561. function computeAsyncExpiration(currentTime) {
  1562. return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
  1563. }
  1564. function computeSuspenseExpiration(currentTime, timeoutMs) {
  1565. // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
  1566. return computeExpirationBucket(currentTime, timeoutMs, LOW_PRIORITY_BATCH_SIZE);
  1567. } // We intentionally set a higher expiration time for interactive updates in
  1568. // dev than in production.
  1569. //
  1570. // If the main thread is being blocked so long that you hit the expiration,
  1571. // it's a problem that could be solved with better scheduling.
  1572. //
  1573. // People will be more likely to notice this and fix it with the long
  1574. // expiration time in development.
  1575. //
  1576. // In production we opt for better UX at the risk of masking scheduling
  1577. // problems, by expiring fast.
  1578. var HIGH_PRIORITY_EXPIRATION = 500 ;
  1579. var HIGH_PRIORITY_BATCH_SIZE = 100;
  1580. function computeInteractiveExpiration(currentTime) {
  1581. return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
  1582. }
  1583. function inferPriorityFromExpirationTime(currentTime, expirationTime) {
  1584. if (expirationTime === Sync) {
  1585. return ImmediatePriority;
  1586. }
  1587. if (expirationTime === Never || expirationTime === Idle) {
  1588. return IdlePriority;
  1589. }
  1590. var msUntil = expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
  1591. if (msUntil <= 0) {
  1592. return ImmediatePriority;
  1593. }
  1594. if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
  1595. return UserBlockingPriority;
  1596. }
  1597. if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
  1598. return NormalPriority;
  1599. } // TODO: Handle LowPriority
  1600. // Assume anything lower has idle priority
  1601. return IdlePriority;
  1602. }
  1603. /**
  1604. * inlined Object.is polyfill to avoid requiring consumers ship their own
  1605. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  1606. */
  1607. function is(x, y) {
  1608. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  1609. ;
  1610. }
  1611. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  1612. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1613. /**
  1614. * Performs equality by iterating through keys on an object and returning false
  1615. * when any key has values which are not strictly equal between the arguments.
  1616. * Returns true when the values of all keys are strictly equal.
  1617. */
  1618. function shallowEqual(objA, objB) {
  1619. if (objectIs(objA, objB)) {
  1620. return true;
  1621. }
  1622. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  1623. return false;
  1624. }
  1625. var keysA = Object.keys(objA);
  1626. var keysB = Object.keys(objB);
  1627. if (keysA.length !== keysB.length) {
  1628. return false;
  1629. } // Test for A's keys different from B.
  1630. for (var i = 0; i < keysA.length; i++) {
  1631. if (!hasOwnProperty.call(objB, keysA[i]) || !objectIs(objA[keysA[i]], objB[keysA[i]])) {
  1632. return false;
  1633. }
  1634. }
  1635. return true;
  1636. }
  1637. var ReactStrictModeWarnings = {
  1638. recordUnsafeLifecycleWarnings: function (fiber, instance) {},
  1639. flushPendingUnsafeLifecycleWarnings: function () {},
  1640. recordLegacyContextWarning: function (fiber, instance) {},
  1641. flushLegacyContextWarning: function () {},
  1642. discardPendingWarnings: function () {}
  1643. };
  1644. {
  1645. var findStrictRoot = function (fiber) {
  1646. var maybeStrictRoot = null;
  1647. var node = fiber;
  1648. while (node !== null) {
  1649. if (node.mode & StrictMode) {
  1650. maybeStrictRoot = node;
  1651. }
  1652. node = node.return;
  1653. }
  1654. return maybeStrictRoot;
  1655. };
  1656. var setToSortedString = function (set) {
  1657. var array = [];
  1658. set.forEach(function (value) {
  1659. array.push(value);
  1660. });
  1661. return array.sort().join(', ');
  1662. };
  1663. var pendingComponentWillMountWarnings = [];
  1664. var pendingUNSAFE_ComponentWillMountWarnings = [];
  1665. var pendingComponentWillReceivePropsWarnings = [];
  1666. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  1667. var pendingComponentWillUpdateWarnings = [];
  1668. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  1669. var didWarnAboutUnsafeLifecycles = new Set();
  1670. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
  1671. // Dedup strategy: Warn once per component.
  1672. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  1673. return;
  1674. }
  1675. if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
  1676. instance.componentWillMount.__suppressDeprecationWarning !== true) {
  1677. pendingComponentWillMountWarnings.push(fiber);
  1678. }
  1679. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillMount === 'function') {
  1680. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  1681. }
  1682. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  1683. pendingComponentWillReceivePropsWarnings.push(fiber);
  1684. }
  1685. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  1686. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  1687. }
  1688. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  1689. pendingComponentWillUpdateWarnings.push(fiber);
  1690. }
  1691. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
  1692. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  1693. }
  1694. };
  1695. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
  1696. // We do an initial pass to gather component names
  1697. var componentWillMountUniqueNames = new Set();
  1698. if (pendingComponentWillMountWarnings.length > 0) {
  1699. pendingComponentWillMountWarnings.forEach(function (fiber) {
  1700. componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1701. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1702. });
  1703. pendingComponentWillMountWarnings = [];
  1704. }
  1705. var UNSAFE_componentWillMountUniqueNames = new Set();
  1706. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  1707. pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
  1708. UNSAFE_componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1709. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1710. });
  1711. pendingUNSAFE_ComponentWillMountWarnings = [];
  1712. }
  1713. var componentWillReceivePropsUniqueNames = new Set();
  1714. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  1715. pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
  1716. componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1717. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1718. });
  1719. pendingComponentWillReceivePropsWarnings = [];
  1720. }
  1721. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  1722. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  1723. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
  1724. UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1725. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1726. });
  1727. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  1728. }
  1729. var componentWillUpdateUniqueNames = new Set();
  1730. if (pendingComponentWillUpdateWarnings.length > 0) {
  1731. pendingComponentWillUpdateWarnings.forEach(function (fiber) {
  1732. componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1733. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1734. });
  1735. pendingComponentWillUpdateWarnings = [];
  1736. }
  1737. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  1738. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  1739. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
  1740. UNSAFE_componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  1741. didWarnAboutUnsafeLifecycles.add(fiber.type);
  1742. });
  1743. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  1744. } // Finally, we flush all the warnings
  1745. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  1746. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  1747. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  1748. 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);
  1749. }
  1750. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  1751. var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
  1752. 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);
  1753. }
  1754. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  1755. var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
  1756. 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);
  1757. }
  1758. if (componentWillMountUniqueNames.size > 0) {
  1759. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  1760. 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);
  1761. }
  1762. if (componentWillReceivePropsUniqueNames.size > 0) {
  1763. var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
  1764. 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);
  1765. }
  1766. if (componentWillUpdateUniqueNames.size > 0) {
  1767. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  1768. 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);
  1769. }
  1770. };
  1771. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  1772. var didWarnAboutLegacyContext = new Set();
  1773. ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
  1774. var strictRoot = findStrictRoot(fiber);
  1775. if (strictRoot === null) {
  1776. 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.');
  1777. return;
  1778. } // Dedup strategy: Warn once per component.
  1779. if (didWarnAboutLegacyContext.has(fiber.type)) {
  1780. return;
  1781. }
  1782. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  1783. if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
  1784. if (warningsForRoot === undefined) {
  1785. warningsForRoot = [];
  1786. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  1787. }
  1788. warningsForRoot.push(fiber);
  1789. }
  1790. };
  1791. ReactStrictModeWarnings.flushLegacyContextWarning = function () {
  1792. pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
  1793. if (fiberArray.length === 0) {
  1794. return;
  1795. }
  1796. var firstFiber = fiberArray[0];
  1797. var uniqueNames = new Set();
  1798. fiberArray.forEach(function (fiber) {
  1799. uniqueNames.add(getComponentName(fiber.type) || 'Component');
  1800. didWarnAboutLegacyContext.add(fiber.type);
  1801. });
  1802. var sortedNames = setToSortedString(uniqueNames);
  1803. var firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
  1804. 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);
  1805. });
  1806. };
  1807. ReactStrictModeWarnings.discardPendingWarnings = function () {
  1808. pendingComponentWillMountWarnings = [];
  1809. pendingUNSAFE_ComponentWillMountWarnings = [];
  1810. pendingComponentWillReceivePropsWarnings = [];
  1811. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  1812. pendingComponentWillUpdateWarnings = [];
  1813. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  1814. pendingLegacyContextWarning = new Map();
  1815. };
  1816. }
  1817. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  1818. var failedBoundaries = null;
  1819. var setRefreshHandler = function (handler) {
  1820. {
  1821. resolveFamily = handler;
  1822. }
  1823. };
  1824. function resolveFunctionForHotReloading(type) {
  1825. {
  1826. if (resolveFamily === null) {
  1827. // Hot reloading is disabled.
  1828. return type;
  1829. }
  1830. var family = resolveFamily(type);
  1831. if (family === undefined) {
  1832. return type;
  1833. } // Use the latest known implementation.
  1834. return family.current;
  1835. }
  1836. }
  1837. function resolveClassForHotReloading(type) {
  1838. // No implementation differences.
  1839. return resolveFunctionForHotReloading(type);
  1840. }
  1841. function resolveForwardRefForHotReloading(type) {
  1842. {
  1843. if (resolveFamily === null) {
  1844. // Hot reloading is disabled.
  1845. return type;
  1846. }
  1847. var family = resolveFamily(type);
  1848. if (family === undefined) {
  1849. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  1850. if (type !== null && type !== undefined && typeof type.render === 'function') {
  1851. // ForwardRef is special because its resolved .type is an object,
  1852. // but it's possible that we only have its inner render function in the map.
  1853. // If that inner render function is different, we'll build a new forwardRef type.
  1854. var currentRender = resolveFunctionForHotReloading(type.render);
  1855. if (type.render !== currentRender) {
  1856. var syntheticType = {
  1857. $$typeof: REACT_FORWARD_REF_TYPE,
  1858. render: currentRender
  1859. };
  1860. if (type.displayName !== undefined) {
  1861. syntheticType.displayName = type.displayName;
  1862. }
  1863. return syntheticType;
  1864. }
  1865. }
  1866. return type;
  1867. } // Use the latest known implementation.
  1868. return family.current;
  1869. }
  1870. }
  1871. function isCompatibleFamilyForHotReloading(fiber, element) {
  1872. {
  1873. if (resolveFamily === null) {
  1874. // Hot reloading is disabled.
  1875. return false;
  1876. }
  1877. var prevType = fiber.elementType;
  1878. var nextType = element.type; // If we got here, we know types aren't === equal.
  1879. var needsCompareFamilies = false;
  1880. var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
  1881. switch (fiber.tag) {
  1882. case ClassComponent:
  1883. {
  1884. if (typeof nextType === 'function') {
  1885. needsCompareFamilies = true;
  1886. }
  1887. break;
  1888. }
  1889. case FunctionComponent:
  1890. {
  1891. if (typeof nextType === 'function') {
  1892. needsCompareFamilies = true;
  1893. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  1894. // We don't know the inner type yet.
  1895. // We're going to assume that the lazy inner type is stable,
  1896. // and so it is sufficient to avoid reconciling it away.
  1897. // We're not going to unwrap or actually use the new lazy type.
  1898. needsCompareFamilies = true;
  1899. }
  1900. break;
  1901. }
  1902. case ForwardRef:
  1903. {
  1904. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  1905. needsCompareFamilies = true;
  1906. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  1907. needsCompareFamilies = true;
  1908. }
  1909. break;
  1910. }
  1911. case MemoComponent:
  1912. case SimpleMemoComponent:
  1913. {
  1914. if ($$typeofNextType === REACT_MEMO_TYPE) {
  1915. // TODO: if it was but can no longer be simple,
  1916. // we shouldn't set this.
  1917. needsCompareFamilies = true;
  1918. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  1919. needsCompareFamilies = true;
  1920. }
  1921. break;
  1922. }
  1923. default:
  1924. return false;
  1925. } // Check if both types have a family and it's the same one.
  1926. if (needsCompareFamilies) {
  1927. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  1928. // This means both of them need to be registered to preserve state.
  1929. // If we unwrapped and compared the inner types for wrappers instead,
  1930. // then we would risk falsely saying two separate memo(Foo)
  1931. // calls are equivalent because they wrap the same Foo function.
  1932. var prevFamily = resolveFamily(prevType);
  1933. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  1934. return true;
  1935. }
  1936. }
  1937. return false;
  1938. }
  1939. }
  1940. function markFailedErrorBoundaryForHotReloading(fiber) {
  1941. {
  1942. if (resolveFamily === null) {
  1943. // Hot reloading is disabled.
  1944. return;
  1945. }
  1946. if (typeof WeakSet !== 'function') {
  1947. return;
  1948. }
  1949. if (failedBoundaries === null) {
  1950. failedBoundaries = new WeakSet();
  1951. }
  1952. failedBoundaries.add(fiber);
  1953. }
  1954. }
  1955. var scheduleRefresh = function (root, update) {
  1956. {
  1957. if (resolveFamily === null) {
  1958. // Hot reloading is disabled.
  1959. return;
  1960. }
  1961. var staleFamilies = update.staleFamilies,
  1962. updatedFamilies = update.updatedFamilies;
  1963. flushPassiveEffects();
  1964. flushSync(function () {
  1965. scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
  1966. });
  1967. }
  1968. };
  1969. var scheduleRoot = function (root, element) {
  1970. {
  1971. if (root.context !== emptyContextObject) {
  1972. // Super edge case: root has a legacy _renderSubtree context
  1973. // but we don't know the parentComponent so we can't pass it.
  1974. // Just ignore. We'll delete this with _renderSubtree code path later.
  1975. return;
  1976. }
  1977. flushPassiveEffects();
  1978. syncUpdates(function () {
  1979. updateContainer(element, root, null, null);
  1980. });
  1981. }
  1982. };
  1983. function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
  1984. {
  1985. var alternate = fiber.alternate,
  1986. child = fiber.child,
  1987. sibling = fiber.sibling,
  1988. tag = fiber.tag,
  1989. type = fiber.type;
  1990. var candidateType = null;
  1991. switch (tag) {
  1992. case FunctionComponent:
  1993. case SimpleMemoComponent:
  1994. case ClassComponent:
  1995. candidateType = type;
  1996. break;
  1997. case ForwardRef:
  1998. candidateType = type.render;
  1999. break;
  2000. }
  2001. if (resolveFamily === null) {
  2002. throw new Error('Expected resolveFamily to be set during hot reload.');
  2003. }
  2004. var needsRender = false;
  2005. var needsRemount = false;
  2006. if (candidateType !== null) {
  2007. var family = resolveFamily(candidateType);
  2008. if (family !== undefined) {
  2009. if (staleFamilies.has(family)) {
  2010. needsRemount = true;
  2011. } else if (updatedFamilies.has(family)) {
  2012. if (tag === ClassComponent) {
  2013. needsRemount = true;
  2014. } else {
  2015. needsRender = true;
  2016. }
  2017. }
  2018. }
  2019. }
  2020. if (failedBoundaries !== null) {
  2021. if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
  2022. needsRemount = true;
  2023. }
  2024. }
  2025. if (needsRemount) {
  2026. fiber._debugNeedsRemount = true;
  2027. }
  2028. if (needsRemount || needsRender) {
  2029. scheduleWork(fiber, Sync);
  2030. }
  2031. if (child !== null && !needsRemount) {
  2032. scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
  2033. }
  2034. if (sibling !== null) {
  2035. scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
  2036. }
  2037. }
  2038. }
  2039. var findHostInstancesForRefresh = function (root, families) {
  2040. {
  2041. var hostInstances = new Set();
  2042. var types = new Set(families.map(function (family) {
  2043. return family.current;
  2044. }));
  2045. findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
  2046. return hostInstances;
  2047. }
  2048. };
  2049. function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
  2050. {
  2051. var child = fiber.child,
  2052. sibling = fiber.sibling,
  2053. tag = fiber.tag,
  2054. type = fiber.type;
  2055. var candidateType = null;
  2056. switch (tag) {
  2057. case FunctionComponent:
  2058. case SimpleMemoComponent:
  2059. case ClassComponent:
  2060. candidateType = type;
  2061. break;
  2062. case ForwardRef:
  2063. candidateType = type.render;
  2064. break;
  2065. }
  2066. var didMatch = false;
  2067. if (candidateType !== null) {
  2068. if (types.has(candidateType)) {
  2069. didMatch = true;
  2070. }
  2071. }
  2072. if (didMatch) {
  2073. // We have a match. This only drills down to the closest host components.
  2074. // There's no need to search deeper because for the purpose of giving
  2075. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  2076. findHostInstancesForFiberShallowly(fiber, hostInstances);
  2077. } else {
  2078. // If there's no match, maybe there will be one further down in the child tree.
  2079. if (child !== null) {
  2080. findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
  2081. }
  2082. }
  2083. if (sibling !== null) {
  2084. findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
  2085. }
  2086. }
  2087. }
  2088. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  2089. {
  2090. var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
  2091. if (foundHostInstances) {
  2092. return;
  2093. } // If we didn't find any host children, fallback to closest host parent.
  2094. var node = fiber;
  2095. while (true) {
  2096. switch (node.tag) {
  2097. case HostComponent:
  2098. hostInstances.add(node.stateNode);
  2099. return;
  2100. case HostPortal:
  2101. hostInstances.add(node.stateNode.containerInfo);
  2102. return;
  2103. case HostRoot:
  2104. hostInstances.add(node.stateNode.containerInfo);
  2105. return;
  2106. }
  2107. if (node.return === null) {
  2108. throw new Error('Expected to reach root first.');
  2109. }
  2110. node = node.return;
  2111. }
  2112. }
  2113. }
  2114. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  2115. {
  2116. var node = fiber;
  2117. var foundHostInstances = false;
  2118. while (true) {
  2119. if (node.tag === HostComponent) {
  2120. // We got a match.
  2121. foundHostInstances = true;
  2122. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  2123. } else if (node.child !== null) {
  2124. node.child.return = node;
  2125. node = node.child;
  2126. continue;
  2127. }
  2128. if (node === fiber) {
  2129. return foundHostInstances;
  2130. }
  2131. while (node.sibling === null) {
  2132. if (node.return === null || node.return === fiber) {
  2133. return foundHostInstances;
  2134. }
  2135. node = node.return;
  2136. }
  2137. node.sibling.return = node.return;
  2138. node = node.sibling;
  2139. }
  2140. }
  2141. return false;
  2142. }
  2143. function resolveDefaultProps(Component, baseProps) {
  2144. if (Component && Component.defaultProps) {
  2145. // Resolve default props. Taken from ReactElement
  2146. var props = _assign({}, baseProps);
  2147. var defaultProps = Component.defaultProps;
  2148. for (var propName in defaultProps) {
  2149. if (props[propName] === undefined) {
  2150. props[propName] = defaultProps[propName];
  2151. }
  2152. }
  2153. return props;
  2154. }
  2155. return baseProps;
  2156. }
  2157. function readLazyComponentType(lazyComponent) {
  2158. initializeLazyComponentType(lazyComponent);
  2159. if (lazyComponent._status !== Resolved) {
  2160. throw lazyComponent._result;
  2161. }
  2162. return lazyComponent._result;
  2163. }
  2164. var valueCursor = createCursor(null);
  2165. var rendererSigil;
  2166. {
  2167. // Use this to detect multiple renderers using the same context
  2168. rendererSigil = {};
  2169. }
  2170. var currentlyRenderingFiber = null;
  2171. var lastContextDependency = null;
  2172. var lastContextWithAllBitsObserved = null;
  2173. var isDisallowedContextReadInDEV = false;
  2174. function resetContextDependencies() {
  2175. // This is called right before React yields execution, to ensure `readContext`
  2176. // cannot be called outside the render phase.
  2177. currentlyRenderingFiber = null;
  2178. lastContextDependency = null;
  2179. lastContextWithAllBitsObserved = null;
  2180. {
  2181. isDisallowedContextReadInDEV = false;
  2182. }
  2183. }
  2184. function enterDisallowedContextReadInDEV() {
  2185. {
  2186. isDisallowedContextReadInDEV = true;
  2187. }
  2188. }
  2189. function exitDisallowedContextReadInDEV() {
  2190. {
  2191. isDisallowedContextReadInDEV = false;
  2192. }
  2193. }
  2194. function pushProvider(providerFiber, nextValue) {
  2195. var context = providerFiber.type._context;
  2196. {
  2197. push(valueCursor, context._currentValue2, providerFiber);
  2198. context._currentValue2 = nextValue;
  2199. {
  2200. if (context._currentRenderer2 !== undefined && context._currentRenderer2 !== null && context._currentRenderer2 !== rendererSigil) {
  2201. error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
  2202. }
  2203. context._currentRenderer2 = rendererSigil;
  2204. }
  2205. }
  2206. }
  2207. function popProvider(providerFiber) {
  2208. var currentValue = valueCursor.current;
  2209. pop(valueCursor, providerFiber);
  2210. var context = providerFiber.type._context;
  2211. {
  2212. context._currentValue2 = currentValue;
  2213. }
  2214. }
  2215. function calculateChangedBits(context, newValue, oldValue) {
  2216. if (objectIs(oldValue, newValue)) {
  2217. // No change
  2218. return 0;
  2219. } else {
  2220. var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
  2221. {
  2222. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  2223. error('calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits);
  2224. }
  2225. }
  2226. return changedBits | 0;
  2227. }
  2228. }
  2229. function scheduleWorkOnParentPath(parent, renderExpirationTime) {
  2230. // Update the child expiration time of all the ancestors, including
  2231. // the alternates.
  2232. var node = parent;
  2233. while (node !== null) {
  2234. var alternate = node.alternate;
  2235. if (node.childExpirationTime < renderExpirationTime) {
  2236. node.childExpirationTime = renderExpirationTime;
  2237. if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
  2238. alternate.childExpirationTime = renderExpirationTime;
  2239. }
  2240. } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
  2241. alternate.childExpirationTime = renderExpirationTime;
  2242. } else {
  2243. // Neither alternate was updated, which means the rest of the
  2244. // ancestor path already has sufficient priority.
  2245. break;
  2246. }
  2247. node = node.return;
  2248. }
  2249. }
  2250. function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
  2251. var fiber = workInProgress.child;
  2252. if (fiber !== null) {
  2253. // Set the return pointer of the child to the work-in-progress fiber.
  2254. fiber.return = workInProgress;
  2255. }
  2256. while (fiber !== null) {
  2257. var nextFiber = void 0; // Visit this fiber.
  2258. var list = fiber.dependencies;
  2259. if (list !== null) {
  2260. nextFiber = fiber.child;
  2261. var dependency = list.firstContext;
  2262. while (dependency !== null) {
  2263. // Check if the context matches.
  2264. if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
  2265. // Match! Schedule an update on this fiber.
  2266. if (fiber.tag === ClassComponent) {
  2267. // Schedule a force update on the work-in-progress.
  2268. var update = createUpdate(renderExpirationTime, null);
  2269. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  2270. // update to the current fiber, too, which means it will persist even if
  2271. // this render is thrown away. Since it's a race condition, not sure it's
  2272. // worth fixing.
  2273. enqueueUpdate(fiber, update);
  2274. }
  2275. if (fiber.expirationTime < renderExpirationTime) {
  2276. fiber.expirationTime = renderExpirationTime;
  2277. }
  2278. var alternate = fiber.alternate;
  2279. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  2280. alternate.expirationTime = renderExpirationTime;
  2281. }
  2282. scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
  2283. if (list.expirationTime < renderExpirationTime) {
  2284. list.expirationTime = renderExpirationTime;
  2285. } // Since we already found a match, we can stop traversing the
  2286. // dependency list.
  2287. break;
  2288. }
  2289. dependency = dependency.next;
  2290. }
  2291. } else if (fiber.tag === ContextProvider) {
  2292. // Don't scan deeper if this is a matching provider
  2293. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  2294. } else {
  2295. // Traverse down.
  2296. nextFiber = fiber.child;
  2297. }
  2298. if (nextFiber !== null) {
  2299. // Set the return pointer of the child to the work-in-progress fiber.
  2300. nextFiber.return = fiber;
  2301. } else {
  2302. // No child. Traverse to next sibling.
  2303. nextFiber = fiber;
  2304. while (nextFiber !== null) {
  2305. if (nextFiber === workInProgress) {
  2306. // We're back to the root of this subtree. Exit.
  2307. nextFiber = null;
  2308. break;
  2309. }
  2310. var sibling = nextFiber.sibling;
  2311. if (sibling !== null) {
  2312. // Set the return pointer of the sibling to the work-in-progress fiber.
  2313. sibling.return = nextFiber.return;
  2314. nextFiber = sibling;
  2315. break;
  2316. } // No more siblings. Traverse up.
  2317. nextFiber = nextFiber.return;
  2318. }
  2319. }
  2320. fiber = nextFiber;
  2321. }
  2322. }
  2323. function prepareToReadContext(workInProgress, renderExpirationTime) {
  2324. currentlyRenderingFiber = workInProgress;
  2325. lastContextDependency = null;
  2326. lastContextWithAllBitsObserved = null;
  2327. var dependencies = workInProgress.dependencies;
  2328. if (dependencies !== null) {
  2329. var firstContext = dependencies.firstContext;
  2330. if (firstContext !== null) {
  2331. if (dependencies.expirationTime >= renderExpirationTime) {
  2332. // Context list has a pending update. Mark that this fiber performed work.
  2333. markWorkInProgressReceivedUpdate();
  2334. } // Reset the work-in-progress list
  2335. dependencies.firstContext = null;
  2336. }
  2337. }
  2338. }
  2339. function readContext(context, observedBits) {
  2340. {
  2341. // This warning would fire if you read context inside a Hook like useMemo.
  2342. // Unlike the class check below, it's not enforced in production for perf.
  2343. if (isDisallowedContextReadInDEV) {
  2344. 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().');
  2345. }
  2346. }
  2347. if (lastContextWithAllBitsObserved === context) ; else if (observedBits === false || observedBits === 0) ; else {
  2348. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  2349. if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
  2350. // Observe all updates.
  2351. lastContextWithAllBitsObserved = context;
  2352. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  2353. } else {
  2354. resolvedObservedBits = observedBits;
  2355. }
  2356. var contextItem = {
  2357. context: context,
  2358. observedBits: resolvedObservedBits,
  2359. next: null
  2360. };
  2361. if (lastContextDependency === null) {
  2362. if (!(currentlyRenderingFiber !== null)) {
  2363. {
  2364. 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()." );
  2365. }
  2366. } // This is the first dependency for this component. Create a new list.
  2367. lastContextDependency = contextItem;
  2368. currentlyRenderingFiber.dependencies = {
  2369. expirationTime: NoWork,
  2370. firstContext: contextItem,
  2371. responders: null
  2372. };
  2373. } else {
  2374. // Append a new context item.
  2375. lastContextDependency = lastContextDependency.next = contextItem;
  2376. }
  2377. }
  2378. return context._currentValue2;
  2379. }
  2380. var UpdateState = 0;
  2381. var ReplaceState = 1;
  2382. var ForceUpdate = 2;
  2383. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  2384. // It should only be read right after calling `processUpdateQueue`, via
  2385. // `checkHasForceUpdateAfterProcessing`.
  2386. var hasForceUpdate = false;
  2387. var didWarnUpdateInsideUpdate;
  2388. var currentlyProcessingQueue;
  2389. {
  2390. didWarnUpdateInsideUpdate = false;
  2391. currentlyProcessingQueue = null;
  2392. }
  2393. function initializeUpdateQueue(fiber) {
  2394. var queue = {
  2395. baseState: fiber.memoizedState,
  2396. baseQueue: null,
  2397. shared: {
  2398. pending: null
  2399. },
  2400. effects: null
  2401. };
  2402. fiber.updateQueue = queue;
  2403. }
  2404. function cloneUpdateQueue(current, workInProgress) {
  2405. // Clone the update queue from current. Unless it's already a clone.
  2406. var queue = workInProgress.updateQueue;
  2407. var currentQueue = current.updateQueue;
  2408. if (queue === currentQueue) {
  2409. var clone = {
  2410. baseState: currentQueue.baseState,
  2411. baseQueue: currentQueue.baseQueue,
  2412. shared: currentQueue.shared,
  2413. effects: currentQueue.effects
  2414. };
  2415. workInProgress.updateQueue = clone;
  2416. }
  2417. }
  2418. function createUpdate(expirationTime, suspenseConfig) {
  2419. var update = {
  2420. expirationTime: expirationTime,
  2421. suspenseConfig: suspenseConfig,
  2422. tag: UpdateState,
  2423. payload: null,
  2424. callback: null,
  2425. next: null
  2426. };
  2427. update.next = update;
  2428. {
  2429. update.priority = getCurrentPriorityLevel();
  2430. }
  2431. return update;
  2432. }
  2433. function enqueueUpdate(fiber, update) {
  2434. var updateQueue = fiber.updateQueue;
  2435. if (updateQueue === null) {
  2436. // Only occurs if the fiber has been unmounted.
  2437. return;
  2438. }
  2439. var sharedQueue = updateQueue.shared;
  2440. var pending = sharedQueue.pending;
  2441. if (pending === null) {
  2442. // This is the first update. Create a circular list.
  2443. update.next = update;
  2444. } else {
  2445. update.next = pending.next;
  2446. pending.next = update;
  2447. }
  2448. sharedQueue.pending = update;
  2449. {
  2450. if (currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate) {
  2451. 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.');
  2452. didWarnUpdateInsideUpdate = true;
  2453. }
  2454. }
  2455. }
  2456. function enqueueCapturedUpdate(workInProgress, update) {
  2457. var current = workInProgress.alternate;
  2458. if (current !== null) {
  2459. // Ensure the work-in-progress queue is a clone
  2460. cloneUpdateQueue(current, workInProgress);
  2461. } // Captured updates go only on the work-in-progress queue.
  2462. var queue = workInProgress.updateQueue; // Append the update to the end of the list.
  2463. var last = queue.baseQueue;
  2464. if (last === null) {
  2465. queue.baseQueue = update.next = update;
  2466. update.next = update;
  2467. } else {
  2468. update.next = last.next;
  2469. last.next = update;
  2470. }
  2471. }
  2472. function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
  2473. switch (update.tag) {
  2474. case ReplaceState:
  2475. {
  2476. var payload = update.payload;
  2477. if (typeof payload === 'function') {
  2478. // Updater function
  2479. {
  2480. enterDisallowedContextReadInDEV();
  2481. }
  2482. var nextState = payload.call(instance, prevState, nextProps);
  2483. {
  2484. exitDisallowedContextReadInDEV();
  2485. }
  2486. return nextState;
  2487. } // State object
  2488. return payload;
  2489. }
  2490. case CaptureUpdate:
  2491. {
  2492. workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
  2493. }
  2494. // Intentional fallthrough
  2495. case UpdateState:
  2496. {
  2497. var _payload = update.payload;
  2498. var partialState;
  2499. if (typeof _payload === 'function') {
  2500. // Updater function
  2501. {
  2502. enterDisallowedContextReadInDEV();
  2503. }
  2504. partialState = _payload.call(instance, prevState, nextProps);
  2505. {
  2506. exitDisallowedContextReadInDEV();
  2507. }
  2508. } else {
  2509. // Partial state object
  2510. partialState = _payload;
  2511. }
  2512. if (partialState === null || partialState === undefined) {
  2513. // Null and undefined are treated as no-ops.
  2514. return prevState;
  2515. } // Merge the partial state and the previous state.
  2516. return _assign({}, prevState, partialState);
  2517. }
  2518. case ForceUpdate:
  2519. {
  2520. hasForceUpdate = true;
  2521. return prevState;
  2522. }
  2523. }
  2524. return prevState;
  2525. }
  2526. function processUpdateQueue(workInProgress, props, instance, renderExpirationTime) {
  2527. // This is always non-null on a ClassComponent or HostRoot
  2528. var queue = workInProgress.updateQueue;
  2529. hasForceUpdate = false;
  2530. {
  2531. currentlyProcessingQueue = queue.shared;
  2532. } // The last rebase update that is NOT part of the base state.
  2533. var baseQueue = queue.baseQueue; // The last pending update that hasn't been processed yet.
  2534. var pendingQueue = queue.shared.pending;
  2535. if (pendingQueue !== null) {
  2536. // We have new updates that haven't been processed yet.
  2537. // We'll add them to the base queue.
  2538. if (baseQueue !== null) {
  2539. // Merge the pending queue and the base queue.
  2540. var baseFirst = baseQueue.next;
  2541. var pendingFirst = pendingQueue.next;
  2542. baseQueue.next = pendingFirst;
  2543. pendingQueue.next = baseFirst;
  2544. }
  2545. baseQueue = pendingQueue;
  2546. queue.shared.pending = null; // TODO: Pass `current` as argument
  2547. var current = workInProgress.alternate;
  2548. if (current !== null) {
  2549. var currentQueue = current.updateQueue;
  2550. if (currentQueue !== null) {
  2551. currentQueue.baseQueue = pendingQueue;
  2552. }
  2553. }
  2554. } // These values may change as we process the queue.
  2555. if (baseQueue !== null) {
  2556. var first = baseQueue.next; // Iterate through the list of updates to compute the result.
  2557. var newState = queue.baseState;
  2558. var newExpirationTime = NoWork;
  2559. var newBaseState = null;
  2560. var newBaseQueueFirst = null;
  2561. var newBaseQueueLast = null;
  2562. if (first !== null) {
  2563. var update = first;
  2564. do {
  2565. var updateExpirationTime = update.expirationTime;
  2566. if (updateExpirationTime < renderExpirationTime) {
  2567. // Priority is insufficient. Skip this update. If this is the first
  2568. // skipped update, the previous update/state is the new base
  2569. // update/state.
  2570. var clone = {
  2571. expirationTime: update.expirationTime,
  2572. suspenseConfig: update.suspenseConfig,
  2573. tag: update.tag,
  2574. payload: update.payload,
  2575. callback: update.callback,
  2576. next: null
  2577. };
  2578. if (newBaseQueueLast === null) {
  2579. newBaseQueueFirst = newBaseQueueLast = clone;
  2580. newBaseState = newState;
  2581. } else {
  2582. newBaseQueueLast = newBaseQueueLast.next = clone;
  2583. } // Update the remaining priority in the queue.
  2584. if (updateExpirationTime > newExpirationTime) {
  2585. newExpirationTime = updateExpirationTime;
  2586. }
  2587. } else {
  2588. // This update does have sufficient priority.
  2589. if (newBaseQueueLast !== null) {
  2590. var _clone = {
  2591. expirationTime: Sync,
  2592. // This update is going to be committed so we never want uncommit it.
  2593. suspenseConfig: update.suspenseConfig,
  2594. tag: update.tag,
  2595. payload: update.payload,
  2596. callback: update.callback,
  2597. next: null
  2598. };
  2599. newBaseQueueLast = newBaseQueueLast.next = _clone;
  2600. } // Mark the event time of this update as relevant to this render pass.
  2601. // TODO: This should ideally use the true event time of this update rather than
  2602. // its priority which is a derived and not reverseable value.
  2603. // TODO: We should skip this update if it was already committed but currently
  2604. // we have no way of detecting the difference between a committed and suspended
  2605. // update here.
  2606. markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process this update.
  2607. newState = getStateFromUpdate(workInProgress, queue, update, newState, props, instance);
  2608. var callback = update.callback;
  2609. if (callback !== null) {
  2610. workInProgress.effectTag |= Callback;
  2611. var effects = queue.effects;
  2612. if (effects === null) {
  2613. queue.effects = [update];
  2614. } else {
  2615. effects.push(update);
  2616. }
  2617. }
  2618. }
  2619. update = update.next;
  2620. if (update === null || update === first) {
  2621. pendingQueue = queue.shared.pending;
  2622. if (pendingQueue === null) {
  2623. break;
  2624. } else {
  2625. // An update was scheduled from inside a reducer. Add the new
  2626. // pending updates to the end of the list and keep processing.
  2627. update = baseQueue.next = pendingQueue.next;
  2628. pendingQueue.next = first;
  2629. queue.baseQueue = baseQueue = pendingQueue;
  2630. queue.shared.pending = null;
  2631. }
  2632. }
  2633. } while (true);
  2634. }
  2635. if (newBaseQueueLast === null) {
  2636. newBaseState = newState;
  2637. } else {
  2638. newBaseQueueLast.next = newBaseQueueFirst;
  2639. }
  2640. queue.baseState = newBaseState;
  2641. queue.baseQueue = newBaseQueueLast; // Set the remaining expiration time to be whatever is remaining in the queue.
  2642. // This should be fine because the only two other things that contribute to
  2643. // expiration time are props and context. We're already in the middle of the
  2644. // begin phase by the time we start processing the queue, so we've already
  2645. // dealt with the props. Context in components that specify
  2646. // shouldComponentUpdate is tricky; but we'll have to account for
  2647. // that regardless.
  2648. markUnprocessedUpdateTime(newExpirationTime);
  2649. workInProgress.expirationTime = newExpirationTime;
  2650. workInProgress.memoizedState = newState;
  2651. }
  2652. {
  2653. currentlyProcessingQueue = null;
  2654. }
  2655. }
  2656. function callCallback(callback, context) {
  2657. if (!(typeof callback === 'function')) {
  2658. {
  2659. throw Error( "Invalid argument passed as callback. Expected a function. Instead received: " + callback );
  2660. }
  2661. }
  2662. callback.call(context);
  2663. }
  2664. function resetHasForceUpdateBeforeProcessing() {
  2665. hasForceUpdate = false;
  2666. }
  2667. function checkHasForceUpdateAfterProcessing() {
  2668. return hasForceUpdate;
  2669. }
  2670. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  2671. // Commit the effects
  2672. var effects = finishedQueue.effects;
  2673. finishedQueue.effects = null;
  2674. if (effects !== null) {
  2675. for (var i = 0; i < effects.length; i++) {
  2676. var effect = effects[i];
  2677. var callback = effect.callback;
  2678. if (callback !== null) {
  2679. effect.callback = null;
  2680. callCallback(callback, instance);
  2681. }
  2682. }
  2683. }
  2684. }
  2685. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  2686. function requestCurrentSuspenseConfig() {
  2687. return ReactCurrentBatchConfig.suspense;
  2688. }
  2689. var fakeInternalInstance = {};
  2690. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  2691. // We'll use it to determine whether we need to initialize legacy refs.
  2692. var emptyRefsObject = new React.Component().refs;
  2693. var didWarnAboutStateAssignmentForComponent;
  2694. var didWarnAboutUninitializedState;
  2695. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  2696. var didWarnAboutLegacyLifecyclesAndDerivedState;
  2697. var didWarnAboutUndefinedDerivedState;
  2698. var warnOnUndefinedDerivedState;
  2699. var warnOnInvalidCallback;
  2700. var didWarnAboutDirectlyAssigningPropsToState;
  2701. var didWarnAboutContextTypeAndContextTypes;
  2702. var didWarnAboutInvalidateContextType;
  2703. {
  2704. didWarnAboutStateAssignmentForComponent = new Set();
  2705. didWarnAboutUninitializedState = new Set();
  2706. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  2707. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  2708. didWarnAboutDirectlyAssigningPropsToState = new Set();
  2709. didWarnAboutUndefinedDerivedState = new Set();
  2710. didWarnAboutContextTypeAndContextTypes = new Set();
  2711. didWarnAboutInvalidateContextType = new Set();
  2712. var didWarnOnInvalidCallback = new Set();
  2713. warnOnInvalidCallback = function (callback, callerName) {
  2714. if (callback === null || typeof callback === 'function') {
  2715. return;
  2716. }
  2717. var key = callerName + "_" + callback;
  2718. if (!didWarnOnInvalidCallback.has(key)) {
  2719. didWarnOnInvalidCallback.add(key);
  2720. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  2721. }
  2722. };
  2723. warnOnUndefinedDerivedState = function (type, partialState) {
  2724. if (partialState === undefined) {
  2725. var componentName = getComponentName(type) || 'Component';
  2726. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  2727. didWarnAboutUndefinedDerivedState.add(componentName);
  2728. error('%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
  2729. }
  2730. }
  2731. }; // This is so gross but it's at least non-critical and can be removed if
  2732. // it causes problems. This is meant to give a nicer error message for
  2733. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  2734. // ...)) which otherwise throws a "_processChildContext is not a function"
  2735. // exception.
  2736. Object.defineProperty(fakeInternalInstance, '_processChildContext', {
  2737. enumerable: false,
  2738. value: function () {
  2739. {
  2740. {
  2741. 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)." );
  2742. }
  2743. }
  2744. }
  2745. });
  2746. Object.freeze(fakeInternalInstance);
  2747. }
  2748. function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
  2749. var prevState = workInProgress.memoizedState;
  2750. var partialState = getDerivedStateFromProps(nextProps, prevState);
  2751. {
  2752. warnOnUndefinedDerivedState(ctor, partialState);
  2753. } // Merge the partial state and the previous state.
  2754. var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
  2755. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  2756. // base state.
  2757. if (workInProgress.expirationTime === NoWork) {
  2758. // Queue is always non-null for classes
  2759. var updateQueue = workInProgress.updateQueue;
  2760. updateQueue.baseState = memoizedState;
  2761. }
  2762. }
  2763. var classComponentUpdater = {
  2764. isMounted: isMounted,
  2765. enqueueSetState: function (inst, payload, callback) {
  2766. var fiber = get(inst);
  2767. var currentTime = requestCurrentTimeForUpdate();
  2768. var suspenseConfig = requestCurrentSuspenseConfig();
  2769. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  2770. var update = createUpdate(expirationTime, suspenseConfig);
  2771. update.payload = payload;
  2772. if (callback !== undefined && callback !== null) {
  2773. {
  2774. warnOnInvalidCallback(callback, 'setState');
  2775. }
  2776. update.callback = callback;
  2777. }
  2778. enqueueUpdate(fiber, update);
  2779. scheduleWork(fiber, expirationTime);
  2780. },
  2781. enqueueReplaceState: function (inst, payload, callback) {
  2782. var fiber = get(inst);
  2783. var currentTime = requestCurrentTimeForUpdate();
  2784. var suspenseConfig = requestCurrentSuspenseConfig();
  2785. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  2786. var update = createUpdate(expirationTime, suspenseConfig);
  2787. update.tag = ReplaceState;
  2788. update.payload = payload;
  2789. if (callback !== undefined && callback !== null) {
  2790. {
  2791. warnOnInvalidCallback(callback, 'replaceState');
  2792. }
  2793. update.callback = callback;
  2794. }
  2795. enqueueUpdate(fiber, update);
  2796. scheduleWork(fiber, expirationTime);
  2797. },
  2798. enqueueForceUpdate: function (inst, callback) {
  2799. var fiber = get(inst);
  2800. var currentTime = requestCurrentTimeForUpdate();
  2801. var suspenseConfig = requestCurrentSuspenseConfig();
  2802. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  2803. var update = createUpdate(expirationTime, suspenseConfig);
  2804. update.tag = ForceUpdate;
  2805. if (callback !== undefined && callback !== null) {
  2806. {
  2807. warnOnInvalidCallback(callback, 'forceUpdate');
  2808. }
  2809. update.callback = callback;
  2810. }
  2811. enqueueUpdate(fiber, update);
  2812. scheduleWork(fiber, expirationTime);
  2813. }
  2814. };
  2815. function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
  2816. var instance = workInProgress.stateNode;
  2817. if (typeof instance.shouldComponentUpdate === 'function') {
  2818. startPhaseTimer(workInProgress, 'shouldComponentUpdate');
  2819. var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
  2820. stopPhaseTimer();
  2821. {
  2822. if (shouldUpdate === undefined) {
  2823. error('%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(ctor) || 'Component');
  2824. }
  2825. }
  2826. return shouldUpdate;
  2827. }
  2828. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  2829. return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
  2830. }
  2831. return true;
  2832. }
  2833. function checkClassInstance(workInProgress, ctor, newProps) {
  2834. var instance = workInProgress.stateNode;
  2835. {
  2836. var name = getComponentName(ctor) || 'Component';
  2837. var renderPresent = instance.render;
  2838. if (!renderPresent) {
  2839. if (ctor.prototype && typeof ctor.prototype.render === 'function') {
  2840. error('%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
  2841. } else {
  2842. error('%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
  2843. }
  2844. }
  2845. if (instance.getInitialState && !instance.getInitialState.isReactClassApproved && !instance.state) {
  2846. 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);
  2847. }
  2848. if (instance.getDefaultProps && !instance.getDefaultProps.isReactClassApproved) {
  2849. 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);
  2850. }
  2851. if (instance.propTypes) {
  2852. error('propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name);
  2853. }
  2854. if (instance.contextType) {
  2855. error('contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name);
  2856. }
  2857. {
  2858. if (instance.contextTypes) {
  2859. error('contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name);
  2860. }
  2861. if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
  2862. didWarnAboutContextTypeAndContextTypes.add(ctor);
  2863. error('%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
  2864. }
  2865. }
  2866. if (typeof instance.componentShouldUpdate === 'function') {
  2867. 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);
  2868. }
  2869. if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
  2870. 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');
  2871. }
  2872. if (typeof instance.componentDidUnmount === 'function') {
  2873. error('%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name);
  2874. }
  2875. if (typeof instance.componentDidReceiveProps === 'function') {
  2876. 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);
  2877. }
  2878. if (typeof instance.componentWillRecieveProps === 'function') {
  2879. error('%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name);
  2880. }
  2881. if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') {
  2882. error('%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name);
  2883. }
  2884. var hasMutatedProps = instance.props !== newProps;
  2885. if (instance.props !== undefined && hasMutatedProps) {
  2886. error('%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, name);
  2887. }
  2888. if (instance.defaultProps) {
  2889. 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);
  2890. }
  2891. if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
  2892. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  2893. error('%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
  2894. }
  2895. if (typeof instance.getDerivedStateFromProps === 'function') {
  2896. error('%s: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  2897. }
  2898. if (typeof instance.getDerivedStateFromError === 'function') {
  2899. error('%s: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  2900. }
  2901. if (typeof ctor.getSnapshotBeforeUpdate === 'function') {
  2902. error('%s: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', name);
  2903. }
  2904. var _state = instance.state;
  2905. if (_state && (typeof _state !== 'object' || isArray(_state))) {
  2906. error('%s.state: must be set to an object or null', name);
  2907. }
  2908. if (typeof instance.getChildContext === 'function' && typeof ctor.childContextTypes !== 'object') {
  2909. error('%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name);
  2910. }
  2911. }
  2912. }
  2913. function adoptClassInstance(workInProgress, instance) {
  2914. instance.updater = classComponentUpdater;
  2915. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  2916. set(instance, workInProgress);
  2917. {
  2918. instance._reactInternalInstance = fakeInternalInstance;
  2919. }
  2920. }
  2921. function constructClassInstance(workInProgress, ctor, props) {
  2922. var isLegacyContextConsumer = false;
  2923. var unmaskedContext = emptyContextObject;
  2924. var context = emptyContextObject;
  2925. var contextType = ctor.contextType;
  2926. {
  2927. if ('contextType' in ctor) {
  2928. var isValid = // Allow null for conditional declaration
  2929. contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
  2930. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  2931. didWarnAboutInvalidateContextType.add(ctor);
  2932. var addendum = '';
  2933. if (contextType === undefined) {
  2934. 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.';
  2935. } else if (typeof contextType !== 'object') {
  2936. addendum = ' However, it is set to a ' + typeof contextType + '.';
  2937. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  2938. addendum = ' Did you accidentally pass the Context.Provider instead?';
  2939. } else if (contextType._context !== undefined) {
  2940. // <Context.Consumer>
  2941. addendum = ' Did you accidentally pass the Context.Consumer instead?';
  2942. } else {
  2943. addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
  2944. }
  2945. error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
  2946. }
  2947. }
  2948. }
  2949. if (typeof contextType === 'object' && contextType !== null) {
  2950. context = readContext(contextType);
  2951. } else {
  2952. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  2953. var contextTypes = ctor.contextTypes;
  2954. isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
  2955. context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
  2956. } // Instantiate twice to help detect side-effects.
  2957. var instance = new ctor(props, context);
  2958. var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
  2959. adoptClassInstance(workInProgress, instance);
  2960. {
  2961. if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
  2962. var componentName = getComponentName(ctor) || 'Component';
  2963. if (!didWarnAboutUninitializedState.has(componentName)) {
  2964. didWarnAboutUninitializedState.add(componentName);
  2965. 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);
  2966. }
  2967. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  2968. // Warn about these lifecycles if they are present.
  2969. // Don't warn about react-lifecycles-compat polyfilled methods though.
  2970. if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
  2971. var foundWillMountName = null;
  2972. var foundWillReceivePropsName = null;
  2973. var foundWillUpdateName = null;
  2974. if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
  2975. foundWillMountName = 'componentWillMount';
  2976. } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
  2977. foundWillMountName = 'UNSAFE_componentWillMount';
  2978. }
  2979. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  2980. foundWillReceivePropsName = 'componentWillReceiveProps';
  2981. } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  2982. foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
  2983. }
  2984. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  2985. foundWillUpdateName = 'componentWillUpdate';
  2986. } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  2987. foundWillUpdateName = 'UNSAFE_componentWillUpdate';
  2988. }
  2989. if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
  2990. var _componentName = getComponentName(ctor) || 'Component';
  2991. var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
  2992. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  2993. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  2994. 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 : '');
  2995. }
  2996. }
  2997. }
  2998. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  2999. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  3000. if (isLegacyContextConsumer) {
  3001. cacheContext(workInProgress, unmaskedContext, context);
  3002. }
  3003. return instance;
  3004. }
  3005. function callComponentWillMount(workInProgress, instance) {
  3006. startPhaseTimer(workInProgress, 'componentWillMount');
  3007. var oldState = instance.state;
  3008. if (typeof instance.componentWillMount === 'function') {
  3009. instance.componentWillMount();
  3010. }
  3011. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  3012. instance.UNSAFE_componentWillMount();
  3013. }
  3014. stopPhaseTimer();
  3015. if (oldState !== instance.state) {
  3016. {
  3017. error('%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + 'constructor). Use setState instead.', getComponentName(workInProgress.type) || 'Component');
  3018. }
  3019. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  3020. }
  3021. }
  3022. function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
  3023. var oldState = instance.state;
  3024. startPhaseTimer(workInProgress, 'componentWillReceiveProps');
  3025. if (typeof instance.componentWillReceiveProps === 'function') {
  3026. instance.componentWillReceiveProps(newProps, nextContext);
  3027. }
  3028. if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  3029. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  3030. }
  3031. stopPhaseTimer();
  3032. if (instance.state !== oldState) {
  3033. {
  3034. var componentName = getComponentName(workInProgress.type) || 'Component';
  3035. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  3036. didWarnAboutStateAssignmentForComponent.add(componentName);
  3037. error('%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
  3038. }
  3039. }
  3040. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  3041. }
  3042. } // Invokes the mount life-cycles on a previously never rendered instance.
  3043. function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
  3044. {
  3045. checkClassInstance(workInProgress, ctor, newProps);
  3046. }
  3047. var instance = workInProgress.stateNode;
  3048. instance.props = newProps;
  3049. instance.state = workInProgress.memoizedState;
  3050. instance.refs = emptyRefsObject;
  3051. initializeUpdateQueue(workInProgress);
  3052. var contextType = ctor.contextType;
  3053. if (typeof contextType === 'object' && contextType !== null) {
  3054. instance.context = readContext(contextType);
  3055. } else {
  3056. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  3057. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  3058. }
  3059. {
  3060. if (instance.state === newProps) {
  3061. var componentName = getComponentName(ctor) || 'Component';
  3062. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  3063. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  3064. 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);
  3065. }
  3066. }
  3067. if (workInProgress.mode & StrictMode) {
  3068. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
  3069. }
  3070. {
  3071. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
  3072. }
  3073. }
  3074. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3075. instance.state = workInProgress.memoizedState;
  3076. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  3077. if (typeof getDerivedStateFromProps === 'function') {
  3078. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  3079. instance.state = workInProgress.memoizedState;
  3080. } // In order to support react-lifecycles-compat polyfilled components,
  3081. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3082. if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  3083. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  3084. // process them now.
  3085. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3086. instance.state = workInProgress.memoizedState;
  3087. }
  3088. if (typeof instance.componentDidMount === 'function') {
  3089. workInProgress.effectTag |= Update;
  3090. }
  3091. }
  3092. function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
  3093. var instance = workInProgress.stateNode;
  3094. var oldProps = workInProgress.memoizedProps;
  3095. instance.props = oldProps;
  3096. var oldContext = instance.context;
  3097. var contextType = ctor.contextType;
  3098. var nextContext = emptyContextObject;
  3099. if (typeof contextType === 'object' && contextType !== null) {
  3100. nextContext = readContext(contextType);
  3101. } else {
  3102. var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  3103. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  3104. }
  3105. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  3106. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  3107. // ever the previously attempted to render - not the "current". However,
  3108. // during componentDidUpdate we pass the "current" props.
  3109. // In order to support react-lifecycles-compat polyfilled components,
  3110. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3111. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  3112. if (oldProps !== newProps || oldContext !== nextContext) {
  3113. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  3114. }
  3115. }
  3116. resetHasForceUpdateBeforeProcessing();
  3117. var oldState = workInProgress.memoizedState;
  3118. var newState = instance.state = oldState;
  3119. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3120. newState = workInProgress.memoizedState;
  3121. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  3122. // If an update was already in progress, we should schedule an Update
  3123. // effect even though we're bailing out, so that cWU/cDU are called.
  3124. if (typeof instance.componentDidMount === 'function') {
  3125. workInProgress.effectTag |= Update;
  3126. }
  3127. return false;
  3128. }
  3129. if (typeof getDerivedStateFromProps === 'function') {
  3130. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  3131. newState = workInProgress.memoizedState;
  3132. }
  3133. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  3134. if (shouldUpdate) {
  3135. // In order to support react-lifecycles-compat polyfilled components,
  3136. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3137. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  3138. startPhaseTimer(workInProgress, 'componentWillMount');
  3139. if (typeof instance.componentWillMount === 'function') {
  3140. instance.componentWillMount();
  3141. }
  3142. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  3143. instance.UNSAFE_componentWillMount();
  3144. }
  3145. stopPhaseTimer();
  3146. }
  3147. if (typeof instance.componentDidMount === 'function') {
  3148. workInProgress.effectTag |= Update;
  3149. }
  3150. } else {
  3151. // If an update was already in progress, we should schedule an Update
  3152. // effect even though we're bailing out, so that cWU/cDU are called.
  3153. if (typeof instance.componentDidMount === 'function') {
  3154. workInProgress.effectTag |= Update;
  3155. } // If shouldComponentUpdate returned false, we should still update the
  3156. // memoized state to indicate that this work can be reused.
  3157. workInProgress.memoizedProps = newProps;
  3158. workInProgress.memoizedState = newState;
  3159. } // Update the existing instance's state, props, and context pointers even
  3160. // if shouldComponentUpdate returns false.
  3161. instance.props = newProps;
  3162. instance.state = newState;
  3163. instance.context = nextContext;
  3164. return shouldUpdate;
  3165. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  3166. function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
  3167. var instance = workInProgress.stateNode;
  3168. cloneUpdateQueue(current, workInProgress);
  3169. var oldProps = workInProgress.memoizedProps;
  3170. instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
  3171. var oldContext = instance.context;
  3172. var contextType = ctor.contextType;
  3173. var nextContext = emptyContextObject;
  3174. if (typeof contextType === 'object' && contextType !== null) {
  3175. nextContext = readContext(contextType);
  3176. } else {
  3177. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  3178. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  3179. }
  3180. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  3181. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  3182. // ever the previously attempted to render - not the "current". However,
  3183. // during componentDidUpdate we pass the "current" props.
  3184. // In order to support react-lifecycles-compat polyfilled components,
  3185. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3186. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  3187. if (oldProps !== newProps || oldContext !== nextContext) {
  3188. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  3189. }
  3190. }
  3191. resetHasForceUpdateBeforeProcessing();
  3192. var oldState = workInProgress.memoizedState;
  3193. var newState = instance.state = oldState;
  3194. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  3195. newState = workInProgress.memoizedState;
  3196. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  3197. // If an update was already in progress, we should schedule an Update
  3198. // effect even though we're bailing out, so that cWU/cDU are called.
  3199. if (typeof instance.componentDidUpdate === 'function') {
  3200. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3201. workInProgress.effectTag |= Update;
  3202. }
  3203. }
  3204. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  3205. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3206. workInProgress.effectTag |= Snapshot;
  3207. }
  3208. }
  3209. return false;
  3210. }
  3211. if (typeof getDerivedStateFromProps === 'function') {
  3212. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  3213. newState = workInProgress.memoizedState;
  3214. }
  3215. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  3216. if (shouldUpdate) {
  3217. // In order to support react-lifecycles-compat polyfilled components,
  3218. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3219. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
  3220. startPhaseTimer(workInProgress, 'componentWillUpdate');
  3221. if (typeof instance.componentWillUpdate === 'function') {
  3222. instance.componentWillUpdate(newProps, newState, nextContext);
  3223. }
  3224. if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  3225. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  3226. }
  3227. stopPhaseTimer();
  3228. }
  3229. if (typeof instance.componentDidUpdate === 'function') {
  3230. workInProgress.effectTag |= Update;
  3231. }
  3232. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  3233. workInProgress.effectTag |= Snapshot;
  3234. }
  3235. } else {
  3236. // If an update was already in progress, we should schedule an Update
  3237. // effect even though we're bailing out, so that cWU/cDU are called.
  3238. if (typeof instance.componentDidUpdate === 'function') {
  3239. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3240. workInProgress.effectTag |= Update;
  3241. }
  3242. }
  3243. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  3244. if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  3245. workInProgress.effectTag |= Snapshot;
  3246. }
  3247. } // If shouldComponentUpdate returned false, we should still update the
  3248. // memoized props/state to indicate that this work can be reused.
  3249. workInProgress.memoizedProps = newProps;
  3250. workInProgress.memoizedState = newState;
  3251. } // Update the existing instance's state, props, and context pointers even
  3252. // if shouldComponentUpdate returns false.
  3253. instance.props = newProps;
  3254. instance.state = newState;
  3255. instance.context = nextContext;
  3256. return shouldUpdate;
  3257. }
  3258. var didWarnAboutMaps;
  3259. var didWarnAboutGenerators;
  3260. var didWarnAboutStringRefs;
  3261. var ownerHasKeyUseWarning;
  3262. var ownerHasFunctionTypeWarning;
  3263. var warnForMissingKey = function (child) {};
  3264. {
  3265. didWarnAboutMaps = false;
  3266. didWarnAboutGenerators = false;
  3267. didWarnAboutStringRefs = {};
  3268. /**
  3269. * Warn if there's no key explicitly set on dynamic arrays of children or
  3270. * object keys are not valid. This allows us to keep track of children between
  3271. * updates.
  3272. */
  3273. ownerHasKeyUseWarning = {};
  3274. ownerHasFunctionTypeWarning = {};
  3275. warnForMissingKey = function (child) {
  3276. if (child === null || typeof child !== 'object') {
  3277. return;
  3278. }
  3279. if (!child._store || child._store.validated || child.key != null) {
  3280. return;
  3281. }
  3282. if (!(typeof child._store === 'object')) {
  3283. {
  3284. throw Error( "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue." );
  3285. }
  3286. }
  3287. child._store.validated = true;
  3288. var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
  3289. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  3290. return;
  3291. }
  3292. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  3293. error('Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
  3294. };
  3295. }
  3296. var isArray$1 = Array.isArray;
  3297. function coerceRef(returnFiber, current, element) {
  3298. var mixedRef = element.ref;
  3299. if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
  3300. {
  3301. // TODO: Clean this up once we turn on the string ref warning for
  3302. // everyone, because the strict mode case will no longer be relevant
  3303. if ((returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  3304. // because these cannot be automatically converted to an arrow function
  3305. // using a codemod. Therefore, we don't have to warn about string refs again.
  3306. !(element._owner && element._self && element._owner.stateNode !== element._self)) {
  3307. var componentName = getComponentName(returnFiber.type) || 'Component';
  3308. if (!didWarnAboutStringRefs[componentName]) {
  3309. {
  3310. 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));
  3311. }
  3312. didWarnAboutStringRefs[componentName] = true;
  3313. }
  3314. }
  3315. }
  3316. if (element._owner) {
  3317. var owner = element._owner;
  3318. var inst;
  3319. if (owner) {
  3320. var ownerFiber = owner;
  3321. if (!(ownerFiber.tag === ClassComponent)) {
  3322. {
  3323. 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" );
  3324. }
  3325. }
  3326. inst = ownerFiber.stateNode;
  3327. }
  3328. if (!inst) {
  3329. {
  3330. throw Error( "Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue." );
  3331. }
  3332. }
  3333. var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
  3334. if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) {
  3335. return current.ref;
  3336. }
  3337. var ref = function (value) {
  3338. var refs = inst.refs;
  3339. if (refs === emptyRefsObject) {
  3340. // This is a lazy pooled frozen object, so we need to initialize.
  3341. refs = inst.refs = {};
  3342. }
  3343. if (value === null) {
  3344. delete refs[stringRef];
  3345. } else {
  3346. refs[stringRef] = value;
  3347. }
  3348. };
  3349. ref._stringRef = stringRef;
  3350. return ref;
  3351. } else {
  3352. if (!(typeof mixedRef === 'string')) {
  3353. {
  3354. throw Error( "Expected ref to be a function, a string, an object returned by React.createRef(), or null." );
  3355. }
  3356. }
  3357. if (!element._owner) {
  3358. {
  3359. 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." );
  3360. }
  3361. }
  3362. }
  3363. }
  3364. return mixedRef;
  3365. }
  3366. function throwOnInvalidObjectType(returnFiber, newChild) {
  3367. if (returnFiber.type !== 'textarea') {
  3368. var addendum = '';
  3369. {
  3370. addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
  3371. }
  3372. {
  3373. {
  3374. 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 );
  3375. }
  3376. }
  3377. }
  3378. }
  3379. function warnOnFunctionType() {
  3380. {
  3381. 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();
  3382. if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
  3383. return;
  3384. }
  3385. ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
  3386. 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.');
  3387. }
  3388. } // This wrapper function exists because I expect to clone the code in each path
  3389. // to be able to optimize each path individually by branching early. This needs
  3390. // a compiler or we can do it manually. Helpers that don't need this branching
  3391. // live outside of this function.
  3392. function ChildReconciler(shouldTrackSideEffects) {
  3393. function deleteChild(returnFiber, childToDelete) {
  3394. if (!shouldTrackSideEffects) {
  3395. // Noop.
  3396. return;
  3397. } // Deletions are added in reversed order so we add it to the front.
  3398. // At this point, the return fiber's effect list is empty except for
  3399. // deletions, so we can just append the deletion to the list. The remaining
  3400. // effects aren't added until the complete phase. Once we implement
  3401. // resuming, this may not be true.
  3402. var last = returnFiber.lastEffect;
  3403. if (last !== null) {
  3404. last.nextEffect = childToDelete;
  3405. returnFiber.lastEffect = childToDelete;
  3406. } else {
  3407. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  3408. }
  3409. childToDelete.nextEffect = null;
  3410. childToDelete.effectTag = Deletion;
  3411. }
  3412. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  3413. if (!shouldTrackSideEffects) {
  3414. // Noop.
  3415. return null;
  3416. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  3417. // assuming that after the first child we've already added everything.
  3418. var childToDelete = currentFirstChild;
  3419. while (childToDelete !== null) {
  3420. deleteChild(returnFiber, childToDelete);
  3421. childToDelete = childToDelete.sibling;
  3422. }
  3423. return null;
  3424. }
  3425. function mapRemainingChildren(returnFiber, currentFirstChild) {
  3426. // Add the remaining children to a temporary map so that we can find them by
  3427. // keys quickly. Implicit (null) keys get added to this set with their index
  3428. // instead.
  3429. var existingChildren = new Map();
  3430. var existingChild = currentFirstChild;
  3431. while (existingChild !== null) {
  3432. if (existingChild.key !== null) {
  3433. existingChildren.set(existingChild.key, existingChild);
  3434. } else {
  3435. existingChildren.set(existingChild.index, existingChild);
  3436. }
  3437. existingChild = existingChild.sibling;
  3438. }
  3439. return existingChildren;
  3440. }
  3441. function useFiber(fiber, pendingProps) {
  3442. // We currently set sibling to null and index to 0 here because it is easy
  3443. // to forget to do before returning it. E.g. for the single child case.
  3444. var clone = createWorkInProgress(fiber, pendingProps);
  3445. clone.index = 0;
  3446. clone.sibling = null;
  3447. return clone;
  3448. }
  3449. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  3450. newFiber.index = newIndex;
  3451. if (!shouldTrackSideEffects) {
  3452. // Noop.
  3453. return lastPlacedIndex;
  3454. }
  3455. var current = newFiber.alternate;
  3456. if (current !== null) {
  3457. var oldIndex = current.index;
  3458. if (oldIndex < lastPlacedIndex) {
  3459. // This is a move.
  3460. newFiber.effectTag = Placement;
  3461. return lastPlacedIndex;
  3462. } else {
  3463. // This item can stay in place.
  3464. return oldIndex;
  3465. }
  3466. } else {
  3467. // This is an insertion.
  3468. newFiber.effectTag = Placement;
  3469. return lastPlacedIndex;
  3470. }
  3471. }
  3472. function placeSingleChild(newFiber) {
  3473. // This is simpler for the single child case. We only need to do a
  3474. // placement for inserting new children.
  3475. if (shouldTrackSideEffects && newFiber.alternate === null) {
  3476. newFiber.effectTag = Placement;
  3477. }
  3478. return newFiber;
  3479. }
  3480. function updateTextNode(returnFiber, current, textContent, expirationTime) {
  3481. if (current === null || current.tag !== HostText) {
  3482. // Insert
  3483. var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
  3484. created.return = returnFiber;
  3485. return created;
  3486. } else {
  3487. // Update
  3488. var existing = useFiber(current, textContent);
  3489. existing.return = returnFiber;
  3490. return existing;
  3491. }
  3492. }
  3493. function updateElement(returnFiber, current, element, expirationTime) {
  3494. if (current !== null) {
  3495. if (current.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  3496. isCompatibleFamilyForHotReloading(current, element) )) {
  3497. // Move based on index
  3498. var existing = useFiber(current, element.props);
  3499. existing.ref = coerceRef(returnFiber, current, element);
  3500. existing.return = returnFiber;
  3501. {
  3502. existing._debugSource = element._source;
  3503. existing._debugOwner = element._owner;
  3504. }
  3505. return existing;
  3506. }
  3507. } // Insert
  3508. var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
  3509. created.ref = coerceRef(returnFiber, current, element);
  3510. created.return = returnFiber;
  3511. return created;
  3512. }
  3513. function updatePortal(returnFiber, current, portal, expirationTime) {
  3514. if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {
  3515. // Insert
  3516. var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
  3517. created.return = returnFiber;
  3518. return created;
  3519. } else {
  3520. // Update
  3521. var existing = useFiber(current, portal.children || []);
  3522. existing.return = returnFiber;
  3523. return existing;
  3524. }
  3525. }
  3526. function updateFragment(returnFiber, current, fragment, expirationTime, key) {
  3527. if (current === null || current.tag !== Fragment) {
  3528. // Insert
  3529. var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
  3530. created.return = returnFiber;
  3531. return created;
  3532. } else {
  3533. // Update
  3534. var existing = useFiber(current, fragment);
  3535. existing.return = returnFiber;
  3536. return existing;
  3537. }
  3538. }
  3539. function createChild(returnFiber, newChild, expirationTime) {
  3540. if (typeof newChild === 'string' || typeof newChild === 'number') {
  3541. // Text nodes don't have keys. If the previous node is implicitly keyed
  3542. // we can continue to replace it without aborting even if it is not a text
  3543. // node.
  3544. var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
  3545. created.return = returnFiber;
  3546. return created;
  3547. }
  3548. if (typeof newChild === 'object' && newChild !== null) {
  3549. switch (newChild.$$typeof) {
  3550. case REACT_ELEMENT_TYPE:
  3551. {
  3552. var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
  3553. _created.ref = coerceRef(returnFiber, null, newChild);
  3554. _created.return = returnFiber;
  3555. return _created;
  3556. }
  3557. case REACT_PORTAL_TYPE:
  3558. {
  3559. var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
  3560. _created2.return = returnFiber;
  3561. return _created2;
  3562. }
  3563. }
  3564. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  3565. var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
  3566. _created3.return = returnFiber;
  3567. return _created3;
  3568. }
  3569. throwOnInvalidObjectType(returnFiber, newChild);
  3570. }
  3571. {
  3572. if (typeof newChild === 'function') {
  3573. warnOnFunctionType();
  3574. }
  3575. }
  3576. return null;
  3577. }
  3578. function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
  3579. // Update the fiber if the keys match, otherwise return null.
  3580. var key = oldFiber !== null ? oldFiber.key : null;
  3581. if (typeof newChild === 'string' || typeof newChild === 'number') {
  3582. // Text nodes don't have keys. If the previous node is implicitly keyed
  3583. // we can continue to replace it without aborting even if it is not a text
  3584. // node.
  3585. if (key !== null) {
  3586. return null;
  3587. }
  3588. return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
  3589. }
  3590. if (typeof newChild === 'object' && newChild !== null) {
  3591. switch (newChild.$$typeof) {
  3592. case REACT_ELEMENT_TYPE:
  3593. {
  3594. if (newChild.key === key) {
  3595. if (newChild.type === REACT_FRAGMENT_TYPE) {
  3596. return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
  3597. }
  3598. return updateElement(returnFiber, oldFiber, newChild, expirationTime);
  3599. } else {
  3600. return null;
  3601. }
  3602. }
  3603. case REACT_PORTAL_TYPE:
  3604. {
  3605. if (newChild.key === key) {
  3606. return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
  3607. } else {
  3608. return null;
  3609. }
  3610. }
  3611. }
  3612. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  3613. if (key !== null) {
  3614. return null;
  3615. }
  3616. return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
  3617. }
  3618. throwOnInvalidObjectType(returnFiber, newChild);
  3619. }
  3620. {
  3621. if (typeof newChild === 'function') {
  3622. warnOnFunctionType();
  3623. }
  3624. }
  3625. return null;
  3626. }
  3627. function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
  3628. if (typeof newChild === 'string' || typeof newChild === 'number') {
  3629. // Text nodes don't have keys, so we neither have to check the old nor
  3630. // new node for the key. If both are text nodes, they match.
  3631. var matchedFiber = existingChildren.get(newIdx) || null;
  3632. return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
  3633. }
  3634. if (typeof newChild === 'object' && newChild !== null) {
  3635. switch (newChild.$$typeof) {
  3636. case REACT_ELEMENT_TYPE:
  3637. {
  3638. var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  3639. if (newChild.type === REACT_FRAGMENT_TYPE) {
  3640. return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
  3641. }
  3642. return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
  3643. }
  3644. case REACT_PORTAL_TYPE:
  3645. {
  3646. var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  3647. return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
  3648. }
  3649. }
  3650. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  3651. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  3652. return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
  3653. }
  3654. throwOnInvalidObjectType(returnFiber, newChild);
  3655. }
  3656. {
  3657. if (typeof newChild === 'function') {
  3658. warnOnFunctionType();
  3659. }
  3660. }
  3661. return null;
  3662. }
  3663. /**
  3664. * Warns if there is a duplicate or missing key
  3665. */
  3666. function warnOnInvalidKey(child, knownKeys) {
  3667. {
  3668. if (typeof child !== 'object' || child === null) {
  3669. return knownKeys;
  3670. }
  3671. switch (child.$$typeof) {
  3672. case REACT_ELEMENT_TYPE:
  3673. case REACT_PORTAL_TYPE:
  3674. warnForMissingKey(child);
  3675. var key = child.key;
  3676. if (typeof key !== 'string') {
  3677. break;
  3678. }
  3679. if (knownKeys === null) {
  3680. knownKeys = new Set();
  3681. knownKeys.add(key);
  3682. break;
  3683. }
  3684. if (!knownKeys.has(key)) {
  3685. knownKeys.add(key);
  3686. break;
  3687. }
  3688. 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);
  3689. break;
  3690. }
  3691. }
  3692. return knownKeys;
  3693. }
  3694. function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
  3695. // This algorithm can't optimize by searching from both ends since we
  3696. // don't have backpointers on fibers. I'm trying to see how far we can get
  3697. // with that model. If it ends up not being worth the tradeoffs, we can
  3698. // add it later.
  3699. // Even with a two ended optimization, we'd want to optimize for the case
  3700. // where there are few changes and brute force the comparison instead of
  3701. // going for the Map. It'd like to explore hitting that path first in
  3702. // forward-only mode and only go for the Map once we notice that we need
  3703. // lots of look ahead. This doesn't handle reversal as well as two ended
  3704. // search but that's unusual. Besides, for the two ended optimization to
  3705. // work on Iterables, we'd need to copy the whole set.
  3706. // In this first iteration, we'll just live with hitting the bad case
  3707. // (adding everything to a Map) in for every insert/move.
  3708. // If you change this code, also update reconcileChildrenIterator() which
  3709. // uses the same algorithm.
  3710. {
  3711. // First, validate keys.
  3712. var knownKeys = null;
  3713. for (var i = 0; i < newChildren.length; i++) {
  3714. var child = newChildren[i];
  3715. knownKeys = warnOnInvalidKey(child, knownKeys);
  3716. }
  3717. }
  3718. var resultingFirstChild = null;
  3719. var previousNewFiber = null;
  3720. var oldFiber = currentFirstChild;
  3721. var lastPlacedIndex = 0;
  3722. var newIdx = 0;
  3723. var nextOldFiber = null;
  3724. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  3725. if (oldFiber.index > newIdx) {
  3726. nextOldFiber = oldFiber;
  3727. oldFiber = null;
  3728. } else {
  3729. nextOldFiber = oldFiber.sibling;
  3730. }
  3731. var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
  3732. if (newFiber === null) {
  3733. // TODO: This breaks on empty slots like null children. That's
  3734. // unfortunate because it triggers the slow path all the time. We need
  3735. // a better way to communicate whether this was a miss or null,
  3736. // boolean, undefined, etc.
  3737. if (oldFiber === null) {
  3738. oldFiber = nextOldFiber;
  3739. }
  3740. break;
  3741. }
  3742. if (shouldTrackSideEffects) {
  3743. if (oldFiber && newFiber.alternate === null) {
  3744. // We matched the slot, but we didn't reuse the existing fiber, so we
  3745. // need to delete the existing child.
  3746. deleteChild(returnFiber, oldFiber);
  3747. }
  3748. }
  3749. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  3750. if (previousNewFiber === null) {
  3751. // TODO: Move out of the loop. This only happens for the first run.
  3752. resultingFirstChild = newFiber;
  3753. } else {
  3754. // TODO: Defer siblings if we're not at the right index for this slot.
  3755. // I.e. if we had null values before, then we want to defer this
  3756. // for each null value. However, we also don't want to call updateSlot
  3757. // with the previous one.
  3758. previousNewFiber.sibling = newFiber;
  3759. }
  3760. previousNewFiber = newFiber;
  3761. oldFiber = nextOldFiber;
  3762. }
  3763. if (newIdx === newChildren.length) {
  3764. // We've reached the end of the new children. We can delete the rest.
  3765. deleteRemainingChildren(returnFiber, oldFiber);
  3766. return resultingFirstChild;
  3767. }
  3768. if (oldFiber === null) {
  3769. // If we don't have any more existing children we can choose a fast path
  3770. // since the rest will all be insertions.
  3771. for (; newIdx < newChildren.length; newIdx++) {
  3772. var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
  3773. if (_newFiber === null) {
  3774. continue;
  3775. }
  3776. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  3777. if (previousNewFiber === null) {
  3778. // TODO: Move out of the loop. This only happens for the first run.
  3779. resultingFirstChild = _newFiber;
  3780. } else {
  3781. previousNewFiber.sibling = _newFiber;
  3782. }
  3783. previousNewFiber = _newFiber;
  3784. }
  3785. return resultingFirstChild;
  3786. } // Add all children to a key map for quick lookups.
  3787. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  3788. for (; newIdx < newChildren.length; newIdx++) {
  3789. var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
  3790. if (_newFiber2 !== null) {
  3791. if (shouldTrackSideEffects) {
  3792. if (_newFiber2.alternate !== null) {
  3793. // The new fiber is a work in progress, but if there exists a
  3794. // current, that means that we reused the fiber. We need to delete
  3795. // it from the child list so that we don't add it to the deletion
  3796. // list.
  3797. existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
  3798. }
  3799. }
  3800. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  3801. if (previousNewFiber === null) {
  3802. resultingFirstChild = _newFiber2;
  3803. } else {
  3804. previousNewFiber.sibling = _newFiber2;
  3805. }
  3806. previousNewFiber = _newFiber2;
  3807. }
  3808. }
  3809. if (shouldTrackSideEffects) {
  3810. // Any existing children that weren't consumed above were deleted. We need
  3811. // to add them to the deletion list.
  3812. existingChildren.forEach(function (child) {
  3813. return deleteChild(returnFiber, child);
  3814. });
  3815. }
  3816. return resultingFirstChild;
  3817. }
  3818. function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
  3819. // This is the same implementation as reconcileChildrenArray(),
  3820. // but using the iterator instead.
  3821. var iteratorFn = getIteratorFn(newChildrenIterable);
  3822. if (!(typeof iteratorFn === 'function')) {
  3823. {
  3824. throw Error( "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue." );
  3825. }
  3826. }
  3827. {
  3828. // We don't support rendering Generators because it's a mutation.
  3829. // See https://github.com/facebook/react/issues/12995
  3830. if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
  3831. newChildrenIterable[Symbol.toStringTag] === 'Generator') {
  3832. if (!didWarnAboutGenerators) {
  3833. 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.');
  3834. }
  3835. didWarnAboutGenerators = true;
  3836. } // Warn about using Maps as children
  3837. if (newChildrenIterable.entries === iteratorFn) {
  3838. if (!didWarnAboutMaps) {
  3839. error('Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.');
  3840. }
  3841. didWarnAboutMaps = true;
  3842. } // First, validate keys.
  3843. // We'll get a different iterator later for the main pass.
  3844. var _newChildren = iteratorFn.call(newChildrenIterable);
  3845. if (_newChildren) {
  3846. var knownKeys = null;
  3847. var _step = _newChildren.next();
  3848. for (; !_step.done; _step = _newChildren.next()) {
  3849. var child = _step.value;
  3850. knownKeys = warnOnInvalidKey(child, knownKeys);
  3851. }
  3852. }
  3853. }
  3854. var newChildren = iteratorFn.call(newChildrenIterable);
  3855. if (!(newChildren != null)) {
  3856. {
  3857. throw Error( "An iterable object provided no iterator." );
  3858. }
  3859. }
  3860. var resultingFirstChild = null;
  3861. var previousNewFiber = null;
  3862. var oldFiber = currentFirstChild;
  3863. var lastPlacedIndex = 0;
  3864. var newIdx = 0;
  3865. var nextOldFiber = null;
  3866. var step = newChildren.next();
  3867. for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
  3868. if (oldFiber.index > newIdx) {
  3869. nextOldFiber = oldFiber;
  3870. oldFiber = null;
  3871. } else {
  3872. nextOldFiber = oldFiber.sibling;
  3873. }
  3874. var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
  3875. if (newFiber === null) {
  3876. // TODO: This breaks on empty slots like null children. That's
  3877. // unfortunate because it triggers the slow path all the time. We need
  3878. // a better way to communicate whether this was a miss or null,
  3879. // boolean, undefined, etc.
  3880. if (oldFiber === null) {
  3881. oldFiber = nextOldFiber;
  3882. }
  3883. break;
  3884. }
  3885. if (shouldTrackSideEffects) {
  3886. if (oldFiber && newFiber.alternate === null) {
  3887. // We matched the slot, but we didn't reuse the existing fiber, so we
  3888. // need to delete the existing child.
  3889. deleteChild(returnFiber, oldFiber);
  3890. }
  3891. }
  3892. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  3893. if (previousNewFiber === null) {
  3894. // TODO: Move out of the loop. This only happens for the first run.
  3895. resultingFirstChild = newFiber;
  3896. } else {
  3897. // TODO: Defer siblings if we're not at the right index for this slot.
  3898. // I.e. if we had null values before, then we want to defer this
  3899. // for each null value. However, we also don't want to call updateSlot
  3900. // with the previous one.
  3901. previousNewFiber.sibling = newFiber;
  3902. }
  3903. previousNewFiber = newFiber;
  3904. oldFiber = nextOldFiber;
  3905. }
  3906. if (step.done) {
  3907. // We've reached the end of the new children. We can delete the rest.
  3908. deleteRemainingChildren(returnFiber, oldFiber);
  3909. return resultingFirstChild;
  3910. }
  3911. if (oldFiber === null) {
  3912. // If we don't have any more existing children we can choose a fast path
  3913. // since the rest will all be insertions.
  3914. for (; !step.done; newIdx++, step = newChildren.next()) {
  3915. var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
  3916. if (_newFiber3 === null) {
  3917. continue;
  3918. }
  3919. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  3920. if (previousNewFiber === null) {
  3921. // TODO: Move out of the loop. This only happens for the first run.
  3922. resultingFirstChild = _newFiber3;
  3923. } else {
  3924. previousNewFiber.sibling = _newFiber3;
  3925. }
  3926. previousNewFiber = _newFiber3;
  3927. }
  3928. return resultingFirstChild;
  3929. } // Add all children to a key map for quick lookups.
  3930. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  3931. for (; !step.done; newIdx++, step = newChildren.next()) {
  3932. var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
  3933. if (_newFiber4 !== null) {
  3934. if (shouldTrackSideEffects) {
  3935. if (_newFiber4.alternate !== null) {
  3936. // The new fiber is a work in progress, but if there exists a
  3937. // current, that means that we reused the fiber. We need to delete
  3938. // it from the child list so that we don't add it to the deletion
  3939. // list.
  3940. existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
  3941. }
  3942. }
  3943. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  3944. if (previousNewFiber === null) {
  3945. resultingFirstChild = _newFiber4;
  3946. } else {
  3947. previousNewFiber.sibling = _newFiber4;
  3948. }
  3949. previousNewFiber = _newFiber4;
  3950. }
  3951. }
  3952. if (shouldTrackSideEffects) {
  3953. // Any existing children that weren't consumed above were deleted. We need
  3954. // to add them to the deletion list.
  3955. existingChildren.forEach(function (child) {
  3956. return deleteChild(returnFiber, child);
  3957. });
  3958. }
  3959. return resultingFirstChild;
  3960. }
  3961. function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
  3962. // There's no need to check for keys on text nodes since we don't have a
  3963. // way to define them.
  3964. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  3965. // We already have an existing node so let's just update it and delete
  3966. // the rest.
  3967. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  3968. var existing = useFiber(currentFirstChild, textContent);
  3969. existing.return = returnFiber;
  3970. return existing;
  3971. } // The existing first child is not a text node so we need to create one
  3972. // and delete the existing ones.
  3973. deleteRemainingChildren(returnFiber, currentFirstChild);
  3974. var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
  3975. created.return = returnFiber;
  3976. return created;
  3977. }
  3978. function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
  3979. var key = element.key;
  3980. var child = currentFirstChild;
  3981. while (child !== null) {
  3982. // TODO: If key === null and child.key === null, then this only applies to
  3983. // the first item in the list.
  3984. if (child.key === key) {
  3985. switch (child.tag) {
  3986. case Fragment:
  3987. {
  3988. if (element.type === REACT_FRAGMENT_TYPE) {
  3989. deleteRemainingChildren(returnFiber, child.sibling);
  3990. var existing = useFiber(child, element.props.children);
  3991. existing.return = returnFiber;
  3992. {
  3993. existing._debugSource = element._source;
  3994. existing._debugOwner = element._owner;
  3995. }
  3996. return existing;
  3997. }
  3998. break;
  3999. }
  4000. case Block:
  4001. // We intentionally fallthrough here if enableBlocksAPI is not on.
  4002. // eslint-disable-next-lined no-fallthrough
  4003. default:
  4004. {
  4005. if (child.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  4006. isCompatibleFamilyForHotReloading(child, element) )) {
  4007. deleteRemainingChildren(returnFiber, child.sibling);
  4008. var _existing3 = useFiber(child, element.props);
  4009. _existing3.ref = coerceRef(returnFiber, child, element);
  4010. _existing3.return = returnFiber;
  4011. {
  4012. _existing3._debugSource = element._source;
  4013. _existing3._debugOwner = element._owner;
  4014. }
  4015. return _existing3;
  4016. }
  4017. break;
  4018. }
  4019. } // Didn't match.
  4020. deleteRemainingChildren(returnFiber, child);
  4021. break;
  4022. } else {
  4023. deleteChild(returnFiber, child);
  4024. }
  4025. child = child.sibling;
  4026. }
  4027. if (element.type === REACT_FRAGMENT_TYPE) {
  4028. var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
  4029. created.return = returnFiber;
  4030. return created;
  4031. } else {
  4032. var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
  4033. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  4034. _created4.return = returnFiber;
  4035. return _created4;
  4036. }
  4037. }
  4038. function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
  4039. var key = portal.key;
  4040. var child = currentFirstChild;
  4041. while (child !== null) {
  4042. // TODO: If key === null and child.key === null, then this only applies to
  4043. // the first item in the list.
  4044. if (child.key === key) {
  4045. if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
  4046. deleteRemainingChildren(returnFiber, child.sibling);
  4047. var existing = useFiber(child, portal.children || []);
  4048. existing.return = returnFiber;
  4049. return existing;
  4050. } else {
  4051. deleteRemainingChildren(returnFiber, child);
  4052. break;
  4053. }
  4054. } else {
  4055. deleteChild(returnFiber, child);
  4056. }
  4057. child = child.sibling;
  4058. }
  4059. var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
  4060. created.return = returnFiber;
  4061. return created;
  4062. } // This API will tag the children with the side-effect of the reconciliation
  4063. // itself. They will be added to the side-effect list as we pass through the
  4064. // children and the parent.
  4065. function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
  4066. // This function is not recursive.
  4067. // If the top level item is an array, we treat it as a set of children,
  4068. // not as a fragment. Nested arrays on the other hand will be treated as
  4069. // fragment nodes. Recursion happens at the normal flow.
  4070. // Handle top level unkeyed fragments as if they were arrays.
  4071. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  4072. // We treat the ambiguous cases above the same.
  4073. var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
  4074. if (isUnkeyedTopLevelFragment) {
  4075. newChild = newChild.props.children;
  4076. } // Handle object types
  4077. var isObject = typeof newChild === 'object' && newChild !== null;
  4078. if (isObject) {
  4079. switch (newChild.$$typeof) {
  4080. case REACT_ELEMENT_TYPE:
  4081. return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
  4082. case REACT_PORTAL_TYPE:
  4083. return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
  4084. }
  4085. }
  4086. if (typeof newChild === 'string' || typeof newChild === 'number') {
  4087. return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
  4088. }
  4089. if (isArray$1(newChild)) {
  4090. return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
  4091. }
  4092. if (getIteratorFn(newChild)) {
  4093. return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
  4094. }
  4095. if (isObject) {
  4096. throwOnInvalidObjectType(returnFiber, newChild);
  4097. }
  4098. {
  4099. if (typeof newChild === 'function') {
  4100. warnOnFunctionType();
  4101. }
  4102. }
  4103. if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
  4104. // If the new child is undefined, and the return fiber is a composite
  4105. // component, throw an error. If Fiber return types are disabled,
  4106. // we already threw above.
  4107. switch (returnFiber.tag) {
  4108. case ClassComponent:
  4109. {
  4110. {
  4111. var instance = returnFiber.stateNode;
  4112. if (instance.render._isMockFunction) {
  4113. // We allow auto-mocks to proceed as if they're returning null.
  4114. break;
  4115. }
  4116. }
  4117. }
  4118. // Intentionally fall through to the next case, which handles both
  4119. // functions and classes
  4120. // eslint-disable-next-lined no-fallthrough
  4121. case FunctionComponent:
  4122. {
  4123. var Component = returnFiber.type;
  4124. {
  4125. {
  4126. 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." );
  4127. }
  4128. }
  4129. }
  4130. }
  4131. } // Remaining cases are all treated as empty.
  4132. return deleteRemainingChildren(returnFiber, currentFirstChild);
  4133. }
  4134. return reconcileChildFibers;
  4135. }
  4136. var reconcileChildFibers = ChildReconciler(true);
  4137. var mountChildFibers = ChildReconciler(false);
  4138. function cloneChildFibers(current, workInProgress) {
  4139. if (!(current === null || workInProgress.child === current.child)) {
  4140. {
  4141. throw Error( "Resuming work not yet implemented." );
  4142. }
  4143. }
  4144. if (workInProgress.child === null) {
  4145. return;
  4146. }
  4147. var currentChild = workInProgress.child;
  4148. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  4149. workInProgress.child = newChild;
  4150. newChild.return = workInProgress;
  4151. while (currentChild.sibling !== null) {
  4152. currentChild = currentChild.sibling;
  4153. newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps);
  4154. newChild.return = workInProgress;
  4155. }
  4156. newChild.sibling = null;
  4157. } // Reset a workInProgress child set to prepare it for a second pass.
  4158. function resetChildFibers(workInProgress, renderExpirationTime) {
  4159. var child = workInProgress.child;
  4160. while (child !== null) {
  4161. resetWorkInProgress(child, renderExpirationTime);
  4162. child = child.sibling;
  4163. }
  4164. }
  4165. var NO_CONTEXT$1 = {};
  4166. var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
  4167. var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
  4168. var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
  4169. function requiredContext(c) {
  4170. if (!(c !== NO_CONTEXT$1)) {
  4171. {
  4172. throw Error( "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." );
  4173. }
  4174. }
  4175. return c;
  4176. }
  4177. function getRootHostContainer() {
  4178. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  4179. return rootInstance;
  4180. }
  4181. function pushHostContainer(fiber, nextRootInstance) {
  4182. // Push current root instance onto the stack;
  4183. // This allows us to reset root when portals are popped.
  4184. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  4185. // This enables us to pop only Fibers that provide unique contexts.
  4186. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  4187. // However, we can't just call getRootHostContext() and push it because
  4188. // we'd have a different number of entries on the stack depending on
  4189. // whether getRootHostContext() throws somewhere in renderer code or not.
  4190. // So we push an empty value first. This lets us safely unwind on errors.
  4191. push(contextStackCursor$1, NO_CONTEXT$1, fiber);
  4192. var nextRootContext = getRootHostContext(); // Now that we know this function doesn't throw, replace it.
  4193. pop(contextStackCursor$1, fiber);
  4194. push(contextStackCursor$1, nextRootContext, fiber);
  4195. }
  4196. function popHostContainer(fiber) {
  4197. pop(contextStackCursor$1, fiber);
  4198. pop(contextFiberStackCursor, fiber);
  4199. pop(rootInstanceStackCursor, fiber);
  4200. }
  4201. function getHostContext() {
  4202. var context = requiredContext(contextStackCursor$1.current);
  4203. return context;
  4204. }
  4205. function pushHostContext(fiber) {
  4206. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  4207. var context = requiredContext(contextStackCursor$1.current);
  4208. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  4209. if (context === nextContext) {
  4210. return;
  4211. } // Track the context and the Fiber that provided it.
  4212. // This enables us to pop only Fibers that provide unique contexts.
  4213. push(contextFiberStackCursor, fiber, fiber);
  4214. push(contextStackCursor$1, nextContext, fiber);
  4215. }
  4216. function popHostContext(fiber) {
  4217. // Do not pop unless this Fiber provided the current context.
  4218. // pushHostContext() only pushes Fibers that provide unique contexts.
  4219. if (contextFiberStackCursor.current !== fiber) {
  4220. return;
  4221. }
  4222. pop(contextStackCursor$1, fiber);
  4223. pop(contextFiberStackCursor, fiber);
  4224. }
  4225. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  4226. // inherited deeply down the subtree. The upper bits only affect
  4227. // this immediate suspense boundary and gets reset each new
  4228. // boundary or suspense list.
  4229. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  4230. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  4231. // boundaries is not currently showing visible main content.
  4232. // Either because it is already showing a fallback or is not mounted at all.
  4233. // We can use this to determine if it is desirable to trigger a fallback at
  4234. // the parent. If not, then we might need to trigger undesirable boundaries
  4235. // and/or suspend the commit to avoid hiding the parent content.
  4236. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  4237. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  4238. // items into their fallback state during one of the render passes.
  4239. var ForceSuspenseFallback = 2;
  4240. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  4241. function hasSuspenseContext(parentContext, flag) {
  4242. return (parentContext & flag) !== 0;
  4243. }
  4244. function setDefaultShallowSuspenseContext(parentContext) {
  4245. return parentContext & SubtreeSuspenseContextMask;
  4246. }
  4247. function setShallowSuspenseContext(parentContext, shallowContext) {
  4248. return parentContext & SubtreeSuspenseContextMask | shallowContext;
  4249. }
  4250. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  4251. return parentContext | subtreeContext;
  4252. }
  4253. function pushSuspenseContext(fiber, newContext) {
  4254. push(suspenseStackCursor, newContext, fiber);
  4255. }
  4256. function popSuspenseContext(fiber) {
  4257. pop(suspenseStackCursor, fiber);
  4258. }
  4259. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  4260. // If it was the primary children that just suspended, capture and render the
  4261. // fallback. Otherwise, don't capture and bubble to the next boundary.
  4262. var nextState = workInProgress.memoizedState;
  4263. if (nextState !== null) {
  4264. if (nextState.dehydrated !== null) {
  4265. // A dehydrated boundary always captures.
  4266. return true;
  4267. }
  4268. return false;
  4269. }
  4270. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  4271. if (props.fallback === undefined) {
  4272. return false;
  4273. } // Regular boundaries always capture.
  4274. if (props.unstable_avoidThisFallback !== true) {
  4275. return true;
  4276. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  4277. // parent boundary if it is currently invisible.
  4278. if (hasInvisibleParent) {
  4279. return false;
  4280. } // If the parent is not able to handle it, we must handle it.
  4281. return true;
  4282. }
  4283. function findFirstSuspended(row) {
  4284. var node = row;
  4285. while (node !== null) {
  4286. if (node.tag === SuspenseComponent) {
  4287. var state = node.memoizedState;
  4288. if (state !== null) {
  4289. var dehydrated = state.dehydrated;
  4290. if (dehydrated === null || isSuspenseInstancePending() || isSuspenseInstanceFallback()) {
  4291. return node;
  4292. }
  4293. }
  4294. } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  4295. // keep track of whether it suspended or not.
  4296. node.memoizedProps.revealOrder !== undefined) {
  4297. var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
  4298. if (didSuspend) {
  4299. return node;
  4300. }
  4301. } else if (node.child !== null) {
  4302. node.child.return = node;
  4303. node = node.child;
  4304. continue;
  4305. }
  4306. if (node === row) {
  4307. return null;
  4308. }
  4309. while (node.sibling === null) {
  4310. if (node.return === null || node.return === row) {
  4311. return null;
  4312. }
  4313. node = node.return;
  4314. }
  4315. node.sibling.return = node.return;
  4316. node = node.sibling;
  4317. }
  4318. return null;
  4319. }
  4320. function createDeprecatedResponderListener(responder, props) {
  4321. var eventResponderListener = {
  4322. responder: responder,
  4323. props: props
  4324. };
  4325. {
  4326. Object.freeze(eventResponderListener);
  4327. }
  4328. return eventResponderListener;
  4329. }
  4330. var HasEffect =
  4331. /* */
  4332. 1; // Represents the phase in which the effect (not the clean-up) fires.
  4333. var Layout =
  4334. /* */
  4335. 2;
  4336. var Passive$1 =
  4337. /* */
  4338. 4;
  4339. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
  4340. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  4341. var didWarnAboutMismatchedHooksForComponent;
  4342. {
  4343. didWarnAboutMismatchedHooksForComponent = new Set();
  4344. }
  4345. // These are set right before calling the component.
  4346. var renderExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
  4347. // the work-in-progress hook.
  4348. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  4349. // current hook list is the list that belongs to the current fiber. The
  4350. // work-in-progress hook list is a new list that will be added to the
  4351. // work-in-progress fiber.
  4352. var currentHook = null;
  4353. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  4354. // does not get reset if we do another render pass; only when we're completely
  4355. // finished evaluating this component. This is an optimization so we know
  4356. // whether we need to clear render phase updates after a throw.
  4357. var didScheduleRenderPhaseUpdate = false;
  4358. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  4359. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  4360. // The list stores the order of hooks used during the initial render (mount).
  4361. // Subsequent renders (updates) reference this list.
  4362. var hookTypesDev = null;
  4363. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  4364. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  4365. // When true, such Hooks will always be "remounted". Only used during hot reload.
  4366. var ignorePreviousDependencies = false;
  4367. function mountHookTypesDev() {
  4368. {
  4369. var hookName = currentHookNameInDev;
  4370. if (hookTypesDev === null) {
  4371. hookTypesDev = [hookName];
  4372. } else {
  4373. hookTypesDev.push(hookName);
  4374. }
  4375. }
  4376. }
  4377. function updateHookTypesDev() {
  4378. {
  4379. var hookName = currentHookNameInDev;
  4380. if (hookTypesDev !== null) {
  4381. hookTypesUpdateIndexDev++;
  4382. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  4383. warnOnHookMismatchInDev(hookName);
  4384. }
  4385. }
  4386. }
  4387. }
  4388. function checkDepsAreArrayDev(deps) {
  4389. {
  4390. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  4391. // Verify deps, but only on mount to avoid extra checks.
  4392. // It's unlikely their type would change as usually you define them inline.
  4393. 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);
  4394. }
  4395. }
  4396. }
  4397. function warnOnHookMismatchInDev(currentHookName) {
  4398. {
  4399. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  4400. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  4401. didWarnAboutMismatchedHooksForComponent.add(componentName);
  4402. if (hookTypesDev !== null) {
  4403. var table = '';
  4404. var secondColumnStart = 30;
  4405. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  4406. var oldHookName = hookTypesDev[i];
  4407. var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  4408. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  4409. // lol @ IE not supporting String#repeat
  4410. while (row.length < secondColumnStart) {
  4411. row += ' ';
  4412. }
  4413. row += newHookName + '\n';
  4414. table += row;
  4415. }
  4416. 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);
  4417. }
  4418. }
  4419. }
  4420. }
  4421. function throwInvalidHookError() {
  4422. {
  4423. {
  4424. 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." );
  4425. }
  4426. }
  4427. }
  4428. function areHookInputsEqual(nextDeps, prevDeps) {
  4429. {
  4430. if (ignorePreviousDependencies) {
  4431. // Only true when this component is being hot reloaded.
  4432. return false;
  4433. }
  4434. }
  4435. if (prevDeps === null) {
  4436. {
  4437. 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);
  4438. }
  4439. return false;
  4440. }
  4441. {
  4442. // Don't bother comparing lengths in prod because these arrays should be
  4443. // passed inline.
  4444. if (nextDeps.length !== prevDeps.length) {
  4445. 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(', ') + "]");
  4446. }
  4447. }
  4448. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  4449. if (objectIs(nextDeps[i], prevDeps[i])) {
  4450. continue;
  4451. }
  4452. return false;
  4453. }
  4454. return true;
  4455. }
  4456. function renderWithHooks(current, workInProgress, Component, props, secondArg, nextRenderExpirationTime) {
  4457. renderExpirationTime = nextRenderExpirationTime;
  4458. currentlyRenderingFiber$1 = workInProgress;
  4459. {
  4460. hookTypesDev = current !== null ? current._debugHookTypes : null;
  4461. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  4462. ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
  4463. }
  4464. workInProgress.memoizedState = null;
  4465. workInProgress.updateQueue = null;
  4466. workInProgress.expirationTime = NoWork; // The following should have already been reset
  4467. // currentHook = null;
  4468. // workInProgressHook = null;
  4469. // didScheduleRenderPhaseUpdate = false;
  4470. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  4471. // Currently we will identify the update render as a mount because memoizedState === null.
  4472. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  4473. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  4474. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  4475. // so memoizedState would be null during updates and mounts.
  4476. {
  4477. if (current !== null && current.memoizedState !== null) {
  4478. ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
  4479. } else if (hookTypesDev !== null) {
  4480. // This dispatcher handles an edge case where a component is updating,
  4481. // but no stateful hooks have been used.
  4482. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  4483. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  4484. // This dispatcher does that.
  4485. ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
  4486. } else {
  4487. ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
  4488. }
  4489. }
  4490. var children = Component(props, secondArg); // Check if there was a render phase update
  4491. if (workInProgress.expirationTime === renderExpirationTime) {
  4492. // Keep rendering in a loop for as long as render phase updates continue to
  4493. // be scheduled. Use a counter to prevent infinite loops.
  4494. var numberOfReRenders = 0;
  4495. do {
  4496. workInProgress.expirationTime = NoWork;
  4497. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  4498. {
  4499. throw Error( "Too many re-renders. React limits the number of renders to prevent an infinite loop." );
  4500. }
  4501. }
  4502. numberOfReRenders += 1;
  4503. {
  4504. // Even when hot reloading, allow dependencies to stabilize
  4505. // after first render to prevent infinite render phase updates.
  4506. ignorePreviousDependencies = false;
  4507. } // Start over from the beginning of the list
  4508. currentHook = null;
  4509. workInProgressHook = null;
  4510. workInProgress.updateQueue = null;
  4511. {
  4512. // Also validate hook order for cascading updates.
  4513. hookTypesUpdateIndexDev = -1;
  4514. }
  4515. ReactCurrentDispatcher.current = HooksDispatcherOnRerenderInDEV ;
  4516. children = Component(props, secondArg);
  4517. } while (workInProgress.expirationTime === renderExpirationTime);
  4518. } // We can assume the previous dispatcher is always this one, since we set it
  4519. // at the beginning of the render phase and there's no re-entrancy.
  4520. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  4521. {
  4522. workInProgress._debugHookTypes = hookTypesDev;
  4523. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  4524. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  4525. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  4526. renderExpirationTime = NoWork;
  4527. currentlyRenderingFiber$1 = null;
  4528. currentHook = null;
  4529. workInProgressHook = null;
  4530. {
  4531. currentHookNameInDev = null;
  4532. hookTypesDev = null;
  4533. hookTypesUpdateIndexDev = -1;
  4534. }
  4535. didScheduleRenderPhaseUpdate = false;
  4536. if (!!didRenderTooFewHooks) {
  4537. {
  4538. throw Error( "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." );
  4539. }
  4540. }
  4541. return children;
  4542. }
  4543. function bailoutHooks(current, workInProgress, expirationTime) {
  4544. workInProgress.updateQueue = current.updateQueue;
  4545. workInProgress.effectTag &= ~(Passive | Update);
  4546. if (current.expirationTime <= expirationTime) {
  4547. current.expirationTime = NoWork;
  4548. }
  4549. }
  4550. function resetHooksAfterThrow() {
  4551. // We can assume the previous dispatcher is always this one, since we set it
  4552. // at the beginning of the render phase and there's no re-entrancy.
  4553. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  4554. if (didScheduleRenderPhaseUpdate) {
  4555. // There were render phase updates. These are only valid for this render
  4556. // phase, which we are now aborting. Remove the updates from the queues so
  4557. // they do not persist to the next render. Do not remove updates from hooks
  4558. // that weren't processed.
  4559. //
  4560. // Only reset the updates from the queue if it has a clone. If it does
  4561. // not have a clone, that means it wasn't processed, and the updates were
  4562. // scheduled before we entered the render phase.
  4563. var hook = currentlyRenderingFiber$1.memoizedState;
  4564. while (hook !== null) {
  4565. var queue = hook.queue;
  4566. if (queue !== null) {
  4567. queue.pending = null;
  4568. }
  4569. hook = hook.next;
  4570. }
  4571. }
  4572. renderExpirationTime = NoWork;
  4573. currentlyRenderingFiber$1 = null;
  4574. currentHook = null;
  4575. workInProgressHook = null;
  4576. {
  4577. hookTypesDev = null;
  4578. hookTypesUpdateIndexDev = -1;
  4579. currentHookNameInDev = null;
  4580. }
  4581. didScheduleRenderPhaseUpdate = false;
  4582. }
  4583. function mountWorkInProgressHook() {
  4584. var hook = {
  4585. memoizedState: null,
  4586. baseState: null,
  4587. baseQueue: null,
  4588. queue: null,
  4589. next: null
  4590. };
  4591. if (workInProgressHook === null) {
  4592. // This is the first hook in the list
  4593. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  4594. } else {
  4595. // Append to the end of the list
  4596. workInProgressHook = workInProgressHook.next = hook;
  4597. }
  4598. return workInProgressHook;
  4599. }
  4600. function updateWorkInProgressHook() {
  4601. // This function is used both for updates and for re-renders triggered by a
  4602. // render phase update. It assumes there is either a current hook we can
  4603. // clone, or a work-in-progress hook from a previous render pass that we can
  4604. // use as a base. When we reach the end of the base list, we must switch to
  4605. // the dispatcher used for mounts.
  4606. var nextCurrentHook;
  4607. if (currentHook === null) {
  4608. var current = currentlyRenderingFiber$1.alternate;
  4609. if (current !== null) {
  4610. nextCurrentHook = current.memoizedState;
  4611. } else {
  4612. nextCurrentHook = null;
  4613. }
  4614. } else {
  4615. nextCurrentHook = currentHook.next;
  4616. }
  4617. var nextWorkInProgressHook;
  4618. if (workInProgressHook === null) {
  4619. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  4620. } else {
  4621. nextWorkInProgressHook = workInProgressHook.next;
  4622. }
  4623. if (nextWorkInProgressHook !== null) {
  4624. // There's already a work-in-progress. Reuse it.
  4625. workInProgressHook = nextWorkInProgressHook;
  4626. nextWorkInProgressHook = workInProgressHook.next;
  4627. currentHook = nextCurrentHook;
  4628. } else {
  4629. // Clone from the current hook.
  4630. if (!(nextCurrentHook !== null)) {
  4631. {
  4632. throw Error( "Rendered more hooks than during the previous render." );
  4633. }
  4634. }
  4635. currentHook = nextCurrentHook;
  4636. var newHook = {
  4637. memoizedState: currentHook.memoizedState,
  4638. baseState: currentHook.baseState,
  4639. baseQueue: currentHook.baseQueue,
  4640. queue: currentHook.queue,
  4641. next: null
  4642. };
  4643. if (workInProgressHook === null) {
  4644. // This is the first hook in the list.
  4645. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  4646. } else {
  4647. // Append to the end of the list.
  4648. workInProgressHook = workInProgressHook.next = newHook;
  4649. }
  4650. }
  4651. return workInProgressHook;
  4652. }
  4653. function createFunctionComponentUpdateQueue() {
  4654. return {
  4655. lastEffect: null
  4656. };
  4657. }
  4658. function basicStateReducer(state, action) {
  4659. // $FlowFixMe: Flow doesn't like mixed types
  4660. return typeof action === 'function' ? action(state) : action;
  4661. }
  4662. function mountReducer(reducer, initialArg, init) {
  4663. var hook = mountWorkInProgressHook();
  4664. var initialState;
  4665. if (init !== undefined) {
  4666. initialState = init(initialArg);
  4667. } else {
  4668. initialState = initialArg;
  4669. }
  4670. hook.memoizedState = hook.baseState = initialState;
  4671. var queue = hook.queue = {
  4672. pending: null,
  4673. dispatch: null,
  4674. lastRenderedReducer: reducer,
  4675. lastRenderedState: initialState
  4676. };
  4677. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  4678. return [hook.memoizedState, dispatch];
  4679. }
  4680. function updateReducer(reducer, initialArg, init) {
  4681. var hook = updateWorkInProgressHook();
  4682. var queue = hook.queue;
  4683. if (!(queue !== null)) {
  4684. {
  4685. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  4686. }
  4687. }
  4688. queue.lastRenderedReducer = reducer;
  4689. var current = currentHook; // The last rebase update that is NOT part of the base state.
  4690. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  4691. var pendingQueue = queue.pending;
  4692. if (pendingQueue !== null) {
  4693. // We have new updates that haven't been processed yet.
  4694. // We'll add them to the base queue.
  4695. if (baseQueue !== null) {
  4696. // Merge the pending queue and the base queue.
  4697. var baseFirst = baseQueue.next;
  4698. var pendingFirst = pendingQueue.next;
  4699. baseQueue.next = pendingFirst;
  4700. pendingQueue.next = baseFirst;
  4701. }
  4702. current.baseQueue = baseQueue = pendingQueue;
  4703. queue.pending = null;
  4704. }
  4705. if (baseQueue !== null) {
  4706. // We have a queue to process.
  4707. var first = baseQueue.next;
  4708. var newState = current.baseState;
  4709. var newBaseState = null;
  4710. var newBaseQueueFirst = null;
  4711. var newBaseQueueLast = null;
  4712. var update = first;
  4713. do {
  4714. var updateExpirationTime = update.expirationTime;
  4715. if (updateExpirationTime < renderExpirationTime) {
  4716. // Priority is insufficient. Skip this update. If this is the first
  4717. // skipped update, the previous update/state is the new base
  4718. // update/state.
  4719. var clone = {
  4720. expirationTime: update.expirationTime,
  4721. suspenseConfig: update.suspenseConfig,
  4722. action: update.action,
  4723. eagerReducer: update.eagerReducer,
  4724. eagerState: update.eagerState,
  4725. next: null
  4726. };
  4727. if (newBaseQueueLast === null) {
  4728. newBaseQueueFirst = newBaseQueueLast = clone;
  4729. newBaseState = newState;
  4730. } else {
  4731. newBaseQueueLast = newBaseQueueLast.next = clone;
  4732. } // Update the remaining priority in the queue.
  4733. if (updateExpirationTime > currentlyRenderingFiber$1.expirationTime) {
  4734. currentlyRenderingFiber$1.expirationTime = updateExpirationTime;
  4735. markUnprocessedUpdateTime(updateExpirationTime);
  4736. }
  4737. } else {
  4738. // This update does have sufficient priority.
  4739. if (newBaseQueueLast !== null) {
  4740. var _clone = {
  4741. expirationTime: Sync,
  4742. // This update is going to be committed so we never want uncommit it.
  4743. suspenseConfig: update.suspenseConfig,
  4744. action: update.action,
  4745. eagerReducer: update.eagerReducer,
  4746. eagerState: update.eagerState,
  4747. next: null
  4748. };
  4749. newBaseQueueLast = newBaseQueueLast.next = _clone;
  4750. } // Mark the event time of this update as relevant to this render pass.
  4751. // TODO: This should ideally use the true event time of this update rather than
  4752. // its priority which is a derived and not reverseable value.
  4753. // TODO: We should skip this update if it was already committed but currently
  4754. // we have no way of detecting the difference between a committed and suspended
  4755. // update here.
  4756. markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process this update.
  4757. if (update.eagerReducer === reducer) {
  4758. // If this update was processed eagerly, and its reducer matches the
  4759. // current reducer, we can use the eagerly computed state.
  4760. newState = update.eagerState;
  4761. } else {
  4762. var action = update.action;
  4763. newState = reducer(newState, action);
  4764. }
  4765. }
  4766. update = update.next;
  4767. } while (update !== null && update !== first);
  4768. if (newBaseQueueLast === null) {
  4769. newBaseState = newState;
  4770. } else {
  4771. newBaseQueueLast.next = newBaseQueueFirst;
  4772. } // Mark that the fiber performed work, but only if the new state is
  4773. // different from the current state.
  4774. if (!objectIs(newState, hook.memoizedState)) {
  4775. markWorkInProgressReceivedUpdate();
  4776. }
  4777. hook.memoizedState = newState;
  4778. hook.baseState = newBaseState;
  4779. hook.baseQueue = newBaseQueueLast;
  4780. queue.lastRenderedState = newState;
  4781. }
  4782. var dispatch = queue.dispatch;
  4783. return [hook.memoizedState, dispatch];
  4784. }
  4785. function rerenderReducer(reducer, initialArg, init) {
  4786. var hook = updateWorkInProgressHook();
  4787. var queue = hook.queue;
  4788. if (!(queue !== null)) {
  4789. {
  4790. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  4791. }
  4792. }
  4793. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  4794. // work-in-progress hook.
  4795. var dispatch = queue.dispatch;
  4796. var lastRenderPhaseUpdate = queue.pending;
  4797. var newState = hook.memoizedState;
  4798. if (lastRenderPhaseUpdate !== null) {
  4799. // The queue doesn't persist past this render pass.
  4800. queue.pending = null;
  4801. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  4802. var update = firstRenderPhaseUpdate;
  4803. do {
  4804. // Process this render phase update. We don't have to check the
  4805. // priority because it will always be the same as the current
  4806. // render's.
  4807. var action = update.action;
  4808. newState = reducer(newState, action);
  4809. update = update.next;
  4810. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  4811. // different from the current state.
  4812. if (!objectIs(newState, hook.memoizedState)) {
  4813. markWorkInProgressReceivedUpdate();
  4814. }
  4815. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  4816. // the base state unless the queue is empty.
  4817. // TODO: Not sure if this is the desired semantics, but it's what we
  4818. // do for gDSFP. I can't remember why.
  4819. if (hook.baseQueue === null) {
  4820. hook.baseState = newState;
  4821. }
  4822. queue.lastRenderedState = newState;
  4823. }
  4824. return [newState, dispatch];
  4825. }
  4826. function mountState(initialState) {
  4827. var hook = mountWorkInProgressHook();
  4828. if (typeof initialState === 'function') {
  4829. // $FlowFixMe: Flow doesn't like mixed types
  4830. initialState = initialState();
  4831. }
  4832. hook.memoizedState = hook.baseState = initialState;
  4833. var queue = hook.queue = {
  4834. pending: null,
  4835. dispatch: null,
  4836. lastRenderedReducer: basicStateReducer,
  4837. lastRenderedState: initialState
  4838. };
  4839. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  4840. return [hook.memoizedState, dispatch];
  4841. }
  4842. function updateState(initialState) {
  4843. return updateReducer(basicStateReducer);
  4844. }
  4845. function rerenderState(initialState) {
  4846. return rerenderReducer(basicStateReducer);
  4847. }
  4848. function pushEffect(tag, create, destroy, deps) {
  4849. var effect = {
  4850. tag: tag,
  4851. create: create,
  4852. destroy: destroy,
  4853. deps: deps,
  4854. // Circular
  4855. next: null
  4856. };
  4857. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  4858. if (componentUpdateQueue === null) {
  4859. componentUpdateQueue = createFunctionComponentUpdateQueue();
  4860. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  4861. componentUpdateQueue.lastEffect = effect.next = effect;
  4862. } else {
  4863. var lastEffect = componentUpdateQueue.lastEffect;
  4864. if (lastEffect === null) {
  4865. componentUpdateQueue.lastEffect = effect.next = effect;
  4866. } else {
  4867. var firstEffect = lastEffect.next;
  4868. lastEffect.next = effect;
  4869. effect.next = firstEffect;
  4870. componentUpdateQueue.lastEffect = effect;
  4871. }
  4872. }
  4873. return effect;
  4874. }
  4875. function mountRef(initialValue) {
  4876. var hook = mountWorkInProgressHook();
  4877. var ref = {
  4878. current: initialValue
  4879. };
  4880. {
  4881. Object.seal(ref);
  4882. }
  4883. hook.memoizedState = ref;
  4884. return ref;
  4885. }
  4886. function updateRef(initialValue) {
  4887. var hook = updateWorkInProgressHook();
  4888. return hook.memoizedState;
  4889. }
  4890. function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  4891. var hook = mountWorkInProgressHook();
  4892. var nextDeps = deps === undefined ? null : deps;
  4893. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  4894. hook.memoizedState = pushEffect(HasEffect | hookEffectTag, create, undefined, nextDeps);
  4895. }
  4896. function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  4897. var hook = updateWorkInProgressHook();
  4898. var nextDeps = deps === undefined ? null : deps;
  4899. var destroy = undefined;
  4900. if (currentHook !== null) {
  4901. var prevEffect = currentHook.memoizedState;
  4902. destroy = prevEffect.destroy;
  4903. if (nextDeps !== null) {
  4904. var prevDeps = prevEffect.deps;
  4905. if (areHookInputsEqual(nextDeps, prevDeps)) {
  4906. pushEffect(hookEffectTag, create, destroy, nextDeps);
  4907. return;
  4908. }
  4909. }
  4910. }
  4911. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  4912. hook.memoizedState = pushEffect(HasEffect | hookEffectTag, create, destroy, nextDeps);
  4913. }
  4914. function mountEffect(create, deps) {
  4915. {
  4916. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  4917. if ('undefined' !== typeof jest) {
  4918. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  4919. }
  4920. }
  4921. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  4922. }
  4923. function updateEffect(create, deps) {
  4924. {
  4925. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  4926. if ('undefined' !== typeof jest) {
  4927. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  4928. }
  4929. }
  4930. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  4931. }
  4932. function mountLayoutEffect(create, deps) {
  4933. return mountEffectImpl(Update, Layout, create, deps);
  4934. }
  4935. function updateLayoutEffect(create, deps) {
  4936. return updateEffectImpl(Update, Layout, create, deps);
  4937. }
  4938. function imperativeHandleEffect(create, ref) {
  4939. if (typeof ref === 'function') {
  4940. var refCallback = ref;
  4941. var _inst = create();
  4942. refCallback(_inst);
  4943. return function () {
  4944. refCallback(null);
  4945. };
  4946. } else if (ref !== null && ref !== undefined) {
  4947. var refObject = ref;
  4948. {
  4949. if (!refObject.hasOwnProperty('current')) {
  4950. 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(', ') + '}');
  4951. }
  4952. }
  4953. var _inst2 = create();
  4954. refObject.current = _inst2;
  4955. return function () {
  4956. refObject.current = null;
  4957. };
  4958. }
  4959. }
  4960. function mountImperativeHandle(ref, create, deps) {
  4961. {
  4962. if (typeof create !== 'function') {
  4963. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  4964. }
  4965. } // TODO: If deps are provided, should we skip comparing the ref itself?
  4966. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  4967. return mountEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  4968. }
  4969. function updateImperativeHandle(ref, create, deps) {
  4970. {
  4971. if (typeof create !== 'function') {
  4972. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  4973. }
  4974. } // TODO: If deps are provided, should we skip comparing the ref itself?
  4975. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  4976. return updateEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  4977. }
  4978. function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
  4979. // The react-debug-hooks package injects its own implementation
  4980. // so that e.g. DevTools can display custom hook values.
  4981. }
  4982. var updateDebugValue = mountDebugValue;
  4983. function mountCallback(callback, deps) {
  4984. var hook = mountWorkInProgressHook();
  4985. var nextDeps = deps === undefined ? null : deps;
  4986. hook.memoizedState = [callback, nextDeps];
  4987. return callback;
  4988. }
  4989. function updateCallback(callback, deps) {
  4990. var hook = updateWorkInProgressHook();
  4991. var nextDeps = deps === undefined ? null : deps;
  4992. var prevState = hook.memoizedState;
  4993. if (prevState !== null) {
  4994. if (nextDeps !== null) {
  4995. var prevDeps = prevState[1];
  4996. if (areHookInputsEqual(nextDeps, prevDeps)) {
  4997. return prevState[0];
  4998. }
  4999. }
  5000. }
  5001. hook.memoizedState = [callback, nextDeps];
  5002. return callback;
  5003. }
  5004. function mountMemo(nextCreate, deps) {
  5005. var hook = mountWorkInProgressHook();
  5006. var nextDeps = deps === undefined ? null : deps;
  5007. var nextValue = nextCreate();
  5008. hook.memoizedState = [nextValue, nextDeps];
  5009. return nextValue;
  5010. }
  5011. function updateMemo(nextCreate, deps) {
  5012. var hook = updateWorkInProgressHook();
  5013. var nextDeps = deps === undefined ? null : deps;
  5014. var prevState = hook.memoizedState;
  5015. if (prevState !== null) {
  5016. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  5017. if (nextDeps !== null) {
  5018. var prevDeps = prevState[1];
  5019. if (areHookInputsEqual(nextDeps, prevDeps)) {
  5020. return prevState[0];
  5021. }
  5022. }
  5023. }
  5024. var nextValue = nextCreate();
  5025. hook.memoizedState = [nextValue, nextDeps];
  5026. return nextValue;
  5027. }
  5028. function mountDeferredValue(value, config) {
  5029. var _mountState = mountState(value),
  5030. prevValue = _mountState[0],
  5031. setValue = _mountState[1];
  5032. mountEffect(function () {
  5033. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5034. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5035. try {
  5036. setValue(value);
  5037. } finally {
  5038. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5039. }
  5040. }, [value, config]);
  5041. return prevValue;
  5042. }
  5043. function updateDeferredValue(value, config) {
  5044. var _updateState = updateState(),
  5045. prevValue = _updateState[0],
  5046. setValue = _updateState[1];
  5047. updateEffect(function () {
  5048. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5049. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5050. try {
  5051. setValue(value);
  5052. } finally {
  5053. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5054. }
  5055. }, [value, config]);
  5056. return prevValue;
  5057. }
  5058. function rerenderDeferredValue(value, config) {
  5059. var _rerenderState = rerenderState(),
  5060. prevValue = _rerenderState[0],
  5061. setValue = _rerenderState[1];
  5062. updateEffect(function () {
  5063. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5064. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5065. try {
  5066. setValue(value);
  5067. } finally {
  5068. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5069. }
  5070. }, [value, config]);
  5071. return prevValue;
  5072. }
  5073. function startTransition(setPending, config, callback) {
  5074. var priorityLevel = getCurrentPriorityLevel();
  5075. runWithPriority(priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, function () {
  5076. setPending(true);
  5077. });
  5078. runWithPriority(priorityLevel > NormalPriority ? NormalPriority : priorityLevel, function () {
  5079. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  5080. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  5081. try {
  5082. setPending(false);
  5083. callback();
  5084. } finally {
  5085. ReactCurrentBatchConfig$1.suspense = previousConfig;
  5086. }
  5087. });
  5088. }
  5089. function mountTransition(config) {
  5090. var _mountState2 = mountState(false),
  5091. isPending = _mountState2[0],
  5092. setPending = _mountState2[1];
  5093. var start = mountCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  5094. return [start, isPending];
  5095. }
  5096. function updateTransition(config) {
  5097. var _updateState2 = updateState(),
  5098. isPending = _updateState2[0],
  5099. setPending = _updateState2[1];
  5100. var start = updateCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  5101. return [start, isPending];
  5102. }
  5103. function rerenderTransition(config) {
  5104. var _rerenderState2 = rerenderState(),
  5105. isPending = _rerenderState2[0],
  5106. setPending = _rerenderState2[1];
  5107. var start = updateCallback(startTransition.bind(null, setPending, config), [setPending, config]);
  5108. return [start, isPending];
  5109. }
  5110. function dispatchAction(fiber, queue, action) {
  5111. {
  5112. if (typeof arguments[3] === 'function') {
  5113. 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().');
  5114. }
  5115. }
  5116. var currentTime = requestCurrentTimeForUpdate();
  5117. var suspenseConfig = requestCurrentSuspenseConfig();
  5118. var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
  5119. var update = {
  5120. expirationTime: expirationTime,
  5121. suspenseConfig: suspenseConfig,
  5122. action: action,
  5123. eagerReducer: null,
  5124. eagerState: null,
  5125. next: null
  5126. };
  5127. {
  5128. update.priority = getCurrentPriorityLevel();
  5129. } // Append the update to the end of the list.
  5130. var pending = queue.pending;
  5131. if (pending === null) {
  5132. // This is the first update. Create a circular list.
  5133. update.next = update;
  5134. } else {
  5135. update.next = pending.next;
  5136. pending.next = update;
  5137. }
  5138. queue.pending = update;
  5139. var alternate = fiber.alternate;
  5140. if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
  5141. // This is a render phase update. Stash it in a lazily-created map of
  5142. // queue -> linked list of updates. After this render pass, we'll restart
  5143. // and apply the stashed updates on top of the work-in-progress hook.
  5144. didScheduleRenderPhaseUpdate = true;
  5145. update.expirationTime = renderExpirationTime;
  5146. currentlyRenderingFiber$1.expirationTime = renderExpirationTime;
  5147. } else {
  5148. if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
  5149. // The queue is currently empty, which means we can eagerly compute the
  5150. // next state before entering the render phase. If the new state is the
  5151. // same as the current state, we may be able to bail out entirely.
  5152. var lastRenderedReducer = queue.lastRenderedReducer;
  5153. if (lastRenderedReducer !== null) {
  5154. var prevDispatcher;
  5155. {
  5156. prevDispatcher = ReactCurrentDispatcher.current;
  5157. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5158. }
  5159. try {
  5160. var currentState = queue.lastRenderedState;
  5161. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  5162. // it, on the update object. If the reducer hasn't changed by the
  5163. // time we enter the render phase, then the eager state can be used
  5164. // without calling the reducer again.
  5165. update.eagerReducer = lastRenderedReducer;
  5166. update.eagerState = eagerState;
  5167. if (objectIs(eagerState, currentState)) {
  5168. // Fast path. We can bail out without scheduling React to re-render.
  5169. // It's still possible that we'll need to rebase this update later,
  5170. // if the component re-renders for a different reason and by that
  5171. // time the reducer has changed.
  5172. return;
  5173. }
  5174. } catch (error) {// Suppress the error. It will throw again in the render phase.
  5175. } finally {
  5176. {
  5177. ReactCurrentDispatcher.current = prevDispatcher;
  5178. }
  5179. }
  5180. }
  5181. }
  5182. {
  5183. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  5184. if ('undefined' !== typeof jest) {
  5185. warnIfNotScopedWithMatchingAct(fiber);
  5186. warnIfNotCurrentlyActingUpdatesInDev(fiber);
  5187. }
  5188. }
  5189. scheduleWork(fiber, expirationTime);
  5190. }
  5191. }
  5192. var ContextOnlyDispatcher = {
  5193. readContext: readContext,
  5194. useCallback: throwInvalidHookError,
  5195. useContext: throwInvalidHookError,
  5196. useEffect: throwInvalidHookError,
  5197. useImperativeHandle: throwInvalidHookError,
  5198. useLayoutEffect: throwInvalidHookError,
  5199. useMemo: throwInvalidHookError,
  5200. useReducer: throwInvalidHookError,
  5201. useRef: throwInvalidHookError,
  5202. useState: throwInvalidHookError,
  5203. useDebugValue: throwInvalidHookError,
  5204. useResponder: throwInvalidHookError,
  5205. useDeferredValue: throwInvalidHookError,
  5206. useTransition: throwInvalidHookError
  5207. };
  5208. var HooksDispatcherOnMountInDEV = null;
  5209. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  5210. var HooksDispatcherOnUpdateInDEV = null;
  5211. var HooksDispatcherOnRerenderInDEV = null;
  5212. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  5213. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  5214. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  5215. {
  5216. var warnInvalidContextAccess = function () {
  5217. 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().');
  5218. };
  5219. var warnInvalidHookAccess = function () {
  5220. 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');
  5221. };
  5222. HooksDispatcherOnMountInDEV = {
  5223. readContext: function (context, observedBits) {
  5224. return readContext(context, observedBits);
  5225. },
  5226. useCallback: function (callback, deps) {
  5227. currentHookNameInDev = 'useCallback';
  5228. mountHookTypesDev();
  5229. checkDepsAreArrayDev(deps);
  5230. return mountCallback(callback, deps);
  5231. },
  5232. useContext: function (context, observedBits) {
  5233. currentHookNameInDev = 'useContext';
  5234. mountHookTypesDev();
  5235. return readContext(context, observedBits);
  5236. },
  5237. useEffect: function (create, deps) {
  5238. currentHookNameInDev = 'useEffect';
  5239. mountHookTypesDev();
  5240. checkDepsAreArrayDev(deps);
  5241. return mountEffect(create, deps);
  5242. },
  5243. useImperativeHandle: function (ref, create, deps) {
  5244. currentHookNameInDev = 'useImperativeHandle';
  5245. mountHookTypesDev();
  5246. checkDepsAreArrayDev(deps);
  5247. return mountImperativeHandle(ref, create, deps);
  5248. },
  5249. useLayoutEffect: function (create, deps) {
  5250. currentHookNameInDev = 'useLayoutEffect';
  5251. mountHookTypesDev();
  5252. checkDepsAreArrayDev(deps);
  5253. return mountLayoutEffect(create, deps);
  5254. },
  5255. useMemo: function (create, deps) {
  5256. currentHookNameInDev = 'useMemo';
  5257. mountHookTypesDev();
  5258. checkDepsAreArrayDev(deps);
  5259. var prevDispatcher = ReactCurrentDispatcher.current;
  5260. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5261. try {
  5262. return mountMemo(create, deps);
  5263. } finally {
  5264. ReactCurrentDispatcher.current = prevDispatcher;
  5265. }
  5266. },
  5267. useReducer: function (reducer, initialArg, init) {
  5268. currentHookNameInDev = 'useReducer';
  5269. mountHookTypesDev();
  5270. var prevDispatcher = ReactCurrentDispatcher.current;
  5271. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5272. try {
  5273. return mountReducer(reducer, initialArg, init);
  5274. } finally {
  5275. ReactCurrentDispatcher.current = prevDispatcher;
  5276. }
  5277. },
  5278. useRef: function (initialValue) {
  5279. currentHookNameInDev = 'useRef';
  5280. mountHookTypesDev();
  5281. return mountRef(initialValue);
  5282. },
  5283. useState: function (initialState) {
  5284. currentHookNameInDev = 'useState';
  5285. mountHookTypesDev();
  5286. var prevDispatcher = ReactCurrentDispatcher.current;
  5287. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5288. try {
  5289. return mountState(initialState);
  5290. } finally {
  5291. ReactCurrentDispatcher.current = prevDispatcher;
  5292. }
  5293. },
  5294. useDebugValue: function (value, formatterFn) {
  5295. currentHookNameInDev = 'useDebugValue';
  5296. mountHookTypesDev();
  5297. return mountDebugValue();
  5298. },
  5299. useResponder: function (responder, props) {
  5300. currentHookNameInDev = 'useResponder';
  5301. mountHookTypesDev();
  5302. return createDeprecatedResponderListener(responder, props);
  5303. },
  5304. useDeferredValue: function (value, config) {
  5305. currentHookNameInDev = 'useDeferredValue';
  5306. mountHookTypesDev();
  5307. return mountDeferredValue(value, config);
  5308. },
  5309. useTransition: function (config) {
  5310. currentHookNameInDev = 'useTransition';
  5311. mountHookTypesDev();
  5312. return mountTransition(config);
  5313. }
  5314. };
  5315. HooksDispatcherOnMountWithHookTypesInDEV = {
  5316. readContext: function (context, observedBits) {
  5317. return readContext(context, observedBits);
  5318. },
  5319. useCallback: function (callback, deps) {
  5320. currentHookNameInDev = 'useCallback';
  5321. updateHookTypesDev();
  5322. return mountCallback(callback, deps);
  5323. },
  5324. useContext: function (context, observedBits) {
  5325. currentHookNameInDev = 'useContext';
  5326. updateHookTypesDev();
  5327. return readContext(context, observedBits);
  5328. },
  5329. useEffect: function (create, deps) {
  5330. currentHookNameInDev = 'useEffect';
  5331. updateHookTypesDev();
  5332. return mountEffect(create, deps);
  5333. },
  5334. useImperativeHandle: function (ref, create, deps) {
  5335. currentHookNameInDev = 'useImperativeHandle';
  5336. updateHookTypesDev();
  5337. return mountImperativeHandle(ref, create, deps);
  5338. },
  5339. useLayoutEffect: function (create, deps) {
  5340. currentHookNameInDev = 'useLayoutEffect';
  5341. updateHookTypesDev();
  5342. return mountLayoutEffect(create, deps);
  5343. },
  5344. useMemo: function (create, deps) {
  5345. currentHookNameInDev = 'useMemo';
  5346. updateHookTypesDev();
  5347. var prevDispatcher = ReactCurrentDispatcher.current;
  5348. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5349. try {
  5350. return mountMemo(create, deps);
  5351. } finally {
  5352. ReactCurrentDispatcher.current = prevDispatcher;
  5353. }
  5354. },
  5355. useReducer: function (reducer, initialArg, init) {
  5356. currentHookNameInDev = 'useReducer';
  5357. updateHookTypesDev();
  5358. var prevDispatcher = ReactCurrentDispatcher.current;
  5359. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5360. try {
  5361. return mountReducer(reducer, initialArg, init);
  5362. } finally {
  5363. ReactCurrentDispatcher.current = prevDispatcher;
  5364. }
  5365. },
  5366. useRef: function (initialValue) {
  5367. currentHookNameInDev = 'useRef';
  5368. updateHookTypesDev();
  5369. return mountRef(initialValue);
  5370. },
  5371. useState: function (initialState) {
  5372. currentHookNameInDev = 'useState';
  5373. updateHookTypesDev();
  5374. var prevDispatcher = ReactCurrentDispatcher.current;
  5375. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5376. try {
  5377. return mountState(initialState);
  5378. } finally {
  5379. ReactCurrentDispatcher.current = prevDispatcher;
  5380. }
  5381. },
  5382. useDebugValue: function (value, formatterFn) {
  5383. currentHookNameInDev = 'useDebugValue';
  5384. updateHookTypesDev();
  5385. return mountDebugValue();
  5386. },
  5387. useResponder: function (responder, props) {
  5388. currentHookNameInDev = 'useResponder';
  5389. updateHookTypesDev();
  5390. return createDeprecatedResponderListener(responder, props);
  5391. },
  5392. useDeferredValue: function (value, config) {
  5393. currentHookNameInDev = 'useDeferredValue';
  5394. updateHookTypesDev();
  5395. return mountDeferredValue(value, config);
  5396. },
  5397. useTransition: function (config) {
  5398. currentHookNameInDev = 'useTransition';
  5399. updateHookTypesDev();
  5400. return mountTransition(config);
  5401. }
  5402. };
  5403. HooksDispatcherOnUpdateInDEV = {
  5404. readContext: function (context, observedBits) {
  5405. return readContext(context, observedBits);
  5406. },
  5407. useCallback: function (callback, deps) {
  5408. currentHookNameInDev = 'useCallback';
  5409. updateHookTypesDev();
  5410. return updateCallback(callback, deps);
  5411. },
  5412. useContext: function (context, observedBits) {
  5413. currentHookNameInDev = 'useContext';
  5414. updateHookTypesDev();
  5415. return readContext(context, observedBits);
  5416. },
  5417. useEffect: function (create, deps) {
  5418. currentHookNameInDev = 'useEffect';
  5419. updateHookTypesDev();
  5420. return updateEffect(create, deps);
  5421. },
  5422. useImperativeHandle: function (ref, create, deps) {
  5423. currentHookNameInDev = 'useImperativeHandle';
  5424. updateHookTypesDev();
  5425. return updateImperativeHandle(ref, create, deps);
  5426. },
  5427. useLayoutEffect: function (create, deps) {
  5428. currentHookNameInDev = 'useLayoutEffect';
  5429. updateHookTypesDev();
  5430. return updateLayoutEffect(create, deps);
  5431. },
  5432. useMemo: function (create, deps) {
  5433. currentHookNameInDev = 'useMemo';
  5434. updateHookTypesDev();
  5435. var prevDispatcher = ReactCurrentDispatcher.current;
  5436. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5437. try {
  5438. return updateMemo(create, deps);
  5439. } finally {
  5440. ReactCurrentDispatcher.current = prevDispatcher;
  5441. }
  5442. },
  5443. useReducer: function (reducer, initialArg, init) {
  5444. currentHookNameInDev = 'useReducer';
  5445. updateHookTypesDev();
  5446. var prevDispatcher = ReactCurrentDispatcher.current;
  5447. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5448. try {
  5449. return updateReducer(reducer, initialArg, init);
  5450. } finally {
  5451. ReactCurrentDispatcher.current = prevDispatcher;
  5452. }
  5453. },
  5454. useRef: function (initialValue) {
  5455. currentHookNameInDev = 'useRef';
  5456. updateHookTypesDev();
  5457. return updateRef();
  5458. },
  5459. useState: function (initialState) {
  5460. currentHookNameInDev = 'useState';
  5461. updateHookTypesDev();
  5462. var prevDispatcher = ReactCurrentDispatcher.current;
  5463. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5464. try {
  5465. return updateState(initialState);
  5466. } finally {
  5467. ReactCurrentDispatcher.current = prevDispatcher;
  5468. }
  5469. },
  5470. useDebugValue: function (value, formatterFn) {
  5471. currentHookNameInDev = 'useDebugValue';
  5472. updateHookTypesDev();
  5473. return updateDebugValue();
  5474. },
  5475. useResponder: function (responder, props) {
  5476. currentHookNameInDev = 'useResponder';
  5477. updateHookTypesDev();
  5478. return createDeprecatedResponderListener(responder, props);
  5479. },
  5480. useDeferredValue: function (value, config) {
  5481. currentHookNameInDev = 'useDeferredValue';
  5482. updateHookTypesDev();
  5483. return updateDeferredValue(value, config);
  5484. },
  5485. useTransition: function (config) {
  5486. currentHookNameInDev = 'useTransition';
  5487. updateHookTypesDev();
  5488. return updateTransition(config);
  5489. }
  5490. };
  5491. HooksDispatcherOnRerenderInDEV = {
  5492. readContext: function (context, observedBits) {
  5493. return readContext(context, observedBits);
  5494. },
  5495. useCallback: function (callback, deps) {
  5496. currentHookNameInDev = 'useCallback';
  5497. updateHookTypesDev();
  5498. return updateCallback(callback, deps);
  5499. },
  5500. useContext: function (context, observedBits) {
  5501. currentHookNameInDev = 'useContext';
  5502. updateHookTypesDev();
  5503. return readContext(context, observedBits);
  5504. },
  5505. useEffect: function (create, deps) {
  5506. currentHookNameInDev = 'useEffect';
  5507. updateHookTypesDev();
  5508. return updateEffect(create, deps);
  5509. },
  5510. useImperativeHandle: function (ref, create, deps) {
  5511. currentHookNameInDev = 'useImperativeHandle';
  5512. updateHookTypesDev();
  5513. return updateImperativeHandle(ref, create, deps);
  5514. },
  5515. useLayoutEffect: function (create, deps) {
  5516. currentHookNameInDev = 'useLayoutEffect';
  5517. updateHookTypesDev();
  5518. return updateLayoutEffect(create, deps);
  5519. },
  5520. useMemo: function (create, deps) {
  5521. currentHookNameInDev = 'useMemo';
  5522. updateHookTypesDev();
  5523. var prevDispatcher = ReactCurrentDispatcher.current;
  5524. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  5525. try {
  5526. return updateMemo(create, deps);
  5527. } finally {
  5528. ReactCurrentDispatcher.current = prevDispatcher;
  5529. }
  5530. },
  5531. useReducer: function (reducer, initialArg, init) {
  5532. currentHookNameInDev = 'useReducer';
  5533. updateHookTypesDev();
  5534. var prevDispatcher = ReactCurrentDispatcher.current;
  5535. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  5536. try {
  5537. return rerenderReducer(reducer, initialArg, init);
  5538. } finally {
  5539. ReactCurrentDispatcher.current = prevDispatcher;
  5540. }
  5541. },
  5542. useRef: function (initialValue) {
  5543. currentHookNameInDev = 'useRef';
  5544. updateHookTypesDev();
  5545. return updateRef();
  5546. },
  5547. useState: function (initialState) {
  5548. currentHookNameInDev = 'useState';
  5549. updateHookTypesDev();
  5550. var prevDispatcher = ReactCurrentDispatcher.current;
  5551. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  5552. try {
  5553. return rerenderState(initialState);
  5554. } finally {
  5555. ReactCurrentDispatcher.current = prevDispatcher;
  5556. }
  5557. },
  5558. useDebugValue: function (value, formatterFn) {
  5559. currentHookNameInDev = 'useDebugValue';
  5560. updateHookTypesDev();
  5561. return updateDebugValue();
  5562. },
  5563. useResponder: function (responder, props) {
  5564. currentHookNameInDev = 'useResponder';
  5565. updateHookTypesDev();
  5566. return createDeprecatedResponderListener(responder, props);
  5567. },
  5568. useDeferredValue: function (value, config) {
  5569. currentHookNameInDev = 'useDeferredValue';
  5570. updateHookTypesDev();
  5571. return rerenderDeferredValue(value, config);
  5572. },
  5573. useTransition: function (config) {
  5574. currentHookNameInDev = 'useTransition';
  5575. updateHookTypesDev();
  5576. return rerenderTransition(config);
  5577. }
  5578. };
  5579. InvalidNestedHooksDispatcherOnMountInDEV = {
  5580. readContext: function (context, observedBits) {
  5581. warnInvalidContextAccess();
  5582. return readContext(context, observedBits);
  5583. },
  5584. useCallback: function (callback, deps) {
  5585. currentHookNameInDev = 'useCallback';
  5586. warnInvalidHookAccess();
  5587. mountHookTypesDev();
  5588. return mountCallback(callback, deps);
  5589. },
  5590. useContext: function (context, observedBits) {
  5591. currentHookNameInDev = 'useContext';
  5592. warnInvalidHookAccess();
  5593. mountHookTypesDev();
  5594. return readContext(context, observedBits);
  5595. },
  5596. useEffect: function (create, deps) {
  5597. currentHookNameInDev = 'useEffect';
  5598. warnInvalidHookAccess();
  5599. mountHookTypesDev();
  5600. return mountEffect(create, deps);
  5601. },
  5602. useImperativeHandle: function (ref, create, deps) {
  5603. currentHookNameInDev = 'useImperativeHandle';
  5604. warnInvalidHookAccess();
  5605. mountHookTypesDev();
  5606. return mountImperativeHandle(ref, create, deps);
  5607. },
  5608. useLayoutEffect: function (create, deps) {
  5609. currentHookNameInDev = 'useLayoutEffect';
  5610. warnInvalidHookAccess();
  5611. mountHookTypesDev();
  5612. return mountLayoutEffect(create, deps);
  5613. },
  5614. useMemo: function (create, deps) {
  5615. currentHookNameInDev = 'useMemo';
  5616. warnInvalidHookAccess();
  5617. mountHookTypesDev();
  5618. var prevDispatcher = ReactCurrentDispatcher.current;
  5619. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5620. try {
  5621. return mountMemo(create, deps);
  5622. } finally {
  5623. ReactCurrentDispatcher.current = prevDispatcher;
  5624. }
  5625. },
  5626. useReducer: function (reducer, initialArg, init) {
  5627. currentHookNameInDev = 'useReducer';
  5628. warnInvalidHookAccess();
  5629. mountHookTypesDev();
  5630. var prevDispatcher = ReactCurrentDispatcher.current;
  5631. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5632. try {
  5633. return mountReducer(reducer, initialArg, init);
  5634. } finally {
  5635. ReactCurrentDispatcher.current = prevDispatcher;
  5636. }
  5637. },
  5638. useRef: function (initialValue) {
  5639. currentHookNameInDev = 'useRef';
  5640. warnInvalidHookAccess();
  5641. mountHookTypesDev();
  5642. return mountRef(initialValue);
  5643. },
  5644. useState: function (initialState) {
  5645. currentHookNameInDev = 'useState';
  5646. warnInvalidHookAccess();
  5647. mountHookTypesDev();
  5648. var prevDispatcher = ReactCurrentDispatcher.current;
  5649. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  5650. try {
  5651. return mountState(initialState);
  5652. } finally {
  5653. ReactCurrentDispatcher.current = prevDispatcher;
  5654. }
  5655. },
  5656. useDebugValue: function (value, formatterFn) {
  5657. currentHookNameInDev = 'useDebugValue';
  5658. warnInvalidHookAccess();
  5659. mountHookTypesDev();
  5660. return mountDebugValue();
  5661. },
  5662. useResponder: function (responder, props) {
  5663. currentHookNameInDev = 'useResponder';
  5664. warnInvalidHookAccess();
  5665. mountHookTypesDev();
  5666. return createDeprecatedResponderListener(responder, props);
  5667. },
  5668. useDeferredValue: function (value, config) {
  5669. currentHookNameInDev = 'useDeferredValue';
  5670. warnInvalidHookAccess();
  5671. mountHookTypesDev();
  5672. return mountDeferredValue(value, config);
  5673. },
  5674. useTransition: function (config) {
  5675. currentHookNameInDev = 'useTransition';
  5676. warnInvalidHookAccess();
  5677. mountHookTypesDev();
  5678. return mountTransition(config);
  5679. }
  5680. };
  5681. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  5682. readContext: function (context, observedBits) {
  5683. warnInvalidContextAccess();
  5684. return readContext(context, observedBits);
  5685. },
  5686. useCallback: function (callback, deps) {
  5687. currentHookNameInDev = 'useCallback';
  5688. warnInvalidHookAccess();
  5689. updateHookTypesDev();
  5690. return updateCallback(callback, deps);
  5691. },
  5692. useContext: function (context, observedBits) {
  5693. currentHookNameInDev = 'useContext';
  5694. warnInvalidHookAccess();
  5695. updateHookTypesDev();
  5696. return readContext(context, observedBits);
  5697. },
  5698. useEffect: function (create, deps) {
  5699. currentHookNameInDev = 'useEffect';
  5700. warnInvalidHookAccess();
  5701. updateHookTypesDev();
  5702. return updateEffect(create, deps);
  5703. },
  5704. useImperativeHandle: function (ref, create, deps) {
  5705. currentHookNameInDev = 'useImperativeHandle';
  5706. warnInvalidHookAccess();
  5707. updateHookTypesDev();
  5708. return updateImperativeHandle(ref, create, deps);
  5709. },
  5710. useLayoutEffect: function (create, deps) {
  5711. currentHookNameInDev = 'useLayoutEffect';
  5712. warnInvalidHookAccess();
  5713. updateHookTypesDev();
  5714. return updateLayoutEffect(create, deps);
  5715. },
  5716. useMemo: function (create, deps) {
  5717. currentHookNameInDev = 'useMemo';
  5718. warnInvalidHookAccess();
  5719. updateHookTypesDev();
  5720. var prevDispatcher = ReactCurrentDispatcher.current;
  5721. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5722. try {
  5723. return updateMemo(create, deps);
  5724. } finally {
  5725. ReactCurrentDispatcher.current = prevDispatcher;
  5726. }
  5727. },
  5728. useReducer: function (reducer, initialArg, init) {
  5729. currentHookNameInDev = 'useReducer';
  5730. warnInvalidHookAccess();
  5731. updateHookTypesDev();
  5732. var prevDispatcher = ReactCurrentDispatcher.current;
  5733. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5734. try {
  5735. return updateReducer(reducer, initialArg, init);
  5736. } finally {
  5737. ReactCurrentDispatcher.current = prevDispatcher;
  5738. }
  5739. },
  5740. useRef: function (initialValue) {
  5741. currentHookNameInDev = 'useRef';
  5742. warnInvalidHookAccess();
  5743. updateHookTypesDev();
  5744. return updateRef();
  5745. },
  5746. useState: function (initialState) {
  5747. currentHookNameInDev = 'useState';
  5748. warnInvalidHookAccess();
  5749. updateHookTypesDev();
  5750. var prevDispatcher = ReactCurrentDispatcher.current;
  5751. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5752. try {
  5753. return updateState(initialState);
  5754. } finally {
  5755. ReactCurrentDispatcher.current = prevDispatcher;
  5756. }
  5757. },
  5758. useDebugValue: function (value, formatterFn) {
  5759. currentHookNameInDev = 'useDebugValue';
  5760. warnInvalidHookAccess();
  5761. updateHookTypesDev();
  5762. return updateDebugValue();
  5763. },
  5764. useResponder: function (responder, props) {
  5765. currentHookNameInDev = 'useResponder';
  5766. warnInvalidHookAccess();
  5767. updateHookTypesDev();
  5768. return createDeprecatedResponderListener(responder, props);
  5769. },
  5770. useDeferredValue: function (value, config) {
  5771. currentHookNameInDev = 'useDeferredValue';
  5772. warnInvalidHookAccess();
  5773. updateHookTypesDev();
  5774. return updateDeferredValue(value, config);
  5775. },
  5776. useTransition: function (config) {
  5777. currentHookNameInDev = 'useTransition';
  5778. warnInvalidHookAccess();
  5779. updateHookTypesDev();
  5780. return updateTransition(config);
  5781. }
  5782. };
  5783. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  5784. readContext: function (context, observedBits) {
  5785. warnInvalidContextAccess();
  5786. return readContext(context, observedBits);
  5787. },
  5788. useCallback: function (callback, deps) {
  5789. currentHookNameInDev = 'useCallback';
  5790. warnInvalidHookAccess();
  5791. updateHookTypesDev();
  5792. return updateCallback(callback, deps);
  5793. },
  5794. useContext: function (context, observedBits) {
  5795. currentHookNameInDev = 'useContext';
  5796. warnInvalidHookAccess();
  5797. updateHookTypesDev();
  5798. return readContext(context, observedBits);
  5799. },
  5800. useEffect: function (create, deps) {
  5801. currentHookNameInDev = 'useEffect';
  5802. warnInvalidHookAccess();
  5803. updateHookTypesDev();
  5804. return updateEffect(create, deps);
  5805. },
  5806. useImperativeHandle: function (ref, create, deps) {
  5807. currentHookNameInDev = 'useImperativeHandle';
  5808. warnInvalidHookAccess();
  5809. updateHookTypesDev();
  5810. return updateImperativeHandle(ref, create, deps);
  5811. },
  5812. useLayoutEffect: function (create, deps) {
  5813. currentHookNameInDev = 'useLayoutEffect';
  5814. warnInvalidHookAccess();
  5815. updateHookTypesDev();
  5816. return updateLayoutEffect(create, deps);
  5817. },
  5818. useMemo: function (create, deps) {
  5819. currentHookNameInDev = 'useMemo';
  5820. warnInvalidHookAccess();
  5821. updateHookTypesDev();
  5822. var prevDispatcher = ReactCurrentDispatcher.current;
  5823. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5824. try {
  5825. return updateMemo(create, deps);
  5826. } finally {
  5827. ReactCurrentDispatcher.current = prevDispatcher;
  5828. }
  5829. },
  5830. useReducer: function (reducer, initialArg, init) {
  5831. currentHookNameInDev = 'useReducer';
  5832. warnInvalidHookAccess();
  5833. updateHookTypesDev();
  5834. var prevDispatcher = ReactCurrentDispatcher.current;
  5835. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5836. try {
  5837. return rerenderReducer(reducer, initialArg, init);
  5838. } finally {
  5839. ReactCurrentDispatcher.current = prevDispatcher;
  5840. }
  5841. },
  5842. useRef: function (initialValue) {
  5843. currentHookNameInDev = 'useRef';
  5844. warnInvalidHookAccess();
  5845. updateHookTypesDev();
  5846. return updateRef();
  5847. },
  5848. useState: function (initialState) {
  5849. currentHookNameInDev = 'useState';
  5850. warnInvalidHookAccess();
  5851. updateHookTypesDev();
  5852. var prevDispatcher = ReactCurrentDispatcher.current;
  5853. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  5854. try {
  5855. return rerenderState(initialState);
  5856. } finally {
  5857. ReactCurrentDispatcher.current = prevDispatcher;
  5858. }
  5859. },
  5860. useDebugValue: function (value, formatterFn) {
  5861. currentHookNameInDev = 'useDebugValue';
  5862. warnInvalidHookAccess();
  5863. updateHookTypesDev();
  5864. return updateDebugValue();
  5865. },
  5866. useResponder: function (responder, props) {
  5867. currentHookNameInDev = 'useResponder';
  5868. warnInvalidHookAccess();
  5869. updateHookTypesDev();
  5870. return createDeprecatedResponderListener(responder, props);
  5871. },
  5872. useDeferredValue: function (value, config) {
  5873. currentHookNameInDev = 'useDeferredValue';
  5874. warnInvalidHookAccess();
  5875. updateHookTypesDev();
  5876. return rerenderDeferredValue(value, config);
  5877. },
  5878. useTransition: function (config) {
  5879. currentHookNameInDev = 'useTransition';
  5880. warnInvalidHookAccess();
  5881. updateHookTypesDev();
  5882. return rerenderTransition(config);
  5883. }
  5884. };
  5885. }
  5886. var now$1 = Scheduler$1.unstable_now;
  5887. var commitTime = 0;
  5888. var profilerStartTime = -1;
  5889. function getCommitTime() {
  5890. return commitTime;
  5891. }
  5892. function recordCommitTime() {
  5893. commitTime = now$1();
  5894. }
  5895. function startProfilerTimer(fiber) {
  5896. profilerStartTime = now$1();
  5897. if (fiber.actualStartTime < 0) {
  5898. fiber.actualStartTime = now$1();
  5899. }
  5900. }
  5901. function stopProfilerTimerIfRunning(fiber) {
  5902. profilerStartTime = -1;
  5903. }
  5904. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  5905. if (profilerStartTime >= 0) {
  5906. var elapsedTime = now$1() - profilerStartTime;
  5907. fiber.actualDuration += elapsedTime;
  5908. if (overrideBaseTime) {
  5909. fiber.selfBaseDuration = elapsedTime;
  5910. }
  5911. profilerStartTime = -1;
  5912. }
  5913. }
  5914. function enterHydrationState(fiber) {
  5915. {
  5916. return false;
  5917. }
  5918. }
  5919. function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
  5920. {
  5921. {
  5922. {
  5923. throw Error( "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." );
  5924. }
  5925. }
  5926. }
  5927. }
  5928. function prepareToHydrateHostTextInstance(fiber) {
  5929. {
  5930. {
  5931. {
  5932. throw Error( "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." );
  5933. }
  5934. }
  5935. }
  5936. var shouldUpdate = hydrateTextInstance();
  5937. }
  5938. function popHydrationState(fiber) {
  5939. {
  5940. return false;
  5941. }
  5942. }
  5943. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  5944. var didReceiveUpdate = false;
  5945. var didWarnAboutBadClass;
  5946. var didWarnAboutModulePatternComponent;
  5947. var didWarnAboutContextTypeOnFunctionComponent;
  5948. var didWarnAboutGetDerivedStateOnFunctionComponent;
  5949. var didWarnAboutFunctionRefs;
  5950. var didWarnAboutReassigningProps;
  5951. var didWarnAboutRevealOrder;
  5952. var didWarnAboutTailOptions;
  5953. {
  5954. didWarnAboutBadClass = {};
  5955. didWarnAboutModulePatternComponent = {};
  5956. didWarnAboutContextTypeOnFunctionComponent = {};
  5957. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  5958. didWarnAboutFunctionRefs = {};
  5959. didWarnAboutReassigningProps = false;
  5960. didWarnAboutRevealOrder = {};
  5961. didWarnAboutTailOptions = {};
  5962. }
  5963. function reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime) {
  5964. if (current === null) {
  5965. // If this is a fresh new component that hasn't been rendered yet, we
  5966. // won't update its child set by applying minimal side-effects. Instead,
  5967. // we will add them all to the child before it gets rendered. That means
  5968. // we can optimize this reconciliation pass by not tracking side-effects.
  5969. workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  5970. } else {
  5971. // If the current child is the same as the work in progress, it means that
  5972. // we haven't yet started any work on these children. Therefore, we use
  5973. // the clone algorithm to create a copy of all the current children.
  5974. // If we had any progressed work already, that is invalid at this point so
  5975. // let's throw it out.
  5976. workInProgress.child = reconcileChildFibers(workInProgress, current.child, nextChildren, renderExpirationTime);
  5977. }
  5978. }
  5979. function forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderExpirationTime) {
  5980. // This function is fork of reconcileChildren. It's used in cases where we
  5981. // want to reconcile without matching against the existing set. This has the
  5982. // effect of all current children being unmounted; even if the type and key
  5983. // are the same, the old child is unmounted and a new child is created.
  5984. //
  5985. // To do this, we're going to go through the reconcile algorithm twice. In
  5986. // the first pass, we schedule a deletion for all the current children by
  5987. // passing null.
  5988. workInProgress.child = reconcileChildFibers(workInProgress, current.child, null, renderExpirationTime); // In the second pass, we mount the new children. The trick here is that we
  5989. // pass null in place of where we usually pass the current child set. This has
  5990. // the effect of remounting all children regardless of whether their
  5991. // identities match.
  5992. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  5993. }
  5994. function updateForwardRef(current, workInProgress, Component, nextProps, renderExpirationTime) {
  5995. // TODO: current can be non-null here even if the component
  5996. // hasn't yet mounted. This happens after the first render suspends.
  5997. // We'll need to figure out if this is fine or can cause issues.
  5998. {
  5999. if (workInProgress.type !== workInProgress.elementType) {
  6000. // Lazy component props can't be validated in createElement
  6001. // because they're only guaranteed to be resolved here.
  6002. var innerPropTypes = Component.propTypes;
  6003. if (innerPropTypes) {
  6004. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  6005. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6006. }
  6007. }
  6008. }
  6009. var render = Component.render;
  6010. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  6011. var nextChildren;
  6012. prepareToReadContext(workInProgress, renderExpirationTime);
  6013. {
  6014. ReactCurrentOwner$1.current = workInProgress;
  6015. setIsRendering(true);
  6016. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderExpirationTime);
  6017. setIsRendering(false);
  6018. }
  6019. if (current !== null && !didReceiveUpdate) {
  6020. bailoutHooks(current, workInProgress, renderExpirationTime);
  6021. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6022. } // React DevTools reads this flag.
  6023. workInProgress.effectTag |= PerformedWork;
  6024. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6025. return workInProgress.child;
  6026. }
  6027. function updateMemoComponent(current, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
  6028. if (current === null) {
  6029. var type = Component.type;
  6030. if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  6031. Component.defaultProps === undefined) {
  6032. var resolvedType = type;
  6033. {
  6034. resolvedType = resolveFunctionForHotReloading(type);
  6035. } // If this is a plain function component without default props,
  6036. // and with only the default shallow comparison, we upgrade it
  6037. // to a SimpleMemoComponent to allow fast path updates.
  6038. workInProgress.tag = SimpleMemoComponent;
  6039. workInProgress.type = resolvedType;
  6040. {
  6041. validateFunctionComponentInDev(workInProgress, type);
  6042. }
  6043. return updateSimpleMemoComponent(current, workInProgress, resolvedType, nextProps, updateExpirationTime, renderExpirationTime);
  6044. }
  6045. {
  6046. var innerPropTypes = type.propTypes;
  6047. if (innerPropTypes) {
  6048. // Inner memo component props aren't currently validated in createElement.
  6049. // We could move it there, but we'd still need this for lazy code path.
  6050. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  6051. 'prop', getComponentName(type), getCurrentFiberStackInDev);
  6052. }
  6053. }
  6054. var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
  6055. child.ref = workInProgress.ref;
  6056. child.return = workInProgress;
  6057. workInProgress.child = child;
  6058. return child;
  6059. }
  6060. {
  6061. var _type = Component.type;
  6062. var _innerPropTypes = _type.propTypes;
  6063. if (_innerPropTypes) {
  6064. // Inner memo component props aren't currently validated in createElement.
  6065. // We could move it there, but we'd still need this for lazy code path.
  6066. checkPropTypes(_innerPropTypes, nextProps, // Resolved props
  6067. 'prop', getComponentName(_type), getCurrentFiberStackInDev);
  6068. }
  6069. }
  6070. var currentChild = current.child; // This is always exactly one child
  6071. if (updateExpirationTime < renderExpirationTime) {
  6072. // This will be the props with resolved defaultProps,
  6073. // unlike current.memoizedProps which will be the unresolved ones.
  6074. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  6075. var compare = Component.compare;
  6076. compare = compare !== null ? compare : shallowEqual;
  6077. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  6078. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6079. }
  6080. } // React DevTools reads this flag.
  6081. workInProgress.effectTag |= PerformedWork;
  6082. var newChild = createWorkInProgress(currentChild, nextProps);
  6083. newChild.ref = workInProgress.ref;
  6084. newChild.return = workInProgress;
  6085. workInProgress.child = newChild;
  6086. return newChild;
  6087. }
  6088. function updateSimpleMemoComponent(current, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
  6089. // TODO: current can be non-null here even if the component
  6090. // hasn't yet mounted. This happens when the inner render suspends.
  6091. // We'll need to figure out if this is fine or can cause issues.
  6092. {
  6093. if (workInProgress.type !== workInProgress.elementType) {
  6094. // Lazy component props can't be validated in createElement
  6095. // because they're only guaranteed to be resolved here.
  6096. var outerMemoType = workInProgress.elementType;
  6097. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  6098. // We warn when you define propTypes on lazy()
  6099. // so let's just skip over it to find memo() outer wrapper.
  6100. // Inner props for memo are validated later.
  6101. outerMemoType = refineResolvedLazyComponent(outerMemoType);
  6102. }
  6103. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  6104. if (outerPropTypes) {
  6105. checkPropTypes(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  6106. 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
  6107. } // Inner propTypes will be validated in the function component path.
  6108. }
  6109. }
  6110. if (current !== null) {
  6111. var prevProps = current.memoizedProps;
  6112. if (shallowEqual(prevProps, nextProps) && current.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload.
  6113. workInProgress.type === current.type )) {
  6114. didReceiveUpdate = false;
  6115. if (updateExpirationTime < renderExpirationTime) {
  6116. // The pending update priority was cleared at the beginning of
  6117. // beginWork. We're about to bail out, but there might be additional
  6118. // updates at a lower priority. Usually, the priority level of the
  6119. // remaining updates is accumlated during the evaluation of the
  6120. // component (i.e. when processing the update queue). But since since
  6121. // we're bailing out early *without* evaluating the component, we need
  6122. // to account for it here, too. Reset to the value of the current fiber.
  6123. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  6124. // because a MemoComponent fiber does not have hooks or an update queue;
  6125. // rather, it wraps around an inner component, which may or may not
  6126. // contains hooks.
  6127. // TODO: Move the reset at in beginWork out of the common path so that
  6128. // this is no longer necessary.
  6129. workInProgress.expirationTime = current.expirationTime;
  6130. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6131. }
  6132. }
  6133. }
  6134. return updateFunctionComponent(current, workInProgress, Component, nextProps, renderExpirationTime);
  6135. }
  6136. function updateFragment(current, workInProgress, renderExpirationTime) {
  6137. var nextChildren = workInProgress.pendingProps;
  6138. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6139. return workInProgress.child;
  6140. }
  6141. function updateMode(current, workInProgress, renderExpirationTime) {
  6142. var nextChildren = workInProgress.pendingProps.children;
  6143. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6144. return workInProgress.child;
  6145. }
  6146. function updateProfiler(current, workInProgress, renderExpirationTime) {
  6147. {
  6148. workInProgress.effectTag |= Update;
  6149. }
  6150. var nextProps = workInProgress.pendingProps;
  6151. var nextChildren = nextProps.children;
  6152. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6153. return workInProgress.child;
  6154. }
  6155. function markRef(current, workInProgress) {
  6156. var ref = workInProgress.ref;
  6157. if (current === null && ref !== null || current !== null && current.ref !== ref) {
  6158. // Schedule a Ref effect
  6159. workInProgress.effectTag |= Ref;
  6160. }
  6161. }
  6162. function updateFunctionComponent(current, workInProgress, Component, nextProps, renderExpirationTime) {
  6163. {
  6164. if (workInProgress.type !== workInProgress.elementType) {
  6165. // Lazy component props can't be validated in createElement
  6166. // because they're only guaranteed to be resolved here.
  6167. var innerPropTypes = Component.propTypes;
  6168. if (innerPropTypes) {
  6169. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  6170. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6171. }
  6172. }
  6173. }
  6174. var context;
  6175. {
  6176. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  6177. context = getMaskedContext(workInProgress, unmaskedContext);
  6178. }
  6179. var nextChildren;
  6180. prepareToReadContext(workInProgress, renderExpirationTime);
  6181. {
  6182. ReactCurrentOwner$1.current = workInProgress;
  6183. setIsRendering(true);
  6184. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderExpirationTime);
  6185. setIsRendering(false);
  6186. }
  6187. if (current !== null && !didReceiveUpdate) {
  6188. bailoutHooks(current, workInProgress, renderExpirationTime);
  6189. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6190. } // React DevTools reads this flag.
  6191. workInProgress.effectTag |= PerformedWork;
  6192. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6193. return workInProgress.child;
  6194. }
  6195. function updateClassComponent(current, workInProgress, Component, nextProps, renderExpirationTime) {
  6196. {
  6197. if (workInProgress.type !== workInProgress.elementType) {
  6198. // Lazy component props can't be validated in createElement
  6199. // because they're only guaranteed to be resolved here.
  6200. var innerPropTypes = Component.propTypes;
  6201. if (innerPropTypes) {
  6202. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  6203. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6204. }
  6205. }
  6206. } // Push context providers early to prevent context stack mismatches.
  6207. // During mounting we don't know the child context yet as the instance doesn't exist.
  6208. // We will invalidate the child context in finishClassComponent() right after rendering.
  6209. var hasContext;
  6210. if (isContextProvider(Component)) {
  6211. hasContext = true;
  6212. pushContextProvider(workInProgress);
  6213. } else {
  6214. hasContext = false;
  6215. }
  6216. prepareToReadContext(workInProgress, renderExpirationTime);
  6217. var instance = workInProgress.stateNode;
  6218. var shouldUpdate;
  6219. if (instance === null) {
  6220. if (current !== null) {
  6221. // A class component without an instance only mounts if it suspended
  6222. // inside a non-concurrent tree, in an inconsistent state. We want to
  6223. // treat it like a new mount, even though an empty version of it already
  6224. // committed. Disconnect the alternate pointers.
  6225. current.alternate = null;
  6226. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6227. workInProgress.effectTag |= Placement;
  6228. } // In the initial pass we might need to construct the instance.
  6229. constructClassInstance(workInProgress, Component, nextProps);
  6230. mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  6231. shouldUpdate = true;
  6232. } else if (current === null) {
  6233. // In a resume, we'll already have an instance we can reuse.
  6234. shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  6235. } else {
  6236. shouldUpdate = updateClassInstance(current, workInProgress, Component, nextProps, renderExpirationTime);
  6237. }
  6238. var nextUnitOfWork = finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
  6239. {
  6240. var inst = workInProgress.stateNode;
  6241. if (inst.props !== nextProps) {
  6242. if (!didWarnAboutReassigningProps) {
  6243. 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');
  6244. }
  6245. didWarnAboutReassigningProps = true;
  6246. }
  6247. }
  6248. return nextUnitOfWork;
  6249. }
  6250. function finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
  6251. // Refs should update even if shouldComponentUpdate returns false
  6252. markRef(current, workInProgress);
  6253. var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
  6254. if (!shouldUpdate && !didCaptureError) {
  6255. // Context providers should defer to sCU for rendering
  6256. if (hasContext) {
  6257. invalidateContextProvider(workInProgress, Component, false);
  6258. }
  6259. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6260. }
  6261. var instance = workInProgress.stateNode; // Rerender
  6262. ReactCurrentOwner$1.current = workInProgress;
  6263. var nextChildren;
  6264. if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
  6265. // If we captured an error, but getDerivedStateFromError is not defined,
  6266. // unmount all the children. componentDidCatch will schedule an update to
  6267. // re-render a fallback. This is temporary until we migrate everyone to
  6268. // the new API.
  6269. // TODO: Warn in a future release.
  6270. nextChildren = null;
  6271. {
  6272. stopProfilerTimerIfRunning();
  6273. }
  6274. } else {
  6275. {
  6276. setIsRendering(true);
  6277. nextChildren = instance.render();
  6278. setIsRendering(false);
  6279. }
  6280. } // React DevTools reads this flag.
  6281. workInProgress.effectTag |= PerformedWork;
  6282. if (current !== null && didCaptureError) {
  6283. // If we're recovering from an error, reconcile without reusing any of
  6284. // the existing children. Conceptually, the normal children and the children
  6285. // that are shown on error are two different sets, so we shouldn't reuse
  6286. // normal children even if their identities match.
  6287. forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderExpirationTime);
  6288. } else {
  6289. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6290. } // Memoize state using the values we just used to render.
  6291. // TODO: Restructure so we never read values from the instance.
  6292. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  6293. if (hasContext) {
  6294. invalidateContextProvider(workInProgress, Component, true);
  6295. }
  6296. return workInProgress.child;
  6297. }
  6298. function pushHostRootContext(workInProgress) {
  6299. var root = workInProgress.stateNode;
  6300. if (root.pendingContext) {
  6301. pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
  6302. } else if (root.context) {
  6303. // Should always be set
  6304. pushTopLevelContextObject(workInProgress, root.context, false);
  6305. }
  6306. pushHostContainer(workInProgress, root.containerInfo);
  6307. }
  6308. function updateHostRoot(current, workInProgress, renderExpirationTime) {
  6309. pushHostRootContext(workInProgress);
  6310. var updateQueue = workInProgress.updateQueue;
  6311. if (!(current !== null && updateQueue !== null)) {
  6312. {
  6313. 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." );
  6314. }
  6315. }
  6316. var nextProps = workInProgress.pendingProps;
  6317. var prevState = workInProgress.memoizedState;
  6318. var prevChildren = prevState !== null ? prevState.element : null;
  6319. cloneUpdateQueue(current, workInProgress);
  6320. processUpdateQueue(workInProgress, nextProps, null, renderExpirationTime);
  6321. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  6322. // being called "element".
  6323. var nextChildren = nextState.element;
  6324. if (nextChildren === prevChildren) {
  6325. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  6326. }
  6327. var root = workInProgress.stateNode;
  6328. if (root.hydrate && enterHydrationState()) {
  6329. // If we don't have any current children this might be the first pass.
  6330. // We always try to hydrate. If this isn't a hydration pass there won't
  6331. // be any children to hydrate which is effectively the same thing as
  6332. // not hydrating.
  6333. var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  6334. workInProgress.child = child;
  6335. var node = child;
  6336. while (node) {
  6337. // Mark each child as hydrating. This is a fast path to know whether this
  6338. // tree is part of a hydrating tree. This is used to determine if a child
  6339. // node has fully mounted yet, and for scheduling event replaying.
  6340. // Conceptually this is similar to Placement in that a new subtree is
  6341. // inserted into the React tree here. It just happens to not need DOM
  6342. // mutations because it already exists.
  6343. node.effectTag = node.effectTag & ~Placement | Hydrating;
  6344. node = node.sibling;
  6345. }
  6346. } else {
  6347. // Otherwise reset hydration state in case we aborted and resumed another
  6348. // root.
  6349. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6350. }
  6351. return workInProgress.child;
  6352. }
  6353. function updateHostComponent(current, workInProgress, renderExpirationTime) {
  6354. pushHostContext(workInProgress);
  6355. var type = workInProgress.type;
  6356. var nextProps = workInProgress.pendingProps;
  6357. var prevProps = current !== null ? current.memoizedProps : null;
  6358. var nextChildren = nextProps.children;
  6359. if (prevProps !== null && shouldSetTextContent()) {
  6360. // If we're switching from a direct text child to a normal child, or to
  6361. // empty, we need to schedule the text content to be reset.
  6362. workInProgress.effectTag |= ContentReset;
  6363. }
  6364. markRef(current, workInProgress); // Check the host config to see if the children are offscreen/hidden.
  6365. if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree()) {
  6366. {
  6367. markSpawnedWork(Never);
  6368. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  6369. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  6370. return null;
  6371. }
  6372. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  6373. return workInProgress.child;
  6374. }
  6375. function updateHostText(current, workInProgress) {
  6376. // immediately after.
  6377. return null;
  6378. }
  6379. function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
  6380. if (_current !== null) {
  6381. // A lazy component only mounts if it suspended inside a non-
  6382. // concurrent tree, in an inconsistent state. We want to treat it like
  6383. // a new mount, even though an empty version of it already committed.
  6384. // Disconnect the alternate pointers.
  6385. _current.alternate = null;
  6386. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6387. workInProgress.effectTag |= Placement;
  6388. }
  6389. var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
  6390. // Cancel and resume right after we know the tag.
  6391. cancelWorkTimer(workInProgress);
  6392. var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
  6393. workInProgress.type = Component;
  6394. var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
  6395. startWorkTimer(workInProgress);
  6396. var resolvedProps = resolveDefaultProps(Component, props);
  6397. var child;
  6398. switch (resolvedTag) {
  6399. case FunctionComponent:
  6400. {
  6401. {
  6402. validateFunctionComponentInDev(workInProgress, Component);
  6403. workInProgress.type = Component = resolveFunctionForHotReloading(Component);
  6404. }
  6405. child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  6406. return child;
  6407. }
  6408. case ClassComponent:
  6409. {
  6410. {
  6411. workInProgress.type = Component = resolveClassForHotReloading(Component);
  6412. }
  6413. child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  6414. return child;
  6415. }
  6416. case ForwardRef:
  6417. {
  6418. {
  6419. workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
  6420. }
  6421. child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
  6422. return child;
  6423. }
  6424. case MemoComponent:
  6425. {
  6426. {
  6427. if (workInProgress.type !== workInProgress.elementType) {
  6428. var outerPropTypes = Component.propTypes;
  6429. if (outerPropTypes) {
  6430. checkPropTypes(outerPropTypes, resolvedProps, // Resolved for outer only
  6431. 'prop', getComponentName(Component), getCurrentFiberStackInDev);
  6432. }
  6433. }
  6434. }
  6435. child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  6436. updateExpirationTime, renderExpirationTime);
  6437. return child;
  6438. }
  6439. }
  6440. var hint = '';
  6441. {
  6442. if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
  6443. hint = ' Did you wrap a component in React.lazy() more than once?';
  6444. }
  6445. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  6446. // because the fact that it's a separate type of work is an
  6447. // implementation detail.
  6448. {
  6449. {
  6450. throw Error( "Element type is invalid. Received a promise that resolves to: " + Component + ". Lazy element type must resolve to a class or function." + hint );
  6451. }
  6452. }
  6453. }
  6454. function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
  6455. if (_current !== null) {
  6456. // An incomplete component only mounts if it suspended inside a non-
  6457. // concurrent tree, in an inconsistent state. We want to treat it like
  6458. // a new mount, even though an empty version of it already committed.
  6459. // Disconnect the alternate pointers.
  6460. _current.alternate = null;
  6461. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6462. workInProgress.effectTag |= Placement;
  6463. } // Promote the fiber to a class and try rendering again.
  6464. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  6465. // Push context providers early to prevent context stack mismatches.
  6466. // During mounting we don't know the child context yet as the instance doesn't exist.
  6467. // We will invalidate the child context in finishClassComponent() right after rendering.
  6468. var hasContext;
  6469. if (isContextProvider(Component)) {
  6470. hasContext = true;
  6471. pushContextProvider(workInProgress);
  6472. } else {
  6473. hasContext = false;
  6474. }
  6475. prepareToReadContext(workInProgress, renderExpirationTime);
  6476. constructClassInstance(workInProgress, Component, nextProps);
  6477. mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
  6478. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
  6479. }
  6480. function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
  6481. if (_current !== null) {
  6482. // An indeterminate component only mounts if it suspended inside a non-
  6483. // concurrent tree, in an inconsistent state. We want to treat it like
  6484. // a new mount, even though an empty version of it already committed.
  6485. // Disconnect the alternate pointers.
  6486. _current.alternate = null;
  6487. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  6488. workInProgress.effectTag |= Placement;
  6489. }
  6490. var props = workInProgress.pendingProps;
  6491. var context;
  6492. {
  6493. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  6494. context = getMaskedContext(workInProgress, unmaskedContext);
  6495. }
  6496. prepareToReadContext(workInProgress, renderExpirationTime);
  6497. var value;
  6498. {
  6499. if (Component.prototype && typeof Component.prototype.render === 'function') {
  6500. var componentName = getComponentName(Component) || 'Unknown';
  6501. if (!didWarnAboutBadClass[componentName]) {
  6502. 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);
  6503. didWarnAboutBadClass[componentName] = true;
  6504. }
  6505. }
  6506. if (workInProgress.mode & StrictMode) {
  6507. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  6508. }
  6509. setIsRendering(true);
  6510. ReactCurrentOwner$1.current = workInProgress;
  6511. value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
  6512. setIsRendering(false);
  6513. } // React DevTools reads this flag.
  6514. workInProgress.effectTag |= PerformedWork;
  6515. if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  6516. {
  6517. var _componentName = getComponentName(Component) || 'Unknown';
  6518. if (!didWarnAboutModulePatternComponent[_componentName]) {
  6519. 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);
  6520. didWarnAboutModulePatternComponent[_componentName] = true;
  6521. }
  6522. } // Proceed under the assumption that this is a class instance
  6523. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  6524. workInProgress.memoizedState = null;
  6525. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  6526. // During mounting we don't know the child context yet as the instance doesn't exist.
  6527. // We will invalidate the child context in finishClassComponent() right after rendering.
  6528. var hasContext = false;
  6529. if (isContextProvider(Component)) {
  6530. hasContext = true;
  6531. pushContextProvider(workInProgress);
  6532. } else {
  6533. hasContext = false;
  6534. }
  6535. workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
  6536. initializeUpdateQueue(workInProgress);
  6537. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  6538. if (typeof getDerivedStateFromProps === 'function') {
  6539. applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
  6540. }
  6541. adoptClassInstance(workInProgress, value);
  6542. mountClassInstance(workInProgress, Component, props, renderExpirationTime);
  6543. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
  6544. } else {
  6545. // Proceed under the assumption that this is a function component
  6546. workInProgress.tag = FunctionComponent;
  6547. reconcileChildren(null, workInProgress, value, renderExpirationTime);
  6548. {
  6549. validateFunctionComponentInDev(workInProgress, Component);
  6550. }
  6551. return workInProgress.child;
  6552. }
  6553. }
  6554. function validateFunctionComponentInDev(workInProgress, Component) {
  6555. {
  6556. if (Component) {
  6557. if (Component.childContextTypes) {
  6558. error('%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component');
  6559. }
  6560. }
  6561. if (workInProgress.ref !== null) {
  6562. var info = '';
  6563. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  6564. if (ownerName) {
  6565. info += '\n\nCheck the render method of `' + ownerName + '`.';
  6566. }
  6567. var warningKey = ownerName || workInProgress._debugID || '';
  6568. var debugSource = workInProgress._debugSource;
  6569. if (debugSource) {
  6570. warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
  6571. }
  6572. if (!didWarnAboutFunctionRefs[warningKey]) {
  6573. didWarnAboutFunctionRefs[warningKey] = true;
  6574. error('Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
  6575. }
  6576. }
  6577. if (typeof Component.getDerivedStateFromProps === 'function') {
  6578. var _componentName2 = getComponentName(Component) || 'Unknown';
  6579. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
  6580. error('%s: Function components do not support getDerivedStateFromProps.', _componentName2);
  6581. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
  6582. }
  6583. }
  6584. if (typeof Component.contextType === 'object' && Component.contextType !== null) {
  6585. var _componentName3 = getComponentName(Component) || 'Unknown';
  6586. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
  6587. error('%s: Function components do not support contextType.', _componentName3);
  6588. didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
  6589. }
  6590. }
  6591. }
  6592. }
  6593. var SUSPENDED_MARKER = {
  6594. dehydrated: null,
  6595. retryTime: NoWork
  6596. };
  6597. function shouldRemainOnFallback(suspenseContext, current, workInProgress) {
  6598. // If the context is telling us that we should show a fallback, and we're not
  6599. // already showing content, then we should show the fallback instead.
  6600. return hasSuspenseContext(suspenseContext, ForceSuspenseFallback) && (current === null || current.memoizedState !== null);
  6601. }
  6602. function updateSuspenseComponent(current, workInProgress, renderExpirationTime) {
  6603. var mode = workInProgress.mode;
  6604. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  6605. {
  6606. if (shouldSuspend(workInProgress)) {
  6607. workInProgress.effectTag |= DidCapture;
  6608. }
  6609. }
  6610. var suspenseContext = suspenseStackCursor.current;
  6611. var nextDidTimeout = false;
  6612. var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
  6613. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  6614. // Something in this boundary's subtree already suspended. Switch to
  6615. // rendering the fallback children.
  6616. nextDidTimeout = true;
  6617. workInProgress.effectTag &= ~DidCapture;
  6618. } else {
  6619. // Attempting the main content
  6620. if (current === null || current.memoizedState !== null) {
  6621. // This is a new mount or this boundary is already showing a fallback state.
  6622. // Mark this subtree context as having at least one invisible parent that could
  6623. // handle the fallback state.
  6624. // Boundaries without fallbacks or should be avoided are not considered since
  6625. // they cannot handle preferred fallback states.
  6626. if (nextProps.fallback !== undefined && nextProps.unstable_avoidThisFallback !== true) {
  6627. suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
  6628. }
  6629. }
  6630. }
  6631. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  6632. pushSuspenseContext(workInProgress, suspenseContext); // This next part is a bit confusing. If the children timeout, we switch to
  6633. // showing the fallback children in place of the "primary" children.
  6634. // However, we don't want to delete the primary children because then their
  6635. // state will be lost (both the React state and the host state, e.g.
  6636. // uncontrolled form inputs). Instead we keep them mounted and hide them.
  6637. // Both the fallback children AND the primary children are rendered at the
  6638. // same time. Once the primary children are un-suspended, we can delete
  6639. // the fallback children — don't need to preserve their state.
  6640. //
  6641. // The two sets of children are siblings in the host environment, but
  6642. // semantically, for purposes of reconciliation, they are two separate sets.
  6643. // So we store them using two fragment fibers.
  6644. //
  6645. // However, we want to avoid allocating extra fibers for every placeholder.
  6646. // They're only necessary when the children time out, because that's the
  6647. // only time when both sets are mounted.
  6648. //
  6649. // So, the extra fragment fibers are only used if the children time out.
  6650. // Otherwise, we render the primary children directly. This requires some
  6651. // custom reconciliation logic to preserve the state of the primary
  6652. // children. It's essentially a very basic form of re-parenting.
  6653. if (current === null) {
  6654. // If we're currently hydrating, try to hydrate this boundary.
  6655. // But only if this has a fallback.
  6656. if (nextProps.fallback !== undefined) ; // This is the initial mount. This branch is pretty simple because there's
  6657. // no previous state that needs to be preserved.
  6658. if (nextDidTimeout) {
  6659. // Mount separate fragments for primary and fallback children.
  6660. var nextFallbackChildren = nextProps.fallback;
  6661. var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
  6662. primaryChildFragment.return = workInProgress;
  6663. if ((workInProgress.mode & BlockingMode) === NoMode) {
  6664. // Outside of blocking mode, we commit the effects from the
  6665. // partially completed, timed-out tree, too.
  6666. var progressedState = workInProgress.memoizedState;
  6667. var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
  6668. primaryChildFragment.child = progressedPrimaryChild;
  6669. var progressedChild = progressedPrimaryChild;
  6670. while (progressedChild !== null) {
  6671. progressedChild.return = primaryChildFragment;
  6672. progressedChild = progressedChild.sibling;
  6673. }
  6674. }
  6675. var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
  6676. fallbackChildFragment.return = workInProgress;
  6677. primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
  6678. // fallback children.
  6679. workInProgress.memoizedState = SUSPENDED_MARKER;
  6680. workInProgress.child = primaryChildFragment;
  6681. return fallbackChildFragment;
  6682. } else {
  6683. // Mount the primary children without an intermediate fragment fiber.
  6684. var nextPrimaryChildren = nextProps.children;
  6685. workInProgress.memoizedState = null;
  6686. return workInProgress.child = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
  6687. }
  6688. } else {
  6689. // This is an update. This branch is more complicated because we need to
  6690. // ensure the state of the primary children is preserved.
  6691. var prevState = current.memoizedState;
  6692. if (prevState !== null) {
  6693. // wrapped in a fragment fiber.
  6694. var currentPrimaryChildFragment = current.child;
  6695. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  6696. if (nextDidTimeout) {
  6697. // Still timed out. Reuse the current primary children by cloning
  6698. // its fragment. We're going to skip over these entirely.
  6699. var _nextFallbackChildren2 = nextProps.fallback;
  6700. var _primaryChildFragment2 = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps);
  6701. _primaryChildFragment2.return = workInProgress;
  6702. if ((workInProgress.mode & BlockingMode) === NoMode) {
  6703. // Outside of blocking mode, we commit the effects from the
  6704. // partially completed, timed-out tree, too.
  6705. var _progressedState = workInProgress.memoizedState;
  6706. var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
  6707. if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
  6708. _primaryChildFragment2.child = _progressedPrimaryChild;
  6709. var _progressedChild2 = _progressedPrimaryChild;
  6710. while (_progressedChild2 !== null) {
  6711. _progressedChild2.return = _primaryChildFragment2;
  6712. _progressedChild2 = _progressedChild2.sibling;
  6713. }
  6714. }
  6715. } // Because primaryChildFragment is a new fiber that we're inserting as the
  6716. // parent of a new tree, we need to set its treeBaseDuration.
  6717. if ( workInProgress.mode & ProfileMode) {
  6718. // treeBaseDuration is the sum of all the child tree base durations.
  6719. var _treeBaseDuration = 0;
  6720. var _hiddenChild = _primaryChildFragment2.child;
  6721. while (_hiddenChild !== null) {
  6722. _treeBaseDuration += _hiddenChild.treeBaseDuration;
  6723. _hiddenChild = _hiddenChild.sibling;
  6724. }
  6725. _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
  6726. } // Clone the fallback child fragment, too. These we'll continue
  6727. // working on.
  6728. var _fallbackChildFragment2 = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren2);
  6729. _fallbackChildFragment2.return = workInProgress;
  6730. _primaryChildFragment2.sibling = _fallbackChildFragment2;
  6731. _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  6732. // fallback children.
  6733. workInProgress.memoizedState = SUSPENDED_MARKER;
  6734. workInProgress.child = _primaryChildFragment2;
  6735. return _fallbackChildFragment2;
  6736. } else {
  6737. // No longer suspended. Switch back to showing the primary children,
  6738. // and remove the intermediate fragment fiber.
  6739. var _nextPrimaryChildren = nextProps.children;
  6740. var currentPrimaryChild = currentPrimaryChildFragment.child;
  6741. var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime); // If this render doesn't suspend, we need to delete the fallback
  6742. // children. Wait until the complete phase, after we've confirmed the
  6743. // fallback is no longer needed.
  6744. // TODO: Would it be better to store the fallback fragment on
  6745. // the stateNode?
  6746. // Continue rendering the children, like we normally do.
  6747. workInProgress.memoizedState = null;
  6748. return workInProgress.child = primaryChild;
  6749. }
  6750. } else {
  6751. // The current tree has not already timed out. That means the primary
  6752. // children are not wrapped in a fragment fiber.
  6753. var _currentPrimaryChild = current.child;
  6754. if (nextDidTimeout) {
  6755. // Timed out. Wrap the children in a fragment fiber to keep them
  6756. // separate from the fallback children.
  6757. var _nextFallbackChildren3 = nextProps.fallback;
  6758. var _primaryChildFragment3 = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
  6759. // going to render this fragment.
  6760. null, mode, NoWork, null);
  6761. _primaryChildFragment3.return = workInProgress;
  6762. _primaryChildFragment3.child = _currentPrimaryChild;
  6763. if (_currentPrimaryChild !== null) {
  6764. _currentPrimaryChild.return = _primaryChildFragment3;
  6765. } // Even though we're creating a new fiber, there are no new children,
  6766. // because we're reusing an already mounted tree. So we don't need to
  6767. // schedule a placement.
  6768. // primaryChildFragment.effectTag |= Placement;
  6769. if ((workInProgress.mode & BlockingMode) === NoMode) {
  6770. // Outside of blocking mode, we commit the effects from the
  6771. // partially completed, timed-out tree, too.
  6772. var _progressedState2 = workInProgress.memoizedState;
  6773. var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
  6774. _primaryChildFragment3.child = _progressedPrimaryChild2;
  6775. var _progressedChild3 = _progressedPrimaryChild2;
  6776. while (_progressedChild3 !== null) {
  6777. _progressedChild3.return = _primaryChildFragment3;
  6778. _progressedChild3 = _progressedChild3.sibling;
  6779. }
  6780. } // Because primaryChildFragment is a new fiber that we're inserting as the
  6781. // parent of a new tree, we need to set its treeBaseDuration.
  6782. if ( workInProgress.mode & ProfileMode) {
  6783. // treeBaseDuration is the sum of all the child tree base durations.
  6784. var _treeBaseDuration2 = 0;
  6785. var _hiddenChild2 = _primaryChildFragment3.child;
  6786. while (_hiddenChild2 !== null) {
  6787. _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
  6788. _hiddenChild2 = _hiddenChild2.sibling;
  6789. }
  6790. _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
  6791. } // Create a fragment from the fallback children, too.
  6792. var _fallbackChildFragment3 = createFiberFromFragment(_nextFallbackChildren3, mode, renderExpirationTime, null);
  6793. _fallbackChildFragment3.return = workInProgress;
  6794. _primaryChildFragment3.sibling = _fallbackChildFragment3;
  6795. _fallbackChildFragment3.effectTag |= Placement;
  6796. _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  6797. // fallback children.
  6798. workInProgress.memoizedState = SUSPENDED_MARKER;
  6799. workInProgress.child = _primaryChildFragment3;
  6800. return _fallbackChildFragment3;
  6801. } else {
  6802. // Still haven't timed out. Continue rendering the children, like we
  6803. // normally do.
  6804. workInProgress.memoizedState = null;
  6805. var _nextPrimaryChildren2 = nextProps.children;
  6806. return workInProgress.child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
  6807. }
  6808. }
  6809. }
  6810. }
  6811. function scheduleWorkOnFiber(fiber, renderExpirationTime) {
  6812. if (fiber.expirationTime < renderExpirationTime) {
  6813. fiber.expirationTime = renderExpirationTime;
  6814. }
  6815. var alternate = fiber.alternate;
  6816. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  6817. alternate.expirationTime = renderExpirationTime;
  6818. }
  6819. scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
  6820. }
  6821. function propagateSuspenseContextChange(workInProgress, firstChild, renderExpirationTime) {
  6822. // Mark any Suspense boundaries with fallbacks as having work to do.
  6823. // If they were previously forced into fallbacks, they may now be able
  6824. // to unblock.
  6825. var node = firstChild;
  6826. while (node !== null) {
  6827. if (node.tag === SuspenseComponent) {
  6828. var state = node.memoizedState;
  6829. if (state !== null) {
  6830. scheduleWorkOnFiber(node, renderExpirationTime);
  6831. }
  6832. } else if (node.tag === SuspenseListComponent) {
  6833. // If the tail is hidden there might not be an Suspense boundaries
  6834. // to schedule work on. In this case we have to schedule it on the
  6835. // list itself.
  6836. // We don't have to traverse to the children of the list since
  6837. // the list will propagate the change when it rerenders.
  6838. scheduleWorkOnFiber(node, renderExpirationTime);
  6839. } else if (node.child !== null) {
  6840. node.child.return = node;
  6841. node = node.child;
  6842. continue;
  6843. }
  6844. if (node === workInProgress) {
  6845. return;
  6846. }
  6847. while (node.sibling === null) {
  6848. if (node.return === null || node.return === workInProgress) {
  6849. return;
  6850. }
  6851. node = node.return;
  6852. }
  6853. node.sibling.return = node.return;
  6854. node = node.sibling;
  6855. }
  6856. }
  6857. function findLastContentRow(firstChild) {
  6858. // This is going to find the last row among these children that is already
  6859. // showing content on the screen, as opposed to being in fallback state or
  6860. // new. If a row has multiple Suspense boundaries, any of them being in the
  6861. // fallback state, counts as the whole row being in a fallback state.
  6862. // Note that the "rows" will be workInProgress, but any nested children
  6863. // will still be current since we haven't rendered them yet. The mounted
  6864. // order may not be the same as the new order. We use the new order.
  6865. var row = firstChild;
  6866. var lastContentRow = null;
  6867. while (row !== null) {
  6868. var currentRow = row.alternate; // New rows can't be content rows.
  6869. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  6870. lastContentRow = row;
  6871. }
  6872. row = row.sibling;
  6873. }
  6874. return lastContentRow;
  6875. }
  6876. function validateRevealOrder(revealOrder) {
  6877. {
  6878. if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
  6879. didWarnAboutRevealOrder[revealOrder] = true;
  6880. if (typeof revealOrder === 'string') {
  6881. switch (revealOrder.toLowerCase()) {
  6882. case 'together':
  6883. case 'forwards':
  6884. case 'backwards':
  6885. {
  6886. error('"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
  6887. break;
  6888. }
  6889. case 'forward':
  6890. case 'backward':
  6891. {
  6892. 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());
  6893. break;
  6894. }
  6895. default:
  6896. error('"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  6897. break;
  6898. }
  6899. } else {
  6900. error('%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  6901. }
  6902. }
  6903. }
  6904. }
  6905. function validateTailOptions(tailMode, revealOrder) {
  6906. {
  6907. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  6908. if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
  6909. didWarnAboutTailOptions[tailMode] = true;
  6910. error('"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
  6911. } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
  6912. didWarnAboutTailOptions[tailMode] = true;
  6913. error('<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
  6914. }
  6915. }
  6916. }
  6917. }
  6918. function validateSuspenseListNestedChild(childSlot, index) {
  6919. {
  6920. var isArray = Array.isArray(childSlot);
  6921. var isIterable = !isArray && typeof getIteratorFn(childSlot) === 'function';
  6922. if (isArray || isIterable) {
  6923. var type = isArray ? 'array' : 'iterable';
  6924. 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);
  6925. return false;
  6926. }
  6927. }
  6928. return true;
  6929. }
  6930. function validateSuspenseListChildren(children, revealOrder) {
  6931. {
  6932. if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
  6933. if (Array.isArray(children)) {
  6934. for (var i = 0; i < children.length; i++) {
  6935. if (!validateSuspenseListNestedChild(children[i], i)) {
  6936. return;
  6937. }
  6938. }
  6939. } else {
  6940. var iteratorFn = getIteratorFn(children);
  6941. if (typeof iteratorFn === 'function') {
  6942. var childrenIterator = iteratorFn.call(children);
  6943. if (childrenIterator) {
  6944. var step = childrenIterator.next();
  6945. var _i = 0;
  6946. for (; !step.done; step = childrenIterator.next()) {
  6947. if (!validateSuspenseListNestedChild(step.value, _i)) {
  6948. return;
  6949. }
  6950. _i++;
  6951. }
  6952. }
  6953. } else {
  6954. 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);
  6955. }
  6956. }
  6957. }
  6958. }
  6959. }
  6960. function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode, lastEffectBeforeRendering) {
  6961. var renderState = workInProgress.memoizedState;
  6962. if (renderState === null) {
  6963. workInProgress.memoizedState = {
  6964. isBackwards: isBackwards,
  6965. rendering: null,
  6966. renderingStartTime: 0,
  6967. last: lastContentRow,
  6968. tail: tail,
  6969. tailExpiration: 0,
  6970. tailMode: tailMode,
  6971. lastEffect: lastEffectBeforeRendering
  6972. };
  6973. } else {
  6974. // We can reuse the existing object from previous renders.
  6975. renderState.isBackwards = isBackwards;
  6976. renderState.rendering = null;
  6977. renderState.renderingStartTime = 0;
  6978. renderState.last = lastContentRow;
  6979. renderState.tail = tail;
  6980. renderState.tailExpiration = 0;
  6981. renderState.tailMode = tailMode;
  6982. renderState.lastEffect = lastEffectBeforeRendering;
  6983. }
  6984. } // This can end up rendering this component multiple passes.
  6985. // The first pass splits the children fibers into two sets. A head and tail.
  6986. // We first render the head. If anything is in fallback state, we do another
  6987. // pass through beginWork to rerender all children (including the tail) with
  6988. // the force suspend context. If the first render didn't have anything in
  6989. // in fallback state. Then we render each row in the tail one-by-one.
  6990. // That happens in the completeWork phase without going back to beginWork.
  6991. function updateSuspenseListComponent(current, workInProgress, renderExpirationTime) {
  6992. var nextProps = workInProgress.pendingProps;
  6993. var revealOrder = nextProps.revealOrder;
  6994. var tailMode = nextProps.tail;
  6995. var newChildren = nextProps.children;
  6996. validateRevealOrder(revealOrder);
  6997. validateTailOptions(tailMode, revealOrder);
  6998. validateSuspenseListChildren(newChildren, revealOrder);
  6999. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  7000. var suspenseContext = suspenseStackCursor.current;
  7001. var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
  7002. if (shouldForceFallback) {
  7003. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  7004. workInProgress.effectTag |= DidCapture;
  7005. } else {
  7006. var didSuspendBefore = current !== null && (current.effectTag & DidCapture) !== NoEffect;
  7007. if (didSuspendBefore) {
  7008. // If we previously forced a fallback, we need to schedule work
  7009. // on any nested boundaries to let them know to try to render
  7010. // again. This is the same as context updating.
  7011. propagateSuspenseContextChange(workInProgress, workInProgress.child, renderExpirationTime);
  7012. }
  7013. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  7014. }
  7015. pushSuspenseContext(workInProgress, suspenseContext);
  7016. if ((workInProgress.mode & BlockingMode) === NoMode) {
  7017. // Outside of blocking mode, SuspenseList doesn't work so we just
  7018. // use make it a noop by treating it as the default revealOrder.
  7019. workInProgress.memoizedState = null;
  7020. } else {
  7021. switch (revealOrder) {
  7022. case 'forwards':
  7023. {
  7024. var lastContentRow = findLastContentRow(workInProgress.child);
  7025. var tail;
  7026. if (lastContentRow === null) {
  7027. // The whole list is part of the tail.
  7028. // TODO: We could fast path by just rendering the tail now.
  7029. tail = workInProgress.child;
  7030. workInProgress.child = null;
  7031. } else {
  7032. // Disconnect the tail rows after the content row.
  7033. // We're going to render them separately later.
  7034. tail = lastContentRow.sibling;
  7035. lastContentRow.sibling = null;
  7036. }
  7037. initSuspenseListRenderState(workInProgress, false, // isBackwards
  7038. tail, lastContentRow, tailMode, workInProgress.lastEffect);
  7039. break;
  7040. }
  7041. case 'backwards':
  7042. {
  7043. // We're going to find the first row that has existing content.
  7044. // At the same time we're going to reverse the list of everything
  7045. // we pass in the meantime. That's going to be our tail in reverse
  7046. // order.
  7047. var _tail = null;
  7048. var row = workInProgress.child;
  7049. workInProgress.child = null;
  7050. while (row !== null) {
  7051. var currentRow = row.alternate; // New rows can't be content rows.
  7052. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  7053. // This is the beginning of the main content.
  7054. workInProgress.child = row;
  7055. break;
  7056. }
  7057. var nextRow = row.sibling;
  7058. row.sibling = _tail;
  7059. _tail = row;
  7060. row = nextRow;
  7061. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  7062. initSuspenseListRenderState(workInProgress, true, // isBackwards
  7063. _tail, null, // last
  7064. tailMode, workInProgress.lastEffect);
  7065. break;
  7066. }
  7067. case 'together':
  7068. {
  7069. initSuspenseListRenderState(workInProgress, false, // isBackwards
  7070. null, // tail
  7071. null, // last
  7072. undefined, workInProgress.lastEffect);
  7073. break;
  7074. }
  7075. default:
  7076. {
  7077. // The default reveal order is the same as not having
  7078. // a boundary.
  7079. workInProgress.memoizedState = null;
  7080. }
  7081. }
  7082. }
  7083. return workInProgress.child;
  7084. }
  7085. function updatePortalComponent(current, workInProgress, renderExpirationTime) {
  7086. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  7087. var nextChildren = workInProgress.pendingProps;
  7088. if (current === null) {
  7089. // Portals are special because we don't append the children during mount
  7090. // but at commit. Therefore we need to track insertions which the normal
  7091. // flow doesn't do during mount. This doesn't happen at the root because
  7092. // the root always starts with a "current" with a null child.
  7093. // TODO: Consider unifying this with how the root works.
  7094. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
  7095. } else {
  7096. reconcileChildren(current, workInProgress, nextChildren, renderExpirationTime);
  7097. }
  7098. return workInProgress.child;
  7099. }
  7100. function updateContextProvider(current, workInProgress, renderExpirationTime) {
  7101. var providerType = workInProgress.type;
  7102. var context = providerType._context;
  7103. var newProps = workInProgress.pendingProps;
  7104. var oldProps = workInProgress.memoizedProps;
  7105. var newValue = newProps.value;
  7106. {
  7107. var providerPropTypes = workInProgress.type.propTypes;
  7108. if (providerPropTypes) {
  7109. checkPropTypes(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
  7110. }
  7111. }
  7112. pushProvider(workInProgress, newValue);
  7113. if (oldProps !== null) {
  7114. var oldValue = oldProps.value;
  7115. var changedBits = calculateChangedBits(context, newValue, oldValue);
  7116. if (changedBits === 0) {
  7117. // No change. Bailout early if children are the same.
  7118. if (oldProps.children === newProps.children && !hasContextChanged()) {
  7119. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  7120. }
  7121. } else {
  7122. // The context value changed. Search for matching consumers and schedule
  7123. // them to update.
  7124. propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
  7125. }
  7126. }
  7127. var newChildren = newProps.children;
  7128. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  7129. return workInProgress.child;
  7130. }
  7131. var hasWarnedAboutUsingContextAsConsumer = false;
  7132. function updateContextConsumer(current, workInProgress, renderExpirationTime) {
  7133. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  7134. // DEV mode, we create a separate object for Context.Consumer that acts
  7135. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  7136. // so we use the old behaviour (Context.Consumer references Context) to
  7137. // reduce size and overhead. The separate object references context via
  7138. // a property called "_context", which also gives us the ability to check
  7139. // in DEV mode if this property exists or not and warn if it does not.
  7140. {
  7141. if (context._context === undefined) {
  7142. // This may be because it's a Context (rather than a Consumer).
  7143. // Or it may be because it's older React where they're the same thing.
  7144. // We only want to warn if we're sure it's a new React.
  7145. if (context !== context.Consumer) {
  7146. if (!hasWarnedAboutUsingContextAsConsumer) {
  7147. hasWarnedAboutUsingContextAsConsumer = true;
  7148. error('Rendering <Context> directly is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
  7149. }
  7150. }
  7151. } else {
  7152. context = context._context;
  7153. }
  7154. }
  7155. var newProps = workInProgress.pendingProps;
  7156. var render = newProps.children;
  7157. {
  7158. if (typeof render !== 'function') {
  7159. 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.');
  7160. }
  7161. }
  7162. prepareToReadContext(workInProgress, renderExpirationTime);
  7163. var newValue = readContext(context, newProps.unstable_observedBits);
  7164. var newChildren;
  7165. {
  7166. ReactCurrentOwner$1.current = workInProgress;
  7167. setIsRendering(true);
  7168. newChildren = render(newValue);
  7169. setIsRendering(false);
  7170. } // React DevTools reads this flag.
  7171. workInProgress.effectTag |= PerformedWork;
  7172. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  7173. return workInProgress.child;
  7174. }
  7175. function markWorkInProgressReceivedUpdate() {
  7176. didReceiveUpdate = true;
  7177. }
  7178. function bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime) {
  7179. cancelWorkTimer(workInProgress);
  7180. if (current !== null) {
  7181. // Reuse previous dependencies
  7182. workInProgress.dependencies = current.dependencies;
  7183. }
  7184. {
  7185. // Don't update "base" render times for bailouts.
  7186. stopProfilerTimerIfRunning();
  7187. }
  7188. var updateExpirationTime = workInProgress.expirationTime;
  7189. if (updateExpirationTime !== NoWork) {
  7190. markUnprocessedUpdateTime(updateExpirationTime);
  7191. } // Check if the children have any pending work.
  7192. var childExpirationTime = workInProgress.childExpirationTime;
  7193. if (childExpirationTime < renderExpirationTime) {
  7194. // The children don't have any work either. We can skip them.
  7195. // TODO: Once we add back resuming, we should check if the children are
  7196. // a work-in-progress set. If so, we need to transfer their effects.
  7197. return null;
  7198. } else {
  7199. // This fiber doesn't have work, but its subtree does. Clone the child
  7200. // fibers and continue.
  7201. cloneChildFibers(current, workInProgress);
  7202. return workInProgress.child;
  7203. }
  7204. }
  7205. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  7206. {
  7207. var returnFiber = oldWorkInProgress.return;
  7208. if (returnFiber === null) {
  7209. throw new Error('Cannot swap the root fiber.');
  7210. } // Disconnect from the old current.
  7211. // It will get deleted.
  7212. current.alternate = null;
  7213. oldWorkInProgress.alternate = null; // Connect to the new tree.
  7214. newWorkInProgress.index = oldWorkInProgress.index;
  7215. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  7216. newWorkInProgress.return = oldWorkInProgress.return;
  7217. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  7218. if (oldWorkInProgress === returnFiber.child) {
  7219. returnFiber.child = newWorkInProgress;
  7220. } else {
  7221. var prevSibling = returnFiber.child;
  7222. if (prevSibling === null) {
  7223. throw new Error('Expected parent to have a child.');
  7224. }
  7225. while (prevSibling.sibling !== oldWorkInProgress) {
  7226. prevSibling = prevSibling.sibling;
  7227. if (prevSibling === null) {
  7228. throw new Error('Expected to find the previous sibling.');
  7229. }
  7230. }
  7231. prevSibling.sibling = newWorkInProgress;
  7232. } // Delete the old fiber and place the new one.
  7233. // Since the old fiber is disconnected, we have to schedule it manually.
  7234. var last = returnFiber.lastEffect;
  7235. if (last !== null) {
  7236. last.nextEffect = current;
  7237. returnFiber.lastEffect = current;
  7238. } else {
  7239. returnFiber.firstEffect = returnFiber.lastEffect = current;
  7240. }
  7241. current.nextEffect = null;
  7242. current.effectTag = Deletion;
  7243. newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
  7244. return newWorkInProgress;
  7245. }
  7246. }
  7247. function beginWork(current, workInProgress, renderExpirationTime) {
  7248. var updateExpirationTime = workInProgress.expirationTime;
  7249. {
  7250. if (workInProgress._debugNeedsRemount && current !== null) {
  7251. // This will restart the begin phase with a new fiber.
  7252. return remountFiber(current, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.expirationTime));
  7253. }
  7254. }
  7255. if (current !== null) {
  7256. var oldProps = current.memoizedProps;
  7257. var newProps = workInProgress.pendingProps;
  7258. if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
  7259. workInProgress.type !== current.type )) {
  7260. // If props or context changed, mark the fiber as having performed work.
  7261. // This may be unset if the props are determined to be equal later (memo).
  7262. didReceiveUpdate = true;
  7263. } else if (updateExpirationTime < renderExpirationTime) {
  7264. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  7265. // the begin phase. There's still some bookkeeping we that needs to be done
  7266. // in this optimized path, mostly pushing stuff onto the stack.
  7267. switch (workInProgress.tag) {
  7268. case HostRoot:
  7269. pushHostRootContext(workInProgress);
  7270. break;
  7271. case HostComponent:
  7272. pushHostContext(workInProgress);
  7273. if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(workInProgress.type)) {
  7274. {
  7275. markSpawnedWork(Never);
  7276. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  7277. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  7278. return null;
  7279. }
  7280. break;
  7281. case ClassComponent:
  7282. {
  7283. var Component = workInProgress.type;
  7284. if (isContextProvider(Component)) {
  7285. pushContextProvider(workInProgress);
  7286. }
  7287. break;
  7288. }
  7289. case HostPortal:
  7290. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  7291. break;
  7292. case ContextProvider:
  7293. {
  7294. var newValue = workInProgress.memoizedProps.value;
  7295. pushProvider(workInProgress, newValue);
  7296. break;
  7297. }
  7298. case Profiler:
  7299. {
  7300. // Profiler should only call onRender when one of its descendants actually rendered.
  7301. var hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
  7302. if (hasChildWork) {
  7303. workInProgress.effectTag |= Update;
  7304. }
  7305. }
  7306. break;
  7307. case SuspenseComponent:
  7308. {
  7309. var state = workInProgress.memoizedState;
  7310. if (state !== null) {
  7311. // whether to retry the primary children, or to skip over it and
  7312. // go straight to the fallback. Check the priority of the primary
  7313. // child fragment.
  7314. var primaryChildFragment = workInProgress.child;
  7315. var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
  7316. if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
  7317. // The primary children have pending work. Use the normal path
  7318. // to attempt to render the primary children again.
  7319. return updateSuspenseComponent(current, workInProgress, renderExpirationTime);
  7320. } else {
  7321. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
  7322. // priority. Bailout.
  7323. var child = bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  7324. if (child !== null) {
  7325. // The fallback children have pending work. Skip over the
  7326. // primary children and work on the fallback.
  7327. return child.sibling;
  7328. } else {
  7329. return null;
  7330. }
  7331. }
  7332. } else {
  7333. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
  7334. }
  7335. break;
  7336. }
  7337. case SuspenseListComponent:
  7338. {
  7339. var didSuspendBefore = (current.effectTag & DidCapture) !== NoEffect;
  7340. var _hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
  7341. if (didSuspendBefore) {
  7342. if (_hasChildWork) {
  7343. // If something was in fallback state last time, and we have all the
  7344. // same children then we're still in progressive loading state.
  7345. // Something might get unblocked by state updates or retries in the
  7346. // tree which will affect the tail. So we need to use the normal
  7347. // path to compute the correct tail.
  7348. return updateSuspenseListComponent(current, workInProgress, renderExpirationTime);
  7349. } // If none of the children had any work, that means that none of
  7350. // them got retried so they'll still be blocked in the same way
  7351. // as before. We can fast bail out.
  7352. workInProgress.effectTag |= DidCapture;
  7353. } // If nothing suspended before and we're rendering the same children,
  7354. // then the tail doesn't matter. Anything new that suspends will work
  7355. // in the "together" mode, so we can continue from the state we had.
  7356. var renderState = workInProgress.memoizedState;
  7357. if (renderState !== null) {
  7358. // Reset to the "together" mode in case we've started a different
  7359. // update in the past but didn't complete it.
  7360. renderState.rendering = null;
  7361. renderState.tail = null;
  7362. }
  7363. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  7364. if (_hasChildWork) {
  7365. break;
  7366. } else {
  7367. // If none of the children had any work, that means that none of
  7368. // them got retried so they'll still be blocked in the same way
  7369. // as before. We can fast bail out.
  7370. return null;
  7371. }
  7372. }
  7373. }
  7374. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderExpirationTime);
  7375. } else {
  7376. // An update was scheduled on this fiber, but there are no new props
  7377. // nor legacy context. Set this to false. If an update queue or context
  7378. // consumer produces a changed value, it will set this to true. Otherwise,
  7379. // the component will assume the children have not changed and bail out.
  7380. didReceiveUpdate = false;
  7381. }
  7382. } else {
  7383. didReceiveUpdate = false;
  7384. } // Before entering the begin phase, clear pending update priority.
  7385. // TODO: This assumes that we're about to evaluate the component and process
  7386. // the update queue. However, there's an exception: SimpleMemoComponent
  7387. // sometimes bails out later in the begin phase. This indicates that we should
  7388. // move this assignment out of the common path and into each branch.
  7389. workInProgress.expirationTime = NoWork;
  7390. switch (workInProgress.tag) {
  7391. case IndeterminateComponent:
  7392. {
  7393. return mountIndeterminateComponent(current, workInProgress, workInProgress.type, renderExpirationTime);
  7394. }
  7395. case LazyComponent:
  7396. {
  7397. var elementType = workInProgress.elementType;
  7398. return mountLazyComponent(current, workInProgress, elementType, updateExpirationTime, renderExpirationTime);
  7399. }
  7400. case FunctionComponent:
  7401. {
  7402. var _Component = workInProgress.type;
  7403. var unresolvedProps = workInProgress.pendingProps;
  7404. var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
  7405. return updateFunctionComponent(current, workInProgress, _Component, resolvedProps, renderExpirationTime);
  7406. }
  7407. case ClassComponent:
  7408. {
  7409. var _Component2 = workInProgress.type;
  7410. var _unresolvedProps = workInProgress.pendingProps;
  7411. var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
  7412. return updateClassComponent(current, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
  7413. }
  7414. case HostRoot:
  7415. return updateHostRoot(current, workInProgress, renderExpirationTime);
  7416. case HostComponent:
  7417. return updateHostComponent(current, workInProgress, renderExpirationTime);
  7418. case HostText:
  7419. return updateHostText();
  7420. case SuspenseComponent:
  7421. return updateSuspenseComponent(current, workInProgress, renderExpirationTime);
  7422. case HostPortal:
  7423. return updatePortalComponent(current, workInProgress, renderExpirationTime);
  7424. case ForwardRef:
  7425. {
  7426. var type = workInProgress.type;
  7427. var _unresolvedProps2 = workInProgress.pendingProps;
  7428. var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
  7429. return updateForwardRef(current, workInProgress, type, _resolvedProps2, renderExpirationTime);
  7430. }
  7431. case Fragment:
  7432. return updateFragment(current, workInProgress, renderExpirationTime);
  7433. case Mode:
  7434. return updateMode(current, workInProgress, renderExpirationTime);
  7435. case Profiler:
  7436. return updateProfiler(current, workInProgress, renderExpirationTime);
  7437. case ContextProvider:
  7438. return updateContextProvider(current, workInProgress, renderExpirationTime);
  7439. case ContextConsumer:
  7440. return updateContextConsumer(current, workInProgress, renderExpirationTime);
  7441. case MemoComponent:
  7442. {
  7443. var _type2 = workInProgress.type;
  7444. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  7445. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  7446. {
  7447. if (workInProgress.type !== workInProgress.elementType) {
  7448. var outerPropTypes = _type2.propTypes;
  7449. if (outerPropTypes) {
  7450. checkPropTypes(outerPropTypes, _resolvedProps3, // Resolved for outer only
  7451. 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
  7452. }
  7453. }
  7454. }
  7455. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  7456. return updateMemoComponent(current, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
  7457. }
  7458. case SimpleMemoComponent:
  7459. {
  7460. return updateSimpleMemoComponent(current, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
  7461. }
  7462. case IncompleteClassComponent:
  7463. {
  7464. var _Component3 = workInProgress.type;
  7465. var _unresolvedProps4 = workInProgress.pendingProps;
  7466. var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
  7467. return mountIncompleteClassComponent(current, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
  7468. }
  7469. case SuspenseListComponent:
  7470. {
  7471. return updateSuspenseListComponent(current, workInProgress, renderExpirationTime);
  7472. }
  7473. }
  7474. {
  7475. {
  7476. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  7477. }
  7478. }
  7479. }
  7480. function markUpdate(workInProgress) {
  7481. // Tag the fiber with an update effect. This turns a Placement into
  7482. // a PlacementAndUpdate.
  7483. workInProgress.effectTag |= Update;
  7484. }
  7485. function markRef$1(workInProgress) {
  7486. workInProgress.effectTag |= Ref;
  7487. }
  7488. var appendAllChildren;
  7489. var updateHostContainer;
  7490. var updateHostComponent$1;
  7491. var updateHostText$1;
  7492. {
  7493. // Mutation mode
  7494. appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
  7495. // We only have the top Fiber that was created but we need recurse down its
  7496. // children to find all the terminal nodes.
  7497. var node = workInProgress.child;
  7498. while (node !== null) {
  7499. if (node.tag === HostComponent || node.tag === HostText) {
  7500. appendInitialChild(parent, node.stateNode);
  7501. } else if (node.tag === HostPortal) ; else if (node.child !== null) {
  7502. node.child.return = node;
  7503. node = node.child;
  7504. continue;
  7505. }
  7506. if (node === workInProgress) {
  7507. return;
  7508. }
  7509. while (node.sibling === null) {
  7510. if (node.return === null || node.return === workInProgress) {
  7511. return;
  7512. }
  7513. node = node.return;
  7514. }
  7515. node.sibling.return = node.return;
  7516. node = node.sibling;
  7517. }
  7518. };
  7519. updateHostContainer = function (workInProgress) {// Noop
  7520. };
  7521. updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
  7522. // If we have an alternate, that means this is an update and we need to
  7523. // schedule a side-effect to do the updates.
  7524. var oldProps = current.memoizedProps;
  7525. if (oldProps === newProps) {
  7526. // In mutation mode, this is sufficient for a bailout because
  7527. // we won't touch this node even if children changed.
  7528. return;
  7529. } // If we get updated because one of our children updated, we don't
  7530. // have newProps so we'll have to reuse them.
  7531. // TODO: Split the update API as separate for the props vs. children.
  7532. // Even better would be if children weren't special cased at all tho.
  7533. var instance = workInProgress.stateNode;
  7534. var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
  7535. // component is hitting the resume path. Figure out why. Possibly
  7536. // related to `hidden`.
  7537. var updatePayload = prepareUpdate(); // TODO: Type this specific to this type of component.
  7538. workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  7539. // is a new ref we mark this as an update. All the work is done in commitWork.
  7540. if (updatePayload) {
  7541. markUpdate(workInProgress);
  7542. }
  7543. };
  7544. updateHostText$1 = function (current, workInProgress, oldText, newText) {
  7545. // If the text differs, mark it as an update. All the work in done in commitWork.
  7546. if (oldText !== newText) {
  7547. markUpdate(workInProgress);
  7548. }
  7549. };
  7550. }
  7551. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  7552. switch (renderState.tailMode) {
  7553. case 'hidden':
  7554. {
  7555. // Any insertions at the end of the tail list after this point
  7556. // should be invisible. If there are already mounted boundaries
  7557. // anything before them are not considered for collapsing.
  7558. // Therefore we need to go through the whole tail to find if
  7559. // there are any.
  7560. var tailNode = renderState.tail;
  7561. var lastTailNode = null;
  7562. while (tailNode !== null) {
  7563. if (tailNode.alternate !== null) {
  7564. lastTailNode = tailNode;
  7565. }
  7566. tailNode = tailNode.sibling;
  7567. } // Next we're simply going to delete all insertions after the
  7568. // last rendered item.
  7569. if (lastTailNode === null) {
  7570. // All remaining items in the tail are insertions.
  7571. renderState.tail = null;
  7572. } else {
  7573. // Detach the insertion after the last node that was already
  7574. // inserted.
  7575. lastTailNode.sibling = null;
  7576. }
  7577. break;
  7578. }
  7579. case 'collapsed':
  7580. {
  7581. // Any insertions at the end of the tail list after this point
  7582. // should be invisible. If there are already mounted boundaries
  7583. // anything before them are not considered for collapsing.
  7584. // Therefore we need to go through the whole tail to find if
  7585. // there are any.
  7586. var _tailNode = renderState.tail;
  7587. var _lastTailNode = null;
  7588. while (_tailNode !== null) {
  7589. if (_tailNode.alternate !== null) {
  7590. _lastTailNode = _tailNode;
  7591. }
  7592. _tailNode = _tailNode.sibling;
  7593. } // Next we're simply going to delete all insertions after the
  7594. // last rendered item.
  7595. if (_lastTailNode === null) {
  7596. // All remaining items in the tail are insertions.
  7597. if (!hasRenderedATailFallback && renderState.tail !== null) {
  7598. // We suspended during the head. We want to show at least one
  7599. // row at the tail. So we'll keep on and cut off the rest.
  7600. renderState.tail.sibling = null;
  7601. } else {
  7602. renderState.tail = null;
  7603. }
  7604. } else {
  7605. // Detach the insertion after the last node that was already
  7606. // inserted.
  7607. _lastTailNode.sibling = null;
  7608. }
  7609. break;
  7610. }
  7611. }
  7612. }
  7613. function completeWork(current, workInProgress, renderExpirationTime) {
  7614. var newProps = workInProgress.pendingProps;
  7615. switch (workInProgress.tag) {
  7616. case IndeterminateComponent:
  7617. case LazyComponent:
  7618. case SimpleMemoComponent:
  7619. case FunctionComponent:
  7620. case ForwardRef:
  7621. case Fragment:
  7622. case Mode:
  7623. case Profiler:
  7624. case ContextConsumer:
  7625. case MemoComponent:
  7626. return null;
  7627. case ClassComponent:
  7628. {
  7629. var Component = workInProgress.type;
  7630. if (isContextProvider(Component)) {
  7631. popContext(workInProgress);
  7632. }
  7633. return null;
  7634. }
  7635. case HostRoot:
  7636. {
  7637. popHostContainer(workInProgress);
  7638. popTopLevelContextObject(workInProgress);
  7639. var fiberRoot = workInProgress.stateNode;
  7640. if (fiberRoot.pendingContext) {
  7641. fiberRoot.context = fiberRoot.pendingContext;
  7642. fiberRoot.pendingContext = null;
  7643. }
  7644. if (current === null || current.child === null) {
  7645. // If we hydrated, pop so that we can delete any remaining children
  7646. // that weren't hydrated.
  7647. var wasHydrated = popHydrationState();
  7648. if (wasHydrated) {
  7649. // If we hydrated, then we'll need to schedule an update for
  7650. // the commit side-effects on the root.
  7651. markUpdate(workInProgress);
  7652. }
  7653. }
  7654. updateHostContainer(workInProgress);
  7655. return null;
  7656. }
  7657. case HostComponent:
  7658. {
  7659. popHostContext(workInProgress);
  7660. var rootContainerInstance = getRootHostContainer();
  7661. var type = workInProgress.type;
  7662. if (current !== null && workInProgress.stateNode != null) {
  7663. updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
  7664. if (current.ref !== workInProgress.ref) {
  7665. markRef$1(workInProgress);
  7666. }
  7667. } else {
  7668. if (!newProps) {
  7669. if (!(workInProgress.stateNode !== null)) {
  7670. {
  7671. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  7672. }
  7673. } // This can happen when we abort work.
  7674. return null;
  7675. }
  7676. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  7677. // "stack" as the parent. Then append children as we go in beginWork
  7678. // or completeWork depending on whether we want to add them top->down or
  7679. // bottom->up. Top->down is faster in IE11.
  7680. var _wasHydrated = popHydrationState();
  7681. if (_wasHydrated) {
  7682. // TODO: Move this and createInstance step into the beginPhase
  7683. // to consolidate.
  7684. if (prepareToHydrateHostInstance()) {
  7685. // If changes to the hydrated node need to be applied at the
  7686. // commit-phase we mark this as such.
  7687. markUpdate(workInProgress);
  7688. }
  7689. } else {
  7690. var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
  7691. appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
  7692. workInProgress.stateNode = instance;
  7693. }
  7694. if (workInProgress.ref !== null) {
  7695. // If there is a ref on a host node we need to schedule a callback
  7696. markRef$1(workInProgress);
  7697. }
  7698. }
  7699. return null;
  7700. }
  7701. case HostText:
  7702. {
  7703. var newText = newProps;
  7704. if (current && workInProgress.stateNode != null) {
  7705. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  7706. // to schedule a side-effect to do the updates.
  7707. updateHostText$1(current, workInProgress, oldText, newText);
  7708. } else {
  7709. if (typeof newText !== 'string') {
  7710. if (!(workInProgress.stateNode !== null)) {
  7711. {
  7712. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  7713. }
  7714. } // This can happen when we abort work.
  7715. }
  7716. var _rootContainerInstance = getRootHostContainer();
  7717. var _currentHostContext = getHostContext();
  7718. var _wasHydrated2 = popHydrationState();
  7719. if (_wasHydrated2) {
  7720. if (prepareToHydrateHostTextInstance()) {
  7721. markUpdate(workInProgress);
  7722. }
  7723. } else {
  7724. workInProgress.stateNode = createTextInstance(newText);
  7725. }
  7726. }
  7727. return null;
  7728. }
  7729. case SuspenseComponent:
  7730. {
  7731. popSuspenseContext(workInProgress);
  7732. var nextState = workInProgress.memoizedState;
  7733. if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
  7734. // Something suspended. Re-render with the fallback children.
  7735. workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
  7736. return workInProgress;
  7737. }
  7738. var nextDidTimeout = nextState !== null;
  7739. var prevDidTimeout = false;
  7740. if (current === null) {
  7741. if (workInProgress.memoizedProps.fallback !== undefined) ;
  7742. } else {
  7743. var prevState = current.memoizedState;
  7744. prevDidTimeout = prevState !== null;
  7745. if (!nextDidTimeout && prevState !== null) {
  7746. // We just switched from the fallback to the normal children.
  7747. // Delete the fallback.
  7748. // TODO: Would it be better to store the fallback fragment on
  7749. // the stateNode during the begin phase?
  7750. var currentFallbackChild = current.child.sibling;
  7751. if (currentFallbackChild !== null) {
  7752. // Deletions go at the beginning of the return fiber's effect list
  7753. var first = workInProgress.firstEffect;
  7754. if (first !== null) {
  7755. workInProgress.firstEffect = currentFallbackChild;
  7756. currentFallbackChild.nextEffect = first;
  7757. } else {
  7758. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
  7759. currentFallbackChild.nextEffect = null;
  7760. }
  7761. currentFallbackChild.effectTag = Deletion;
  7762. }
  7763. }
  7764. }
  7765. if (nextDidTimeout && !prevDidTimeout) {
  7766. // If this subtreee is running in blocking mode we can suspend,
  7767. // otherwise we won't suspend.
  7768. // TODO: This will still suspend a synchronous tree if anything
  7769. // in the concurrent tree already suspended during this render.
  7770. // This is a known bug.
  7771. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  7772. // TODO: Move this back to throwException because this is too late
  7773. // if this is a large tree which is common for initial loads. We
  7774. // don't know if we should restart a render or not until we get
  7775. // this marker, and this is too late.
  7776. // If this render already had a ping or lower pri updates,
  7777. // and this is the first time we know we're going to suspend we
  7778. // should be able to immediately restart from within throwException.
  7779. var hasInvisibleChildContext = current === null && workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  7780. if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
  7781. // If this was in an invisible tree or a new render, then showing
  7782. // this boundary is ok.
  7783. renderDidSuspend();
  7784. } else {
  7785. // Otherwise, we're going to have to hide content so we should
  7786. // suspend for longer if possible.
  7787. renderDidSuspendDelayIfPossible();
  7788. }
  7789. }
  7790. }
  7791. {
  7792. // TODO: Only schedule updates if these values are non equal, i.e. it changed.
  7793. if (nextDidTimeout || prevDidTimeout) {
  7794. // If this boundary just timed out, schedule an effect to attach a
  7795. // retry listener to the promise. This flag is also used to hide the
  7796. // primary children. In mutation mode, we also need the flag to
  7797. // *unhide* children that were previously hidden, so check if this
  7798. // is currently timed out, too.
  7799. workInProgress.effectTag |= Update;
  7800. }
  7801. }
  7802. return null;
  7803. }
  7804. case HostPortal:
  7805. popHostContainer(workInProgress);
  7806. updateHostContainer(workInProgress);
  7807. return null;
  7808. case ContextProvider:
  7809. // Pop provider fiber
  7810. popProvider(workInProgress);
  7811. return null;
  7812. case IncompleteClassComponent:
  7813. {
  7814. // Same as class component case. I put it down here so that the tags are
  7815. // sequential to ensure this switch is compiled to a jump table.
  7816. var _Component = workInProgress.type;
  7817. if (isContextProvider(_Component)) {
  7818. popContext(workInProgress);
  7819. }
  7820. return null;
  7821. }
  7822. case SuspenseListComponent:
  7823. {
  7824. popSuspenseContext(workInProgress);
  7825. var renderState = workInProgress.memoizedState;
  7826. if (renderState === null) {
  7827. // We're running in the default, "independent" mode.
  7828. // We don't do anything in this mode.
  7829. return null;
  7830. }
  7831. var didSuspendAlready = (workInProgress.effectTag & DidCapture) !== NoEffect;
  7832. var renderedTail = renderState.rendering;
  7833. if (renderedTail === null) {
  7834. // We just rendered the head.
  7835. if (!didSuspendAlready) {
  7836. // This is the first pass. We need to figure out if anything is still
  7837. // suspended in the rendered set.
  7838. // If new content unsuspended, but there's still some content that
  7839. // didn't. Then we need to do a second pass that forces everything
  7840. // to keep showing their fallbacks.
  7841. // We might be suspended if something in this render pass suspended, or
  7842. // something in the previous committed pass suspended. Otherwise,
  7843. // there's no chance so we can skip the expensive call to
  7844. // findFirstSuspended.
  7845. var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.effectTag & DidCapture) === NoEffect);
  7846. if (!cannotBeSuspended) {
  7847. var row = workInProgress.child;
  7848. while (row !== null) {
  7849. var suspended = findFirstSuspended(row);
  7850. if (suspended !== null) {
  7851. didSuspendAlready = true;
  7852. workInProgress.effectTag |= DidCapture;
  7853. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  7854. // part of the second pass. In that case nothing will subscribe to
  7855. // its thennables. Instead, we'll transfer its thennables to the
  7856. // SuspenseList so that it can retry if they resolve.
  7857. // There might be multiple of these in the list but since we're
  7858. // going to wait for all of them anyway, it doesn't really matter
  7859. // which ones gets to ping. In theory we could get clever and keep
  7860. // track of how many dependencies remain but it gets tricky because
  7861. // in the meantime, we can add/remove/change items and dependencies.
  7862. // We might bail out of the loop before finding any but that
  7863. // doesn't matter since that means that the other boundaries that
  7864. // we did find already has their listeners attached.
  7865. var newThennables = suspended.updateQueue;
  7866. if (newThennables !== null) {
  7867. workInProgress.updateQueue = newThennables;
  7868. workInProgress.effectTag |= Update;
  7869. } // Rerender the whole list, but this time, we'll force fallbacks
  7870. // to stay in place.
  7871. // Reset the effect list before doing the second pass since that's now invalid.
  7872. if (renderState.lastEffect === null) {
  7873. workInProgress.firstEffect = null;
  7874. }
  7875. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  7876. resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
  7877. // rerender the children.
  7878. pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback));
  7879. return workInProgress.child;
  7880. }
  7881. row = row.sibling;
  7882. }
  7883. }
  7884. } else {
  7885. cutOffTailIfNeeded(renderState, false);
  7886. } // Next we're going to render the tail.
  7887. } else {
  7888. // Append the rendered row to the child list.
  7889. if (!didSuspendAlready) {
  7890. var _suspended = findFirstSuspended(renderedTail);
  7891. if (_suspended !== null) {
  7892. workInProgress.effectTag |= DidCapture;
  7893. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  7894. // get lost if this row ends up dropped during a second pass.
  7895. var _newThennables = _suspended.updateQueue;
  7896. if (_newThennables !== null) {
  7897. workInProgress.updateQueue = _newThennables;
  7898. workInProgress.effectTag |= Update;
  7899. }
  7900. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  7901. if (renderState.tail === null && renderState.tailMode === 'hidden' && !renderedTail.alternate) {
  7902. // We need to delete the row we just rendered.
  7903. // Reset the effect list to what it was before we rendered this
  7904. // child. The nested children have already appended themselves.
  7905. var lastEffect = workInProgress.lastEffect = renderState.lastEffect; // Remove any effects that were appended after this point.
  7906. if (lastEffect !== null) {
  7907. lastEffect.nextEffect = null;
  7908. } // We're done.
  7909. return null;
  7910. }
  7911. } else if ( // The time it took to render last row is greater than time until
  7912. // the expiration.
  7913. now() * 2 - renderState.renderingStartTime > renderState.tailExpiration && renderExpirationTime > Never) {
  7914. // We have now passed our CPU deadline and we'll just give up further
  7915. // attempts to render the main content and only render fallbacks.
  7916. // The assumption is that this is usually faster.
  7917. workInProgress.effectTag |= DidCapture;
  7918. didSuspendAlready = true;
  7919. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  7920. // to get it started back up to attempt the next item. If we can show
  7921. // them, then they really have the same priority as this render.
  7922. // So we'll pick it back up the very next render pass once we've had
  7923. // an opportunity to yield for paint.
  7924. var nextPriority = renderExpirationTime - 1;
  7925. workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
  7926. {
  7927. markSpawnedWork(nextPriority);
  7928. }
  7929. }
  7930. }
  7931. if (renderState.isBackwards) {
  7932. // The effect list of the backwards tail will have been added
  7933. // to the end. This breaks the guarantee that life-cycles fire in
  7934. // sibling order but that isn't a strong guarantee promised by React.
  7935. // Especially since these might also just pop in during future commits.
  7936. // Append to the beginning of the list.
  7937. renderedTail.sibling = workInProgress.child;
  7938. workInProgress.child = renderedTail;
  7939. } else {
  7940. var previousSibling = renderState.last;
  7941. if (previousSibling !== null) {
  7942. previousSibling.sibling = renderedTail;
  7943. } else {
  7944. workInProgress.child = renderedTail;
  7945. }
  7946. renderState.last = renderedTail;
  7947. }
  7948. }
  7949. if (renderState.tail !== null) {
  7950. // We still have tail rows to render.
  7951. if (renderState.tailExpiration === 0) {
  7952. // Heuristic for how long we're willing to spend rendering rows
  7953. // until we just give up and show what we have so far.
  7954. var TAIL_EXPIRATION_TIMEOUT_MS = 500;
  7955. renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS; // TODO: This is meant to mimic the train model or JND but this
  7956. // is a per component value. It should really be since the start
  7957. // of the total render or last commit. Consider using something like
  7958. // globalMostRecentFallbackTime. That doesn't account for being
  7959. // suspended for part of the time or when it's a new render.
  7960. // It should probably use a global start time value instead.
  7961. } // Pop a row.
  7962. var next = renderState.tail;
  7963. renderState.rendering = next;
  7964. renderState.tail = next.sibling;
  7965. renderState.lastEffect = workInProgress.lastEffect;
  7966. renderState.renderingStartTime = now();
  7967. next.sibling = null; // Restore the context.
  7968. // TODO: We can probably just avoid popping it instead and only
  7969. // setting it the first time we go from not suspended to suspended.
  7970. var suspenseContext = suspenseStackCursor.current;
  7971. if (didSuspendAlready) {
  7972. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  7973. } else {
  7974. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  7975. }
  7976. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  7977. return next;
  7978. }
  7979. return null;
  7980. }
  7981. }
  7982. {
  7983. {
  7984. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  7985. }
  7986. }
  7987. }
  7988. function unwindWork(workInProgress, renderExpirationTime) {
  7989. switch (workInProgress.tag) {
  7990. case ClassComponent:
  7991. {
  7992. var Component = workInProgress.type;
  7993. if (isContextProvider(Component)) {
  7994. popContext(workInProgress);
  7995. }
  7996. var effectTag = workInProgress.effectTag;
  7997. if (effectTag & ShouldCapture) {
  7998. workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
  7999. return workInProgress;
  8000. }
  8001. return null;
  8002. }
  8003. case HostRoot:
  8004. {
  8005. popHostContainer(workInProgress);
  8006. popTopLevelContextObject(workInProgress);
  8007. var _effectTag = workInProgress.effectTag;
  8008. if (!((_effectTag & DidCapture) === NoEffect)) {
  8009. {
  8010. throw Error( "The root failed to unmount after an error. This is likely a bug in React. Please file an issue." );
  8011. }
  8012. }
  8013. workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
  8014. return workInProgress;
  8015. }
  8016. case HostComponent:
  8017. {
  8018. // TODO: popHydrationState
  8019. popHostContext(workInProgress);
  8020. return null;
  8021. }
  8022. case SuspenseComponent:
  8023. {
  8024. popSuspenseContext(workInProgress);
  8025. var _effectTag2 = workInProgress.effectTag;
  8026. if (_effectTag2 & ShouldCapture) {
  8027. workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
  8028. return workInProgress;
  8029. }
  8030. return null;
  8031. }
  8032. case SuspenseListComponent:
  8033. {
  8034. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  8035. // caught by a nested boundary. If not, it should bubble through.
  8036. return null;
  8037. }
  8038. case HostPortal:
  8039. popHostContainer(workInProgress);
  8040. return null;
  8041. case ContextProvider:
  8042. popProvider(workInProgress);
  8043. return null;
  8044. default:
  8045. return null;
  8046. }
  8047. }
  8048. function unwindInterruptedWork(interruptedWork) {
  8049. switch (interruptedWork.tag) {
  8050. case ClassComponent:
  8051. {
  8052. var childContextTypes = interruptedWork.type.childContextTypes;
  8053. if (childContextTypes !== null && childContextTypes !== undefined) {
  8054. popContext(interruptedWork);
  8055. }
  8056. break;
  8057. }
  8058. case HostRoot:
  8059. {
  8060. popHostContainer(interruptedWork);
  8061. popTopLevelContextObject(interruptedWork);
  8062. break;
  8063. }
  8064. case HostComponent:
  8065. {
  8066. popHostContext(interruptedWork);
  8067. break;
  8068. }
  8069. case HostPortal:
  8070. popHostContainer(interruptedWork);
  8071. break;
  8072. case SuspenseComponent:
  8073. popSuspenseContext(interruptedWork);
  8074. break;
  8075. case SuspenseListComponent:
  8076. popSuspenseContext(interruptedWork);
  8077. break;
  8078. case ContextProvider:
  8079. popProvider(interruptedWork);
  8080. break;
  8081. }
  8082. }
  8083. function createCapturedValue(value, source) {
  8084. // If the value is an error, call this function immediately after it is thrown
  8085. // so the stack is accurate.
  8086. return {
  8087. value: value,
  8088. source: source,
  8089. stack: getStackByFiberInDevAndProd(source)
  8090. };
  8091. }
  8092. var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
  8093. var funcArgs = Array.prototype.slice.call(arguments, 3);
  8094. try {
  8095. func.apply(context, funcArgs);
  8096. } catch (error) {
  8097. this.onError(error);
  8098. }
  8099. };
  8100. {
  8101. // In DEV mode, we swap out invokeGuardedCallback for a special version
  8102. // that plays more nicely with the browser's DevTools. The idea is to preserve
  8103. // "Pause on exceptions" behavior. Because React wraps all user-provided
  8104. // functions in invokeGuardedCallback, and the production version of
  8105. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  8106. // like caught exceptions, and the DevTools won't pause unless the developer
  8107. // takes the extra step of enabling pause on caught exceptions. This is
  8108. // unintuitive, though, because even though React has caught the error, from
  8109. // the developer's perspective, the error is uncaught.
  8110. //
  8111. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  8112. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  8113. // DOM node, and call the user-provided callback from inside an event handler
  8114. // for that fake event. If the callback throws, the error is "captured" using
  8115. // a global event handler. But because the error happens in a different
  8116. // event loop context, it does not interrupt the normal program flow.
  8117. // Effectively, this gives us try-catch behavior without actually using
  8118. // try-catch. Neat!
  8119. // Check that the browser supports the APIs we need to implement our special
  8120. // DEV version of invokeGuardedCallback
  8121. if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
  8122. var fakeNode = document.createElement('react');
  8123. var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
  8124. // If document doesn't exist we know for sure we will crash in this method
  8125. // when we call document.createEvent(). However this can cause confusing
  8126. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  8127. // So we preemptively throw with a better message instead.
  8128. if (!(typeof document !== 'undefined')) {
  8129. {
  8130. 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." );
  8131. }
  8132. }
  8133. var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
  8134. // set this to true at the beginning, then set it to false right after
  8135. // calling the function. If the function errors, `didError` will never be
  8136. // set to false. This strategy works even if the browser is flaky and
  8137. // fails to call our global error handler, because it doesn't rely on
  8138. // the error event at all.
  8139. var didError = true; // Keeps track of the value of window.event so that we can reset it
  8140. // during the callback to let user code access window.event in the
  8141. // browsers that support it.
  8142. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  8143. // dispatching: https://github.com/facebook/react/issues/13688
  8144. var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event'); // Create an event handler for our fake event. We will synchronously
  8145. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  8146. // call the user-provided callback.
  8147. var funcArgs = Array.prototype.slice.call(arguments, 3);
  8148. function callCallback() {
  8149. // We immediately remove the callback from event listeners so that
  8150. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  8151. // nested call would trigger the fake event handlers of any call higher
  8152. // in the stack.
  8153. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  8154. // window.event assignment in both IE <= 10 as they throw an error
  8155. // "Member not found" in strict mode, and in Firefox which does not
  8156. // support window.event.
  8157. if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
  8158. window.event = windowEvent;
  8159. }
  8160. func.apply(context, funcArgs);
  8161. didError = false;
  8162. } // Create a global error event handler. We use this to capture the value
  8163. // that was thrown. It's possible that this error handler will fire more
  8164. // than once; for example, if non-React code also calls `dispatchEvent`
  8165. // and a handler for that event throws. We should be resilient to most of
  8166. // those cases. Even if our error event handler fires more than once, the
  8167. // last error event is always used. If the callback actually does error,
  8168. // we know that the last error event is the correct one, because it's not
  8169. // possible for anything else to have happened in between our callback
  8170. // erroring and the code that follows the `dispatchEvent` call below. If
  8171. // the callback doesn't error, but the error event was fired, we know to
  8172. // ignore it because `didError` will be false, as described above.
  8173. var error; // Use this to track whether the error event is ever called.
  8174. var didSetError = false;
  8175. var isCrossOriginError = false;
  8176. function handleWindowError(event) {
  8177. error = event.error;
  8178. didSetError = true;
  8179. if (error === null && event.colno === 0 && event.lineno === 0) {
  8180. isCrossOriginError = true;
  8181. }
  8182. if (event.defaultPrevented) {
  8183. // Some other error handler has prevented default.
  8184. // Browsers silence the error report if this happens.
  8185. // We'll remember this to later decide whether to log it or not.
  8186. if (error != null && typeof error === 'object') {
  8187. try {
  8188. error._suppressLogging = true;
  8189. } catch (inner) {// Ignore.
  8190. }
  8191. }
  8192. }
  8193. } // Create a fake event type.
  8194. var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
  8195. window.addEventListener('error', handleWindowError);
  8196. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  8197. // errors, it will trigger our global error handler.
  8198. evt.initEvent(evtType, false, false);
  8199. fakeNode.dispatchEvent(evt);
  8200. if (windowEventDescriptor) {
  8201. Object.defineProperty(window, 'event', windowEventDescriptor);
  8202. }
  8203. if (didError) {
  8204. if (!didSetError) {
  8205. // The callback errored, but the error event never fired.
  8206. 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.');
  8207. } else if (isCrossOriginError) {
  8208. 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.');
  8209. }
  8210. this.onError(error);
  8211. } // Remove our event listeners
  8212. window.removeEventListener('error', handleWindowError);
  8213. };
  8214. invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
  8215. }
  8216. }
  8217. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  8218. var hasError = false;
  8219. var caughtError = null; // Used by event system to capture/rethrow the first error.
  8220. var reporter = {
  8221. onError: function (error) {
  8222. hasError = true;
  8223. caughtError = error;
  8224. }
  8225. };
  8226. /**
  8227. * Call a function while guarding against errors that happens within it.
  8228. * Returns an error if it throws, otherwise null.
  8229. *
  8230. * In production, this is implemented using a try-catch. The reason we don't
  8231. * use a try-catch directly is so that we can swap out a different
  8232. * implementation in DEV mode.
  8233. *
  8234. * @param {String} name of the guard to use for logging or debugging
  8235. * @param {Function} func The function to invoke
  8236. * @param {*} context The context to use when calling the function
  8237. * @param {...*} args Arguments for function
  8238. */
  8239. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  8240. hasError = false;
  8241. caughtError = null;
  8242. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  8243. }
  8244. function hasCaughtError() {
  8245. return hasError;
  8246. }
  8247. function clearCaughtError() {
  8248. if (hasError) {
  8249. var error = caughtError;
  8250. hasError = false;
  8251. caughtError = null;
  8252. return error;
  8253. } else {
  8254. {
  8255. {
  8256. throw Error( "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue." );
  8257. }
  8258. }
  8259. }
  8260. }
  8261. function logCapturedError(capturedError) {
  8262. var error = capturedError.error;
  8263. {
  8264. var componentName = capturedError.componentName,
  8265. componentStack = capturedError.componentStack,
  8266. errorBoundaryName = capturedError.errorBoundaryName,
  8267. errorBoundaryFound = capturedError.errorBoundaryFound,
  8268. willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
  8269. // `preventDefault()` in window `error` handler.
  8270. // We record this information as an expando on the error.
  8271. if (error != null && error._suppressLogging) {
  8272. if (errorBoundaryFound && willRetry) {
  8273. // The error is recoverable and was silenced.
  8274. // Ignore it and don't print the stack addendum.
  8275. // This is handy for testing error boundaries without noise.
  8276. return;
  8277. } // The error is fatal. Since the silencing might have
  8278. // been accidental, we'll surface it anyway.
  8279. // However, the browser would have silenced the original error
  8280. // so we'll print it first, and then print the stack addendum.
  8281. console['error'](error); // Don't transform to our wrapper
  8282. // For a more detailed description of this block, see:
  8283. // https://github.com/facebook/react/pull/13384
  8284. }
  8285. var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
  8286. var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
  8287. if (errorBoundaryFound && errorBoundaryName) {
  8288. if (willRetry) {
  8289. errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
  8290. } else {
  8291. errorBoundaryMessage = "This error was initially handled by the error boundary " + errorBoundaryName + ".\n" + "Recreating the tree from scratch failed so React will unmount the tree.";
  8292. }
  8293. } else {
  8294. 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.';
  8295. }
  8296. var combinedMessage = "" + componentNameMessage + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  8297. // We don't include the original error message and JS stack because the browser
  8298. // has already printed it. Even if the application swallows the error, it is still
  8299. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  8300. console['error'](combinedMessage); // Don't transform to our wrapper
  8301. }
  8302. }
  8303. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  8304. {
  8305. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  8306. }
  8307. var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
  8308. function logError(boundary, errorInfo) {
  8309. var source = errorInfo.source;
  8310. var stack = errorInfo.stack;
  8311. if (stack === null && source !== null) {
  8312. stack = getStackByFiberInDevAndProd(source);
  8313. }
  8314. var capturedError = {
  8315. componentName: source !== null ? getComponentName(source.type) : null,
  8316. componentStack: stack !== null ? stack : '',
  8317. error: errorInfo.value,
  8318. errorBoundary: null,
  8319. errorBoundaryName: null,
  8320. errorBoundaryFound: false,
  8321. willRetry: false
  8322. };
  8323. if (boundary !== null && boundary.tag === ClassComponent) {
  8324. capturedError.errorBoundary = boundary.stateNode;
  8325. capturedError.errorBoundaryName = getComponentName(boundary.type);
  8326. capturedError.errorBoundaryFound = true;
  8327. capturedError.willRetry = true;
  8328. }
  8329. try {
  8330. logCapturedError(capturedError);
  8331. } catch (e) {
  8332. // This method must not throw, or React internal state will get messed up.
  8333. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  8334. // we want to report this error outside of the normal stack as a last resort.
  8335. // https://github.com/facebook/react/issues/13188
  8336. setTimeout(function () {
  8337. throw e;
  8338. });
  8339. }
  8340. }
  8341. var callComponentWillUnmountWithTimer = function (current, instance) {
  8342. startPhaseTimer(current, 'componentWillUnmount');
  8343. instance.props = current.memoizedProps;
  8344. instance.state = current.memoizedState;
  8345. instance.componentWillUnmount();
  8346. stopPhaseTimer();
  8347. }; // Capture errors so they don't interrupt unmounting.
  8348. function safelyCallComponentWillUnmount(current, instance) {
  8349. {
  8350. invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current, instance);
  8351. if (hasCaughtError()) {
  8352. var unmountError = clearCaughtError();
  8353. captureCommitPhaseError(current, unmountError);
  8354. }
  8355. }
  8356. }
  8357. function safelyDetachRef(current) {
  8358. var ref = current.ref;
  8359. if (ref !== null) {
  8360. if (typeof ref === 'function') {
  8361. {
  8362. invokeGuardedCallback(null, ref, null, null);
  8363. if (hasCaughtError()) {
  8364. var refError = clearCaughtError();
  8365. captureCommitPhaseError(current, refError);
  8366. }
  8367. }
  8368. } else {
  8369. ref.current = null;
  8370. }
  8371. }
  8372. }
  8373. function safelyCallDestroy(current, destroy) {
  8374. {
  8375. invokeGuardedCallback(null, destroy, null);
  8376. if (hasCaughtError()) {
  8377. var error = clearCaughtError();
  8378. captureCommitPhaseError(current, error);
  8379. }
  8380. }
  8381. }
  8382. function commitBeforeMutationLifeCycles(current, finishedWork) {
  8383. switch (finishedWork.tag) {
  8384. case FunctionComponent:
  8385. case ForwardRef:
  8386. case SimpleMemoComponent:
  8387. case Block:
  8388. {
  8389. return;
  8390. }
  8391. case ClassComponent:
  8392. {
  8393. if (finishedWork.effectTag & Snapshot) {
  8394. if (current !== null) {
  8395. var prevProps = current.memoizedProps;
  8396. var prevState = current.memoizedState;
  8397. startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
  8398. var instance = finishedWork.stateNode; // We could update instance props and state here,
  8399. // but instead we rely on them being set during last render.
  8400. // TODO: revisit this when we implement resuming.
  8401. {
  8402. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8403. if (instance.props !== finishedWork.memoizedProps) {
  8404. 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');
  8405. }
  8406. if (instance.state !== finishedWork.memoizedState) {
  8407. 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');
  8408. }
  8409. }
  8410. }
  8411. var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
  8412. {
  8413. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  8414. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  8415. didWarnSet.add(finishedWork.type);
  8416. error('%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
  8417. }
  8418. }
  8419. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  8420. stopPhaseTimer();
  8421. }
  8422. }
  8423. return;
  8424. }
  8425. case HostRoot:
  8426. case HostComponent:
  8427. case HostText:
  8428. case HostPortal:
  8429. case IncompleteClassComponent:
  8430. // Nothing to do for these component types
  8431. return;
  8432. }
  8433. {
  8434. {
  8435. 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." );
  8436. }
  8437. }
  8438. }
  8439. function commitHookEffectListUnmount(tag, finishedWork) {
  8440. var updateQueue = finishedWork.updateQueue;
  8441. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  8442. if (lastEffect !== null) {
  8443. var firstEffect = lastEffect.next;
  8444. var effect = firstEffect;
  8445. do {
  8446. if ((effect.tag & tag) === tag) {
  8447. // Unmount
  8448. var destroy = effect.destroy;
  8449. effect.destroy = undefined;
  8450. if (destroy !== undefined) {
  8451. destroy();
  8452. }
  8453. }
  8454. effect = effect.next;
  8455. } while (effect !== firstEffect);
  8456. }
  8457. }
  8458. function commitHookEffectListMount(tag, finishedWork) {
  8459. var updateQueue = finishedWork.updateQueue;
  8460. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  8461. if (lastEffect !== null) {
  8462. var firstEffect = lastEffect.next;
  8463. var effect = firstEffect;
  8464. do {
  8465. if ((effect.tag & tag) === tag) {
  8466. // Mount
  8467. var create = effect.create;
  8468. effect.destroy = create();
  8469. {
  8470. var destroy = effect.destroy;
  8471. if (destroy !== undefined && typeof destroy !== 'function') {
  8472. var addendum = void 0;
  8473. if (destroy === null) {
  8474. addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
  8475. } else if (typeof destroy.then === 'function') {
  8476. 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';
  8477. } else {
  8478. addendum = ' You returned: ' + destroy;
  8479. }
  8480. error('An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
  8481. }
  8482. }
  8483. }
  8484. effect = effect.next;
  8485. } while (effect !== firstEffect);
  8486. }
  8487. }
  8488. function commitPassiveHookEffects(finishedWork) {
  8489. if ((finishedWork.effectTag & Passive) !== NoEffect) {
  8490. switch (finishedWork.tag) {
  8491. case FunctionComponent:
  8492. case ForwardRef:
  8493. case SimpleMemoComponent:
  8494. case Block:
  8495. {
  8496. // TODO (#17945) We should call all passive destroy functions (for all fibers)
  8497. // before calling any create functions. The current approach only serializes
  8498. // these for a single fiber.
  8499. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
  8500. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  8501. break;
  8502. }
  8503. }
  8504. }
  8505. }
  8506. function commitLifeCycles(finishedRoot, current, finishedWork, committedExpirationTime) {
  8507. switch (finishedWork.tag) {
  8508. case FunctionComponent:
  8509. case ForwardRef:
  8510. case SimpleMemoComponent:
  8511. case Block:
  8512. {
  8513. // At this point layout effects have already been destroyed (during mutation phase).
  8514. // This is done to prevent sibling component effects from interfering with each other,
  8515. // e.g. a destroy function in one component should never override a ref set
  8516. // by a create function in another component during the same commit.
  8517. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  8518. return;
  8519. }
  8520. case ClassComponent:
  8521. {
  8522. var instance = finishedWork.stateNode;
  8523. if (finishedWork.effectTag & Update) {
  8524. if (current === null) {
  8525. startPhaseTimer(finishedWork, 'componentDidMount'); // We could update instance props and state here,
  8526. // but instead we rely on them being set during last render.
  8527. // TODO: revisit this when we implement resuming.
  8528. {
  8529. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8530. if (instance.props !== finishedWork.memoizedProps) {
  8531. 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');
  8532. }
  8533. if (instance.state !== finishedWork.memoizedState) {
  8534. 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');
  8535. }
  8536. }
  8537. }
  8538. instance.componentDidMount();
  8539. stopPhaseTimer();
  8540. } else {
  8541. var prevProps = finishedWork.elementType === finishedWork.type ? current.memoizedProps : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  8542. var prevState = current.memoizedState;
  8543. startPhaseTimer(finishedWork, 'componentDidUpdate'); // We could update instance props and state here,
  8544. // but instead we rely on them being set during last render.
  8545. // TODO: revisit this when we implement resuming.
  8546. {
  8547. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8548. if (instance.props !== finishedWork.memoizedProps) {
  8549. 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');
  8550. }
  8551. if (instance.state !== finishedWork.memoizedState) {
  8552. 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');
  8553. }
  8554. }
  8555. }
  8556. instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
  8557. stopPhaseTimer();
  8558. }
  8559. }
  8560. var updateQueue = finishedWork.updateQueue;
  8561. if (updateQueue !== null) {
  8562. {
  8563. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  8564. if (instance.props !== finishedWork.memoizedProps) {
  8565. 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');
  8566. }
  8567. if (instance.state !== finishedWork.memoizedState) {
  8568. 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');
  8569. }
  8570. }
  8571. } // We could update instance props and state here,
  8572. // but instead we rely on them being set during last render.
  8573. // TODO: revisit this when we implement resuming.
  8574. commitUpdateQueue(finishedWork, updateQueue, instance);
  8575. }
  8576. return;
  8577. }
  8578. case HostRoot:
  8579. {
  8580. var _updateQueue = finishedWork.updateQueue;
  8581. if (_updateQueue !== null) {
  8582. var _instance = null;
  8583. if (finishedWork.child !== null) {
  8584. switch (finishedWork.child.tag) {
  8585. case HostComponent:
  8586. _instance = getPublicInstance(finishedWork.child.stateNode);
  8587. break;
  8588. case ClassComponent:
  8589. _instance = finishedWork.child.stateNode;
  8590. break;
  8591. }
  8592. }
  8593. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  8594. }
  8595. return;
  8596. }
  8597. case HostComponent:
  8598. {
  8599. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  8600. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  8601. // These effects should only be committed when components are first mounted,
  8602. // aka when there is no current/alternate.
  8603. if (current === null && finishedWork.effectTag & Update) {
  8604. var type = finishedWork.type;
  8605. var props = finishedWork.memoizedProps;
  8606. }
  8607. return;
  8608. }
  8609. case HostText:
  8610. {
  8611. // We have no life-cycles associated with text.
  8612. return;
  8613. }
  8614. case HostPortal:
  8615. {
  8616. // We have no life-cycles associated with portals.
  8617. return;
  8618. }
  8619. case Profiler:
  8620. {
  8621. {
  8622. var onRender = finishedWork.memoizedProps.onRender;
  8623. if (typeof onRender === 'function') {
  8624. {
  8625. onRender(finishedWork.memoizedProps.id, current === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
  8626. }
  8627. }
  8628. }
  8629. return;
  8630. }
  8631. case SuspenseComponent:
  8632. {
  8633. return;
  8634. }
  8635. case SuspenseListComponent:
  8636. case IncompleteClassComponent:
  8637. case FundamentalComponent:
  8638. case ScopeComponent:
  8639. return;
  8640. }
  8641. {
  8642. {
  8643. 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." );
  8644. }
  8645. }
  8646. }
  8647. function hideOrUnhideAllChildren(finishedWork, isHidden) {
  8648. {
  8649. // We only have the top Fiber that was inserted but we need to recurse down its
  8650. // children to find all the terminal nodes.
  8651. var node = finishedWork;
  8652. while (true) {
  8653. if (node.tag === HostComponent) {
  8654. var instance = node.stateNode;
  8655. if (isHidden) {
  8656. hideInstance(instance);
  8657. } else {
  8658. unhideInstance(node.stateNode, node.memoizedProps);
  8659. }
  8660. } else if (node.tag === HostText) {
  8661. var _instance3 = node.stateNode;
  8662. if (isHidden) {
  8663. hideTextInstance(_instance3);
  8664. } else {
  8665. unhideTextInstance(_instance3, node.memoizedProps);
  8666. }
  8667. } else if (node.tag === SuspenseComponent && node.memoizedState !== null && node.memoizedState.dehydrated === null) {
  8668. // Found a nested Suspense component that timed out. Skip over the
  8669. // primary child fragment, which should remain hidden.
  8670. var fallbackChildFragment = node.child.sibling;
  8671. fallbackChildFragment.return = node;
  8672. node = fallbackChildFragment;
  8673. continue;
  8674. } else if (node.child !== null) {
  8675. node.child.return = node;
  8676. node = node.child;
  8677. continue;
  8678. }
  8679. if (node === finishedWork) {
  8680. return;
  8681. }
  8682. while (node.sibling === null) {
  8683. if (node.return === null || node.return === finishedWork) {
  8684. return;
  8685. }
  8686. node = node.return;
  8687. }
  8688. node.sibling.return = node.return;
  8689. node = node.sibling;
  8690. }
  8691. }
  8692. }
  8693. function commitAttachRef(finishedWork) {
  8694. var ref = finishedWork.ref;
  8695. if (ref !== null) {
  8696. var instance = finishedWork.stateNode;
  8697. var instanceToUse;
  8698. switch (finishedWork.tag) {
  8699. case HostComponent:
  8700. instanceToUse = getPublicInstance(instance);
  8701. break;
  8702. default:
  8703. instanceToUse = instance;
  8704. } // Moved outside to ensure DCE works with this flag
  8705. if (typeof ref === 'function') {
  8706. ref(instanceToUse);
  8707. } else {
  8708. {
  8709. if (!ref.hasOwnProperty('current')) {
  8710. error('Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
  8711. }
  8712. }
  8713. ref.current = instanceToUse;
  8714. }
  8715. }
  8716. }
  8717. function commitDetachRef(current) {
  8718. var currentRef = current.ref;
  8719. if (currentRef !== null) {
  8720. if (typeof currentRef === 'function') {
  8721. currentRef(null);
  8722. } else {
  8723. currentRef.current = null;
  8724. }
  8725. }
  8726. } // User-originating errors (lifecycles and refs) should not interrupt
  8727. // deletion, so don't let them throw. Host-originating errors should
  8728. // interrupt deletion, so it's okay
  8729. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  8730. onCommitUnmount(current);
  8731. switch (current.tag) {
  8732. case FunctionComponent:
  8733. case ForwardRef:
  8734. case MemoComponent:
  8735. case SimpleMemoComponent:
  8736. case Block:
  8737. {
  8738. var updateQueue = current.updateQueue;
  8739. if (updateQueue !== null) {
  8740. var lastEffect = updateQueue.lastEffect;
  8741. if (lastEffect !== null) {
  8742. var firstEffect = lastEffect.next;
  8743. {
  8744. // When the owner fiber is deleted, the destroy function of a passive
  8745. // effect hook is called during the synchronous commit phase. This is
  8746. // a concession to implementation complexity. Calling it in the
  8747. // passive effect phase (like they usually are, when dependencies
  8748. // change during an update) would require either traversing the
  8749. // children of the deleted fiber again, or including unmount effects
  8750. // as part of the fiber effect list.
  8751. //
  8752. // Because this is during the sync commit phase, we need to change
  8753. // the priority.
  8754. //
  8755. // TODO: Reconsider this implementation trade off.
  8756. var priorityLevel = renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel;
  8757. runWithPriority(priorityLevel, function () {
  8758. var effect = firstEffect;
  8759. do {
  8760. var _destroy = effect.destroy;
  8761. if (_destroy !== undefined) {
  8762. safelyCallDestroy(current, _destroy);
  8763. }
  8764. effect = effect.next;
  8765. } while (effect !== firstEffect);
  8766. });
  8767. }
  8768. }
  8769. }
  8770. return;
  8771. }
  8772. case ClassComponent:
  8773. {
  8774. safelyDetachRef(current);
  8775. var instance = current.stateNode;
  8776. if (typeof instance.componentWillUnmount === 'function') {
  8777. safelyCallComponentWillUnmount(current, instance);
  8778. }
  8779. return;
  8780. }
  8781. case HostComponent:
  8782. {
  8783. safelyDetachRef(current);
  8784. return;
  8785. }
  8786. case HostPortal:
  8787. {
  8788. // TODO: this is recursive.
  8789. // We are also not using this parent because
  8790. // the portal will get pushed immediately.
  8791. {
  8792. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  8793. }
  8794. return;
  8795. }
  8796. case FundamentalComponent:
  8797. {
  8798. return;
  8799. }
  8800. case DehydratedFragment:
  8801. {
  8802. return;
  8803. }
  8804. case ScopeComponent:
  8805. {
  8806. return;
  8807. }
  8808. }
  8809. }
  8810. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  8811. // While we're inside a removed host node we don't want to call
  8812. // removeChild on the inner nodes because they're removed by the top
  8813. // call anyway. We also want to call componentWillUnmount on all
  8814. // composites before this host node is removed from the tree. Therefore
  8815. // we do an inner loop while we're still inside the host node.
  8816. var node = root;
  8817. while (true) {
  8818. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
  8819. // Skip portals because commitUnmount() currently visits them recursively.
  8820. if (node.child !== null && ( // If we use mutation we drill down into portals using commitUnmount above.
  8821. // If we don't use mutation we drill down into portals here instead.
  8822. node.tag !== HostPortal)) {
  8823. node.child.return = node;
  8824. node = node.child;
  8825. continue;
  8826. }
  8827. if (node === root) {
  8828. return;
  8829. }
  8830. while (node.sibling === null) {
  8831. if (node.return === null || node.return === root) {
  8832. return;
  8833. }
  8834. node = node.return;
  8835. }
  8836. node.sibling.return = node.return;
  8837. node = node.sibling;
  8838. }
  8839. }
  8840. function detachFiber(current) {
  8841. var alternate = current.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
  8842. // should clear the child pointer of the parent alternate to let this
  8843. // get GC:ed but we don't know which for sure which parent is the current
  8844. // one so we'll settle for GC:ing the subtree of this child. This child
  8845. // itself will be GC:ed when the parent updates the next time.
  8846. current.return = null;
  8847. current.child = null;
  8848. current.memoizedState = null;
  8849. current.updateQueue = null;
  8850. current.dependencies = null;
  8851. current.alternate = null;
  8852. current.firstEffect = null;
  8853. current.lastEffect = null;
  8854. current.pendingProps = null;
  8855. current.memoizedProps = null;
  8856. current.stateNode = null;
  8857. if (alternate !== null) {
  8858. detachFiber(alternate);
  8859. }
  8860. }
  8861. function getHostParentFiber(fiber) {
  8862. var parent = fiber.return;
  8863. while (parent !== null) {
  8864. if (isHostParent(parent)) {
  8865. return parent;
  8866. }
  8867. parent = parent.return;
  8868. }
  8869. {
  8870. {
  8871. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  8872. }
  8873. }
  8874. }
  8875. function isHostParent(fiber) {
  8876. return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
  8877. }
  8878. function getHostSibling(fiber) {
  8879. // We're going to search forward into the tree until we find a sibling host
  8880. // node. Unfortunately, if multiple insertions are done in a row we have to
  8881. // search past them. This leads to exponential search for the next sibling.
  8882. // TODO: Find a more efficient way to do this.
  8883. var node = fiber;
  8884. siblings: while (true) {
  8885. // If we didn't find anything, let's try the next sibling.
  8886. while (node.sibling === null) {
  8887. if (node.return === null || isHostParent(node.return)) {
  8888. // If we pop out of the root or hit the parent the fiber we are the
  8889. // last sibling.
  8890. return null;
  8891. }
  8892. node = node.return;
  8893. }
  8894. node.sibling.return = node.return;
  8895. node = node.sibling;
  8896. while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
  8897. // If it is not host node and, we might have a host node inside it.
  8898. // Try to search down until we find one.
  8899. if (node.effectTag & Placement) {
  8900. // If we don't have a child, try the siblings instead.
  8901. continue siblings;
  8902. } // If we don't have a child, try the siblings instead.
  8903. // We also skip portals because they are not part of this host tree.
  8904. if (node.child === null || node.tag === HostPortal) {
  8905. continue siblings;
  8906. } else {
  8907. node.child.return = node;
  8908. node = node.child;
  8909. }
  8910. } // Check if this host node is stable or about to be placed.
  8911. if (!(node.effectTag & Placement)) {
  8912. // Found it!
  8913. return node.stateNode;
  8914. }
  8915. }
  8916. }
  8917. function commitPlacement(finishedWork) {
  8918. var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
  8919. var parent;
  8920. var isContainer;
  8921. var parentStateNode = parentFiber.stateNode;
  8922. switch (parentFiber.tag) {
  8923. case HostComponent:
  8924. parent = parentStateNode;
  8925. isContainer = false;
  8926. break;
  8927. case HostRoot:
  8928. parent = parentStateNode.containerInfo;
  8929. isContainer = true;
  8930. break;
  8931. case HostPortal:
  8932. parent = parentStateNode.containerInfo;
  8933. isContainer = true;
  8934. break;
  8935. case FundamentalComponent:
  8936. // eslint-disable-next-line-no-fallthrough
  8937. default:
  8938. {
  8939. {
  8940. throw Error( "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." );
  8941. }
  8942. }
  8943. }
  8944. if (parentFiber.effectTag & ContentReset) {
  8945. parentFiber.effectTag &= ~ContentReset;
  8946. }
  8947. var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
  8948. // children to find all the terminal nodes.
  8949. if (isContainer) {
  8950. insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
  8951. } else {
  8952. insertOrAppendPlacementNode(finishedWork, before, parent);
  8953. }
  8954. }
  8955. function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
  8956. var tag = node.tag;
  8957. var isHost = tag === HostComponent || tag === HostText;
  8958. if (isHost || enableFundamentalAPI ) {
  8959. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  8960. if (before) {
  8961. insertInContainerBefore(parent, stateNode, before);
  8962. } else {
  8963. appendChildToContainer(parent, stateNode);
  8964. }
  8965. } else if (tag === HostPortal) ; else {
  8966. var child = node.child;
  8967. if (child !== null) {
  8968. insertOrAppendPlacementNodeIntoContainer(child, before, parent);
  8969. var sibling = child.sibling;
  8970. while (sibling !== null) {
  8971. insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
  8972. sibling = sibling.sibling;
  8973. }
  8974. }
  8975. }
  8976. }
  8977. function insertOrAppendPlacementNode(node, before, parent) {
  8978. var tag = node.tag;
  8979. var isHost = tag === HostComponent || tag === HostText;
  8980. if (isHost || enableFundamentalAPI ) {
  8981. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  8982. if (before) {
  8983. insertBefore(parent, stateNode, before);
  8984. } else {
  8985. appendChild(parent, stateNode);
  8986. }
  8987. } else if (tag === HostPortal) ; else {
  8988. var child = node.child;
  8989. if (child !== null) {
  8990. insertOrAppendPlacementNode(child, before, parent);
  8991. var sibling = child.sibling;
  8992. while (sibling !== null) {
  8993. insertOrAppendPlacementNode(sibling, before, parent);
  8994. sibling = sibling.sibling;
  8995. }
  8996. }
  8997. }
  8998. }
  8999. function unmountHostComponents(finishedRoot, current, renderPriorityLevel) {
  9000. // We only have the top Fiber that was deleted but we need to recurse down its
  9001. // children to find all the terminal nodes.
  9002. var node = current; // Each iteration, currentParent is populated with node's host parent if not
  9003. // currentParentIsValid.
  9004. var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
  9005. var currentParent;
  9006. var currentParentIsContainer;
  9007. while (true) {
  9008. if (!currentParentIsValid) {
  9009. var parent = node.return;
  9010. findParent: while (true) {
  9011. if (!(parent !== null)) {
  9012. {
  9013. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  9014. }
  9015. }
  9016. var parentStateNode = parent.stateNode;
  9017. switch (parent.tag) {
  9018. case HostComponent:
  9019. currentParent = parentStateNode;
  9020. currentParentIsContainer = false;
  9021. break findParent;
  9022. case HostRoot:
  9023. currentParent = parentStateNode.containerInfo;
  9024. currentParentIsContainer = true;
  9025. break findParent;
  9026. case HostPortal:
  9027. currentParent = parentStateNode.containerInfo;
  9028. currentParentIsContainer = true;
  9029. break findParent;
  9030. }
  9031. parent = parent.return;
  9032. }
  9033. currentParentIsValid = true;
  9034. }
  9035. if (node.tag === HostComponent || node.tag === HostText) {
  9036. commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
  9037. // node from the tree.
  9038. if (currentParentIsContainer) {
  9039. removeChildFromContainer(currentParent, node.stateNode);
  9040. } else {
  9041. removeChild(currentParent, node.stateNode);
  9042. } // Don't visit children because we already visited them.
  9043. } else if (node.tag === HostPortal) {
  9044. if (node.child !== null) {
  9045. // When we go into a portal, it becomes the parent to remove from.
  9046. // We will reassign it back when we pop the portal on the way up.
  9047. currentParent = node.stateNode.containerInfo;
  9048. currentParentIsContainer = true; // Visit children because portals might contain host components.
  9049. node.child.return = node;
  9050. node = node.child;
  9051. continue;
  9052. }
  9053. } else {
  9054. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
  9055. if (node.child !== null) {
  9056. node.child.return = node;
  9057. node = node.child;
  9058. continue;
  9059. }
  9060. }
  9061. if (node === current) {
  9062. return;
  9063. }
  9064. while (node.sibling === null) {
  9065. if (node.return === null || node.return === current) {
  9066. return;
  9067. }
  9068. node = node.return;
  9069. if (node.tag === HostPortal) {
  9070. // When we go out of the portal, we need to restore the parent.
  9071. // Since we don't keep a stack of them, we will search for it.
  9072. currentParentIsValid = false;
  9073. }
  9074. }
  9075. node.sibling.return = node.return;
  9076. node = node.sibling;
  9077. }
  9078. }
  9079. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  9080. {
  9081. // Recursively delete all host nodes from the parent.
  9082. // Detach refs and call componentWillUnmount() on the whole subtree.
  9083. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  9084. }
  9085. detachFiber(current);
  9086. }
  9087. function commitWork(current, finishedWork) {
  9088. switch (finishedWork.tag) {
  9089. case FunctionComponent:
  9090. case ForwardRef:
  9091. case MemoComponent:
  9092. case SimpleMemoComponent:
  9093. case Block:
  9094. {
  9095. // Layout effects are destroyed during the mutation phase so that all
  9096. // destroy functions for all fibers are called before any create functions.
  9097. // This prevents sibling component effects from interfering with each other,
  9098. // e.g. a destroy function in one component should never override a ref set
  9099. // by a create function in another component during the same commit.
  9100. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  9101. return;
  9102. }
  9103. case ClassComponent:
  9104. {
  9105. return;
  9106. }
  9107. case HostComponent:
  9108. {
  9109. var instance = finishedWork.stateNode;
  9110. if (instance != null) {
  9111. // Commit the work prepared earlier.
  9112. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  9113. // as the newProps. The updatePayload will contain the real change in
  9114. // this case.
  9115. var oldProps = current !== null ? current.memoizedProps : newProps;
  9116. var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
  9117. var updatePayload = finishedWork.updateQueue;
  9118. finishedWork.updateQueue = null;
  9119. if (updatePayload !== null) {
  9120. commitUpdate(instance, updatePayload, type, oldProps, newProps);
  9121. }
  9122. }
  9123. return;
  9124. }
  9125. case HostText:
  9126. {
  9127. if (!(finishedWork.stateNode !== null)) {
  9128. {
  9129. throw Error( "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." );
  9130. }
  9131. }
  9132. var textInstance = finishedWork.stateNode;
  9133. var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  9134. // as the newProps. The updatePayload will contain the real change in
  9135. // this case.
  9136. var oldText = current !== null ? current.memoizedProps : newText;
  9137. commitTextUpdate(textInstance, oldText, newText);
  9138. return;
  9139. }
  9140. case HostRoot:
  9141. {
  9142. return;
  9143. }
  9144. case Profiler:
  9145. {
  9146. return;
  9147. }
  9148. case SuspenseComponent:
  9149. {
  9150. commitSuspenseComponent(finishedWork);
  9151. attachSuspenseRetryListeners(finishedWork);
  9152. return;
  9153. }
  9154. case SuspenseListComponent:
  9155. {
  9156. attachSuspenseRetryListeners(finishedWork);
  9157. return;
  9158. }
  9159. case IncompleteClassComponent:
  9160. {
  9161. return;
  9162. }
  9163. }
  9164. {
  9165. {
  9166. 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." );
  9167. }
  9168. }
  9169. }
  9170. function commitSuspenseComponent(finishedWork) {
  9171. var newState = finishedWork.memoizedState;
  9172. var newDidTimeout;
  9173. var primaryChildParent = finishedWork;
  9174. if (newState === null) {
  9175. newDidTimeout = false;
  9176. } else {
  9177. newDidTimeout = true;
  9178. primaryChildParent = finishedWork.child;
  9179. markCommitTimeOfFallback();
  9180. }
  9181. if ( primaryChildParent !== null) {
  9182. hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
  9183. }
  9184. }
  9185. function attachSuspenseRetryListeners(finishedWork) {
  9186. // If this boundary just timed out, then it will have a set of thenables.
  9187. // For each thenable, attach a listener so that when it resolves, React
  9188. // attempts to re-render the boundary in the primary (pre-timeout) state.
  9189. var thenables = finishedWork.updateQueue;
  9190. if (thenables !== null) {
  9191. finishedWork.updateQueue = null;
  9192. var retryCache = finishedWork.stateNode;
  9193. if (retryCache === null) {
  9194. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  9195. }
  9196. thenables.forEach(function (thenable) {
  9197. // Memoize using the boundary fiber to prevent redundant listeners.
  9198. var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
  9199. if (!retryCache.has(thenable)) {
  9200. {
  9201. if (thenable.__reactDoNotTraceInteractions !== true) {
  9202. retry = tracing.unstable_wrap(retry);
  9203. }
  9204. }
  9205. retryCache.add(thenable);
  9206. thenable.then(retry, retry);
  9207. }
  9208. });
  9209. }
  9210. }
  9211. function commitResetTextContent(current) {
  9212. resetTextContent(current.stateNode);
  9213. }
  9214. var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
  9215. function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
  9216. var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
  9217. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  9218. // being called "element".
  9219. update.payload = {
  9220. element: null
  9221. };
  9222. var error = errorInfo.value;
  9223. update.callback = function () {
  9224. onUncaughtError(error);
  9225. logError(fiber, errorInfo);
  9226. };
  9227. return update;
  9228. }
  9229. function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
  9230. var update = createUpdate(expirationTime, null);
  9231. update.tag = CaptureUpdate;
  9232. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  9233. if (typeof getDerivedStateFromError === 'function') {
  9234. var error$1 = errorInfo.value;
  9235. update.payload = function () {
  9236. logError(fiber, errorInfo);
  9237. return getDerivedStateFromError(error$1);
  9238. };
  9239. }
  9240. var inst = fiber.stateNode;
  9241. if (inst !== null && typeof inst.componentDidCatch === 'function') {
  9242. update.callback = function callback() {
  9243. {
  9244. markFailedErrorBoundaryForHotReloading(fiber);
  9245. }
  9246. if (typeof getDerivedStateFromError !== 'function') {
  9247. // To preserve the preexisting retry behavior of error boundaries,
  9248. // we keep track of which ones already failed during this batch.
  9249. // This gets reset before we yield back to the browser.
  9250. // TODO: Warn in strict mode if getDerivedStateFromError is
  9251. // not defined.
  9252. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  9253. logError(fiber, errorInfo);
  9254. }
  9255. var error$1 = errorInfo.value;
  9256. var stack = errorInfo.stack;
  9257. this.componentDidCatch(error$1, {
  9258. componentStack: stack !== null ? stack : ''
  9259. });
  9260. {
  9261. if (typeof getDerivedStateFromError !== 'function') {
  9262. // If componentDidCatch is the only error boundary method defined,
  9263. // then it needs to call setState to recover from errors.
  9264. // If no state update is scheduled then the boundary will swallow the error.
  9265. if (fiber.expirationTime !== Sync) {
  9266. 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');
  9267. }
  9268. }
  9269. }
  9270. };
  9271. } else {
  9272. update.callback = function () {
  9273. markFailedErrorBoundaryForHotReloading(fiber);
  9274. };
  9275. }
  9276. return update;
  9277. }
  9278. function attachPingListener(root, renderExpirationTime, thenable) {
  9279. // Attach a listener to the promise to "ping" the root and retry. But
  9280. // only if one does not already exist for the current render expiration
  9281. // time (which acts like a "thread ID" here).
  9282. var pingCache = root.pingCache;
  9283. var threadIDs;
  9284. if (pingCache === null) {
  9285. pingCache = root.pingCache = new PossiblyWeakMap();
  9286. threadIDs = new Set();
  9287. pingCache.set(thenable, threadIDs);
  9288. } else {
  9289. threadIDs = pingCache.get(thenable);
  9290. if (threadIDs === undefined) {
  9291. threadIDs = new Set();
  9292. pingCache.set(thenable, threadIDs);
  9293. }
  9294. }
  9295. if (!threadIDs.has(renderExpirationTime)) {
  9296. // Memoize using the thread ID to prevent redundant listeners.
  9297. threadIDs.add(renderExpirationTime);
  9298. var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
  9299. thenable.then(ping, ping);
  9300. }
  9301. }
  9302. function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
  9303. // The source fiber did not complete.
  9304. sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
  9305. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  9306. if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
  9307. // This is a thenable.
  9308. var thenable = value;
  9309. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  9310. // Reset the memoizedState to what it was before we attempted
  9311. // to render it.
  9312. var currentSource = sourceFiber.alternate;
  9313. if (currentSource) {
  9314. sourceFiber.updateQueue = currentSource.updateQueue;
  9315. sourceFiber.memoizedState = currentSource.memoizedState;
  9316. sourceFiber.expirationTime = currentSource.expirationTime;
  9317. } else {
  9318. sourceFiber.updateQueue = null;
  9319. sourceFiber.memoizedState = null;
  9320. }
  9321. }
  9322. var hasInvisibleParentBoundary = hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext); // Schedule the nearest Suspense to re-render the timed out view.
  9323. var _workInProgress = returnFiber;
  9324. do {
  9325. if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)) {
  9326. // Found the nearest boundary.
  9327. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  9328. // attach another listener to flip the boundary back to its normal state.
  9329. var thenables = _workInProgress.updateQueue;
  9330. if (thenables === null) {
  9331. var updateQueue = new Set();
  9332. updateQueue.add(thenable);
  9333. _workInProgress.updateQueue = updateQueue;
  9334. } else {
  9335. thenables.add(thenable);
  9336. } // If the boundary is outside of blocking mode, we should *not*
  9337. // suspend the commit. Pretend as if the suspended component rendered
  9338. // null and keep rendering. In the commit phase, we'll schedule a
  9339. // subsequent synchronous update to re-render the Suspense.
  9340. //
  9341. // Note: It doesn't matter whether the component that suspended was
  9342. // inside a blocking mode tree. If the Suspense is outside of it, we
  9343. // should *not* suspend the commit.
  9344. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  9345. _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
  9346. // But we shouldn't call any lifecycle methods or callbacks. Remove
  9347. // all lifecycle effect tags.
  9348. sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
  9349. if (sourceFiber.tag === ClassComponent) {
  9350. var currentSourceFiber = sourceFiber.alternate;
  9351. if (currentSourceFiber === null) {
  9352. // This is a new mount. Change the tag so it's not mistaken for a
  9353. // completed class component. For example, we should not call
  9354. // componentWillUnmount if it is deleted.
  9355. sourceFiber.tag = IncompleteClassComponent;
  9356. } else {
  9357. // When we try rendering again, we should not reuse the current fiber,
  9358. // since it's known to be in an inconsistent state. Use a force update to
  9359. // prevent a bail out.
  9360. var update = createUpdate(Sync, null);
  9361. update.tag = ForceUpdate;
  9362. enqueueUpdate(sourceFiber, update);
  9363. }
  9364. } // The source fiber did not complete. Mark it with Sync priority to
  9365. // indicate that it still has pending work.
  9366. sourceFiber.expirationTime = Sync; // Exit without suspending.
  9367. return;
  9368. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  9369. // with the normal suspend path.
  9370. //
  9371. // After this we'll use a set of heuristics to determine whether this
  9372. // render pass will run to completion or restart or "suspend" the commit.
  9373. // The actual logic for this is spread out in different places.
  9374. //
  9375. // This first principle is that if we're going to suspend when we complete
  9376. // a root, then we should also restart if we get an update or ping that
  9377. // might unsuspend it, and vice versa. The only reason to suspend is
  9378. // because you think you might want to restart before committing. However,
  9379. // it doesn't make sense to restart only while in the period we're suspended.
  9380. //
  9381. // Restarting too aggressively is also not good because it starves out any
  9382. // intermediate loading state. So we use heuristics to determine when.
  9383. // Suspense Heuristics
  9384. //
  9385. // If nothing threw a Promise or all the same fallbacks are already showing,
  9386. // then don't suspend/restart.
  9387. //
  9388. // If this is an initial render of a new tree of Suspense boundaries and
  9389. // those trigger a fallback, then don't suspend/restart. We want to ensure
  9390. // that we can show the initial loading state as quickly as possible.
  9391. //
  9392. // If we hit a "Delayed" case, such as when we'd switch from content back into
  9393. // a fallback, then we should always suspend/restart. SuspenseConfig applies to
  9394. // this case. If none is defined, JND is used instead.
  9395. //
  9396. // If we're already showing a fallback and it gets "retried", allowing us to show
  9397. // another level, but there's still an inner boundary that would show a fallback,
  9398. // then we suspend/restart for 500ms since the last time we showed a fallback
  9399. // anywhere in the tree. This effectively throttles progressive loading into a
  9400. // consistent train of commits. This also gives us an opportunity to restart to
  9401. // get to the completed state slightly earlier.
  9402. //
  9403. // If there's ambiguity due to batching it's resolved in preference of:
  9404. // 1) "delayed", 2) "initial render", 3) "retry".
  9405. //
  9406. // We want to ensure that a "busy" state doesn't get force committed. We want to
  9407. // ensure that new initial loading states can commit as soon as possible.
  9408. attachPingListener(root, renderExpirationTime, thenable);
  9409. _workInProgress.effectTag |= ShouldCapture;
  9410. _workInProgress.expirationTime = renderExpirationTime;
  9411. return;
  9412. } // This boundary already captured during this render. Continue to the next
  9413. // boundary.
  9414. _workInProgress = _workInProgress.return;
  9415. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  9416. // TODO: Use invariant so the message is stripped in prod?
  9417. 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));
  9418. } // We didn't find a boundary that could handle this type of exception. Start
  9419. // over and traverse parent path again, this time treating the exception
  9420. // as an error.
  9421. renderDidError();
  9422. value = createCapturedValue(value, sourceFiber);
  9423. var workInProgress = returnFiber;
  9424. do {
  9425. switch (workInProgress.tag) {
  9426. case HostRoot:
  9427. {
  9428. var _errorInfo = value;
  9429. workInProgress.effectTag |= ShouldCapture;
  9430. workInProgress.expirationTime = renderExpirationTime;
  9431. var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
  9432. enqueueCapturedUpdate(workInProgress, _update);
  9433. return;
  9434. }
  9435. case ClassComponent:
  9436. // Capture and retry
  9437. var errorInfo = value;
  9438. var ctor = workInProgress.type;
  9439. var instance = workInProgress.stateNode;
  9440. if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
  9441. workInProgress.effectTag |= ShouldCapture;
  9442. workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
  9443. var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
  9444. enqueueCapturedUpdate(workInProgress, _update2);
  9445. return;
  9446. }
  9447. break;
  9448. }
  9449. workInProgress = workInProgress.return;
  9450. } while (workInProgress !== null);
  9451. }
  9452. var ceil = Math.ceil;
  9453. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  9454. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  9455. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  9456. var NoContext =
  9457. /* */
  9458. 0;
  9459. var BatchedContext =
  9460. /* */
  9461. 1;
  9462. var DiscreteEventContext =
  9463. /* */
  9464. 4;
  9465. var LegacyUnbatchedContext =
  9466. /* */
  9467. 8;
  9468. var RenderContext =
  9469. /* */
  9470. 16;
  9471. var CommitContext =
  9472. /* */
  9473. 32;
  9474. var RootIncomplete = 0;
  9475. var RootFatalErrored = 1;
  9476. var RootErrored = 2;
  9477. var RootSuspended = 3;
  9478. var RootSuspendedWithDelay = 4;
  9479. var RootCompleted = 5;
  9480. // Describes where we are in the React execution stack
  9481. var executionContext = NoContext; // The root we're working on
  9482. var workInProgressRoot = null; // The fiber we're working on
  9483. var workInProgress = null; // The expiration time we're rendering
  9484. var renderExpirationTime$1 = NoWork; // Whether to root completed, errored, suspended, etc.
  9485. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  9486. var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
  9487. // This is conceptually a time stamp but expressed in terms of an ExpirationTime
  9488. // because we deal mostly with expiration times in the hot path, so this avoids
  9489. // the conversion happening in the hot path.
  9490. var workInProgressRootLatestProcessedExpirationTime = Sync;
  9491. var workInProgressRootLatestSuspenseTimeout = Sync;
  9492. var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
  9493. // includes unprocessed updates, not work in bailed out children.
  9494. var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
  9495. // This flag determines if it might be worthwhile to restart if an opportunity
  9496. // happens latere.
  9497. var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
  9498. // model where we don't commit new loading states in too quick succession.
  9499. var globalMostRecentFallbackTime = 0;
  9500. var FALLBACK_THROTTLE_MS = 500;
  9501. var nextEffect = null;
  9502. var hasUncaughtError = false;
  9503. var firstUncaughtError = null;
  9504. var legacyErrorBoundariesThatAlreadyFailed = null;
  9505. var rootDoesHavePassiveEffects = false;
  9506. var rootWithPendingPassiveEffects = null;
  9507. var pendingPassiveEffectsRenderPriority = NoPriority;
  9508. var pendingPassiveEffectsExpirationTime = NoWork;
  9509. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  9510. var NESTED_UPDATE_LIMIT = 50;
  9511. var nestedUpdateCount = 0;
  9512. var rootWithNestedUpdates = null;
  9513. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  9514. var nestedPassiveUpdateCount = 0;
  9515. var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
  9516. // during the commit phase. This enables them to be traced across components
  9517. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  9518. // hydration or SuspenseList.
  9519. var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
  9520. // time). However, if two updates are scheduled within the same event, we
  9521. // should treat their start times as simultaneous, even if the actual clock
  9522. // time has advanced between the first and second call.
  9523. // In other words, because expiration times determine how updates are batched,
  9524. // we want all updates of like priority that occur within the same event to
  9525. // receive the same expiration time. Otherwise we get tearing.
  9526. var currentEventTime = NoWork;
  9527. function requestCurrentTimeForUpdate() {
  9528. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  9529. // We're inside React, so it's fine to read the actual time.
  9530. return msToExpirationTime(now());
  9531. } // We're not inside React, so we may be in the middle of a browser event.
  9532. if (currentEventTime !== NoWork) {
  9533. // Use the same start time for all updates until we enter React again.
  9534. return currentEventTime;
  9535. } // This is the first update since React yielded. Compute a new start time.
  9536. currentEventTime = msToExpirationTime(now());
  9537. return currentEventTime;
  9538. }
  9539. function getCurrentTime() {
  9540. return msToExpirationTime(now());
  9541. }
  9542. function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
  9543. var mode = fiber.mode;
  9544. if ((mode & BlockingMode) === NoMode) {
  9545. return Sync;
  9546. }
  9547. var priorityLevel = getCurrentPriorityLevel();
  9548. if ((mode & ConcurrentMode) === NoMode) {
  9549. return priorityLevel === ImmediatePriority ? Sync : Batched;
  9550. }
  9551. if ((executionContext & RenderContext) !== NoContext) {
  9552. // Use whatever time we're already rendering
  9553. // TODO: Should there be a way to opt out, like with `runWithPriority`?
  9554. return renderExpirationTime$1;
  9555. }
  9556. var expirationTime;
  9557. if (suspenseConfig !== null) {
  9558. // Compute an expiration time based on the Suspense timeout.
  9559. expirationTime = computeSuspenseExpiration(currentTime, suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
  9560. } else {
  9561. // Compute an expiration time based on the Scheduler priority.
  9562. switch (priorityLevel) {
  9563. case ImmediatePriority:
  9564. expirationTime = Sync;
  9565. break;
  9566. case UserBlockingPriority:
  9567. // TODO: Rename this to computeUserBlockingExpiration
  9568. expirationTime = computeInteractiveExpiration(currentTime);
  9569. break;
  9570. case NormalPriority:
  9571. case LowPriority:
  9572. // TODO: Handle LowPriority
  9573. // TODO: Rename this to... something better.
  9574. expirationTime = computeAsyncExpiration(currentTime);
  9575. break;
  9576. case IdlePriority:
  9577. expirationTime = Idle;
  9578. break;
  9579. default:
  9580. {
  9581. {
  9582. throw Error( "Expected a valid priority level" );
  9583. }
  9584. }
  9585. }
  9586. } // If we're in the middle of rendering a tree, do not update at the same
  9587. // expiration time that is already rendering.
  9588. // TODO: We shouldn't have to do this if the update is on a different root.
  9589. // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
  9590. // the root when we check for this condition.
  9591. if (workInProgressRoot !== null && expirationTime === renderExpirationTime$1) {
  9592. // This is a trick to move this update into a separate batch
  9593. expirationTime -= 1;
  9594. }
  9595. return expirationTime;
  9596. }
  9597. function scheduleUpdateOnFiber(fiber, expirationTime) {
  9598. checkForNestedUpdates();
  9599. warnAboutRenderPhaseUpdatesInDEV(fiber);
  9600. var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
  9601. if (root === null) {
  9602. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  9603. return;
  9604. }
  9605. checkForInterruption(fiber, expirationTime);
  9606. recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
  9607. // priority as an argument to that function and this one.
  9608. var priorityLevel = getCurrentPriorityLevel();
  9609. if (expirationTime === Sync) {
  9610. if ( // Check if we're inside unbatchedUpdates
  9611. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  9612. (executionContext & (RenderContext | CommitContext)) === NoContext) {
  9613. // Register pending interactions on the root to avoid losing traced interaction data.
  9614. schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  9615. // root inside of batchedUpdates should be synchronous, but layout updates
  9616. // should be deferred until the end of the batch.
  9617. performSyncWorkOnRoot(root);
  9618. } else {
  9619. ensureRootIsScheduled(root);
  9620. schedulePendingInteractions(root, expirationTime);
  9621. if (executionContext === NoContext) {
  9622. // Flush the synchronous work now, unless we're already working or inside
  9623. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  9624. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  9625. // without immediately flushing it. We only do this for user-initiated
  9626. // updates, to preserve historical behavior of legacy mode.
  9627. flushSyncCallbackQueue();
  9628. }
  9629. }
  9630. } else {
  9631. ensureRootIsScheduled(root);
  9632. schedulePendingInteractions(root, expirationTime);
  9633. }
  9634. if ((executionContext & DiscreteEventContext) !== NoContext && ( // Only updates at user-blocking priority or greater are considered
  9635. // discrete, even inside a discrete event.
  9636. priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority)) {
  9637. // This is the result of a discrete event. Track the lowest priority
  9638. // discrete update per root so we can flush them early, if needed.
  9639. if (rootsWithPendingDiscreteUpdates === null) {
  9640. rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
  9641. } else {
  9642. var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
  9643. if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
  9644. rootsWithPendingDiscreteUpdates.set(root, expirationTime);
  9645. }
  9646. }
  9647. }
  9648. }
  9649. var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
  9650. // work without treating it as a typical update that originates from an event;
  9651. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  9652. // on a fiber.
  9653. function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
  9654. // Update the source fiber's expiration time
  9655. if (fiber.expirationTime < expirationTime) {
  9656. fiber.expirationTime = expirationTime;
  9657. }
  9658. var alternate = fiber.alternate;
  9659. if (alternate !== null && alternate.expirationTime < expirationTime) {
  9660. alternate.expirationTime = expirationTime;
  9661. } // Walk the parent path to the root and update the child expiration time.
  9662. var node = fiber.return;
  9663. var root = null;
  9664. if (node === null && fiber.tag === HostRoot) {
  9665. root = fiber.stateNode;
  9666. } else {
  9667. while (node !== null) {
  9668. alternate = node.alternate;
  9669. if (node.childExpirationTime < expirationTime) {
  9670. node.childExpirationTime = expirationTime;
  9671. if (alternate !== null && alternate.childExpirationTime < expirationTime) {
  9672. alternate.childExpirationTime = expirationTime;
  9673. }
  9674. } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
  9675. alternate.childExpirationTime = expirationTime;
  9676. }
  9677. if (node.return === null && node.tag === HostRoot) {
  9678. root = node.stateNode;
  9679. break;
  9680. }
  9681. node = node.return;
  9682. }
  9683. }
  9684. if (root !== null) {
  9685. if (workInProgressRoot === root) {
  9686. // Received an update to a tree that's in the middle of rendering. Mark
  9687. // that's unprocessed work on this root.
  9688. markUnprocessedUpdateTime(expirationTime);
  9689. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  9690. // The root already suspended with a delay, which means this render
  9691. // definitely won't finish. Since we have a new update, let's mark it as
  9692. // suspended now, right before marking the incoming update. This has the
  9693. // effect of interrupting the current render and switching to the update.
  9694. // TODO: This happens to work when receiving an update during the render
  9695. // phase, because of the trick inside computeExpirationForFiber to
  9696. // subtract 1 from `renderExpirationTime` to move it into a
  9697. // separate bucket. But we should probably model it with an exception,
  9698. // using the same mechanism we use to force hydration of a subtree.
  9699. // TODO: This does not account for low pri updates that were already
  9700. // scheduled before the root started rendering. Need to track the next
  9701. // pending expiration time (perhaps by backtracking the return path) and
  9702. // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
  9703. markRootSuspendedAtTime(root, renderExpirationTime$1);
  9704. }
  9705. } // Mark that the root has a pending update.
  9706. markRootUpdatedAtTime(root, expirationTime);
  9707. }
  9708. return root;
  9709. }
  9710. function getNextRootExpirationTimeToWorkOn(root) {
  9711. // Determines the next expiration time that the root should render, taking
  9712. // into account levels that may be suspended, or levels that may have
  9713. // received a ping.
  9714. var lastExpiredTime = root.lastExpiredTime;
  9715. if (lastExpiredTime !== NoWork) {
  9716. return lastExpiredTime;
  9717. } // "Pending" refers to any update that hasn't committed yet, including if it
  9718. // suspended. The "suspended" range is therefore a subset.
  9719. var firstPendingTime = root.firstPendingTime;
  9720. if (!isRootSuspendedAtTime(root, firstPendingTime)) {
  9721. // The highest priority pending time is not suspended. Let's work on that.
  9722. return firstPendingTime;
  9723. } // If the first pending time is suspended, check if there's a lower priority
  9724. // pending level that we know about. Or check if we received a ping. Work
  9725. // on whichever is higher priority.
  9726. var lastPingedTime = root.lastPingedTime;
  9727. var nextKnownPendingLevel = root.nextKnownPendingLevel;
  9728. var nextLevel = lastPingedTime > nextKnownPendingLevel ? lastPingedTime : nextKnownPendingLevel;
  9729. if ( nextLevel <= Idle && firstPendingTime !== nextLevel) {
  9730. // Don't work on Idle/Never priority unless everything else is committed.
  9731. return NoWork;
  9732. }
  9733. return nextLevel;
  9734. } // Use this function to schedule a task for a root. There's only one task per
  9735. // root; if a task was already scheduled, we'll check to make sure the
  9736. // expiration time of the existing task is the same as the expiration time of
  9737. // the next level that the root has work on. This function is called on every
  9738. // update, and right before exiting a task.
  9739. function ensureRootIsScheduled(root) {
  9740. var lastExpiredTime = root.lastExpiredTime;
  9741. if (lastExpiredTime !== NoWork) {
  9742. // Special case: Expired work should flush synchronously.
  9743. root.callbackExpirationTime = Sync;
  9744. root.callbackPriority = ImmediatePriority;
  9745. root.callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  9746. return;
  9747. }
  9748. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  9749. var existingCallbackNode = root.callbackNode;
  9750. if (expirationTime === NoWork) {
  9751. // There's nothing to work on.
  9752. if (existingCallbackNode !== null) {
  9753. root.callbackNode = null;
  9754. root.callbackExpirationTime = NoWork;
  9755. root.callbackPriority = NoPriority;
  9756. }
  9757. return;
  9758. } // TODO: If this is an update, we already read the current time. Pass the
  9759. // time as an argument.
  9760. var currentTime = requestCurrentTimeForUpdate();
  9761. var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime); // If there's an existing render task, confirm it has the correct priority and
  9762. // expiration time. Otherwise, we'll cancel it and schedule a new one.
  9763. if (existingCallbackNode !== null) {
  9764. var existingCallbackPriority = root.callbackPriority;
  9765. var existingCallbackExpirationTime = root.callbackExpirationTime;
  9766. if ( // Callback must have the exact same expiration time.
  9767. existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
  9768. existingCallbackPriority >= priorityLevel) {
  9769. // Existing callback is sufficient.
  9770. return;
  9771. } // Need to schedule a new task.
  9772. // TODO: Instead of scheduling a new task, we should be able to change the
  9773. // priority of the existing one.
  9774. cancelCallback(existingCallbackNode);
  9775. }
  9776. root.callbackExpirationTime = expirationTime;
  9777. root.callbackPriority = priorityLevel;
  9778. var callbackNode;
  9779. if (expirationTime === Sync) {
  9780. // Sync React callbacks are scheduled on a special internal queue
  9781. callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  9782. } else {
  9783. callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
  9784. // ordering because tasks are processed in timeout order.
  9785. {
  9786. timeout: expirationTimeToMs(expirationTime) - now()
  9787. });
  9788. }
  9789. root.callbackNode = callbackNode;
  9790. } // This is the entry point for every concurrent task, i.e. anything that
  9791. // goes through Scheduler.
  9792. function performConcurrentWorkOnRoot(root, didTimeout) {
  9793. // Since we know we're in a React event, we can clear the current
  9794. // event time. The next update will compute a new event time.
  9795. currentEventTime = NoWork;
  9796. if (didTimeout) {
  9797. // The render task took too long to complete. Mark the current time as
  9798. // expired to synchronously render all expired work in a single batch.
  9799. var currentTime = requestCurrentTimeForUpdate();
  9800. markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
  9801. ensureRootIsScheduled(root);
  9802. return null;
  9803. } // Determine the next expiration time to work on, using the fields stored
  9804. // on the root.
  9805. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  9806. if (expirationTime !== NoWork) {
  9807. var originalCallbackNode = root.callbackNode;
  9808. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  9809. {
  9810. throw Error( "Should not already be working." );
  9811. }
  9812. }
  9813. flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
  9814. // and prepare a fresh one. Otherwise we'll continue where we left off.
  9815. if (root !== workInProgressRoot || expirationTime !== renderExpirationTime$1) {
  9816. prepareFreshStack(root, expirationTime);
  9817. startWorkOnPendingInteractions(root, expirationTime);
  9818. } // If we have a work-in-progress fiber, it means there's still work to do
  9819. // in this root.
  9820. if (workInProgress !== null) {
  9821. var prevExecutionContext = executionContext;
  9822. executionContext |= RenderContext;
  9823. var prevDispatcher = pushDispatcher();
  9824. var prevInteractions = pushInteractions(root);
  9825. startWorkLoopTimer(workInProgress);
  9826. do {
  9827. try {
  9828. workLoopConcurrent();
  9829. break;
  9830. } catch (thrownValue) {
  9831. handleError(root, thrownValue);
  9832. }
  9833. } while (true);
  9834. resetContextDependencies();
  9835. executionContext = prevExecutionContext;
  9836. popDispatcher(prevDispatcher);
  9837. {
  9838. popInteractions(prevInteractions);
  9839. }
  9840. if (workInProgressRootExitStatus === RootFatalErrored) {
  9841. var fatalError = workInProgressRootFatalError;
  9842. stopInterruptedWorkLoopTimer();
  9843. prepareFreshStack(root, expirationTime);
  9844. markRootSuspendedAtTime(root, expirationTime);
  9845. ensureRootIsScheduled(root);
  9846. throw fatalError;
  9847. }
  9848. if (workInProgress !== null) {
  9849. // There's still work left over. Exit without committing.
  9850. stopInterruptedWorkLoopTimer();
  9851. } else {
  9852. // We now have a consistent tree. The next step is either to commit it,
  9853. // or, if something suspended, wait to commit it after a timeout.
  9854. stopFinishedWorkLoopTimer();
  9855. var finishedWork = root.finishedWork = root.current.alternate;
  9856. root.finishedExpirationTime = expirationTime;
  9857. finishConcurrentRender(root, finishedWork, workInProgressRootExitStatus, expirationTime);
  9858. }
  9859. ensureRootIsScheduled(root);
  9860. if (root.callbackNode === originalCallbackNode) {
  9861. // The task node scheduled for this root is the same one that's
  9862. // currently executed. Need to return a continuation.
  9863. return performConcurrentWorkOnRoot.bind(null, root);
  9864. }
  9865. }
  9866. }
  9867. return null;
  9868. }
  9869. function finishConcurrentRender(root, finishedWork, exitStatus, expirationTime) {
  9870. // Set this to null to indicate there's no in-progress render.
  9871. workInProgressRoot = null;
  9872. switch (exitStatus) {
  9873. case RootIncomplete:
  9874. case RootFatalErrored:
  9875. {
  9876. {
  9877. {
  9878. throw Error( "Root did not complete. This is a bug in React." );
  9879. }
  9880. }
  9881. }
  9882. // Flow knows about invariant, so it complains if I add a break
  9883. // statement, but eslint doesn't know about invariant, so it complains
  9884. // if I do. eslint-disable-next-line no-fallthrough
  9885. case RootErrored:
  9886. {
  9887. // If this was an async render, the error may have happened due to
  9888. // a mutation in a concurrent event. Try rendering one more time,
  9889. // synchronously, to see if the error goes away. If there are
  9890. // lower priority updates, let's include those, too, in case they
  9891. // fix the inconsistency. Render at Idle to include all updates.
  9892. // If it was Idle or Never or some not-yet-invented time, render
  9893. // at that time.
  9894. markRootExpiredAtTime(root, expirationTime > Idle ? Idle : expirationTime); // We assume that this second render pass will be synchronous
  9895. // and therefore not hit this path again.
  9896. break;
  9897. }
  9898. case RootSuspended:
  9899. {
  9900. markRootSuspendedAtTime(root, expirationTime);
  9901. var lastSuspendedTime = root.lastSuspendedTime;
  9902. if (expirationTime === lastSuspendedTime) {
  9903. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  9904. } // We have an acceptable loading state. We need to figure out if we
  9905. // should immediately commit it or wait a bit.
  9906. // If we have processed new updates during this render, we may now
  9907. // have a new loading state ready. We want to ensure that we commit
  9908. // that as soon as possible.
  9909. var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync;
  9910. if (hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
  9911. !( IsThisRendererActing.current)) {
  9912. // If we have not processed any new updates during this pass, then
  9913. // this is either a retry of an existing fallback state or a
  9914. // hidden tree. Hidden trees shouldn't be batched with other work
  9915. // and after that's fixed it can only be a retry. We're going to
  9916. // throttle committing retries so that we don't show too many
  9917. // loading states too quickly.
  9918. var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  9919. if (msUntilTimeout > 10) {
  9920. if (workInProgressRootHasPendingPing) {
  9921. var lastPingedTime = root.lastPingedTime;
  9922. if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
  9923. // This render was pinged but we didn't get to restart
  9924. // earlier so try restarting now instead.
  9925. root.lastPingedTime = expirationTime;
  9926. prepareFreshStack(root, expirationTime);
  9927. break;
  9928. }
  9929. }
  9930. var nextTime = getNextRootExpirationTimeToWorkOn(root);
  9931. if (nextTime !== NoWork && nextTime !== expirationTime) {
  9932. // There's additional work on this root.
  9933. break;
  9934. }
  9935. if (lastSuspendedTime !== NoWork && lastSuspendedTime !== expirationTime) {
  9936. // We should prefer to render the fallback of at the last
  9937. // suspended level. Ping the last suspended level to try
  9938. // rendering it again.
  9939. root.lastPingedTime = lastSuspendedTime;
  9940. break;
  9941. } // The render is suspended, it hasn't timed out, and there's no
  9942. // lower priority work to do. Instead of committing the fallback
  9943. // immediately, wait for more data to arrive.
  9944. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), msUntilTimeout);
  9945. break;
  9946. }
  9947. } // The work expired. Commit immediately.
  9948. commitRoot(root);
  9949. break;
  9950. }
  9951. case RootSuspendedWithDelay:
  9952. {
  9953. markRootSuspendedAtTime(root, expirationTime);
  9954. var _lastSuspendedTime = root.lastSuspendedTime;
  9955. if (expirationTime === _lastSuspendedTime) {
  9956. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  9957. }
  9958. if ( // do not delay if we're inside an act() scope
  9959. !( IsThisRendererActing.current)) {
  9960. // We're suspended in a state that should be avoided. We'll try to
  9961. // avoid committing it for as long as the timeouts let us.
  9962. if (workInProgressRootHasPendingPing) {
  9963. var _lastPingedTime = root.lastPingedTime;
  9964. if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
  9965. // This render was pinged but we didn't get to restart earlier
  9966. // so try restarting now instead.
  9967. root.lastPingedTime = expirationTime;
  9968. prepareFreshStack(root, expirationTime);
  9969. break;
  9970. }
  9971. }
  9972. var _nextTime = getNextRootExpirationTimeToWorkOn(root);
  9973. if (_nextTime !== NoWork && _nextTime !== expirationTime) {
  9974. // There's additional work on this root.
  9975. break;
  9976. }
  9977. if (_lastSuspendedTime !== NoWork && _lastSuspendedTime !== expirationTime) {
  9978. // We should prefer to render the fallback of at the last
  9979. // suspended level. Ping the last suspended level to try
  9980. // rendering it again.
  9981. root.lastPingedTime = _lastSuspendedTime;
  9982. break;
  9983. }
  9984. var _msUntilTimeout;
  9985. if (workInProgressRootLatestSuspenseTimeout !== Sync) {
  9986. // We have processed a suspense config whose expiration time we
  9987. // can use as the timeout.
  9988. _msUntilTimeout = expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
  9989. } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
  9990. // This should never normally happen because only new updates
  9991. // cause delayed states, so we should have processed something.
  9992. // However, this could also happen in an offscreen tree.
  9993. _msUntilTimeout = 0;
  9994. } else {
  9995. // If we don't have a suspense config, we're going to use a
  9996. // heuristic to determine how long we can suspend.
  9997. var eventTimeMs = inferTimeFromExpirationTime(workInProgressRootLatestProcessedExpirationTime);
  9998. var currentTimeMs = now();
  9999. var timeUntilExpirationMs = expirationTimeToMs(expirationTime) - currentTimeMs;
  10000. var timeElapsed = currentTimeMs - eventTimeMs;
  10001. if (timeElapsed < 0) {
  10002. // We get this wrong some time since we estimate the time.
  10003. timeElapsed = 0;
  10004. }
  10005. _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
  10006. // event time is exact instead of inferred from expiration time
  10007. // we don't need this.
  10008. if (timeUntilExpirationMs < _msUntilTimeout) {
  10009. _msUntilTimeout = timeUntilExpirationMs;
  10010. }
  10011. } // Don't bother with a very short suspense time.
  10012. if (_msUntilTimeout > 10) {
  10013. // The render is suspended, it hasn't timed out, and there's no
  10014. // lower priority work to do. Instead of committing the fallback
  10015. // immediately, wait for more data to arrive.
  10016. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout);
  10017. break;
  10018. }
  10019. } // The work expired. Commit immediately.
  10020. commitRoot(root);
  10021. break;
  10022. }
  10023. case RootCompleted:
  10024. {
  10025. // The work completed. Ready to commit.
  10026. if ( // do not delay if we're inside an act() scope
  10027. !( IsThisRendererActing.current) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null) {
  10028. // If we have exceeded the minimum loading delay, which probably
  10029. // means we have shown a spinner already, we might have to suspend
  10030. // a bit longer to ensure that the spinner is shown for
  10031. // enough time.
  10032. var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(workInProgressRootLatestProcessedExpirationTime, expirationTime, workInProgressRootCanSuspendUsingConfig);
  10033. if (_msUntilTimeout2 > 10) {
  10034. markRootSuspendedAtTime(root, expirationTime);
  10035. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout2);
  10036. break;
  10037. }
  10038. }
  10039. commitRoot(root);
  10040. break;
  10041. }
  10042. default:
  10043. {
  10044. {
  10045. {
  10046. throw Error( "Unknown root exit status." );
  10047. }
  10048. }
  10049. }
  10050. }
  10051. } // This is the entry point for synchronous tasks that don't go
  10052. // through Scheduler
  10053. function performSyncWorkOnRoot(root) {
  10054. // Check if there's expired work on this root. Otherwise, render at Sync.
  10055. var lastExpiredTime = root.lastExpiredTime;
  10056. var expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync;
  10057. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  10058. {
  10059. throw Error( "Should not already be working." );
  10060. }
  10061. }
  10062. flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
  10063. // and prepare a fresh one. Otherwise we'll continue where we left off.
  10064. if (root !== workInProgressRoot || expirationTime !== renderExpirationTime$1) {
  10065. prepareFreshStack(root, expirationTime);
  10066. startWorkOnPendingInteractions(root, expirationTime);
  10067. } // If we have a work-in-progress fiber, it means there's still work to do
  10068. // in this root.
  10069. if (workInProgress !== null) {
  10070. var prevExecutionContext = executionContext;
  10071. executionContext |= RenderContext;
  10072. var prevDispatcher = pushDispatcher();
  10073. var prevInteractions = pushInteractions(root);
  10074. startWorkLoopTimer(workInProgress);
  10075. do {
  10076. try {
  10077. workLoopSync();
  10078. break;
  10079. } catch (thrownValue) {
  10080. handleError(root, thrownValue);
  10081. }
  10082. } while (true);
  10083. resetContextDependencies();
  10084. executionContext = prevExecutionContext;
  10085. popDispatcher(prevDispatcher);
  10086. {
  10087. popInteractions(prevInteractions);
  10088. }
  10089. if (workInProgressRootExitStatus === RootFatalErrored) {
  10090. var fatalError = workInProgressRootFatalError;
  10091. stopInterruptedWorkLoopTimer();
  10092. prepareFreshStack(root, expirationTime);
  10093. markRootSuspendedAtTime(root, expirationTime);
  10094. ensureRootIsScheduled(root);
  10095. throw fatalError;
  10096. }
  10097. if (workInProgress !== null) {
  10098. // This is a sync render, so we should have finished the whole tree.
  10099. {
  10100. {
  10101. throw Error( "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." );
  10102. }
  10103. }
  10104. } else {
  10105. // We now have a consistent tree. Because this is a sync render, we
  10106. // will commit it even if something suspended.
  10107. stopFinishedWorkLoopTimer();
  10108. root.finishedWork = root.current.alternate;
  10109. root.finishedExpirationTime = expirationTime;
  10110. finishSyncRender(root);
  10111. } // Before exiting, make sure there's a callback scheduled for the next
  10112. // pending level.
  10113. ensureRootIsScheduled(root);
  10114. }
  10115. return null;
  10116. }
  10117. function finishSyncRender(root) {
  10118. // Set this to null to indicate there's no in-progress render.
  10119. workInProgressRoot = null;
  10120. commitRoot(root);
  10121. }
  10122. function syncUpdates(fn, a, b, c) {
  10123. return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
  10124. }
  10125. function batchedUpdates(fn, a) {
  10126. var prevExecutionContext = executionContext;
  10127. executionContext |= BatchedContext;
  10128. try {
  10129. return fn(a);
  10130. } finally {
  10131. executionContext = prevExecutionContext;
  10132. if (executionContext === NoContext) {
  10133. // Flush the immediate callbacks that were scheduled during this batch
  10134. flushSyncCallbackQueue();
  10135. }
  10136. }
  10137. }
  10138. function flushSync(fn, a) {
  10139. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  10140. {
  10141. {
  10142. throw Error( "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." );
  10143. }
  10144. }
  10145. }
  10146. var prevExecutionContext = executionContext;
  10147. executionContext |= BatchedContext;
  10148. try {
  10149. return runWithPriority(ImmediatePriority, fn.bind(null, a));
  10150. } finally {
  10151. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  10152. // Note that this will happen even if batchedUpdates is higher up
  10153. // the stack.
  10154. flushSyncCallbackQueue();
  10155. }
  10156. }
  10157. function prepareFreshStack(root, expirationTime) {
  10158. root.finishedWork = null;
  10159. root.finishedExpirationTime = NoWork;
  10160. var timeoutHandle = root.timeoutHandle;
  10161. if (timeoutHandle !== noTimeout) {
  10162. // The root previous suspended and scheduled a timeout to commit a fallback
  10163. // state. Now that we have additional work, cancel the timeout.
  10164. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  10165. cancelTimeout(timeoutHandle);
  10166. }
  10167. if (workInProgress !== null) {
  10168. var interruptedWork = workInProgress.return;
  10169. while (interruptedWork !== null) {
  10170. unwindInterruptedWork(interruptedWork);
  10171. interruptedWork = interruptedWork.return;
  10172. }
  10173. }
  10174. workInProgressRoot = root;
  10175. workInProgress = createWorkInProgress(root.current, null);
  10176. renderExpirationTime$1 = expirationTime;
  10177. workInProgressRootExitStatus = RootIncomplete;
  10178. workInProgressRootFatalError = null;
  10179. workInProgressRootLatestProcessedExpirationTime = Sync;
  10180. workInProgressRootLatestSuspenseTimeout = Sync;
  10181. workInProgressRootCanSuspendUsingConfig = null;
  10182. workInProgressRootNextUnprocessedUpdateTime = NoWork;
  10183. workInProgressRootHasPendingPing = false;
  10184. {
  10185. spawnedWorkDuringRender = null;
  10186. }
  10187. {
  10188. ReactStrictModeWarnings.discardPendingWarnings();
  10189. }
  10190. }
  10191. function handleError(root, thrownValue) {
  10192. do {
  10193. try {
  10194. // Reset module-level state that was set during the render phase.
  10195. resetContextDependencies();
  10196. resetHooksAfterThrow();
  10197. resetCurrentFiber();
  10198. if (workInProgress === null || workInProgress.return === null) {
  10199. // Expected to be working on a non-root fiber. This is a fatal error
  10200. // because there's no ancestor that can handle it; the root is
  10201. // supposed to capture all errors that weren't caught by an error
  10202. // boundary.
  10203. workInProgressRootExitStatus = RootFatalErrored;
  10204. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  10205. // sibling, or the parent if there are no siblings. But since the root
  10206. // has no siblings nor a parent, we set it to null. Usually this is
  10207. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  10208. // interntionally not calling those, we need set it here.
  10209. // TODO: Consider calling `unwindWork` to pop the contexts.
  10210. workInProgress = null;
  10211. return null;
  10212. }
  10213. if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
  10214. // Record the time spent rendering before an error was thrown. This
  10215. // avoids inaccurate Profiler durations in the case of a
  10216. // suspended render.
  10217. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
  10218. }
  10219. throwException(root, workInProgress.return, workInProgress, thrownValue, renderExpirationTime$1);
  10220. workInProgress = completeUnitOfWork(workInProgress);
  10221. } catch (yetAnotherThrownValue) {
  10222. // Something in the return path also threw.
  10223. thrownValue = yetAnotherThrownValue;
  10224. continue;
  10225. } // Return to the normal work loop.
  10226. return;
  10227. } while (true);
  10228. }
  10229. function pushDispatcher(root) {
  10230. var prevDispatcher = ReactCurrentDispatcher$1.current;
  10231. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  10232. if (prevDispatcher === null) {
  10233. // The React isomorphic package does not include a default dispatcher.
  10234. // Instead the first renderer will lazily attach one, in order to give
  10235. // nicer error messages.
  10236. return ContextOnlyDispatcher;
  10237. } else {
  10238. return prevDispatcher;
  10239. }
  10240. }
  10241. function popDispatcher(prevDispatcher) {
  10242. ReactCurrentDispatcher$1.current = prevDispatcher;
  10243. }
  10244. function pushInteractions(root) {
  10245. {
  10246. var prevInteractions = tracing.__interactionsRef.current;
  10247. tracing.__interactionsRef.current = root.memoizedInteractions;
  10248. return prevInteractions;
  10249. }
  10250. }
  10251. function popInteractions(prevInteractions) {
  10252. {
  10253. tracing.__interactionsRef.current = prevInteractions;
  10254. }
  10255. }
  10256. function markCommitTimeOfFallback() {
  10257. globalMostRecentFallbackTime = now();
  10258. }
  10259. function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
  10260. if (expirationTime < workInProgressRootLatestProcessedExpirationTime && expirationTime > Idle) {
  10261. workInProgressRootLatestProcessedExpirationTime = expirationTime;
  10262. }
  10263. if (suspenseConfig !== null) {
  10264. if (expirationTime < workInProgressRootLatestSuspenseTimeout && expirationTime > Idle) {
  10265. workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
  10266. workInProgressRootCanSuspendUsingConfig = suspenseConfig;
  10267. }
  10268. }
  10269. }
  10270. function markUnprocessedUpdateTime(expirationTime) {
  10271. if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
  10272. workInProgressRootNextUnprocessedUpdateTime = expirationTime;
  10273. }
  10274. }
  10275. function renderDidSuspend() {
  10276. if (workInProgressRootExitStatus === RootIncomplete) {
  10277. workInProgressRootExitStatus = RootSuspended;
  10278. }
  10279. }
  10280. function renderDidSuspendDelayIfPossible() {
  10281. if (workInProgressRootExitStatus === RootIncomplete || workInProgressRootExitStatus === RootSuspended) {
  10282. workInProgressRootExitStatus = RootSuspendedWithDelay;
  10283. } // Check if there's a lower priority update somewhere else in the tree.
  10284. if (workInProgressRootNextUnprocessedUpdateTime !== NoWork && workInProgressRoot !== null) {
  10285. // Mark the current render as suspended, and then mark that there's a
  10286. // pending update.
  10287. // TODO: This should immediately interrupt the current render, instead
  10288. // of waiting until the next time we yield.
  10289. markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime$1);
  10290. markRootUpdatedAtTime(workInProgressRoot, workInProgressRootNextUnprocessedUpdateTime);
  10291. }
  10292. }
  10293. function renderDidError() {
  10294. if (workInProgressRootExitStatus !== RootCompleted) {
  10295. workInProgressRootExitStatus = RootErrored;
  10296. }
  10297. } // Called during render to determine if anything has suspended.
  10298. // Returns false if we're not sure.
  10299. function renderHasNotSuspendedYet() {
  10300. // If something errored or completed, we can't really be sure,
  10301. // so those are false.
  10302. return workInProgressRootExitStatus === RootIncomplete;
  10303. }
  10304. function inferTimeFromExpirationTime(expirationTime) {
  10305. // We don't know exactly when the update was scheduled, but we can infer an
  10306. // approximate start time from the expiration time.
  10307. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  10308. return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
  10309. }
  10310. function inferTimeFromExpirationTimeWithSuspenseConfig(expirationTime, suspenseConfig) {
  10311. // We don't know exactly when the update was scheduled, but we can infer an
  10312. // approximate start time from the expiration time by subtracting the timeout
  10313. // that was added to the event time.
  10314. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  10315. return earliestExpirationTimeMs - (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
  10316. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  10317. /** @noinline */
  10318. function workLoopSync() {
  10319. // Already timed out, so perform work without checking if we need to yield.
  10320. while (workInProgress !== null) {
  10321. workInProgress = performUnitOfWork(workInProgress);
  10322. }
  10323. }
  10324. /** @noinline */
  10325. function workLoopConcurrent() {
  10326. // Perform work until Scheduler asks us to yield
  10327. while (workInProgress !== null && !shouldYield()) {
  10328. workInProgress = performUnitOfWork(workInProgress);
  10329. }
  10330. }
  10331. function performUnitOfWork(unitOfWork) {
  10332. // The current, flushed, state of this fiber is the alternate. Ideally
  10333. // nothing should rely on this, but relying on it here means that we don't
  10334. // need an additional field on the work in progress.
  10335. var current = unitOfWork.alternate;
  10336. startWorkTimer(unitOfWork);
  10337. setCurrentFiber(unitOfWork);
  10338. var next;
  10339. if ( (unitOfWork.mode & ProfileMode) !== NoMode) {
  10340. startProfilerTimer(unitOfWork);
  10341. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  10342. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  10343. } else {
  10344. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  10345. }
  10346. resetCurrentFiber();
  10347. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  10348. if (next === null) {
  10349. // If this doesn't spawn new work, complete the current work.
  10350. next = completeUnitOfWork(unitOfWork);
  10351. }
  10352. ReactCurrentOwner$2.current = null;
  10353. return next;
  10354. }
  10355. function completeUnitOfWork(unitOfWork) {
  10356. // Attempt to complete the current unit of work, then move to the next
  10357. // sibling. If there are no more siblings, return to the parent fiber.
  10358. workInProgress = unitOfWork;
  10359. do {
  10360. // The current, flushed, state of this fiber is the alternate. Ideally
  10361. // nothing should rely on this, but relying on it here means that we don't
  10362. // need an additional field on the work in progress.
  10363. var current = workInProgress.alternate;
  10364. var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
  10365. if ((workInProgress.effectTag & Incomplete) === NoEffect) {
  10366. setCurrentFiber(workInProgress);
  10367. var next = void 0;
  10368. if ( (workInProgress.mode & ProfileMode) === NoMode) {
  10369. next = completeWork(current, workInProgress, renderExpirationTime$1);
  10370. } else {
  10371. startProfilerTimer(workInProgress);
  10372. next = completeWork(current, workInProgress, renderExpirationTime$1); // Update render duration assuming we didn't error.
  10373. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
  10374. }
  10375. stopWorkTimer(workInProgress);
  10376. resetCurrentFiber();
  10377. resetChildExpirationTime(workInProgress);
  10378. if (next !== null) {
  10379. // Completing this fiber spawned new work. Work on that next.
  10380. return next;
  10381. }
  10382. if (returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  10383. (returnFiber.effectTag & Incomplete) === NoEffect) {
  10384. // Append all the effects of the subtree and this fiber onto the effect
  10385. // list of the parent. The completion order of the children affects the
  10386. // side-effect order.
  10387. if (returnFiber.firstEffect === null) {
  10388. returnFiber.firstEffect = workInProgress.firstEffect;
  10389. }
  10390. if (workInProgress.lastEffect !== null) {
  10391. if (returnFiber.lastEffect !== null) {
  10392. returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
  10393. }
  10394. returnFiber.lastEffect = workInProgress.lastEffect;
  10395. } // If this fiber had side-effects, we append it AFTER the children's
  10396. // side-effects. We can perform certain side-effects earlier if needed,
  10397. // by doing multiple passes over the effect list. We don't want to
  10398. // schedule our own side-effect on our own list because if end up
  10399. // reusing children we'll schedule this effect onto itself since we're
  10400. // at the end.
  10401. var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
  10402. // list. PerformedWork effect is read by React DevTools but shouldn't be
  10403. // committed.
  10404. if (effectTag > PerformedWork) {
  10405. if (returnFiber.lastEffect !== null) {
  10406. returnFiber.lastEffect.nextEffect = workInProgress;
  10407. } else {
  10408. returnFiber.firstEffect = workInProgress;
  10409. }
  10410. returnFiber.lastEffect = workInProgress;
  10411. }
  10412. }
  10413. } else {
  10414. // This fiber did not complete because something threw. Pop values off
  10415. // the stack without entering the complete phase. If this is a boundary,
  10416. // capture values if possible.
  10417. var _next = unwindWork(workInProgress); // Because this fiber did not complete, don't reset its expiration time.
  10418. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  10419. // Record the render duration for the fiber that errored.
  10420. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
  10421. var actualDuration = workInProgress.actualDuration;
  10422. var child = workInProgress.child;
  10423. while (child !== null) {
  10424. actualDuration += child.actualDuration;
  10425. child = child.sibling;
  10426. }
  10427. workInProgress.actualDuration = actualDuration;
  10428. }
  10429. if (_next !== null) {
  10430. // If completing this work spawned new work, do that next. We'll come
  10431. // back here again.
  10432. // Since we're restarting, remove anything that is not a host effect
  10433. // from the effect tag.
  10434. // TODO: The name stopFailedWorkTimer is misleading because Suspense
  10435. // also captures and restarts.
  10436. stopFailedWorkTimer(workInProgress);
  10437. _next.effectTag &= HostEffectMask;
  10438. return _next;
  10439. }
  10440. stopWorkTimer(workInProgress);
  10441. if (returnFiber !== null) {
  10442. // Mark the parent fiber as incomplete and clear its effect list.
  10443. returnFiber.firstEffect = returnFiber.lastEffect = null;
  10444. returnFiber.effectTag |= Incomplete;
  10445. }
  10446. }
  10447. var siblingFiber = workInProgress.sibling;
  10448. if (siblingFiber !== null) {
  10449. // If there is more work to do in this returnFiber, do that next.
  10450. return siblingFiber;
  10451. } // Otherwise, return to the parent
  10452. workInProgress = returnFiber;
  10453. } while (workInProgress !== null); // We've reached the root.
  10454. if (workInProgressRootExitStatus === RootIncomplete) {
  10455. workInProgressRootExitStatus = RootCompleted;
  10456. }
  10457. return null;
  10458. }
  10459. function getRemainingExpirationTime(fiber) {
  10460. var updateExpirationTime = fiber.expirationTime;
  10461. var childExpirationTime = fiber.childExpirationTime;
  10462. return updateExpirationTime > childExpirationTime ? updateExpirationTime : childExpirationTime;
  10463. }
  10464. function resetChildExpirationTime(completedWork) {
  10465. if (renderExpirationTime$1 !== Never && completedWork.childExpirationTime === Never) {
  10466. // The children of this component are hidden. Don't bubble their
  10467. // expiration times.
  10468. return;
  10469. }
  10470. var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
  10471. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  10472. // In profiling mode, resetChildExpirationTime is also used to reset
  10473. // profiler durations.
  10474. var actualDuration = completedWork.actualDuration;
  10475. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  10476. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  10477. // When work is done, it should bubble to the parent's actualDuration. If
  10478. // the fiber has not been cloned though, (meaning no work was done), then
  10479. // this value will reflect the amount of time spent working on a previous
  10480. // render. In that case it should not bubble. We determine whether it was
  10481. // cloned by comparing the child pointer.
  10482. var shouldBubbleActualDurations = completedWork.alternate === null || completedWork.child !== completedWork.alternate.child;
  10483. var child = completedWork.child;
  10484. while (child !== null) {
  10485. var childUpdateExpirationTime = child.expirationTime;
  10486. var childChildExpirationTime = child.childExpirationTime;
  10487. if (childUpdateExpirationTime > newChildExpirationTime) {
  10488. newChildExpirationTime = childUpdateExpirationTime;
  10489. }
  10490. if (childChildExpirationTime > newChildExpirationTime) {
  10491. newChildExpirationTime = childChildExpirationTime;
  10492. }
  10493. if (shouldBubbleActualDurations) {
  10494. actualDuration += child.actualDuration;
  10495. }
  10496. treeBaseDuration += child.treeBaseDuration;
  10497. child = child.sibling;
  10498. }
  10499. completedWork.actualDuration = actualDuration;
  10500. completedWork.treeBaseDuration = treeBaseDuration;
  10501. } else {
  10502. var _child = completedWork.child;
  10503. while (_child !== null) {
  10504. var _childUpdateExpirationTime = _child.expirationTime;
  10505. var _childChildExpirationTime = _child.childExpirationTime;
  10506. if (_childUpdateExpirationTime > newChildExpirationTime) {
  10507. newChildExpirationTime = _childUpdateExpirationTime;
  10508. }
  10509. if (_childChildExpirationTime > newChildExpirationTime) {
  10510. newChildExpirationTime = _childChildExpirationTime;
  10511. }
  10512. _child = _child.sibling;
  10513. }
  10514. }
  10515. completedWork.childExpirationTime = newChildExpirationTime;
  10516. }
  10517. function commitRoot(root) {
  10518. var renderPriorityLevel = getCurrentPriorityLevel();
  10519. runWithPriority(ImmediatePriority, commitRootImpl.bind(null, root, renderPriorityLevel));
  10520. return null;
  10521. }
  10522. function commitRootImpl(root, renderPriorityLevel) {
  10523. do {
  10524. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  10525. // means `flushPassiveEffects` will sometimes result in additional
  10526. // passive effects. So we need to keep flushing in a loop until there are
  10527. // no more pending effects.
  10528. // TODO: Might be better if `flushPassiveEffects` did not automatically
  10529. // flush synchronous work at the end, to avoid factoring hazards like this.
  10530. flushPassiveEffects();
  10531. } while (rootWithPendingPassiveEffects !== null);
  10532. flushRenderPhaseStrictModeWarningsInDEV();
  10533. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  10534. {
  10535. throw Error( "Should not already be working." );
  10536. }
  10537. }
  10538. var finishedWork = root.finishedWork;
  10539. var expirationTime = root.finishedExpirationTime;
  10540. if (finishedWork === null) {
  10541. return null;
  10542. }
  10543. root.finishedWork = null;
  10544. root.finishedExpirationTime = NoWork;
  10545. if (!(finishedWork !== root.current)) {
  10546. {
  10547. throw Error( "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue." );
  10548. }
  10549. } // commitRoot never returns a continuation; it always finishes synchronously.
  10550. // So we can clear these now to allow a new callback to be scheduled.
  10551. root.callbackNode = null;
  10552. root.callbackExpirationTime = NoWork;
  10553. root.callbackPriority = NoPriority;
  10554. root.nextKnownPendingLevel = NoWork;
  10555. startCommitTimer(); // Update the first and last pending times on this root. The new first
  10556. // pending time is whatever is left on the root fiber.
  10557. var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(finishedWork);
  10558. markRootFinishedAtTime(root, expirationTime, remainingExpirationTimeBeforeCommit);
  10559. if (root === workInProgressRoot) {
  10560. // We can reset these now that they are finished.
  10561. workInProgressRoot = null;
  10562. workInProgress = null;
  10563. renderExpirationTime$1 = NoWork;
  10564. } // This indicates that the last root we worked on is not the same one that
  10565. // we're committing now. This most commonly happens when a suspended root
  10566. // times out.
  10567. // Get the list of effects.
  10568. var firstEffect;
  10569. if (finishedWork.effectTag > PerformedWork) {
  10570. // A fiber's effect list consists only of its children, not itself. So if
  10571. // the root has an effect, we need to add it to the end of the list. The
  10572. // resulting list is the set that would belong to the root's parent, if it
  10573. // had one; that is, all the effects in the tree including the root.
  10574. if (finishedWork.lastEffect !== null) {
  10575. finishedWork.lastEffect.nextEffect = finishedWork;
  10576. firstEffect = finishedWork.firstEffect;
  10577. } else {
  10578. firstEffect = finishedWork;
  10579. }
  10580. } else {
  10581. // There is no effect on the root.
  10582. firstEffect = finishedWork.firstEffect;
  10583. }
  10584. if (firstEffect !== null) {
  10585. var prevExecutionContext = executionContext;
  10586. executionContext |= CommitContext;
  10587. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  10588. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  10589. // of the effect list for each phase: all mutation effects come before all
  10590. // layout effects, and so on.
  10591. // The first phase a "before mutation" phase. We use this phase to read the
  10592. // state of the host tree right before we mutate it. This is where
  10593. // getSnapshotBeforeUpdate is called.
  10594. startCommitSnapshotEffectsTimer();
  10595. prepareForCommit(root.containerInfo);
  10596. nextEffect = firstEffect;
  10597. do {
  10598. {
  10599. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  10600. if (hasCaughtError()) {
  10601. if (!(nextEffect !== null)) {
  10602. {
  10603. throw Error( "Should be working on an effect." );
  10604. }
  10605. }
  10606. var error = clearCaughtError();
  10607. captureCommitPhaseError(nextEffect, error);
  10608. nextEffect = nextEffect.nextEffect;
  10609. }
  10610. }
  10611. } while (nextEffect !== null);
  10612. stopCommitSnapshotEffectsTimer();
  10613. {
  10614. // Mark the current commit time to be shared by all Profilers in this
  10615. // batch. This enables them to be grouped later.
  10616. recordCommitTime();
  10617. } // The next phase is the mutation phase, where we mutate the host tree.
  10618. startCommitHostEffectsTimer();
  10619. nextEffect = firstEffect;
  10620. do {
  10621. {
  10622. invokeGuardedCallback(null, commitMutationEffects, null, root, renderPriorityLevel);
  10623. if (hasCaughtError()) {
  10624. if (!(nextEffect !== null)) {
  10625. {
  10626. throw Error( "Should be working on an effect." );
  10627. }
  10628. }
  10629. var _error = clearCaughtError();
  10630. captureCommitPhaseError(nextEffect, _error);
  10631. nextEffect = nextEffect.nextEffect;
  10632. }
  10633. }
  10634. } while (nextEffect !== null);
  10635. stopCommitHostEffectsTimer();
  10636. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  10637. // the mutation phase, so that the previous tree is still current during
  10638. // componentWillUnmount, but before the layout phase, so that the finished
  10639. // work is current during componentDidMount/Update.
  10640. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  10641. // the host tree after it's been mutated. The idiomatic use case for this is
  10642. // layout, but class component lifecycles also fire here for legacy reasons.
  10643. startCommitLifeCyclesTimer();
  10644. nextEffect = firstEffect;
  10645. do {
  10646. {
  10647. invokeGuardedCallback(null, commitLayoutEffects, null, root, expirationTime);
  10648. if (hasCaughtError()) {
  10649. if (!(nextEffect !== null)) {
  10650. {
  10651. throw Error( "Should be working on an effect." );
  10652. }
  10653. }
  10654. var _error2 = clearCaughtError();
  10655. captureCommitPhaseError(nextEffect, _error2);
  10656. nextEffect = nextEffect.nextEffect;
  10657. }
  10658. }
  10659. } while (nextEffect !== null);
  10660. stopCommitLifeCyclesTimer();
  10661. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  10662. // opportunity to paint.
  10663. requestPaint();
  10664. {
  10665. popInteractions(prevInteractions);
  10666. }
  10667. executionContext = prevExecutionContext;
  10668. } else {
  10669. // No effects.
  10670. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  10671. // no effects.
  10672. // TODO: Maybe there's a better way to report this.
  10673. startCommitSnapshotEffectsTimer();
  10674. stopCommitSnapshotEffectsTimer();
  10675. {
  10676. recordCommitTime();
  10677. }
  10678. startCommitHostEffectsTimer();
  10679. stopCommitHostEffectsTimer();
  10680. startCommitLifeCyclesTimer();
  10681. stopCommitLifeCyclesTimer();
  10682. }
  10683. stopCommitTimer();
  10684. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  10685. if (rootDoesHavePassiveEffects) {
  10686. // This commit has passive effects. Stash a reference to them. But don't
  10687. // schedule a callback until after flushing layout work.
  10688. rootDoesHavePassiveEffects = false;
  10689. rootWithPendingPassiveEffects = root;
  10690. pendingPassiveEffectsExpirationTime = expirationTime;
  10691. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  10692. } else {
  10693. // We are done with the effect chain at this point so let's clear the
  10694. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  10695. // clear this in flushPassiveEffects.
  10696. nextEffect = firstEffect;
  10697. while (nextEffect !== null) {
  10698. var nextNextEffect = nextEffect.nextEffect;
  10699. nextEffect.nextEffect = null;
  10700. nextEffect = nextNextEffect;
  10701. }
  10702. } // Check if there's remaining work on this root
  10703. var remainingExpirationTime = root.firstPendingTime;
  10704. if (remainingExpirationTime !== NoWork) {
  10705. {
  10706. if (spawnedWorkDuringRender !== null) {
  10707. var expirationTimes = spawnedWorkDuringRender;
  10708. spawnedWorkDuringRender = null;
  10709. for (var i = 0; i < expirationTimes.length; i++) {
  10710. scheduleInteractions(root, expirationTimes[i], root.memoizedInteractions);
  10711. }
  10712. }
  10713. schedulePendingInteractions(root, remainingExpirationTime);
  10714. }
  10715. } else {
  10716. // If there's no remaining work, we can clear the set of already failed
  10717. // error boundaries.
  10718. legacyErrorBoundariesThatAlreadyFailed = null;
  10719. }
  10720. {
  10721. if (!rootDidHavePassiveEffects) {
  10722. // If there are no passive effects, then we can complete the pending interactions.
  10723. // Otherwise, we'll wait until after the passive effects are flushed.
  10724. // Wait to do this until after remaining work has been scheduled,
  10725. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  10726. finishPendingInteractions(root, expirationTime);
  10727. }
  10728. }
  10729. if (remainingExpirationTime === Sync) {
  10730. // Count the number of times the root synchronously re-renders without
  10731. // finishing. If there are too many, it indicates an infinite update loop.
  10732. if (root === rootWithNestedUpdates) {
  10733. nestedUpdateCount++;
  10734. } else {
  10735. nestedUpdateCount = 0;
  10736. rootWithNestedUpdates = root;
  10737. }
  10738. } else {
  10739. nestedUpdateCount = 0;
  10740. }
  10741. onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
  10742. // additional work on this root is scheduled.
  10743. ensureRootIsScheduled(root);
  10744. if (hasUncaughtError) {
  10745. hasUncaughtError = false;
  10746. var _error3 = firstUncaughtError;
  10747. firstUncaughtError = null;
  10748. throw _error3;
  10749. }
  10750. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  10751. // This is a legacy edge case. We just committed the initial mount of
  10752. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  10753. // synchronously, but layout updates should be deferred until the end
  10754. // of the batch.
  10755. return null;
  10756. } // If layout work was scheduled, flush it now.
  10757. flushSyncCallbackQueue();
  10758. return null;
  10759. }
  10760. function commitBeforeMutationEffects() {
  10761. while (nextEffect !== null) {
  10762. var effectTag = nextEffect.effectTag;
  10763. if ((effectTag & Snapshot) !== NoEffect) {
  10764. setCurrentFiber(nextEffect);
  10765. recordEffect();
  10766. var current = nextEffect.alternate;
  10767. commitBeforeMutationLifeCycles(current, nextEffect);
  10768. resetCurrentFiber();
  10769. }
  10770. if ((effectTag & Passive) !== NoEffect) {
  10771. // If there are passive effects, schedule a callback to flush at
  10772. // the earliest opportunity.
  10773. if (!rootDoesHavePassiveEffects) {
  10774. rootDoesHavePassiveEffects = true;
  10775. scheduleCallback(NormalPriority, function () {
  10776. flushPassiveEffects();
  10777. return null;
  10778. });
  10779. }
  10780. }
  10781. nextEffect = nextEffect.nextEffect;
  10782. }
  10783. }
  10784. function commitMutationEffects(root, renderPriorityLevel) {
  10785. // TODO: Should probably move the bulk of this function to commitWork.
  10786. while (nextEffect !== null) {
  10787. setCurrentFiber(nextEffect);
  10788. var effectTag = nextEffect.effectTag;
  10789. if (effectTag & ContentReset) {
  10790. commitResetTextContent(nextEffect);
  10791. }
  10792. if (effectTag & Ref) {
  10793. var current = nextEffect.alternate;
  10794. if (current !== null) {
  10795. commitDetachRef(current);
  10796. }
  10797. } // The following switch statement is only concerned about placement,
  10798. // updates, and deletions. To avoid needing to add a case for every possible
  10799. // bitmap value, we remove the secondary effects from the effect tag and
  10800. // switch on that value.
  10801. var primaryEffectTag = effectTag & (Placement | Update | Deletion | Hydrating);
  10802. switch (primaryEffectTag) {
  10803. case Placement:
  10804. {
  10805. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  10806. // inserted, before any life-cycles like componentDidMount gets called.
  10807. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  10808. // and isMounted is deprecated anyway so we should be able to kill this.
  10809. nextEffect.effectTag &= ~Placement;
  10810. break;
  10811. }
  10812. case PlacementAndUpdate:
  10813. {
  10814. // Placement
  10815. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  10816. // inserted, before any life-cycles like componentDidMount gets called.
  10817. nextEffect.effectTag &= ~Placement; // Update
  10818. var _current = nextEffect.alternate;
  10819. commitWork(_current, nextEffect);
  10820. break;
  10821. }
  10822. case Hydrating:
  10823. {
  10824. nextEffect.effectTag &= ~Hydrating;
  10825. break;
  10826. }
  10827. case HydratingAndUpdate:
  10828. {
  10829. nextEffect.effectTag &= ~Hydrating; // Update
  10830. var _current2 = nextEffect.alternate;
  10831. commitWork(_current2, nextEffect);
  10832. break;
  10833. }
  10834. case Update:
  10835. {
  10836. var _current3 = nextEffect.alternate;
  10837. commitWork(_current3, nextEffect);
  10838. break;
  10839. }
  10840. case Deletion:
  10841. {
  10842. commitDeletion(root, nextEffect, renderPriorityLevel);
  10843. break;
  10844. }
  10845. } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
  10846. recordEffect();
  10847. resetCurrentFiber();
  10848. nextEffect = nextEffect.nextEffect;
  10849. }
  10850. }
  10851. function commitLayoutEffects(root, committedExpirationTime) {
  10852. // TODO: Should probably move the bulk of this function to commitWork.
  10853. while (nextEffect !== null) {
  10854. setCurrentFiber(nextEffect);
  10855. var effectTag = nextEffect.effectTag;
  10856. if (effectTag & (Update | Callback)) {
  10857. recordEffect();
  10858. var current = nextEffect.alternate;
  10859. commitLifeCycles(root, current, nextEffect);
  10860. }
  10861. if (effectTag & Ref) {
  10862. recordEffect();
  10863. commitAttachRef(nextEffect);
  10864. }
  10865. resetCurrentFiber();
  10866. nextEffect = nextEffect.nextEffect;
  10867. }
  10868. }
  10869. function flushPassiveEffects() {
  10870. if (pendingPassiveEffectsRenderPriority !== NoPriority) {
  10871. var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority ? NormalPriority : pendingPassiveEffectsRenderPriority;
  10872. pendingPassiveEffectsRenderPriority = NoPriority;
  10873. return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
  10874. }
  10875. }
  10876. function flushPassiveEffectsImpl() {
  10877. if (rootWithPendingPassiveEffects === null) {
  10878. return false;
  10879. }
  10880. var root = rootWithPendingPassiveEffects;
  10881. var expirationTime = pendingPassiveEffectsExpirationTime;
  10882. rootWithPendingPassiveEffects = null;
  10883. pendingPassiveEffectsExpirationTime = NoWork;
  10884. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  10885. {
  10886. throw Error( "Cannot flush passive effects while already rendering." );
  10887. }
  10888. }
  10889. var prevExecutionContext = executionContext;
  10890. executionContext |= CommitContext;
  10891. var prevInteractions = pushInteractions(root);
  10892. {
  10893. // Note: This currently assumes there are no passive effects on the root fiber
  10894. // because the root is not part of its own effect list.
  10895. // This could change in the future.
  10896. var _effect2 = root.current.firstEffect;
  10897. while (_effect2 !== null) {
  10898. {
  10899. setCurrentFiber(_effect2);
  10900. invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
  10901. if (hasCaughtError()) {
  10902. if (!(_effect2 !== null)) {
  10903. {
  10904. throw Error( "Should be working on an effect." );
  10905. }
  10906. }
  10907. var _error5 = clearCaughtError();
  10908. captureCommitPhaseError(_effect2, _error5);
  10909. }
  10910. resetCurrentFiber();
  10911. }
  10912. var nextNextEffect = _effect2.nextEffect; // Remove nextEffect pointer to assist GC
  10913. _effect2.nextEffect = null;
  10914. _effect2 = nextNextEffect;
  10915. }
  10916. }
  10917. {
  10918. popInteractions(prevInteractions);
  10919. finishPendingInteractions(root, expirationTime);
  10920. }
  10921. executionContext = prevExecutionContext;
  10922. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  10923. // exceeds the limit, we'll fire a warning.
  10924. nestedPassiveUpdateCount = rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  10925. return true;
  10926. }
  10927. function isAlreadyFailedLegacyErrorBoundary(instance) {
  10928. return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
  10929. }
  10930. function markLegacyErrorBoundaryAsFailed(instance) {
  10931. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  10932. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  10933. } else {
  10934. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  10935. }
  10936. }
  10937. function prepareToThrowUncaughtError(error) {
  10938. if (!hasUncaughtError) {
  10939. hasUncaughtError = true;
  10940. firstUncaughtError = error;
  10941. }
  10942. }
  10943. var onUncaughtError = prepareToThrowUncaughtError;
  10944. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  10945. var errorInfo = createCapturedValue(error, sourceFiber);
  10946. var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
  10947. enqueueUpdate(rootFiber, update);
  10948. var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
  10949. if (root !== null) {
  10950. ensureRootIsScheduled(root);
  10951. schedulePendingInteractions(root, Sync);
  10952. }
  10953. }
  10954. function captureCommitPhaseError(sourceFiber, error) {
  10955. if (sourceFiber.tag === HostRoot) {
  10956. // Error was thrown at the root. There is no parent, so the root
  10957. // itself should capture it.
  10958. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  10959. return;
  10960. }
  10961. var fiber = sourceFiber.return;
  10962. while (fiber !== null) {
  10963. if (fiber.tag === HostRoot) {
  10964. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  10965. return;
  10966. } else if (fiber.tag === ClassComponent) {
  10967. var ctor = fiber.type;
  10968. var instance = fiber.stateNode;
  10969. if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
  10970. var errorInfo = createCapturedValue(error, sourceFiber);
  10971. var update = createClassErrorUpdate(fiber, errorInfo, // TODO: This is always sync
  10972. Sync);
  10973. enqueueUpdate(fiber, update);
  10974. var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
  10975. if (root !== null) {
  10976. ensureRootIsScheduled(root);
  10977. schedulePendingInteractions(root, Sync);
  10978. }
  10979. return;
  10980. }
  10981. }
  10982. fiber = fiber.return;
  10983. }
  10984. }
  10985. function pingSuspendedRoot(root, thenable, suspendedTime) {
  10986. var pingCache = root.pingCache;
  10987. if (pingCache !== null) {
  10988. // The thenable resolved, so we no longer need to memoize, because it will
  10989. // never be thrown again.
  10990. pingCache.delete(thenable);
  10991. }
  10992. if (workInProgressRoot === root && renderExpirationTime$1 === suspendedTime) {
  10993. // Received a ping at the same priority level at which we're currently
  10994. // rendering. We might want to restart this render. This should mirror
  10995. // the logic of whether or not a root suspends once it completes.
  10996. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  10997. // we should probably never restart.
  10998. // If we're suspended with delay, we'll always suspend so we can always
  10999. // restart. If we're suspended without any updates, it might be a retry.
  11000. // If it's early in the retry we can restart. We can't know for sure
  11001. // whether we'll eventually process an update during this render pass,
  11002. // but it's somewhat unlikely that we get to a ping before that, since
  11003. // getting to the root most update is usually very fast.
  11004. if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && workInProgressRootLatestProcessedExpirationTime === Sync && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
  11005. // Restart from the root. Don't need to schedule a ping because
  11006. // we're already working on this tree.
  11007. prepareFreshStack(root, renderExpirationTime$1);
  11008. } else {
  11009. // Even though we can't restart right now, we might get an
  11010. // opportunity later. So we mark this render as having a ping.
  11011. workInProgressRootHasPendingPing = true;
  11012. }
  11013. return;
  11014. }
  11015. if (!isRootSuspendedAtTime(root, suspendedTime)) {
  11016. // The root is no longer suspended at this time.
  11017. return;
  11018. }
  11019. var lastPingedTime = root.lastPingedTime;
  11020. if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
  11021. // There's already a lower priority ping scheduled.
  11022. return;
  11023. } // Mark the time at which this ping was scheduled.
  11024. root.lastPingedTime = suspendedTime;
  11025. ensureRootIsScheduled(root);
  11026. schedulePendingInteractions(root, suspendedTime);
  11027. }
  11028. function retryTimedOutBoundary(boundaryFiber, retryTime) {
  11029. // The boundary fiber (a Suspense component or SuspenseList component)
  11030. // previously was rendered in its fallback state. One of the promises that
  11031. // suspended it has resolved, which means at least part of the tree was
  11032. // likely unblocked. Try rendering again, at a new expiration time.
  11033. if (retryTime === NoWork) {
  11034. var suspenseConfig = null; // Retries don't carry over the already committed update.
  11035. var currentTime = requestCurrentTimeForUpdate();
  11036. retryTime = computeExpirationForFiber(currentTime, boundaryFiber, suspenseConfig);
  11037. } // TODO: Special case idle priority?
  11038. var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
  11039. if (root !== null) {
  11040. ensureRootIsScheduled(root);
  11041. schedulePendingInteractions(root, retryTime);
  11042. }
  11043. }
  11044. function resolveRetryThenable(boundaryFiber, thenable) {
  11045. var retryTime = NoWork; // Default
  11046. var retryCache;
  11047. {
  11048. retryCache = boundaryFiber.stateNode;
  11049. }
  11050. if (retryCache !== null) {
  11051. // The thenable resolved, so we no longer need to memoize, because it will
  11052. // never be thrown again.
  11053. retryCache.delete(thenable);
  11054. }
  11055. retryTimedOutBoundary(boundaryFiber, retryTime);
  11056. } // Computes the next Just Noticeable Difference (JND) boundary.
  11057. // The theory is that a person can't tell the difference between small differences in time.
  11058. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  11059. // difference in the experience. However, waiting for longer might mean that we can avoid
  11060. // showing an intermediate loading state. The longer we have already waited, the harder it
  11061. // is to tell small differences in time. Therefore, the longer we've already waited,
  11062. // the longer we can wait additionally. At some point we have to give up though.
  11063. // We pick a train model where the next boundary commits at a consistent schedule.
  11064. // These particular numbers are vague estimates. We expect to adjust them based on research.
  11065. function jnd(timeElapsed) {
  11066. return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
  11067. }
  11068. function computeMsUntilSuspenseLoadingDelay(mostRecentEventTime, committedExpirationTime, suspenseConfig) {
  11069. var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
  11070. if (busyMinDurationMs <= 0) {
  11071. return 0;
  11072. }
  11073. var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
  11074. var currentTimeMs = now();
  11075. var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(mostRecentEventTime, suspenseConfig);
  11076. var timeElapsed = currentTimeMs - eventTimeMs;
  11077. if (timeElapsed <= busyDelayMs) {
  11078. // If we haven't yet waited longer than the initial delay, we don't
  11079. // have to wait any additional time.
  11080. return 0;
  11081. }
  11082. var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
  11083. return msUntilTimeout;
  11084. }
  11085. function checkForNestedUpdates() {
  11086. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  11087. nestedUpdateCount = 0;
  11088. rootWithNestedUpdates = null;
  11089. {
  11090. {
  11091. 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." );
  11092. }
  11093. }
  11094. }
  11095. {
  11096. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  11097. nestedPassiveUpdateCount = 0;
  11098. 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.');
  11099. }
  11100. }
  11101. }
  11102. function flushRenderPhaseStrictModeWarningsInDEV() {
  11103. {
  11104. ReactStrictModeWarnings.flushLegacyContextWarning();
  11105. {
  11106. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  11107. }
  11108. }
  11109. }
  11110. function stopFinishedWorkLoopTimer() {
  11111. var didCompleteRoot = true;
  11112. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  11113. interruptedBy = null;
  11114. }
  11115. function stopInterruptedWorkLoopTimer() {
  11116. // TODO: Track which fiber caused the interruption.
  11117. var didCompleteRoot = false;
  11118. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  11119. interruptedBy = null;
  11120. }
  11121. function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
  11122. if ( workInProgressRoot !== null && updateExpirationTime > renderExpirationTime$1) {
  11123. interruptedBy = fiberThatReceivedUpdate;
  11124. }
  11125. }
  11126. var didWarnStateUpdateForUnmountedComponent = null;
  11127. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  11128. {
  11129. var tag = fiber.tag;
  11130. if (tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent && tag !== Block) {
  11131. // Only warn for user-defined components, not internal ones like Suspense.
  11132. return;
  11133. }
  11134. // the problematic code almost always lies inside that component.
  11135. var componentName = getComponentName(fiber.type) || 'ReactComponent';
  11136. if (didWarnStateUpdateForUnmountedComponent !== null) {
  11137. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  11138. return;
  11139. }
  11140. didWarnStateUpdateForUnmountedComponent.add(componentName);
  11141. } else {
  11142. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  11143. }
  11144. 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));
  11145. }
  11146. }
  11147. var beginWork$1;
  11148. {
  11149. beginWork$1 = beginWork;
  11150. }
  11151. var didWarnAboutUpdateInRender = false;
  11152. var didWarnAboutUpdateInRenderForAnotherComponent;
  11153. {
  11154. didWarnAboutUpdateInRenderForAnotherComponent = new Set();
  11155. }
  11156. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  11157. {
  11158. if (isRendering && (executionContext & RenderContext) !== NoContext) {
  11159. switch (fiber.tag) {
  11160. case FunctionComponent:
  11161. case ForwardRef:
  11162. case SimpleMemoComponent:
  11163. {
  11164. var renderingComponentName = workInProgress && getComponentName(workInProgress.type) || 'Unknown'; // Dedupe by the rendering component because it's the one that needs to be fixed.
  11165. var dedupeKey = renderingComponentName;
  11166. if (!didWarnAboutUpdateInRenderForAnotherComponent.has(dedupeKey)) {
  11167. didWarnAboutUpdateInRenderForAnotherComponent.add(dedupeKey);
  11168. var setStateComponentName = getComponentName(fiber.type) || 'Unknown';
  11169. 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);
  11170. }
  11171. break;
  11172. }
  11173. case ClassComponent:
  11174. {
  11175. if (!didWarnAboutUpdateInRender) {
  11176. error('Cannot update during an existing state transition (such as ' + 'within `render`). Render methods should be a pure ' + 'function of props and state.');
  11177. didWarnAboutUpdateInRender = true;
  11178. }
  11179. break;
  11180. }
  11181. }
  11182. }
  11183. }
  11184. } // a 'shared' variable that changes when act() opens/closes in tests.
  11185. var IsThisRendererActing = {
  11186. current: false
  11187. };
  11188. function warnIfNotScopedWithMatchingAct(fiber) {
  11189. {
  11190. if ( IsSomeRendererActing.current === true && IsThisRendererActing.current !== true) {
  11191. 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));
  11192. }
  11193. }
  11194. }
  11195. function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
  11196. {
  11197. if ( (fiber.mode & StrictMode) !== NoMode && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  11198. 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));
  11199. }
  11200. }
  11201. }
  11202. function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
  11203. {
  11204. if ( executionContext === NoContext && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  11205. 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));
  11206. }
  11207. }
  11208. }
  11209. var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
  11210. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  11211. // scheduler is the actual recommendation. The alternative could be a testing build,
  11212. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  11213. // to get their tests right.
  11214. function warnIfUnmockedScheduler(fiber) {
  11215. {
  11216. if (didWarnAboutUnmockedScheduler === false && Scheduler$1.unstable_flushAllWithoutAsserting === undefined) {
  11217. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  11218. didWarnAboutUnmockedScheduler = true;
  11219. 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');
  11220. }
  11221. }
  11222. }
  11223. }
  11224. function computeThreadID(root, expirationTime) {
  11225. // Interaction threads are unique per root and expiration time.
  11226. return expirationTime * 1000 + root.interactionThreadID;
  11227. }
  11228. function markSpawnedWork(expirationTime) {
  11229. if (spawnedWorkDuringRender === null) {
  11230. spawnedWorkDuringRender = [expirationTime];
  11231. } else {
  11232. spawnedWorkDuringRender.push(expirationTime);
  11233. }
  11234. }
  11235. function scheduleInteractions(root, expirationTime, interactions) {
  11236. if (interactions.size > 0) {
  11237. var pendingInteractionMap = root.pendingInteractionMap;
  11238. var pendingInteractions = pendingInteractionMap.get(expirationTime);
  11239. if (pendingInteractions != null) {
  11240. interactions.forEach(function (interaction) {
  11241. if (!pendingInteractions.has(interaction)) {
  11242. // Update the pending async work count for previously unscheduled interaction.
  11243. interaction.__count++;
  11244. }
  11245. pendingInteractions.add(interaction);
  11246. });
  11247. } else {
  11248. pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
  11249. interactions.forEach(function (interaction) {
  11250. interaction.__count++;
  11251. });
  11252. }
  11253. var subscriber = tracing.__subscriberRef.current;
  11254. if (subscriber !== null) {
  11255. var threadID = computeThreadID(root, expirationTime);
  11256. subscriber.onWorkScheduled(interactions, threadID);
  11257. }
  11258. }
  11259. }
  11260. function schedulePendingInteractions(root, expirationTime) {
  11261. scheduleInteractions(root, expirationTime, tracing.__interactionsRef.current);
  11262. }
  11263. function startWorkOnPendingInteractions(root, expirationTime) {
  11264. // we can accurately attribute time spent working on it, And so that cascading
  11265. // work triggered during the render phase will be associated with it.
  11266. var interactions = new Set();
  11267. root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
  11268. if (scheduledExpirationTime >= expirationTime) {
  11269. scheduledInteractions.forEach(function (interaction) {
  11270. return interactions.add(interaction);
  11271. });
  11272. }
  11273. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  11274. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  11275. // without having to recalculate it. We will also use it in commitWork() to
  11276. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  11277. // way to access it when the onCommitRoot() hook is called.
  11278. root.memoizedInteractions = interactions;
  11279. if (interactions.size > 0) {
  11280. var subscriber = tracing.__subscriberRef.current;
  11281. if (subscriber !== null) {
  11282. var threadID = computeThreadID(root, expirationTime);
  11283. try {
  11284. subscriber.onWorkStarted(interactions, threadID);
  11285. } catch (error) {
  11286. // If the subscriber throws, rethrow it in a separate task
  11287. scheduleCallback(ImmediatePriority, function () {
  11288. throw error;
  11289. });
  11290. }
  11291. }
  11292. }
  11293. }
  11294. function finishPendingInteractions(root, committedExpirationTime) {
  11295. var earliestRemainingTimeAfterCommit = root.firstPendingTime;
  11296. var subscriber;
  11297. try {
  11298. subscriber = tracing.__subscriberRef.current;
  11299. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  11300. var threadID = computeThreadID(root, committedExpirationTime);
  11301. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  11302. }
  11303. } catch (error) {
  11304. // If the subscriber throws, rethrow it in a separate task
  11305. scheduleCallback(ImmediatePriority, function () {
  11306. throw error;
  11307. });
  11308. } finally {
  11309. // Clear completed interactions from the pending Map.
  11310. // Unless the render was suspended or cascading work was scheduled,
  11311. // In which case– leave pending interactions until the subsequent render.
  11312. var pendingInteractionMap = root.pendingInteractionMap;
  11313. pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
  11314. // Only decrement the pending interaction count if we're done.
  11315. // If there's still work at the current priority,
  11316. // That indicates that we are waiting for suspense data.
  11317. if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
  11318. pendingInteractionMap.delete(scheduledExpirationTime);
  11319. scheduledInteractions.forEach(function (interaction) {
  11320. interaction.__count--;
  11321. if (subscriber !== null && interaction.__count === 0) {
  11322. try {
  11323. subscriber.onInteractionScheduledWorkCompleted(interaction);
  11324. } catch (error) {
  11325. // If the subscriber throws, rethrow it in a separate task
  11326. scheduleCallback(ImmediatePriority, function () {
  11327. throw error;
  11328. });
  11329. }
  11330. }
  11331. });
  11332. }
  11333. });
  11334. }
  11335. }
  11336. var onScheduleFiberRoot = null;
  11337. var onCommitFiberRoot = null;
  11338. var onCommitFiberUnmount = null;
  11339. var hasLoggedError = false;
  11340. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
  11341. function injectInternals(internals) {
  11342. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
  11343. // No DevTools
  11344. return false;
  11345. }
  11346. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  11347. if (hook.isDisabled) {
  11348. // This isn't a real property on the hook, but it can be set to opt out
  11349. // of DevTools integration and associated warnings and logs.
  11350. // https://github.com/facebook/react/issues/3877
  11351. return true;
  11352. }
  11353. if (!hook.supportsFiber) {
  11354. {
  11355. 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');
  11356. } // DevTools exists, even though it doesn't support Fiber.
  11357. return true;
  11358. }
  11359. try {
  11360. var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  11361. if (true) {
  11362. // Only used by Fast Refresh
  11363. if (typeof hook.onScheduleFiberRoot === 'function') {
  11364. onScheduleFiberRoot = function (root, children) {
  11365. try {
  11366. hook.onScheduleFiberRoot(rendererID, root, children);
  11367. } catch (err) {
  11368. if (true && !hasLoggedError) {
  11369. hasLoggedError = true;
  11370. error('React instrumentation encountered an error: %s', err);
  11371. }
  11372. }
  11373. };
  11374. }
  11375. }
  11376. onCommitFiberRoot = function (root, expirationTime) {
  11377. try {
  11378. var didError = (root.current.effectTag & DidCapture) === DidCapture;
  11379. if (enableProfilerTimer) {
  11380. var currentTime = getCurrentTime();
  11381. var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime);
  11382. hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  11383. } else {
  11384. hook.onCommitFiberRoot(rendererID, root, undefined, didError);
  11385. }
  11386. } catch (err) {
  11387. if (true) {
  11388. if (!hasLoggedError) {
  11389. hasLoggedError = true;
  11390. error('React instrumentation encountered an error: %s', err);
  11391. }
  11392. }
  11393. }
  11394. };
  11395. onCommitFiberUnmount = function (fiber) {
  11396. try {
  11397. hook.onCommitFiberUnmount(rendererID, fiber);
  11398. } catch (err) {
  11399. if (true) {
  11400. if (!hasLoggedError) {
  11401. hasLoggedError = true;
  11402. error('React instrumentation encountered an error: %s', err);
  11403. }
  11404. }
  11405. }
  11406. };
  11407. } catch (err) {
  11408. // Catch all errors because it is unsafe to throw during initialization.
  11409. {
  11410. error('React instrumentation encountered an error: %s.', err);
  11411. }
  11412. } // DevTools exists
  11413. return true;
  11414. }
  11415. function onScheduleRoot(root, children) {
  11416. if (typeof onScheduleFiberRoot === 'function') {
  11417. onScheduleFiberRoot(root, children);
  11418. }
  11419. }
  11420. function onCommitRoot(root, expirationTime) {
  11421. if (typeof onCommitFiberRoot === 'function') {
  11422. onCommitFiberRoot(root, expirationTime);
  11423. }
  11424. }
  11425. function onCommitUnmount(fiber) {
  11426. if (typeof onCommitFiberUnmount === 'function') {
  11427. onCommitFiberUnmount(fiber);
  11428. }
  11429. }
  11430. var hasBadMapPolyfill;
  11431. {
  11432. hasBadMapPolyfill = false;
  11433. try {
  11434. var nonExtensibleObject = Object.preventExtensions({});
  11435. var testMap = new Map([[nonExtensibleObject, null]]);
  11436. var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
  11437. // https://github.com/rollup/rollup/issues/1771
  11438. // TODO: we can remove these if Rollup fixes the bug.
  11439. testMap.set(0, 0);
  11440. testSet.add(0);
  11441. } catch (e) {
  11442. // TODO: Consider warning about bad polyfills
  11443. hasBadMapPolyfill = true;
  11444. }
  11445. }
  11446. var debugCounter = 1;
  11447. function FiberNode(tag, pendingProps, key, mode) {
  11448. // Instance
  11449. this.tag = tag;
  11450. this.key = key;
  11451. this.elementType = null;
  11452. this.type = null;
  11453. this.stateNode = null; // Fiber
  11454. this.return = null;
  11455. this.child = null;
  11456. this.sibling = null;
  11457. this.index = 0;
  11458. this.ref = null;
  11459. this.pendingProps = pendingProps;
  11460. this.memoizedProps = null;
  11461. this.updateQueue = null;
  11462. this.memoizedState = null;
  11463. this.dependencies = null;
  11464. this.mode = mode; // Effects
  11465. this.effectTag = NoEffect;
  11466. this.nextEffect = null;
  11467. this.firstEffect = null;
  11468. this.lastEffect = null;
  11469. this.expirationTime = NoWork;
  11470. this.childExpirationTime = NoWork;
  11471. this.alternate = null;
  11472. {
  11473. // Note: The following is done to avoid a v8 performance cliff.
  11474. //
  11475. // Initializing the fields below to smis and later updating them with
  11476. // double values will cause Fibers to end up having separate shapes.
  11477. // This behavior/bug has something to do with Object.preventExtension().
  11478. // Fortunately this only impacts DEV builds.
  11479. // Unfortunately it makes React unusably slow for some applications.
  11480. // To work around this, initialize the fields below with doubles.
  11481. //
  11482. // Learn more about this here:
  11483. // https://github.com/facebook/react/issues/14365
  11484. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  11485. this.actualDuration = Number.NaN;
  11486. this.actualStartTime = Number.NaN;
  11487. this.selfBaseDuration = Number.NaN;
  11488. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  11489. // This won't trigger the performance cliff mentioned above,
  11490. // and it simplifies other profiler code (including DevTools).
  11491. this.actualDuration = 0;
  11492. this.actualStartTime = -1;
  11493. this.selfBaseDuration = 0;
  11494. this.treeBaseDuration = 0;
  11495. } // This is normally DEV-only except www when it adds listeners.
  11496. // TODO: remove the User Timing integration in favor of Root Events.
  11497. {
  11498. this._debugID = debugCounter++;
  11499. this._debugIsCurrentlyTiming = false;
  11500. }
  11501. {
  11502. this._debugSource = null;
  11503. this._debugOwner = null;
  11504. this._debugNeedsRemount = false;
  11505. this._debugHookTypes = null;
  11506. if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
  11507. Object.preventExtensions(this);
  11508. }
  11509. }
  11510. } // This is a constructor function, rather than a POJO constructor, still
  11511. // please ensure we do the following:
  11512. // 1) Nobody should add any instance methods on this. Instance methods can be
  11513. // more difficult to predict when they get optimized and they are almost
  11514. // never inlined properly in static compilers.
  11515. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  11516. // always know when it is a fiber.
  11517. // 3) We might want to experiment with using numeric keys since they are easier
  11518. // to optimize in a non-JIT environment.
  11519. // 4) We can easily go from a constructor to a createFiber object literal if that
  11520. // is faster.
  11521. // 5) It should be easy to port this to a C struct and keep a C implementation
  11522. // compatible.
  11523. var createFiber = function (tag, pendingProps, key, mode) {
  11524. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  11525. return new FiberNode(tag, pendingProps, key, mode);
  11526. };
  11527. function shouldConstruct(Component) {
  11528. var prototype = Component.prototype;
  11529. return !!(prototype && prototype.isReactComponent);
  11530. }
  11531. function isSimpleFunctionComponent(type) {
  11532. return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
  11533. }
  11534. function resolveLazyComponentTag(Component) {
  11535. if (typeof Component === 'function') {
  11536. return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
  11537. } else if (Component !== undefined && Component !== null) {
  11538. var $$typeof = Component.$$typeof;
  11539. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  11540. return ForwardRef;
  11541. }
  11542. if ($$typeof === REACT_MEMO_TYPE) {
  11543. return MemoComponent;
  11544. }
  11545. }
  11546. return IndeterminateComponent;
  11547. } // This is used to create an alternate fiber to do work on.
  11548. function createWorkInProgress(current, pendingProps) {
  11549. var workInProgress = current.alternate;
  11550. if (workInProgress === null) {
  11551. // We use a double buffering pooling technique because we know that we'll
  11552. // only ever need at most two versions of a tree. We pool the "other" unused
  11553. // node that we're free to reuse. This is lazily created to avoid allocating
  11554. // extra objects for things that are never updated. It also allow us to
  11555. // reclaim the extra memory if needed.
  11556. workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
  11557. workInProgress.elementType = current.elementType;
  11558. workInProgress.type = current.type;
  11559. workInProgress.stateNode = current.stateNode;
  11560. {
  11561. // DEV-only fields
  11562. {
  11563. workInProgress._debugID = current._debugID;
  11564. }
  11565. workInProgress._debugSource = current._debugSource;
  11566. workInProgress._debugOwner = current._debugOwner;
  11567. workInProgress._debugHookTypes = current._debugHookTypes;
  11568. }
  11569. workInProgress.alternate = current;
  11570. current.alternate = workInProgress;
  11571. } else {
  11572. workInProgress.pendingProps = pendingProps; // We already have an alternate.
  11573. // Reset the effect tag.
  11574. workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
  11575. workInProgress.nextEffect = null;
  11576. workInProgress.firstEffect = null;
  11577. workInProgress.lastEffect = null;
  11578. {
  11579. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  11580. // This prevents time from endlessly accumulating in new commits.
  11581. // This has the downside of resetting values for different priority renders,
  11582. // But works for yielding (the common case) and should support resuming.
  11583. workInProgress.actualDuration = 0;
  11584. workInProgress.actualStartTime = -1;
  11585. }
  11586. }
  11587. workInProgress.childExpirationTime = current.childExpirationTime;
  11588. workInProgress.expirationTime = current.expirationTime;
  11589. workInProgress.child = current.child;
  11590. workInProgress.memoizedProps = current.memoizedProps;
  11591. workInProgress.memoizedState = current.memoizedState;
  11592. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  11593. // it cannot be shared with the current fiber.
  11594. var currentDependencies = current.dependencies;
  11595. workInProgress.dependencies = currentDependencies === null ? null : {
  11596. expirationTime: currentDependencies.expirationTime,
  11597. firstContext: currentDependencies.firstContext,
  11598. responders: currentDependencies.responders
  11599. }; // These will be overridden during the parent's reconciliation
  11600. workInProgress.sibling = current.sibling;
  11601. workInProgress.index = current.index;
  11602. workInProgress.ref = current.ref;
  11603. {
  11604. workInProgress.selfBaseDuration = current.selfBaseDuration;
  11605. workInProgress.treeBaseDuration = current.treeBaseDuration;
  11606. }
  11607. {
  11608. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  11609. switch (workInProgress.tag) {
  11610. case IndeterminateComponent:
  11611. case FunctionComponent:
  11612. case SimpleMemoComponent:
  11613. workInProgress.type = resolveFunctionForHotReloading(current.type);
  11614. break;
  11615. case ClassComponent:
  11616. workInProgress.type = resolveClassForHotReloading(current.type);
  11617. break;
  11618. case ForwardRef:
  11619. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  11620. break;
  11621. }
  11622. }
  11623. return workInProgress;
  11624. } // Used to reuse a Fiber for a second pass.
  11625. function resetWorkInProgress(workInProgress, renderExpirationTime) {
  11626. // This resets the Fiber to what createFiber or createWorkInProgress would
  11627. // have set the values to before during the first pass. Ideally this wouldn't
  11628. // be necessary but unfortunately many code paths reads from the workInProgress
  11629. // when they should be reading from current and writing to workInProgress.
  11630. // We assume pendingProps, index, key, ref, return are still untouched to
  11631. // avoid doing another reconciliation.
  11632. // Reset the effect tag but keep any Placement tags, since that's something
  11633. // that child fiber is setting, not the reconciliation.
  11634. workInProgress.effectTag &= Placement; // The effect list is no longer valid.
  11635. workInProgress.nextEffect = null;
  11636. workInProgress.firstEffect = null;
  11637. workInProgress.lastEffect = null;
  11638. var current = workInProgress.alternate;
  11639. if (current === null) {
  11640. // Reset to createFiber's initial values.
  11641. workInProgress.childExpirationTime = NoWork;
  11642. workInProgress.expirationTime = renderExpirationTime;
  11643. workInProgress.child = null;
  11644. workInProgress.memoizedProps = null;
  11645. workInProgress.memoizedState = null;
  11646. workInProgress.updateQueue = null;
  11647. workInProgress.dependencies = null;
  11648. {
  11649. // Note: We don't reset the actualTime counts. It's useful to accumulate
  11650. // actual time across multiple render passes.
  11651. workInProgress.selfBaseDuration = 0;
  11652. workInProgress.treeBaseDuration = 0;
  11653. }
  11654. } else {
  11655. // Reset to the cloned values that createWorkInProgress would've.
  11656. workInProgress.childExpirationTime = current.childExpirationTime;
  11657. workInProgress.expirationTime = current.expirationTime;
  11658. workInProgress.child = current.child;
  11659. workInProgress.memoizedProps = current.memoizedProps;
  11660. workInProgress.memoizedState = current.memoizedState;
  11661. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  11662. // it cannot be shared with the current fiber.
  11663. var currentDependencies = current.dependencies;
  11664. workInProgress.dependencies = currentDependencies === null ? null : {
  11665. expirationTime: currentDependencies.expirationTime,
  11666. firstContext: currentDependencies.firstContext,
  11667. responders: currentDependencies.responders
  11668. };
  11669. {
  11670. // Note: We don't reset the actualTime counts. It's useful to accumulate
  11671. // actual time across multiple render passes.
  11672. workInProgress.selfBaseDuration = current.selfBaseDuration;
  11673. workInProgress.treeBaseDuration = current.treeBaseDuration;
  11674. }
  11675. }
  11676. return workInProgress;
  11677. }
  11678. function createHostRootFiber(tag) {
  11679. var mode;
  11680. if (tag === ConcurrentRoot) {
  11681. mode = ConcurrentMode | BlockingMode | StrictMode;
  11682. } else if (tag === BlockingRoot) {
  11683. mode = BlockingMode | StrictMode;
  11684. } else {
  11685. mode = NoMode;
  11686. }
  11687. if ( isDevToolsPresent) {
  11688. // Always collect profile timings when DevTools are present.
  11689. // This enables DevTools to start capturing timing at any point–
  11690. // Without some nodes in the tree having empty base times.
  11691. mode |= ProfileMode;
  11692. }
  11693. return createFiber(HostRoot, null, null, mode);
  11694. }
  11695. function createFiberFromTypeAndProps(type, // React$ElementType
  11696. key, pendingProps, owner, mode, expirationTime) {
  11697. var fiber;
  11698. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  11699. var resolvedType = type;
  11700. if (typeof type === 'function') {
  11701. if (shouldConstruct(type)) {
  11702. fiberTag = ClassComponent;
  11703. {
  11704. resolvedType = resolveClassForHotReloading(resolvedType);
  11705. }
  11706. } else {
  11707. {
  11708. resolvedType = resolveFunctionForHotReloading(resolvedType);
  11709. }
  11710. }
  11711. } else if (typeof type === 'string') {
  11712. fiberTag = HostComponent;
  11713. } else {
  11714. getTag: switch (type) {
  11715. case REACT_FRAGMENT_TYPE:
  11716. return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
  11717. case REACT_CONCURRENT_MODE_TYPE:
  11718. fiberTag = Mode;
  11719. mode |= ConcurrentMode | BlockingMode | StrictMode;
  11720. break;
  11721. case REACT_STRICT_MODE_TYPE:
  11722. fiberTag = Mode;
  11723. mode |= StrictMode;
  11724. break;
  11725. case REACT_PROFILER_TYPE:
  11726. return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
  11727. case REACT_SUSPENSE_TYPE:
  11728. return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
  11729. case REACT_SUSPENSE_LIST_TYPE:
  11730. return createFiberFromSuspenseList(pendingProps, mode, expirationTime, key);
  11731. default:
  11732. {
  11733. if (typeof type === 'object' && type !== null) {
  11734. switch (type.$$typeof) {
  11735. case REACT_PROVIDER_TYPE:
  11736. fiberTag = ContextProvider;
  11737. break getTag;
  11738. case REACT_CONTEXT_TYPE:
  11739. // This is a consumer
  11740. fiberTag = ContextConsumer;
  11741. break getTag;
  11742. case REACT_FORWARD_REF_TYPE:
  11743. fiberTag = ForwardRef;
  11744. {
  11745. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  11746. }
  11747. break getTag;
  11748. case REACT_MEMO_TYPE:
  11749. fiberTag = MemoComponent;
  11750. break getTag;
  11751. case REACT_LAZY_TYPE:
  11752. fiberTag = LazyComponent;
  11753. resolvedType = null;
  11754. break getTag;
  11755. case REACT_BLOCK_TYPE:
  11756. fiberTag = Block;
  11757. break getTag;
  11758. }
  11759. }
  11760. var info = '';
  11761. {
  11762. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  11763. 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.';
  11764. }
  11765. var ownerName = owner ? getComponentName(owner.type) : null;
  11766. if (ownerName) {
  11767. info += '\n\nCheck the render method of `' + ownerName + '`.';
  11768. }
  11769. }
  11770. {
  11771. {
  11772. 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 );
  11773. }
  11774. }
  11775. }
  11776. }
  11777. }
  11778. fiber = createFiber(fiberTag, pendingProps, key, mode);
  11779. fiber.elementType = type;
  11780. fiber.type = resolvedType;
  11781. fiber.expirationTime = expirationTime;
  11782. return fiber;
  11783. }
  11784. function createFiberFromElement(element, mode, expirationTime) {
  11785. var owner = null;
  11786. {
  11787. owner = element._owner;
  11788. }
  11789. var type = element.type;
  11790. var key = element.key;
  11791. var pendingProps = element.props;
  11792. var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
  11793. {
  11794. fiber._debugSource = element._source;
  11795. fiber._debugOwner = element._owner;
  11796. }
  11797. return fiber;
  11798. }
  11799. function createFiberFromFragment(elements, mode, expirationTime, key) {
  11800. var fiber = createFiber(Fragment, elements, key, mode);
  11801. fiber.expirationTime = expirationTime;
  11802. return fiber;
  11803. }
  11804. function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
  11805. {
  11806. if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
  11807. error('Profiler must specify an "id" string and "onRender" function as props');
  11808. }
  11809. }
  11810. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  11811. fiber.elementType = REACT_PROFILER_TYPE;
  11812. fiber.type = REACT_PROFILER_TYPE;
  11813. fiber.expirationTime = expirationTime;
  11814. return fiber;
  11815. }
  11816. function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
  11817. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  11818. // This needs to be fixed in getComponentName so that it relies on the tag
  11819. // instead.
  11820. fiber.type = REACT_SUSPENSE_TYPE;
  11821. fiber.elementType = REACT_SUSPENSE_TYPE;
  11822. fiber.expirationTime = expirationTime;
  11823. return fiber;
  11824. }
  11825. function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
  11826. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  11827. {
  11828. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  11829. // This needs to be fixed in getComponentName so that it relies on the tag
  11830. // instead.
  11831. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  11832. }
  11833. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  11834. fiber.expirationTime = expirationTime;
  11835. return fiber;
  11836. }
  11837. function createFiberFromText(content, mode, expirationTime) {
  11838. var fiber = createFiber(HostText, content, null, mode);
  11839. fiber.expirationTime = expirationTime;
  11840. return fiber;
  11841. }
  11842. function createFiberFromPortal(portal, mode, expirationTime) {
  11843. var pendingProps = portal.children !== null ? portal.children : [];
  11844. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  11845. fiber.expirationTime = expirationTime;
  11846. fiber.stateNode = {
  11847. containerInfo: portal.containerInfo,
  11848. pendingChildren: null,
  11849. // Used by persistent updates
  11850. implementation: portal.implementation
  11851. };
  11852. return fiber;
  11853. } // Used for stashing WIP properties to replay failed work in DEV.
  11854. function FiberRootNode(containerInfo, tag, hydrate) {
  11855. this.tag = tag;
  11856. this.current = null;
  11857. this.containerInfo = containerInfo;
  11858. this.pendingChildren = null;
  11859. this.pingCache = null;
  11860. this.finishedExpirationTime = NoWork;
  11861. this.finishedWork = null;
  11862. this.timeoutHandle = noTimeout;
  11863. this.context = null;
  11864. this.pendingContext = null;
  11865. this.hydrate = hydrate;
  11866. this.callbackNode = null;
  11867. this.callbackPriority = NoPriority;
  11868. this.firstPendingTime = NoWork;
  11869. this.firstSuspendedTime = NoWork;
  11870. this.lastSuspendedTime = NoWork;
  11871. this.nextKnownPendingLevel = NoWork;
  11872. this.lastPingedTime = NoWork;
  11873. this.lastExpiredTime = NoWork;
  11874. {
  11875. this.interactionThreadID = tracing.unstable_getThreadID();
  11876. this.memoizedInteractions = new Set();
  11877. this.pendingInteractionMap = new Map();
  11878. }
  11879. }
  11880. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  11881. var root = new FiberRootNode(containerInfo, tag, hydrate);
  11882. // stateNode is any.
  11883. var uninitializedFiber = createHostRootFiber(tag);
  11884. root.current = uninitializedFiber;
  11885. uninitializedFiber.stateNode = root;
  11886. initializeUpdateQueue(uninitializedFiber);
  11887. return root;
  11888. }
  11889. function isRootSuspendedAtTime(root, expirationTime) {
  11890. var firstSuspendedTime = root.firstSuspendedTime;
  11891. var lastSuspendedTime = root.lastSuspendedTime;
  11892. return firstSuspendedTime !== NoWork && firstSuspendedTime >= expirationTime && lastSuspendedTime <= expirationTime;
  11893. }
  11894. function markRootSuspendedAtTime(root, expirationTime) {
  11895. var firstSuspendedTime = root.firstSuspendedTime;
  11896. var lastSuspendedTime = root.lastSuspendedTime;
  11897. if (firstSuspendedTime < expirationTime) {
  11898. root.firstSuspendedTime = expirationTime;
  11899. }
  11900. if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
  11901. root.lastSuspendedTime = expirationTime;
  11902. }
  11903. if (expirationTime <= root.lastPingedTime) {
  11904. root.lastPingedTime = NoWork;
  11905. }
  11906. if (expirationTime <= root.lastExpiredTime) {
  11907. root.lastExpiredTime = NoWork;
  11908. }
  11909. }
  11910. function markRootUpdatedAtTime(root, expirationTime) {
  11911. // Update the range of pending times
  11912. var firstPendingTime = root.firstPendingTime;
  11913. if (expirationTime > firstPendingTime) {
  11914. root.firstPendingTime = expirationTime;
  11915. } // Update the range of suspended times. Treat everything lower priority or
  11916. // equal to this update as unsuspended.
  11917. var firstSuspendedTime = root.firstSuspendedTime;
  11918. if (firstSuspendedTime !== NoWork) {
  11919. if (expirationTime >= firstSuspendedTime) {
  11920. // The entire suspended range is now unsuspended.
  11921. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  11922. } else if (expirationTime >= root.lastSuspendedTime) {
  11923. root.lastSuspendedTime = expirationTime + 1;
  11924. } // This is a pending level. Check if it's higher priority than the next
  11925. // known pending level.
  11926. if (expirationTime > root.nextKnownPendingLevel) {
  11927. root.nextKnownPendingLevel = expirationTime;
  11928. }
  11929. }
  11930. }
  11931. function markRootFinishedAtTime(root, finishedExpirationTime, remainingExpirationTime) {
  11932. // Update the range of pending times
  11933. root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
  11934. // equal to this update as unsuspended.
  11935. if (finishedExpirationTime <= root.lastSuspendedTime) {
  11936. // The entire suspended range is now unsuspended.
  11937. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  11938. } else if (finishedExpirationTime <= root.firstSuspendedTime) {
  11939. // Part of the suspended range is now unsuspended. Narrow the range to
  11940. // include everything between the unsuspended time (non-inclusive) and the
  11941. // last suspended time.
  11942. root.firstSuspendedTime = finishedExpirationTime - 1;
  11943. }
  11944. if (finishedExpirationTime <= root.lastPingedTime) {
  11945. // Clear the pinged time
  11946. root.lastPingedTime = NoWork;
  11947. }
  11948. if (finishedExpirationTime <= root.lastExpiredTime) {
  11949. // Clear the expired time
  11950. root.lastExpiredTime = NoWork;
  11951. }
  11952. }
  11953. function markRootExpiredAtTime(root, expirationTime) {
  11954. var lastExpiredTime = root.lastExpiredTime;
  11955. if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
  11956. root.lastExpiredTime = expirationTime;
  11957. }
  11958. }
  11959. var didWarnAboutMessageChannel = false;
  11960. var enqueueTaskImpl = null;
  11961. function enqueueTask(task) {
  11962. if (enqueueTaskImpl === null) {
  11963. try {
  11964. // read require off the module object to get around the bundlers.
  11965. // we don't want them to detect a require and bundle a Node polyfill.
  11966. var requireString = ('require' + Math.random()).slice(0, 7);
  11967. var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
  11968. // version of setImmediate, bypassing fake timers if any.
  11969. enqueueTaskImpl = nodeRequire('timers').setImmediate;
  11970. } catch (_err) {
  11971. // we're in a browser
  11972. // we can't use regular timers because they may still be faked
  11973. // so we try MessageChannel+postMessage instead
  11974. enqueueTaskImpl = function (callback) {
  11975. {
  11976. if (didWarnAboutMessageChannel === false) {
  11977. didWarnAboutMessageChannel = true;
  11978. if (typeof MessageChannel === 'undefined') {
  11979. 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.');
  11980. }
  11981. }
  11982. }
  11983. var channel = new MessageChannel();
  11984. channel.port1.onmessage = callback;
  11985. channel.port2.postMessage(undefined);
  11986. };
  11987. }
  11988. }
  11989. return enqueueTaskImpl(task);
  11990. }
  11991. var didWarnAboutNestedUpdates;
  11992. {
  11993. didWarnAboutNestedUpdates = false;
  11994. }
  11995. function getContextForSubtree(parentComponent) {
  11996. if (!parentComponent) {
  11997. return emptyContextObject;
  11998. }
  11999. var fiber = get(parentComponent);
  12000. var parentContext = findCurrentUnmaskedContext(fiber);
  12001. if (fiber.tag === ClassComponent) {
  12002. var Component = fiber.type;
  12003. if (isContextProvider(Component)) {
  12004. return processChildContext(fiber, Component, parentContext);
  12005. }
  12006. }
  12007. return parentContext;
  12008. }
  12009. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  12010. return createFiberRoot(containerInfo, tag, hydrate);
  12011. }
  12012. function updateContainer(element, container, parentComponent, callback) {
  12013. {
  12014. onScheduleRoot(container, element);
  12015. }
  12016. var current$1 = container.current;
  12017. var currentTime = requestCurrentTimeForUpdate();
  12018. {
  12019. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  12020. if ('undefined' !== typeof jest) {
  12021. warnIfUnmockedScheduler(current$1);
  12022. warnIfNotScopedWithMatchingAct(current$1);
  12023. }
  12024. }
  12025. var suspenseConfig = requestCurrentSuspenseConfig();
  12026. var expirationTime = computeExpirationForFiber(currentTime, current$1, suspenseConfig);
  12027. var context = getContextForSubtree(parentComponent);
  12028. if (container.context === null) {
  12029. container.context = context;
  12030. } else {
  12031. container.pendingContext = context;
  12032. }
  12033. {
  12034. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  12035. didWarnAboutNestedUpdates = true;
  12036. 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');
  12037. }
  12038. }
  12039. var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
  12040. // being called "element".
  12041. update.payload = {
  12042. element: element
  12043. };
  12044. callback = callback === undefined ? null : callback;
  12045. if (callback !== null) {
  12046. {
  12047. if (typeof callback !== 'function') {
  12048. error('render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback);
  12049. }
  12050. }
  12051. update.callback = callback;
  12052. }
  12053. enqueueUpdate(current$1, update);
  12054. scheduleWork(current$1, expirationTime);
  12055. return expirationTime;
  12056. }
  12057. function getPublicRootInstance(container) {
  12058. var containerFiber = container.current;
  12059. if (!containerFiber.child) {
  12060. return null;
  12061. }
  12062. switch (containerFiber.child.tag) {
  12063. case HostComponent:
  12064. return getPublicInstance(containerFiber.child.stateNode);
  12065. default:
  12066. return containerFiber.child.stateNode;
  12067. }
  12068. }
  12069. var shouldSuspendImpl = function (fiber) {
  12070. return false;
  12071. };
  12072. function shouldSuspend(fiber) {
  12073. return shouldSuspendImpl(fiber);
  12074. }
  12075. var overrideHookState = null;
  12076. var overrideProps = null;
  12077. var scheduleUpdate = null;
  12078. var setSuspenseHandler = null;
  12079. {
  12080. var copyWithSetImpl = function (obj, path, idx, value) {
  12081. if (idx >= path.length) {
  12082. return value;
  12083. }
  12084. var key = path[idx];
  12085. var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
  12086. updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
  12087. return updated;
  12088. };
  12089. var copyWithSet = function (obj, path, value) {
  12090. return copyWithSetImpl(obj, path, 0, value);
  12091. }; // Support DevTools editable values for useState and useReducer.
  12092. overrideHookState = function (fiber, id, path, value) {
  12093. // For now, the "id" of stateful hooks is just the stateful hook index.
  12094. // This may change in the future with e.g. nested hooks.
  12095. var currentHook = fiber.memoizedState;
  12096. while (currentHook !== null && id > 0) {
  12097. currentHook = currentHook.next;
  12098. id--;
  12099. }
  12100. if (currentHook !== null) {
  12101. var newState = copyWithSet(currentHook.memoizedState, path, value);
  12102. currentHook.memoizedState = newState;
  12103. currentHook.baseState = newState; // We aren't actually adding an update to the queue,
  12104. // because there is no update we can add for useReducer hooks that won't trigger an error.
  12105. // (There's no appropriate action type for DevTools overrides.)
  12106. // As a result though, React will see the scheduled update as a noop and bailout.
  12107. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  12108. fiber.memoizedProps = _assign({}, fiber.memoizedProps);
  12109. scheduleWork(fiber, Sync);
  12110. }
  12111. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  12112. overrideProps = function (fiber, path, value) {
  12113. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  12114. if (fiber.alternate) {
  12115. fiber.alternate.pendingProps = fiber.pendingProps;
  12116. }
  12117. scheduleWork(fiber, Sync);
  12118. };
  12119. scheduleUpdate = function (fiber) {
  12120. scheduleWork(fiber, Sync);
  12121. };
  12122. setSuspenseHandler = function (newShouldSuspendImpl) {
  12123. shouldSuspendImpl = newShouldSuspendImpl;
  12124. };
  12125. }
  12126. function injectIntoDevTools(devToolsConfig) {
  12127. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  12128. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  12129. return injectInternals(_assign({}, devToolsConfig, {
  12130. overrideHookState: overrideHookState,
  12131. overrideProps: overrideProps,
  12132. setSuspenseHandler: setSuspenseHandler,
  12133. scheduleUpdate: scheduleUpdate,
  12134. currentDispatcherRef: ReactCurrentDispatcher,
  12135. findHostInstanceByFiber: function (fiber) {
  12136. var hostFiber = findCurrentHostFiber(fiber);
  12137. if (hostFiber === null) {
  12138. return null;
  12139. }
  12140. return hostFiber.stateNode;
  12141. },
  12142. findFiberByHostInstance: function (instance) {
  12143. if (!findFiberByHostInstance) {
  12144. // Might not be implemented by the renderer.
  12145. return null;
  12146. }
  12147. return findFiberByHostInstance(instance);
  12148. },
  12149. // React Refresh
  12150. findHostInstancesForRefresh: findHostInstancesForRefresh ,
  12151. scheduleRefresh: scheduleRefresh ,
  12152. scheduleRoot: scheduleRoot ,
  12153. setRefreshHandler: setRefreshHandler ,
  12154. // Enables DevTools to append owner stacks to error messages in DEV mode.
  12155. getCurrentFiber: function () {
  12156. return current;
  12157. }
  12158. }));
  12159. }
  12160. var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing;
  12161. var isSchedulerMocked = typeof Scheduler$1.unstable_flushAllWithoutAsserting === 'function';
  12162. var flushWork = Scheduler$1.unstable_flushAllWithoutAsserting || function () {
  12163. var didFlushWork = false;
  12164. while (flushPassiveEffects()) {
  12165. didFlushWork = true;
  12166. }
  12167. return didFlushWork;
  12168. };
  12169. function flushWorkAndMicroTasks(onDone) {
  12170. try {
  12171. flushWork();
  12172. enqueueTask(function () {
  12173. if (flushWork()) {
  12174. flushWorkAndMicroTasks(onDone);
  12175. } else {
  12176. onDone();
  12177. }
  12178. });
  12179. } catch (err) {
  12180. onDone(err);
  12181. }
  12182. } // we track the 'depth' of the act() calls with this counter,
  12183. // so we can tell if any async act() calls try to run in parallel.
  12184. var actingUpdatesScopeDepth = 0;
  12185. function act(callback) {
  12186. var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
  12187. var previousIsSomeRendererActing;
  12188. var previousIsThisRendererActing;
  12189. actingUpdatesScopeDepth++;
  12190. previousIsSomeRendererActing = IsSomeRendererActing$1.current;
  12191. previousIsThisRendererActing = IsThisRendererActing.current;
  12192. IsSomeRendererActing$1.current = true;
  12193. IsThisRendererActing.current = true;
  12194. function onDone() {
  12195. actingUpdatesScopeDepth--;
  12196. IsSomeRendererActing$1.current = previousIsSomeRendererActing;
  12197. IsThisRendererActing.current = previousIsThisRendererActing;
  12198. {
  12199. if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
  12200. // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
  12201. error('You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
  12202. }
  12203. }
  12204. }
  12205. var result;
  12206. try {
  12207. result = batchedUpdates(callback);
  12208. } catch (error) {
  12209. // on sync errors, we still want to 'cleanup' and decrement actingUpdatesScopeDepth
  12210. onDone();
  12211. throw error;
  12212. }
  12213. if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
  12214. // setup a boolean that gets set to true only
  12215. // once this act() call is await-ed
  12216. var called = false;
  12217. {
  12218. if (typeof Promise !== 'undefined') {
  12219. //eslint-disable-next-line no-undef
  12220. Promise.resolve().then(function () {}).then(function () {
  12221. if (called === false) {
  12222. 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 () => ...);');
  12223. }
  12224. });
  12225. }
  12226. } // in the async case, the returned thenable runs the callback, flushes
  12227. // effects and microtasks in a loop until flushPassiveEffects() === false,
  12228. // and cleans up
  12229. return {
  12230. then: function (resolve, reject) {
  12231. called = true;
  12232. result.then(function () {
  12233. if (actingUpdatesScopeDepth > 1 || isSchedulerMocked === true && previousIsSomeRendererActing === true) {
  12234. onDone();
  12235. resolve();
  12236. return;
  12237. } // we're about to exit the act() scope,
  12238. // now's the time to flush tasks/effects
  12239. flushWorkAndMicroTasks(function (err) {
  12240. onDone();
  12241. if (err) {
  12242. reject(err);
  12243. } else {
  12244. resolve();
  12245. }
  12246. });
  12247. }, function (err) {
  12248. onDone();
  12249. reject(err);
  12250. });
  12251. }
  12252. };
  12253. } else {
  12254. {
  12255. if (result !== undefined) {
  12256. error('The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result);
  12257. }
  12258. } // flush effects until none remain, and cleanup
  12259. try {
  12260. if (actingUpdatesScopeDepth === 1 && (isSchedulerMocked === false || previousIsSomeRendererActing === false)) {
  12261. // we're about to exit the act() scope,
  12262. // now's the time to flush effects
  12263. flushWork();
  12264. }
  12265. onDone();
  12266. } catch (err) {
  12267. onDone();
  12268. throw err;
  12269. } // in the sync case, the returned thenable only warns *if* await-ed
  12270. return {
  12271. then: function (resolve) {
  12272. {
  12273. error('Do not await the result of calling act(...) with sync logic, it is not a Promise.');
  12274. }
  12275. resolve();
  12276. }
  12277. };
  12278. }
  12279. }
  12280. var ReactVersion = '16.13.1';
  12281. var defaultTestOptions = {
  12282. createNodeMock: function () {
  12283. return null;
  12284. }
  12285. };
  12286. function toJSON(inst) {
  12287. if (inst.isHidden) {
  12288. // Omit timed out children from output entirely. This seems like the least
  12289. // surprising behavior. We could perhaps add a separate API that includes
  12290. // them, if it turns out people need it.
  12291. return null;
  12292. }
  12293. switch (inst.tag) {
  12294. case 'TEXT':
  12295. return inst.text;
  12296. case 'INSTANCE':
  12297. {
  12298. /* eslint-disable no-unused-vars */
  12299. // We don't include the `children` prop in JSON.
  12300. // Instead, we will include the actual rendered children.
  12301. var _inst$props = inst.props,
  12302. children = _inst$props.children,
  12303. props = _objectWithoutPropertiesLoose(_inst$props, ["children"]);
  12304. /* eslint-enable */
  12305. var renderedChildren = null;
  12306. if (inst.children && inst.children.length) {
  12307. for (var i = 0; i < inst.children.length; i++) {
  12308. var renderedChild = toJSON(inst.children[i]);
  12309. if (renderedChild !== null) {
  12310. if (renderedChildren === null) {
  12311. renderedChildren = [renderedChild];
  12312. } else {
  12313. renderedChildren.push(renderedChild);
  12314. }
  12315. }
  12316. }
  12317. }
  12318. var json = {
  12319. type: inst.type,
  12320. props: props,
  12321. children: renderedChildren
  12322. };
  12323. Object.defineProperty(json, '$$typeof', {
  12324. value: Symbol.for('react.test.json')
  12325. });
  12326. return json;
  12327. }
  12328. default:
  12329. throw new Error("Unexpected node type in toJSON: " + inst.tag);
  12330. }
  12331. }
  12332. function childrenToTree(node) {
  12333. if (!node) {
  12334. return null;
  12335. }
  12336. var children = nodeAndSiblingsArray(node);
  12337. if (children.length === 0) {
  12338. return null;
  12339. } else if (children.length === 1) {
  12340. return toTree(children[0]);
  12341. }
  12342. return flatten(children.map(toTree));
  12343. }
  12344. function nodeAndSiblingsArray(nodeWithSibling) {
  12345. var array = [];
  12346. var node = nodeWithSibling;
  12347. while (node != null) {
  12348. array.push(node);
  12349. node = node.sibling;
  12350. }
  12351. return array;
  12352. }
  12353. function flatten(arr) {
  12354. var result = [];
  12355. var stack = [{
  12356. i: 0,
  12357. array: arr
  12358. }];
  12359. while (stack.length) {
  12360. var n = stack.pop();
  12361. while (n.i < n.array.length) {
  12362. var el = n.array[n.i];
  12363. n.i += 1;
  12364. if (Array.isArray(el)) {
  12365. stack.push(n);
  12366. stack.push({
  12367. i: 0,
  12368. array: el
  12369. });
  12370. break;
  12371. }
  12372. result.push(el);
  12373. }
  12374. }
  12375. return result;
  12376. }
  12377. function toTree(node) {
  12378. if (node == null) {
  12379. return null;
  12380. }
  12381. switch (node.tag) {
  12382. case HostRoot:
  12383. return childrenToTree(node.child);
  12384. case HostPortal:
  12385. return childrenToTree(node.child);
  12386. case ClassComponent:
  12387. return {
  12388. nodeType: 'component',
  12389. type: node.type,
  12390. props: _assign({}, node.memoizedProps),
  12391. instance: node.stateNode,
  12392. rendered: childrenToTree(node.child)
  12393. };
  12394. case FunctionComponent:
  12395. case SimpleMemoComponent:
  12396. return {
  12397. nodeType: 'component',
  12398. type: node.type,
  12399. props: _assign({}, node.memoizedProps),
  12400. instance: null,
  12401. rendered: childrenToTree(node.child)
  12402. };
  12403. case Block:
  12404. return {
  12405. nodeType: 'block',
  12406. type: node.type,
  12407. props: _assign({}, node.memoizedProps),
  12408. instance: null,
  12409. rendered: childrenToTree(node.child)
  12410. };
  12411. case HostComponent:
  12412. {
  12413. return {
  12414. nodeType: 'host',
  12415. type: node.type,
  12416. props: _assign({}, node.memoizedProps),
  12417. instance: null,
  12418. // TODO: use createNodeMock here somehow?
  12419. rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
  12420. };
  12421. }
  12422. case HostText:
  12423. return node.stateNode.text;
  12424. case Fragment:
  12425. case ContextProvider:
  12426. case ContextConsumer:
  12427. case Mode:
  12428. case Profiler:
  12429. case ForwardRef:
  12430. case MemoComponent:
  12431. case IncompleteClassComponent:
  12432. case ScopeComponent:
  12433. return childrenToTree(node.child);
  12434. default:
  12435. {
  12436. {
  12437. throw Error( "toTree() does not yet know how to handle nodes with tag=" + node.tag );
  12438. }
  12439. }
  12440. }
  12441. }
  12442. var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent, Block, // Normally skipped, but used when there's more than one root child.
  12443. HostRoot]);
  12444. function getChildren(parent) {
  12445. var children = [];
  12446. var startingNode = parent;
  12447. var node = startingNode;
  12448. if (node.child === null) {
  12449. return children;
  12450. }
  12451. node.child.return = node;
  12452. node = node.child;
  12453. outer: while (true) {
  12454. var descend = false;
  12455. if (validWrapperTypes.has(node.tag)) {
  12456. children.push(wrapFiber(node));
  12457. } else if (node.tag === HostText) {
  12458. children.push('' + node.memoizedProps);
  12459. } else {
  12460. descend = true;
  12461. }
  12462. if (descend && node.child !== null) {
  12463. node.child.return = node;
  12464. node = node.child;
  12465. continue;
  12466. }
  12467. while (node.sibling === null) {
  12468. if (node.return === startingNode) {
  12469. break outer;
  12470. }
  12471. node = node.return;
  12472. }
  12473. node.sibling.return = node.return;
  12474. node = node.sibling;
  12475. }
  12476. return children;
  12477. }
  12478. var ReactTestInstance =
  12479. /*#__PURE__*/
  12480. function () {
  12481. var _proto = ReactTestInstance.prototype;
  12482. _proto._currentFiber = function _currentFiber() {
  12483. // Throws if this component has been unmounted.
  12484. var fiber = findCurrentFiberUsingSlowPath(this._fiber);
  12485. if (!(fiber !== null)) {
  12486. {
  12487. throw Error( "Can't read from currently-mounting component. This error is likely caused by a bug in React. Please file an issue." );
  12488. }
  12489. }
  12490. return fiber;
  12491. };
  12492. function ReactTestInstance(fiber) {
  12493. if (!validWrapperTypes.has(fiber.tag)) {
  12494. {
  12495. throw Error( "Unexpected object passed to ReactTestInstance constructor (tag: " + fiber.tag + "). This is probably a bug in React." );
  12496. }
  12497. }
  12498. this._fiber = fiber;
  12499. }
  12500. // Custom search functions
  12501. _proto.find = function find(predicate) {
  12502. return expectOne(this.findAll(predicate, {
  12503. deep: false
  12504. }), "matching custom predicate: " + predicate.toString());
  12505. };
  12506. _proto.findByType = function findByType(type) {
  12507. return expectOne(this.findAllByType(type, {
  12508. deep: false
  12509. }), "with node type: \"" + (type.displayName || type.name) + "\"");
  12510. };
  12511. _proto.findByProps = function findByProps(props) {
  12512. return expectOne(this.findAllByProps(props, {
  12513. deep: false
  12514. }), "with props: " + JSON.stringify(props));
  12515. };
  12516. _proto.findAll = function findAll(predicate) {
  12517. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12518. return _findAll(this, predicate, options);
  12519. };
  12520. _proto.findAllByType = function findAllByType(type) {
  12521. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12522. return _findAll(this, function (node) {
  12523. return node.type === type;
  12524. }, options);
  12525. };
  12526. _proto.findAllByProps = function findAllByProps(props) {
  12527. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12528. return _findAll(this, function (node) {
  12529. return node.props && propsMatch(node.props, props);
  12530. }, options);
  12531. };
  12532. _createClass(ReactTestInstance, [{
  12533. key: "instance",
  12534. get: function () {
  12535. if (this._fiber.tag === HostComponent) {
  12536. return getPublicInstance(this._fiber.stateNode);
  12537. } else {
  12538. return this._fiber.stateNode;
  12539. }
  12540. }
  12541. }, {
  12542. key: "type",
  12543. get: function () {
  12544. return this._fiber.type;
  12545. }
  12546. }, {
  12547. key: "props",
  12548. get: function () {
  12549. return this._currentFiber().memoizedProps;
  12550. }
  12551. }, {
  12552. key: "parent",
  12553. get: function () {
  12554. var parent = this._fiber.return;
  12555. while (parent !== null) {
  12556. if (validWrapperTypes.has(parent.tag)) {
  12557. if (parent.tag === HostRoot) {
  12558. // Special case: we only "materialize" instances for roots
  12559. // if they have more than a single child. So we'll check that now.
  12560. if (getChildren(parent).length < 2) {
  12561. return null;
  12562. }
  12563. }
  12564. return wrapFiber(parent);
  12565. }
  12566. parent = parent.return;
  12567. }
  12568. return null;
  12569. }
  12570. }, {
  12571. key: "children",
  12572. get: function () {
  12573. return getChildren(this._currentFiber());
  12574. }
  12575. }]);
  12576. return ReactTestInstance;
  12577. }();
  12578. function _findAll(root, predicate, options) {
  12579. var deep = options ? options.deep : true;
  12580. var results = [];
  12581. if (predicate(root)) {
  12582. results.push(root);
  12583. if (!deep) {
  12584. return results;
  12585. }
  12586. }
  12587. root.children.forEach(function (child) {
  12588. if (typeof child === 'string') {
  12589. return;
  12590. }
  12591. results.push.apply(results, _findAll(child, predicate, options));
  12592. });
  12593. return results;
  12594. }
  12595. function expectOne(all, message) {
  12596. if (all.length === 1) {
  12597. return all[0];
  12598. }
  12599. var prefix = all.length === 0 ? 'No instances found ' : "Expected 1 but found " + all.length + " instances ";
  12600. throw new Error(prefix + message);
  12601. }
  12602. function propsMatch(props, filter) {
  12603. for (var key in filter) {
  12604. if (props[key] !== filter[key]) {
  12605. return false;
  12606. }
  12607. }
  12608. return true;
  12609. }
  12610. var ReactTestRendererFiber = {
  12611. _Scheduler: Scheduler,
  12612. create: function (element, options) {
  12613. var createNodeMock = defaultTestOptions.createNodeMock;
  12614. var isConcurrent = false;
  12615. if (typeof options === 'object' && options !== null) {
  12616. if (typeof options.createNodeMock === 'function') {
  12617. createNodeMock = options.createNodeMock;
  12618. }
  12619. if (options.unstable_isConcurrent === true) {
  12620. isConcurrent = true;
  12621. }
  12622. }
  12623. var container = {
  12624. children: [],
  12625. createNodeMock: createNodeMock,
  12626. tag: 'CONTAINER'
  12627. };
  12628. var root = createContainer(container, isConcurrent ? ConcurrentRoot : LegacyRoot, false);
  12629. if (!(root != null)) {
  12630. {
  12631. throw Error( "something went wrong" );
  12632. }
  12633. }
  12634. updateContainer(element, root, null, null);
  12635. var entry = {
  12636. _Scheduler: Scheduler,
  12637. root: undefined,
  12638. // makes flow happy
  12639. // we define a 'getter' for 'root' below using 'Object.defineProperty'
  12640. toJSON: function () {
  12641. if (root == null || root.current == null || container == null) {
  12642. return null;
  12643. }
  12644. if (container.children.length === 0) {
  12645. return null;
  12646. }
  12647. if (container.children.length === 1) {
  12648. return toJSON(container.children[0]);
  12649. }
  12650. if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
  12651. // Omit timed out children from output entirely, including the fact that we
  12652. // temporarily wrap fallback and timed out children in an array.
  12653. return toJSON(container.children[1]);
  12654. }
  12655. var renderedChildren = null;
  12656. if (container.children && container.children.length) {
  12657. for (var i = 0; i < container.children.length; i++) {
  12658. var renderedChild = toJSON(container.children[i]);
  12659. if (renderedChild !== null) {
  12660. if (renderedChildren === null) {
  12661. renderedChildren = [renderedChild];
  12662. } else {
  12663. renderedChildren.push(renderedChild);
  12664. }
  12665. }
  12666. }
  12667. }
  12668. return renderedChildren;
  12669. },
  12670. toTree: function () {
  12671. if (root == null || root.current == null) {
  12672. return null;
  12673. }
  12674. return toTree(root.current);
  12675. },
  12676. update: function (newElement) {
  12677. if (root == null || root.current == null) {
  12678. return;
  12679. }
  12680. updateContainer(newElement, root, null, null);
  12681. },
  12682. unmount: function () {
  12683. if (root == null || root.current == null) {
  12684. return;
  12685. }
  12686. updateContainer(null, root, null, null);
  12687. container = null;
  12688. root = null;
  12689. },
  12690. getInstance: function () {
  12691. if (root == null || root.current == null) {
  12692. return null;
  12693. }
  12694. return getPublicRootInstance(root);
  12695. },
  12696. unstable_flushSync: function (fn) {
  12697. return flushSync(fn);
  12698. }
  12699. };
  12700. Object.defineProperty(entry, 'root', {
  12701. configurable: true,
  12702. enumerable: true,
  12703. get: function () {
  12704. if (root === null) {
  12705. throw new Error("Can't access .root on unmounted test renderer");
  12706. }
  12707. var children = getChildren(root.current);
  12708. if (children.length === 0) {
  12709. throw new Error("Can't access .root on unmounted test renderer");
  12710. } else if (children.length === 1) {
  12711. // Normally, we skip the root and just give you the child.
  12712. return children[0];
  12713. } else {
  12714. // However, we give you the root if there's more than one root child.
  12715. // We could make this the behavior for all cases but it would be a breaking change.
  12716. return wrapFiber(root.current);
  12717. }
  12718. }
  12719. });
  12720. return entry;
  12721. },
  12722. /* eslint-disable-next-line camelcase */
  12723. unstable_batchedUpdates: batchedUpdates,
  12724. act: act
  12725. };
  12726. var fiberToWrapper = new WeakMap();
  12727. function wrapFiber(fiber) {
  12728. var wrapper = fiberToWrapper.get(fiber);
  12729. if (wrapper === undefined && fiber.alternate !== null) {
  12730. wrapper = fiberToWrapper.get(fiber.alternate);
  12731. }
  12732. if (wrapper === undefined) {
  12733. wrapper = new ReactTestInstance(fiber);
  12734. fiberToWrapper.set(fiber, wrapper);
  12735. }
  12736. return wrapper;
  12737. } // Enable ReactTestRenderer to be used to test DevTools integration.
  12738. injectIntoDevTools({
  12739. findFiberByHostInstance: function () {
  12740. throw new Error('TestRenderer does not support findFiberByHostInstance()');
  12741. },
  12742. bundleType: 1 ,
  12743. version: ReactVersion,
  12744. rendererPackageName: 'react-test-renderer'
  12745. });
  12746. // TODO: decide on the top-level export form.
  12747. // This is hacky but makes it work with both Rollup and Jest.
  12748. var reactTestRenderer = ReactTestRendererFiber.default || ReactTestRendererFiber;
  12749. module.exports = reactTestRenderer;
  12750. })();
  12751. }