react-dom.development.js 1002 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868
  1. /**
  2. * @license React
  3. * react-dom.development.js
  4. *
  5. * Copyright (c) Facebook, Inc. and its affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */
  10. 'use strict';
  11. if (process.env.NODE_ENV !== "production") {
  12. (function() {
  13. 'use strict';
  14. /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  15. if (
  16. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
  17. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
  18. 'function'
  19. ) {
  20. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
  21. }
  22. var React = require('react');
  23. var Scheduler = require('scheduler');
  24. var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  25. var suppressWarning = false;
  26. function setSuppressWarning(newSuppressWarning) {
  27. {
  28. suppressWarning = newSuppressWarning;
  29. }
  30. } // In DEV, calls to console.warn and console.error get replaced
  31. // by calls to these methods by a Babel plugin.
  32. //
  33. // In PROD (or in packages without access to React internals),
  34. // they are left as they are instead.
  35. function warn(format) {
  36. {
  37. if (!suppressWarning) {
  38. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  39. args[_key - 1] = arguments[_key];
  40. }
  41. printWarning('warn', format, args);
  42. }
  43. }
  44. }
  45. function error(format) {
  46. {
  47. if (!suppressWarning) {
  48. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  49. args[_key2 - 1] = arguments[_key2];
  50. }
  51. printWarning('error', format, args);
  52. }
  53. }
  54. }
  55. function printWarning(level, format, args) {
  56. // When changing this logic, you might want to also
  57. // update consoleWithStackDev.www.js as well.
  58. {
  59. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  60. var stack = ReactDebugCurrentFrame.getStackAddendum();
  61. if (stack !== '') {
  62. format += '%s';
  63. args = args.concat([stack]);
  64. } // eslint-disable-next-line react-internal/safe-string-coercion
  65. var argsWithFormat = args.map(function (item) {
  66. return String(item);
  67. }); // Careful: RN currently depends on this prefix
  68. argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
  69. // breaks IE9: https://github.com/facebook/react/issues/13610
  70. // eslint-disable-next-line react-internal/no-production-logging
  71. Function.prototype.apply.call(console[level], console, argsWithFormat);
  72. }
  73. }
  74. var FunctionComponent = 0;
  75. var ClassComponent = 1;
  76. var IndeterminateComponent = 2; // Before we know whether it is function or class
  77. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  78. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  79. var HostComponent = 5;
  80. var HostText = 6;
  81. var Fragment = 7;
  82. var Mode = 8;
  83. var ContextConsumer = 9;
  84. var ContextProvider = 10;
  85. var ForwardRef = 11;
  86. var Profiler = 12;
  87. var SuspenseComponent = 13;
  88. var MemoComponent = 14;
  89. var SimpleMemoComponent = 15;
  90. var LazyComponent = 16;
  91. var IncompleteClassComponent = 17;
  92. var DehydratedFragment = 18;
  93. var SuspenseListComponent = 19;
  94. var ScopeComponent = 21;
  95. var OffscreenComponent = 22;
  96. var LegacyHiddenComponent = 23;
  97. var CacheComponent = 24;
  98. var TracingMarkerComponent = 25;
  99. // -----------------------------------------------------------------------------
  100. var enableClientRenderFallbackOnTextMismatch = true; // TODO: Need to review this code one more time before landing
  101. // the react-reconciler package.
  102. var enableNewReconciler = false; // Support legacy Primer support on internal FB www
  103. var enableLazyContextPropagation = false; // FB-only usage. The new API has different semantics.
  104. var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
  105. var enableSuspenseAvoidThisFallback = false; // Enables unstable_avoidThisFallback feature in Fizz
  106. // React DOM Chopping Block
  107. //
  108. // Similar to main Chopping Block but only flags related to React DOM. These are
  109. // grouped because we will likely batch all of them into a single major release.
  110. // -----------------------------------------------------------------------------
  111. // Disable support for comment nodes as React DOM containers. Already disabled
  112. // in open source, but www codebase still relies on it. Need to remove.
  113. var disableCommentsAsDOMContainers = true; // Disable javascript: URL strings in href for XSS protection.
  114. // and client rendering, mostly to allow JSX attributes to apply to the custom
  115. // element's object properties instead of only HTML attributes.
  116. // https://github.com/facebook/react/issues/11347
  117. var enableCustomElementPropertySupport = false; // Disables children for <textarea> elements
  118. var warnAboutStringRefs = false; // -----------------------------------------------------------------------------
  119. // Debugging and DevTools
  120. // -----------------------------------------------------------------------------
  121. // Adds user timing marks for e.g. state updates, suspense, and work loop stuff,
  122. // for an experimental timeline tool.
  123. var enableSchedulingProfiler = true; // Helps identify side effects in render-phase lifecycle hooks and setState
  124. var enableProfilerTimer = true; // Record durations for commit and passive effects phases.
  125. var enableProfilerCommitHooks = true; // Phase param passed to onRender callback differentiates between an "update" and a "cascading-update".
  126. var allNativeEvents = new Set();
  127. /**
  128. * Mapping from registration name to event name
  129. */
  130. var registrationNameDependencies = {};
  131. /**
  132. * Mapping from lowercase registration names to the properly cased version,
  133. * used to warn in the case of missing event handlers. Available
  134. * only in true.
  135. * @type {Object}
  136. */
  137. var possibleRegistrationNames = {} ; // Trust the developer to only use possibleRegistrationNames in true
  138. function registerTwoPhaseEvent(registrationName, dependencies) {
  139. registerDirectEvent(registrationName, dependencies);
  140. registerDirectEvent(registrationName + 'Capture', dependencies);
  141. }
  142. function registerDirectEvent(registrationName, dependencies) {
  143. {
  144. if (registrationNameDependencies[registrationName]) {
  145. error('EventRegistry: More than one plugin attempted to publish the same ' + 'registration name, `%s`.', registrationName);
  146. }
  147. }
  148. registrationNameDependencies[registrationName] = dependencies;
  149. {
  150. var lowerCasedName = registrationName.toLowerCase();
  151. possibleRegistrationNames[lowerCasedName] = registrationName;
  152. if (registrationName === 'onDoubleClick') {
  153. possibleRegistrationNames.ondblclick = registrationName;
  154. }
  155. }
  156. for (var i = 0; i < dependencies.length; i++) {
  157. allNativeEvents.add(dependencies[i]);
  158. }
  159. }
  160. var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
  161. var hasOwnProperty = Object.prototype.hasOwnProperty;
  162. /*
  163. * The `'' + value` pattern (used in in perf-sensitive code) throws for Symbol
  164. * and Temporal.* types. See https://github.com/facebook/react/pull/22064.
  165. *
  166. * The functions in this module will throw an easier-to-understand,
  167. * easier-to-debug exception with a clear errors message message explaining the
  168. * problem. (Instead of a confusing exception thrown inside the implementation
  169. * of the `value` object).
  170. */
  171. // $FlowFixMe only called in DEV, so void return is not possible.
  172. function typeName(value) {
  173. {
  174. // toStringTag is needed for namespaced types like Temporal.Instant
  175. var hasToStringTag = typeof Symbol === 'function' && Symbol.toStringTag;
  176. var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || 'Object';
  177. return type;
  178. }
  179. } // $FlowFixMe only called in DEV, so void return is not possible.
  180. function willCoercionThrow(value) {
  181. {
  182. try {
  183. testStringCoercion(value);
  184. return false;
  185. } catch (e) {
  186. return true;
  187. }
  188. }
  189. }
  190. function testStringCoercion(value) {
  191. // If you ended up here by following an exception call stack, here's what's
  192. // happened: you supplied an object or symbol value to React (as a prop, key,
  193. // DOM attribute, CSS property, string ref, etc.) and when React tried to
  194. // coerce it to a string using `'' + value`, an exception was thrown.
  195. //
  196. // The most common types that will cause this exception are `Symbol` instances
  197. // and Temporal objects like `Temporal.Instant`. But any object that has a
  198. // `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
  199. // exception. (Library authors do this to prevent users from using built-in
  200. // numeric operators like `+` or comparison operators like `>=` because custom
  201. // methods are needed to perform accurate arithmetic or comparison.)
  202. //
  203. // To fix the problem, coerce this object or symbol value to a string before
  204. // passing it to React. The most reliable way is usually `String(value)`.
  205. //
  206. // To find which value is throwing, check the browser or debugger console.
  207. // Before this exception was thrown, there should be `console.error` output
  208. // that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
  209. // problem and how that type was used: key, atrribute, input value prop, etc.
  210. // In most cases, this console output also shows the component and its
  211. // ancestor components where the exception happened.
  212. //
  213. // eslint-disable-next-line react-internal/safe-string-coercion
  214. return '' + value;
  215. }
  216. function checkAttributeStringCoercion(value, attributeName) {
  217. {
  218. if (willCoercionThrow(value)) {
  219. error('The provided `%s` attribute is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', attributeName, typeName(value));
  220. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  221. }
  222. }
  223. }
  224. function checkKeyStringCoercion(value) {
  225. {
  226. if (willCoercionThrow(value)) {
  227. error('The provided key is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
  228. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  229. }
  230. }
  231. }
  232. function checkPropStringCoercion(value, propName) {
  233. {
  234. if (willCoercionThrow(value)) {
  235. error('The provided `%s` prop is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', propName, typeName(value));
  236. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  237. }
  238. }
  239. }
  240. function checkCSSPropertyStringCoercion(value, propName) {
  241. {
  242. if (willCoercionThrow(value)) {
  243. error('The provided `%s` CSS property is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', propName, typeName(value));
  244. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  245. }
  246. }
  247. }
  248. function checkHtmlStringCoercion(value) {
  249. {
  250. if (willCoercionThrow(value)) {
  251. error('The provided HTML markup uses a value of unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
  252. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  253. }
  254. }
  255. }
  256. function checkFormFieldValueStringCoercion(value) {
  257. {
  258. if (willCoercionThrow(value)) {
  259. error('Form field values (value, checked, defaultValue, or defaultChecked props)' + ' must be strings, not %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
  260. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  261. }
  262. }
  263. }
  264. // A reserved attribute.
  265. // It is handled by React separately and shouldn't be written to the DOM.
  266. var RESERVED = 0; // A simple string attribute.
  267. // Attributes that aren't in the filter are presumed to have this type.
  268. var STRING = 1; // A string attribute that accepts booleans in React. In HTML, these are called
  269. // "enumerated" attributes with "true" and "false" as possible values.
  270. // When true, it should be set to a "true" string.
  271. // When false, it should be set to a "false" string.
  272. var BOOLEANISH_STRING = 2; // A real boolean attribute.
  273. // When true, it should be present (set either to an empty string or its name).
  274. // When false, it should be omitted.
  275. var BOOLEAN = 3; // An attribute that can be used as a flag as well as with a value.
  276. // When true, it should be present (set either to an empty string or its name).
  277. // When false, it should be omitted.
  278. // For any other value, should be present with that value.
  279. var OVERLOADED_BOOLEAN = 4; // An attribute that must be numeric or parse as a numeric.
  280. // When falsy, it should be removed.
  281. var NUMERIC = 5; // An attribute that must be positive numeric or parse as a positive numeric.
  282. // When falsy, it should be removed.
  283. var POSITIVE_NUMERIC = 6;
  284. /* eslint-disable max-len */
  285. var ATTRIBUTE_NAME_START_CHAR = ":A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
  286. /* eslint-enable max-len */
  287. var ATTRIBUTE_NAME_CHAR = ATTRIBUTE_NAME_START_CHAR + "\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
  288. var VALID_ATTRIBUTE_NAME_REGEX = new RegExp('^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$');
  289. var illegalAttributeNameCache = {};
  290. var validatedAttributeNameCache = {};
  291. function isAttributeNameSafe(attributeName) {
  292. if (hasOwnProperty.call(validatedAttributeNameCache, attributeName)) {
  293. return true;
  294. }
  295. if (hasOwnProperty.call(illegalAttributeNameCache, attributeName)) {
  296. return false;
  297. }
  298. if (VALID_ATTRIBUTE_NAME_REGEX.test(attributeName)) {
  299. validatedAttributeNameCache[attributeName] = true;
  300. return true;
  301. }
  302. illegalAttributeNameCache[attributeName] = true;
  303. {
  304. error('Invalid attribute name: `%s`', attributeName);
  305. }
  306. return false;
  307. }
  308. function shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag) {
  309. if (propertyInfo !== null) {
  310. return propertyInfo.type === RESERVED;
  311. }
  312. if (isCustomComponentTag) {
  313. return false;
  314. }
  315. if (name.length > 2 && (name[0] === 'o' || name[0] === 'O') && (name[1] === 'n' || name[1] === 'N')) {
  316. return true;
  317. }
  318. return false;
  319. }
  320. function shouldRemoveAttributeWithWarning(name, value, propertyInfo, isCustomComponentTag) {
  321. if (propertyInfo !== null && propertyInfo.type === RESERVED) {
  322. return false;
  323. }
  324. switch (typeof value) {
  325. case 'function': // $FlowIssue symbol is perfectly valid here
  326. case 'symbol':
  327. // eslint-disable-line
  328. return true;
  329. case 'boolean':
  330. {
  331. if (isCustomComponentTag) {
  332. return false;
  333. }
  334. if (propertyInfo !== null) {
  335. return !propertyInfo.acceptsBooleans;
  336. } else {
  337. var prefix = name.toLowerCase().slice(0, 5);
  338. return prefix !== 'data-' && prefix !== 'aria-';
  339. }
  340. }
  341. default:
  342. return false;
  343. }
  344. }
  345. function shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag) {
  346. if (value === null || typeof value === 'undefined') {
  347. return true;
  348. }
  349. if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, isCustomComponentTag)) {
  350. return true;
  351. }
  352. if (isCustomComponentTag) {
  353. return false;
  354. }
  355. if (propertyInfo !== null) {
  356. switch (propertyInfo.type) {
  357. case BOOLEAN:
  358. return !value;
  359. case OVERLOADED_BOOLEAN:
  360. return value === false;
  361. case NUMERIC:
  362. return isNaN(value);
  363. case POSITIVE_NUMERIC:
  364. return isNaN(value) || value < 1;
  365. }
  366. }
  367. return false;
  368. }
  369. function getPropertyInfo(name) {
  370. return properties.hasOwnProperty(name) ? properties[name] : null;
  371. }
  372. function PropertyInfoRecord(name, type, mustUseProperty, attributeName, attributeNamespace, sanitizeURL, removeEmptyString) {
  373. this.acceptsBooleans = type === BOOLEANISH_STRING || type === BOOLEAN || type === OVERLOADED_BOOLEAN;
  374. this.attributeName = attributeName;
  375. this.attributeNamespace = attributeNamespace;
  376. this.mustUseProperty = mustUseProperty;
  377. this.propertyName = name;
  378. this.type = type;
  379. this.sanitizeURL = sanitizeURL;
  380. this.removeEmptyString = removeEmptyString;
  381. } // When adding attributes to this list, be sure to also add them to
  382. // the `possibleStandardNames` module to ensure casing and incorrect
  383. // name warnings.
  384. var properties = {}; // These props are reserved by React. They shouldn't be written to the DOM.
  385. var reservedProps = ['children', 'dangerouslySetInnerHTML', // TODO: This prevents the assignment of defaultValue to regular
  386. // elements (not just inputs). Now that ReactDOMInput assigns to the
  387. // defaultValue property -- do we need this?
  388. 'defaultValue', 'defaultChecked', 'innerHTML', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'style'];
  389. reservedProps.forEach(function (name) {
  390. properties[name] = new PropertyInfoRecord(name, RESERVED, false, // mustUseProperty
  391. name, // attributeName
  392. null, // attributeNamespace
  393. false, // sanitizeURL
  394. false);
  395. }); // A few React string attributes have a different name.
  396. // This is a mapping from React prop names to the attribute names.
  397. [['acceptCharset', 'accept-charset'], ['className', 'class'], ['htmlFor', 'for'], ['httpEquiv', 'http-equiv']].forEach(function (_ref) {
  398. var name = _ref[0],
  399. attributeName = _ref[1];
  400. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  401. attributeName, // attributeName
  402. null, // attributeNamespace
  403. false, // sanitizeURL
  404. false);
  405. }); // These are "enumerated" HTML attributes that accept "true" and "false".
  406. // In React, we let users pass `true` and `false` even though technically
  407. // these aren't boolean attributes (they are coerced to strings).
  408. ['contentEditable', 'draggable', 'spellCheck', 'value'].forEach(function (name) {
  409. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  410. name.toLowerCase(), // attributeName
  411. null, // attributeNamespace
  412. false, // sanitizeURL
  413. false);
  414. }); // These are "enumerated" SVG attributes that accept "true" and "false".
  415. // In React, we let users pass `true` and `false` even though technically
  416. // these aren't boolean attributes (they are coerced to strings).
  417. // Since these are SVG attributes, their attribute names are case-sensitive.
  418. ['autoReverse', 'externalResourcesRequired', 'focusable', 'preserveAlpha'].forEach(function (name) {
  419. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  420. name, // attributeName
  421. null, // attributeNamespace
  422. false, // sanitizeURL
  423. false);
  424. }); // These are HTML boolean attributes.
  425. ['allowFullScreen', 'async', // Note: there is a special case that prevents it from being written to the DOM
  426. // on the client side because the browsers are inconsistent. Instead we call focus().
  427. 'autoFocus', 'autoPlay', 'controls', 'default', 'defer', 'disabled', 'disablePictureInPicture', 'disableRemotePlayback', 'formNoValidate', 'hidden', 'loop', 'noModule', 'noValidate', 'open', 'playsInline', 'readOnly', 'required', 'reversed', 'scoped', 'seamless', // Microdata
  428. 'itemScope'].forEach(function (name) {
  429. properties[name] = new PropertyInfoRecord(name, BOOLEAN, false, // mustUseProperty
  430. name.toLowerCase(), // attributeName
  431. null, // attributeNamespace
  432. false, // sanitizeURL
  433. false);
  434. }); // These are the few React props that we set as DOM properties
  435. // rather than attributes. These are all booleans.
  436. ['checked', // Note: `option.selected` is not updated if `select.multiple` is
  437. // disabled with `removeAttribute`. We have special logic for handling this.
  438. 'multiple', 'muted', 'selected' // NOTE: if you add a camelCased prop to this list,
  439. // you'll need to set attributeName to name.toLowerCase()
  440. // instead in the assignment below.
  441. ].forEach(function (name) {
  442. properties[name] = new PropertyInfoRecord(name, BOOLEAN, true, // mustUseProperty
  443. name, // attributeName
  444. null, // attributeNamespace
  445. false, // sanitizeURL
  446. false);
  447. }); // These are HTML attributes that are "overloaded booleans": they behave like
  448. // booleans, but can also accept a string value.
  449. ['capture', 'download' // NOTE: if you add a camelCased prop to this list,
  450. // you'll need to set attributeName to name.toLowerCase()
  451. // instead in the assignment below.
  452. ].forEach(function (name) {
  453. properties[name] = new PropertyInfoRecord(name, OVERLOADED_BOOLEAN, false, // mustUseProperty
  454. name, // attributeName
  455. null, // attributeNamespace
  456. false, // sanitizeURL
  457. false);
  458. }); // These are HTML attributes that must be positive numbers.
  459. ['cols', 'rows', 'size', 'span' // NOTE: if you add a camelCased prop to this list,
  460. // you'll need to set attributeName to name.toLowerCase()
  461. // instead in the assignment below.
  462. ].forEach(function (name) {
  463. properties[name] = new PropertyInfoRecord(name, POSITIVE_NUMERIC, false, // mustUseProperty
  464. name, // attributeName
  465. null, // attributeNamespace
  466. false, // sanitizeURL
  467. false);
  468. }); // These are HTML attributes that must be numbers.
  469. ['rowSpan', 'start'].forEach(function (name) {
  470. properties[name] = new PropertyInfoRecord(name, NUMERIC, false, // mustUseProperty
  471. name.toLowerCase(), // attributeName
  472. null, // attributeNamespace
  473. false, // sanitizeURL
  474. false);
  475. });
  476. var CAMELIZE = /[\-\:]([a-z])/g;
  477. var capitalize = function (token) {
  478. return token[1].toUpperCase();
  479. }; // This is a list of all SVG attributes that need special casing, namespacing,
  480. // or boolean value assignment. Regular attributes that just accept strings
  481. // and have the same names are omitted, just like in the HTML attribute filter.
  482. // Some of these attributes can be hard to find. This list was created by
  483. // scraping the MDN documentation.
  484. ['accent-height', 'alignment-baseline', 'arabic-form', 'baseline-shift', 'cap-height', 'clip-path', 'clip-rule', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'dominant-baseline', 'enable-background', 'fill-opacity', 'fill-rule', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-name', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'horiz-adv-x', 'horiz-origin-x', 'image-rendering', 'letter-spacing', 'lighting-color', 'marker-end', 'marker-mid', 'marker-start', 'overline-position', 'overline-thickness', 'paint-order', 'panose-1', 'pointer-events', 'rendering-intent', 'shape-rendering', 'stop-color', 'stop-opacity', 'strikethrough-position', 'strikethrough-thickness', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-decoration', 'text-rendering', 'underline-position', 'underline-thickness', 'unicode-bidi', 'unicode-range', 'units-per-em', 'v-alphabetic', 'v-hanging', 'v-ideographic', 'v-mathematical', 'vector-effect', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'word-spacing', 'writing-mode', 'xmlns:xlink', 'x-height' // NOTE: if you add a camelCased prop to this list,
  485. // you'll need to set attributeName to name.toLowerCase()
  486. // instead in the assignment below.
  487. ].forEach(function (attributeName) {
  488. var name = attributeName.replace(CAMELIZE, capitalize);
  489. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  490. attributeName, null, // attributeNamespace
  491. false, // sanitizeURL
  492. false);
  493. }); // String SVG attributes with the xlink namespace.
  494. ['xlink:actuate', 'xlink:arcrole', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type' // NOTE: if you add a camelCased prop to this list,
  495. // you'll need to set attributeName to name.toLowerCase()
  496. // instead in the assignment below.
  497. ].forEach(function (attributeName) {
  498. var name = attributeName.replace(CAMELIZE, capitalize);
  499. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  500. attributeName, 'http://www.w3.org/1999/xlink', false, // sanitizeURL
  501. false);
  502. }); // String SVG attributes with the xml namespace.
  503. ['xml:base', 'xml:lang', 'xml:space' // NOTE: if you add a camelCased prop to this list,
  504. // you'll need to set attributeName to name.toLowerCase()
  505. // instead in the assignment below.
  506. ].forEach(function (attributeName) {
  507. var name = attributeName.replace(CAMELIZE, capitalize);
  508. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  509. attributeName, 'http://www.w3.org/XML/1998/namespace', false, // sanitizeURL
  510. false);
  511. }); // These attribute exists both in HTML and SVG.
  512. // The attribute name is case-sensitive in SVG so we can't just use
  513. // the React name like we do for attributes that exist only in HTML.
  514. ['tabIndex', 'crossOrigin'].forEach(function (attributeName) {
  515. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  516. attributeName.toLowerCase(), // attributeName
  517. null, // attributeNamespace
  518. false, // sanitizeURL
  519. false);
  520. }); // These attributes accept URLs. These must not allow javascript: URLS.
  521. // These will also need to accept Trusted Types object in the future.
  522. var xlinkHref = 'xlinkHref';
  523. properties[xlinkHref] = new PropertyInfoRecord('xlinkHref', STRING, false, // mustUseProperty
  524. 'xlink:href', 'http://www.w3.org/1999/xlink', true, // sanitizeURL
  525. false);
  526. ['src', 'href', 'action', 'formAction'].forEach(function (attributeName) {
  527. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  528. attributeName.toLowerCase(), // attributeName
  529. null, // attributeNamespace
  530. true, // sanitizeURL
  531. true);
  532. });
  533. // and any newline or tab are filtered out as if they're not part of the URL.
  534. // https://url.spec.whatwg.org/#url-parsing
  535. // Tab or newline are defined as \r\n\t:
  536. // https://infra.spec.whatwg.org/#ascii-tab-or-newline
  537. // A C0 control is a code point in the range \u0000 NULL to \u001F
  538. // INFORMATION SEPARATOR ONE, inclusive:
  539. // https://infra.spec.whatwg.org/#c0-control-or-space
  540. /* eslint-disable max-len */
  541. var isJavaScriptProtocol = /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*\:/i;
  542. var didWarn = false;
  543. function sanitizeURL(url) {
  544. {
  545. if (!didWarn && isJavaScriptProtocol.test(url)) {
  546. didWarn = true;
  547. error('A future version of React will block javascript: URLs as a security precaution. ' + 'Use event handlers instead if you can. If you need to generate unsafe HTML try ' + 'using dangerouslySetInnerHTML instead. React was passed %s.', JSON.stringify(url));
  548. }
  549. }
  550. }
  551. /**
  552. * Get the value for a property on a node. Only used in DEV for SSR validation.
  553. * The "expected" argument is used as a hint of what the expected value is.
  554. * Some properties have multiple equivalent values.
  555. */
  556. function getValueForProperty(node, name, expected, propertyInfo) {
  557. {
  558. if (propertyInfo.mustUseProperty) {
  559. var propertyName = propertyInfo.propertyName;
  560. return node[propertyName];
  561. } else {
  562. // This check protects multiple uses of `expected`, which is why the
  563. // react-internal/safe-string-coercion rule is disabled in several spots
  564. // below.
  565. {
  566. checkAttributeStringCoercion(expected, name);
  567. }
  568. if ( propertyInfo.sanitizeURL) {
  569. // If we haven't fully disabled javascript: URLs, and if
  570. // the hydration is successful of a javascript: URL, we
  571. // still want to warn on the client.
  572. // eslint-disable-next-line react-internal/safe-string-coercion
  573. sanitizeURL('' + expected);
  574. }
  575. var attributeName = propertyInfo.attributeName;
  576. var stringValue = null;
  577. if (propertyInfo.type === OVERLOADED_BOOLEAN) {
  578. if (node.hasAttribute(attributeName)) {
  579. var value = node.getAttribute(attributeName);
  580. if (value === '') {
  581. return true;
  582. }
  583. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  584. return value;
  585. } // eslint-disable-next-line react-internal/safe-string-coercion
  586. if (value === '' + expected) {
  587. return expected;
  588. }
  589. return value;
  590. }
  591. } else if (node.hasAttribute(attributeName)) {
  592. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  593. // We had an attribute but shouldn't have had one, so read it
  594. // for the error message.
  595. return node.getAttribute(attributeName);
  596. }
  597. if (propertyInfo.type === BOOLEAN) {
  598. // If this was a boolean, it doesn't matter what the value is
  599. // the fact that we have it is the same as the expected.
  600. return expected;
  601. } // Even if this property uses a namespace we use getAttribute
  602. // because we assume its namespaced name is the same as our config.
  603. // To use getAttributeNS we need the local name which we don't have
  604. // in our config atm.
  605. stringValue = node.getAttribute(attributeName);
  606. }
  607. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  608. return stringValue === null ? expected : stringValue; // eslint-disable-next-line react-internal/safe-string-coercion
  609. } else if (stringValue === '' + expected) {
  610. return expected;
  611. } else {
  612. return stringValue;
  613. }
  614. }
  615. }
  616. }
  617. /**
  618. * Get the value for a attribute on a node. Only used in DEV for SSR validation.
  619. * The third argument is used as a hint of what the expected value is. Some
  620. * attributes have multiple equivalent values.
  621. */
  622. function getValueForAttribute(node, name, expected, isCustomComponentTag) {
  623. {
  624. if (!isAttributeNameSafe(name)) {
  625. return;
  626. }
  627. if (!node.hasAttribute(name)) {
  628. return expected === undefined ? undefined : null;
  629. }
  630. var value = node.getAttribute(name);
  631. {
  632. checkAttributeStringCoercion(expected, name);
  633. }
  634. if (value === '' + expected) {
  635. return expected;
  636. }
  637. return value;
  638. }
  639. }
  640. /**
  641. * Sets the value for a property on a node.
  642. *
  643. * @param {DOMElement} node
  644. * @param {string} name
  645. * @param {*} value
  646. */
  647. function setValueForProperty(node, name, value, isCustomComponentTag) {
  648. var propertyInfo = getPropertyInfo(name);
  649. if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
  650. return;
  651. }
  652. if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
  653. value = null;
  654. }
  655. if (isCustomComponentTag || propertyInfo === null) {
  656. if (isAttributeNameSafe(name)) {
  657. var _attributeName = name;
  658. if (value === null) {
  659. node.removeAttribute(_attributeName);
  660. } else {
  661. {
  662. checkAttributeStringCoercion(value, name);
  663. }
  664. node.setAttribute(_attributeName, '' + value);
  665. }
  666. }
  667. return;
  668. }
  669. var mustUseProperty = propertyInfo.mustUseProperty;
  670. if (mustUseProperty) {
  671. var propertyName = propertyInfo.propertyName;
  672. if (value === null) {
  673. var type = propertyInfo.type;
  674. node[propertyName] = type === BOOLEAN ? false : '';
  675. } else {
  676. // Contrary to `setAttribute`, object properties are properly
  677. // `toString`ed by IE8/9.
  678. node[propertyName] = value;
  679. }
  680. return;
  681. } // The rest are treated as attributes with special cases.
  682. var attributeName = propertyInfo.attributeName,
  683. attributeNamespace = propertyInfo.attributeNamespace;
  684. if (value === null) {
  685. node.removeAttribute(attributeName);
  686. } else {
  687. var _type = propertyInfo.type;
  688. var attributeValue;
  689. if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
  690. // If attribute type is boolean, we know for sure it won't be an execution sink
  691. // and we won't require Trusted Type here.
  692. attributeValue = '';
  693. } else {
  694. // `setAttribute` with objects becomes only `[object]` in IE8/9,
  695. // ('' + value) makes it output the correct toString()-value.
  696. {
  697. {
  698. checkAttributeStringCoercion(value, attributeName);
  699. }
  700. attributeValue = '' + value;
  701. }
  702. if (propertyInfo.sanitizeURL) {
  703. sanitizeURL(attributeValue.toString());
  704. }
  705. }
  706. if (attributeNamespace) {
  707. node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
  708. } else {
  709. node.setAttribute(attributeName, attributeValue);
  710. }
  711. }
  712. }
  713. // ATTENTION
  714. // When adding new symbols to this file,
  715. // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
  716. // The Symbol used to tag the ReactElement-like types.
  717. var REACT_ELEMENT_TYPE = Symbol.for('react.element');
  718. var REACT_PORTAL_TYPE = Symbol.for('react.portal');
  719. var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
  720. var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
  721. var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
  722. var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
  723. var REACT_CONTEXT_TYPE = Symbol.for('react.context');
  724. var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
  725. var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
  726. var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
  727. var REACT_MEMO_TYPE = Symbol.for('react.memo');
  728. var REACT_LAZY_TYPE = Symbol.for('react.lazy');
  729. var REACT_SCOPE_TYPE = Symbol.for('react.scope');
  730. var REACT_DEBUG_TRACING_MODE_TYPE = Symbol.for('react.debug_trace_mode');
  731. var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
  732. var REACT_LEGACY_HIDDEN_TYPE = Symbol.for('react.legacy_hidden');
  733. var REACT_CACHE_TYPE = Symbol.for('react.cache');
  734. var REACT_TRACING_MARKER_TYPE = Symbol.for('react.tracing_marker');
  735. var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
  736. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  737. function getIteratorFn(maybeIterable) {
  738. if (maybeIterable === null || typeof maybeIterable !== 'object') {
  739. return null;
  740. }
  741. var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
  742. if (typeof maybeIterator === 'function') {
  743. return maybeIterator;
  744. }
  745. return null;
  746. }
  747. var assign = Object.assign;
  748. // Helpers to patch console.logs to avoid logging during side-effect free
  749. // replaying on render function. This currently only patches the object
  750. // lazily which won't cover if the log function was extracted eagerly.
  751. // We could also eagerly patch the method.
  752. var disabledDepth = 0;
  753. var prevLog;
  754. var prevInfo;
  755. var prevWarn;
  756. var prevError;
  757. var prevGroup;
  758. var prevGroupCollapsed;
  759. var prevGroupEnd;
  760. function disabledLog() {}
  761. disabledLog.__reactDisabledLog = true;
  762. function disableLogs() {
  763. {
  764. if (disabledDepth === 0) {
  765. /* eslint-disable react-internal/no-production-logging */
  766. prevLog = console.log;
  767. prevInfo = console.info;
  768. prevWarn = console.warn;
  769. prevError = console.error;
  770. prevGroup = console.group;
  771. prevGroupCollapsed = console.groupCollapsed;
  772. prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
  773. var props = {
  774. configurable: true,
  775. enumerable: true,
  776. value: disabledLog,
  777. writable: true
  778. }; // $FlowFixMe Flow thinks console is immutable.
  779. Object.defineProperties(console, {
  780. info: props,
  781. log: props,
  782. warn: props,
  783. error: props,
  784. group: props,
  785. groupCollapsed: props,
  786. groupEnd: props
  787. });
  788. /* eslint-enable react-internal/no-production-logging */
  789. }
  790. disabledDepth++;
  791. }
  792. }
  793. function reenableLogs() {
  794. {
  795. disabledDepth--;
  796. if (disabledDepth === 0) {
  797. /* eslint-disable react-internal/no-production-logging */
  798. var props = {
  799. configurable: true,
  800. enumerable: true,
  801. writable: true
  802. }; // $FlowFixMe Flow thinks console is immutable.
  803. Object.defineProperties(console, {
  804. log: assign({}, props, {
  805. value: prevLog
  806. }),
  807. info: assign({}, props, {
  808. value: prevInfo
  809. }),
  810. warn: assign({}, props, {
  811. value: prevWarn
  812. }),
  813. error: assign({}, props, {
  814. value: prevError
  815. }),
  816. group: assign({}, props, {
  817. value: prevGroup
  818. }),
  819. groupCollapsed: assign({}, props, {
  820. value: prevGroupCollapsed
  821. }),
  822. groupEnd: assign({}, props, {
  823. value: prevGroupEnd
  824. })
  825. });
  826. /* eslint-enable react-internal/no-production-logging */
  827. }
  828. if (disabledDepth < 0) {
  829. error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
  830. }
  831. }
  832. }
  833. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  834. var prefix;
  835. function describeBuiltInComponentFrame(name, source, ownerFn) {
  836. {
  837. if (prefix === undefined) {
  838. // Extract the VM specific prefix used by each line.
  839. try {
  840. throw Error();
  841. } catch (x) {
  842. var match = x.stack.trim().match(/\n( *(at )?)/);
  843. prefix = match && match[1] || '';
  844. }
  845. } // We use the prefix to ensure our stacks line up with native stack frames.
  846. return '\n' + prefix + name;
  847. }
  848. }
  849. var reentry = false;
  850. var componentFrameCache;
  851. {
  852. var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
  853. componentFrameCache = new PossiblyWeakMap();
  854. }
  855. function describeNativeComponentFrame(fn, construct) {
  856. // If something asked for a stack inside a fake render, it should get ignored.
  857. if ( !fn || reentry) {
  858. return '';
  859. }
  860. {
  861. var frame = componentFrameCache.get(fn);
  862. if (frame !== undefined) {
  863. return frame;
  864. }
  865. }
  866. var control;
  867. reentry = true;
  868. var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
  869. Error.prepareStackTrace = undefined;
  870. var previousDispatcher;
  871. {
  872. previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
  873. // for warnings.
  874. ReactCurrentDispatcher.current = null;
  875. disableLogs();
  876. }
  877. try {
  878. // This should throw.
  879. if (construct) {
  880. // Something should be setting the props in the constructor.
  881. var Fake = function () {
  882. throw Error();
  883. }; // $FlowFixMe
  884. Object.defineProperty(Fake.prototype, 'props', {
  885. set: function () {
  886. // We use a throwing setter instead of frozen or non-writable props
  887. // because that won't throw in a non-strict mode function.
  888. throw Error();
  889. }
  890. });
  891. if (typeof Reflect === 'object' && Reflect.construct) {
  892. // We construct a different control for this case to include any extra
  893. // frames added by the construct call.
  894. try {
  895. Reflect.construct(Fake, []);
  896. } catch (x) {
  897. control = x;
  898. }
  899. Reflect.construct(fn, [], Fake);
  900. } else {
  901. try {
  902. Fake.call();
  903. } catch (x) {
  904. control = x;
  905. }
  906. fn.call(Fake.prototype);
  907. }
  908. } else {
  909. try {
  910. throw Error();
  911. } catch (x) {
  912. control = x;
  913. }
  914. fn();
  915. }
  916. } catch (sample) {
  917. // This is inlined manually because closure doesn't do it for us.
  918. if (sample && control && typeof sample.stack === 'string') {
  919. // This extracts the first frame from the sample that isn't also in the control.
  920. // Skipping one frame that we assume is the frame that calls the two.
  921. var sampleLines = sample.stack.split('\n');
  922. var controlLines = control.stack.split('\n');
  923. var s = sampleLines.length - 1;
  924. var c = controlLines.length - 1;
  925. while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
  926. // We expect at least one stack frame to be shared.
  927. // Typically this will be the root most one. However, stack frames may be
  928. // cut off due to maximum stack limits. In this case, one maybe cut off
  929. // earlier than the other. We assume that the sample is longer or the same
  930. // and there for cut off earlier. So we should find the root most frame in
  931. // the sample somewhere in the control.
  932. c--;
  933. }
  934. for (; s >= 1 && c >= 0; s--, c--) {
  935. // Next we find the first one that isn't the same which should be the
  936. // frame that called our sample function and the control.
  937. if (sampleLines[s] !== controlLines[c]) {
  938. // In V8, the first line is describing the message but other VMs don't.
  939. // If we're about to return the first line, and the control is also on the same
  940. // line, that's a pretty good indicator that our sample threw at same line as
  941. // the control. I.e. before we entered the sample frame. So we ignore this result.
  942. // This can happen if you passed a class to function component, or non-function.
  943. if (s !== 1 || c !== 1) {
  944. do {
  945. s--;
  946. c--; // We may still have similar intermediate frames from the construct call.
  947. // The next one that isn't the same should be our match though.
  948. if (c < 0 || sampleLines[s] !== controlLines[c]) {
  949. // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
  950. var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); // If our component frame is labeled "<anonymous>"
  951. // but we have a user-provided "displayName"
  952. // splice it in to make the stack more readable.
  953. if (fn.displayName && _frame.includes('<anonymous>')) {
  954. _frame = _frame.replace('<anonymous>', fn.displayName);
  955. }
  956. {
  957. if (typeof fn === 'function') {
  958. componentFrameCache.set(fn, _frame);
  959. }
  960. } // Return the line we found.
  961. return _frame;
  962. }
  963. } while (s >= 1 && c >= 0);
  964. }
  965. break;
  966. }
  967. }
  968. }
  969. } finally {
  970. reentry = false;
  971. {
  972. ReactCurrentDispatcher.current = previousDispatcher;
  973. reenableLogs();
  974. }
  975. Error.prepareStackTrace = previousPrepareStackTrace;
  976. } // Fallback to just using the name if we couldn't make it throw.
  977. var name = fn ? fn.displayName || fn.name : '';
  978. var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
  979. {
  980. if (typeof fn === 'function') {
  981. componentFrameCache.set(fn, syntheticFrame);
  982. }
  983. }
  984. return syntheticFrame;
  985. }
  986. function describeClassComponentFrame(ctor, source, ownerFn) {
  987. {
  988. return describeNativeComponentFrame(ctor, true);
  989. }
  990. }
  991. function describeFunctionComponentFrame(fn, source, ownerFn) {
  992. {
  993. return describeNativeComponentFrame(fn, false);
  994. }
  995. }
  996. function shouldConstruct(Component) {
  997. var prototype = Component.prototype;
  998. return !!(prototype && prototype.isReactComponent);
  999. }
  1000. function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
  1001. if (type == null) {
  1002. return '';
  1003. }
  1004. if (typeof type === 'function') {
  1005. {
  1006. return describeNativeComponentFrame(type, shouldConstruct(type));
  1007. }
  1008. }
  1009. if (typeof type === 'string') {
  1010. return describeBuiltInComponentFrame(type);
  1011. }
  1012. switch (type) {
  1013. case REACT_SUSPENSE_TYPE:
  1014. return describeBuiltInComponentFrame('Suspense');
  1015. case REACT_SUSPENSE_LIST_TYPE:
  1016. return describeBuiltInComponentFrame('SuspenseList');
  1017. }
  1018. if (typeof type === 'object') {
  1019. switch (type.$$typeof) {
  1020. case REACT_FORWARD_REF_TYPE:
  1021. return describeFunctionComponentFrame(type.render);
  1022. case REACT_MEMO_TYPE:
  1023. // Memo may contain any component type so we recursively resolve it.
  1024. return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
  1025. case REACT_LAZY_TYPE:
  1026. {
  1027. var lazyComponent = type;
  1028. var payload = lazyComponent._payload;
  1029. var init = lazyComponent._init;
  1030. try {
  1031. // Lazy may contain any component type so we recursively resolve it.
  1032. return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
  1033. } catch (x) {}
  1034. }
  1035. }
  1036. }
  1037. return '';
  1038. }
  1039. function describeFiber(fiber) {
  1040. var owner = fiber._debugOwner ? fiber._debugOwner.type : null ;
  1041. var source = fiber._debugSource ;
  1042. switch (fiber.tag) {
  1043. case HostComponent:
  1044. return describeBuiltInComponentFrame(fiber.type);
  1045. case LazyComponent:
  1046. return describeBuiltInComponentFrame('Lazy');
  1047. case SuspenseComponent:
  1048. return describeBuiltInComponentFrame('Suspense');
  1049. case SuspenseListComponent:
  1050. return describeBuiltInComponentFrame('SuspenseList');
  1051. case FunctionComponent:
  1052. case IndeterminateComponent:
  1053. case SimpleMemoComponent:
  1054. return describeFunctionComponentFrame(fiber.type);
  1055. case ForwardRef:
  1056. return describeFunctionComponentFrame(fiber.type.render);
  1057. case ClassComponent:
  1058. return describeClassComponentFrame(fiber.type);
  1059. default:
  1060. return '';
  1061. }
  1062. }
  1063. function getStackByFiberInDevAndProd(workInProgress) {
  1064. try {
  1065. var info = '';
  1066. var node = workInProgress;
  1067. do {
  1068. info += describeFiber(node);
  1069. node = node.return;
  1070. } while (node);
  1071. return info;
  1072. } catch (x) {
  1073. return '\nError generating stack: ' + x.message + '\n' + x.stack;
  1074. }
  1075. }
  1076. function getWrappedName(outerType, innerType, wrapperName) {
  1077. var displayName = outerType.displayName;
  1078. if (displayName) {
  1079. return displayName;
  1080. }
  1081. var functionName = innerType.displayName || innerType.name || '';
  1082. return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
  1083. } // Keep in sync with react-reconciler/getComponentNameFromFiber
  1084. function getContextName(type) {
  1085. return type.displayName || 'Context';
  1086. } // Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
  1087. function getComponentNameFromType(type) {
  1088. if (type == null) {
  1089. // Host root, text node or just invalid type.
  1090. return null;
  1091. }
  1092. {
  1093. if (typeof type.tag === 'number') {
  1094. error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
  1095. }
  1096. }
  1097. if (typeof type === 'function') {
  1098. return type.displayName || type.name || null;
  1099. }
  1100. if (typeof type === 'string') {
  1101. return type;
  1102. }
  1103. switch (type) {
  1104. case REACT_FRAGMENT_TYPE:
  1105. return 'Fragment';
  1106. case REACT_PORTAL_TYPE:
  1107. return 'Portal';
  1108. case REACT_PROFILER_TYPE:
  1109. return 'Profiler';
  1110. case REACT_STRICT_MODE_TYPE:
  1111. return 'StrictMode';
  1112. case REACT_SUSPENSE_TYPE:
  1113. return 'Suspense';
  1114. case REACT_SUSPENSE_LIST_TYPE:
  1115. return 'SuspenseList';
  1116. }
  1117. if (typeof type === 'object') {
  1118. switch (type.$$typeof) {
  1119. case REACT_CONTEXT_TYPE:
  1120. var context = type;
  1121. return getContextName(context) + '.Consumer';
  1122. case REACT_PROVIDER_TYPE:
  1123. var provider = type;
  1124. return getContextName(provider._context) + '.Provider';
  1125. case REACT_FORWARD_REF_TYPE:
  1126. return getWrappedName(type, type.render, 'ForwardRef');
  1127. case REACT_MEMO_TYPE:
  1128. var outerName = type.displayName || null;
  1129. if (outerName !== null) {
  1130. return outerName;
  1131. }
  1132. return getComponentNameFromType(type.type) || 'Memo';
  1133. case REACT_LAZY_TYPE:
  1134. {
  1135. var lazyComponent = type;
  1136. var payload = lazyComponent._payload;
  1137. var init = lazyComponent._init;
  1138. try {
  1139. return getComponentNameFromType(init(payload));
  1140. } catch (x) {
  1141. return null;
  1142. }
  1143. }
  1144. // eslint-disable-next-line no-fallthrough
  1145. }
  1146. }
  1147. return null;
  1148. }
  1149. function getWrappedName$1(outerType, innerType, wrapperName) {
  1150. var functionName = innerType.displayName || innerType.name || '';
  1151. return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
  1152. } // Keep in sync with shared/getComponentNameFromType
  1153. function getContextName$1(type) {
  1154. return type.displayName || 'Context';
  1155. }
  1156. function getComponentNameFromFiber(fiber) {
  1157. var tag = fiber.tag,
  1158. type = fiber.type;
  1159. switch (tag) {
  1160. case CacheComponent:
  1161. return 'Cache';
  1162. case ContextConsumer:
  1163. var context = type;
  1164. return getContextName$1(context) + '.Consumer';
  1165. case ContextProvider:
  1166. var provider = type;
  1167. return getContextName$1(provider._context) + '.Provider';
  1168. case DehydratedFragment:
  1169. return 'DehydratedFragment';
  1170. case ForwardRef:
  1171. return getWrappedName$1(type, type.render, 'ForwardRef');
  1172. case Fragment:
  1173. return 'Fragment';
  1174. case HostComponent:
  1175. // Host component type is the display name (e.g. "div", "View")
  1176. return type;
  1177. case HostPortal:
  1178. return 'Portal';
  1179. case HostRoot:
  1180. return 'Root';
  1181. case HostText:
  1182. return 'Text';
  1183. case LazyComponent:
  1184. // Name comes from the type in this case; we don't have a tag.
  1185. return getComponentNameFromType(type);
  1186. case Mode:
  1187. if (type === REACT_STRICT_MODE_TYPE) {
  1188. // Don't be less specific than shared/getComponentNameFromType
  1189. return 'StrictMode';
  1190. }
  1191. return 'Mode';
  1192. case OffscreenComponent:
  1193. return 'Offscreen';
  1194. case Profiler:
  1195. return 'Profiler';
  1196. case ScopeComponent:
  1197. return 'Scope';
  1198. case SuspenseComponent:
  1199. return 'Suspense';
  1200. case SuspenseListComponent:
  1201. return 'SuspenseList';
  1202. case TracingMarkerComponent:
  1203. return 'TracingMarker';
  1204. // The display name for this tags come from the user-provided type:
  1205. case ClassComponent:
  1206. case FunctionComponent:
  1207. case IncompleteClassComponent:
  1208. case IndeterminateComponent:
  1209. case MemoComponent:
  1210. case SimpleMemoComponent:
  1211. if (typeof type === 'function') {
  1212. return type.displayName || type.name || null;
  1213. }
  1214. if (typeof type === 'string') {
  1215. return type;
  1216. }
  1217. break;
  1218. }
  1219. return null;
  1220. }
  1221. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  1222. var current = null;
  1223. var isRendering = false;
  1224. function getCurrentFiberOwnerNameInDevOrNull() {
  1225. {
  1226. if (current === null) {
  1227. return null;
  1228. }
  1229. var owner = current._debugOwner;
  1230. if (owner !== null && typeof owner !== 'undefined') {
  1231. return getComponentNameFromFiber(owner);
  1232. }
  1233. }
  1234. return null;
  1235. }
  1236. function getCurrentFiberStackInDev() {
  1237. {
  1238. if (current === null) {
  1239. return '';
  1240. } // Safe because if current fiber exists, we are reconciling,
  1241. // and it is guaranteed to be the work-in-progress version.
  1242. return getStackByFiberInDevAndProd(current);
  1243. }
  1244. }
  1245. function resetCurrentFiber() {
  1246. {
  1247. ReactDebugCurrentFrame.getCurrentStack = null;
  1248. current = null;
  1249. isRendering = false;
  1250. }
  1251. }
  1252. function setCurrentFiber(fiber) {
  1253. {
  1254. ReactDebugCurrentFrame.getCurrentStack = fiber === null ? null : getCurrentFiberStackInDev;
  1255. current = fiber;
  1256. isRendering = false;
  1257. }
  1258. }
  1259. function getCurrentFiber() {
  1260. {
  1261. return current;
  1262. }
  1263. }
  1264. function setIsRendering(rendering) {
  1265. {
  1266. isRendering = rendering;
  1267. }
  1268. }
  1269. // Flow does not allow string concatenation of most non-string types. To work
  1270. // around this limitation, we use an opaque type that can only be obtained by
  1271. // passing the value through getToStringValue first.
  1272. function toString(value) {
  1273. // The coercion safety check is performed in getToStringValue().
  1274. // eslint-disable-next-line react-internal/safe-string-coercion
  1275. return '' + value;
  1276. }
  1277. function getToStringValue(value) {
  1278. switch (typeof value) {
  1279. case 'boolean':
  1280. case 'number':
  1281. case 'string':
  1282. case 'undefined':
  1283. return value;
  1284. case 'object':
  1285. {
  1286. checkFormFieldValueStringCoercion(value);
  1287. }
  1288. return value;
  1289. default:
  1290. // function, symbol are assigned as empty strings
  1291. return '';
  1292. }
  1293. }
  1294. var hasReadOnlyValue = {
  1295. button: true,
  1296. checkbox: true,
  1297. image: true,
  1298. hidden: true,
  1299. radio: true,
  1300. reset: true,
  1301. submit: true
  1302. };
  1303. function checkControlledValueProps(tagName, props) {
  1304. {
  1305. if (!(hasReadOnlyValue[props.type] || props.onChange || props.onInput || props.readOnly || props.disabled || props.value == null)) {
  1306. error('You provided a `value` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultValue`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
  1307. }
  1308. if (!(props.onChange || props.readOnly || props.disabled || props.checked == null)) {
  1309. error('You provided a `checked` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultChecked`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
  1310. }
  1311. }
  1312. }
  1313. function isCheckable(elem) {
  1314. var type = elem.type;
  1315. var nodeName = elem.nodeName;
  1316. return nodeName && nodeName.toLowerCase() === 'input' && (type === 'checkbox' || type === 'radio');
  1317. }
  1318. function getTracker(node) {
  1319. return node._valueTracker;
  1320. }
  1321. function detachTracker(node) {
  1322. node._valueTracker = null;
  1323. }
  1324. function getValueFromNode(node) {
  1325. var value = '';
  1326. if (!node) {
  1327. return value;
  1328. }
  1329. if (isCheckable(node)) {
  1330. value = node.checked ? 'true' : 'false';
  1331. } else {
  1332. value = node.value;
  1333. }
  1334. return value;
  1335. }
  1336. function trackValueOnNode(node) {
  1337. var valueField = isCheckable(node) ? 'checked' : 'value';
  1338. var descriptor = Object.getOwnPropertyDescriptor(node.constructor.prototype, valueField);
  1339. {
  1340. checkFormFieldValueStringCoercion(node[valueField]);
  1341. }
  1342. var currentValue = '' + node[valueField]; // if someone has already defined a value or Safari, then bail
  1343. // and don't track value will cause over reporting of changes,
  1344. // but it's better then a hard failure
  1345. // (needed for certain tests that spyOn input values and Safari)
  1346. if (node.hasOwnProperty(valueField) || typeof descriptor === 'undefined' || typeof descriptor.get !== 'function' || typeof descriptor.set !== 'function') {
  1347. return;
  1348. }
  1349. var get = descriptor.get,
  1350. set = descriptor.set;
  1351. Object.defineProperty(node, valueField, {
  1352. configurable: true,
  1353. get: function () {
  1354. return get.call(this);
  1355. },
  1356. set: function (value) {
  1357. {
  1358. checkFormFieldValueStringCoercion(value);
  1359. }
  1360. currentValue = '' + value;
  1361. set.call(this, value);
  1362. }
  1363. }); // We could've passed this the first time
  1364. // but it triggers a bug in IE11 and Edge 14/15.
  1365. // Calling defineProperty() again should be equivalent.
  1366. // https://github.com/facebook/react/issues/11768
  1367. Object.defineProperty(node, valueField, {
  1368. enumerable: descriptor.enumerable
  1369. });
  1370. var tracker = {
  1371. getValue: function () {
  1372. return currentValue;
  1373. },
  1374. setValue: function (value) {
  1375. {
  1376. checkFormFieldValueStringCoercion(value);
  1377. }
  1378. currentValue = '' + value;
  1379. },
  1380. stopTracking: function () {
  1381. detachTracker(node);
  1382. delete node[valueField];
  1383. }
  1384. };
  1385. return tracker;
  1386. }
  1387. function track(node) {
  1388. if (getTracker(node)) {
  1389. return;
  1390. } // TODO: Once it's just Fiber we can move this to node._wrapperState
  1391. node._valueTracker = trackValueOnNode(node);
  1392. }
  1393. function updateValueIfChanged(node) {
  1394. if (!node) {
  1395. return false;
  1396. }
  1397. var tracker = getTracker(node); // if there is no tracker at this point it's unlikely
  1398. // that trying again will succeed
  1399. if (!tracker) {
  1400. return true;
  1401. }
  1402. var lastValue = tracker.getValue();
  1403. var nextValue = getValueFromNode(node);
  1404. if (nextValue !== lastValue) {
  1405. tracker.setValue(nextValue);
  1406. return true;
  1407. }
  1408. return false;
  1409. }
  1410. function getActiveElement(doc) {
  1411. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  1412. if (typeof doc === 'undefined') {
  1413. return null;
  1414. }
  1415. try {
  1416. return doc.activeElement || doc.body;
  1417. } catch (e) {
  1418. return doc.body;
  1419. }
  1420. }
  1421. var didWarnValueDefaultValue = false;
  1422. var didWarnCheckedDefaultChecked = false;
  1423. var didWarnControlledToUncontrolled = false;
  1424. var didWarnUncontrolledToControlled = false;
  1425. function isControlled(props) {
  1426. var usesChecked = props.type === 'checkbox' || props.type === 'radio';
  1427. return usesChecked ? props.checked != null : props.value != null;
  1428. }
  1429. /**
  1430. * Implements an <input> host component that allows setting these optional
  1431. * props: `checked`, `value`, `defaultChecked`, and `defaultValue`.
  1432. *
  1433. * If `checked` or `value` are not supplied (or null/undefined), user actions
  1434. * that affect the checked state or value will trigger updates to the element.
  1435. *
  1436. * If they are supplied (and not null/undefined), the rendered element will not
  1437. * trigger updates to the element. Instead, the props must change in order for
  1438. * the rendered element to be updated.
  1439. *
  1440. * The rendered element will be initialized as unchecked (or `defaultChecked`)
  1441. * with an empty value (or `defaultValue`).
  1442. *
  1443. * See http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
  1444. */
  1445. function getHostProps(element, props) {
  1446. var node = element;
  1447. var checked = props.checked;
  1448. var hostProps = assign({}, props, {
  1449. defaultChecked: undefined,
  1450. defaultValue: undefined,
  1451. value: undefined,
  1452. checked: checked != null ? checked : node._wrapperState.initialChecked
  1453. });
  1454. return hostProps;
  1455. }
  1456. function initWrapperState(element, props) {
  1457. {
  1458. checkControlledValueProps('input', props);
  1459. if (props.checked !== undefined && props.defaultChecked !== undefined && !didWarnCheckedDefaultChecked) {
  1460. error('%s contains an input of type %s with both checked and defaultChecked props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the checked prop, or the defaultChecked prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component', props.type);
  1461. didWarnCheckedDefaultChecked = true;
  1462. }
  1463. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue) {
  1464. error('%s contains an input of type %s with both value and defaultValue props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component', props.type);
  1465. didWarnValueDefaultValue = true;
  1466. }
  1467. }
  1468. var node = element;
  1469. var defaultValue = props.defaultValue == null ? '' : props.defaultValue;
  1470. node._wrapperState = {
  1471. initialChecked: props.checked != null ? props.checked : props.defaultChecked,
  1472. initialValue: getToStringValue(props.value != null ? props.value : defaultValue),
  1473. controlled: isControlled(props)
  1474. };
  1475. }
  1476. function updateChecked(element, props) {
  1477. var node = element;
  1478. var checked = props.checked;
  1479. if (checked != null) {
  1480. setValueForProperty(node, 'checked', checked, false);
  1481. }
  1482. }
  1483. function updateWrapper(element, props) {
  1484. var node = element;
  1485. {
  1486. var controlled = isControlled(props);
  1487. if (!node._wrapperState.controlled && controlled && !didWarnUncontrolledToControlled) {
  1488. error('A component is changing an uncontrolled input to be controlled. ' + 'This is likely caused by the value changing from undefined to ' + 'a defined value, which should not happen. ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components');
  1489. didWarnUncontrolledToControlled = true;
  1490. }
  1491. if (node._wrapperState.controlled && !controlled && !didWarnControlledToUncontrolled) {
  1492. error('A component is changing a controlled input to be uncontrolled. ' + 'This is likely caused by the value changing from a defined to ' + 'undefined, which should not happen. ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components');
  1493. didWarnControlledToUncontrolled = true;
  1494. }
  1495. }
  1496. updateChecked(element, props);
  1497. var value = getToStringValue(props.value);
  1498. var type = props.type;
  1499. if (value != null) {
  1500. if (type === 'number') {
  1501. if (value === 0 && node.value === '' || // We explicitly want to coerce to number here if possible.
  1502. // eslint-disable-next-line
  1503. node.value != value) {
  1504. node.value = toString(value);
  1505. }
  1506. } else if (node.value !== toString(value)) {
  1507. node.value = toString(value);
  1508. }
  1509. } else if (type === 'submit' || type === 'reset') {
  1510. // Submit/reset inputs need the attribute removed completely to avoid
  1511. // blank-text buttons.
  1512. node.removeAttribute('value');
  1513. return;
  1514. }
  1515. {
  1516. // When syncing the value attribute, the value comes from a cascade of
  1517. // properties:
  1518. // 1. The value React property
  1519. // 2. The defaultValue React property
  1520. // 3. Otherwise there should be no change
  1521. if (props.hasOwnProperty('value')) {
  1522. setDefaultValue(node, props.type, value);
  1523. } else if (props.hasOwnProperty('defaultValue')) {
  1524. setDefaultValue(node, props.type, getToStringValue(props.defaultValue));
  1525. }
  1526. }
  1527. {
  1528. // When syncing the checked attribute, it only changes when it needs
  1529. // to be removed, such as transitioning from a checkbox into a text input
  1530. if (props.checked == null && props.defaultChecked != null) {
  1531. node.defaultChecked = !!props.defaultChecked;
  1532. }
  1533. }
  1534. }
  1535. function postMountWrapper(element, props, isHydrating) {
  1536. var node = element; // Do not assign value if it is already set. This prevents user text input
  1537. // from being lost during SSR hydration.
  1538. if (props.hasOwnProperty('value') || props.hasOwnProperty('defaultValue')) {
  1539. var type = props.type;
  1540. var isButton = type === 'submit' || type === 'reset'; // Avoid setting value attribute on submit/reset inputs as it overrides the
  1541. // default value provided by the browser. See: #12872
  1542. if (isButton && (props.value === undefined || props.value === null)) {
  1543. return;
  1544. }
  1545. var initialValue = toString(node._wrapperState.initialValue); // Do not assign value if it is already set. This prevents user text input
  1546. // from being lost during SSR hydration.
  1547. if (!isHydrating) {
  1548. {
  1549. // When syncing the value attribute, the value property should use
  1550. // the wrapperState._initialValue property. This uses:
  1551. //
  1552. // 1. The value React property when present
  1553. // 2. The defaultValue React property when present
  1554. // 3. An empty string
  1555. if (initialValue !== node.value) {
  1556. node.value = initialValue;
  1557. }
  1558. }
  1559. }
  1560. {
  1561. // Otherwise, the value attribute is synchronized to the property,
  1562. // so we assign defaultValue to the same thing as the value property
  1563. // assignment step above.
  1564. node.defaultValue = initialValue;
  1565. }
  1566. } // Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug
  1567. // this is needed to work around a chrome bug where setting defaultChecked
  1568. // will sometimes influence the value of checked (even after detachment).
  1569. // Reference: https://bugs.chromium.org/p/chromium/issues/detail?id=608416
  1570. // We need to temporarily unset name to avoid disrupting radio button groups.
  1571. var name = node.name;
  1572. if (name !== '') {
  1573. node.name = '';
  1574. }
  1575. {
  1576. // When syncing the checked attribute, both the checked property and
  1577. // attribute are assigned at the same time using defaultChecked. This uses:
  1578. //
  1579. // 1. The checked React property when present
  1580. // 2. The defaultChecked React property when present
  1581. // 3. Otherwise, false
  1582. node.defaultChecked = !node.defaultChecked;
  1583. node.defaultChecked = !!node._wrapperState.initialChecked;
  1584. }
  1585. if (name !== '') {
  1586. node.name = name;
  1587. }
  1588. }
  1589. function restoreControlledState(element, props) {
  1590. var node = element;
  1591. updateWrapper(node, props);
  1592. updateNamedCousins(node, props);
  1593. }
  1594. function updateNamedCousins(rootNode, props) {
  1595. var name = props.name;
  1596. if (props.type === 'radio' && name != null) {
  1597. var queryRoot = rootNode;
  1598. while (queryRoot.parentNode) {
  1599. queryRoot = queryRoot.parentNode;
  1600. } // If `rootNode.form` was non-null, then we could try `form.elements`,
  1601. // but that sometimes behaves strangely in IE8. We could also try using
  1602. // `form.getElementsByName`, but that will only return direct children
  1603. // and won't include inputs that use the HTML5 `form=` attribute. Since
  1604. // the input might not even be in a form. It might not even be in the
  1605. // document. Let's just use the local `querySelectorAll` to ensure we don't
  1606. // miss anything.
  1607. {
  1608. checkAttributeStringCoercion(name, 'name');
  1609. }
  1610. var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]');
  1611. for (var i = 0; i < group.length; i++) {
  1612. var otherNode = group[i];
  1613. if (otherNode === rootNode || otherNode.form !== rootNode.form) {
  1614. continue;
  1615. } // This will throw if radio buttons rendered by different copies of React
  1616. // and the same name are rendered into the same form (same as #1939).
  1617. // That's probably okay; we don't support it just as we don't support
  1618. // mixing React radio buttons with non-React ones.
  1619. var otherProps = getFiberCurrentPropsFromNode(otherNode);
  1620. if (!otherProps) {
  1621. throw new Error('ReactDOMInput: Mixing React and non-React radio inputs with the ' + 'same `name` is not supported.');
  1622. } // We need update the tracked value on the named cousin since the value
  1623. // was changed but the input saw no event or value set
  1624. updateValueIfChanged(otherNode); // If this is a controlled radio button group, forcing the input that
  1625. // was previously checked to update will cause it to be come re-checked
  1626. // as appropriate.
  1627. updateWrapper(otherNode, otherProps);
  1628. }
  1629. }
  1630. } // In Chrome, assigning defaultValue to certain input types triggers input validation.
  1631. // For number inputs, the display value loses trailing decimal points. For email inputs,
  1632. // Chrome raises "The specified value <x> is not a valid email address".
  1633. //
  1634. // Here we check to see if the defaultValue has actually changed, avoiding these problems
  1635. // when the user is inputting text
  1636. //
  1637. // https://github.com/facebook/react/issues/7253
  1638. function setDefaultValue(node, type, value) {
  1639. if ( // Focused number inputs synchronize on blur. See ChangeEventPlugin.js
  1640. type !== 'number' || getActiveElement(node.ownerDocument) !== node) {
  1641. if (value == null) {
  1642. node.defaultValue = toString(node._wrapperState.initialValue);
  1643. } else if (node.defaultValue !== toString(value)) {
  1644. node.defaultValue = toString(value);
  1645. }
  1646. }
  1647. }
  1648. var didWarnSelectedSetOnOption = false;
  1649. var didWarnInvalidChild = false;
  1650. var didWarnInvalidInnerHTML = false;
  1651. /**
  1652. * Implements an <option> host component that warns when `selected` is set.
  1653. */
  1654. function validateProps(element, props) {
  1655. {
  1656. // If a value is not provided, then the children must be simple.
  1657. if (props.value == null) {
  1658. if (typeof props.children === 'object' && props.children !== null) {
  1659. React.Children.forEach(props.children, function (child) {
  1660. if (child == null) {
  1661. return;
  1662. }
  1663. if (typeof child === 'string' || typeof child === 'number') {
  1664. return;
  1665. }
  1666. if (!didWarnInvalidChild) {
  1667. didWarnInvalidChild = true;
  1668. error('Cannot infer the option value of complex children. ' + 'Pass a `value` prop or use a plain string as children to <option>.');
  1669. }
  1670. });
  1671. } else if (props.dangerouslySetInnerHTML != null) {
  1672. if (!didWarnInvalidInnerHTML) {
  1673. didWarnInvalidInnerHTML = true;
  1674. error('Pass a `value` prop if you set dangerouslyInnerHTML so React knows ' + 'which value should be selected.');
  1675. }
  1676. }
  1677. } // TODO: Remove support for `selected` in <option>.
  1678. if (props.selected != null && !didWarnSelectedSetOnOption) {
  1679. error('Use the `defaultValue` or `value` props on <select> instead of ' + 'setting `selected` on <option>.');
  1680. didWarnSelectedSetOnOption = true;
  1681. }
  1682. }
  1683. }
  1684. function postMountWrapper$1(element, props) {
  1685. // value="" should make a value attribute (#6219)
  1686. if (props.value != null) {
  1687. element.setAttribute('value', toString(getToStringValue(props.value)));
  1688. }
  1689. }
  1690. var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
  1691. function isArray(a) {
  1692. return isArrayImpl(a);
  1693. }
  1694. var didWarnValueDefaultValue$1;
  1695. {
  1696. didWarnValueDefaultValue$1 = false;
  1697. }
  1698. function getDeclarationErrorAddendum() {
  1699. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  1700. if (ownerName) {
  1701. return '\n\nCheck the render method of `' + ownerName + '`.';
  1702. }
  1703. return '';
  1704. }
  1705. var valuePropNames = ['value', 'defaultValue'];
  1706. /**
  1707. * Validation function for `value` and `defaultValue`.
  1708. */
  1709. function checkSelectPropTypes(props) {
  1710. {
  1711. checkControlledValueProps('select', props);
  1712. for (var i = 0; i < valuePropNames.length; i++) {
  1713. var propName = valuePropNames[i];
  1714. if (props[propName] == null) {
  1715. continue;
  1716. }
  1717. var propNameIsArray = isArray(props[propName]);
  1718. if (props.multiple && !propNameIsArray) {
  1719. error('The `%s` prop supplied to <select> must be an array if ' + '`multiple` is true.%s', propName, getDeclarationErrorAddendum());
  1720. } else if (!props.multiple && propNameIsArray) {
  1721. error('The `%s` prop supplied to <select> must be a scalar ' + 'value if `multiple` is false.%s', propName, getDeclarationErrorAddendum());
  1722. }
  1723. }
  1724. }
  1725. }
  1726. function updateOptions(node, multiple, propValue, setDefaultSelected) {
  1727. var options = node.options;
  1728. if (multiple) {
  1729. var selectedValues = propValue;
  1730. var selectedValue = {};
  1731. for (var i = 0; i < selectedValues.length; i++) {
  1732. // Prefix to avoid chaos with special keys.
  1733. selectedValue['$' + selectedValues[i]] = true;
  1734. }
  1735. for (var _i = 0; _i < options.length; _i++) {
  1736. var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
  1737. if (options[_i].selected !== selected) {
  1738. options[_i].selected = selected;
  1739. }
  1740. if (selected && setDefaultSelected) {
  1741. options[_i].defaultSelected = true;
  1742. }
  1743. }
  1744. } else {
  1745. // Do not set `select.value` as exact behavior isn't consistent across all
  1746. // browsers for all cases.
  1747. var _selectedValue = toString(getToStringValue(propValue));
  1748. var defaultSelected = null;
  1749. for (var _i2 = 0; _i2 < options.length; _i2++) {
  1750. if (options[_i2].value === _selectedValue) {
  1751. options[_i2].selected = true;
  1752. if (setDefaultSelected) {
  1753. options[_i2].defaultSelected = true;
  1754. }
  1755. return;
  1756. }
  1757. if (defaultSelected === null && !options[_i2].disabled) {
  1758. defaultSelected = options[_i2];
  1759. }
  1760. }
  1761. if (defaultSelected !== null) {
  1762. defaultSelected.selected = true;
  1763. }
  1764. }
  1765. }
  1766. /**
  1767. * Implements a <select> host component that allows optionally setting the
  1768. * props `value` and `defaultValue`. If `multiple` is false, the prop must be a
  1769. * stringable. If `multiple` is true, the prop must be an array of stringables.
  1770. *
  1771. * If `value` is not supplied (or null/undefined), user actions that change the
  1772. * selected option will trigger updates to the rendered options.
  1773. *
  1774. * If it is supplied (and not null/undefined), the rendered options will not
  1775. * update in response to user actions. Instead, the `value` prop must change in
  1776. * order for the rendered options to update.
  1777. *
  1778. * If `defaultValue` is provided, any options with the supplied values will be
  1779. * selected.
  1780. */
  1781. function getHostProps$1(element, props) {
  1782. return assign({}, props, {
  1783. value: undefined
  1784. });
  1785. }
  1786. function initWrapperState$1(element, props) {
  1787. var node = element;
  1788. {
  1789. checkSelectPropTypes(props);
  1790. }
  1791. node._wrapperState = {
  1792. wasMultiple: !!props.multiple
  1793. };
  1794. {
  1795. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue$1) {
  1796. error('Select elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled select ' + 'element and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components');
  1797. didWarnValueDefaultValue$1 = true;
  1798. }
  1799. }
  1800. }
  1801. function postMountWrapper$2(element, props) {
  1802. var node = element;
  1803. node.multiple = !!props.multiple;
  1804. var value = props.value;
  1805. if (value != null) {
  1806. updateOptions(node, !!props.multiple, value, false);
  1807. } else if (props.defaultValue != null) {
  1808. updateOptions(node, !!props.multiple, props.defaultValue, true);
  1809. }
  1810. }
  1811. function postUpdateWrapper(element, props) {
  1812. var node = element;
  1813. var wasMultiple = node._wrapperState.wasMultiple;
  1814. node._wrapperState.wasMultiple = !!props.multiple;
  1815. var value = props.value;
  1816. if (value != null) {
  1817. updateOptions(node, !!props.multiple, value, false);
  1818. } else if (wasMultiple !== !!props.multiple) {
  1819. // For simplicity, reapply `defaultValue` if `multiple` is toggled.
  1820. if (props.defaultValue != null) {
  1821. updateOptions(node, !!props.multiple, props.defaultValue, true);
  1822. } else {
  1823. // Revert the select back to its default unselected state.
  1824. updateOptions(node, !!props.multiple, props.multiple ? [] : '', false);
  1825. }
  1826. }
  1827. }
  1828. function restoreControlledState$1(element, props) {
  1829. var node = element;
  1830. var value = props.value;
  1831. if (value != null) {
  1832. updateOptions(node, !!props.multiple, value, false);
  1833. }
  1834. }
  1835. var didWarnValDefaultVal = false;
  1836. /**
  1837. * Implements a <textarea> host component that allows setting `value`, and
  1838. * `defaultValue`. This differs from the traditional DOM API because value is
  1839. * usually set as PCDATA children.
  1840. *
  1841. * If `value` is not supplied (or null/undefined), user actions that affect the
  1842. * value will trigger updates to the element.
  1843. *
  1844. * If `value` is supplied (and not null/undefined), the rendered element will
  1845. * not trigger updates to the element. Instead, the `value` prop must change in
  1846. * order for the rendered element to be updated.
  1847. *
  1848. * The rendered element will be initialized with an empty value, the prop
  1849. * `defaultValue` if specified, or the children content (deprecated).
  1850. */
  1851. function getHostProps$2(element, props) {
  1852. var node = element;
  1853. if (props.dangerouslySetInnerHTML != null) {
  1854. throw new Error('`dangerouslySetInnerHTML` does not make sense on <textarea>.');
  1855. } // Always set children to the same thing. In IE9, the selection range will
  1856. // get reset if `textContent` is mutated. We could add a check in setTextContent
  1857. // to only set the value if/when the value differs from the node value (which would
  1858. // completely solve this IE9 bug), but Sebastian+Sophie seemed to like this
  1859. // solution. The value can be a boolean or object so that's why it's forced
  1860. // to be a string.
  1861. var hostProps = assign({}, props, {
  1862. value: undefined,
  1863. defaultValue: undefined,
  1864. children: toString(node._wrapperState.initialValue)
  1865. });
  1866. return hostProps;
  1867. }
  1868. function initWrapperState$2(element, props) {
  1869. var node = element;
  1870. {
  1871. checkControlledValueProps('textarea', props);
  1872. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValDefaultVal) {
  1873. error('%s contains a textarea with both value and defaultValue props. ' + 'Textarea elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled textarea ' + 'and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component');
  1874. didWarnValDefaultVal = true;
  1875. }
  1876. }
  1877. var initialValue = props.value; // Only bother fetching default value if we're going to use it
  1878. if (initialValue == null) {
  1879. var children = props.children,
  1880. defaultValue = props.defaultValue;
  1881. if (children != null) {
  1882. {
  1883. error('Use the `defaultValue` or `value` props instead of setting ' + 'children on <textarea>.');
  1884. }
  1885. {
  1886. if (defaultValue != null) {
  1887. throw new Error('If you supply `defaultValue` on a <textarea>, do not pass children.');
  1888. }
  1889. if (isArray(children)) {
  1890. if (children.length > 1) {
  1891. throw new Error('<textarea> can only have at most one child.');
  1892. }
  1893. children = children[0];
  1894. }
  1895. defaultValue = children;
  1896. }
  1897. }
  1898. if (defaultValue == null) {
  1899. defaultValue = '';
  1900. }
  1901. initialValue = defaultValue;
  1902. }
  1903. node._wrapperState = {
  1904. initialValue: getToStringValue(initialValue)
  1905. };
  1906. }
  1907. function updateWrapper$1(element, props) {
  1908. var node = element;
  1909. var value = getToStringValue(props.value);
  1910. var defaultValue = getToStringValue(props.defaultValue);
  1911. if (value != null) {
  1912. // Cast `value` to a string to ensure the value is set correctly. While
  1913. // browsers typically do this as necessary, jsdom doesn't.
  1914. var newValue = toString(value); // To avoid side effects (such as losing text selection), only set value if changed
  1915. if (newValue !== node.value) {
  1916. node.value = newValue;
  1917. }
  1918. if (props.defaultValue == null && node.defaultValue !== newValue) {
  1919. node.defaultValue = newValue;
  1920. }
  1921. }
  1922. if (defaultValue != null) {
  1923. node.defaultValue = toString(defaultValue);
  1924. }
  1925. }
  1926. function postMountWrapper$3(element, props) {
  1927. var node = element; // This is in postMount because we need access to the DOM node, which is not
  1928. // available until after the component has mounted.
  1929. var textContent = node.textContent; // Only set node.value if textContent is equal to the expected
  1930. // initial value. In IE10/IE11 there is a bug where the placeholder attribute
  1931. // will populate textContent as well.
  1932. // https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
  1933. if (textContent === node._wrapperState.initialValue) {
  1934. if (textContent !== '' && textContent !== null) {
  1935. node.value = textContent;
  1936. }
  1937. }
  1938. }
  1939. function restoreControlledState$2(element, props) {
  1940. // DOM component is still mounted; update
  1941. updateWrapper$1(element, props);
  1942. }
  1943. var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
  1944. var MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
  1945. var SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; // Assumes there is no parent namespace.
  1946. function getIntrinsicNamespace(type) {
  1947. switch (type) {
  1948. case 'svg':
  1949. return SVG_NAMESPACE;
  1950. case 'math':
  1951. return MATH_NAMESPACE;
  1952. default:
  1953. return HTML_NAMESPACE;
  1954. }
  1955. }
  1956. function getChildNamespace(parentNamespace, type) {
  1957. if (parentNamespace == null || parentNamespace === HTML_NAMESPACE) {
  1958. // No (or default) parent namespace: potential entry point.
  1959. return getIntrinsicNamespace(type);
  1960. }
  1961. if (parentNamespace === SVG_NAMESPACE && type === 'foreignObject') {
  1962. // We're leaving SVG.
  1963. return HTML_NAMESPACE;
  1964. } // By default, pass namespace below.
  1965. return parentNamespace;
  1966. }
  1967. /* globals MSApp */
  1968. /**
  1969. * Create a function which has 'unsafe' privileges (required by windows8 apps)
  1970. */
  1971. var createMicrosoftUnsafeLocalFunction = function (func) {
  1972. if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
  1973. return function (arg0, arg1, arg2, arg3) {
  1974. MSApp.execUnsafeLocalFunction(function () {
  1975. return func(arg0, arg1, arg2, arg3);
  1976. });
  1977. };
  1978. } else {
  1979. return func;
  1980. }
  1981. };
  1982. var reusableSVGContainer;
  1983. /**
  1984. * Set the innerHTML property of a node
  1985. *
  1986. * @param {DOMElement} node
  1987. * @param {string} html
  1988. * @internal
  1989. */
  1990. var setInnerHTML = createMicrosoftUnsafeLocalFunction(function (node, html) {
  1991. if (node.namespaceURI === SVG_NAMESPACE) {
  1992. if (!('innerHTML' in node)) {
  1993. // IE does not have innerHTML for SVG nodes, so instead we inject the
  1994. // new markup in a temp node and then move the child nodes across into
  1995. // the target node
  1996. reusableSVGContainer = reusableSVGContainer || document.createElement('div');
  1997. reusableSVGContainer.innerHTML = '<svg>' + html.valueOf().toString() + '</svg>';
  1998. var svgNode = reusableSVGContainer.firstChild;
  1999. while (node.firstChild) {
  2000. node.removeChild(node.firstChild);
  2001. }
  2002. while (svgNode.firstChild) {
  2003. node.appendChild(svgNode.firstChild);
  2004. }
  2005. return;
  2006. }
  2007. }
  2008. node.innerHTML = html;
  2009. });
  2010. /**
  2011. * HTML nodeType values that represent the type of the node
  2012. */
  2013. var ELEMENT_NODE = 1;
  2014. var TEXT_NODE = 3;
  2015. var COMMENT_NODE = 8;
  2016. var DOCUMENT_NODE = 9;
  2017. var DOCUMENT_FRAGMENT_NODE = 11;
  2018. /**
  2019. * Set the textContent property of a node. For text updates, it's faster
  2020. * to set the `nodeValue` of the Text node directly instead of using
  2021. * `.textContent` which will remove the existing node and create a new one.
  2022. *
  2023. * @param {DOMElement} node
  2024. * @param {string} text
  2025. * @internal
  2026. */
  2027. var setTextContent = function (node, text) {
  2028. if (text) {
  2029. var firstChild = node.firstChild;
  2030. if (firstChild && firstChild === node.lastChild && firstChild.nodeType === TEXT_NODE) {
  2031. firstChild.nodeValue = text;
  2032. return;
  2033. }
  2034. }
  2035. node.textContent = text;
  2036. };
  2037. // List derived from Gecko source code:
  2038. // https://github.com/mozilla/gecko-dev/blob/4e638efc71/layout/style/test/property_database.js
  2039. var shorthandToLonghand = {
  2040. animation: ['animationDelay', 'animationDirection', 'animationDuration', 'animationFillMode', 'animationIterationCount', 'animationName', 'animationPlayState', 'animationTimingFunction'],
  2041. background: ['backgroundAttachment', 'backgroundClip', 'backgroundColor', 'backgroundImage', 'backgroundOrigin', 'backgroundPositionX', 'backgroundPositionY', 'backgroundRepeat', 'backgroundSize'],
  2042. backgroundPosition: ['backgroundPositionX', 'backgroundPositionY'],
  2043. border: ['borderBottomColor', 'borderBottomStyle', 'borderBottomWidth', 'borderImageOutset', 'borderImageRepeat', 'borderImageSlice', 'borderImageSource', 'borderImageWidth', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderTopColor', 'borderTopStyle', 'borderTopWidth'],
  2044. borderBlockEnd: ['borderBlockEndColor', 'borderBlockEndStyle', 'borderBlockEndWidth'],
  2045. borderBlockStart: ['borderBlockStartColor', 'borderBlockStartStyle', 'borderBlockStartWidth'],
  2046. borderBottom: ['borderBottomColor', 'borderBottomStyle', 'borderBottomWidth'],
  2047. borderColor: ['borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor'],
  2048. borderImage: ['borderImageOutset', 'borderImageRepeat', 'borderImageSlice', 'borderImageSource', 'borderImageWidth'],
  2049. borderInlineEnd: ['borderInlineEndColor', 'borderInlineEndStyle', 'borderInlineEndWidth'],
  2050. borderInlineStart: ['borderInlineStartColor', 'borderInlineStartStyle', 'borderInlineStartWidth'],
  2051. borderLeft: ['borderLeftColor', 'borderLeftStyle', 'borderLeftWidth'],
  2052. borderRadius: ['borderBottomLeftRadius', 'borderBottomRightRadius', 'borderTopLeftRadius', 'borderTopRightRadius'],
  2053. borderRight: ['borderRightColor', 'borderRightStyle', 'borderRightWidth'],
  2054. borderStyle: ['borderBottomStyle', 'borderLeftStyle', 'borderRightStyle', 'borderTopStyle'],
  2055. borderTop: ['borderTopColor', 'borderTopStyle', 'borderTopWidth'],
  2056. borderWidth: ['borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth'],
  2057. columnRule: ['columnRuleColor', 'columnRuleStyle', 'columnRuleWidth'],
  2058. columns: ['columnCount', 'columnWidth'],
  2059. flex: ['flexBasis', 'flexGrow', 'flexShrink'],
  2060. flexFlow: ['flexDirection', 'flexWrap'],
  2061. font: ['fontFamily', 'fontFeatureSettings', 'fontKerning', 'fontLanguageOverride', 'fontSize', 'fontSizeAdjust', 'fontStretch', 'fontStyle', 'fontVariant', 'fontVariantAlternates', 'fontVariantCaps', 'fontVariantEastAsian', 'fontVariantLigatures', 'fontVariantNumeric', 'fontVariantPosition', 'fontWeight', 'lineHeight'],
  2062. fontVariant: ['fontVariantAlternates', 'fontVariantCaps', 'fontVariantEastAsian', 'fontVariantLigatures', 'fontVariantNumeric', 'fontVariantPosition'],
  2063. gap: ['columnGap', 'rowGap'],
  2064. grid: ['gridAutoColumns', 'gridAutoFlow', 'gridAutoRows', 'gridTemplateAreas', 'gridTemplateColumns', 'gridTemplateRows'],
  2065. gridArea: ['gridColumnEnd', 'gridColumnStart', 'gridRowEnd', 'gridRowStart'],
  2066. gridColumn: ['gridColumnEnd', 'gridColumnStart'],
  2067. gridColumnGap: ['columnGap'],
  2068. gridGap: ['columnGap', 'rowGap'],
  2069. gridRow: ['gridRowEnd', 'gridRowStart'],
  2070. gridRowGap: ['rowGap'],
  2071. gridTemplate: ['gridTemplateAreas', 'gridTemplateColumns', 'gridTemplateRows'],
  2072. listStyle: ['listStyleImage', 'listStylePosition', 'listStyleType'],
  2073. margin: ['marginBottom', 'marginLeft', 'marginRight', 'marginTop'],
  2074. marker: ['markerEnd', 'markerMid', 'markerStart'],
  2075. mask: ['maskClip', 'maskComposite', 'maskImage', 'maskMode', 'maskOrigin', 'maskPositionX', 'maskPositionY', 'maskRepeat', 'maskSize'],
  2076. maskPosition: ['maskPositionX', 'maskPositionY'],
  2077. outline: ['outlineColor', 'outlineStyle', 'outlineWidth'],
  2078. overflow: ['overflowX', 'overflowY'],
  2079. padding: ['paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop'],
  2080. placeContent: ['alignContent', 'justifyContent'],
  2081. placeItems: ['alignItems', 'justifyItems'],
  2082. placeSelf: ['alignSelf', 'justifySelf'],
  2083. textDecoration: ['textDecorationColor', 'textDecorationLine', 'textDecorationStyle'],
  2084. textEmphasis: ['textEmphasisColor', 'textEmphasisStyle'],
  2085. transition: ['transitionDelay', 'transitionDuration', 'transitionProperty', 'transitionTimingFunction'],
  2086. wordWrap: ['overflowWrap']
  2087. };
  2088. /**
  2089. * CSS properties which accept numbers but are not in units of "px".
  2090. */
  2091. var isUnitlessNumber = {
  2092. animationIterationCount: true,
  2093. aspectRatio: true,
  2094. borderImageOutset: true,
  2095. borderImageSlice: true,
  2096. borderImageWidth: true,
  2097. boxFlex: true,
  2098. boxFlexGroup: true,
  2099. boxOrdinalGroup: true,
  2100. columnCount: true,
  2101. columns: true,
  2102. flex: true,
  2103. flexGrow: true,
  2104. flexPositive: true,
  2105. flexShrink: true,
  2106. flexNegative: true,
  2107. flexOrder: true,
  2108. gridArea: true,
  2109. gridRow: true,
  2110. gridRowEnd: true,
  2111. gridRowSpan: true,
  2112. gridRowStart: true,
  2113. gridColumn: true,
  2114. gridColumnEnd: true,
  2115. gridColumnSpan: true,
  2116. gridColumnStart: true,
  2117. fontWeight: true,
  2118. lineClamp: true,
  2119. lineHeight: true,
  2120. opacity: true,
  2121. order: true,
  2122. orphans: true,
  2123. tabSize: true,
  2124. widows: true,
  2125. zIndex: true,
  2126. zoom: true,
  2127. // SVG-related properties
  2128. fillOpacity: true,
  2129. floodOpacity: true,
  2130. stopOpacity: true,
  2131. strokeDasharray: true,
  2132. strokeDashoffset: true,
  2133. strokeMiterlimit: true,
  2134. strokeOpacity: true,
  2135. strokeWidth: true
  2136. };
  2137. /**
  2138. * @param {string} prefix vendor-specific prefix, eg: Webkit
  2139. * @param {string} key style name, eg: transitionDuration
  2140. * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
  2141. * WebkitTransitionDuration
  2142. */
  2143. function prefixKey(prefix, key) {
  2144. return prefix + key.charAt(0).toUpperCase() + key.substring(1);
  2145. }
  2146. /**
  2147. * Support style names that may come passed in prefixed by adding permutations
  2148. * of vendor prefixes.
  2149. */
  2150. var prefixes = ['Webkit', 'ms', 'Moz', 'O']; // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
  2151. // infinite loop, because it iterates over the newly added props too.
  2152. Object.keys(isUnitlessNumber).forEach(function (prop) {
  2153. prefixes.forEach(function (prefix) {
  2154. isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
  2155. });
  2156. });
  2157. /**
  2158. * Convert a value into the proper css writable value. The style name `name`
  2159. * should be logical (no hyphens), as specified
  2160. * in `CSSProperty.isUnitlessNumber`.
  2161. *
  2162. * @param {string} name CSS property name such as `topMargin`.
  2163. * @param {*} value CSS property value such as `10px`.
  2164. * @return {string} Normalized style value with dimensions applied.
  2165. */
  2166. function dangerousStyleValue(name, value, isCustomProperty) {
  2167. // Note that we've removed escapeTextForBrowser() calls here since the
  2168. // whole string will be escaped when the attribute is injected into
  2169. // the markup. If you provide unsafe user data here they can inject
  2170. // arbitrary CSS which may be problematic (I couldn't repro this):
  2171. // https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
  2172. // http://www.thespanner.co.uk/2007/11/26/ultimate-xss-css-injection/
  2173. // This is not an XSS hole but instead a potential CSS injection issue
  2174. // which has lead to a greater discussion about how we're going to
  2175. // trust URLs moving forward. See #2115901
  2176. var isEmpty = value == null || typeof value === 'boolean' || value === '';
  2177. if (isEmpty) {
  2178. return '';
  2179. }
  2180. if (!isCustomProperty && typeof value === 'number' && value !== 0 && !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])) {
  2181. return value + 'px'; // Presumes implicit 'px' suffix for unitless numbers
  2182. }
  2183. {
  2184. checkCSSPropertyStringCoercion(value, name);
  2185. }
  2186. return ('' + value).trim();
  2187. }
  2188. var uppercasePattern = /([A-Z])/g;
  2189. var msPattern = /^ms-/;
  2190. /**
  2191. * Hyphenates a camelcased CSS property name, for example:
  2192. *
  2193. * > hyphenateStyleName('backgroundColor')
  2194. * < "background-color"
  2195. * > hyphenateStyleName('MozTransition')
  2196. * < "-moz-transition"
  2197. * > hyphenateStyleName('msTransition')
  2198. * < "-ms-transition"
  2199. *
  2200. * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
  2201. * is converted to `-ms-`.
  2202. */
  2203. function hyphenateStyleName(name) {
  2204. return name.replace(uppercasePattern, '-$1').toLowerCase().replace(msPattern, '-ms-');
  2205. }
  2206. var warnValidStyle = function () {};
  2207. {
  2208. // 'msTransform' is correct, but the other prefixes should be capitalized
  2209. var badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
  2210. var msPattern$1 = /^-ms-/;
  2211. var hyphenPattern = /-(.)/g; // style values shouldn't contain a semicolon
  2212. var badStyleValueWithSemicolonPattern = /;\s*$/;
  2213. var warnedStyleNames = {};
  2214. var warnedStyleValues = {};
  2215. var warnedForNaNValue = false;
  2216. var warnedForInfinityValue = false;
  2217. var camelize = function (string) {
  2218. return string.replace(hyphenPattern, function (_, character) {
  2219. return character.toUpperCase();
  2220. });
  2221. };
  2222. var warnHyphenatedStyleName = function (name) {
  2223. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  2224. return;
  2225. }
  2226. warnedStyleNames[name] = true;
  2227. error('Unsupported style property %s. Did you mean %s?', name, // As Andi Smith suggests
  2228. // (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix
  2229. // is converted to lowercase `ms`.
  2230. camelize(name.replace(msPattern$1, 'ms-')));
  2231. };
  2232. var warnBadVendoredStyleName = function (name) {
  2233. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  2234. return;
  2235. }
  2236. warnedStyleNames[name] = true;
  2237. error('Unsupported vendor-prefixed style property %s. Did you mean %s?', name, name.charAt(0).toUpperCase() + name.slice(1));
  2238. };
  2239. var warnStyleValueWithSemicolon = function (name, value) {
  2240. if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
  2241. return;
  2242. }
  2243. warnedStyleValues[value] = true;
  2244. error("Style property values shouldn't contain a semicolon. " + 'Try "%s: %s" instead.', name, value.replace(badStyleValueWithSemicolonPattern, ''));
  2245. };
  2246. var warnStyleValueIsNaN = function (name, value) {
  2247. if (warnedForNaNValue) {
  2248. return;
  2249. }
  2250. warnedForNaNValue = true;
  2251. error('`NaN` is an invalid value for the `%s` css style property.', name);
  2252. };
  2253. var warnStyleValueIsInfinity = function (name, value) {
  2254. if (warnedForInfinityValue) {
  2255. return;
  2256. }
  2257. warnedForInfinityValue = true;
  2258. error('`Infinity` is an invalid value for the `%s` css style property.', name);
  2259. };
  2260. warnValidStyle = function (name, value) {
  2261. if (name.indexOf('-') > -1) {
  2262. warnHyphenatedStyleName(name);
  2263. } else if (badVendoredStyleNamePattern.test(name)) {
  2264. warnBadVendoredStyleName(name);
  2265. } else if (badStyleValueWithSemicolonPattern.test(value)) {
  2266. warnStyleValueWithSemicolon(name, value);
  2267. }
  2268. if (typeof value === 'number') {
  2269. if (isNaN(value)) {
  2270. warnStyleValueIsNaN(name, value);
  2271. } else if (!isFinite(value)) {
  2272. warnStyleValueIsInfinity(name, value);
  2273. }
  2274. }
  2275. };
  2276. }
  2277. var warnValidStyle$1 = warnValidStyle;
  2278. /**
  2279. * Operations for dealing with CSS properties.
  2280. */
  2281. /**
  2282. * This creates a string that is expected to be equivalent to the style
  2283. * attribute generated by server-side rendering. It by-passes warnings and
  2284. * security checks so it's not safe to use this value for anything other than
  2285. * comparison. It is only used in DEV for SSR validation.
  2286. */
  2287. function createDangerousStringForStyles(styles) {
  2288. {
  2289. var serialized = '';
  2290. var delimiter = '';
  2291. for (var styleName in styles) {
  2292. if (!styles.hasOwnProperty(styleName)) {
  2293. continue;
  2294. }
  2295. var styleValue = styles[styleName];
  2296. if (styleValue != null) {
  2297. var isCustomProperty = styleName.indexOf('--') === 0;
  2298. serialized += delimiter + (isCustomProperty ? styleName : hyphenateStyleName(styleName)) + ':';
  2299. serialized += dangerousStyleValue(styleName, styleValue, isCustomProperty);
  2300. delimiter = ';';
  2301. }
  2302. }
  2303. return serialized || null;
  2304. }
  2305. }
  2306. /**
  2307. * Sets the value for multiple styles on a node. If a value is specified as
  2308. * '' (empty string), the corresponding style property will be unset.
  2309. *
  2310. * @param {DOMElement} node
  2311. * @param {object} styles
  2312. */
  2313. function setValueForStyles(node, styles) {
  2314. var style = node.style;
  2315. for (var styleName in styles) {
  2316. if (!styles.hasOwnProperty(styleName)) {
  2317. continue;
  2318. }
  2319. var isCustomProperty = styleName.indexOf('--') === 0;
  2320. {
  2321. if (!isCustomProperty) {
  2322. warnValidStyle$1(styleName, styles[styleName]);
  2323. }
  2324. }
  2325. var styleValue = dangerousStyleValue(styleName, styles[styleName], isCustomProperty);
  2326. if (styleName === 'float') {
  2327. styleName = 'cssFloat';
  2328. }
  2329. if (isCustomProperty) {
  2330. style.setProperty(styleName, styleValue);
  2331. } else {
  2332. style[styleName] = styleValue;
  2333. }
  2334. }
  2335. }
  2336. function isValueEmpty(value) {
  2337. return value == null || typeof value === 'boolean' || value === '';
  2338. }
  2339. /**
  2340. * Given {color: 'red', overflow: 'hidden'} returns {
  2341. * color: 'color',
  2342. * overflowX: 'overflow',
  2343. * overflowY: 'overflow',
  2344. * }. This can be read as "the overflowY property was set by the overflow
  2345. * shorthand". That is, the values are the property that each was derived from.
  2346. */
  2347. function expandShorthandMap(styles) {
  2348. var expanded = {};
  2349. for (var key in styles) {
  2350. var longhands = shorthandToLonghand[key] || [key];
  2351. for (var i = 0; i < longhands.length; i++) {
  2352. expanded[longhands[i]] = key;
  2353. }
  2354. }
  2355. return expanded;
  2356. }
  2357. /**
  2358. * When mixing shorthand and longhand property names, we warn during updates if
  2359. * we expect an incorrect result to occur. In particular, we warn for:
  2360. *
  2361. * Updating a shorthand property (longhand gets overwritten):
  2362. * {font: 'foo', fontVariant: 'bar'} -> {font: 'baz', fontVariant: 'bar'}
  2363. * becomes .style.font = 'baz'
  2364. * Removing a shorthand property (longhand gets lost too):
  2365. * {font: 'foo', fontVariant: 'bar'} -> {fontVariant: 'bar'}
  2366. * becomes .style.font = ''
  2367. * Removing a longhand property (should revert to shorthand; doesn't):
  2368. * {font: 'foo', fontVariant: 'bar'} -> {font: 'foo'}
  2369. * becomes .style.fontVariant = ''
  2370. */
  2371. function validateShorthandPropertyCollisionInDev(styleUpdates, nextStyles) {
  2372. {
  2373. if (!nextStyles) {
  2374. return;
  2375. }
  2376. var expandedUpdates = expandShorthandMap(styleUpdates);
  2377. var expandedStyles = expandShorthandMap(nextStyles);
  2378. var warnedAbout = {};
  2379. for (var key in expandedUpdates) {
  2380. var originalKey = expandedUpdates[key];
  2381. var correctOriginalKey = expandedStyles[key];
  2382. if (correctOriginalKey && originalKey !== correctOriginalKey) {
  2383. var warningKey = originalKey + ',' + correctOriginalKey;
  2384. if (warnedAbout[warningKey]) {
  2385. continue;
  2386. }
  2387. warnedAbout[warningKey] = true;
  2388. error('%s a style property during rerender (%s) when a ' + 'conflicting property is set (%s) can lead to styling bugs. To ' + "avoid this, don't mix shorthand and non-shorthand properties " + 'for the same value; instead, replace the shorthand with ' + 'separate values.', isValueEmpty(styleUpdates[originalKey]) ? 'Removing' : 'Updating', originalKey, correctOriginalKey);
  2389. }
  2390. }
  2391. }
  2392. }
  2393. // For HTML, certain tags should omit their close tag. We keep a list for
  2394. // those special-case tags.
  2395. var omittedCloseTags = {
  2396. area: true,
  2397. base: true,
  2398. br: true,
  2399. col: true,
  2400. embed: true,
  2401. hr: true,
  2402. img: true,
  2403. input: true,
  2404. keygen: true,
  2405. link: true,
  2406. meta: true,
  2407. param: true,
  2408. source: true,
  2409. track: true,
  2410. wbr: true // NOTE: menuitem's close tag should be omitted, but that causes problems.
  2411. };
  2412. // `omittedCloseTags` except that `menuitem` should still have its closing tag.
  2413. var voidElementTags = assign({
  2414. menuitem: true
  2415. }, omittedCloseTags);
  2416. var HTML = '__html';
  2417. function assertValidProps(tag, props) {
  2418. if (!props) {
  2419. return;
  2420. } // Note the use of `==` which checks for null or undefined.
  2421. if (voidElementTags[tag]) {
  2422. if (props.children != null || props.dangerouslySetInnerHTML != null) {
  2423. throw new Error(tag + " is a void element tag and must neither have `children` nor " + 'use `dangerouslySetInnerHTML`.');
  2424. }
  2425. }
  2426. if (props.dangerouslySetInnerHTML != null) {
  2427. if (props.children != null) {
  2428. throw new Error('Can only set one of `children` or `props.dangerouslySetInnerHTML`.');
  2429. }
  2430. if (typeof props.dangerouslySetInnerHTML !== 'object' || !(HTML in props.dangerouslySetInnerHTML)) {
  2431. throw new Error('`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' + 'Please visit https://reactjs.org/link/dangerously-set-inner-html ' + 'for more information.');
  2432. }
  2433. }
  2434. {
  2435. if (!props.suppressContentEditableWarning && props.contentEditable && props.children != null) {
  2436. error('A component is `contentEditable` and contains `children` managed by ' + 'React. It is now your responsibility to guarantee that none of ' + 'those nodes are unexpectedly modified or duplicated. This is ' + 'probably not intentional.');
  2437. }
  2438. }
  2439. if (props.style != null && typeof props.style !== 'object') {
  2440. throw new Error('The `style` prop expects a mapping from style properties to values, ' + "not a string. For example, style={{marginRight: spacing + 'em'}} when " + 'using JSX.');
  2441. }
  2442. }
  2443. function isCustomComponent(tagName, props) {
  2444. if (tagName.indexOf('-') === -1) {
  2445. return typeof props.is === 'string';
  2446. }
  2447. switch (tagName) {
  2448. // These are reserved SVG and MathML elements.
  2449. // We don't mind this list too much because we expect it to never grow.
  2450. // The alternative is to track the namespace in a few places which is convoluted.
  2451. // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
  2452. case 'annotation-xml':
  2453. case 'color-profile':
  2454. case 'font-face':
  2455. case 'font-face-src':
  2456. case 'font-face-uri':
  2457. case 'font-face-format':
  2458. case 'font-face-name':
  2459. case 'missing-glyph':
  2460. return false;
  2461. default:
  2462. return true;
  2463. }
  2464. }
  2465. // When adding attributes to the HTML or SVG allowed attribute list, be sure to
  2466. // also add them to this module to ensure casing and incorrect name
  2467. // warnings.
  2468. var possibleStandardNames = {
  2469. // HTML
  2470. accept: 'accept',
  2471. acceptcharset: 'acceptCharset',
  2472. 'accept-charset': 'acceptCharset',
  2473. accesskey: 'accessKey',
  2474. action: 'action',
  2475. allowfullscreen: 'allowFullScreen',
  2476. alt: 'alt',
  2477. as: 'as',
  2478. async: 'async',
  2479. autocapitalize: 'autoCapitalize',
  2480. autocomplete: 'autoComplete',
  2481. autocorrect: 'autoCorrect',
  2482. autofocus: 'autoFocus',
  2483. autoplay: 'autoPlay',
  2484. autosave: 'autoSave',
  2485. capture: 'capture',
  2486. cellpadding: 'cellPadding',
  2487. cellspacing: 'cellSpacing',
  2488. challenge: 'challenge',
  2489. charset: 'charSet',
  2490. checked: 'checked',
  2491. children: 'children',
  2492. cite: 'cite',
  2493. class: 'className',
  2494. classid: 'classID',
  2495. classname: 'className',
  2496. cols: 'cols',
  2497. colspan: 'colSpan',
  2498. content: 'content',
  2499. contenteditable: 'contentEditable',
  2500. contextmenu: 'contextMenu',
  2501. controls: 'controls',
  2502. controlslist: 'controlsList',
  2503. coords: 'coords',
  2504. crossorigin: 'crossOrigin',
  2505. dangerouslysetinnerhtml: 'dangerouslySetInnerHTML',
  2506. data: 'data',
  2507. datetime: 'dateTime',
  2508. default: 'default',
  2509. defaultchecked: 'defaultChecked',
  2510. defaultvalue: 'defaultValue',
  2511. defer: 'defer',
  2512. dir: 'dir',
  2513. disabled: 'disabled',
  2514. disablepictureinpicture: 'disablePictureInPicture',
  2515. disableremoteplayback: 'disableRemotePlayback',
  2516. download: 'download',
  2517. draggable: 'draggable',
  2518. enctype: 'encType',
  2519. enterkeyhint: 'enterKeyHint',
  2520. for: 'htmlFor',
  2521. form: 'form',
  2522. formmethod: 'formMethod',
  2523. formaction: 'formAction',
  2524. formenctype: 'formEncType',
  2525. formnovalidate: 'formNoValidate',
  2526. formtarget: 'formTarget',
  2527. frameborder: 'frameBorder',
  2528. headers: 'headers',
  2529. height: 'height',
  2530. hidden: 'hidden',
  2531. high: 'high',
  2532. href: 'href',
  2533. hreflang: 'hrefLang',
  2534. htmlfor: 'htmlFor',
  2535. httpequiv: 'httpEquiv',
  2536. 'http-equiv': 'httpEquiv',
  2537. icon: 'icon',
  2538. id: 'id',
  2539. imagesizes: 'imageSizes',
  2540. imagesrcset: 'imageSrcSet',
  2541. innerhtml: 'innerHTML',
  2542. inputmode: 'inputMode',
  2543. integrity: 'integrity',
  2544. is: 'is',
  2545. itemid: 'itemID',
  2546. itemprop: 'itemProp',
  2547. itemref: 'itemRef',
  2548. itemscope: 'itemScope',
  2549. itemtype: 'itemType',
  2550. keyparams: 'keyParams',
  2551. keytype: 'keyType',
  2552. kind: 'kind',
  2553. label: 'label',
  2554. lang: 'lang',
  2555. list: 'list',
  2556. loop: 'loop',
  2557. low: 'low',
  2558. manifest: 'manifest',
  2559. marginwidth: 'marginWidth',
  2560. marginheight: 'marginHeight',
  2561. max: 'max',
  2562. maxlength: 'maxLength',
  2563. media: 'media',
  2564. mediagroup: 'mediaGroup',
  2565. method: 'method',
  2566. min: 'min',
  2567. minlength: 'minLength',
  2568. multiple: 'multiple',
  2569. muted: 'muted',
  2570. name: 'name',
  2571. nomodule: 'noModule',
  2572. nonce: 'nonce',
  2573. novalidate: 'noValidate',
  2574. open: 'open',
  2575. optimum: 'optimum',
  2576. pattern: 'pattern',
  2577. placeholder: 'placeholder',
  2578. playsinline: 'playsInline',
  2579. poster: 'poster',
  2580. preload: 'preload',
  2581. profile: 'profile',
  2582. radiogroup: 'radioGroup',
  2583. readonly: 'readOnly',
  2584. referrerpolicy: 'referrerPolicy',
  2585. rel: 'rel',
  2586. required: 'required',
  2587. reversed: 'reversed',
  2588. role: 'role',
  2589. rows: 'rows',
  2590. rowspan: 'rowSpan',
  2591. sandbox: 'sandbox',
  2592. scope: 'scope',
  2593. scoped: 'scoped',
  2594. scrolling: 'scrolling',
  2595. seamless: 'seamless',
  2596. selected: 'selected',
  2597. shape: 'shape',
  2598. size: 'size',
  2599. sizes: 'sizes',
  2600. span: 'span',
  2601. spellcheck: 'spellCheck',
  2602. src: 'src',
  2603. srcdoc: 'srcDoc',
  2604. srclang: 'srcLang',
  2605. srcset: 'srcSet',
  2606. start: 'start',
  2607. step: 'step',
  2608. style: 'style',
  2609. summary: 'summary',
  2610. tabindex: 'tabIndex',
  2611. target: 'target',
  2612. title: 'title',
  2613. type: 'type',
  2614. usemap: 'useMap',
  2615. value: 'value',
  2616. width: 'width',
  2617. wmode: 'wmode',
  2618. wrap: 'wrap',
  2619. // SVG
  2620. about: 'about',
  2621. accentheight: 'accentHeight',
  2622. 'accent-height': 'accentHeight',
  2623. accumulate: 'accumulate',
  2624. additive: 'additive',
  2625. alignmentbaseline: 'alignmentBaseline',
  2626. 'alignment-baseline': 'alignmentBaseline',
  2627. allowreorder: 'allowReorder',
  2628. alphabetic: 'alphabetic',
  2629. amplitude: 'amplitude',
  2630. arabicform: 'arabicForm',
  2631. 'arabic-form': 'arabicForm',
  2632. ascent: 'ascent',
  2633. attributename: 'attributeName',
  2634. attributetype: 'attributeType',
  2635. autoreverse: 'autoReverse',
  2636. azimuth: 'azimuth',
  2637. basefrequency: 'baseFrequency',
  2638. baselineshift: 'baselineShift',
  2639. 'baseline-shift': 'baselineShift',
  2640. baseprofile: 'baseProfile',
  2641. bbox: 'bbox',
  2642. begin: 'begin',
  2643. bias: 'bias',
  2644. by: 'by',
  2645. calcmode: 'calcMode',
  2646. capheight: 'capHeight',
  2647. 'cap-height': 'capHeight',
  2648. clip: 'clip',
  2649. clippath: 'clipPath',
  2650. 'clip-path': 'clipPath',
  2651. clippathunits: 'clipPathUnits',
  2652. cliprule: 'clipRule',
  2653. 'clip-rule': 'clipRule',
  2654. color: 'color',
  2655. colorinterpolation: 'colorInterpolation',
  2656. 'color-interpolation': 'colorInterpolation',
  2657. colorinterpolationfilters: 'colorInterpolationFilters',
  2658. 'color-interpolation-filters': 'colorInterpolationFilters',
  2659. colorprofile: 'colorProfile',
  2660. 'color-profile': 'colorProfile',
  2661. colorrendering: 'colorRendering',
  2662. 'color-rendering': 'colorRendering',
  2663. contentscripttype: 'contentScriptType',
  2664. contentstyletype: 'contentStyleType',
  2665. cursor: 'cursor',
  2666. cx: 'cx',
  2667. cy: 'cy',
  2668. d: 'd',
  2669. datatype: 'datatype',
  2670. decelerate: 'decelerate',
  2671. descent: 'descent',
  2672. diffuseconstant: 'diffuseConstant',
  2673. direction: 'direction',
  2674. display: 'display',
  2675. divisor: 'divisor',
  2676. dominantbaseline: 'dominantBaseline',
  2677. 'dominant-baseline': 'dominantBaseline',
  2678. dur: 'dur',
  2679. dx: 'dx',
  2680. dy: 'dy',
  2681. edgemode: 'edgeMode',
  2682. elevation: 'elevation',
  2683. enablebackground: 'enableBackground',
  2684. 'enable-background': 'enableBackground',
  2685. end: 'end',
  2686. exponent: 'exponent',
  2687. externalresourcesrequired: 'externalResourcesRequired',
  2688. fill: 'fill',
  2689. fillopacity: 'fillOpacity',
  2690. 'fill-opacity': 'fillOpacity',
  2691. fillrule: 'fillRule',
  2692. 'fill-rule': 'fillRule',
  2693. filter: 'filter',
  2694. filterres: 'filterRes',
  2695. filterunits: 'filterUnits',
  2696. floodopacity: 'floodOpacity',
  2697. 'flood-opacity': 'floodOpacity',
  2698. floodcolor: 'floodColor',
  2699. 'flood-color': 'floodColor',
  2700. focusable: 'focusable',
  2701. fontfamily: 'fontFamily',
  2702. 'font-family': 'fontFamily',
  2703. fontsize: 'fontSize',
  2704. 'font-size': 'fontSize',
  2705. fontsizeadjust: 'fontSizeAdjust',
  2706. 'font-size-adjust': 'fontSizeAdjust',
  2707. fontstretch: 'fontStretch',
  2708. 'font-stretch': 'fontStretch',
  2709. fontstyle: 'fontStyle',
  2710. 'font-style': 'fontStyle',
  2711. fontvariant: 'fontVariant',
  2712. 'font-variant': 'fontVariant',
  2713. fontweight: 'fontWeight',
  2714. 'font-weight': 'fontWeight',
  2715. format: 'format',
  2716. from: 'from',
  2717. fx: 'fx',
  2718. fy: 'fy',
  2719. g1: 'g1',
  2720. g2: 'g2',
  2721. glyphname: 'glyphName',
  2722. 'glyph-name': 'glyphName',
  2723. glyphorientationhorizontal: 'glyphOrientationHorizontal',
  2724. 'glyph-orientation-horizontal': 'glyphOrientationHorizontal',
  2725. glyphorientationvertical: 'glyphOrientationVertical',
  2726. 'glyph-orientation-vertical': 'glyphOrientationVertical',
  2727. glyphref: 'glyphRef',
  2728. gradienttransform: 'gradientTransform',
  2729. gradientunits: 'gradientUnits',
  2730. hanging: 'hanging',
  2731. horizadvx: 'horizAdvX',
  2732. 'horiz-adv-x': 'horizAdvX',
  2733. horizoriginx: 'horizOriginX',
  2734. 'horiz-origin-x': 'horizOriginX',
  2735. ideographic: 'ideographic',
  2736. imagerendering: 'imageRendering',
  2737. 'image-rendering': 'imageRendering',
  2738. in2: 'in2',
  2739. in: 'in',
  2740. inlist: 'inlist',
  2741. intercept: 'intercept',
  2742. k1: 'k1',
  2743. k2: 'k2',
  2744. k3: 'k3',
  2745. k4: 'k4',
  2746. k: 'k',
  2747. kernelmatrix: 'kernelMatrix',
  2748. kernelunitlength: 'kernelUnitLength',
  2749. kerning: 'kerning',
  2750. keypoints: 'keyPoints',
  2751. keysplines: 'keySplines',
  2752. keytimes: 'keyTimes',
  2753. lengthadjust: 'lengthAdjust',
  2754. letterspacing: 'letterSpacing',
  2755. 'letter-spacing': 'letterSpacing',
  2756. lightingcolor: 'lightingColor',
  2757. 'lighting-color': 'lightingColor',
  2758. limitingconeangle: 'limitingConeAngle',
  2759. local: 'local',
  2760. markerend: 'markerEnd',
  2761. 'marker-end': 'markerEnd',
  2762. markerheight: 'markerHeight',
  2763. markermid: 'markerMid',
  2764. 'marker-mid': 'markerMid',
  2765. markerstart: 'markerStart',
  2766. 'marker-start': 'markerStart',
  2767. markerunits: 'markerUnits',
  2768. markerwidth: 'markerWidth',
  2769. mask: 'mask',
  2770. maskcontentunits: 'maskContentUnits',
  2771. maskunits: 'maskUnits',
  2772. mathematical: 'mathematical',
  2773. mode: 'mode',
  2774. numoctaves: 'numOctaves',
  2775. offset: 'offset',
  2776. opacity: 'opacity',
  2777. operator: 'operator',
  2778. order: 'order',
  2779. orient: 'orient',
  2780. orientation: 'orientation',
  2781. origin: 'origin',
  2782. overflow: 'overflow',
  2783. overlineposition: 'overlinePosition',
  2784. 'overline-position': 'overlinePosition',
  2785. overlinethickness: 'overlineThickness',
  2786. 'overline-thickness': 'overlineThickness',
  2787. paintorder: 'paintOrder',
  2788. 'paint-order': 'paintOrder',
  2789. panose1: 'panose1',
  2790. 'panose-1': 'panose1',
  2791. pathlength: 'pathLength',
  2792. patterncontentunits: 'patternContentUnits',
  2793. patterntransform: 'patternTransform',
  2794. patternunits: 'patternUnits',
  2795. pointerevents: 'pointerEvents',
  2796. 'pointer-events': 'pointerEvents',
  2797. points: 'points',
  2798. pointsatx: 'pointsAtX',
  2799. pointsaty: 'pointsAtY',
  2800. pointsatz: 'pointsAtZ',
  2801. prefix: 'prefix',
  2802. preservealpha: 'preserveAlpha',
  2803. preserveaspectratio: 'preserveAspectRatio',
  2804. primitiveunits: 'primitiveUnits',
  2805. property: 'property',
  2806. r: 'r',
  2807. radius: 'radius',
  2808. refx: 'refX',
  2809. refy: 'refY',
  2810. renderingintent: 'renderingIntent',
  2811. 'rendering-intent': 'renderingIntent',
  2812. repeatcount: 'repeatCount',
  2813. repeatdur: 'repeatDur',
  2814. requiredextensions: 'requiredExtensions',
  2815. requiredfeatures: 'requiredFeatures',
  2816. resource: 'resource',
  2817. restart: 'restart',
  2818. result: 'result',
  2819. results: 'results',
  2820. rotate: 'rotate',
  2821. rx: 'rx',
  2822. ry: 'ry',
  2823. scale: 'scale',
  2824. security: 'security',
  2825. seed: 'seed',
  2826. shaperendering: 'shapeRendering',
  2827. 'shape-rendering': 'shapeRendering',
  2828. slope: 'slope',
  2829. spacing: 'spacing',
  2830. specularconstant: 'specularConstant',
  2831. specularexponent: 'specularExponent',
  2832. speed: 'speed',
  2833. spreadmethod: 'spreadMethod',
  2834. startoffset: 'startOffset',
  2835. stddeviation: 'stdDeviation',
  2836. stemh: 'stemh',
  2837. stemv: 'stemv',
  2838. stitchtiles: 'stitchTiles',
  2839. stopcolor: 'stopColor',
  2840. 'stop-color': 'stopColor',
  2841. stopopacity: 'stopOpacity',
  2842. 'stop-opacity': 'stopOpacity',
  2843. strikethroughposition: 'strikethroughPosition',
  2844. 'strikethrough-position': 'strikethroughPosition',
  2845. strikethroughthickness: 'strikethroughThickness',
  2846. 'strikethrough-thickness': 'strikethroughThickness',
  2847. string: 'string',
  2848. stroke: 'stroke',
  2849. strokedasharray: 'strokeDasharray',
  2850. 'stroke-dasharray': 'strokeDasharray',
  2851. strokedashoffset: 'strokeDashoffset',
  2852. 'stroke-dashoffset': 'strokeDashoffset',
  2853. strokelinecap: 'strokeLinecap',
  2854. 'stroke-linecap': 'strokeLinecap',
  2855. strokelinejoin: 'strokeLinejoin',
  2856. 'stroke-linejoin': 'strokeLinejoin',
  2857. strokemiterlimit: 'strokeMiterlimit',
  2858. 'stroke-miterlimit': 'strokeMiterlimit',
  2859. strokewidth: 'strokeWidth',
  2860. 'stroke-width': 'strokeWidth',
  2861. strokeopacity: 'strokeOpacity',
  2862. 'stroke-opacity': 'strokeOpacity',
  2863. suppresscontenteditablewarning: 'suppressContentEditableWarning',
  2864. suppresshydrationwarning: 'suppressHydrationWarning',
  2865. surfacescale: 'surfaceScale',
  2866. systemlanguage: 'systemLanguage',
  2867. tablevalues: 'tableValues',
  2868. targetx: 'targetX',
  2869. targety: 'targetY',
  2870. textanchor: 'textAnchor',
  2871. 'text-anchor': 'textAnchor',
  2872. textdecoration: 'textDecoration',
  2873. 'text-decoration': 'textDecoration',
  2874. textlength: 'textLength',
  2875. textrendering: 'textRendering',
  2876. 'text-rendering': 'textRendering',
  2877. to: 'to',
  2878. transform: 'transform',
  2879. typeof: 'typeof',
  2880. u1: 'u1',
  2881. u2: 'u2',
  2882. underlineposition: 'underlinePosition',
  2883. 'underline-position': 'underlinePosition',
  2884. underlinethickness: 'underlineThickness',
  2885. 'underline-thickness': 'underlineThickness',
  2886. unicode: 'unicode',
  2887. unicodebidi: 'unicodeBidi',
  2888. 'unicode-bidi': 'unicodeBidi',
  2889. unicoderange: 'unicodeRange',
  2890. 'unicode-range': 'unicodeRange',
  2891. unitsperem: 'unitsPerEm',
  2892. 'units-per-em': 'unitsPerEm',
  2893. unselectable: 'unselectable',
  2894. valphabetic: 'vAlphabetic',
  2895. 'v-alphabetic': 'vAlphabetic',
  2896. values: 'values',
  2897. vectoreffect: 'vectorEffect',
  2898. 'vector-effect': 'vectorEffect',
  2899. version: 'version',
  2900. vertadvy: 'vertAdvY',
  2901. 'vert-adv-y': 'vertAdvY',
  2902. vertoriginx: 'vertOriginX',
  2903. 'vert-origin-x': 'vertOriginX',
  2904. vertoriginy: 'vertOriginY',
  2905. 'vert-origin-y': 'vertOriginY',
  2906. vhanging: 'vHanging',
  2907. 'v-hanging': 'vHanging',
  2908. videographic: 'vIdeographic',
  2909. 'v-ideographic': 'vIdeographic',
  2910. viewbox: 'viewBox',
  2911. viewtarget: 'viewTarget',
  2912. visibility: 'visibility',
  2913. vmathematical: 'vMathematical',
  2914. 'v-mathematical': 'vMathematical',
  2915. vocab: 'vocab',
  2916. widths: 'widths',
  2917. wordspacing: 'wordSpacing',
  2918. 'word-spacing': 'wordSpacing',
  2919. writingmode: 'writingMode',
  2920. 'writing-mode': 'writingMode',
  2921. x1: 'x1',
  2922. x2: 'x2',
  2923. x: 'x',
  2924. xchannelselector: 'xChannelSelector',
  2925. xheight: 'xHeight',
  2926. 'x-height': 'xHeight',
  2927. xlinkactuate: 'xlinkActuate',
  2928. 'xlink:actuate': 'xlinkActuate',
  2929. xlinkarcrole: 'xlinkArcrole',
  2930. 'xlink:arcrole': 'xlinkArcrole',
  2931. xlinkhref: 'xlinkHref',
  2932. 'xlink:href': 'xlinkHref',
  2933. xlinkrole: 'xlinkRole',
  2934. 'xlink:role': 'xlinkRole',
  2935. xlinkshow: 'xlinkShow',
  2936. 'xlink:show': 'xlinkShow',
  2937. xlinktitle: 'xlinkTitle',
  2938. 'xlink:title': 'xlinkTitle',
  2939. xlinktype: 'xlinkType',
  2940. 'xlink:type': 'xlinkType',
  2941. xmlbase: 'xmlBase',
  2942. 'xml:base': 'xmlBase',
  2943. xmllang: 'xmlLang',
  2944. 'xml:lang': 'xmlLang',
  2945. xmlns: 'xmlns',
  2946. 'xml:space': 'xmlSpace',
  2947. xmlnsxlink: 'xmlnsXlink',
  2948. 'xmlns:xlink': 'xmlnsXlink',
  2949. xmlspace: 'xmlSpace',
  2950. y1: 'y1',
  2951. y2: 'y2',
  2952. y: 'y',
  2953. ychannelselector: 'yChannelSelector',
  2954. z: 'z',
  2955. zoomandpan: 'zoomAndPan'
  2956. };
  2957. var ariaProperties = {
  2958. 'aria-current': 0,
  2959. // state
  2960. 'aria-description': 0,
  2961. 'aria-details': 0,
  2962. 'aria-disabled': 0,
  2963. // state
  2964. 'aria-hidden': 0,
  2965. // state
  2966. 'aria-invalid': 0,
  2967. // state
  2968. 'aria-keyshortcuts': 0,
  2969. 'aria-label': 0,
  2970. 'aria-roledescription': 0,
  2971. // Widget Attributes
  2972. 'aria-autocomplete': 0,
  2973. 'aria-checked': 0,
  2974. 'aria-expanded': 0,
  2975. 'aria-haspopup': 0,
  2976. 'aria-level': 0,
  2977. 'aria-modal': 0,
  2978. 'aria-multiline': 0,
  2979. 'aria-multiselectable': 0,
  2980. 'aria-orientation': 0,
  2981. 'aria-placeholder': 0,
  2982. 'aria-pressed': 0,
  2983. 'aria-readonly': 0,
  2984. 'aria-required': 0,
  2985. 'aria-selected': 0,
  2986. 'aria-sort': 0,
  2987. 'aria-valuemax': 0,
  2988. 'aria-valuemin': 0,
  2989. 'aria-valuenow': 0,
  2990. 'aria-valuetext': 0,
  2991. // Live Region Attributes
  2992. 'aria-atomic': 0,
  2993. 'aria-busy': 0,
  2994. 'aria-live': 0,
  2995. 'aria-relevant': 0,
  2996. // Drag-and-Drop Attributes
  2997. 'aria-dropeffect': 0,
  2998. 'aria-grabbed': 0,
  2999. // Relationship Attributes
  3000. 'aria-activedescendant': 0,
  3001. 'aria-colcount': 0,
  3002. 'aria-colindex': 0,
  3003. 'aria-colspan': 0,
  3004. 'aria-controls': 0,
  3005. 'aria-describedby': 0,
  3006. 'aria-errormessage': 0,
  3007. 'aria-flowto': 0,
  3008. 'aria-labelledby': 0,
  3009. 'aria-owns': 0,
  3010. 'aria-posinset': 0,
  3011. 'aria-rowcount': 0,
  3012. 'aria-rowindex': 0,
  3013. 'aria-rowspan': 0,
  3014. 'aria-setsize': 0
  3015. };
  3016. var warnedProperties = {};
  3017. var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  3018. var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  3019. function validateProperty(tagName, name) {
  3020. {
  3021. if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
  3022. return true;
  3023. }
  3024. if (rARIACamel.test(name)) {
  3025. var ariaName = 'aria-' + name.slice(4).toLowerCase();
  3026. var correctName = ariaProperties.hasOwnProperty(ariaName) ? ariaName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  3027. // DOM properties, then it is an invalid aria-* attribute.
  3028. if (correctName == null) {
  3029. error('Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.', name);
  3030. warnedProperties[name] = true;
  3031. return true;
  3032. } // aria-* attributes should be lowercase; suggest the lowercase version.
  3033. if (name !== correctName) {
  3034. error('Invalid ARIA attribute `%s`. Did you mean `%s`?', name, correctName);
  3035. warnedProperties[name] = true;
  3036. return true;
  3037. }
  3038. }
  3039. if (rARIA.test(name)) {
  3040. var lowerCasedName = name.toLowerCase();
  3041. var standardName = ariaProperties.hasOwnProperty(lowerCasedName) ? lowerCasedName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  3042. // DOM properties, then it is an invalid aria-* attribute.
  3043. if (standardName == null) {
  3044. warnedProperties[name] = true;
  3045. return false;
  3046. } // aria-* attributes should be lowercase; suggest the lowercase version.
  3047. if (name !== standardName) {
  3048. error('Unknown ARIA attribute `%s`. Did you mean `%s`?', name, standardName);
  3049. warnedProperties[name] = true;
  3050. return true;
  3051. }
  3052. }
  3053. }
  3054. return true;
  3055. }
  3056. function warnInvalidARIAProps(type, props) {
  3057. {
  3058. var invalidProps = [];
  3059. for (var key in props) {
  3060. var isValid = validateProperty(type, key);
  3061. if (!isValid) {
  3062. invalidProps.push(key);
  3063. }
  3064. }
  3065. var unknownPropString = invalidProps.map(function (prop) {
  3066. return '`' + prop + '`';
  3067. }).join(', ');
  3068. if (invalidProps.length === 1) {
  3069. error('Invalid aria prop %s on <%s> tag. ' + 'For details, see https://reactjs.org/link/invalid-aria-props', unknownPropString, type);
  3070. } else if (invalidProps.length > 1) {
  3071. error('Invalid aria props %s on <%s> tag. ' + 'For details, see https://reactjs.org/link/invalid-aria-props', unknownPropString, type);
  3072. }
  3073. }
  3074. }
  3075. function validateProperties(type, props) {
  3076. if (isCustomComponent(type, props)) {
  3077. return;
  3078. }
  3079. warnInvalidARIAProps(type, props);
  3080. }
  3081. var didWarnValueNull = false;
  3082. function validateProperties$1(type, props) {
  3083. {
  3084. if (type !== 'input' && type !== 'textarea' && type !== 'select') {
  3085. return;
  3086. }
  3087. if (props != null && props.value === null && !didWarnValueNull) {
  3088. didWarnValueNull = true;
  3089. if (type === 'select' && props.multiple) {
  3090. error('`value` prop on `%s` should not be null. ' + 'Consider using an empty array when `multiple` is set to `true` ' + 'to clear the component or `undefined` for uncontrolled components.', type);
  3091. } else {
  3092. error('`value` prop on `%s` should not be null. ' + 'Consider using an empty string to clear the component or `undefined` ' + 'for uncontrolled components.', type);
  3093. }
  3094. }
  3095. }
  3096. }
  3097. var validateProperty$1 = function () {};
  3098. {
  3099. var warnedProperties$1 = {};
  3100. var EVENT_NAME_REGEX = /^on./;
  3101. var INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
  3102. var rARIA$1 = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  3103. var rARIACamel$1 = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  3104. validateProperty$1 = function (tagName, name, value, eventRegistry) {
  3105. if (hasOwnProperty.call(warnedProperties$1, name) && warnedProperties$1[name]) {
  3106. return true;
  3107. }
  3108. var lowerCasedName = name.toLowerCase();
  3109. if (lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout') {
  3110. error('React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' + 'All React events are normalized to bubble, so onFocusIn and onFocusOut ' + 'are not needed/supported by React.');
  3111. warnedProperties$1[name] = true;
  3112. return true;
  3113. } // We can't rely on the event system being injected on the server.
  3114. if (eventRegistry != null) {
  3115. var registrationNameDependencies = eventRegistry.registrationNameDependencies,
  3116. possibleRegistrationNames = eventRegistry.possibleRegistrationNames;
  3117. if (registrationNameDependencies.hasOwnProperty(name)) {
  3118. return true;
  3119. }
  3120. var registrationName = possibleRegistrationNames.hasOwnProperty(lowerCasedName) ? possibleRegistrationNames[lowerCasedName] : null;
  3121. if (registrationName != null) {
  3122. error('Invalid event handler property `%s`. Did you mean `%s`?', name, registrationName);
  3123. warnedProperties$1[name] = true;
  3124. return true;
  3125. }
  3126. if (EVENT_NAME_REGEX.test(name)) {
  3127. error('Unknown event handler property `%s`. It will be ignored.', name);
  3128. warnedProperties$1[name] = true;
  3129. return true;
  3130. }
  3131. } else if (EVENT_NAME_REGEX.test(name)) {
  3132. // If no event plugins have been injected, we are in a server environment.
  3133. // So we can't tell if the event name is correct for sure, but we can filter
  3134. // out known bad ones like `onclick`. We can't suggest a specific replacement though.
  3135. if (INVALID_EVENT_NAME_REGEX.test(name)) {
  3136. error('Invalid event handler property `%s`. ' + 'React events use the camelCase naming convention, for example `onClick`.', name);
  3137. }
  3138. warnedProperties$1[name] = true;
  3139. return true;
  3140. } // Let the ARIA attribute hook validate ARIA attributes
  3141. if (rARIA$1.test(name) || rARIACamel$1.test(name)) {
  3142. return true;
  3143. }
  3144. if (lowerCasedName === 'innerhtml') {
  3145. error('Directly setting property `innerHTML` is not permitted. ' + 'For more information, lookup documentation on `dangerouslySetInnerHTML`.');
  3146. warnedProperties$1[name] = true;
  3147. return true;
  3148. }
  3149. if (lowerCasedName === 'aria') {
  3150. error('The `aria` attribute is reserved for future use in React. ' + 'Pass individual `aria-` attributes instead.');
  3151. warnedProperties$1[name] = true;
  3152. return true;
  3153. }
  3154. if (lowerCasedName === 'is' && value !== null && value !== undefined && typeof value !== 'string') {
  3155. error('Received a `%s` for a string attribute `is`. If this is expected, cast ' + 'the value to a string.', typeof value);
  3156. warnedProperties$1[name] = true;
  3157. return true;
  3158. }
  3159. if (typeof value === 'number' && isNaN(value)) {
  3160. error('Received NaN for the `%s` attribute. If this is expected, cast ' + 'the value to a string.', name);
  3161. warnedProperties$1[name] = true;
  3162. return true;
  3163. }
  3164. var propertyInfo = getPropertyInfo(name);
  3165. var isReserved = propertyInfo !== null && propertyInfo.type === RESERVED; // Known attributes should match the casing specified in the property config.
  3166. if (possibleStandardNames.hasOwnProperty(lowerCasedName)) {
  3167. var standardName = possibleStandardNames[lowerCasedName];
  3168. if (standardName !== name) {
  3169. error('Invalid DOM property `%s`. Did you mean `%s`?', name, standardName);
  3170. warnedProperties$1[name] = true;
  3171. return true;
  3172. }
  3173. } else if (!isReserved && name !== lowerCasedName) {
  3174. // Unknown attributes should have lowercase casing since that's how they
  3175. // will be cased anyway with server rendering.
  3176. error('React does not recognize the `%s` prop on a DOM element. If you ' + 'intentionally want it to appear in the DOM as a custom ' + 'attribute, spell it as lowercase `%s` instead. ' + 'If you accidentally passed it from a parent component, remove ' + 'it from the DOM element.', name, lowerCasedName);
  3177. warnedProperties$1[name] = true;
  3178. return true;
  3179. }
  3180. if (typeof value === 'boolean' && shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  3181. if (value) {
  3182. error('Received `%s` for a non-boolean attribute `%s`.\n\n' + 'If you want to write it to the DOM, pass a string instead: ' + '%s="%s" or %s={value.toString()}.', value, name, name, value, name);
  3183. } else {
  3184. error('Received `%s` for a non-boolean attribute `%s`.\n\n' + 'If you want to write it to the DOM, pass a string instead: ' + '%s="%s" or %s={value.toString()}.\n\n' + 'If you used to conditionally omit it with %s={condition && value}, ' + 'pass %s={condition ? value : undefined} instead.', value, name, name, value, name, name, name);
  3185. }
  3186. warnedProperties$1[name] = true;
  3187. return true;
  3188. } // Now that we've validated casing, do not validate
  3189. // data types for reserved props
  3190. if (isReserved) {
  3191. return true;
  3192. } // Warn when a known attribute is a bad type
  3193. if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  3194. warnedProperties$1[name] = true;
  3195. return false;
  3196. } // Warn when passing the strings 'false' or 'true' into a boolean prop
  3197. if ((value === 'false' || value === 'true') && propertyInfo !== null && propertyInfo.type === BOOLEAN) {
  3198. error('Received the string `%s` for the boolean attribute `%s`. ' + '%s ' + 'Did you mean %s={%s}?', value, name, value === 'false' ? 'The browser will interpret it as a truthy value.' : 'Although this works, it will not work as expected if you pass the string "false".', name, value);
  3199. warnedProperties$1[name] = true;
  3200. return true;
  3201. }
  3202. return true;
  3203. };
  3204. }
  3205. var warnUnknownProperties = function (type, props, eventRegistry) {
  3206. {
  3207. var unknownProps = [];
  3208. for (var key in props) {
  3209. var isValid = validateProperty$1(type, key, props[key], eventRegistry);
  3210. if (!isValid) {
  3211. unknownProps.push(key);
  3212. }
  3213. }
  3214. var unknownPropString = unknownProps.map(function (prop) {
  3215. return '`' + prop + '`';
  3216. }).join(', ');
  3217. if (unknownProps.length === 1) {
  3218. error('Invalid value for prop %s on <%s> tag. Either remove it from the element, ' + 'or pass a string or number value to keep it in the DOM. ' + 'For details, see https://reactjs.org/link/attribute-behavior ', unknownPropString, type);
  3219. } else if (unknownProps.length > 1) {
  3220. error('Invalid values for props %s on <%s> tag. Either remove them from the element, ' + 'or pass a string or number value to keep them in the DOM. ' + 'For details, see https://reactjs.org/link/attribute-behavior ', unknownPropString, type);
  3221. }
  3222. }
  3223. };
  3224. function validateProperties$2(type, props, eventRegistry) {
  3225. if (isCustomComponent(type, props)) {
  3226. return;
  3227. }
  3228. warnUnknownProperties(type, props, eventRegistry);
  3229. }
  3230. var IS_EVENT_HANDLE_NON_MANAGED_NODE = 1;
  3231. var IS_NON_DELEGATED = 1 << 1;
  3232. var IS_CAPTURE_PHASE = 1 << 2;
  3233. // set to LEGACY_FB_SUPPORT. LEGACY_FB_SUPPORT only gets set when
  3234. // we call willDeferLaterForLegacyFBSupport, thus not bailing out
  3235. // will result in endless cycles like an infinite loop.
  3236. // We also don't want to defer during event replaying.
  3237. var SHOULD_NOT_PROCESS_POLYFILL_EVENT_PLUGINS = IS_EVENT_HANDLE_NON_MANAGED_NODE | IS_NON_DELEGATED | IS_CAPTURE_PHASE;
  3238. // This exists to avoid circular dependency between ReactDOMEventReplaying
  3239. // and DOMPluginEventSystem.
  3240. var currentReplayingEvent = null;
  3241. function setReplayingEvent(event) {
  3242. {
  3243. if (currentReplayingEvent !== null) {
  3244. error('Expected currently replaying event to be null. This error ' + 'is likely caused by a bug in React. Please file an issue.');
  3245. }
  3246. }
  3247. currentReplayingEvent = event;
  3248. }
  3249. function resetReplayingEvent() {
  3250. {
  3251. if (currentReplayingEvent === null) {
  3252. error('Expected currently replaying event to not be null. This error ' + 'is likely caused by a bug in React. Please file an issue.');
  3253. }
  3254. }
  3255. currentReplayingEvent = null;
  3256. }
  3257. function isReplayingEvent(event) {
  3258. return event === currentReplayingEvent;
  3259. }
  3260. /**
  3261. * Gets the target node from a native browser event by accounting for
  3262. * inconsistencies in browser DOM APIs.
  3263. *
  3264. * @param {object} nativeEvent Native browser event.
  3265. * @return {DOMEventTarget} Target node.
  3266. */
  3267. function getEventTarget(nativeEvent) {
  3268. // Fallback to nativeEvent.srcElement for IE9
  3269. // https://github.com/facebook/react/issues/12506
  3270. var target = nativeEvent.target || nativeEvent.srcElement || window; // Normalize SVG <use> element events #4963
  3271. if (target.correspondingUseElement) {
  3272. target = target.correspondingUseElement;
  3273. } // Safari may fire events on text nodes (Node.TEXT_NODE is 3).
  3274. // @see http://www.quirksmode.org/js/events_properties.html
  3275. return target.nodeType === TEXT_NODE ? target.parentNode : target;
  3276. }
  3277. var restoreImpl = null;
  3278. var restoreTarget = null;
  3279. var restoreQueue = null;
  3280. function restoreStateOfTarget(target) {
  3281. // We perform this translation at the end of the event loop so that we
  3282. // always receive the correct fiber here
  3283. var internalInstance = getInstanceFromNode(target);
  3284. if (!internalInstance) {
  3285. // Unmounted
  3286. return;
  3287. }
  3288. if (typeof restoreImpl !== 'function') {
  3289. throw new Error('setRestoreImplementation() needs to be called to handle a target for controlled ' + 'events. This error is likely caused by a bug in React. Please file an issue.');
  3290. }
  3291. var stateNode = internalInstance.stateNode; // Guard against Fiber being unmounted.
  3292. if (stateNode) {
  3293. var _props = getFiberCurrentPropsFromNode(stateNode);
  3294. restoreImpl(internalInstance.stateNode, internalInstance.type, _props);
  3295. }
  3296. }
  3297. function setRestoreImplementation(impl) {
  3298. restoreImpl = impl;
  3299. }
  3300. function enqueueStateRestore(target) {
  3301. if (restoreTarget) {
  3302. if (restoreQueue) {
  3303. restoreQueue.push(target);
  3304. } else {
  3305. restoreQueue = [target];
  3306. }
  3307. } else {
  3308. restoreTarget = target;
  3309. }
  3310. }
  3311. function needsStateRestore() {
  3312. return restoreTarget !== null || restoreQueue !== null;
  3313. }
  3314. function restoreStateIfNeeded() {
  3315. if (!restoreTarget) {
  3316. return;
  3317. }
  3318. var target = restoreTarget;
  3319. var queuedTargets = restoreQueue;
  3320. restoreTarget = null;
  3321. restoreQueue = null;
  3322. restoreStateOfTarget(target);
  3323. if (queuedTargets) {
  3324. for (var i = 0; i < queuedTargets.length; i++) {
  3325. restoreStateOfTarget(queuedTargets[i]);
  3326. }
  3327. }
  3328. }
  3329. // the renderer. Such as when we're dispatching events or if third party
  3330. // libraries need to call batchedUpdates. Eventually, this API will go away when
  3331. // everything is batched by default. We'll then have a similar API to opt-out of
  3332. // scheduled work and instead do synchronous work.
  3333. // Defaults
  3334. var batchedUpdatesImpl = function (fn, bookkeeping) {
  3335. return fn(bookkeeping);
  3336. };
  3337. var flushSyncImpl = function () {};
  3338. var isInsideEventHandler = false;
  3339. function finishEventHandler() {
  3340. // Here we wait until all updates have propagated, which is important
  3341. // when using controlled components within layers:
  3342. // https://github.com/facebook/react/issues/1698
  3343. // Then we restore state of any controlled component.
  3344. var controlledComponentsHavePendingUpdates = needsStateRestore();
  3345. if (controlledComponentsHavePendingUpdates) {
  3346. // If a controlled event was fired, we may need to restore the state of
  3347. // the DOM node back to the controlled value. This is necessary when React
  3348. // bails out of the update without touching the DOM.
  3349. // TODO: Restore state in the microtask, after the discrete updates flush,
  3350. // instead of early flushing them here.
  3351. flushSyncImpl();
  3352. restoreStateIfNeeded();
  3353. }
  3354. }
  3355. function batchedUpdates(fn, a, b) {
  3356. if (isInsideEventHandler) {
  3357. // If we are currently inside another batch, we need to wait until it
  3358. // fully completes before restoring state.
  3359. return fn(a, b);
  3360. }
  3361. isInsideEventHandler = true;
  3362. try {
  3363. return batchedUpdatesImpl(fn, a, b);
  3364. } finally {
  3365. isInsideEventHandler = false;
  3366. finishEventHandler();
  3367. }
  3368. } // TODO: Replace with flushSync
  3369. function setBatchingImplementation(_batchedUpdatesImpl, _discreteUpdatesImpl, _flushSyncImpl) {
  3370. batchedUpdatesImpl = _batchedUpdatesImpl;
  3371. flushSyncImpl = _flushSyncImpl;
  3372. }
  3373. function isInteractive(tag) {
  3374. return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
  3375. }
  3376. function shouldPreventMouseEvent(name, type, props) {
  3377. switch (name) {
  3378. case 'onClick':
  3379. case 'onClickCapture':
  3380. case 'onDoubleClick':
  3381. case 'onDoubleClickCapture':
  3382. case 'onMouseDown':
  3383. case 'onMouseDownCapture':
  3384. case 'onMouseMove':
  3385. case 'onMouseMoveCapture':
  3386. case 'onMouseUp':
  3387. case 'onMouseUpCapture':
  3388. case 'onMouseEnter':
  3389. return !!(props.disabled && isInteractive(type));
  3390. default:
  3391. return false;
  3392. }
  3393. }
  3394. /**
  3395. * @param {object} inst The instance, which is the source of events.
  3396. * @param {string} registrationName Name of listener (e.g. `onClick`).
  3397. * @return {?function} The stored callback.
  3398. */
  3399. function getListener(inst, registrationName) {
  3400. var stateNode = inst.stateNode;
  3401. if (stateNode === null) {
  3402. // Work in progress (ex: onload events in incremental mode).
  3403. return null;
  3404. }
  3405. var props = getFiberCurrentPropsFromNode(stateNode);
  3406. if (props === null) {
  3407. // Work in progress.
  3408. return null;
  3409. }
  3410. var listener = props[registrationName];
  3411. if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
  3412. return null;
  3413. }
  3414. if (listener && typeof listener !== 'function') {
  3415. throw new Error("Expected `" + registrationName + "` listener to be a function, instead got a value of `" + typeof listener + "` type.");
  3416. }
  3417. return listener;
  3418. }
  3419. var passiveBrowserEventsSupported = false; // Check if browser support events with passive listeners
  3420. // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  3421. if (canUseDOM) {
  3422. try {
  3423. var options = {}; // $FlowFixMe: Ignore Flow complaining about needing a value
  3424. Object.defineProperty(options, 'passive', {
  3425. get: function () {
  3426. passiveBrowserEventsSupported = true;
  3427. }
  3428. });
  3429. window.addEventListener('test', options, options);
  3430. window.removeEventListener('test', options, options);
  3431. } catch (e) {
  3432. passiveBrowserEventsSupported = false;
  3433. }
  3434. }
  3435. function invokeGuardedCallbackProd(name, func, context, a, b, c, d, e, f) {
  3436. var funcArgs = Array.prototype.slice.call(arguments, 3);
  3437. try {
  3438. func.apply(context, funcArgs);
  3439. } catch (error) {
  3440. this.onError(error);
  3441. }
  3442. }
  3443. var invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
  3444. {
  3445. // In DEV mode, we swap out invokeGuardedCallback for a special version
  3446. // that plays more nicely with the browser's DevTools. The idea is to preserve
  3447. // "Pause on exceptions" behavior. Because React wraps all user-provided
  3448. // functions in invokeGuardedCallback, and the production version of
  3449. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  3450. // like caught exceptions, and the DevTools won't pause unless the developer
  3451. // takes the extra step of enabling pause on caught exceptions. This is
  3452. // unintuitive, though, because even though React has caught the error, from
  3453. // the developer's perspective, the error is uncaught.
  3454. //
  3455. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  3456. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  3457. // DOM node, and call the user-provided callback from inside an event handler
  3458. // for that fake event. If the callback throws, the error is "captured" using
  3459. // a global event handler. But because the error happens in a different
  3460. // event loop context, it does not interrupt the normal program flow.
  3461. // Effectively, this gives us try-catch behavior without actually using
  3462. // try-catch. Neat!
  3463. // Check that the browser supports the APIs we need to implement our special
  3464. // DEV version of invokeGuardedCallback
  3465. if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
  3466. var fakeNode = document.createElement('react');
  3467. invokeGuardedCallbackImpl = function invokeGuardedCallbackDev(name, func, context, a, b, c, d, e, f) {
  3468. // If document doesn't exist we know for sure we will crash in this method
  3469. // when we call document.createEvent(). However this can cause confusing
  3470. // errors: https://github.com/facebook/create-react-app/issues/3482
  3471. // So we preemptively throw with a better message instead.
  3472. if (typeof document === 'undefined' || document === null) {
  3473. throw new 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.');
  3474. }
  3475. var evt = document.createEvent('Event');
  3476. var didCall = false; // Keeps track of whether the user-provided callback threw an error. We
  3477. // set this to true at the beginning, then set it to false right after
  3478. // calling the function. If the function errors, `didError` will never be
  3479. // set to false. This strategy works even if the browser is flaky and
  3480. // fails to call our global error handler, because it doesn't rely on
  3481. // the error event at all.
  3482. var didError = true; // Keeps track of the value of window.event so that we can reset it
  3483. // during the callback to let user code access window.event in the
  3484. // browsers that support it.
  3485. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  3486. // dispatching: https://github.com/facebook/react/issues/13688
  3487. var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
  3488. function restoreAfterDispatch() {
  3489. // We immediately remove the callback from event listeners so that
  3490. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  3491. // nested call would trigger the fake event handlers of any call higher
  3492. // in the stack.
  3493. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  3494. // window.event assignment in both IE <= 10 as they throw an error
  3495. // "Member not found" in strict mode, and in Firefox which does not
  3496. // support window.event.
  3497. if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
  3498. window.event = windowEvent;
  3499. }
  3500. } // Create an event handler for our fake event. We will synchronously
  3501. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  3502. // call the user-provided callback.
  3503. var funcArgs = Array.prototype.slice.call(arguments, 3);
  3504. function callCallback() {
  3505. didCall = true;
  3506. restoreAfterDispatch();
  3507. func.apply(context, funcArgs);
  3508. didError = false;
  3509. } // Create a global error event handler. We use this to capture the value
  3510. // that was thrown. It's possible that this error handler will fire more
  3511. // than once; for example, if non-React code also calls `dispatchEvent`
  3512. // and a handler for that event throws. We should be resilient to most of
  3513. // those cases. Even if our error event handler fires more than once, the
  3514. // last error event is always used. If the callback actually does error,
  3515. // we know that the last error event is the correct one, because it's not
  3516. // possible for anything else to have happened in between our callback
  3517. // erroring and the code that follows the `dispatchEvent` call below. If
  3518. // the callback doesn't error, but the error event was fired, we know to
  3519. // ignore it because `didError` will be false, as described above.
  3520. var error; // Use this to track whether the error event is ever called.
  3521. var didSetError = false;
  3522. var isCrossOriginError = false;
  3523. function handleWindowError(event) {
  3524. error = event.error;
  3525. didSetError = true;
  3526. if (error === null && event.colno === 0 && event.lineno === 0) {
  3527. isCrossOriginError = true;
  3528. }
  3529. if (event.defaultPrevented) {
  3530. // Some other error handler has prevented default.
  3531. // Browsers silence the error report if this happens.
  3532. // We'll remember this to later decide whether to log it or not.
  3533. if (error != null && typeof error === 'object') {
  3534. try {
  3535. error._suppressLogging = true;
  3536. } catch (inner) {// Ignore.
  3537. }
  3538. }
  3539. }
  3540. } // Create a fake event type.
  3541. var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
  3542. window.addEventListener('error', handleWindowError);
  3543. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  3544. // errors, it will trigger our global error handler.
  3545. evt.initEvent(evtType, false, false);
  3546. fakeNode.dispatchEvent(evt);
  3547. if (windowEventDescriptor) {
  3548. Object.defineProperty(window, 'event', windowEventDescriptor);
  3549. }
  3550. if (didCall && didError) {
  3551. if (!didSetError) {
  3552. // The callback errored, but the error event never fired.
  3553. // eslint-disable-next-line react-internal/prod-error-codes
  3554. 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.');
  3555. } else if (isCrossOriginError) {
  3556. // eslint-disable-next-line react-internal/prod-error-codes
  3557. error = new Error("A cross-origin error was thrown. React doesn't have access to " + 'the actual error object in development. ' + 'See https://reactjs.org/link/crossorigin-error for more information.');
  3558. }
  3559. this.onError(error);
  3560. } // Remove our event listeners
  3561. window.removeEventListener('error', handleWindowError);
  3562. if (!didCall) {
  3563. // Something went really wrong, and our event was not dispatched.
  3564. // https://github.com/facebook/react/issues/16734
  3565. // https://github.com/facebook/react/issues/16585
  3566. // Fall back to the production implementation.
  3567. restoreAfterDispatch();
  3568. return invokeGuardedCallbackProd.apply(this, arguments);
  3569. }
  3570. };
  3571. }
  3572. }
  3573. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  3574. var hasError = false;
  3575. var caughtError = null; // Used by event system to capture/rethrow the first error.
  3576. var hasRethrowError = false;
  3577. var rethrowError = null;
  3578. var reporter = {
  3579. onError: function (error) {
  3580. hasError = true;
  3581. caughtError = error;
  3582. }
  3583. };
  3584. /**
  3585. * Call a function while guarding against errors that happens within it.
  3586. * Returns an error if it throws, otherwise null.
  3587. *
  3588. * In production, this is implemented using a try-catch. The reason we don't
  3589. * use a try-catch directly is so that we can swap out a different
  3590. * implementation in DEV mode.
  3591. *
  3592. * @param {String} name of the guard to use for logging or debugging
  3593. * @param {Function} func The function to invoke
  3594. * @param {*} context The context to use when calling the function
  3595. * @param {...*} args Arguments for function
  3596. */
  3597. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  3598. hasError = false;
  3599. caughtError = null;
  3600. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  3601. }
  3602. /**
  3603. * Same as invokeGuardedCallback, but instead of returning an error, it stores
  3604. * it in a global so it can be rethrown by `rethrowCaughtError` later.
  3605. * TODO: See if caughtError and rethrowError can be unified.
  3606. *
  3607. * @param {String} name of the guard to use for logging or debugging
  3608. * @param {Function} func The function to invoke
  3609. * @param {*} context The context to use when calling the function
  3610. * @param {...*} args Arguments for function
  3611. */
  3612. function invokeGuardedCallbackAndCatchFirstError(name, func, context, a, b, c, d, e, f) {
  3613. invokeGuardedCallback.apply(this, arguments);
  3614. if (hasError) {
  3615. var error = clearCaughtError();
  3616. if (!hasRethrowError) {
  3617. hasRethrowError = true;
  3618. rethrowError = error;
  3619. }
  3620. }
  3621. }
  3622. /**
  3623. * During execution of guarded functions we will capture the first error which
  3624. * we will rethrow to be handled by the top level error handler.
  3625. */
  3626. function rethrowCaughtError() {
  3627. if (hasRethrowError) {
  3628. var error = rethrowError;
  3629. hasRethrowError = false;
  3630. rethrowError = null;
  3631. throw error;
  3632. }
  3633. }
  3634. function hasCaughtError() {
  3635. return hasError;
  3636. }
  3637. function clearCaughtError() {
  3638. if (hasError) {
  3639. var error = caughtError;
  3640. hasError = false;
  3641. caughtError = null;
  3642. return error;
  3643. } else {
  3644. throw new Error('clearCaughtError was called but no error was captured. This error ' + 'is likely caused by a bug in React. Please file an issue.');
  3645. }
  3646. }
  3647. /**
  3648. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  3649. * instance (key) and the internal representation (value). This allows public
  3650. * methods to accept the user facing instance as an argument and map them back
  3651. * to internal methods.
  3652. *
  3653. * Note that this module is currently shared and assumed to be stateless.
  3654. * If this becomes an actual Map, that will break.
  3655. */
  3656. function get(key) {
  3657. return key._reactInternals;
  3658. }
  3659. function has(key) {
  3660. return key._reactInternals !== undefined;
  3661. }
  3662. function set(key, value) {
  3663. key._reactInternals = value;
  3664. }
  3665. // Don't change these two values. They're used by React Dev Tools.
  3666. var NoFlags =
  3667. /* */
  3668. 0;
  3669. var PerformedWork =
  3670. /* */
  3671. 1; // You can change the rest (and add more).
  3672. var Placement =
  3673. /* */
  3674. 2;
  3675. var Update =
  3676. /* */
  3677. 4;
  3678. var ChildDeletion =
  3679. /* */
  3680. 16;
  3681. var ContentReset =
  3682. /* */
  3683. 32;
  3684. var Callback =
  3685. /* */
  3686. 64;
  3687. var DidCapture =
  3688. /* */
  3689. 128;
  3690. var ForceClientRender =
  3691. /* */
  3692. 256;
  3693. var Ref =
  3694. /* */
  3695. 512;
  3696. var Snapshot =
  3697. /* */
  3698. 1024;
  3699. var Passive =
  3700. /* */
  3701. 2048;
  3702. var Hydrating =
  3703. /* */
  3704. 4096;
  3705. var Visibility =
  3706. /* */
  3707. 8192;
  3708. var StoreConsistency =
  3709. /* */
  3710. 16384;
  3711. var LifecycleEffectMask = Passive | Update | Callback | Ref | Snapshot | StoreConsistency; // Union of all commit flags (flags with the lifetime of a particular commit)
  3712. var HostEffectMask =
  3713. /* */
  3714. 32767; // These are not really side effects, but we still reuse this field.
  3715. var Incomplete =
  3716. /* */
  3717. 32768;
  3718. var ShouldCapture =
  3719. /* */
  3720. 65536;
  3721. var ForceUpdateForLegacySuspense =
  3722. /* */
  3723. 131072;
  3724. var Forked =
  3725. /* */
  3726. 1048576; // Static tags describe aspects of a fiber that are not specific to a render,
  3727. // e.g. a fiber uses a passive effect (even if there are no updates on this particular render).
  3728. // This enables us to defer more work in the unmount case,
  3729. // since we can defer traversing the tree during layout to look for Passive effects,
  3730. // and instead rely on the static flag as a signal that there may be cleanup work.
  3731. var RefStatic =
  3732. /* */
  3733. 2097152;
  3734. var LayoutStatic =
  3735. /* */
  3736. 4194304;
  3737. var PassiveStatic =
  3738. /* */
  3739. 8388608; // These flags allow us to traverse to fibers that have effects on mount
  3740. // without traversing the entire tree after every commit for
  3741. // double invoking
  3742. var MountLayoutDev =
  3743. /* */
  3744. 16777216;
  3745. var MountPassiveDev =
  3746. /* */
  3747. 33554432; // Groups of flags that are used in the commit phase to skip over trees that
  3748. // don't contain effects, by checking subtreeFlags.
  3749. var BeforeMutationMask = // TODO: Remove Update flag from before mutation phase by re-landing Visibility
  3750. // flag logic (see #20043)
  3751. Update | Snapshot | ( 0);
  3752. var MutationMask = Placement | Update | ChildDeletion | ContentReset | Ref | Hydrating | Visibility;
  3753. var LayoutMask = Update | Callback | Ref | Visibility; // TODO: Split into PassiveMountMask and PassiveUnmountMask
  3754. var PassiveMask = Passive | ChildDeletion; // Union of tags that don't get reset on clones.
  3755. // This allows certain concepts to persist without recalculating them,
  3756. // e.g. whether a subtree contains passive effects or portals.
  3757. var StaticMask = LayoutStatic | PassiveStatic | RefStatic;
  3758. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  3759. function getNearestMountedFiber(fiber) {
  3760. var node = fiber;
  3761. var nearestMounted = fiber;
  3762. if (!fiber.alternate) {
  3763. // If there is no alternate, this might be a new tree that isn't inserted
  3764. // yet. If it is, then it will have a pending insertion effect on it.
  3765. var nextNode = node;
  3766. do {
  3767. node = nextNode;
  3768. if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
  3769. // This is an insertion or in-progress hydration. The nearest possible
  3770. // mounted fiber is the parent but we need to continue to figure out
  3771. // if that one is still mounted.
  3772. nearestMounted = node.return;
  3773. }
  3774. nextNode = node.return;
  3775. } while (nextNode);
  3776. } else {
  3777. while (node.return) {
  3778. node = node.return;
  3779. }
  3780. }
  3781. if (node.tag === HostRoot) {
  3782. // TODO: Check if this was a nested HostRoot when used with
  3783. // renderContainerIntoSubtree.
  3784. return nearestMounted;
  3785. } // If we didn't hit the root, that means that we're in an disconnected tree
  3786. // that has been unmounted.
  3787. return null;
  3788. }
  3789. function getSuspenseInstanceFromFiber(fiber) {
  3790. if (fiber.tag === SuspenseComponent) {
  3791. var suspenseState = fiber.memoizedState;
  3792. if (suspenseState === null) {
  3793. var current = fiber.alternate;
  3794. if (current !== null) {
  3795. suspenseState = current.memoizedState;
  3796. }
  3797. }
  3798. if (suspenseState !== null) {
  3799. return suspenseState.dehydrated;
  3800. }
  3801. }
  3802. return null;
  3803. }
  3804. function getContainerFromFiber(fiber) {
  3805. return fiber.tag === HostRoot ? fiber.stateNode.containerInfo : null;
  3806. }
  3807. function isFiberMounted(fiber) {
  3808. return getNearestMountedFiber(fiber) === fiber;
  3809. }
  3810. function isMounted(component) {
  3811. {
  3812. var owner = ReactCurrentOwner.current;
  3813. if (owner !== null && owner.tag === ClassComponent) {
  3814. var ownerFiber = owner;
  3815. var instance = ownerFiber.stateNode;
  3816. if (!instance._warnedAboutRefsInRender) {
  3817. 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.', getComponentNameFromFiber(ownerFiber) || 'A component');
  3818. }
  3819. instance._warnedAboutRefsInRender = true;
  3820. }
  3821. }
  3822. var fiber = get(component);
  3823. if (!fiber) {
  3824. return false;
  3825. }
  3826. return getNearestMountedFiber(fiber) === fiber;
  3827. }
  3828. function assertIsMounted(fiber) {
  3829. if (getNearestMountedFiber(fiber) !== fiber) {
  3830. throw new Error('Unable to find node on an unmounted component.');
  3831. }
  3832. }
  3833. function findCurrentFiberUsingSlowPath(fiber) {
  3834. var alternate = fiber.alternate;
  3835. if (!alternate) {
  3836. // If there is no alternate, then we only need to check if it is mounted.
  3837. var nearestMounted = getNearestMountedFiber(fiber);
  3838. if (nearestMounted === null) {
  3839. throw new Error('Unable to find node on an unmounted component.');
  3840. }
  3841. if (nearestMounted !== fiber) {
  3842. return null;
  3843. }
  3844. return fiber;
  3845. } // If we have two possible branches, we'll walk backwards up to the root
  3846. // to see what path the root points to. On the way we may hit one of the
  3847. // special cases and we'll deal with them.
  3848. var a = fiber;
  3849. var b = alternate;
  3850. while (true) {
  3851. var parentA = a.return;
  3852. if (parentA === null) {
  3853. // We're at the root.
  3854. break;
  3855. }
  3856. var parentB = parentA.alternate;
  3857. if (parentB === null) {
  3858. // There is no alternate. This is an unusual case. Currently, it only
  3859. // happens when a Suspense component is hidden. An extra fragment fiber
  3860. // is inserted in between the Suspense fiber and its children. Skip
  3861. // over this extra fragment fiber and proceed to the next parent.
  3862. var nextParent = parentA.return;
  3863. if (nextParent !== null) {
  3864. a = b = nextParent;
  3865. continue;
  3866. } // If there's no parent, we're at the root.
  3867. break;
  3868. } // If both copies of the parent fiber point to the same child, we can
  3869. // assume that the child is current. This happens when we bailout on low
  3870. // priority: the bailed out fiber's child reuses the current child.
  3871. if (parentA.child === parentB.child) {
  3872. var child = parentA.child;
  3873. while (child) {
  3874. if (child === a) {
  3875. // We've determined that A is the current branch.
  3876. assertIsMounted(parentA);
  3877. return fiber;
  3878. }
  3879. if (child === b) {
  3880. // We've determined that B is the current branch.
  3881. assertIsMounted(parentA);
  3882. return alternate;
  3883. }
  3884. child = child.sibling;
  3885. } // We should never have an alternate for any mounting node. So the only
  3886. // way this could possibly happen is if this was unmounted, if at all.
  3887. throw new Error('Unable to find node on an unmounted component.');
  3888. }
  3889. if (a.return !== b.return) {
  3890. // The return pointer of A and the return pointer of B point to different
  3891. // fibers. We assume that return pointers never criss-cross, so A must
  3892. // belong to the child set of A.return, and B must belong to the child
  3893. // set of B.return.
  3894. a = parentA;
  3895. b = parentB;
  3896. } else {
  3897. // The return pointers point to the same fiber. We'll have to use the
  3898. // default, slow path: scan the child sets of each parent alternate to see
  3899. // which child belongs to which set.
  3900. //
  3901. // Search parent A's child set
  3902. var didFindChild = false;
  3903. var _child = parentA.child;
  3904. while (_child) {
  3905. if (_child === a) {
  3906. didFindChild = true;
  3907. a = parentA;
  3908. b = parentB;
  3909. break;
  3910. }
  3911. if (_child === b) {
  3912. didFindChild = true;
  3913. b = parentA;
  3914. a = parentB;
  3915. break;
  3916. }
  3917. _child = _child.sibling;
  3918. }
  3919. if (!didFindChild) {
  3920. // Search parent B's child set
  3921. _child = parentB.child;
  3922. while (_child) {
  3923. if (_child === a) {
  3924. didFindChild = true;
  3925. a = parentB;
  3926. b = parentA;
  3927. break;
  3928. }
  3929. if (_child === b) {
  3930. didFindChild = true;
  3931. b = parentB;
  3932. a = parentA;
  3933. break;
  3934. }
  3935. _child = _child.sibling;
  3936. }
  3937. if (!didFindChild) {
  3938. throw new Error('Child was not found in either parent set. This indicates a bug ' + 'in React related to the return pointer. Please file an issue.');
  3939. }
  3940. }
  3941. }
  3942. if (a.alternate !== b) {
  3943. throw new Error("Return fibers should always be each others' alternates. " + 'This error is likely caused by a bug in React. Please file an issue.');
  3944. }
  3945. } // If the root is not a host container, we're in a disconnected tree. I.e.
  3946. // unmounted.
  3947. if (a.tag !== HostRoot) {
  3948. throw new Error('Unable to find node on an unmounted component.');
  3949. }
  3950. if (a.stateNode.current === a) {
  3951. // We've determined that A is the current branch.
  3952. return fiber;
  3953. } // Otherwise B has to be current branch.
  3954. return alternate;
  3955. }
  3956. function findCurrentHostFiber(parent) {
  3957. var currentParent = findCurrentFiberUsingSlowPath(parent);
  3958. return currentParent !== null ? findCurrentHostFiberImpl(currentParent) : null;
  3959. }
  3960. function findCurrentHostFiberImpl(node) {
  3961. // Next we'll drill down this component to find the first HostComponent/Text.
  3962. if (node.tag === HostComponent || node.tag === HostText) {
  3963. return node;
  3964. }
  3965. var child = node.child;
  3966. while (child !== null) {
  3967. var match = findCurrentHostFiberImpl(child);
  3968. if (match !== null) {
  3969. return match;
  3970. }
  3971. child = child.sibling;
  3972. }
  3973. return null;
  3974. }
  3975. function findCurrentHostFiberWithNoPortals(parent) {
  3976. var currentParent = findCurrentFiberUsingSlowPath(parent);
  3977. return currentParent !== null ? findCurrentHostFiberWithNoPortalsImpl(currentParent) : null;
  3978. }
  3979. function findCurrentHostFiberWithNoPortalsImpl(node) {
  3980. // Next we'll drill down this component to find the first HostComponent/Text.
  3981. if (node.tag === HostComponent || node.tag === HostText) {
  3982. return node;
  3983. }
  3984. var child = node.child;
  3985. while (child !== null) {
  3986. if (child.tag !== HostPortal) {
  3987. var match = findCurrentHostFiberWithNoPortalsImpl(child);
  3988. if (match !== null) {
  3989. return match;
  3990. }
  3991. }
  3992. child = child.sibling;
  3993. }
  3994. return null;
  3995. }
  3996. // This module only exists as an ESM wrapper around the external CommonJS
  3997. var scheduleCallback = Scheduler.unstable_scheduleCallback;
  3998. var cancelCallback = Scheduler.unstable_cancelCallback;
  3999. var shouldYield = Scheduler.unstable_shouldYield;
  4000. var requestPaint = Scheduler.unstable_requestPaint;
  4001. var now = Scheduler.unstable_now;
  4002. var getCurrentPriorityLevel = Scheduler.unstable_getCurrentPriorityLevel;
  4003. var ImmediatePriority = Scheduler.unstable_ImmediatePriority;
  4004. var UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
  4005. var NormalPriority = Scheduler.unstable_NormalPriority;
  4006. var LowPriority = Scheduler.unstable_LowPriority;
  4007. var IdlePriority = Scheduler.unstable_IdlePriority;
  4008. // this doesn't actually exist on the scheduler, but it *does*
  4009. // on scheduler/unstable_mock, which we'll need for internal testing
  4010. var unstable_yieldValue = Scheduler.unstable_yieldValue;
  4011. var unstable_setDisableYieldValue = Scheduler.unstable_setDisableYieldValue;
  4012. var rendererID = null;
  4013. var injectedHook = null;
  4014. var injectedProfilingHooks = null;
  4015. var hasLoggedError = false;
  4016. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
  4017. function injectInternals(internals) {
  4018. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
  4019. // No DevTools
  4020. return false;
  4021. }
  4022. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  4023. if (hook.isDisabled) {
  4024. // This isn't a real property on the hook, but it can be set to opt out
  4025. // of DevTools integration and associated warnings and logs.
  4026. // https://github.com/facebook/react/issues/3877
  4027. return true;
  4028. }
  4029. if (!hook.supportsFiber) {
  4030. {
  4031. 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://reactjs.org/link/react-devtools');
  4032. } // DevTools exists, even though it doesn't support Fiber.
  4033. return true;
  4034. }
  4035. try {
  4036. if (enableSchedulingProfiler) {
  4037. // Conditionally inject these hooks only if Timeline profiler is supported by this build.
  4038. // This gives DevTools a way to feature detect that isn't tied to version number
  4039. // (since profiling and timeline are controlled by different feature flags).
  4040. internals = assign({}, internals, {
  4041. getLaneLabelMap: getLaneLabelMap,
  4042. injectProfilingHooks: injectProfilingHooks
  4043. });
  4044. }
  4045. rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  4046. injectedHook = hook;
  4047. } catch (err) {
  4048. // Catch all errors because it is unsafe to throw during initialization.
  4049. {
  4050. error('React instrumentation encountered an error: %s.', err);
  4051. }
  4052. }
  4053. if (hook.checkDCE) {
  4054. // This is the real DevTools.
  4055. return true;
  4056. } else {
  4057. // This is likely a hook installed by Fast Refresh runtime.
  4058. return false;
  4059. }
  4060. }
  4061. function onScheduleRoot(root, children) {
  4062. {
  4063. if (injectedHook && typeof injectedHook.onScheduleFiberRoot === 'function') {
  4064. try {
  4065. injectedHook.onScheduleFiberRoot(rendererID, root, children);
  4066. } catch (err) {
  4067. if ( !hasLoggedError) {
  4068. hasLoggedError = true;
  4069. error('React instrumentation encountered an error: %s', err);
  4070. }
  4071. }
  4072. }
  4073. }
  4074. }
  4075. function onCommitRoot(root, eventPriority) {
  4076. if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
  4077. try {
  4078. var didError = (root.current.flags & DidCapture) === DidCapture;
  4079. if (enableProfilerTimer) {
  4080. var schedulerPriority;
  4081. switch (eventPriority) {
  4082. case DiscreteEventPriority:
  4083. schedulerPriority = ImmediatePriority;
  4084. break;
  4085. case ContinuousEventPriority:
  4086. schedulerPriority = UserBlockingPriority;
  4087. break;
  4088. case DefaultEventPriority:
  4089. schedulerPriority = NormalPriority;
  4090. break;
  4091. case IdleEventPriority:
  4092. schedulerPriority = IdlePriority;
  4093. break;
  4094. default:
  4095. schedulerPriority = NormalPriority;
  4096. break;
  4097. }
  4098. injectedHook.onCommitFiberRoot(rendererID, root, schedulerPriority, didError);
  4099. } else {
  4100. injectedHook.onCommitFiberRoot(rendererID, root, undefined, didError);
  4101. }
  4102. } catch (err) {
  4103. {
  4104. if (!hasLoggedError) {
  4105. hasLoggedError = true;
  4106. error('React instrumentation encountered an error: %s', err);
  4107. }
  4108. }
  4109. }
  4110. }
  4111. }
  4112. function onPostCommitRoot(root) {
  4113. if (injectedHook && typeof injectedHook.onPostCommitFiberRoot === 'function') {
  4114. try {
  4115. injectedHook.onPostCommitFiberRoot(rendererID, root);
  4116. } catch (err) {
  4117. {
  4118. if (!hasLoggedError) {
  4119. hasLoggedError = true;
  4120. error('React instrumentation encountered an error: %s', err);
  4121. }
  4122. }
  4123. }
  4124. }
  4125. }
  4126. function onCommitUnmount(fiber) {
  4127. if (injectedHook && typeof injectedHook.onCommitFiberUnmount === 'function') {
  4128. try {
  4129. injectedHook.onCommitFiberUnmount(rendererID, fiber);
  4130. } catch (err) {
  4131. {
  4132. if (!hasLoggedError) {
  4133. hasLoggedError = true;
  4134. error('React instrumentation encountered an error: %s', err);
  4135. }
  4136. }
  4137. }
  4138. }
  4139. }
  4140. function setIsStrictModeForDevtools(newIsStrictMode) {
  4141. {
  4142. if (typeof unstable_yieldValue === 'function') {
  4143. // We're in a test because Scheduler.unstable_yieldValue only exists
  4144. // in SchedulerMock. To reduce the noise in strict mode tests,
  4145. // suppress warnings and disable scheduler yielding during the double render
  4146. unstable_setDisableYieldValue(newIsStrictMode);
  4147. setSuppressWarning(newIsStrictMode);
  4148. }
  4149. if (injectedHook && typeof injectedHook.setStrictMode === 'function') {
  4150. try {
  4151. injectedHook.setStrictMode(rendererID, newIsStrictMode);
  4152. } catch (err) {
  4153. {
  4154. if (!hasLoggedError) {
  4155. hasLoggedError = true;
  4156. error('React instrumentation encountered an error: %s', err);
  4157. }
  4158. }
  4159. }
  4160. }
  4161. }
  4162. } // Profiler API hooks
  4163. function injectProfilingHooks(profilingHooks) {
  4164. injectedProfilingHooks = profilingHooks;
  4165. }
  4166. function getLaneLabelMap() {
  4167. {
  4168. var map = new Map();
  4169. var lane = 1;
  4170. for (var index = 0; index < TotalLanes; index++) {
  4171. var label = getLabelForLane(lane);
  4172. map.set(lane, label);
  4173. lane *= 2;
  4174. }
  4175. return map;
  4176. }
  4177. }
  4178. function markCommitStarted(lanes) {
  4179. {
  4180. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markCommitStarted === 'function') {
  4181. injectedProfilingHooks.markCommitStarted(lanes);
  4182. }
  4183. }
  4184. }
  4185. function markCommitStopped() {
  4186. {
  4187. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markCommitStopped === 'function') {
  4188. injectedProfilingHooks.markCommitStopped();
  4189. }
  4190. }
  4191. }
  4192. function markComponentRenderStarted(fiber) {
  4193. {
  4194. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentRenderStarted === 'function') {
  4195. injectedProfilingHooks.markComponentRenderStarted(fiber);
  4196. }
  4197. }
  4198. }
  4199. function markComponentRenderStopped() {
  4200. {
  4201. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentRenderStopped === 'function') {
  4202. injectedProfilingHooks.markComponentRenderStopped();
  4203. }
  4204. }
  4205. }
  4206. function markComponentPassiveEffectMountStarted(fiber) {
  4207. {
  4208. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentPassiveEffectMountStarted === 'function') {
  4209. injectedProfilingHooks.markComponentPassiveEffectMountStarted(fiber);
  4210. }
  4211. }
  4212. }
  4213. function markComponentPassiveEffectMountStopped() {
  4214. {
  4215. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentPassiveEffectMountStopped === 'function') {
  4216. injectedProfilingHooks.markComponentPassiveEffectMountStopped();
  4217. }
  4218. }
  4219. }
  4220. function markComponentPassiveEffectUnmountStarted(fiber) {
  4221. {
  4222. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentPassiveEffectUnmountStarted === 'function') {
  4223. injectedProfilingHooks.markComponentPassiveEffectUnmountStarted(fiber);
  4224. }
  4225. }
  4226. }
  4227. function markComponentPassiveEffectUnmountStopped() {
  4228. {
  4229. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentPassiveEffectUnmountStopped === 'function') {
  4230. injectedProfilingHooks.markComponentPassiveEffectUnmountStopped();
  4231. }
  4232. }
  4233. }
  4234. function markComponentLayoutEffectMountStarted(fiber) {
  4235. {
  4236. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentLayoutEffectMountStarted === 'function') {
  4237. injectedProfilingHooks.markComponentLayoutEffectMountStarted(fiber);
  4238. }
  4239. }
  4240. }
  4241. function markComponentLayoutEffectMountStopped() {
  4242. {
  4243. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentLayoutEffectMountStopped === 'function') {
  4244. injectedProfilingHooks.markComponentLayoutEffectMountStopped();
  4245. }
  4246. }
  4247. }
  4248. function markComponentLayoutEffectUnmountStarted(fiber) {
  4249. {
  4250. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentLayoutEffectUnmountStarted === 'function') {
  4251. injectedProfilingHooks.markComponentLayoutEffectUnmountStarted(fiber);
  4252. }
  4253. }
  4254. }
  4255. function markComponentLayoutEffectUnmountStopped() {
  4256. {
  4257. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentLayoutEffectUnmountStopped === 'function') {
  4258. injectedProfilingHooks.markComponentLayoutEffectUnmountStopped();
  4259. }
  4260. }
  4261. }
  4262. function markComponentErrored(fiber, thrownValue, lanes) {
  4263. {
  4264. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentErrored === 'function') {
  4265. injectedProfilingHooks.markComponentErrored(fiber, thrownValue, lanes);
  4266. }
  4267. }
  4268. }
  4269. function markComponentSuspended(fiber, wakeable, lanes) {
  4270. {
  4271. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markComponentSuspended === 'function') {
  4272. injectedProfilingHooks.markComponentSuspended(fiber, wakeable, lanes);
  4273. }
  4274. }
  4275. }
  4276. function markLayoutEffectsStarted(lanes) {
  4277. {
  4278. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markLayoutEffectsStarted === 'function') {
  4279. injectedProfilingHooks.markLayoutEffectsStarted(lanes);
  4280. }
  4281. }
  4282. }
  4283. function markLayoutEffectsStopped() {
  4284. {
  4285. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markLayoutEffectsStopped === 'function') {
  4286. injectedProfilingHooks.markLayoutEffectsStopped();
  4287. }
  4288. }
  4289. }
  4290. function markPassiveEffectsStarted(lanes) {
  4291. {
  4292. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markPassiveEffectsStarted === 'function') {
  4293. injectedProfilingHooks.markPassiveEffectsStarted(lanes);
  4294. }
  4295. }
  4296. }
  4297. function markPassiveEffectsStopped() {
  4298. {
  4299. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markPassiveEffectsStopped === 'function') {
  4300. injectedProfilingHooks.markPassiveEffectsStopped();
  4301. }
  4302. }
  4303. }
  4304. function markRenderStarted(lanes) {
  4305. {
  4306. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markRenderStarted === 'function') {
  4307. injectedProfilingHooks.markRenderStarted(lanes);
  4308. }
  4309. }
  4310. }
  4311. function markRenderYielded() {
  4312. {
  4313. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markRenderYielded === 'function') {
  4314. injectedProfilingHooks.markRenderYielded();
  4315. }
  4316. }
  4317. }
  4318. function markRenderStopped() {
  4319. {
  4320. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markRenderStopped === 'function') {
  4321. injectedProfilingHooks.markRenderStopped();
  4322. }
  4323. }
  4324. }
  4325. function markRenderScheduled(lane) {
  4326. {
  4327. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markRenderScheduled === 'function') {
  4328. injectedProfilingHooks.markRenderScheduled(lane);
  4329. }
  4330. }
  4331. }
  4332. function markForceUpdateScheduled(fiber, lane) {
  4333. {
  4334. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markForceUpdateScheduled === 'function') {
  4335. injectedProfilingHooks.markForceUpdateScheduled(fiber, lane);
  4336. }
  4337. }
  4338. }
  4339. function markStateUpdateScheduled(fiber, lane) {
  4340. {
  4341. if (injectedProfilingHooks !== null && typeof injectedProfilingHooks.markStateUpdateScheduled === 'function') {
  4342. injectedProfilingHooks.markStateUpdateScheduled(fiber, lane);
  4343. }
  4344. }
  4345. }
  4346. var NoMode =
  4347. /* */
  4348. 0; // TODO: Remove ConcurrentMode by reading from the root tag instead
  4349. var ConcurrentMode =
  4350. /* */
  4351. 1;
  4352. var ProfileMode =
  4353. /* */
  4354. 2;
  4355. var StrictLegacyMode =
  4356. /* */
  4357. 8;
  4358. var StrictEffectsMode =
  4359. /* */
  4360. 16;
  4361. // TODO: This is pretty well supported by browsers. Maybe we can drop it.
  4362. var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
  4363. // Based on:
  4364. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
  4365. var log = Math.log;
  4366. var LN2 = Math.LN2;
  4367. function clz32Fallback(x) {
  4368. var asUint = x >>> 0;
  4369. if (asUint === 0) {
  4370. return 32;
  4371. }
  4372. return 31 - (log(asUint) / LN2 | 0) | 0;
  4373. }
  4374. // If those values are changed that package should be rebuilt and redeployed.
  4375. var TotalLanes = 31;
  4376. var NoLanes =
  4377. /* */
  4378. 0;
  4379. var NoLane =
  4380. /* */
  4381. 0;
  4382. var SyncLane =
  4383. /* */
  4384. 1;
  4385. var InputContinuousHydrationLane =
  4386. /* */
  4387. 2;
  4388. var InputContinuousLane =
  4389. /* */
  4390. 4;
  4391. var DefaultHydrationLane =
  4392. /* */
  4393. 8;
  4394. var DefaultLane =
  4395. /* */
  4396. 16;
  4397. var TransitionHydrationLane =
  4398. /* */
  4399. 32;
  4400. var TransitionLanes =
  4401. /* */
  4402. 4194240;
  4403. var TransitionLane1 =
  4404. /* */
  4405. 64;
  4406. var TransitionLane2 =
  4407. /* */
  4408. 128;
  4409. var TransitionLane3 =
  4410. /* */
  4411. 256;
  4412. var TransitionLane4 =
  4413. /* */
  4414. 512;
  4415. var TransitionLane5 =
  4416. /* */
  4417. 1024;
  4418. var TransitionLane6 =
  4419. /* */
  4420. 2048;
  4421. var TransitionLane7 =
  4422. /* */
  4423. 4096;
  4424. var TransitionLane8 =
  4425. /* */
  4426. 8192;
  4427. var TransitionLane9 =
  4428. /* */
  4429. 16384;
  4430. var TransitionLane10 =
  4431. /* */
  4432. 32768;
  4433. var TransitionLane11 =
  4434. /* */
  4435. 65536;
  4436. var TransitionLane12 =
  4437. /* */
  4438. 131072;
  4439. var TransitionLane13 =
  4440. /* */
  4441. 262144;
  4442. var TransitionLane14 =
  4443. /* */
  4444. 524288;
  4445. var TransitionLane15 =
  4446. /* */
  4447. 1048576;
  4448. var TransitionLane16 =
  4449. /* */
  4450. 2097152;
  4451. var RetryLanes =
  4452. /* */
  4453. 130023424;
  4454. var RetryLane1 =
  4455. /* */
  4456. 4194304;
  4457. var RetryLane2 =
  4458. /* */
  4459. 8388608;
  4460. var RetryLane3 =
  4461. /* */
  4462. 16777216;
  4463. var RetryLane4 =
  4464. /* */
  4465. 33554432;
  4466. var RetryLane5 =
  4467. /* */
  4468. 67108864;
  4469. var SomeRetryLane = RetryLane1;
  4470. var SelectiveHydrationLane =
  4471. /* */
  4472. 134217728;
  4473. var NonIdleLanes =
  4474. /* */
  4475. 268435455;
  4476. var IdleHydrationLane =
  4477. /* */
  4478. 268435456;
  4479. var IdleLane =
  4480. /* */
  4481. 536870912;
  4482. var OffscreenLane =
  4483. /* */
  4484. 1073741824; // This function is used for the experimental timeline (react-devtools-timeline)
  4485. // It should be kept in sync with the Lanes values above.
  4486. function getLabelForLane(lane) {
  4487. {
  4488. if (lane & SyncLane) {
  4489. return 'Sync';
  4490. }
  4491. if (lane & InputContinuousHydrationLane) {
  4492. return 'InputContinuousHydration';
  4493. }
  4494. if (lane & InputContinuousLane) {
  4495. return 'InputContinuous';
  4496. }
  4497. if (lane & DefaultHydrationLane) {
  4498. return 'DefaultHydration';
  4499. }
  4500. if (lane & DefaultLane) {
  4501. return 'Default';
  4502. }
  4503. if (lane & TransitionHydrationLane) {
  4504. return 'TransitionHydration';
  4505. }
  4506. if (lane & TransitionLanes) {
  4507. return 'Transition';
  4508. }
  4509. if (lane & RetryLanes) {
  4510. return 'Retry';
  4511. }
  4512. if (lane & SelectiveHydrationLane) {
  4513. return 'SelectiveHydration';
  4514. }
  4515. if (lane & IdleHydrationLane) {
  4516. return 'IdleHydration';
  4517. }
  4518. if (lane & IdleLane) {
  4519. return 'Idle';
  4520. }
  4521. if (lane & OffscreenLane) {
  4522. return 'Offscreen';
  4523. }
  4524. }
  4525. }
  4526. var NoTimestamp = -1;
  4527. var nextTransitionLane = TransitionLane1;
  4528. var nextRetryLane = RetryLane1;
  4529. function getHighestPriorityLanes(lanes) {
  4530. switch (getHighestPriorityLane(lanes)) {
  4531. case SyncLane:
  4532. return SyncLane;
  4533. case InputContinuousHydrationLane:
  4534. return InputContinuousHydrationLane;
  4535. case InputContinuousLane:
  4536. return InputContinuousLane;
  4537. case DefaultHydrationLane:
  4538. return DefaultHydrationLane;
  4539. case DefaultLane:
  4540. return DefaultLane;
  4541. case TransitionHydrationLane:
  4542. return TransitionHydrationLane;
  4543. case TransitionLane1:
  4544. case TransitionLane2:
  4545. case TransitionLane3:
  4546. case TransitionLane4:
  4547. case TransitionLane5:
  4548. case TransitionLane6:
  4549. case TransitionLane7:
  4550. case TransitionLane8:
  4551. case TransitionLane9:
  4552. case TransitionLane10:
  4553. case TransitionLane11:
  4554. case TransitionLane12:
  4555. case TransitionLane13:
  4556. case TransitionLane14:
  4557. case TransitionLane15:
  4558. case TransitionLane16:
  4559. return lanes & TransitionLanes;
  4560. case RetryLane1:
  4561. case RetryLane2:
  4562. case RetryLane3:
  4563. case RetryLane4:
  4564. case RetryLane5:
  4565. return lanes & RetryLanes;
  4566. case SelectiveHydrationLane:
  4567. return SelectiveHydrationLane;
  4568. case IdleHydrationLane:
  4569. return IdleHydrationLane;
  4570. case IdleLane:
  4571. return IdleLane;
  4572. case OffscreenLane:
  4573. return OffscreenLane;
  4574. default:
  4575. {
  4576. error('Should have found matching lanes. This is a bug in React.');
  4577. } // This shouldn't be reachable, but as a fallback, return the entire bitmask.
  4578. return lanes;
  4579. }
  4580. }
  4581. function getNextLanes(root, wipLanes) {
  4582. // Early bailout if there's no pending work left.
  4583. var pendingLanes = root.pendingLanes;
  4584. if (pendingLanes === NoLanes) {
  4585. return NoLanes;
  4586. }
  4587. var nextLanes = NoLanes;
  4588. var suspendedLanes = root.suspendedLanes;
  4589. var pingedLanes = root.pingedLanes; // Do not work on any idle work until all the non-idle work has finished,
  4590. // even if the work is suspended.
  4591. var nonIdlePendingLanes = pendingLanes & NonIdleLanes;
  4592. if (nonIdlePendingLanes !== NoLanes) {
  4593. var nonIdleUnblockedLanes = nonIdlePendingLanes & ~suspendedLanes;
  4594. if (nonIdleUnblockedLanes !== NoLanes) {
  4595. nextLanes = getHighestPriorityLanes(nonIdleUnblockedLanes);
  4596. } else {
  4597. var nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes;
  4598. if (nonIdlePingedLanes !== NoLanes) {
  4599. nextLanes = getHighestPriorityLanes(nonIdlePingedLanes);
  4600. }
  4601. }
  4602. } else {
  4603. // The only remaining work is Idle.
  4604. var unblockedLanes = pendingLanes & ~suspendedLanes;
  4605. if (unblockedLanes !== NoLanes) {
  4606. nextLanes = getHighestPriorityLanes(unblockedLanes);
  4607. } else {
  4608. if (pingedLanes !== NoLanes) {
  4609. nextLanes = getHighestPriorityLanes(pingedLanes);
  4610. }
  4611. }
  4612. }
  4613. if (nextLanes === NoLanes) {
  4614. // This should only be reachable if we're suspended
  4615. // TODO: Consider warning in this path if a fallback timer is not scheduled.
  4616. return NoLanes;
  4617. } // If we're already in the middle of a render, switching lanes will interrupt
  4618. // it and we'll lose our progress. We should only do this if the new lanes are
  4619. // higher priority.
  4620. if (wipLanes !== NoLanes && wipLanes !== nextLanes && // If we already suspended with a delay, then interrupting is fine. Don't
  4621. // bother waiting until the root is complete.
  4622. (wipLanes & suspendedLanes) === NoLanes) {
  4623. var nextLane = getHighestPriorityLane(nextLanes);
  4624. var wipLane = getHighestPriorityLane(wipLanes);
  4625. if ( // Tests whether the next lane is equal or lower priority than the wip
  4626. // one. This works because the bits decrease in priority as you go left.
  4627. nextLane >= wipLane || // Default priority updates should not interrupt transition updates. The
  4628. // only difference between default updates and transition updates is that
  4629. // default updates do not support refresh transitions.
  4630. nextLane === DefaultLane && (wipLane & TransitionLanes) !== NoLanes) {
  4631. // Keep working on the existing in-progress tree. Do not interrupt.
  4632. return wipLanes;
  4633. }
  4634. }
  4635. if ((nextLanes & InputContinuousLane) !== NoLanes) {
  4636. // When updates are sync by default, we entangle continuous priority updates
  4637. // and default updates, so they render in the same batch. The only reason
  4638. // they use separate lanes is because continuous updates should interrupt
  4639. // transitions, but default updates should not.
  4640. nextLanes |= pendingLanes & DefaultLane;
  4641. } // Check for entangled lanes and add them to the batch.
  4642. //
  4643. // A lane is said to be entangled with another when it's not allowed to render
  4644. // in a batch that does not also include the other lane. Typically we do this
  4645. // when multiple updates have the same source, and we only want to respond to
  4646. // the most recent event from that source.
  4647. //
  4648. // Note that we apply entanglements *after* checking for partial work above.
  4649. // This means that if a lane is entangled during an interleaved event while
  4650. // it's already rendering, we won't interrupt it. This is intentional, since
  4651. // entanglement is usually "best effort": we'll try our best to render the
  4652. // lanes in the same batch, but it's not worth throwing out partially
  4653. // completed work in order to do it.
  4654. // TODO: Reconsider this. The counter-argument is that the partial work
  4655. // represents an intermediate state, which we don't want to show to the user.
  4656. // And by spending extra time finishing it, we're increasing the amount of
  4657. // time it takes to show the final state, which is what they are actually
  4658. // waiting for.
  4659. //
  4660. // For those exceptions where entanglement is semantically important, like
  4661. // useMutableSource, we should ensure that there is no partial work at the
  4662. // time we apply the entanglement.
  4663. var entangledLanes = root.entangledLanes;
  4664. if (entangledLanes !== NoLanes) {
  4665. var entanglements = root.entanglements;
  4666. var lanes = nextLanes & entangledLanes;
  4667. while (lanes > 0) {
  4668. var index = pickArbitraryLaneIndex(lanes);
  4669. var lane = 1 << index;
  4670. nextLanes |= entanglements[index];
  4671. lanes &= ~lane;
  4672. }
  4673. }
  4674. return nextLanes;
  4675. }
  4676. function getMostRecentEventTime(root, lanes) {
  4677. var eventTimes = root.eventTimes;
  4678. var mostRecentEventTime = NoTimestamp;
  4679. while (lanes > 0) {
  4680. var index = pickArbitraryLaneIndex(lanes);
  4681. var lane = 1 << index;
  4682. var eventTime = eventTimes[index];
  4683. if (eventTime > mostRecentEventTime) {
  4684. mostRecentEventTime = eventTime;
  4685. }
  4686. lanes &= ~lane;
  4687. }
  4688. return mostRecentEventTime;
  4689. }
  4690. function computeExpirationTime(lane, currentTime) {
  4691. switch (lane) {
  4692. case SyncLane:
  4693. case InputContinuousHydrationLane:
  4694. case InputContinuousLane:
  4695. // User interactions should expire slightly more quickly.
  4696. //
  4697. // NOTE: This is set to the corresponding constant as in Scheduler.js.
  4698. // When we made it larger, a product metric in www regressed, suggesting
  4699. // there's a user interaction that's being starved by a series of
  4700. // synchronous updates. If that theory is correct, the proper solution is
  4701. // to fix the starvation. However, this scenario supports the idea that
  4702. // expiration times are an important safeguard when starvation
  4703. // does happen.
  4704. return currentTime + 250;
  4705. case DefaultHydrationLane:
  4706. case DefaultLane:
  4707. case TransitionHydrationLane:
  4708. case TransitionLane1:
  4709. case TransitionLane2:
  4710. case TransitionLane3:
  4711. case TransitionLane4:
  4712. case TransitionLane5:
  4713. case TransitionLane6:
  4714. case TransitionLane7:
  4715. case TransitionLane8:
  4716. case TransitionLane9:
  4717. case TransitionLane10:
  4718. case TransitionLane11:
  4719. case TransitionLane12:
  4720. case TransitionLane13:
  4721. case TransitionLane14:
  4722. case TransitionLane15:
  4723. case TransitionLane16:
  4724. return currentTime + 5000;
  4725. case RetryLane1:
  4726. case RetryLane2:
  4727. case RetryLane3:
  4728. case RetryLane4:
  4729. case RetryLane5:
  4730. // TODO: Retries should be allowed to expire if they are CPU bound for
  4731. // too long, but when I made this change it caused a spike in browser
  4732. // crashes. There must be some other underlying bug; not super urgent but
  4733. // ideally should figure out why and fix it. Unfortunately we don't have
  4734. // a repro for the crashes, only detected via production metrics.
  4735. return NoTimestamp;
  4736. case SelectiveHydrationLane:
  4737. case IdleHydrationLane:
  4738. case IdleLane:
  4739. case OffscreenLane:
  4740. // Anything idle priority or lower should never expire.
  4741. return NoTimestamp;
  4742. default:
  4743. {
  4744. error('Should have found matching lanes. This is a bug in React.');
  4745. }
  4746. return NoTimestamp;
  4747. }
  4748. }
  4749. function markStarvedLanesAsExpired(root, currentTime) {
  4750. // TODO: This gets called every time we yield. We can optimize by storing
  4751. // the earliest expiration time on the root. Then use that to quickly bail out
  4752. // of this function.
  4753. var pendingLanes = root.pendingLanes;
  4754. var suspendedLanes = root.suspendedLanes;
  4755. var pingedLanes = root.pingedLanes;
  4756. var expirationTimes = root.expirationTimes; // Iterate through the pending lanes and check if we've reached their
  4757. // expiration time. If so, we'll assume the update is being starved and mark
  4758. // it as expired to force it to finish.
  4759. var lanes = pendingLanes;
  4760. while (lanes > 0) {
  4761. var index = pickArbitraryLaneIndex(lanes);
  4762. var lane = 1 << index;
  4763. var expirationTime = expirationTimes[index];
  4764. if (expirationTime === NoTimestamp) {
  4765. // Found a pending lane with no expiration time. If it's not suspended, or
  4766. // if it's pinged, assume it's CPU-bound. Compute a new expiration time
  4767. // using the current time.
  4768. if ((lane & suspendedLanes) === NoLanes || (lane & pingedLanes) !== NoLanes) {
  4769. // Assumes timestamps are monotonically increasing.
  4770. expirationTimes[index] = computeExpirationTime(lane, currentTime);
  4771. }
  4772. } else if (expirationTime <= currentTime) {
  4773. // This lane expired
  4774. root.expiredLanes |= lane;
  4775. }
  4776. lanes &= ~lane;
  4777. }
  4778. } // This returns the highest priority pending lanes regardless of whether they
  4779. // are suspended.
  4780. function getHighestPriorityPendingLanes(root) {
  4781. return getHighestPriorityLanes(root.pendingLanes);
  4782. }
  4783. function getLanesToRetrySynchronouslyOnError(root) {
  4784. var everythingButOffscreen = root.pendingLanes & ~OffscreenLane;
  4785. if (everythingButOffscreen !== NoLanes) {
  4786. return everythingButOffscreen;
  4787. }
  4788. if (everythingButOffscreen & OffscreenLane) {
  4789. return OffscreenLane;
  4790. }
  4791. return NoLanes;
  4792. }
  4793. function includesSyncLane(lanes) {
  4794. return (lanes & SyncLane) !== NoLanes;
  4795. }
  4796. function includesNonIdleWork(lanes) {
  4797. return (lanes & NonIdleLanes) !== NoLanes;
  4798. }
  4799. function includesOnlyRetries(lanes) {
  4800. return (lanes & RetryLanes) === lanes;
  4801. }
  4802. function includesOnlyNonUrgentLanes(lanes) {
  4803. var UrgentLanes = SyncLane | InputContinuousLane | DefaultLane;
  4804. return (lanes & UrgentLanes) === NoLanes;
  4805. }
  4806. function includesOnlyTransitions(lanes) {
  4807. return (lanes & TransitionLanes) === lanes;
  4808. }
  4809. function includesBlockingLane(root, lanes) {
  4810. var SyncDefaultLanes = InputContinuousHydrationLane | InputContinuousLane | DefaultHydrationLane | DefaultLane;
  4811. return (lanes & SyncDefaultLanes) !== NoLanes;
  4812. }
  4813. function includesExpiredLane(root, lanes) {
  4814. // This is a separate check from includesBlockingLane because a lane can
  4815. // expire after a render has already started.
  4816. return (lanes & root.expiredLanes) !== NoLanes;
  4817. }
  4818. function isTransitionLane(lane) {
  4819. return (lane & TransitionLanes) !== NoLanes;
  4820. }
  4821. function claimNextTransitionLane() {
  4822. // Cycle through the lanes, assigning each new transition to the next lane.
  4823. // In most cases, this means every transition gets its own lane, until we
  4824. // run out of lanes and cycle back to the beginning.
  4825. var lane = nextTransitionLane;
  4826. nextTransitionLane <<= 1;
  4827. if ((nextTransitionLane & TransitionLanes) === NoLanes) {
  4828. nextTransitionLane = TransitionLane1;
  4829. }
  4830. return lane;
  4831. }
  4832. function claimNextRetryLane() {
  4833. var lane = nextRetryLane;
  4834. nextRetryLane <<= 1;
  4835. if ((nextRetryLane & RetryLanes) === NoLanes) {
  4836. nextRetryLane = RetryLane1;
  4837. }
  4838. return lane;
  4839. }
  4840. function getHighestPriorityLane(lanes) {
  4841. return lanes & -lanes;
  4842. }
  4843. function pickArbitraryLane(lanes) {
  4844. // This wrapper function gets inlined. Only exists so to communicate that it
  4845. // doesn't matter which bit is selected; you can pick any bit without
  4846. // affecting the algorithms where its used. Here I'm using
  4847. // getHighestPriorityLane because it requires the fewest operations.
  4848. return getHighestPriorityLane(lanes);
  4849. }
  4850. function pickArbitraryLaneIndex(lanes) {
  4851. return 31 - clz32(lanes);
  4852. }
  4853. function laneToIndex(lane) {
  4854. return pickArbitraryLaneIndex(lane);
  4855. }
  4856. function includesSomeLane(a, b) {
  4857. return (a & b) !== NoLanes;
  4858. }
  4859. function isSubsetOfLanes(set, subset) {
  4860. return (set & subset) === subset;
  4861. }
  4862. function mergeLanes(a, b) {
  4863. return a | b;
  4864. }
  4865. function removeLanes(set, subset) {
  4866. return set & ~subset;
  4867. }
  4868. function intersectLanes(a, b) {
  4869. return a & b;
  4870. } // Seems redundant, but it changes the type from a single lane (used for
  4871. // updates) to a group of lanes (used for flushing work).
  4872. function laneToLanes(lane) {
  4873. return lane;
  4874. }
  4875. function higherPriorityLane(a, b) {
  4876. // This works because the bit ranges decrease in priority as you go left.
  4877. return a !== NoLane && a < b ? a : b;
  4878. }
  4879. function createLaneMap(initial) {
  4880. // Intentionally pushing one by one.
  4881. // https://v8.dev/blog/elements-kinds#avoid-creating-holes
  4882. var laneMap = [];
  4883. for (var i = 0; i < TotalLanes; i++) {
  4884. laneMap.push(initial);
  4885. }
  4886. return laneMap;
  4887. }
  4888. function markRootUpdated(root, updateLane, eventTime) {
  4889. root.pendingLanes |= updateLane; // If there are any suspended transitions, it's possible this new update
  4890. // could unblock them. Clear the suspended lanes so that we can try rendering
  4891. // them again.
  4892. //
  4893. // TODO: We really only need to unsuspend only lanes that are in the
  4894. // `subtreeLanes` of the updated fiber, or the update lanes of the return
  4895. // path. This would exclude suspended updates in an unrelated sibling tree,
  4896. // since there's no way for this update to unblock it.
  4897. //
  4898. // We don't do this if the incoming update is idle, because we never process
  4899. // idle updates until after all the regular updates have finished; there's no
  4900. // way it could unblock a transition.
  4901. if (updateLane !== IdleLane) {
  4902. root.suspendedLanes = NoLanes;
  4903. root.pingedLanes = NoLanes;
  4904. }
  4905. var eventTimes = root.eventTimes;
  4906. var index = laneToIndex(updateLane); // We can always overwrite an existing timestamp because we prefer the most
  4907. // recent event, and we assume time is monotonically increasing.
  4908. eventTimes[index] = eventTime;
  4909. }
  4910. function markRootSuspended(root, suspendedLanes) {
  4911. root.suspendedLanes |= suspendedLanes;
  4912. root.pingedLanes &= ~suspendedLanes; // The suspended lanes are no longer CPU-bound. Clear their expiration times.
  4913. var expirationTimes = root.expirationTimes;
  4914. var lanes = suspendedLanes;
  4915. while (lanes > 0) {
  4916. var index = pickArbitraryLaneIndex(lanes);
  4917. var lane = 1 << index;
  4918. expirationTimes[index] = NoTimestamp;
  4919. lanes &= ~lane;
  4920. }
  4921. }
  4922. function markRootPinged(root, pingedLanes, eventTime) {
  4923. root.pingedLanes |= root.suspendedLanes & pingedLanes;
  4924. }
  4925. function markRootFinished(root, remainingLanes) {
  4926. var noLongerPendingLanes = root.pendingLanes & ~remainingLanes;
  4927. root.pendingLanes = remainingLanes; // Let's try everything again
  4928. root.suspendedLanes = NoLanes;
  4929. root.pingedLanes = NoLanes;
  4930. root.expiredLanes &= remainingLanes;
  4931. root.mutableReadLanes &= remainingLanes;
  4932. root.entangledLanes &= remainingLanes;
  4933. var entanglements = root.entanglements;
  4934. var eventTimes = root.eventTimes;
  4935. var expirationTimes = root.expirationTimes; // Clear the lanes that no longer have pending work
  4936. var lanes = noLongerPendingLanes;
  4937. while (lanes > 0) {
  4938. var index = pickArbitraryLaneIndex(lanes);
  4939. var lane = 1 << index;
  4940. entanglements[index] = NoLanes;
  4941. eventTimes[index] = NoTimestamp;
  4942. expirationTimes[index] = NoTimestamp;
  4943. lanes &= ~lane;
  4944. }
  4945. }
  4946. function markRootEntangled(root, entangledLanes) {
  4947. // In addition to entangling each of the given lanes with each other, we also
  4948. // have to consider _transitive_ entanglements. For each lane that is already
  4949. // entangled with *any* of the given lanes, that lane is now transitively
  4950. // entangled with *all* the given lanes.
  4951. //
  4952. // Translated: If C is entangled with A, then entangling A with B also
  4953. // entangles C with B.
  4954. //
  4955. // If this is hard to grasp, it might help to intentionally break this
  4956. // function and look at the tests that fail in ReactTransition-test.js. Try
  4957. // commenting out one of the conditions below.
  4958. var rootEntangledLanes = root.entangledLanes |= entangledLanes;
  4959. var entanglements = root.entanglements;
  4960. var lanes = rootEntangledLanes;
  4961. while (lanes) {
  4962. var index = pickArbitraryLaneIndex(lanes);
  4963. var lane = 1 << index;
  4964. if ( // Is this one of the newly entangled lanes?
  4965. lane & entangledLanes | // Is this lane transitively entangled with the newly entangled lanes?
  4966. entanglements[index] & entangledLanes) {
  4967. entanglements[index] |= entangledLanes;
  4968. }
  4969. lanes &= ~lane;
  4970. }
  4971. }
  4972. function getBumpedLaneForHydration(root, renderLanes) {
  4973. var renderLane = getHighestPriorityLane(renderLanes);
  4974. var lane;
  4975. switch (renderLane) {
  4976. case InputContinuousLane:
  4977. lane = InputContinuousHydrationLane;
  4978. break;
  4979. case DefaultLane:
  4980. lane = DefaultHydrationLane;
  4981. break;
  4982. case TransitionLane1:
  4983. case TransitionLane2:
  4984. case TransitionLane3:
  4985. case TransitionLane4:
  4986. case TransitionLane5:
  4987. case TransitionLane6:
  4988. case TransitionLane7:
  4989. case TransitionLane8:
  4990. case TransitionLane9:
  4991. case TransitionLane10:
  4992. case TransitionLane11:
  4993. case TransitionLane12:
  4994. case TransitionLane13:
  4995. case TransitionLane14:
  4996. case TransitionLane15:
  4997. case TransitionLane16:
  4998. case RetryLane1:
  4999. case RetryLane2:
  5000. case RetryLane3:
  5001. case RetryLane4:
  5002. case RetryLane5:
  5003. lane = TransitionHydrationLane;
  5004. break;
  5005. case IdleLane:
  5006. lane = IdleHydrationLane;
  5007. break;
  5008. default:
  5009. // Everything else is already either a hydration lane, or shouldn't
  5010. // be retried at a hydration lane.
  5011. lane = NoLane;
  5012. break;
  5013. } // Check if the lane we chose is suspended. If so, that indicates that we
  5014. // already attempted and failed to hydrate at that level. Also check if we're
  5015. // already rendering that lane, which is rare but could happen.
  5016. if ((lane & (root.suspendedLanes | renderLanes)) !== NoLane) {
  5017. // Give up trying to hydrate and fall back to client render.
  5018. return NoLane;
  5019. }
  5020. return lane;
  5021. }
  5022. function addFiberToLanesMap(root, fiber, lanes) {
  5023. if (!isDevToolsPresent) {
  5024. return;
  5025. }
  5026. var pendingUpdatersLaneMap = root.pendingUpdatersLaneMap;
  5027. while (lanes > 0) {
  5028. var index = laneToIndex(lanes);
  5029. var lane = 1 << index;
  5030. var updaters = pendingUpdatersLaneMap[index];
  5031. updaters.add(fiber);
  5032. lanes &= ~lane;
  5033. }
  5034. }
  5035. function movePendingFibersToMemoized(root, lanes) {
  5036. if (!isDevToolsPresent) {
  5037. return;
  5038. }
  5039. var pendingUpdatersLaneMap = root.pendingUpdatersLaneMap;
  5040. var memoizedUpdaters = root.memoizedUpdaters;
  5041. while (lanes > 0) {
  5042. var index = laneToIndex(lanes);
  5043. var lane = 1 << index;
  5044. var updaters = pendingUpdatersLaneMap[index];
  5045. if (updaters.size > 0) {
  5046. updaters.forEach(function (fiber) {
  5047. var alternate = fiber.alternate;
  5048. if (alternate === null || !memoizedUpdaters.has(alternate)) {
  5049. memoizedUpdaters.add(fiber);
  5050. }
  5051. });
  5052. updaters.clear();
  5053. }
  5054. lanes &= ~lane;
  5055. }
  5056. }
  5057. function getTransitionsForLanes(root, lanes) {
  5058. {
  5059. return null;
  5060. }
  5061. }
  5062. var DiscreteEventPriority = SyncLane;
  5063. var ContinuousEventPriority = InputContinuousLane;
  5064. var DefaultEventPriority = DefaultLane;
  5065. var IdleEventPriority = IdleLane;
  5066. var currentUpdatePriority = NoLane;
  5067. function getCurrentUpdatePriority() {
  5068. return currentUpdatePriority;
  5069. }
  5070. function setCurrentUpdatePriority(newPriority) {
  5071. currentUpdatePriority = newPriority;
  5072. }
  5073. function runWithPriority(priority, fn) {
  5074. var previousPriority = currentUpdatePriority;
  5075. try {
  5076. currentUpdatePriority = priority;
  5077. return fn();
  5078. } finally {
  5079. currentUpdatePriority = previousPriority;
  5080. }
  5081. }
  5082. function higherEventPriority(a, b) {
  5083. return a !== 0 && a < b ? a : b;
  5084. }
  5085. function lowerEventPriority(a, b) {
  5086. return a === 0 || a > b ? a : b;
  5087. }
  5088. function isHigherEventPriority(a, b) {
  5089. return a !== 0 && a < b;
  5090. }
  5091. function lanesToEventPriority(lanes) {
  5092. var lane = getHighestPriorityLane(lanes);
  5093. if (!isHigherEventPriority(DiscreteEventPriority, lane)) {
  5094. return DiscreteEventPriority;
  5095. }
  5096. if (!isHigherEventPriority(ContinuousEventPriority, lane)) {
  5097. return ContinuousEventPriority;
  5098. }
  5099. if (includesNonIdleWork(lane)) {
  5100. return DefaultEventPriority;
  5101. }
  5102. return IdleEventPriority;
  5103. }
  5104. // This is imported by the event replaying implementation in React DOM. It's
  5105. // in a separate file to break a circular dependency between the renderer and
  5106. // the reconciler.
  5107. function isRootDehydrated(root) {
  5108. var currentState = root.current.memoizedState;
  5109. return currentState.isDehydrated;
  5110. }
  5111. var _attemptSynchronousHydration;
  5112. function setAttemptSynchronousHydration(fn) {
  5113. _attemptSynchronousHydration = fn;
  5114. }
  5115. function attemptSynchronousHydration(fiber) {
  5116. _attemptSynchronousHydration(fiber);
  5117. }
  5118. var attemptContinuousHydration;
  5119. function setAttemptContinuousHydration(fn) {
  5120. attemptContinuousHydration = fn;
  5121. }
  5122. var attemptHydrationAtCurrentPriority;
  5123. function setAttemptHydrationAtCurrentPriority(fn) {
  5124. attemptHydrationAtCurrentPriority = fn;
  5125. }
  5126. var getCurrentUpdatePriority$1;
  5127. function setGetCurrentUpdatePriority(fn) {
  5128. getCurrentUpdatePriority$1 = fn;
  5129. }
  5130. var attemptHydrationAtPriority;
  5131. function setAttemptHydrationAtPriority(fn) {
  5132. attemptHydrationAtPriority = fn;
  5133. } // TODO: Upgrade this definition once we're on a newer version of Flow that
  5134. // has this definition built-in.
  5135. var hasScheduledReplayAttempt = false; // The queue of discrete events to be replayed.
  5136. var queuedDiscreteEvents = []; // Indicates if any continuous event targets are non-null for early bailout.
  5137. // if the last target was dehydrated.
  5138. var queuedFocus = null;
  5139. var queuedDrag = null;
  5140. var queuedMouse = null; // For pointer events there can be one latest event per pointerId.
  5141. var queuedPointers = new Map();
  5142. var queuedPointerCaptures = new Map(); // We could consider replaying selectionchange and touchmoves too.
  5143. var queuedExplicitHydrationTargets = [];
  5144. var discreteReplayableEvents = ['mousedown', 'mouseup', 'touchcancel', 'touchend', 'touchstart', 'auxclick', 'dblclick', 'pointercancel', 'pointerdown', 'pointerup', 'dragend', 'dragstart', 'drop', 'compositionend', 'compositionstart', 'keydown', 'keypress', 'keyup', 'input', 'textInput', // Intentionally camelCase
  5145. 'copy', 'cut', 'paste', 'click', 'change', 'contextmenu', 'reset', 'submit'];
  5146. function isDiscreteEventThatRequiresHydration(eventType) {
  5147. return discreteReplayableEvents.indexOf(eventType) > -1;
  5148. }
  5149. function createQueuedReplayableEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  5150. return {
  5151. blockedOn: blockedOn,
  5152. domEventName: domEventName,
  5153. eventSystemFlags: eventSystemFlags,
  5154. nativeEvent: nativeEvent,
  5155. targetContainers: [targetContainer]
  5156. };
  5157. }
  5158. function clearIfContinuousEvent(domEventName, nativeEvent) {
  5159. switch (domEventName) {
  5160. case 'focusin':
  5161. case 'focusout':
  5162. queuedFocus = null;
  5163. break;
  5164. case 'dragenter':
  5165. case 'dragleave':
  5166. queuedDrag = null;
  5167. break;
  5168. case 'mouseover':
  5169. case 'mouseout':
  5170. queuedMouse = null;
  5171. break;
  5172. case 'pointerover':
  5173. case 'pointerout':
  5174. {
  5175. var pointerId = nativeEvent.pointerId;
  5176. queuedPointers.delete(pointerId);
  5177. break;
  5178. }
  5179. case 'gotpointercapture':
  5180. case 'lostpointercapture':
  5181. {
  5182. var _pointerId = nativeEvent.pointerId;
  5183. queuedPointerCaptures.delete(_pointerId);
  5184. break;
  5185. }
  5186. }
  5187. }
  5188. function accumulateOrCreateContinuousQueuedReplayableEvent(existingQueuedEvent, blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  5189. if (existingQueuedEvent === null || existingQueuedEvent.nativeEvent !== nativeEvent) {
  5190. var queuedEvent = createQueuedReplayableEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent);
  5191. if (blockedOn !== null) {
  5192. var _fiber2 = getInstanceFromNode(blockedOn);
  5193. if (_fiber2 !== null) {
  5194. // Attempt to increase the priority of this target.
  5195. attemptContinuousHydration(_fiber2);
  5196. }
  5197. }
  5198. return queuedEvent;
  5199. } // If we have already queued this exact event, then it's because
  5200. // the different event systems have different DOM event listeners.
  5201. // We can accumulate the flags, and the targetContainers, and
  5202. // store a single event to be replayed.
  5203. existingQueuedEvent.eventSystemFlags |= eventSystemFlags;
  5204. var targetContainers = existingQueuedEvent.targetContainers;
  5205. if (targetContainer !== null && targetContainers.indexOf(targetContainer) === -1) {
  5206. targetContainers.push(targetContainer);
  5207. }
  5208. return existingQueuedEvent;
  5209. }
  5210. function queueIfContinuousEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  5211. // These set relatedTarget to null because the replayed event will be treated as if we
  5212. // moved from outside the window (no target) onto the target once it hydrates.
  5213. // Instead of mutating we could clone the event.
  5214. switch (domEventName) {
  5215. case 'focusin':
  5216. {
  5217. var focusEvent = nativeEvent;
  5218. queuedFocus = accumulateOrCreateContinuousQueuedReplayableEvent(queuedFocus, blockedOn, domEventName, eventSystemFlags, targetContainer, focusEvent);
  5219. return true;
  5220. }
  5221. case 'dragenter':
  5222. {
  5223. var dragEvent = nativeEvent;
  5224. queuedDrag = accumulateOrCreateContinuousQueuedReplayableEvent(queuedDrag, blockedOn, domEventName, eventSystemFlags, targetContainer, dragEvent);
  5225. return true;
  5226. }
  5227. case 'mouseover':
  5228. {
  5229. var mouseEvent = nativeEvent;
  5230. queuedMouse = accumulateOrCreateContinuousQueuedReplayableEvent(queuedMouse, blockedOn, domEventName, eventSystemFlags, targetContainer, mouseEvent);
  5231. return true;
  5232. }
  5233. case 'pointerover':
  5234. {
  5235. var pointerEvent = nativeEvent;
  5236. var pointerId = pointerEvent.pointerId;
  5237. queuedPointers.set(pointerId, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointers.get(pointerId) || null, blockedOn, domEventName, eventSystemFlags, targetContainer, pointerEvent));
  5238. return true;
  5239. }
  5240. case 'gotpointercapture':
  5241. {
  5242. var _pointerEvent = nativeEvent;
  5243. var _pointerId2 = _pointerEvent.pointerId;
  5244. queuedPointerCaptures.set(_pointerId2, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointerCaptures.get(_pointerId2) || null, blockedOn, domEventName, eventSystemFlags, targetContainer, _pointerEvent));
  5245. return true;
  5246. }
  5247. }
  5248. return false;
  5249. } // Check if this target is unblocked. Returns true if it's unblocked.
  5250. function attemptExplicitHydrationTarget(queuedTarget) {
  5251. // TODO: This function shares a lot of logic with findInstanceBlockingEvent.
  5252. // Try to unify them. It's a bit tricky since it would require two return
  5253. // values.
  5254. var targetInst = getClosestInstanceFromNode(queuedTarget.target);
  5255. if (targetInst !== null) {
  5256. var nearestMounted = getNearestMountedFiber(targetInst);
  5257. if (nearestMounted !== null) {
  5258. var tag = nearestMounted.tag;
  5259. if (tag === SuspenseComponent) {
  5260. var instance = getSuspenseInstanceFromFiber(nearestMounted);
  5261. if (instance !== null) {
  5262. // We're blocked on hydrating this boundary.
  5263. // Increase its priority.
  5264. queuedTarget.blockedOn = instance;
  5265. attemptHydrationAtPriority(queuedTarget.priority, function () {
  5266. attemptHydrationAtCurrentPriority(nearestMounted);
  5267. });
  5268. return;
  5269. }
  5270. } else if (tag === HostRoot) {
  5271. var root = nearestMounted.stateNode;
  5272. if (isRootDehydrated(root)) {
  5273. queuedTarget.blockedOn = getContainerFromFiber(nearestMounted); // We don't currently have a way to increase the priority of
  5274. // a root other than sync.
  5275. return;
  5276. }
  5277. }
  5278. }
  5279. }
  5280. queuedTarget.blockedOn = null;
  5281. }
  5282. function queueExplicitHydrationTarget(target) {
  5283. // TODO: This will read the priority if it's dispatched by the React
  5284. // event system but not native events. Should read window.event.type, like
  5285. // we do for updates (getCurrentEventPriority).
  5286. var updatePriority = getCurrentUpdatePriority$1();
  5287. var queuedTarget = {
  5288. blockedOn: null,
  5289. target: target,
  5290. priority: updatePriority
  5291. };
  5292. var i = 0;
  5293. for (; i < queuedExplicitHydrationTargets.length; i++) {
  5294. // Stop once we hit the first target with lower priority than
  5295. if (!isHigherEventPriority(updatePriority, queuedExplicitHydrationTargets[i].priority)) {
  5296. break;
  5297. }
  5298. }
  5299. queuedExplicitHydrationTargets.splice(i, 0, queuedTarget);
  5300. if (i === 0) {
  5301. attemptExplicitHydrationTarget(queuedTarget);
  5302. }
  5303. }
  5304. function attemptReplayContinuousQueuedEvent(queuedEvent) {
  5305. if (queuedEvent.blockedOn !== null) {
  5306. return false;
  5307. }
  5308. var targetContainers = queuedEvent.targetContainers;
  5309. while (targetContainers.length > 0) {
  5310. var targetContainer = targetContainers[0];
  5311. var nextBlockedOn = findInstanceBlockingEvent(queuedEvent.domEventName, queuedEvent.eventSystemFlags, targetContainer, queuedEvent.nativeEvent);
  5312. if (nextBlockedOn === null) {
  5313. {
  5314. var nativeEvent = queuedEvent.nativeEvent;
  5315. var nativeEventClone = new nativeEvent.constructor(nativeEvent.type, nativeEvent);
  5316. setReplayingEvent(nativeEventClone);
  5317. nativeEvent.target.dispatchEvent(nativeEventClone);
  5318. resetReplayingEvent();
  5319. }
  5320. } else {
  5321. // We're still blocked. Try again later.
  5322. var _fiber3 = getInstanceFromNode(nextBlockedOn);
  5323. if (_fiber3 !== null) {
  5324. attemptContinuousHydration(_fiber3);
  5325. }
  5326. queuedEvent.blockedOn = nextBlockedOn;
  5327. return false;
  5328. } // This target container was successfully dispatched. Try the next.
  5329. targetContainers.shift();
  5330. }
  5331. return true;
  5332. }
  5333. function attemptReplayContinuousQueuedEventInMap(queuedEvent, key, map) {
  5334. if (attemptReplayContinuousQueuedEvent(queuedEvent)) {
  5335. map.delete(key);
  5336. }
  5337. }
  5338. function replayUnblockedEvents() {
  5339. hasScheduledReplayAttempt = false;
  5340. if (queuedFocus !== null && attemptReplayContinuousQueuedEvent(queuedFocus)) {
  5341. queuedFocus = null;
  5342. }
  5343. if (queuedDrag !== null && attemptReplayContinuousQueuedEvent(queuedDrag)) {
  5344. queuedDrag = null;
  5345. }
  5346. if (queuedMouse !== null && attemptReplayContinuousQueuedEvent(queuedMouse)) {
  5347. queuedMouse = null;
  5348. }
  5349. queuedPointers.forEach(attemptReplayContinuousQueuedEventInMap);
  5350. queuedPointerCaptures.forEach(attemptReplayContinuousQueuedEventInMap);
  5351. }
  5352. function scheduleCallbackIfUnblocked(queuedEvent, unblocked) {
  5353. if (queuedEvent.blockedOn === unblocked) {
  5354. queuedEvent.blockedOn = null;
  5355. if (!hasScheduledReplayAttempt) {
  5356. hasScheduledReplayAttempt = true; // Schedule a callback to attempt replaying as many events as are
  5357. // now unblocked. This first might not actually be unblocked yet.
  5358. // We could check it early to avoid scheduling an unnecessary callback.
  5359. Scheduler.unstable_scheduleCallback(Scheduler.unstable_NormalPriority, replayUnblockedEvents);
  5360. }
  5361. }
  5362. }
  5363. function retryIfBlockedOn(unblocked) {
  5364. // Mark anything that was blocked on this as no longer blocked
  5365. // and eligible for a replay.
  5366. if (queuedDiscreteEvents.length > 0) {
  5367. scheduleCallbackIfUnblocked(queuedDiscreteEvents[0], unblocked); // This is a exponential search for each boundary that commits. I think it's
  5368. // worth it because we expect very few discrete events to queue up and once
  5369. // we are actually fully unblocked it will be fast to replay them.
  5370. for (var i = 1; i < queuedDiscreteEvents.length; i++) {
  5371. var queuedEvent = queuedDiscreteEvents[i];
  5372. if (queuedEvent.blockedOn === unblocked) {
  5373. queuedEvent.blockedOn = null;
  5374. }
  5375. }
  5376. }
  5377. if (queuedFocus !== null) {
  5378. scheduleCallbackIfUnblocked(queuedFocus, unblocked);
  5379. }
  5380. if (queuedDrag !== null) {
  5381. scheduleCallbackIfUnblocked(queuedDrag, unblocked);
  5382. }
  5383. if (queuedMouse !== null) {
  5384. scheduleCallbackIfUnblocked(queuedMouse, unblocked);
  5385. }
  5386. var unblock = function (queuedEvent) {
  5387. return scheduleCallbackIfUnblocked(queuedEvent, unblocked);
  5388. };
  5389. queuedPointers.forEach(unblock);
  5390. queuedPointerCaptures.forEach(unblock);
  5391. for (var _i = 0; _i < queuedExplicitHydrationTargets.length; _i++) {
  5392. var queuedTarget = queuedExplicitHydrationTargets[_i];
  5393. if (queuedTarget.blockedOn === unblocked) {
  5394. queuedTarget.blockedOn = null;
  5395. }
  5396. }
  5397. while (queuedExplicitHydrationTargets.length > 0) {
  5398. var nextExplicitTarget = queuedExplicitHydrationTargets[0];
  5399. if (nextExplicitTarget.blockedOn !== null) {
  5400. // We're still blocked.
  5401. break;
  5402. } else {
  5403. attemptExplicitHydrationTarget(nextExplicitTarget);
  5404. if (nextExplicitTarget.blockedOn === null) {
  5405. // We're unblocked.
  5406. queuedExplicitHydrationTargets.shift();
  5407. }
  5408. }
  5409. }
  5410. }
  5411. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig; // TODO: can we stop exporting these?
  5412. var _enabled = true; // This is exported in FB builds for use by legacy FB layer infra.
  5413. // We'd like to remove this but it's not clear if this is safe.
  5414. function setEnabled(enabled) {
  5415. _enabled = !!enabled;
  5416. }
  5417. function isEnabled() {
  5418. return _enabled;
  5419. }
  5420. function createEventListenerWrapperWithPriority(targetContainer, domEventName, eventSystemFlags) {
  5421. var eventPriority = getEventPriority(domEventName);
  5422. var listenerWrapper;
  5423. switch (eventPriority) {
  5424. case DiscreteEventPriority:
  5425. listenerWrapper = dispatchDiscreteEvent;
  5426. break;
  5427. case ContinuousEventPriority:
  5428. listenerWrapper = dispatchContinuousEvent;
  5429. break;
  5430. case DefaultEventPriority:
  5431. default:
  5432. listenerWrapper = dispatchEvent;
  5433. break;
  5434. }
  5435. return listenerWrapper.bind(null, domEventName, eventSystemFlags, targetContainer);
  5436. }
  5437. function dispatchDiscreteEvent(domEventName, eventSystemFlags, container, nativeEvent) {
  5438. var previousPriority = getCurrentUpdatePriority();
  5439. var prevTransition = ReactCurrentBatchConfig.transition;
  5440. ReactCurrentBatchConfig.transition = null;
  5441. try {
  5442. setCurrentUpdatePriority(DiscreteEventPriority);
  5443. dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
  5444. } finally {
  5445. setCurrentUpdatePriority(previousPriority);
  5446. ReactCurrentBatchConfig.transition = prevTransition;
  5447. }
  5448. }
  5449. function dispatchContinuousEvent(domEventName, eventSystemFlags, container, nativeEvent) {
  5450. var previousPriority = getCurrentUpdatePriority();
  5451. var prevTransition = ReactCurrentBatchConfig.transition;
  5452. ReactCurrentBatchConfig.transition = null;
  5453. try {
  5454. setCurrentUpdatePriority(ContinuousEventPriority);
  5455. dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
  5456. } finally {
  5457. setCurrentUpdatePriority(previousPriority);
  5458. ReactCurrentBatchConfig.transition = prevTransition;
  5459. }
  5460. }
  5461. function dispatchEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  5462. if (!_enabled) {
  5463. return;
  5464. }
  5465. {
  5466. dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay(domEventName, eventSystemFlags, targetContainer, nativeEvent);
  5467. }
  5468. }
  5469. function dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay(domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  5470. var blockedOn = findInstanceBlockingEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent);
  5471. if (blockedOn === null) {
  5472. dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, return_targetInst, targetContainer);
  5473. clearIfContinuousEvent(domEventName, nativeEvent);
  5474. return;
  5475. }
  5476. if (queueIfContinuousEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent)) {
  5477. nativeEvent.stopPropagation();
  5478. return;
  5479. } // We need to clear only if we didn't queue because
  5480. // queueing is accumulative.
  5481. clearIfContinuousEvent(domEventName, nativeEvent);
  5482. if (eventSystemFlags & IS_CAPTURE_PHASE && isDiscreteEventThatRequiresHydration(domEventName)) {
  5483. while (blockedOn !== null) {
  5484. var fiber = getInstanceFromNode(blockedOn);
  5485. if (fiber !== null) {
  5486. attemptSynchronousHydration(fiber);
  5487. }
  5488. var nextBlockedOn = findInstanceBlockingEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent);
  5489. if (nextBlockedOn === null) {
  5490. dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, return_targetInst, targetContainer);
  5491. }
  5492. if (nextBlockedOn === blockedOn) {
  5493. break;
  5494. }
  5495. blockedOn = nextBlockedOn;
  5496. }
  5497. if (blockedOn !== null) {
  5498. nativeEvent.stopPropagation();
  5499. }
  5500. return;
  5501. } // This is not replayable so we'll invoke it but without a target,
  5502. // in case the event system needs to trace it.
  5503. dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, null, targetContainer);
  5504. }
  5505. var return_targetInst = null; // Returns a SuspenseInstance or Container if it's blocked.
  5506. // The return_targetInst field above is conceptually part of the return value.
  5507. function findInstanceBlockingEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  5508. // TODO: Warn if _enabled is false.
  5509. return_targetInst = null;
  5510. var nativeEventTarget = getEventTarget(nativeEvent);
  5511. var targetInst = getClosestInstanceFromNode(nativeEventTarget);
  5512. if (targetInst !== null) {
  5513. var nearestMounted = getNearestMountedFiber(targetInst);
  5514. if (nearestMounted === null) {
  5515. // This tree has been unmounted already. Dispatch without a target.
  5516. targetInst = null;
  5517. } else {
  5518. var tag = nearestMounted.tag;
  5519. if (tag === SuspenseComponent) {
  5520. var instance = getSuspenseInstanceFromFiber(nearestMounted);
  5521. if (instance !== null) {
  5522. // Queue the event to be replayed later. Abort dispatching since we
  5523. // don't want this event dispatched twice through the event system.
  5524. // TODO: If this is the first discrete event in the queue. Schedule an increased
  5525. // priority for this boundary.
  5526. return instance;
  5527. } // This shouldn't happen, something went wrong but to avoid blocking
  5528. // the whole system, dispatch the event without a target.
  5529. // TODO: Warn.
  5530. targetInst = null;
  5531. } else if (tag === HostRoot) {
  5532. var root = nearestMounted.stateNode;
  5533. if (isRootDehydrated(root)) {
  5534. // If this happens during a replay something went wrong and it might block
  5535. // the whole system.
  5536. return getContainerFromFiber(nearestMounted);
  5537. }
  5538. targetInst = null;
  5539. } else if (nearestMounted !== targetInst) {
  5540. // If we get an event (ex: img onload) before committing that
  5541. // component's mount, ignore it for now (that is, treat it as if it was an
  5542. // event on a non-React tree). We might also consider queueing events and
  5543. // dispatching them after the mount.
  5544. targetInst = null;
  5545. }
  5546. }
  5547. }
  5548. return_targetInst = targetInst; // We're not blocked on anything.
  5549. return null;
  5550. }
  5551. function getEventPriority(domEventName) {
  5552. switch (domEventName) {
  5553. // Used by SimpleEventPlugin:
  5554. case 'cancel':
  5555. case 'click':
  5556. case 'close':
  5557. case 'contextmenu':
  5558. case 'copy':
  5559. case 'cut':
  5560. case 'auxclick':
  5561. case 'dblclick':
  5562. case 'dragend':
  5563. case 'dragstart':
  5564. case 'drop':
  5565. case 'focusin':
  5566. case 'focusout':
  5567. case 'input':
  5568. case 'invalid':
  5569. case 'keydown':
  5570. case 'keypress':
  5571. case 'keyup':
  5572. case 'mousedown':
  5573. case 'mouseup':
  5574. case 'paste':
  5575. case 'pause':
  5576. case 'play':
  5577. case 'pointercancel':
  5578. case 'pointerdown':
  5579. case 'pointerup':
  5580. case 'ratechange':
  5581. case 'reset':
  5582. case 'resize':
  5583. case 'seeked':
  5584. case 'submit':
  5585. case 'touchcancel':
  5586. case 'touchend':
  5587. case 'touchstart':
  5588. case 'volumechange': // Used by polyfills:
  5589. // eslint-disable-next-line no-fallthrough
  5590. case 'change':
  5591. case 'selectionchange':
  5592. case 'textInput':
  5593. case 'compositionstart':
  5594. case 'compositionend':
  5595. case 'compositionupdate': // Only enableCreateEventHandleAPI:
  5596. // eslint-disable-next-line no-fallthrough
  5597. case 'beforeblur':
  5598. case 'afterblur': // Not used by React but could be by user code:
  5599. // eslint-disable-next-line no-fallthrough
  5600. case 'beforeinput':
  5601. case 'blur':
  5602. case 'fullscreenchange':
  5603. case 'focus':
  5604. case 'hashchange':
  5605. case 'popstate':
  5606. case 'select':
  5607. case 'selectstart':
  5608. return DiscreteEventPriority;
  5609. case 'drag':
  5610. case 'dragenter':
  5611. case 'dragexit':
  5612. case 'dragleave':
  5613. case 'dragover':
  5614. case 'mousemove':
  5615. case 'mouseout':
  5616. case 'mouseover':
  5617. case 'pointermove':
  5618. case 'pointerout':
  5619. case 'pointerover':
  5620. case 'scroll':
  5621. case 'toggle':
  5622. case 'touchmove':
  5623. case 'wheel': // Not used by React but could be by user code:
  5624. // eslint-disable-next-line no-fallthrough
  5625. case 'mouseenter':
  5626. case 'mouseleave':
  5627. case 'pointerenter':
  5628. case 'pointerleave':
  5629. return ContinuousEventPriority;
  5630. case 'message':
  5631. {
  5632. // We might be in the Scheduler callback.
  5633. // Eventually this mechanism will be replaced by a check
  5634. // of the current priority on the native scheduler.
  5635. var schedulerPriority = getCurrentPriorityLevel();
  5636. switch (schedulerPriority) {
  5637. case ImmediatePriority:
  5638. return DiscreteEventPriority;
  5639. case UserBlockingPriority:
  5640. return ContinuousEventPriority;
  5641. case NormalPriority:
  5642. case LowPriority:
  5643. // TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
  5644. return DefaultEventPriority;
  5645. case IdlePriority:
  5646. return IdleEventPriority;
  5647. default:
  5648. return DefaultEventPriority;
  5649. }
  5650. }
  5651. default:
  5652. return DefaultEventPriority;
  5653. }
  5654. }
  5655. function addEventBubbleListener(target, eventType, listener) {
  5656. target.addEventListener(eventType, listener, false);
  5657. return listener;
  5658. }
  5659. function addEventCaptureListener(target, eventType, listener) {
  5660. target.addEventListener(eventType, listener, true);
  5661. return listener;
  5662. }
  5663. function addEventCaptureListenerWithPassiveFlag(target, eventType, listener, passive) {
  5664. target.addEventListener(eventType, listener, {
  5665. capture: true,
  5666. passive: passive
  5667. });
  5668. return listener;
  5669. }
  5670. function addEventBubbleListenerWithPassiveFlag(target, eventType, listener, passive) {
  5671. target.addEventListener(eventType, listener, {
  5672. passive: passive
  5673. });
  5674. return listener;
  5675. }
  5676. /**
  5677. * These variables store information about text content of a target node,
  5678. * allowing comparison of content before and after a given event.
  5679. *
  5680. * Identify the node where selection currently begins, then observe
  5681. * both its text content and its current position in the DOM. Since the
  5682. * browser may natively replace the target node during composition, we can
  5683. * use its position to find its replacement.
  5684. *
  5685. *
  5686. */
  5687. var root = null;
  5688. var startText = null;
  5689. var fallbackText = null;
  5690. function initialize(nativeEventTarget) {
  5691. root = nativeEventTarget;
  5692. startText = getText();
  5693. return true;
  5694. }
  5695. function reset() {
  5696. root = null;
  5697. startText = null;
  5698. fallbackText = null;
  5699. }
  5700. function getData() {
  5701. if (fallbackText) {
  5702. return fallbackText;
  5703. }
  5704. var start;
  5705. var startValue = startText;
  5706. var startLength = startValue.length;
  5707. var end;
  5708. var endValue = getText();
  5709. var endLength = endValue.length;
  5710. for (start = 0; start < startLength; start++) {
  5711. if (startValue[start] !== endValue[start]) {
  5712. break;
  5713. }
  5714. }
  5715. var minEnd = startLength - start;
  5716. for (end = 1; end <= minEnd; end++) {
  5717. if (startValue[startLength - end] !== endValue[endLength - end]) {
  5718. break;
  5719. }
  5720. }
  5721. var sliceTail = end > 1 ? 1 - end : undefined;
  5722. fallbackText = endValue.slice(start, sliceTail);
  5723. return fallbackText;
  5724. }
  5725. function getText() {
  5726. if ('value' in root) {
  5727. return root.value;
  5728. }
  5729. return root.textContent;
  5730. }
  5731. /**
  5732. * `charCode` represents the actual "character code" and is safe to use with
  5733. * `String.fromCharCode`. As such, only keys that correspond to printable
  5734. * characters produce a valid `charCode`, the only exception to this is Enter.
  5735. * The Tab-key is considered non-printable and does not have a `charCode`,
  5736. * presumably because it does not produce a tab-character in browsers.
  5737. *
  5738. * @param {object} nativeEvent Native browser event.
  5739. * @return {number} Normalized `charCode` property.
  5740. */
  5741. function getEventCharCode(nativeEvent) {
  5742. var charCode;
  5743. var keyCode = nativeEvent.keyCode;
  5744. if ('charCode' in nativeEvent) {
  5745. charCode = nativeEvent.charCode; // FF does not set `charCode` for the Enter-key, check against `keyCode`.
  5746. if (charCode === 0 && keyCode === 13) {
  5747. charCode = 13;
  5748. }
  5749. } else {
  5750. // IE8 does not implement `charCode`, but `keyCode` has the correct value.
  5751. charCode = keyCode;
  5752. } // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
  5753. // report Enter as charCode 10 when ctrl is pressed.
  5754. if (charCode === 10) {
  5755. charCode = 13;
  5756. } // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
  5757. // Must not discard the (non-)printable Enter-key.
  5758. if (charCode >= 32 || charCode === 13) {
  5759. return charCode;
  5760. }
  5761. return 0;
  5762. }
  5763. function functionThatReturnsTrue() {
  5764. return true;
  5765. }
  5766. function functionThatReturnsFalse() {
  5767. return false;
  5768. } // This is intentionally a factory so that we have different returned constructors.
  5769. // If we had a single constructor, it would be megamorphic and engines would deopt.
  5770. function createSyntheticEvent(Interface) {
  5771. /**
  5772. * Synthetic events are dispatched by event plugins, typically in response to a
  5773. * top-level event delegation handler.
  5774. *
  5775. * These systems should generally use pooling to reduce the frequency of garbage
  5776. * collection. The system should check `isPersistent` to determine whether the
  5777. * event should be released into the pool after being dispatched. Users that
  5778. * need a persisted event should invoke `persist`.
  5779. *
  5780. * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
  5781. * normalizing browser quirks. Subclasses do not necessarily have to implement a
  5782. * DOM interface; custom application-specific events can also subclass this.
  5783. */
  5784. function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) {
  5785. this._reactName = reactName;
  5786. this._targetInst = targetInst;
  5787. this.type = reactEventType;
  5788. this.nativeEvent = nativeEvent;
  5789. this.target = nativeEventTarget;
  5790. this.currentTarget = null;
  5791. for (var _propName in Interface) {
  5792. if (!Interface.hasOwnProperty(_propName)) {
  5793. continue;
  5794. }
  5795. var normalize = Interface[_propName];
  5796. if (normalize) {
  5797. this[_propName] = normalize(nativeEvent);
  5798. } else {
  5799. this[_propName] = nativeEvent[_propName];
  5800. }
  5801. }
  5802. var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
  5803. if (defaultPrevented) {
  5804. this.isDefaultPrevented = functionThatReturnsTrue;
  5805. } else {
  5806. this.isDefaultPrevented = functionThatReturnsFalse;
  5807. }
  5808. this.isPropagationStopped = functionThatReturnsFalse;
  5809. return this;
  5810. }
  5811. assign(SyntheticBaseEvent.prototype, {
  5812. preventDefault: function () {
  5813. this.defaultPrevented = true;
  5814. var event = this.nativeEvent;
  5815. if (!event) {
  5816. return;
  5817. }
  5818. if (event.preventDefault) {
  5819. event.preventDefault(); // $FlowFixMe - flow is not aware of `unknown` in IE
  5820. } else if (typeof event.returnValue !== 'unknown') {
  5821. event.returnValue = false;
  5822. }
  5823. this.isDefaultPrevented = functionThatReturnsTrue;
  5824. },
  5825. stopPropagation: function () {
  5826. var event = this.nativeEvent;
  5827. if (!event) {
  5828. return;
  5829. }
  5830. if (event.stopPropagation) {
  5831. event.stopPropagation(); // $FlowFixMe - flow is not aware of `unknown` in IE
  5832. } else if (typeof event.cancelBubble !== 'unknown') {
  5833. // The ChangeEventPlugin registers a "propertychange" event for
  5834. // IE. This event does not support bubbling or cancelling, and
  5835. // any references to cancelBubble throw "Member not found". A
  5836. // typeof check of "unknown" circumvents this issue (and is also
  5837. // IE specific).
  5838. event.cancelBubble = true;
  5839. }
  5840. this.isPropagationStopped = functionThatReturnsTrue;
  5841. },
  5842. /**
  5843. * We release all dispatched `SyntheticEvent`s after each event loop, adding
  5844. * them back into the pool. This allows a way to hold onto a reference that
  5845. * won't be added back into the pool.
  5846. */
  5847. persist: function () {// Modern event system doesn't use pooling.
  5848. },
  5849. /**
  5850. * Checks if this event should be released back into the pool.
  5851. *
  5852. * @return {boolean} True if this should not be released, false otherwise.
  5853. */
  5854. isPersistent: functionThatReturnsTrue
  5855. });
  5856. return SyntheticBaseEvent;
  5857. }
  5858. /**
  5859. * @interface Event
  5860. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5861. */
  5862. var EventInterface = {
  5863. eventPhase: 0,
  5864. bubbles: 0,
  5865. cancelable: 0,
  5866. timeStamp: function (event) {
  5867. return event.timeStamp || Date.now();
  5868. },
  5869. defaultPrevented: 0,
  5870. isTrusted: 0
  5871. };
  5872. var SyntheticEvent = createSyntheticEvent(EventInterface);
  5873. var UIEventInterface = assign({}, EventInterface, {
  5874. view: 0,
  5875. detail: 0
  5876. });
  5877. var SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
  5878. var lastMovementX;
  5879. var lastMovementY;
  5880. var lastMouseEvent;
  5881. function updateMouseMovementPolyfillState(event) {
  5882. if (event !== lastMouseEvent) {
  5883. if (lastMouseEvent && event.type === 'mousemove') {
  5884. lastMovementX = event.screenX - lastMouseEvent.screenX;
  5885. lastMovementY = event.screenY - lastMouseEvent.screenY;
  5886. } else {
  5887. lastMovementX = 0;
  5888. lastMovementY = 0;
  5889. }
  5890. lastMouseEvent = event;
  5891. }
  5892. }
  5893. /**
  5894. * @interface MouseEvent
  5895. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5896. */
  5897. var MouseEventInterface = assign({}, UIEventInterface, {
  5898. screenX: 0,
  5899. screenY: 0,
  5900. clientX: 0,
  5901. clientY: 0,
  5902. pageX: 0,
  5903. pageY: 0,
  5904. ctrlKey: 0,
  5905. shiftKey: 0,
  5906. altKey: 0,
  5907. metaKey: 0,
  5908. getModifierState: getEventModifierState,
  5909. button: 0,
  5910. buttons: 0,
  5911. relatedTarget: function (event) {
  5912. if (event.relatedTarget === undefined) return event.fromElement === event.srcElement ? event.toElement : event.fromElement;
  5913. return event.relatedTarget;
  5914. },
  5915. movementX: function (event) {
  5916. if ('movementX' in event) {
  5917. return event.movementX;
  5918. }
  5919. updateMouseMovementPolyfillState(event);
  5920. return lastMovementX;
  5921. },
  5922. movementY: function (event) {
  5923. if ('movementY' in event) {
  5924. return event.movementY;
  5925. } // Don't need to call updateMouseMovementPolyfillState() here
  5926. // because it's guaranteed to have already run when movementX
  5927. // was copied.
  5928. return lastMovementY;
  5929. }
  5930. });
  5931. var SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
  5932. /**
  5933. * @interface DragEvent
  5934. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5935. */
  5936. var DragEventInterface = assign({}, MouseEventInterface, {
  5937. dataTransfer: 0
  5938. });
  5939. var SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
  5940. /**
  5941. * @interface FocusEvent
  5942. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5943. */
  5944. var FocusEventInterface = assign({}, UIEventInterface, {
  5945. relatedTarget: 0
  5946. });
  5947. var SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
  5948. /**
  5949. * @interface Event
  5950. * @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
  5951. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
  5952. */
  5953. var AnimationEventInterface = assign({}, EventInterface, {
  5954. animationName: 0,
  5955. elapsedTime: 0,
  5956. pseudoElement: 0
  5957. });
  5958. var SyntheticAnimationEvent = createSyntheticEvent(AnimationEventInterface);
  5959. /**
  5960. * @interface Event
  5961. * @see http://www.w3.org/TR/clipboard-apis/
  5962. */
  5963. var ClipboardEventInterface = assign({}, EventInterface, {
  5964. clipboardData: function (event) {
  5965. return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
  5966. }
  5967. });
  5968. var SyntheticClipboardEvent = createSyntheticEvent(ClipboardEventInterface);
  5969. /**
  5970. * @interface Event
  5971. * @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
  5972. */
  5973. var CompositionEventInterface = assign({}, EventInterface, {
  5974. data: 0
  5975. });
  5976. var SyntheticCompositionEvent = createSyntheticEvent(CompositionEventInterface);
  5977. /**
  5978. * @interface Event
  5979. * @see http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105
  5980. * /#events-inputevents
  5981. */
  5982. // Happens to share the same list for now.
  5983. var SyntheticInputEvent = SyntheticCompositionEvent;
  5984. /**
  5985. * Normalization of deprecated HTML5 `key` values
  5986. * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
  5987. */
  5988. var normalizeKey = {
  5989. Esc: 'Escape',
  5990. Spacebar: ' ',
  5991. Left: 'ArrowLeft',
  5992. Up: 'ArrowUp',
  5993. Right: 'ArrowRight',
  5994. Down: 'ArrowDown',
  5995. Del: 'Delete',
  5996. Win: 'OS',
  5997. Menu: 'ContextMenu',
  5998. Apps: 'ContextMenu',
  5999. Scroll: 'ScrollLock',
  6000. MozPrintableKey: 'Unidentified'
  6001. };
  6002. /**
  6003. * Translation from legacy `keyCode` to HTML5 `key`
  6004. * Only special keys supported, all others depend on keyboard layout or browser
  6005. * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
  6006. */
  6007. var translateToKey = {
  6008. '8': 'Backspace',
  6009. '9': 'Tab',
  6010. '12': 'Clear',
  6011. '13': 'Enter',
  6012. '16': 'Shift',
  6013. '17': 'Control',
  6014. '18': 'Alt',
  6015. '19': 'Pause',
  6016. '20': 'CapsLock',
  6017. '27': 'Escape',
  6018. '32': ' ',
  6019. '33': 'PageUp',
  6020. '34': 'PageDown',
  6021. '35': 'End',
  6022. '36': 'Home',
  6023. '37': 'ArrowLeft',
  6024. '38': 'ArrowUp',
  6025. '39': 'ArrowRight',
  6026. '40': 'ArrowDown',
  6027. '45': 'Insert',
  6028. '46': 'Delete',
  6029. '112': 'F1',
  6030. '113': 'F2',
  6031. '114': 'F3',
  6032. '115': 'F4',
  6033. '116': 'F5',
  6034. '117': 'F6',
  6035. '118': 'F7',
  6036. '119': 'F8',
  6037. '120': 'F9',
  6038. '121': 'F10',
  6039. '122': 'F11',
  6040. '123': 'F12',
  6041. '144': 'NumLock',
  6042. '145': 'ScrollLock',
  6043. '224': 'Meta'
  6044. };
  6045. /**
  6046. * @param {object} nativeEvent Native browser event.
  6047. * @return {string} Normalized `key` property.
  6048. */
  6049. function getEventKey(nativeEvent) {
  6050. if (nativeEvent.key) {
  6051. // Normalize inconsistent values reported by browsers due to
  6052. // implementations of a working draft specification.
  6053. // FireFox implements `key` but returns `MozPrintableKey` for all
  6054. // printable characters (normalized to `Unidentified`), ignore it.
  6055. var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
  6056. if (key !== 'Unidentified') {
  6057. return key;
  6058. }
  6059. } // Browser does not implement `key`, polyfill as much of it as we can.
  6060. if (nativeEvent.type === 'keypress') {
  6061. var charCode = getEventCharCode(nativeEvent); // The enter-key is technically both printable and non-printable and can
  6062. // thus be captured by `keypress`, no other non-printable key should.
  6063. return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
  6064. }
  6065. if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
  6066. // While user keyboard layout determines the actual meaning of each
  6067. // `keyCode` value, almost all function keys have a universal value.
  6068. return translateToKey[nativeEvent.keyCode] || 'Unidentified';
  6069. }
  6070. return '';
  6071. }
  6072. /**
  6073. * Translation from modifier key to the associated property in the event.
  6074. * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
  6075. */
  6076. var modifierKeyToProp = {
  6077. Alt: 'altKey',
  6078. Control: 'ctrlKey',
  6079. Meta: 'metaKey',
  6080. Shift: 'shiftKey'
  6081. }; // Older browsers (Safari <= 10, iOS Safari <= 10.2) do not support
  6082. // getModifierState. If getModifierState is not supported, we map it to a set of
  6083. // modifier keys exposed by the event. In this case, Lock-keys are not supported.
  6084. function modifierStateGetter(keyArg) {
  6085. var syntheticEvent = this;
  6086. var nativeEvent = syntheticEvent.nativeEvent;
  6087. if (nativeEvent.getModifierState) {
  6088. return nativeEvent.getModifierState(keyArg);
  6089. }
  6090. var keyProp = modifierKeyToProp[keyArg];
  6091. return keyProp ? !!nativeEvent[keyProp] : false;
  6092. }
  6093. function getEventModifierState(nativeEvent) {
  6094. return modifierStateGetter;
  6095. }
  6096. /**
  6097. * @interface KeyboardEvent
  6098. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  6099. */
  6100. var KeyboardEventInterface = assign({}, UIEventInterface, {
  6101. key: getEventKey,
  6102. code: 0,
  6103. location: 0,
  6104. ctrlKey: 0,
  6105. shiftKey: 0,
  6106. altKey: 0,
  6107. metaKey: 0,
  6108. repeat: 0,
  6109. locale: 0,
  6110. getModifierState: getEventModifierState,
  6111. // Legacy Interface
  6112. charCode: function (event) {
  6113. // `charCode` is the result of a KeyPress event and represents the value of
  6114. // the actual printable character.
  6115. // KeyPress is deprecated, but its replacement is not yet final and not
  6116. // implemented in any major browser. Only KeyPress has charCode.
  6117. if (event.type === 'keypress') {
  6118. return getEventCharCode(event);
  6119. }
  6120. return 0;
  6121. },
  6122. keyCode: function (event) {
  6123. // `keyCode` is the result of a KeyDown/Up event and represents the value of
  6124. // physical keyboard key.
  6125. // The actual meaning of the value depends on the users' keyboard layout
  6126. // which cannot be detected. Assuming that it is a US keyboard layout
  6127. // provides a surprisingly accurate mapping for US and European users.
  6128. // Due to this, it is left to the user to implement at this time.
  6129. if (event.type === 'keydown' || event.type === 'keyup') {
  6130. return event.keyCode;
  6131. }
  6132. return 0;
  6133. },
  6134. which: function (event) {
  6135. // `which` is an alias for either `keyCode` or `charCode` depending on the
  6136. // type of the event.
  6137. if (event.type === 'keypress') {
  6138. return getEventCharCode(event);
  6139. }
  6140. if (event.type === 'keydown' || event.type === 'keyup') {
  6141. return event.keyCode;
  6142. }
  6143. return 0;
  6144. }
  6145. });
  6146. var SyntheticKeyboardEvent = createSyntheticEvent(KeyboardEventInterface);
  6147. /**
  6148. * @interface PointerEvent
  6149. * @see http://www.w3.org/TR/pointerevents/
  6150. */
  6151. var PointerEventInterface = assign({}, MouseEventInterface, {
  6152. pointerId: 0,
  6153. width: 0,
  6154. height: 0,
  6155. pressure: 0,
  6156. tangentialPressure: 0,
  6157. tiltX: 0,
  6158. tiltY: 0,
  6159. twist: 0,
  6160. pointerType: 0,
  6161. isPrimary: 0
  6162. });
  6163. var SyntheticPointerEvent = createSyntheticEvent(PointerEventInterface);
  6164. /**
  6165. * @interface TouchEvent
  6166. * @see http://www.w3.org/TR/touch-events/
  6167. */
  6168. var TouchEventInterface = assign({}, UIEventInterface, {
  6169. touches: 0,
  6170. targetTouches: 0,
  6171. changedTouches: 0,
  6172. altKey: 0,
  6173. metaKey: 0,
  6174. ctrlKey: 0,
  6175. shiftKey: 0,
  6176. getModifierState: getEventModifierState
  6177. });
  6178. var SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
  6179. /**
  6180. * @interface Event
  6181. * @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
  6182. * @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
  6183. */
  6184. var TransitionEventInterface = assign({}, EventInterface, {
  6185. propertyName: 0,
  6186. elapsedTime: 0,
  6187. pseudoElement: 0
  6188. });
  6189. var SyntheticTransitionEvent = createSyntheticEvent(TransitionEventInterface);
  6190. /**
  6191. * @interface WheelEvent
  6192. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  6193. */
  6194. var WheelEventInterface = assign({}, MouseEventInterface, {
  6195. deltaX: function (event) {
  6196. return 'deltaX' in event ? event.deltaX : // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
  6197. 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
  6198. },
  6199. deltaY: function (event) {
  6200. return 'deltaY' in event ? event.deltaY : // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
  6201. 'wheelDeltaY' in event ? -event.wheelDeltaY : // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
  6202. 'wheelDelta' in event ? -event.wheelDelta : 0;
  6203. },
  6204. deltaZ: 0,
  6205. // Browsers without "deltaMode" is reporting in raw wheel delta where one
  6206. // notch on the scroll is always +/- 120, roughly equivalent to pixels.
  6207. // A good approximation of DOM_DELTA_LINE (1) is 5% of viewport size or
  6208. // ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
  6209. deltaMode: 0
  6210. });
  6211. var SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
  6212. var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
  6213. var START_KEYCODE = 229;
  6214. var canUseCompositionEvent = canUseDOM && 'CompositionEvent' in window;
  6215. var documentMode = null;
  6216. if (canUseDOM && 'documentMode' in document) {
  6217. documentMode = document.documentMode;
  6218. } // Webkit offers a very useful `textInput` event that can be used to
  6219. // directly represent `beforeInput`. The IE `textinput` event is not as
  6220. // useful, so we don't use it.
  6221. var canUseTextInputEvent = canUseDOM && 'TextEvent' in window && !documentMode; // In IE9+, we have access to composition events, but the data supplied
  6222. // by the native compositionend event may be incorrect. Japanese ideographic
  6223. // spaces, for instance (\u3000) are not recorded correctly.
  6224. var useFallbackCompositionData = canUseDOM && (!canUseCompositionEvent || documentMode && documentMode > 8 && documentMode <= 11);
  6225. var SPACEBAR_CODE = 32;
  6226. var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE);
  6227. function registerEvents() {
  6228. registerTwoPhaseEvent('onBeforeInput', ['compositionend', 'keypress', 'textInput', 'paste']);
  6229. registerTwoPhaseEvent('onCompositionEnd', ['compositionend', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']);
  6230. registerTwoPhaseEvent('onCompositionStart', ['compositionstart', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']);
  6231. registerTwoPhaseEvent('onCompositionUpdate', ['compositionupdate', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']);
  6232. } // Track whether we've ever handled a keypress on the space key.
  6233. var hasSpaceKeypress = false;
  6234. /**
  6235. * Return whether a native keypress event is assumed to be a command.
  6236. * This is required because Firefox fires `keypress` events for key commands
  6237. * (cut, copy, select-all, etc.) even though no character is inserted.
  6238. */
  6239. function isKeypressCommand(nativeEvent) {
  6240. return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) && // ctrlKey && altKey is equivalent to AltGr, and is not a command.
  6241. !(nativeEvent.ctrlKey && nativeEvent.altKey);
  6242. }
  6243. /**
  6244. * Translate native top level events into event types.
  6245. */
  6246. function getCompositionEventType(domEventName) {
  6247. switch (domEventName) {
  6248. case 'compositionstart':
  6249. return 'onCompositionStart';
  6250. case 'compositionend':
  6251. return 'onCompositionEnd';
  6252. case 'compositionupdate':
  6253. return 'onCompositionUpdate';
  6254. }
  6255. }
  6256. /**
  6257. * Does our fallback best-guess model think this event signifies that
  6258. * composition has begun?
  6259. */
  6260. function isFallbackCompositionStart(domEventName, nativeEvent) {
  6261. return domEventName === 'keydown' && nativeEvent.keyCode === START_KEYCODE;
  6262. }
  6263. /**
  6264. * Does our fallback mode think that this event is the end of composition?
  6265. */
  6266. function isFallbackCompositionEnd(domEventName, nativeEvent) {
  6267. switch (domEventName) {
  6268. case 'keyup':
  6269. // Command keys insert or clear IME input.
  6270. return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1;
  6271. case 'keydown':
  6272. // Expect IME keyCode on each keydown. If we get any other
  6273. // code we must have exited earlier.
  6274. return nativeEvent.keyCode !== START_KEYCODE;
  6275. case 'keypress':
  6276. case 'mousedown':
  6277. case 'focusout':
  6278. // Events are not possible without cancelling IME.
  6279. return true;
  6280. default:
  6281. return false;
  6282. }
  6283. }
  6284. /**
  6285. * Google Input Tools provides composition data via a CustomEvent,
  6286. * with the `data` property populated in the `detail` object. If this
  6287. * is available on the event object, use it. If not, this is a plain
  6288. * composition event and we have nothing special to extract.
  6289. *
  6290. * @param {object} nativeEvent
  6291. * @return {?string}
  6292. */
  6293. function getDataFromCustomEvent(nativeEvent) {
  6294. var detail = nativeEvent.detail;
  6295. if (typeof detail === 'object' && 'data' in detail) {
  6296. return detail.data;
  6297. }
  6298. return null;
  6299. }
  6300. /**
  6301. * Check if a composition event was triggered by Korean IME.
  6302. * Our fallback mode does not work well with IE's Korean IME,
  6303. * so just use native composition events when Korean IME is used.
  6304. * Although CompositionEvent.locale property is deprecated,
  6305. * it is available in IE, where our fallback mode is enabled.
  6306. *
  6307. * @param {object} nativeEvent
  6308. * @return {boolean}
  6309. */
  6310. function isUsingKoreanIME(nativeEvent) {
  6311. return nativeEvent.locale === 'ko';
  6312. } // Track the current IME composition status, if any.
  6313. var isComposing = false;
  6314. /**
  6315. * @return {?object} A SyntheticCompositionEvent.
  6316. */
  6317. function extractCompositionEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget) {
  6318. var eventType;
  6319. var fallbackData;
  6320. if (canUseCompositionEvent) {
  6321. eventType = getCompositionEventType(domEventName);
  6322. } else if (!isComposing) {
  6323. if (isFallbackCompositionStart(domEventName, nativeEvent)) {
  6324. eventType = 'onCompositionStart';
  6325. }
  6326. } else if (isFallbackCompositionEnd(domEventName, nativeEvent)) {
  6327. eventType = 'onCompositionEnd';
  6328. }
  6329. if (!eventType) {
  6330. return null;
  6331. }
  6332. if (useFallbackCompositionData && !isUsingKoreanIME(nativeEvent)) {
  6333. // The current composition is stored statically and must not be
  6334. // overwritten while composition continues.
  6335. if (!isComposing && eventType === 'onCompositionStart') {
  6336. isComposing = initialize(nativeEventTarget);
  6337. } else if (eventType === 'onCompositionEnd') {
  6338. if (isComposing) {
  6339. fallbackData = getData();
  6340. }
  6341. }
  6342. }
  6343. var listeners = accumulateTwoPhaseListeners(targetInst, eventType);
  6344. if (listeners.length > 0) {
  6345. var event = new SyntheticCompositionEvent(eventType, domEventName, null, nativeEvent, nativeEventTarget);
  6346. dispatchQueue.push({
  6347. event: event,
  6348. listeners: listeners
  6349. });
  6350. if (fallbackData) {
  6351. // Inject data generated from fallback path into the synthetic event.
  6352. // This matches the property of native CompositionEventInterface.
  6353. event.data = fallbackData;
  6354. } else {
  6355. var customData = getDataFromCustomEvent(nativeEvent);
  6356. if (customData !== null) {
  6357. event.data = customData;
  6358. }
  6359. }
  6360. }
  6361. }
  6362. function getNativeBeforeInputChars(domEventName, nativeEvent) {
  6363. switch (domEventName) {
  6364. case 'compositionend':
  6365. return getDataFromCustomEvent(nativeEvent);
  6366. case 'keypress':
  6367. /**
  6368. * If native `textInput` events are available, our goal is to make
  6369. * use of them. However, there is a special case: the spacebar key.
  6370. * In Webkit, preventing default on a spacebar `textInput` event
  6371. * cancels character insertion, but it *also* causes the browser
  6372. * to fall back to its default spacebar behavior of scrolling the
  6373. * page.
  6374. *
  6375. * Tracking at:
  6376. * https://code.google.com/p/chromium/issues/detail?id=355103
  6377. *
  6378. * To avoid this issue, use the keypress event as if no `textInput`
  6379. * event is available.
  6380. */
  6381. var which = nativeEvent.which;
  6382. if (which !== SPACEBAR_CODE) {
  6383. return null;
  6384. }
  6385. hasSpaceKeypress = true;
  6386. return SPACEBAR_CHAR;
  6387. case 'textInput':
  6388. // Record the characters to be added to the DOM.
  6389. var chars = nativeEvent.data; // If it's a spacebar character, assume that we have already handled
  6390. // it at the keypress level and bail immediately. Android Chrome
  6391. // doesn't give us keycodes, so we need to ignore it.
  6392. if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
  6393. return null;
  6394. }
  6395. return chars;
  6396. default:
  6397. // For other native event types, do nothing.
  6398. return null;
  6399. }
  6400. }
  6401. /**
  6402. * For browsers that do not provide the `textInput` event, extract the
  6403. * appropriate string to use for SyntheticInputEvent.
  6404. */
  6405. function getFallbackBeforeInputChars(domEventName, nativeEvent) {
  6406. // If we are currently composing (IME) and using a fallback to do so,
  6407. // try to extract the composed characters from the fallback object.
  6408. // If composition event is available, we extract a string only at
  6409. // compositionevent, otherwise extract it at fallback events.
  6410. if (isComposing) {
  6411. if (domEventName === 'compositionend' || !canUseCompositionEvent && isFallbackCompositionEnd(domEventName, nativeEvent)) {
  6412. var chars = getData();
  6413. reset();
  6414. isComposing = false;
  6415. return chars;
  6416. }
  6417. return null;
  6418. }
  6419. switch (domEventName) {
  6420. case 'paste':
  6421. // If a paste event occurs after a keypress, throw out the input
  6422. // chars. Paste events should not lead to BeforeInput events.
  6423. return null;
  6424. case 'keypress':
  6425. /**
  6426. * As of v27, Firefox may fire keypress events even when no character
  6427. * will be inserted. A few possibilities:
  6428. *
  6429. * - `which` is `0`. Arrow keys, Esc key, etc.
  6430. *
  6431. * - `which` is the pressed key code, but no char is available.
  6432. * Ex: 'AltGr + d` in Polish. There is no modified character for
  6433. * this key combination and no character is inserted into the
  6434. * document, but FF fires the keypress for char code `100` anyway.
  6435. * No `input` event will occur.
  6436. *
  6437. * - `which` is the pressed key code, but a command combination is
  6438. * being used. Ex: `Cmd+C`. No character is inserted, and no
  6439. * `input` event will occur.
  6440. */
  6441. if (!isKeypressCommand(nativeEvent)) {
  6442. // IE fires the `keypress` event when a user types an emoji via
  6443. // Touch keyboard of Windows. In such a case, the `char` property
  6444. // holds an emoji character like `\uD83D\uDE0A`. Because its length
  6445. // is 2, the property `which` does not represent an emoji correctly.
  6446. // In such a case, we directly return the `char` property instead of
  6447. // using `which`.
  6448. if (nativeEvent.char && nativeEvent.char.length > 1) {
  6449. return nativeEvent.char;
  6450. } else if (nativeEvent.which) {
  6451. return String.fromCharCode(nativeEvent.which);
  6452. }
  6453. }
  6454. return null;
  6455. case 'compositionend':
  6456. return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent) ? null : nativeEvent.data;
  6457. default:
  6458. return null;
  6459. }
  6460. }
  6461. /**
  6462. * Extract a SyntheticInputEvent for `beforeInput`, based on either native
  6463. * `textInput` or fallback behavior.
  6464. *
  6465. * @return {?object} A SyntheticInputEvent.
  6466. */
  6467. function extractBeforeInputEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget) {
  6468. var chars;
  6469. if (canUseTextInputEvent) {
  6470. chars = getNativeBeforeInputChars(domEventName, nativeEvent);
  6471. } else {
  6472. chars = getFallbackBeforeInputChars(domEventName, nativeEvent);
  6473. } // If no characters are being inserted, no BeforeInput event should
  6474. // be fired.
  6475. if (!chars) {
  6476. return null;
  6477. }
  6478. var listeners = accumulateTwoPhaseListeners(targetInst, 'onBeforeInput');
  6479. if (listeners.length > 0) {
  6480. var event = new SyntheticInputEvent('onBeforeInput', 'beforeinput', null, nativeEvent, nativeEventTarget);
  6481. dispatchQueue.push({
  6482. event: event,
  6483. listeners: listeners
  6484. });
  6485. event.data = chars;
  6486. }
  6487. }
  6488. /**
  6489. * Create an `onBeforeInput` event to match
  6490. * http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-inputevents.
  6491. *
  6492. * This event plugin is based on the native `textInput` event
  6493. * available in Chrome, Safari, Opera, and IE. This event fires after
  6494. * `onKeyPress` and `onCompositionEnd`, but before `onInput`.
  6495. *
  6496. * `beforeInput` is spec'd but not implemented in any browsers, and
  6497. * the `input` event does not provide any useful information about what has
  6498. * actually been added, contrary to the spec. Thus, `textInput` is the best
  6499. * available event to identify the characters that have actually been inserted
  6500. * into the target node.
  6501. *
  6502. * This plugin is also responsible for emitting `composition` events, thus
  6503. * allowing us to share composition fallback code for both `beforeInput` and
  6504. * `composition` event types.
  6505. */
  6506. function extractEvents(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6507. extractCompositionEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  6508. extractBeforeInputEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  6509. }
  6510. /**
  6511. * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
  6512. */
  6513. var supportedInputTypes = {
  6514. color: true,
  6515. date: true,
  6516. datetime: true,
  6517. 'datetime-local': true,
  6518. email: true,
  6519. month: true,
  6520. number: true,
  6521. password: true,
  6522. range: true,
  6523. search: true,
  6524. tel: true,
  6525. text: true,
  6526. time: true,
  6527. url: true,
  6528. week: true
  6529. };
  6530. function isTextInputElement(elem) {
  6531. var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
  6532. if (nodeName === 'input') {
  6533. return !!supportedInputTypes[elem.type];
  6534. }
  6535. if (nodeName === 'textarea') {
  6536. return true;
  6537. }
  6538. return false;
  6539. }
  6540. /**
  6541. * Checks if an event is supported in the current execution environment.
  6542. *
  6543. * NOTE: This will not work correctly for non-generic events such as `change`,
  6544. * `reset`, `load`, `error`, and `select`.
  6545. *
  6546. * Borrows from Modernizr.
  6547. *
  6548. * @param {string} eventNameSuffix Event name, e.g. "click".
  6549. * @return {boolean} True if the event is supported.
  6550. * @internal
  6551. * @license Modernizr 3.0.0pre (Custom Build) | MIT
  6552. */
  6553. function isEventSupported(eventNameSuffix) {
  6554. if (!canUseDOM) {
  6555. return false;
  6556. }
  6557. var eventName = 'on' + eventNameSuffix;
  6558. var isSupported = (eventName in document);
  6559. if (!isSupported) {
  6560. var element = document.createElement('div');
  6561. element.setAttribute(eventName, 'return;');
  6562. isSupported = typeof element[eventName] === 'function';
  6563. }
  6564. return isSupported;
  6565. }
  6566. function registerEvents$1() {
  6567. registerTwoPhaseEvent('onChange', ['change', 'click', 'focusin', 'focusout', 'input', 'keydown', 'keyup', 'selectionchange']);
  6568. }
  6569. function createAndAccumulateChangeEvent(dispatchQueue, inst, nativeEvent, target) {
  6570. // Flag this event loop as needing state restore.
  6571. enqueueStateRestore(target);
  6572. var listeners = accumulateTwoPhaseListeners(inst, 'onChange');
  6573. if (listeners.length > 0) {
  6574. var event = new SyntheticEvent('onChange', 'change', null, nativeEvent, target);
  6575. dispatchQueue.push({
  6576. event: event,
  6577. listeners: listeners
  6578. });
  6579. }
  6580. }
  6581. /**
  6582. * For IE shims
  6583. */
  6584. var activeElement = null;
  6585. var activeElementInst = null;
  6586. /**
  6587. * SECTION: handle `change` event
  6588. */
  6589. function shouldUseChangeEvent(elem) {
  6590. var nodeName = elem.nodeName && elem.nodeName.toLowerCase();
  6591. return nodeName === 'select' || nodeName === 'input' && elem.type === 'file';
  6592. }
  6593. function manualDispatchChangeEvent(nativeEvent) {
  6594. var dispatchQueue = [];
  6595. createAndAccumulateChangeEvent(dispatchQueue, activeElementInst, nativeEvent, getEventTarget(nativeEvent)); // If change and propertychange bubbled, we'd just bind to it like all the
  6596. // other events and have it go through ReactBrowserEventEmitter. Since it
  6597. // doesn't, we manually listen for the events and so we have to enqueue and
  6598. // process the abstract event manually.
  6599. //
  6600. // Batching is necessary here in order to ensure that all event handlers run
  6601. // before the next rerender (including event handlers attached to ancestor
  6602. // elements instead of directly on the input). Without this, controlled
  6603. // components don't work properly in conjunction with event bubbling because
  6604. // the component is rerendered and the value reverted before all the event
  6605. // handlers can run. See https://github.com/facebook/react/issues/708.
  6606. batchedUpdates(runEventInBatch, dispatchQueue);
  6607. }
  6608. function runEventInBatch(dispatchQueue) {
  6609. processDispatchQueue(dispatchQueue, 0);
  6610. }
  6611. function getInstIfValueChanged(targetInst) {
  6612. var targetNode = getNodeFromInstance(targetInst);
  6613. if (updateValueIfChanged(targetNode)) {
  6614. return targetInst;
  6615. }
  6616. }
  6617. function getTargetInstForChangeEvent(domEventName, targetInst) {
  6618. if (domEventName === 'change') {
  6619. return targetInst;
  6620. }
  6621. }
  6622. /**
  6623. * SECTION: handle `input` event
  6624. */
  6625. var isInputEventSupported = false;
  6626. if (canUseDOM) {
  6627. // IE9 claims to support the input event but fails to trigger it when
  6628. // deleting text, so we ignore its input events.
  6629. isInputEventSupported = isEventSupported('input') && (!document.documentMode || document.documentMode > 9);
  6630. }
  6631. /**
  6632. * (For IE <=9) Starts tracking propertychange events on the passed-in element
  6633. * and override the value property so that we can distinguish user events from
  6634. * value changes in JS.
  6635. */
  6636. function startWatchingForValueChange(target, targetInst) {
  6637. activeElement = target;
  6638. activeElementInst = targetInst;
  6639. activeElement.attachEvent('onpropertychange', handlePropertyChange);
  6640. }
  6641. /**
  6642. * (For IE <=9) Removes the event listeners from the currently-tracked element,
  6643. * if any exists.
  6644. */
  6645. function stopWatchingForValueChange() {
  6646. if (!activeElement) {
  6647. return;
  6648. }
  6649. activeElement.detachEvent('onpropertychange', handlePropertyChange);
  6650. activeElement = null;
  6651. activeElementInst = null;
  6652. }
  6653. /**
  6654. * (For IE <=9) Handles a propertychange event, sending a `change` event if
  6655. * the value of the active element has changed.
  6656. */
  6657. function handlePropertyChange(nativeEvent) {
  6658. if (nativeEvent.propertyName !== 'value') {
  6659. return;
  6660. }
  6661. if (getInstIfValueChanged(activeElementInst)) {
  6662. manualDispatchChangeEvent(nativeEvent);
  6663. }
  6664. }
  6665. function handleEventsForInputEventPolyfill(domEventName, target, targetInst) {
  6666. if (domEventName === 'focusin') {
  6667. // In IE9, propertychange fires for most input events but is buggy and
  6668. // doesn't fire when text is deleted, but conveniently, selectionchange
  6669. // appears to fire in all of the remaining cases so we catch those and
  6670. // forward the event if the value has changed
  6671. // In either case, we don't want to call the event handler if the value
  6672. // is changed from JS so we redefine a setter for `.value` that updates
  6673. // our activeElementValue variable, allowing us to ignore those changes
  6674. //
  6675. // stopWatching() should be a noop here but we call it just in case we
  6676. // missed a blur event somehow.
  6677. stopWatchingForValueChange();
  6678. startWatchingForValueChange(target, targetInst);
  6679. } else if (domEventName === 'focusout') {
  6680. stopWatchingForValueChange();
  6681. }
  6682. } // For IE8 and IE9.
  6683. function getTargetInstForInputEventPolyfill(domEventName, targetInst) {
  6684. if (domEventName === 'selectionchange' || domEventName === 'keyup' || domEventName === 'keydown') {
  6685. // On the selectionchange event, the target is just document which isn't
  6686. // helpful for us so just check activeElement instead.
  6687. //
  6688. // 99% of the time, keydown and keyup aren't necessary. IE8 fails to fire
  6689. // propertychange on the first input event after setting `value` from a
  6690. // script and fires only keydown, keypress, keyup. Catching keyup usually
  6691. // gets it and catching keydown lets us fire an event for the first
  6692. // keystroke if user does a key repeat (it'll be a little delayed: right
  6693. // before the second keystroke). Other input methods (e.g., paste) seem to
  6694. // fire selectionchange normally.
  6695. return getInstIfValueChanged(activeElementInst);
  6696. }
  6697. }
  6698. /**
  6699. * SECTION: handle `click` event
  6700. */
  6701. function shouldUseClickEvent(elem) {
  6702. // Use the `click` event to detect changes to checkbox and radio inputs.
  6703. // This approach works across all browsers, whereas `change` does not fire
  6704. // until `blur` in IE8.
  6705. var nodeName = elem.nodeName;
  6706. return nodeName && nodeName.toLowerCase() === 'input' && (elem.type === 'checkbox' || elem.type === 'radio');
  6707. }
  6708. function getTargetInstForClickEvent(domEventName, targetInst) {
  6709. if (domEventName === 'click') {
  6710. return getInstIfValueChanged(targetInst);
  6711. }
  6712. }
  6713. function getTargetInstForInputOrChangeEvent(domEventName, targetInst) {
  6714. if (domEventName === 'input' || domEventName === 'change') {
  6715. return getInstIfValueChanged(targetInst);
  6716. }
  6717. }
  6718. function handleControlledInputBlur(node) {
  6719. var state = node._wrapperState;
  6720. if (!state || !state.controlled || node.type !== 'number') {
  6721. return;
  6722. }
  6723. {
  6724. // If controlled, assign the value attribute to the current value on blur
  6725. setDefaultValue(node, 'number', node.value);
  6726. }
  6727. }
  6728. /**
  6729. * This plugin creates an `onChange` event that normalizes change events
  6730. * across form elements. This event fires at a time when it's possible to
  6731. * change the element's value without seeing a flicker.
  6732. *
  6733. * Supported elements are:
  6734. * - input (see `isTextInputElement`)
  6735. * - textarea
  6736. * - select
  6737. */
  6738. function extractEvents$1(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6739. var targetNode = targetInst ? getNodeFromInstance(targetInst) : window;
  6740. var getTargetInstFunc, handleEventFunc;
  6741. if (shouldUseChangeEvent(targetNode)) {
  6742. getTargetInstFunc = getTargetInstForChangeEvent;
  6743. } else if (isTextInputElement(targetNode)) {
  6744. if (isInputEventSupported) {
  6745. getTargetInstFunc = getTargetInstForInputOrChangeEvent;
  6746. } else {
  6747. getTargetInstFunc = getTargetInstForInputEventPolyfill;
  6748. handleEventFunc = handleEventsForInputEventPolyfill;
  6749. }
  6750. } else if (shouldUseClickEvent(targetNode)) {
  6751. getTargetInstFunc = getTargetInstForClickEvent;
  6752. }
  6753. if (getTargetInstFunc) {
  6754. var inst = getTargetInstFunc(domEventName, targetInst);
  6755. if (inst) {
  6756. createAndAccumulateChangeEvent(dispatchQueue, inst, nativeEvent, nativeEventTarget);
  6757. return;
  6758. }
  6759. }
  6760. if (handleEventFunc) {
  6761. handleEventFunc(domEventName, targetNode, targetInst);
  6762. } // When blurring, set the value attribute for number inputs
  6763. if (domEventName === 'focusout') {
  6764. handleControlledInputBlur(targetNode);
  6765. }
  6766. }
  6767. function registerEvents$2() {
  6768. registerDirectEvent('onMouseEnter', ['mouseout', 'mouseover']);
  6769. registerDirectEvent('onMouseLeave', ['mouseout', 'mouseover']);
  6770. registerDirectEvent('onPointerEnter', ['pointerout', 'pointerover']);
  6771. registerDirectEvent('onPointerLeave', ['pointerout', 'pointerover']);
  6772. }
  6773. /**
  6774. * For almost every interaction we care about, there will be both a top-level
  6775. * `mouseover` and `mouseout` event that occurs. Only use `mouseout` so that
  6776. * we do not extract duplicate events. However, moving the mouse into the
  6777. * browser from outside will not fire a `mouseout` event. In this case, we use
  6778. * the `mouseover` top-level event.
  6779. */
  6780. function extractEvents$2(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6781. var isOverEvent = domEventName === 'mouseover' || domEventName === 'pointerover';
  6782. var isOutEvent = domEventName === 'mouseout' || domEventName === 'pointerout';
  6783. if (isOverEvent && !isReplayingEvent(nativeEvent)) {
  6784. // If this is an over event with a target, we might have already dispatched
  6785. // the event in the out event of the other target. If this is replayed,
  6786. // then it's because we couldn't dispatch against this target previously
  6787. // so we have to do it now instead.
  6788. var related = nativeEvent.relatedTarget || nativeEvent.fromElement;
  6789. if (related) {
  6790. // If the related node is managed by React, we can assume that we have
  6791. // already dispatched the corresponding events during its mouseout.
  6792. if (getClosestInstanceFromNode(related) || isContainerMarkedAsRoot(related)) {
  6793. return;
  6794. }
  6795. }
  6796. }
  6797. if (!isOutEvent && !isOverEvent) {
  6798. // Must not be a mouse or pointer in or out - ignoring.
  6799. return;
  6800. }
  6801. var win; // TODO: why is this nullable in the types but we read from it?
  6802. if (nativeEventTarget.window === nativeEventTarget) {
  6803. // `nativeEventTarget` is probably a window object.
  6804. win = nativeEventTarget;
  6805. } else {
  6806. // TODO: Figure out why `ownerDocument` is sometimes undefined in IE8.
  6807. var doc = nativeEventTarget.ownerDocument;
  6808. if (doc) {
  6809. win = doc.defaultView || doc.parentWindow;
  6810. } else {
  6811. win = window;
  6812. }
  6813. }
  6814. var from;
  6815. var to;
  6816. if (isOutEvent) {
  6817. var _related = nativeEvent.relatedTarget || nativeEvent.toElement;
  6818. from = targetInst;
  6819. to = _related ? getClosestInstanceFromNode(_related) : null;
  6820. if (to !== null) {
  6821. var nearestMounted = getNearestMountedFiber(to);
  6822. if (to !== nearestMounted || to.tag !== HostComponent && to.tag !== HostText) {
  6823. to = null;
  6824. }
  6825. }
  6826. } else {
  6827. // Moving to a node from outside the window.
  6828. from = null;
  6829. to = targetInst;
  6830. }
  6831. if (from === to) {
  6832. // Nothing pertains to our managed components.
  6833. return;
  6834. }
  6835. var SyntheticEventCtor = SyntheticMouseEvent;
  6836. var leaveEventType = 'onMouseLeave';
  6837. var enterEventType = 'onMouseEnter';
  6838. var eventTypePrefix = 'mouse';
  6839. if (domEventName === 'pointerout' || domEventName === 'pointerover') {
  6840. SyntheticEventCtor = SyntheticPointerEvent;
  6841. leaveEventType = 'onPointerLeave';
  6842. enterEventType = 'onPointerEnter';
  6843. eventTypePrefix = 'pointer';
  6844. }
  6845. var fromNode = from == null ? win : getNodeFromInstance(from);
  6846. var toNode = to == null ? win : getNodeFromInstance(to);
  6847. var leave = new SyntheticEventCtor(leaveEventType, eventTypePrefix + 'leave', from, nativeEvent, nativeEventTarget);
  6848. leave.target = fromNode;
  6849. leave.relatedTarget = toNode;
  6850. var enter = null; // We should only process this nativeEvent if we are processing
  6851. // the first ancestor. Next time, we will ignore the event.
  6852. var nativeTargetInst = getClosestInstanceFromNode(nativeEventTarget);
  6853. if (nativeTargetInst === targetInst) {
  6854. var enterEvent = new SyntheticEventCtor(enterEventType, eventTypePrefix + 'enter', to, nativeEvent, nativeEventTarget);
  6855. enterEvent.target = toNode;
  6856. enterEvent.relatedTarget = fromNode;
  6857. enter = enterEvent;
  6858. }
  6859. accumulateEnterLeaveTwoPhaseListeners(dispatchQueue, leave, enter, from, to);
  6860. }
  6861. /**
  6862. * inlined Object.is polyfill to avoid requiring consumers ship their own
  6863. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  6864. */
  6865. function is(x, y) {
  6866. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  6867. ;
  6868. }
  6869. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  6870. /**
  6871. * Performs equality by iterating through keys on an object and returning false
  6872. * when any key has values which are not strictly equal between the arguments.
  6873. * Returns true when the values of all keys are strictly equal.
  6874. */
  6875. function shallowEqual(objA, objB) {
  6876. if (objectIs(objA, objB)) {
  6877. return true;
  6878. }
  6879. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  6880. return false;
  6881. }
  6882. var keysA = Object.keys(objA);
  6883. var keysB = Object.keys(objB);
  6884. if (keysA.length !== keysB.length) {
  6885. return false;
  6886. } // Test for A's keys different from B.
  6887. for (var i = 0; i < keysA.length; i++) {
  6888. var currentKey = keysA[i];
  6889. if (!hasOwnProperty.call(objB, currentKey) || !objectIs(objA[currentKey], objB[currentKey])) {
  6890. return false;
  6891. }
  6892. }
  6893. return true;
  6894. }
  6895. /**
  6896. * Given any node return the first leaf node without children.
  6897. *
  6898. * @param {DOMElement|DOMTextNode} node
  6899. * @return {DOMElement|DOMTextNode}
  6900. */
  6901. function getLeafNode(node) {
  6902. while (node && node.firstChild) {
  6903. node = node.firstChild;
  6904. }
  6905. return node;
  6906. }
  6907. /**
  6908. * Get the next sibling within a container. This will walk up the
  6909. * DOM if a node's siblings have been exhausted.
  6910. *
  6911. * @param {DOMElement|DOMTextNode} node
  6912. * @return {?DOMElement|DOMTextNode}
  6913. */
  6914. function getSiblingNode(node) {
  6915. while (node) {
  6916. if (node.nextSibling) {
  6917. return node.nextSibling;
  6918. }
  6919. node = node.parentNode;
  6920. }
  6921. }
  6922. /**
  6923. * Get object describing the nodes which contain characters at offset.
  6924. *
  6925. * @param {DOMElement|DOMTextNode} root
  6926. * @param {number} offset
  6927. * @return {?object}
  6928. */
  6929. function getNodeForCharacterOffset(root, offset) {
  6930. var node = getLeafNode(root);
  6931. var nodeStart = 0;
  6932. var nodeEnd = 0;
  6933. while (node) {
  6934. if (node.nodeType === TEXT_NODE) {
  6935. nodeEnd = nodeStart + node.textContent.length;
  6936. if (nodeStart <= offset && nodeEnd >= offset) {
  6937. return {
  6938. node: node,
  6939. offset: offset - nodeStart
  6940. };
  6941. }
  6942. nodeStart = nodeEnd;
  6943. }
  6944. node = getLeafNode(getSiblingNode(node));
  6945. }
  6946. }
  6947. /**
  6948. * @param {DOMElement} outerNode
  6949. * @return {?object}
  6950. */
  6951. function getOffsets(outerNode) {
  6952. var ownerDocument = outerNode.ownerDocument;
  6953. var win = ownerDocument && ownerDocument.defaultView || window;
  6954. var selection = win.getSelection && win.getSelection();
  6955. if (!selection || selection.rangeCount === 0) {
  6956. return null;
  6957. }
  6958. var anchorNode = selection.anchorNode,
  6959. anchorOffset = selection.anchorOffset,
  6960. focusNode = selection.focusNode,
  6961. focusOffset = selection.focusOffset; // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
  6962. // up/down buttons on an <input type="number">. Anonymous divs do not seem to
  6963. // expose properties, triggering a "Permission denied error" if any of its
  6964. // properties are accessed. The only seemingly possible way to avoid erroring
  6965. // is to access a property that typically works for non-anonymous divs and
  6966. // catch any error that may otherwise arise. See
  6967. // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
  6968. try {
  6969. /* eslint-disable no-unused-expressions */
  6970. anchorNode.nodeType;
  6971. focusNode.nodeType;
  6972. /* eslint-enable no-unused-expressions */
  6973. } catch (e) {
  6974. return null;
  6975. }
  6976. return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset);
  6977. }
  6978. /**
  6979. * Returns {start, end} where `start` is the character/codepoint index of
  6980. * (anchorNode, anchorOffset) within the textContent of `outerNode`, and
  6981. * `end` is the index of (focusNode, focusOffset).
  6982. *
  6983. * Returns null if you pass in garbage input but we should probably just crash.
  6984. *
  6985. * Exported only for testing.
  6986. */
  6987. function getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset) {
  6988. var length = 0;
  6989. var start = -1;
  6990. var end = -1;
  6991. var indexWithinAnchor = 0;
  6992. var indexWithinFocus = 0;
  6993. var node = outerNode;
  6994. var parentNode = null;
  6995. outer: while (true) {
  6996. var next = null;
  6997. while (true) {
  6998. if (node === anchorNode && (anchorOffset === 0 || node.nodeType === TEXT_NODE)) {
  6999. start = length + anchorOffset;
  7000. }
  7001. if (node === focusNode && (focusOffset === 0 || node.nodeType === TEXT_NODE)) {
  7002. end = length + focusOffset;
  7003. }
  7004. if (node.nodeType === TEXT_NODE) {
  7005. length += node.nodeValue.length;
  7006. }
  7007. if ((next = node.firstChild) === null) {
  7008. break;
  7009. } // Moving from `node` to its first child `next`.
  7010. parentNode = node;
  7011. node = next;
  7012. }
  7013. while (true) {
  7014. if (node === outerNode) {
  7015. // If `outerNode` has children, this is always the second time visiting
  7016. // it. If it has no children, this is still the first loop, and the only
  7017. // valid selection is anchorNode and focusNode both equal to this node
  7018. // and both offsets 0, in which case we will have handled above.
  7019. break outer;
  7020. }
  7021. if (parentNode === anchorNode && ++indexWithinAnchor === anchorOffset) {
  7022. start = length;
  7023. }
  7024. if (parentNode === focusNode && ++indexWithinFocus === focusOffset) {
  7025. end = length;
  7026. }
  7027. if ((next = node.nextSibling) !== null) {
  7028. break;
  7029. }
  7030. node = parentNode;
  7031. parentNode = node.parentNode;
  7032. } // Moving from `node` to its next sibling `next`.
  7033. node = next;
  7034. }
  7035. if (start === -1 || end === -1) {
  7036. // This should never happen. (Would happen if the anchor/focus nodes aren't
  7037. // actually inside the passed-in node.)
  7038. return null;
  7039. }
  7040. return {
  7041. start: start,
  7042. end: end
  7043. };
  7044. }
  7045. /**
  7046. * In modern non-IE browsers, we can support both forward and backward
  7047. * selections.
  7048. *
  7049. * Note: IE10+ supports the Selection object, but it does not support
  7050. * the `extend` method, which means that even in modern IE, it's not possible
  7051. * to programmatically create a backward selection. Thus, for all IE
  7052. * versions, we use the old IE API to create our selections.
  7053. *
  7054. * @param {DOMElement|DOMTextNode} node
  7055. * @param {object} offsets
  7056. */
  7057. function setOffsets(node, offsets) {
  7058. var doc = node.ownerDocument || document;
  7059. var win = doc && doc.defaultView || window; // Edge fails with "Object expected" in some scenarios.
  7060. // (For instance: TinyMCE editor used in a list component that supports pasting to add more,
  7061. // fails when pasting 100+ items)
  7062. if (!win.getSelection) {
  7063. return;
  7064. }
  7065. var selection = win.getSelection();
  7066. var length = node.textContent.length;
  7067. var start = Math.min(offsets.start, length);
  7068. var end = offsets.end === undefined ? start : Math.min(offsets.end, length); // IE 11 uses modern selection, but doesn't support the extend method.
  7069. // Flip backward selections, so we can set with a single range.
  7070. if (!selection.extend && start > end) {
  7071. var temp = end;
  7072. end = start;
  7073. start = temp;
  7074. }
  7075. var startMarker = getNodeForCharacterOffset(node, start);
  7076. var endMarker = getNodeForCharacterOffset(node, end);
  7077. if (startMarker && endMarker) {
  7078. if (selection.rangeCount === 1 && selection.anchorNode === startMarker.node && selection.anchorOffset === startMarker.offset && selection.focusNode === endMarker.node && selection.focusOffset === endMarker.offset) {
  7079. return;
  7080. }
  7081. var range = doc.createRange();
  7082. range.setStart(startMarker.node, startMarker.offset);
  7083. selection.removeAllRanges();
  7084. if (start > end) {
  7085. selection.addRange(range);
  7086. selection.extend(endMarker.node, endMarker.offset);
  7087. } else {
  7088. range.setEnd(endMarker.node, endMarker.offset);
  7089. selection.addRange(range);
  7090. }
  7091. }
  7092. }
  7093. function isTextNode(node) {
  7094. return node && node.nodeType === TEXT_NODE;
  7095. }
  7096. function containsNode(outerNode, innerNode) {
  7097. if (!outerNode || !innerNode) {
  7098. return false;
  7099. } else if (outerNode === innerNode) {
  7100. return true;
  7101. } else if (isTextNode(outerNode)) {
  7102. return false;
  7103. } else if (isTextNode(innerNode)) {
  7104. return containsNode(outerNode, innerNode.parentNode);
  7105. } else if ('contains' in outerNode) {
  7106. return outerNode.contains(innerNode);
  7107. } else if (outerNode.compareDocumentPosition) {
  7108. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  7109. } else {
  7110. return false;
  7111. }
  7112. }
  7113. function isInDocument(node) {
  7114. return node && node.ownerDocument && containsNode(node.ownerDocument.documentElement, node);
  7115. }
  7116. function isSameOriginFrame(iframe) {
  7117. try {
  7118. // Accessing the contentDocument of a HTMLIframeElement can cause the browser
  7119. // to throw, e.g. if it has a cross-origin src attribute.
  7120. // Safari will show an error in the console when the access results in "Blocked a frame with origin". e.g:
  7121. // iframe.contentDocument.defaultView;
  7122. // A safety way is to access one of the cross origin properties: Window or Location
  7123. // Which might result in "SecurityError" DOM Exception and it is compatible to Safari.
  7124. // https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl
  7125. return typeof iframe.contentWindow.location.href === 'string';
  7126. } catch (err) {
  7127. return false;
  7128. }
  7129. }
  7130. function getActiveElementDeep() {
  7131. var win = window;
  7132. var element = getActiveElement();
  7133. while (element instanceof win.HTMLIFrameElement) {
  7134. if (isSameOriginFrame(element)) {
  7135. win = element.contentWindow;
  7136. } else {
  7137. return element;
  7138. }
  7139. element = getActiveElement(win.document);
  7140. }
  7141. return element;
  7142. }
  7143. /**
  7144. * @ReactInputSelection: React input selection module. Based on Selection.js,
  7145. * but modified to be suitable for react and has a couple of bug fixes (doesn't
  7146. * assume buttons have range selections allowed).
  7147. * Input selection module for React.
  7148. */
  7149. /**
  7150. * @hasSelectionCapabilities: we get the element types that support selection
  7151. * from https://html.spec.whatwg.org/#do-not-apply, looking at `selectionStart`
  7152. * and `selectionEnd` rows.
  7153. */
  7154. function hasSelectionCapabilities(elem) {
  7155. var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
  7156. return nodeName && (nodeName === 'input' && (elem.type === 'text' || elem.type === 'search' || elem.type === 'tel' || elem.type === 'url' || elem.type === 'password') || nodeName === 'textarea' || elem.contentEditable === 'true');
  7157. }
  7158. function getSelectionInformation() {
  7159. var focusedElem = getActiveElementDeep();
  7160. return {
  7161. focusedElem: focusedElem,
  7162. selectionRange: hasSelectionCapabilities(focusedElem) ? getSelection(focusedElem) : null
  7163. };
  7164. }
  7165. /**
  7166. * @restoreSelection: If any selection information was potentially lost,
  7167. * restore it. This is useful when performing operations that could remove dom
  7168. * nodes and place them back in, resulting in focus being lost.
  7169. */
  7170. function restoreSelection(priorSelectionInformation) {
  7171. var curFocusedElem = getActiveElementDeep();
  7172. var priorFocusedElem = priorSelectionInformation.focusedElem;
  7173. var priorSelectionRange = priorSelectionInformation.selectionRange;
  7174. if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) {
  7175. if (priorSelectionRange !== null && hasSelectionCapabilities(priorFocusedElem)) {
  7176. setSelection(priorFocusedElem, priorSelectionRange);
  7177. } // Focusing a node can change the scroll position, which is undesirable
  7178. var ancestors = [];
  7179. var ancestor = priorFocusedElem;
  7180. while (ancestor = ancestor.parentNode) {
  7181. if (ancestor.nodeType === ELEMENT_NODE) {
  7182. ancestors.push({
  7183. element: ancestor,
  7184. left: ancestor.scrollLeft,
  7185. top: ancestor.scrollTop
  7186. });
  7187. }
  7188. }
  7189. if (typeof priorFocusedElem.focus === 'function') {
  7190. priorFocusedElem.focus();
  7191. }
  7192. for (var i = 0; i < ancestors.length; i++) {
  7193. var info = ancestors[i];
  7194. info.element.scrollLeft = info.left;
  7195. info.element.scrollTop = info.top;
  7196. }
  7197. }
  7198. }
  7199. /**
  7200. * @getSelection: Gets the selection bounds of a focused textarea, input or
  7201. * contentEditable node.
  7202. * -@input: Look up selection bounds of this input
  7203. * -@return {start: selectionStart, end: selectionEnd}
  7204. */
  7205. function getSelection(input) {
  7206. var selection;
  7207. if ('selectionStart' in input) {
  7208. // Modern browser with input or textarea.
  7209. selection = {
  7210. start: input.selectionStart,
  7211. end: input.selectionEnd
  7212. };
  7213. } else {
  7214. // Content editable or old IE textarea.
  7215. selection = getOffsets(input);
  7216. }
  7217. return selection || {
  7218. start: 0,
  7219. end: 0
  7220. };
  7221. }
  7222. /**
  7223. * @setSelection: Sets the selection bounds of a textarea or input and focuses
  7224. * the input.
  7225. * -@input Set selection bounds of this input or textarea
  7226. * -@offsets Object of same form that is returned from get*
  7227. */
  7228. function setSelection(input, offsets) {
  7229. var start = offsets.start;
  7230. var end = offsets.end;
  7231. if (end === undefined) {
  7232. end = start;
  7233. }
  7234. if ('selectionStart' in input) {
  7235. input.selectionStart = start;
  7236. input.selectionEnd = Math.min(end, input.value.length);
  7237. } else {
  7238. setOffsets(input, offsets);
  7239. }
  7240. }
  7241. var skipSelectionChangeEvent = canUseDOM && 'documentMode' in document && document.documentMode <= 11;
  7242. function registerEvents$3() {
  7243. registerTwoPhaseEvent('onSelect', ['focusout', 'contextmenu', 'dragend', 'focusin', 'keydown', 'keyup', 'mousedown', 'mouseup', 'selectionchange']);
  7244. }
  7245. var activeElement$1 = null;
  7246. var activeElementInst$1 = null;
  7247. var lastSelection = null;
  7248. var mouseDown = false;
  7249. /**
  7250. * Get an object which is a unique representation of the current selection.
  7251. *
  7252. * The return value will not be consistent across nodes or browsers, but
  7253. * two identical selections on the same node will return identical objects.
  7254. */
  7255. function getSelection$1(node) {
  7256. if ('selectionStart' in node && hasSelectionCapabilities(node)) {
  7257. return {
  7258. start: node.selectionStart,
  7259. end: node.selectionEnd
  7260. };
  7261. } else {
  7262. var win = node.ownerDocument && node.ownerDocument.defaultView || window;
  7263. var selection = win.getSelection();
  7264. return {
  7265. anchorNode: selection.anchorNode,
  7266. anchorOffset: selection.anchorOffset,
  7267. focusNode: selection.focusNode,
  7268. focusOffset: selection.focusOffset
  7269. };
  7270. }
  7271. }
  7272. /**
  7273. * Get document associated with the event target.
  7274. */
  7275. function getEventTargetDocument(eventTarget) {
  7276. return eventTarget.window === eventTarget ? eventTarget.document : eventTarget.nodeType === DOCUMENT_NODE ? eventTarget : eventTarget.ownerDocument;
  7277. }
  7278. /**
  7279. * Poll selection to see whether it's changed.
  7280. *
  7281. * @param {object} nativeEvent
  7282. * @param {object} nativeEventTarget
  7283. * @return {?SyntheticEvent}
  7284. */
  7285. function constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget) {
  7286. // Ensure we have the right element, and that the user is not dragging a
  7287. // selection (this matches native `select` event behavior). In HTML5, select
  7288. // fires only on input and textarea thus if there's no focused element we
  7289. // won't dispatch.
  7290. var doc = getEventTargetDocument(nativeEventTarget);
  7291. if (mouseDown || activeElement$1 == null || activeElement$1 !== getActiveElement(doc)) {
  7292. return;
  7293. } // Only fire when selection has actually changed.
  7294. var currentSelection = getSelection$1(activeElement$1);
  7295. if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
  7296. lastSelection = currentSelection;
  7297. var listeners = accumulateTwoPhaseListeners(activeElementInst$1, 'onSelect');
  7298. if (listeners.length > 0) {
  7299. var event = new SyntheticEvent('onSelect', 'select', null, nativeEvent, nativeEventTarget);
  7300. dispatchQueue.push({
  7301. event: event,
  7302. listeners: listeners
  7303. });
  7304. event.target = activeElement$1;
  7305. }
  7306. }
  7307. }
  7308. /**
  7309. * This plugin creates an `onSelect` event that normalizes select events
  7310. * across form elements.
  7311. *
  7312. * Supported elements are:
  7313. * - input (see `isTextInputElement`)
  7314. * - textarea
  7315. * - contentEditable
  7316. *
  7317. * This differs from native browser implementations in the following ways:
  7318. * - Fires on contentEditable fields as well as inputs.
  7319. * - Fires for collapsed selection.
  7320. * - Fires after user input.
  7321. */
  7322. function extractEvents$3(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  7323. var targetNode = targetInst ? getNodeFromInstance(targetInst) : window;
  7324. switch (domEventName) {
  7325. // Track the input node that has focus.
  7326. case 'focusin':
  7327. if (isTextInputElement(targetNode) || targetNode.contentEditable === 'true') {
  7328. activeElement$1 = targetNode;
  7329. activeElementInst$1 = targetInst;
  7330. lastSelection = null;
  7331. }
  7332. break;
  7333. case 'focusout':
  7334. activeElement$1 = null;
  7335. activeElementInst$1 = null;
  7336. lastSelection = null;
  7337. break;
  7338. // Don't fire the event while the user is dragging. This matches the
  7339. // semantics of the native select event.
  7340. case 'mousedown':
  7341. mouseDown = true;
  7342. break;
  7343. case 'contextmenu':
  7344. case 'mouseup':
  7345. case 'dragend':
  7346. mouseDown = false;
  7347. constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget);
  7348. break;
  7349. // Chrome and IE fire non-standard event when selection is changed (and
  7350. // sometimes when it hasn't). IE's event fires out of order with respect
  7351. // to key and input events on deletion, so we discard it.
  7352. //
  7353. // Firefox doesn't support selectionchange, so check selection status
  7354. // after each key entry. The selection changes after keydown and before
  7355. // keyup, but we check on keydown as well in the case of holding down a
  7356. // key, when multiple keydown events are fired but only one keyup is.
  7357. // This is also our approach for IE handling, for the reason above.
  7358. case 'selectionchange':
  7359. if (skipSelectionChangeEvent) {
  7360. break;
  7361. }
  7362. // falls through
  7363. case 'keydown':
  7364. case 'keyup':
  7365. constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget);
  7366. }
  7367. }
  7368. /**
  7369. * Generate a mapping of standard vendor prefixes using the defined style property and event name.
  7370. *
  7371. * @param {string} styleProp
  7372. * @param {string} eventName
  7373. * @returns {object}
  7374. */
  7375. function makePrefixMap(styleProp, eventName) {
  7376. var prefixes = {};
  7377. prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
  7378. prefixes['Webkit' + styleProp] = 'webkit' + eventName;
  7379. prefixes['Moz' + styleProp] = 'moz' + eventName;
  7380. return prefixes;
  7381. }
  7382. /**
  7383. * A list of event names to a configurable list of vendor prefixes.
  7384. */
  7385. var vendorPrefixes = {
  7386. animationend: makePrefixMap('Animation', 'AnimationEnd'),
  7387. animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
  7388. animationstart: makePrefixMap('Animation', 'AnimationStart'),
  7389. transitionend: makePrefixMap('Transition', 'TransitionEnd')
  7390. };
  7391. /**
  7392. * Event names that have already been detected and prefixed (if applicable).
  7393. */
  7394. var prefixedEventNames = {};
  7395. /**
  7396. * Element to check for prefixes on.
  7397. */
  7398. var style = {};
  7399. /**
  7400. * Bootstrap if a DOM exists.
  7401. */
  7402. if (canUseDOM) {
  7403. style = document.createElement('div').style; // On some platforms, in particular some releases of Android 4.x,
  7404. // the un-prefixed "animation" and "transition" properties are defined on the
  7405. // style object but the events that fire will still be prefixed, so we need
  7406. // to check if the un-prefixed events are usable, and if not remove them from the map.
  7407. if (!('AnimationEvent' in window)) {
  7408. delete vendorPrefixes.animationend.animation;
  7409. delete vendorPrefixes.animationiteration.animation;
  7410. delete vendorPrefixes.animationstart.animation;
  7411. } // Same as above
  7412. if (!('TransitionEvent' in window)) {
  7413. delete vendorPrefixes.transitionend.transition;
  7414. }
  7415. }
  7416. /**
  7417. * Attempts to determine the correct vendor prefixed event name.
  7418. *
  7419. * @param {string} eventName
  7420. * @returns {string}
  7421. */
  7422. function getVendorPrefixedEventName(eventName) {
  7423. if (prefixedEventNames[eventName]) {
  7424. return prefixedEventNames[eventName];
  7425. } else if (!vendorPrefixes[eventName]) {
  7426. return eventName;
  7427. }
  7428. var prefixMap = vendorPrefixes[eventName];
  7429. for (var styleProp in prefixMap) {
  7430. if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
  7431. return prefixedEventNames[eventName] = prefixMap[styleProp];
  7432. }
  7433. }
  7434. return eventName;
  7435. }
  7436. var ANIMATION_END = getVendorPrefixedEventName('animationend');
  7437. var ANIMATION_ITERATION = getVendorPrefixedEventName('animationiteration');
  7438. var ANIMATION_START = getVendorPrefixedEventName('animationstart');
  7439. var TRANSITION_END = getVendorPrefixedEventName('transitionend');
  7440. var topLevelEventsToReactNames = new Map(); // NOTE: Capitalization is important in this list!
  7441. //
  7442. // E.g. it needs "pointerDown", not "pointerdown".
  7443. // This is because we derive both React name ("onPointerDown")
  7444. // and DOM name ("pointerdown") from the same list.
  7445. //
  7446. // Exceptions that don't match this convention are listed separately.
  7447. //
  7448. // prettier-ignore
  7449. var simpleEventPluginEvents = ['abort', 'auxClick', 'cancel', 'canPlay', 'canPlayThrough', 'click', 'close', 'contextMenu', 'copy', 'cut', 'drag', 'dragEnd', 'dragEnter', 'dragExit', 'dragLeave', 'dragOver', 'dragStart', 'drop', 'durationChange', 'emptied', 'encrypted', 'ended', 'error', 'gotPointerCapture', 'input', 'invalid', 'keyDown', 'keyPress', 'keyUp', 'load', 'loadedData', 'loadedMetadata', 'loadStart', 'lostPointerCapture', 'mouseDown', 'mouseMove', 'mouseOut', 'mouseOver', 'mouseUp', 'paste', 'pause', 'play', 'playing', 'pointerCancel', 'pointerDown', 'pointerMove', 'pointerOut', 'pointerOver', 'pointerUp', 'progress', 'rateChange', 'reset', 'resize', 'seeked', 'seeking', 'stalled', 'submit', 'suspend', 'timeUpdate', 'touchCancel', 'touchEnd', 'touchStart', 'volumeChange', 'scroll', 'toggle', 'touchMove', 'waiting', 'wheel'];
  7450. function registerSimpleEvent(domEventName, reactName) {
  7451. topLevelEventsToReactNames.set(domEventName, reactName);
  7452. registerTwoPhaseEvent(reactName, [domEventName]);
  7453. }
  7454. function registerSimpleEvents() {
  7455. for (var i = 0; i < simpleEventPluginEvents.length; i++) {
  7456. var eventName = simpleEventPluginEvents[i];
  7457. var domEventName = eventName.toLowerCase();
  7458. var capitalizedEvent = eventName[0].toUpperCase() + eventName.slice(1);
  7459. registerSimpleEvent(domEventName, 'on' + capitalizedEvent);
  7460. } // Special cases where event names don't match.
  7461. registerSimpleEvent(ANIMATION_END, 'onAnimationEnd');
  7462. registerSimpleEvent(ANIMATION_ITERATION, 'onAnimationIteration');
  7463. registerSimpleEvent(ANIMATION_START, 'onAnimationStart');
  7464. registerSimpleEvent('dblclick', 'onDoubleClick');
  7465. registerSimpleEvent('focusin', 'onFocus');
  7466. registerSimpleEvent('focusout', 'onBlur');
  7467. registerSimpleEvent(TRANSITION_END, 'onTransitionEnd');
  7468. }
  7469. function extractEvents$4(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  7470. var reactName = topLevelEventsToReactNames.get(domEventName);
  7471. if (reactName === undefined) {
  7472. return;
  7473. }
  7474. var SyntheticEventCtor = SyntheticEvent;
  7475. var reactEventType = domEventName;
  7476. switch (domEventName) {
  7477. case 'keypress':
  7478. // Firefox creates a keypress event for function keys too. This removes
  7479. // the unwanted keypress events. Enter is however both printable and
  7480. // non-printable. One would expect Tab to be as well (but it isn't).
  7481. if (getEventCharCode(nativeEvent) === 0) {
  7482. return;
  7483. }
  7484. /* falls through */
  7485. case 'keydown':
  7486. case 'keyup':
  7487. SyntheticEventCtor = SyntheticKeyboardEvent;
  7488. break;
  7489. case 'focusin':
  7490. reactEventType = 'focus';
  7491. SyntheticEventCtor = SyntheticFocusEvent;
  7492. break;
  7493. case 'focusout':
  7494. reactEventType = 'blur';
  7495. SyntheticEventCtor = SyntheticFocusEvent;
  7496. break;
  7497. case 'beforeblur':
  7498. case 'afterblur':
  7499. SyntheticEventCtor = SyntheticFocusEvent;
  7500. break;
  7501. case 'click':
  7502. // Firefox creates a click event on right mouse clicks. This removes the
  7503. // unwanted click events.
  7504. if (nativeEvent.button === 2) {
  7505. return;
  7506. }
  7507. /* falls through */
  7508. case 'auxclick':
  7509. case 'dblclick':
  7510. case 'mousedown':
  7511. case 'mousemove':
  7512. case 'mouseup': // TODO: Disabled elements should not respond to mouse events
  7513. /* falls through */
  7514. case 'mouseout':
  7515. case 'mouseover':
  7516. case 'contextmenu':
  7517. SyntheticEventCtor = SyntheticMouseEvent;
  7518. break;
  7519. case 'drag':
  7520. case 'dragend':
  7521. case 'dragenter':
  7522. case 'dragexit':
  7523. case 'dragleave':
  7524. case 'dragover':
  7525. case 'dragstart':
  7526. case 'drop':
  7527. SyntheticEventCtor = SyntheticDragEvent;
  7528. break;
  7529. case 'touchcancel':
  7530. case 'touchend':
  7531. case 'touchmove':
  7532. case 'touchstart':
  7533. SyntheticEventCtor = SyntheticTouchEvent;
  7534. break;
  7535. case ANIMATION_END:
  7536. case ANIMATION_ITERATION:
  7537. case ANIMATION_START:
  7538. SyntheticEventCtor = SyntheticAnimationEvent;
  7539. break;
  7540. case TRANSITION_END:
  7541. SyntheticEventCtor = SyntheticTransitionEvent;
  7542. break;
  7543. case 'scroll':
  7544. SyntheticEventCtor = SyntheticUIEvent;
  7545. break;
  7546. case 'wheel':
  7547. SyntheticEventCtor = SyntheticWheelEvent;
  7548. break;
  7549. case 'copy':
  7550. case 'cut':
  7551. case 'paste':
  7552. SyntheticEventCtor = SyntheticClipboardEvent;
  7553. break;
  7554. case 'gotpointercapture':
  7555. case 'lostpointercapture':
  7556. case 'pointercancel':
  7557. case 'pointerdown':
  7558. case 'pointermove':
  7559. case 'pointerout':
  7560. case 'pointerover':
  7561. case 'pointerup':
  7562. SyntheticEventCtor = SyntheticPointerEvent;
  7563. break;
  7564. }
  7565. var inCapturePhase = (eventSystemFlags & IS_CAPTURE_PHASE) !== 0;
  7566. {
  7567. // Some events don't bubble in the browser.
  7568. // In the past, React has always bubbled them, but this can be surprising.
  7569. // We're going to try aligning closer to the browser behavior by not bubbling
  7570. // them in React either. We'll start by not bubbling onScroll, and then expand.
  7571. var accumulateTargetOnly = !inCapturePhase && // TODO: ideally, we'd eventually add all events from
  7572. // nonDelegatedEvents list in DOMPluginEventSystem.
  7573. // Then we can remove this special list.
  7574. // This is a breaking change that can wait until React 18.
  7575. domEventName === 'scroll';
  7576. var _listeners = accumulateSinglePhaseListeners(targetInst, reactName, nativeEvent.type, inCapturePhase, accumulateTargetOnly);
  7577. if (_listeners.length > 0) {
  7578. // Intentionally create event lazily.
  7579. var _event = new SyntheticEventCtor(reactName, reactEventType, null, nativeEvent, nativeEventTarget);
  7580. dispatchQueue.push({
  7581. event: _event,
  7582. listeners: _listeners
  7583. });
  7584. }
  7585. }
  7586. }
  7587. // TODO: remove top-level side effect.
  7588. registerSimpleEvents();
  7589. registerEvents$2();
  7590. registerEvents$1();
  7591. registerEvents$3();
  7592. registerEvents();
  7593. function extractEvents$5(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  7594. // TODO: we should remove the concept of a "SimpleEventPlugin".
  7595. // This is the basic functionality of the event system. All
  7596. // the other plugins are essentially polyfills. So the plugin
  7597. // should probably be inlined somewhere and have its logic
  7598. // be core the to event system. This would potentially allow
  7599. // us to ship builds of React without the polyfilled plugins below.
  7600. extractEvents$4(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags);
  7601. var shouldProcessPolyfillPlugins = (eventSystemFlags & SHOULD_NOT_PROCESS_POLYFILL_EVENT_PLUGINS) === 0; // We don't process these events unless we are in the
  7602. // event's native "bubble" phase, which means that we're
  7603. // not in the capture phase. That's because we emulate
  7604. // the capture phase here still. This is a trade-off,
  7605. // because in an ideal world we would not emulate and use
  7606. // the phases properly, like we do with the SimpleEvent
  7607. // plugin. However, the plugins below either expect
  7608. // emulation (EnterLeave) or use state localized to that
  7609. // plugin (BeforeInput, Change, Select). The state in
  7610. // these modules complicates things, as you'll essentially
  7611. // get the case where the capture phase event might change
  7612. // state, only for the following bubble event to come in
  7613. // later and not trigger anything as the state now
  7614. // invalidates the heuristics of the event plugin. We
  7615. // could alter all these plugins to work in such ways, but
  7616. // that might cause other unknown side-effects that we
  7617. // can't foresee right now.
  7618. if (shouldProcessPolyfillPlugins) {
  7619. extractEvents$2(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  7620. extractEvents$1(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  7621. extractEvents$3(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  7622. extractEvents(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  7623. }
  7624. } // List of events that need to be individually attached to media elements.
  7625. var mediaEventTypes = ['abort', 'canplay', 'canplaythrough', 'durationchange', 'emptied', 'encrypted', 'ended', 'error', 'loadeddata', 'loadedmetadata', 'loadstart', 'pause', 'play', 'playing', 'progress', 'ratechange', 'resize', 'seeked', 'seeking', 'stalled', 'suspend', 'timeupdate', 'volumechange', 'waiting']; // We should not delegate these events to the container, but rather
  7626. // set them on the actual target element itself. This is primarily
  7627. // because these events do not consistently bubble in the DOM.
  7628. var nonDelegatedEvents = new Set(['cancel', 'close', 'invalid', 'load', 'scroll', 'toggle'].concat(mediaEventTypes));
  7629. function executeDispatch(event, listener, currentTarget) {
  7630. var type = event.type || 'unknown-event';
  7631. event.currentTarget = currentTarget;
  7632. invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
  7633. event.currentTarget = null;
  7634. }
  7635. function processDispatchQueueItemsInOrder(event, dispatchListeners, inCapturePhase) {
  7636. var previousInstance;
  7637. if (inCapturePhase) {
  7638. for (var i = dispatchListeners.length - 1; i >= 0; i--) {
  7639. var _dispatchListeners$i = dispatchListeners[i],
  7640. instance = _dispatchListeners$i.instance,
  7641. currentTarget = _dispatchListeners$i.currentTarget,
  7642. listener = _dispatchListeners$i.listener;
  7643. if (instance !== previousInstance && event.isPropagationStopped()) {
  7644. return;
  7645. }
  7646. executeDispatch(event, listener, currentTarget);
  7647. previousInstance = instance;
  7648. }
  7649. } else {
  7650. for (var _i = 0; _i < dispatchListeners.length; _i++) {
  7651. var _dispatchListeners$_i = dispatchListeners[_i],
  7652. _instance = _dispatchListeners$_i.instance,
  7653. _currentTarget = _dispatchListeners$_i.currentTarget,
  7654. _listener = _dispatchListeners$_i.listener;
  7655. if (_instance !== previousInstance && event.isPropagationStopped()) {
  7656. return;
  7657. }
  7658. executeDispatch(event, _listener, _currentTarget);
  7659. previousInstance = _instance;
  7660. }
  7661. }
  7662. }
  7663. function processDispatchQueue(dispatchQueue, eventSystemFlags) {
  7664. var inCapturePhase = (eventSystemFlags & IS_CAPTURE_PHASE) !== 0;
  7665. for (var i = 0; i < dispatchQueue.length; i++) {
  7666. var _dispatchQueue$i = dispatchQueue[i],
  7667. event = _dispatchQueue$i.event,
  7668. listeners = _dispatchQueue$i.listeners;
  7669. processDispatchQueueItemsInOrder(event, listeners, inCapturePhase); // event system doesn't use pooling.
  7670. } // This would be a good time to rethrow if any of the event handlers threw.
  7671. rethrowCaughtError();
  7672. }
  7673. function dispatchEventsForPlugins(domEventName, eventSystemFlags, nativeEvent, targetInst, targetContainer) {
  7674. var nativeEventTarget = getEventTarget(nativeEvent);
  7675. var dispatchQueue = [];
  7676. extractEvents$5(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags);
  7677. processDispatchQueue(dispatchQueue, eventSystemFlags);
  7678. }
  7679. function listenToNonDelegatedEvent(domEventName, targetElement) {
  7680. {
  7681. if (!nonDelegatedEvents.has(domEventName)) {
  7682. error('Did not expect a listenToNonDelegatedEvent() call for "%s". ' + 'This is a bug in React. Please file an issue.', domEventName);
  7683. }
  7684. }
  7685. var isCapturePhaseListener = false;
  7686. var listenerSet = getEventListenerSet(targetElement);
  7687. var listenerSetKey = getListenerSetKey(domEventName, isCapturePhaseListener);
  7688. if (!listenerSet.has(listenerSetKey)) {
  7689. addTrappedEventListener(targetElement, domEventName, IS_NON_DELEGATED, isCapturePhaseListener);
  7690. listenerSet.add(listenerSetKey);
  7691. }
  7692. }
  7693. function listenToNativeEvent(domEventName, isCapturePhaseListener, target) {
  7694. {
  7695. if (nonDelegatedEvents.has(domEventName) && !isCapturePhaseListener) {
  7696. error('Did not expect a listenToNativeEvent() call for "%s" in the bubble phase. ' + 'This is a bug in React. Please file an issue.', domEventName);
  7697. }
  7698. }
  7699. var eventSystemFlags = 0;
  7700. if (isCapturePhaseListener) {
  7701. eventSystemFlags |= IS_CAPTURE_PHASE;
  7702. }
  7703. addTrappedEventListener(target, domEventName, eventSystemFlags, isCapturePhaseListener);
  7704. } // This is only used by createEventHandle when the
  7705. var listeningMarker = '_reactListening' + Math.random().toString(36).slice(2);
  7706. function listenToAllSupportedEvents(rootContainerElement) {
  7707. if (!rootContainerElement[listeningMarker]) {
  7708. rootContainerElement[listeningMarker] = true;
  7709. allNativeEvents.forEach(function (domEventName) {
  7710. // We handle selectionchange separately because it
  7711. // doesn't bubble and needs to be on the document.
  7712. if (domEventName !== 'selectionchange') {
  7713. if (!nonDelegatedEvents.has(domEventName)) {
  7714. listenToNativeEvent(domEventName, false, rootContainerElement);
  7715. }
  7716. listenToNativeEvent(domEventName, true, rootContainerElement);
  7717. }
  7718. });
  7719. var ownerDocument = rootContainerElement.nodeType === DOCUMENT_NODE ? rootContainerElement : rootContainerElement.ownerDocument;
  7720. if (ownerDocument !== null) {
  7721. // The selectionchange event also needs deduplication
  7722. // but it is attached to the document.
  7723. if (!ownerDocument[listeningMarker]) {
  7724. ownerDocument[listeningMarker] = true;
  7725. listenToNativeEvent('selectionchange', false, ownerDocument);
  7726. }
  7727. }
  7728. }
  7729. }
  7730. function addTrappedEventListener(targetContainer, domEventName, eventSystemFlags, isCapturePhaseListener, isDeferredListenerForLegacyFBSupport) {
  7731. var listener = createEventListenerWrapperWithPriority(targetContainer, domEventName, eventSystemFlags); // If passive option is not supported, then the event will be
  7732. // active and not passive.
  7733. var isPassiveListener = undefined;
  7734. if (passiveBrowserEventsSupported) {
  7735. // Browsers introduced an intervention, making these events
  7736. // passive by default on document. React doesn't bind them
  7737. // to document anymore, but changing this now would undo
  7738. // the performance wins from the change. So we emulate
  7739. // the existing behavior manually on the roots now.
  7740. // https://github.com/facebook/react/issues/19651
  7741. if (domEventName === 'touchstart' || domEventName === 'touchmove' || domEventName === 'wheel') {
  7742. isPassiveListener = true;
  7743. }
  7744. }
  7745. targetContainer = targetContainer;
  7746. var unsubscribeListener; // When legacyFBSupport is enabled, it's for when we
  7747. if (isCapturePhaseListener) {
  7748. if (isPassiveListener !== undefined) {
  7749. unsubscribeListener = addEventCaptureListenerWithPassiveFlag(targetContainer, domEventName, listener, isPassiveListener);
  7750. } else {
  7751. unsubscribeListener = addEventCaptureListener(targetContainer, domEventName, listener);
  7752. }
  7753. } else {
  7754. if (isPassiveListener !== undefined) {
  7755. unsubscribeListener = addEventBubbleListenerWithPassiveFlag(targetContainer, domEventName, listener, isPassiveListener);
  7756. } else {
  7757. unsubscribeListener = addEventBubbleListener(targetContainer, domEventName, listener);
  7758. }
  7759. }
  7760. }
  7761. function isMatchingRootContainer(grandContainer, targetContainer) {
  7762. return grandContainer === targetContainer || grandContainer.nodeType === COMMENT_NODE && grandContainer.parentNode === targetContainer;
  7763. }
  7764. function dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, targetInst, targetContainer) {
  7765. var ancestorInst = targetInst;
  7766. if ((eventSystemFlags & IS_EVENT_HANDLE_NON_MANAGED_NODE) === 0 && (eventSystemFlags & IS_NON_DELEGATED) === 0) {
  7767. var targetContainerNode = targetContainer; // If we are using the legacy FB support flag, we
  7768. if (targetInst !== null) {
  7769. // The below logic attempts to work out if we need to change
  7770. // the target fiber to a different ancestor. We had similar logic
  7771. // in the legacy event system, except the big difference between
  7772. // systems is that the modern event system now has an event listener
  7773. // attached to each React Root and React Portal Root. Together,
  7774. // the DOM nodes representing these roots are the "rootContainer".
  7775. // To figure out which ancestor instance we should use, we traverse
  7776. // up the fiber tree from the target instance and attempt to find
  7777. // root boundaries that match that of our current "rootContainer".
  7778. // If we find that "rootContainer", we find the parent fiber
  7779. // sub-tree for that root and make that our ancestor instance.
  7780. var node = targetInst;
  7781. mainLoop: while (true) {
  7782. if (node === null) {
  7783. return;
  7784. }
  7785. var nodeTag = node.tag;
  7786. if (nodeTag === HostRoot || nodeTag === HostPortal) {
  7787. var container = node.stateNode.containerInfo;
  7788. if (isMatchingRootContainer(container, targetContainerNode)) {
  7789. break;
  7790. }
  7791. if (nodeTag === HostPortal) {
  7792. // The target is a portal, but it's not the rootContainer we're looking for.
  7793. // Normally portals handle their own events all the way down to the root.
  7794. // So we should be able to stop now. However, we don't know if this portal
  7795. // was part of *our* root.
  7796. var grandNode = node.return;
  7797. while (grandNode !== null) {
  7798. var grandTag = grandNode.tag;
  7799. if (grandTag === HostRoot || grandTag === HostPortal) {
  7800. var grandContainer = grandNode.stateNode.containerInfo;
  7801. if (isMatchingRootContainer(grandContainer, targetContainerNode)) {
  7802. // This is the rootContainer we're looking for and we found it as
  7803. // a parent of the Portal. That means we can ignore it because the
  7804. // Portal will bubble through to us.
  7805. return;
  7806. }
  7807. }
  7808. grandNode = grandNode.return;
  7809. }
  7810. } // Now we need to find it's corresponding host fiber in the other
  7811. // tree. To do this we can use getClosestInstanceFromNode, but we
  7812. // need to validate that the fiber is a host instance, otherwise
  7813. // we need to traverse up through the DOM till we find the correct
  7814. // node that is from the other tree.
  7815. while (container !== null) {
  7816. var parentNode = getClosestInstanceFromNode(container);
  7817. if (parentNode === null) {
  7818. return;
  7819. }
  7820. var parentTag = parentNode.tag;
  7821. if (parentTag === HostComponent || parentTag === HostText) {
  7822. node = ancestorInst = parentNode;
  7823. continue mainLoop;
  7824. }
  7825. container = container.parentNode;
  7826. }
  7827. }
  7828. node = node.return;
  7829. }
  7830. }
  7831. }
  7832. batchedUpdates(function () {
  7833. return dispatchEventsForPlugins(domEventName, eventSystemFlags, nativeEvent, ancestorInst);
  7834. });
  7835. }
  7836. function createDispatchListener(instance, listener, currentTarget) {
  7837. return {
  7838. instance: instance,
  7839. listener: listener,
  7840. currentTarget: currentTarget
  7841. };
  7842. }
  7843. function accumulateSinglePhaseListeners(targetFiber, reactName, nativeEventType, inCapturePhase, accumulateTargetOnly, nativeEvent) {
  7844. var captureName = reactName !== null ? reactName + 'Capture' : null;
  7845. var reactEventName = inCapturePhase ? captureName : reactName;
  7846. var listeners = [];
  7847. var instance = targetFiber;
  7848. var lastHostComponent = null; // Accumulate all instances and listeners via the target -> root path.
  7849. while (instance !== null) {
  7850. var _instance2 = instance,
  7851. stateNode = _instance2.stateNode,
  7852. tag = _instance2.tag; // Handle listeners that are on HostComponents (i.e. <div>)
  7853. if (tag === HostComponent && stateNode !== null) {
  7854. lastHostComponent = stateNode; // createEventHandle listeners
  7855. if (reactEventName !== null) {
  7856. var listener = getListener(instance, reactEventName);
  7857. if (listener != null) {
  7858. listeners.push(createDispatchListener(instance, listener, lastHostComponent));
  7859. }
  7860. }
  7861. } // If we are only accumulating events for the target, then we don't
  7862. // continue to propagate through the React fiber tree to find other
  7863. // listeners.
  7864. if (accumulateTargetOnly) {
  7865. break;
  7866. } // If we are processing the onBeforeBlur event, then we need to take
  7867. instance = instance.return;
  7868. }
  7869. return listeners;
  7870. } // We should only use this function for:
  7871. // - BeforeInputEventPlugin
  7872. // - ChangeEventPlugin
  7873. // - SelectEventPlugin
  7874. // This is because we only process these plugins
  7875. // in the bubble phase, so we need to accumulate two
  7876. // phase event listeners (via emulation).
  7877. function accumulateTwoPhaseListeners(targetFiber, reactName) {
  7878. var captureName = reactName + 'Capture';
  7879. var listeners = [];
  7880. var instance = targetFiber; // Accumulate all instances and listeners via the target -> root path.
  7881. while (instance !== null) {
  7882. var _instance3 = instance,
  7883. stateNode = _instance3.stateNode,
  7884. tag = _instance3.tag; // Handle listeners that are on HostComponents (i.e. <div>)
  7885. if (tag === HostComponent && stateNode !== null) {
  7886. var currentTarget = stateNode;
  7887. var captureListener = getListener(instance, captureName);
  7888. if (captureListener != null) {
  7889. listeners.unshift(createDispatchListener(instance, captureListener, currentTarget));
  7890. }
  7891. var bubbleListener = getListener(instance, reactName);
  7892. if (bubbleListener != null) {
  7893. listeners.push(createDispatchListener(instance, bubbleListener, currentTarget));
  7894. }
  7895. }
  7896. instance = instance.return;
  7897. }
  7898. return listeners;
  7899. }
  7900. function getParent(inst) {
  7901. if (inst === null) {
  7902. return null;
  7903. }
  7904. do {
  7905. inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
  7906. // That is depending on if we want nested subtrees (layers) to bubble
  7907. // events to their parent. We could also go through parentNode on the
  7908. // host node but that wouldn't work for React Native and doesn't let us
  7909. // do the portal feature.
  7910. } while (inst && inst.tag !== HostComponent);
  7911. if (inst) {
  7912. return inst;
  7913. }
  7914. return null;
  7915. }
  7916. /**
  7917. * Return the lowest common ancestor of A and B, or null if they are in
  7918. * different trees.
  7919. */
  7920. function getLowestCommonAncestor(instA, instB) {
  7921. var nodeA = instA;
  7922. var nodeB = instB;
  7923. var depthA = 0;
  7924. for (var tempA = nodeA; tempA; tempA = getParent(tempA)) {
  7925. depthA++;
  7926. }
  7927. var depthB = 0;
  7928. for (var tempB = nodeB; tempB; tempB = getParent(tempB)) {
  7929. depthB++;
  7930. } // If A is deeper, crawl up.
  7931. while (depthA - depthB > 0) {
  7932. nodeA = getParent(nodeA);
  7933. depthA--;
  7934. } // If B is deeper, crawl up.
  7935. while (depthB - depthA > 0) {
  7936. nodeB = getParent(nodeB);
  7937. depthB--;
  7938. } // Walk in lockstep until we find a match.
  7939. var depth = depthA;
  7940. while (depth--) {
  7941. if (nodeA === nodeB || nodeB !== null && nodeA === nodeB.alternate) {
  7942. return nodeA;
  7943. }
  7944. nodeA = getParent(nodeA);
  7945. nodeB = getParent(nodeB);
  7946. }
  7947. return null;
  7948. }
  7949. function accumulateEnterLeaveListenersForEvent(dispatchQueue, event, target, common, inCapturePhase) {
  7950. var registrationName = event._reactName;
  7951. var listeners = [];
  7952. var instance = target;
  7953. while (instance !== null) {
  7954. if (instance === common) {
  7955. break;
  7956. }
  7957. var _instance4 = instance,
  7958. alternate = _instance4.alternate,
  7959. stateNode = _instance4.stateNode,
  7960. tag = _instance4.tag;
  7961. if (alternate !== null && alternate === common) {
  7962. break;
  7963. }
  7964. if (tag === HostComponent && stateNode !== null) {
  7965. var currentTarget = stateNode;
  7966. if (inCapturePhase) {
  7967. var captureListener = getListener(instance, registrationName);
  7968. if (captureListener != null) {
  7969. listeners.unshift(createDispatchListener(instance, captureListener, currentTarget));
  7970. }
  7971. } else if (!inCapturePhase) {
  7972. var bubbleListener = getListener(instance, registrationName);
  7973. if (bubbleListener != null) {
  7974. listeners.push(createDispatchListener(instance, bubbleListener, currentTarget));
  7975. }
  7976. }
  7977. }
  7978. instance = instance.return;
  7979. }
  7980. if (listeners.length !== 0) {
  7981. dispatchQueue.push({
  7982. event: event,
  7983. listeners: listeners
  7984. });
  7985. }
  7986. } // We should only use this function for:
  7987. // - EnterLeaveEventPlugin
  7988. // This is because we only process this plugin
  7989. // in the bubble phase, so we need to accumulate two
  7990. // phase event listeners.
  7991. function accumulateEnterLeaveTwoPhaseListeners(dispatchQueue, leaveEvent, enterEvent, from, to) {
  7992. var common = from && to ? getLowestCommonAncestor(from, to) : null;
  7993. if (from !== null) {
  7994. accumulateEnterLeaveListenersForEvent(dispatchQueue, leaveEvent, from, common, false);
  7995. }
  7996. if (to !== null && enterEvent !== null) {
  7997. accumulateEnterLeaveListenersForEvent(dispatchQueue, enterEvent, to, common, true);
  7998. }
  7999. }
  8000. function getListenerSetKey(domEventName, capture) {
  8001. return domEventName + "__" + (capture ? 'capture' : 'bubble');
  8002. }
  8003. var didWarnInvalidHydration = false;
  8004. var DANGEROUSLY_SET_INNER_HTML = 'dangerouslySetInnerHTML';
  8005. var SUPPRESS_CONTENT_EDITABLE_WARNING = 'suppressContentEditableWarning';
  8006. var SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
  8007. var AUTOFOCUS = 'autoFocus';
  8008. var CHILDREN = 'children';
  8009. var STYLE = 'style';
  8010. var HTML$1 = '__html';
  8011. var warnedUnknownTags;
  8012. var validatePropertiesInDevelopment;
  8013. var warnForPropDifference;
  8014. var warnForExtraAttributes;
  8015. var warnForInvalidEventListener;
  8016. var canDiffStyleForHydrationWarning;
  8017. var normalizeHTML;
  8018. {
  8019. warnedUnknownTags = {
  8020. // There are working polyfills for <dialog>. Let people use it.
  8021. dialog: true,
  8022. // Electron ships a custom <webview> tag to display external web content in
  8023. // an isolated frame and process.
  8024. // This tag is not present in non Electron environments such as JSDom which
  8025. // is often used for testing purposes.
  8026. // @see https://electronjs.org/docs/api/webview-tag
  8027. webview: true
  8028. };
  8029. validatePropertiesInDevelopment = function (type, props) {
  8030. validateProperties(type, props);
  8031. validateProperties$1(type, props);
  8032. validateProperties$2(type, props, {
  8033. registrationNameDependencies: registrationNameDependencies,
  8034. possibleRegistrationNames: possibleRegistrationNames
  8035. });
  8036. }; // IE 11 parses & normalizes the style attribute as opposed to other
  8037. // browsers. It adds spaces and sorts the properties in some
  8038. // non-alphabetical order. Handling that would require sorting CSS
  8039. // properties in the client & server versions or applying
  8040. // `expectedStyle` to a temporary DOM node to read its `style` attribute
  8041. // normalized. Since it only affects IE, we're skipping style warnings
  8042. // in that browser completely in favor of doing all that work.
  8043. // See https://github.com/facebook/react/issues/11807
  8044. canDiffStyleForHydrationWarning = canUseDOM && !document.documentMode;
  8045. warnForPropDifference = function (propName, serverValue, clientValue) {
  8046. if (didWarnInvalidHydration) {
  8047. return;
  8048. }
  8049. var normalizedClientValue = normalizeMarkupForTextOrAttribute(clientValue);
  8050. var normalizedServerValue = normalizeMarkupForTextOrAttribute(serverValue);
  8051. if (normalizedServerValue === normalizedClientValue) {
  8052. return;
  8053. }
  8054. didWarnInvalidHydration = true;
  8055. error('Prop `%s` did not match. Server: %s Client: %s', propName, JSON.stringify(normalizedServerValue), JSON.stringify(normalizedClientValue));
  8056. };
  8057. warnForExtraAttributes = function (attributeNames) {
  8058. if (didWarnInvalidHydration) {
  8059. return;
  8060. }
  8061. didWarnInvalidHydration = true;
  8062. var names = [];
  8063. attributeNames.forEach(function (name) {
  8064. names.push(name);
  8065. });
  8066. error('Extra attributes from the server: %s', names);
  8067. };
  8068. warnForInvalidEventListener = function (registrationName, listener) {
  8069. if (listener === false) {
  8070. error('Expected `%s` listener to be a function, instead got `false`.\n\n' + 'If you used to conditionally omit it with %s={condition && value}, ' + 'pass %s={condition ? value : undefined} instead.', registrationName, registrationName, registrationName);
  8071. } else {
  8072. error('Expected `%s` listener to be a function, instead got a value of `%s` type.', registrationName, typeof listener);
  8073. }
  8074. }; // Parse the HTML and read it back to normalize the HTML string so that it
  8075. // can be used for comparison.
  8076. normalizeHTML = function (parent, html) {
  8077. // We could have created a separate document here to avoid
  8078. // re-initializing custom elements if they exist. But this breaks
  8079. // how <noscript> is being handled. So we use the same document.
  8080. // See the discussion in https://github.com/facebook/react/pull/11157.
  8081. var testElement = parent.namespaceURI === HTML_NAMESPACE ? parent.ownerDocument.createElement(parent.tagName) : parent.ownerDocument.createElementNS(parent.namespaceURI, parent.tagName);
  8082. testElement.innerHTML = html;
  8083. return testElement.innerHTML;
  8084. };
  8085. } // HTML parsing normalizes CR and CRLF to LF.
  8086. // It also can turn \u0000 into \uFFFD inside attributes.
  8087. // https://www.w3.org/TR/html5/single-page.html#preprocessing-the-input-stream
  8088. // If we have a mismatch, it might be caused by that.
  8089. // We will still patch up in this case but not fire the warning.
  8090. var NORMALIZE_NEWLINES_REGEX = /\r\n?/g;
  8091. var NORMALIZE_NULL_AND_REPLACEMENT_REGEX = /\u0000|\uFFFD/g;
  8092. function normalizeMarkupForTextOrAttribute(markup) {
  8093. {
  8094. checkHtmlStringCoercion(markup);
  8095. }
  8096. var markupString = typeof markup === 'string' ? markup : '' + markup;
  8097. return markupString.replace(NORMALIZE_NEWLINES_REGEX, '\n').replace(NORMALIZE_NULL_AND_REPLACEMENT_REGEX, '');
  8098. }
  8099. function checkForUnmatchedText(serverText, clientText, isConcurrentMode, shouldWarnDev) {
  8100. var normalizedClientText = normalizeMarkupForTextOrAttribute(clientText);
  8101. var normalizedServerText = normalizeMarkupForTextOrAttribute(serverText);
  8102. if (normalizedServerText === normalizedClientText) {
  8103. return;
  8104. }
  8105. if (shouldWarnDev) {
  8106. {
  8107. if (!didWarnInvalidHydration) {
  8108. didWarnInvalidHydration = true;
  8109. error('Text content did not match. Server: "%s" Client: "%s"', normalizedServerText, normalizedClientText);
  8110. }
  8111. }
  8112. }
  8113. if (isConcurrentMode && enableClientRenderFallbackOnTextMismatch) {
  8114. // In concurrent roots, we throw when there's a text mismatch and revert to
  8115. // client rendering, up to the nearest Suspense boundary.
  8116. throw new Error('Text content does not match server-rendered HTML.');
  8117. }
  8118. }
  8119. function getOwnerDocumentFromRootContainer(rootContainerElement) {
  8120. return rootContainerElement.nodeType === DOCUMENT_NODE ? rootContainerElement : rootContainerElement.ownerDocument;
  8121. }
  8122. function noop() {}
  8123. function trapClickOnNonInteractiveElement(node) {
  8124. // Mobile Safari does not fire properly bubble click events on
  8125. // non-interactive elements, which means delegated click listeners do not
  8126. // fire. The workaround for this bug involves attaching an empty click
  8127. // listener on the target node.
  8128. // https://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
  8129. // Just set it using the onclick property so that we don't have to manage any
  8130. // bookkeeping for it. Not sure if we need to clear it when the listener is
  8131. // removed.
  8132. // TODO: Only do this for the relevant Safaris maybe?
  8133. node.onclick = noop;
  8134. }
  8135. function setInitialDOMProperties(tag, domElement, rootContainerElement, nextProps, isCustomComponentTag) {
  8136. for (var propKey in nextProps) {
  8137. if (!nextProps.hasOwnProperty(propKey)) {
  8138. continue;
  8139. }
  8140. var nextProp = nextProps[propKey];
  8141. if (propKey === STYLE) {
  8142. {
  8143. if (nextProp) {
  8144. // Freeze the next style object so that we can assume it won't be
  8145. // mutated. We have already warned for this in the past.
  8146. Object.freeze(nextProp);
  8147. }
  8148. } // Relies on `updateStylesByID` not mutating `styleUpdates`.
  8149. setValueForStyles(domElement, nextProp);
  8150. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  8151. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  8152. if (nextHtml != null) {
  8153. setInnerHTML(domElement, nextHtml);
  8154. }
  8155. } else if (propKey === CHILDREN) {
  8156. if (typeof nextProp === 'string') {
  8157. // Avoid setting initial textContent when the text is empty. In IE11 setting
  8158. // textContent on a <textarea> will cause the placeholder to not
  8159. // show within the <textarea> until it has been focused and blurred again.
  8160. // https://github.com/facebook/react/issues/6731#issuecomment-254874553
  8161. var canSetTextContent = tag !== 'textarea' || nextProp !== '';
  8162. if (canSetTextContent) {
  8163. setTextContent(domElement, nextProp);
  8164. }
  8165. } else if (typeof nextProp === 'number') {
  8166. setTextContent(domElement, '' + nextProp);
  8167. }
  8168. } else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (propKey === AUTOFOCUS) ; else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  8169. if (nextProp != null) {
  8170. if ( typeof nextProp !== 'function') {
  8171. warnForInvalidEventListener(propKey, nextProp);
  8172. }
  8173. if (propKey === 'onScroll') {
  8174. listenToNonDelegatedEvent('scroll', domElement);
  8175. }
  8176. }
  8177. } else if (nextProp != null) {
  8178. setValueForProperty(domElement, propKey, nextProp, isCustomComponentTag);
  8179. }
  8180. }
  8181. }
  8182. function updateDOMProperties(domElement, updatePayload, wasCustomComponentTag, isCustomComponentTag) {
  8183. // TODO: Handle wasCustomComponentTag
  8184. for (var i = 0; i < updatePayload.length; i += 2) {
  8185. var propKey = updatePayload[i];
  8186. var propValue = updatePayload[i + 1];
  8187. if (propKey === STYLE) {
  8188. setValueForStyles(domElement, propValue);
  8189. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  8190. setInnerHTML(domElement, propValue);
  8191. } else if (propKey === CHILDREN) {
  8192. setTextContent(domElement, propValue);
  8193. } else {
  8194. setValueForProperty(domElement, propKey, propValue, isCustomComponentTag);
  8195. }
  8196. }
  8197. }
  8198. function createElement(type, props, rootContainerElement, parentNamespace) {
  8199. var isCustomComponentTag; // We create tags in the namespace of their parent container, except HTML
  8200. // tags get no namespace.
  8201. var ownerDocument = getOwnerDocumentFromRootContainer(rootContainerElement);
  8202. var domElement;
  8203. var namespaceURI = parentNamespace;
  8204. if (namespaceURI === HTML_NAMESPACE) {
  8205. namespaceURI = getIntrinsicNamespace(type);
  8206. }
  8207. if (namespaceURI === HTML_NAMESPACE) {
  8208. {
  8209. isCustomComponentTag = isCustomComponent(type, props); // Should this check be gated by parent namespace? Not sure we want to
  8210. // allow <SVG> or <mATH>.
  8211. if (!isCustomComponentTag && type !== type.toLowerCase()) {
  8212. error('<%s /> is using incorrect casing. ' + 'Use PascalCase for React components, ' + 'or lowercase for HTML elements.', type);
  8213. }
  8214. }
  8215. if (type === 'script') {
  8216. // Create the script via .innerHTML so its "parser-inserted" flag is
  8217. // set to true and it does not execute
  8218. var div = ownerDocument.createElement('div');
  8219. div.innerHTML = '<script><' + '/script>'; // eslint-disable-line
  8220. // This is guaranteed to yield a script element.
  8221. var firstChild = div.firstChild;
  8222. domElement = div.removeChild(firstChild);
  8223. } else if (typeof props.is === 'string') {
  8224. // $FlowIssue `createElement` should be updated for Web Components
  8225. domElement = ownerDocument.createElement(type, {
  8226. is: props.is
  8227. });
  8228. } else {
  8229. // Separate else branch instead of using `props.is || undefined` above because of a Firefox bug.
  8230. // See discussion in https://github.com/facebook/react/pull/6896
  8231. // and discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1276240
  8232. domElement = ownerDocument.createElement(type); // Normally attributes are assigned in `setInitialDOMProperties`, however the `multiple` and `size`
  8233. // attributes on `select`s needs to be added before `option`s are inserted.
  8234. // This prevents:
  8235. // - a bug where the `select` does not scroll to the correct option because singular
  8236. // `select` elements automatically pick the first item #13222
  8237. // - a bug where the `select` set the first item as selected despite the `size` attribute #14239
  8238. // See https://github.com/facebook/react/issues/13222
  8239. // and https://github.com/facebook/react/issues/14239
  8240. if (type === 'select') {
  8241. var node = domElement;
  8242. if (props.multiple) {
  8243. node.multiple = true;
  8244. } else if (props.size) {
  8245. // Setting a size greater than 1 causes a select to behave like `multiple=true`, where
  8246. // it is possible that no option is selected.
  8247. //
  8248. // This is only necessary when a select in "single selection mode".
  8249. node.size = props.size;
  8250. }
  8251. }
  8252. }
  8253. } else {
  8254. domElement = ownerDocument.createElementNS(namespaceURI, type);
  8255. }
  8256. {
  8257. if (namespaceURI === HTML_NAMESPACE) {
  8258. if (!isCustomComponentTag && Object.prototype.toString.call(domElement) === '[object HTMLUnknownElement]' && !hasOwnProperty.call(warnedUnknownTags, type)) {
  8259. warnedUnknownTags[type] = true;
  8260. error('The tag <%s> is unrecognized in this browser. ' + 'If you meant to render a React component, start its name with ' + 'an uppercase letter.', type);
  8261. }
  8262. }
  8263. }
  8264. return domElement;
  8265. }
  8266. function createTextNode(text, rootContainerElement) {
  8267. return getOwnerDocumentFromRootContainer(rootContainerElement).createTextNode(text);
  8268. }
  8269. function setInitialProperties(domElement, tag, rawProps, rootContainerElement) {
  8270. var isCustomComponentTag = isCustomComponent(tag, rawProps);
  8271. {
  8272. validatePropertiesInDevelopment(tag, rawProps);
  8273. } // TODO: Make sure that we check isMounted before firing any of these events.
  8274. var props;
  8275. switch (tag) {
  8276. case 'dialog':
  8277. listenToNonDelegatedEvent('cancel', domElement);
  8278. listenToNonDelegatedEvent('close', domElement);
  8279. props = rawProps;
  8280. break;
  8281. case 'iframe':
  8282. case 'object':
  8283. case 'embed':
  8284. // We listen to this event in case to ensure emulated bubble
  8285. // listeners still fire for the load event.
  8286. listenToNonDelegatedEvent('load', domElement);
  8287. props = rawProps;
  8288. break;
  8289. case 'video':
  8290. case 'audio':
  8291. // We listen to these events in case to ensure emulated bubble
  8292. // listeners still fire for all the media events.
  8293. for (var i = 0; i < mediaEventTypes.length; i++) {
  8294. listenToNonDelegatedEvent(mediaEventTypes[i], domElement);
  8295. }
  8296. props = rawProps;
  8297. break;
  8298. case 'source':
  8299. // We listen to this event in case to ensure emulated bubble
  8300. // listeners still fire for the error event.
  8301. listenToNonDelegatedEvent('error', domElement);
  8302. props = rawProps;
  8303. break;
  8304. case 'img':
  8305. case 'image':
  8306. case 'link':
  8307. // We listen to these events in case to ensure emulated bubble
  8308. // listeners still fire for error and load events.
  8309. listenToNonDelegatedEvent('error', domElement);
  8310. listenToNonDelegatedEvent('load', domElement);
  8311. props = rawProps;
  8312. break;
  8313. case 'details':
  8314. // We listen to this event in case to ensure emulated bubble
  8315. // listeners still fire for the toggle event.
  8316. listenToNonDelegatedEvent('toggle', domElement);
  8317. props = rawProps;
  8318. break;
  8319. case 'input':
  8320. initWrapperState(domElement, rawProps);
  8321. props = getHostProps(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  8322. // listeners still fire for the invalid event.
  8323. listenToNonDelegatedEvent('invalid', domElement);
  8324. break;
  8325. case 'option':
  8326. validateProps(domElement, rawProps);
  8327. props = rawProps;
  8328. break;
  8329. case 'select':
  8330. initWrapperState$1(domElement, rawProps);
  8331. props = getHostProps$1(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  8332. // listeners still fire for the invalid event.
  8333. listenToNonDelegatedEvent('invalid', domElement);
  8334. break;
  8335. case 'textarea':
  8336. initWrapperState$2(domElement, rawProps);
  8337. props = getHostProps$2(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  8338. // listeners still fire for the invalid event.
  8339. listenToNonDelegatedEvent('invalid', domElement);
  8340. break;
  8341. default:
  8342. props = rawProps;
  8343. }
  8344. assertValidProps(tag, props);
  8345. setInitialDOMProperties(tag, domElement, rootContainerElement, props, isCustomComponentTag);
  8346. switch (tag) {
  8347. case 'input':
  8348. // TODO: Make sure we check if this is still unmounted or do any clean
  8349. // up necessary since we never stop tracking anymore.
  8350. track(domElement);
  8351. postMountWrapper(domElement, rawProps, false);
  8352. break;
  8353. case 'textarea':
  8354. // TODO: Make sure we check if this is still unmounted or do any clean
  8355. // up necessary since we never stop tracking anymore.
  8356. track(domElement);
  8357. postMountWrapper$3(domElement);
  8358. break;
  8359. case 'option':
  8360. postMountWrapper$1(domElement, rawProps);
  8361. break;
  8362. case 'select':
  8363. postMountWrapper$2(domElement, rawProps);
  8364. break;
  8365. default:
  8366. if (typeof props.onClick === 'function') {
  8367. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  8368. trapClickOnNonInteractiveElement(domElement);
  8369. }
  8370. break;
  8371. }
  8372. } // Calculate the diff between the two objects.
  8373. function diffProperties(domElement, tag, lastRawProps, nextRawProps, rootContainerElement) {
  8374. {
  8375. validatePropertiesInDevelopment(tag, nextRawProps);
  8376. }
  8377. var updatePayload = null;
  8378. var lastProps;
  8379. var nextProps;
  8380. switch (tag) {
  8381. case 'input':
  8382. lastProps = getHostProps(domElement, lastRawProps);
  8383. nextProps = getHostProps(domElement, nextRawProps);
  8384. updatePayload = [];
  8385. break;
  8386. case 'select':
  8387. lastProps = getHostProps$1(domElement, lastRawProps);
  8388. nextProps = getHostProps$1(domElement, nextRawProps);
  8389. updatePayload = [];
  8390. break;
  8391. case 'textarea':
  8392. lastProps = getHostProps$2(domElement, lastRawProps);
  8393. nextProps = getHostProps$2(domElement, nextRawProps);
  8394. updatePayload = [];
  8395. break;
  8396. default:
  8397. lastProps = lastRawProps;
  8398. nextProps = nextRawProps;
  8399. if (typeof lastProps.onClick !== 'function' && typeof nextProps.onClick === 'function') {
  8400. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  8401. trapClickOnNonInteractiveElement(domElement);
  8402. }
  8403. break;
  8404. }
  8405. assertValidProps(tag, nextProps);
  8406. var propKey;
  8407. var styleName;
  8408. var styleUpdates = null;
  8409. for (propKey in lastProps) {
  8410. if (nextProps.hasOwnProperty(propKey) || !lastProps.hasOwnProperty(propKey) || lastProps[propKey] == null) {
  8411. continue;
  8412. }
  8413. if (propKey === STYLE) {
  8414. var lastStyle = lastProps[propKey];
  8415. for (styleName in lastStyle) {
  8416. if (lastStyle.hasOwnProperty(styleName)) {
  8417. if (!styleUpdates) {
  8418. styleUpdates = {};
  8419. }
  8420. styleUpdates[styleName] = '';
  8421. }
  8422. }
  8423. } else if (propKey === DANGEROUSLY_SET_INNER_HTML || propKey === CHILDREN) ; else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (propKey === AUTOFOCUS) ; else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  8424. // This is a special case. If any listener updates we need to ensure
  8425. // that the "current" fiber pointer gets updated so we need a commit
  8426. // to update this element.
  8427. if (!updatePayload) {
  8428. updatePayload = [];
  8429. }
  8430. } else {
  8431. // For all other deleted properties we add it to the queue. We use
  8432. // the allowed property list in the commit phase instead.
  8433. (updatePayload = updatePayload || []).push(propKey, null);
  8434. }
  8435. }
  8436. for (propKey in nextProps) {
  8437. var nextProp = nextProps[propKey];
  8438. var lastProp = lastProps != null ? lastProps[propKey] : undefined;
  8439. if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp || nextProp == null && lastProp == null) {
  8440. continue;
  8441. }
  8442. if (propKey === STYLE) {
  8443. {
  8444. if (nextProp) {
  8445. // Freeze the next style object so that we can assume it won't be
  8446. // mutated. We have already warned for this in the past.
  8447. Object.freeze(nextProp);
  8448. }
  8449. }
  8450. if (lastProp) {
  8451. // Unset styles on `lastProp` but not on `nextProp`.
  8452. for (styleName in lastProp) {
  8453. if (lastProp.hasOwnProperty(styleName) && (!nextProp || !nextProp.hasOwnProperty(styleName))) {
  8454. if (!styleUpdates) {
  8455. styleUpdates = {};
  8456. }
  8457. styleUpdates[styleName] = '';
  8458. }
  8459. } // Update styles that changed since `lastProp`.
  8460. for (styleName in nextProp) {
  8461. if (nextProp.hasOwnProperty(styleName) && lastProp[styleName] !== nextProp[styleName]) {
  8462. if (!styleUpdates) {
  8463. styleUpdates = {};
  8464. }
  8465. styleUpdates[styleName] = nextProp[styleName];
  8466. }
  8467. }
  8468. } else {
  8469. // Relies on `updateStylesByID` not mutating `styleUpdates`.
  8470. if (!styleUpdates) {
  8471. if (!updatePayload) {
  8472. updatePayload = [];
  8473. }
  8474. updatePayload.push(propKey, styleUpdates);
  8475. }
  8476. styleUpdates = nextProp;
  8477. }
  8478. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  8479. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  8480. var lastHtml = lastProp ? lastProp[HTML$1] : undefined;
  8481. if (nextHtml != null) {
  8482. if (lastHtml !== nextHtml) {
  8483. (updatePayload = updatePayload || []).push(propKey, nextHtml);
  8484. }
  8485. }
  8486. } else if (propKey === CHILDREN) {
  8487. if (typeof nextProp === 'string' || typeof nextProp === 'number') {
  8488. (updatePayload = updatePayload || []).push(propKey, '' + nextProp);
  8489. }
  8490. } else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  8491. if (nextProp != null) {
  8492. // We eagerly listen to this even though we haven't committed yet.
  8493. if ( typeof nextProp !== 'function') {
  8494. warnForInvalidEventListener(propKey, nextProp);
  8495. }
  8496. if (propKey === 'onScroll') {
  8497. listenToNonDelegatedEvent('scroll', domElement);
  8498. }
  8499. }
  8500. if (!updatePayload && lastProp !== nextProp) {
  8501. // This is a special case. If any listener updates we need to ensure
  8502. // that the "current" props pointer gets updated so we need a commit
  8503. // to update this element.
  8504. updatePayload = [];
  8505. }
  8506. } else {
  8507. // For any other property we always add it to the queue and then we
  8508. // filter it out using the allowed property list during the commit.
  8509. (updatePayload = updatePayload || []).push(propKey, nextProp);
  8510. }
  8511. }
  8512. if (styleUpdates) {
  8513. {
  8514. validateShorthandPropertyCollisionInDev(styleUpdates, nextProps[STYLE]);
  8515. }
  8516. (updatePayload = updatePayload || []).push(STYLE, styleUpdates);
  8517. }
  8518. return updatePayload;
  8519. } // Apply the diff.
  8520. function updateProperties(domElement, updatePayload, tag, lastRawProps, nextRawProps) {
  8521. // Update checked *before* name.
  8522. // In the middle of an update, it is possible to have multiple checked.
  8523. // When a checked radio tries to change name, browser makes another radio's checked false.
  8524. if (tag === 'input' && nextRawProps.type === 'radio' && nextRawProps.name != null) {
  8525. updateChecked(domElement, nextRawProps);
  8526. }
  8527. var wasCustomComponentTag = isCustomComponent(tag, lastRawProps);
  8528. var isCustomComponentTag = isCustomComponent(tag, nextRawProps); // Apply the diff.
  8529. updateDOMProperties(domElement, updatePayload, wasCustomComponentTag, isCustomComponentTag); // TODO: Ensure that an update gets scheduled if any of the special props
  8530. // changed.
  8531. switch (tag) {
  8532. case 'input':
  8533. // Update the wrapper around inputs *after* updating props. This has to
  8534. // happen after `updateDOMProperties`. Otherwise HTML5 input validations
  8535. // raise warnings and prevent the new value from being assigned.
  8536. updateWrapper(domElement, nextRawProps);
  8537. break;
  8538. case 'textarea':
  8539. updateWrapper$1(domElement, nextRawProps);
  8540. break;
  8541. case 'select':
  8542. // <select> value update needs to occur after <option> children
  8543. // reconciliation
  8544. postUpdateWrapper(domElement, nextRawProps);
  8545. break;
  8546. }
  8547. }
  8548. function getPossibleStandardName(propName) {
  8549. {
  8550. var lowerCasedName = propName.toLowerCase();
  8551. if (!possibleStandardNames.hasOwnProperty(lowerCasedName)) {
  8552. return null;
  8553. }
  8554. return possibleStandardNames[lowerCasedName] || null;
  8555. }
  8556. }
  8557. function diffHydratedProperties(domElement, tag, rawProps, parentNamespace, rootContainerElement, isConcurrentMode, shouldWarnDev) {
  8558. var isCustomComponentTag;
  8559. var extraAttributeNames;
  8560. {
  8561. isCustomComponentTag = isCustomComponent(tag, rawProps);
  8562. validatePropertiesInDevelopment(tag, rawProps);
  8563. } // TODO: Make sure that we check isMounted before firing any of these events.
  8564. switch (tag) {
  8565. case 'dialog':
  8566. listenToNonDelegatedEvent('cancel', domElement);
  8567. listenToNonDelegatedEvent('close', domElement);
  8568. break;
  8569. case 'iframe':
  8570. case 'object':
  8571. case 'embed':
  8572. // We listen to this event in case to ensure emulated bubble
  8573. // listeners still fire for the load event.
  8574. listenToNonDelegatedEvent('load', domElement);
  8575. break;
  8576. case 'video':
  8577. case 'audio':
  8578. // We listen to these events in case to ensure emulated bubble
  8579. // listeners still fire for all the media events.
  8580. for (var i = 0; i < mediaEventTypes.length; i++) {
  8581. listenToNonDelegatedEvent(mediaEventTypes[i], domElement);
  8582. }
  8583. break;
  8584. case 'source':
  8585. // We listen to this event in case to ensure emulated bubble
  8586. // listeners still fire for the error event.
  8587. listenToNonDelegatedEvent('error', domElement);
  8588. break;
  8589. case 'img':
  8590. case 'image':
  8591. case 'link':
  8592. // We listen to these events in case to ensure emulated bubble
  8593. // listeners still fire for error and load events.
  8594. listenToNonDelegatedEvent('error', domElement);
  8595. listenToNonDelegatedEvent('load', domElement);
  8596. break;
  8597. case 'details':
  8598. // We listen to this event in case to ensure emulated bubble
  8599. // listeners still fire for the toggle event.
  8600. listenToNonDelegatedEvent('toggle', domElement);
  8601. break;
  8602. case 'input':
  8603. initWrapperState(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  8604. // listeners still fire for the invalid event.
  8605. listenToNonDelegatedEvent('invalid', domElement);
  8606. break;
  8607. case 'option':
  8608. validateProps(domElement, rawProps);
  8609. break;
  8610. case 'select':
  8611. initWrapperState$1(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  8612. // listeners still fire for the invalid event.
  8613. listenToNonDelegatedEvent('invalid', domElement);
  8614. break;
  8615. case 'textarea':
  8616. initWrapperState$2(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  8617. // listeners still fire for the invalid event.
  8618. listenToNonDelegatedEvent('invalid', domElement);
  8619. break;
  8620. }
  8621. assertValidProps(tag, rawProps);
  8622. {
  8623. extraAttributeNames = new Set();
  8624. var attributes = domElement.attributes;
  8625. for (var _i = 0; _i < attributes.length; _i++) {
  8626. var name = attributes[_i].name.toLowerCase();
  8627. switch (name) {
  8628. // Controlled attributes are not validated
  8629. // TODO: Only ignore them on controlled tags.
  8630. case 'value':
  8631. break;
  8632. case 'checked':
  8633. break;
  8634. case 'selected':
  8635. break;
  8636. default:
  8637. // Intentionally use the original name.
  8638. // See discussion in https://github.com/facebook/react/pull/10676.
  8639. extraAttributeNames.add(attributes[_i].name);
  8640. }
  8641. }
  8642. }
  8643. var updatePayload = null;
  8644. for (var propKey in rawProps) {
  8645. if (!rawProps.hasOwnProperty(propKey)) {
  8646. continue;
  8647. }
  8648. var nextProp = rawProps[propKey];
  8649. if (propKey === CHILDREN) {
  8650. // For text content children we compare against textContent. This
  8651. // might match additional HTML that is hidden when we read it using
  8652. // textContent. E.g. "foo" will match "f<span>oo</span>" but that still
  8653. // satisfies our requirement. Our requirement is not to produce perfect
  8654. // HTML and attributes. Ideally we should preserve structure but it's
  8655. // ok not to if the visible content is still enough to indicate what
  8656. // even listeners these nodes might be wired up to.
  8657. // TODO: Warn if there is more than a single textNode as a child.
  8658. // TODO: Should we use domElement.firstChild.nodeValue to compare?
  8659. if (typeof nextProp === 'string') {
  8660. if (domElement.textContent !== nextProp) {
  8661. if (rawProps[SUPPRESS_HYDRATION_WARNING] !== true) {
  8662. checkForUnmatchedText(domElement.textContent, nextProp, isConcurrentMode, shouldWarnDev);
  8663. }
  8664. updatePayload = [CHILDREN, nextProp];
  8665. }
  8666. } else if (typeof nextProp === 'number') {
  8667. if (domElement.textContent !== '' + nextProp) {
  8668. if (rawProps[SUPPRESS_HYDRATION_WARNING] !== true) {
  8669. checkForUnmatchedText(domElement.textContent, nextProp, isConcurrentMode, shouldWarnDev);
  8670. }
  8671. updatePayload = [CHILDREN, '' + nextProp];
  8672. }
  8673. }
  8674. } else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  8675. if (nextProp != null) {
  8676. if ( typeof nextProp !== 'function') {
  8677. warnForInvalidEventListener(propKey, nextProp);
  8678. }
  8679. if (propKey === 'onScroll') {
  8680. listenToNonDelegatedEvent('scroll', domElement);
  8681. }
  8682. }
  8683. } else if (shouldWarnDev && true && // Convince Flow we've calculated it (it's DEV-only in this method.)
  8684. typeof isCustomComponentTag === 'boolean') {
  8685. // Validate that the properties correspond to their expected values.
  8686. var serverValue = void 0;
  8687. var propertyInfo = isCustomComponentTag && enableCustomElementPropertySupport ? null : getPropertyInfo(propKey);
  8688. if (rawProps[SUPPRESS_HYDRATION_WARNING] === true) ; else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING || // Controlled attributes are not validated
  8689. // TODO: Only ignore them on controlled tags.
  8690. propKey === 'value' || propKey === 'checked' || propKey === 'selected') ; else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  8691. var serverHTML = domElement.innerHTML;
  8692. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  8693. if (nextHtml != null) {
  8694. var expectedHTML = normalizeHTML(domElement, nextHtml);
  8695. if (expectedHTML !== serverHTML) {
  8696. warnForPropDifference(propKey, serverHTML, expectedHTML);
  8697. }
  8698. }
  8699. } else if (propKey === STYLE) {
  8700. // $FlowFixMe - Should be inferred as not undefined.
  8701. extraAttributeNames.delete(propKey);
  8702. if (canDiffStyleForHydrationWarning) {
  8703. var expectedStyle = createDangerousStringForStyles(nextProp);
  8704. serverValue = domElement.getAttribute('style');
  8705. if (expectedStyle !== serverValue) {
  8706. warnForPropDifference(propKey, serverValue, expectedStyle);
  8707. }
  8708. }
  8709. } else if (isCustomComponentTag && !enableCustomElementPropertySupport) {
  8710. // $FlowFixMe - Should be inferred as not undefined.
  8711. extraAttributeNames.delete(propKey.toLowerCase());
  8712. serverValue = getValueForAttribute(domElement, propKey, nextProp);
  8713. if (nextProp !== serverValue) {
  8714. warnForPropDifference(propKey, serverValue, nextProp);
  8715. }
  8716. } else if (!shouldIgnoreAttribute(propKey, propertyInfo, isCustomComponentTag) && !shouldRemoveAttribute(propKey, nextProp, propertyInfo, isCustomComponentTag)) {
  8717. var isMismatchDueToBadCasing = false;
  8718. if (propertyInfo !== null) {
  8719. // $FlowFixMe - Should be inferred as not undefined.
  8720. extraAttributeNames.delete(propertyInfo.attributeName);
  8721. serverValue = getValueForProperty(domElement, propKey, nextProp, propertyInfo);
  8722. } else {
  8723. var ownNamespace = parentNamespace;
  8724. if (ownNamespace === HTML_NAMESPACE) {
  8725. ownNamespace = getIntrinsicNamespace(tag);
  8726. }
  8727. if (ownNamespace === HTML_NAMESPACE) {
  8728. // $FlowFixMe - Should be inferred as not undefined.
  8729. extraAttributeNames.delete(propKey.toLowerCase());
  8730. } else {
  8731. var standardName = getPossibleStandardName(propKey);
  8732. if (standardName !== null && standardName !== propKey) {
  8733. // If an SVG prop is supplied with bad casing, it will
  8734. // be successfully parsed from HTML, but will produce a mismatch
  8735. // (and would be incorrectly rendered on the client).
  8736. // However, we already warn about bad casing elsewhere.
  8737. // So we'll skip the misleading extra mismatch warning in this case.
  8738. isMismatchDueToBadCasing = true; // $FlowFixMe - Should be inferred as not undefined.
  8739. extraAttributeNames.delete(standardName);
  8740. } // $FlowFixMe - Should be inferred as not undefined.
  8741. extraAttributeNames.delete(propKey);
  8742. }
  8743. serverValue = getValueForAttribute(domElement, propKey, nextProp);
  8744. }
  8745. var dontWarnCustomElement = enableCustomElementPropertySupport ;
  8746. if (!dontWarnCustomElement && nextProp !== serverValue && !isMismatchDueToBadCasing) {
  8747. warnForPropDifference(propKey, serverValue, nextProp);
  8748. }
  8749. }
  8750. }
  8751. }
  8752. {
  8753. if (shouldWarnDev) {
  8754. if ( // $FlowFixMe - Should be inferred as not undefined.
  8755. extraAttributeNames.size > 0 && rawProps[SUPPRESS_HYDRATION_WARNING] !== true) {
  8756. // $FlowFixMe - Should be inferred as not undefined.
  8757. warnForExtraAttributes(extraAttributeNames);
  8758. }
  8759. }
  8760. }
  8761. switch (tag) {
  8762. case 'input':
  8763. // TODO: Make sure we check if this is still unmounted or do any clean
  8764. // up necessary since we never stop tracking anymore.
  8765. track(domElement);
  8766. postMountWrapper(domElement, rawProps, true);
  8767. break;
  8768. case 'textarea':
  8769. // TODO: Make sure we check if this is still unmounted or do any clean
  8770. // up necessary since we never stop tracking anymore.
  8771. track(domElement);
  8772. postMountWrapper$3(domElement);
  8773. break;
  8774. case 'select':
  8775. case 'option':
  8776. // For input and textarea we current always set the value property at
  8777. // post mount to force it to diverge from attributes. However, for
  8778. // option and select we don't quite do the same thing and select
  8779. // is not resilient to the DOM state changing so we don't do that here.
  8780. // TODO: Consider not doing this for input and textarea.
  8781. break;
  8782. default:
  8783. if (typeof rawProps.onClick === 'function') {
  8784. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  8785. trapClickOnNonInteractiveElement(domElement);
  8786. }
  8787. break;
  8788. }
  8789. return updatePayload;
  8790. }
  8791. function diffHydratedText(textNode, text, isConcurrentMode) {
  8792. var isDifferent = textNode.nodeValue !== text;
  8793. return isDifferent;
  8794. }
  8795. function warnForDeletedHydratableElement(parentNode, child) {
  8796. {
  8797. if (didWarnInvalidHydration) {
  8798. return;
  8799. }
  8800. didWarnInvalidHydration = true;
  8801. error('Did not expect server HTML to contain a <%s> in <%s>.', child.nodeName.toLowerCase(), parentNode.nodeName.toLowerCase());
  8802. }
  8803. }
  8804. function warnForDeletedHydratableText(parentNode, child) {
  8805. {
  8806. if (didWarnInvalidHydration) {
  8807. return;
  8808. }
  8809. didWarnInvalidHydration = true;
  8810. error('Did not expect server HTML to contain the text node "%s" in <%s>.', child.nodeValue, parentNode.nodeName.toLowerCase());
  8811. }
  8812. }
  8813. function warnForInsertedHydratedElement(parentNode, tag, props) {
  8814. {
  8815. if (didWarnInvalidHydration) {
  8816. return;
  8817. }
  8818. didWarnInvalidHydration = true;
  8819. error('Expected server HTML to contain a matching <%s> in <%s>.', tag, parentNode.nodeName.toLowerCase());
  8820. }
  8821. }
  8822. function warnForInsertedHydratedText(parentNode, text) {
  8823. {
  8824. if (text === '') {
  8825. // We expect to insert empty text nodes since they're not represented in
  8826. // the HTML.
  8827. // TODO: Remove this special case if we can just avoid inserting empty
  8828. // text nodes.
  8829. return;
  8830. }
  8831. if (didWarnInvalidHydration) {
  8832. return;
  8833. }
  8834. didWarnInvalidHydration = true;
  8835. error('Expected server HTML to contain a matching text node for "%s" in <%s>.', text, parentNode.nodeName.toLowerCase());
  8836. }
  8837. }
  8838. function restoreControlledState$3(domElement, tag, props) {
  8839. switch (tag) {
  8840. case 'input':
  8841. restoreControlledState(domElement, props);
  8842. return;
  8843. case 'textarea':
  8844. restoreControlledState$2(domElement, props);
  8845. return;
  8846. case 'select':
  8847. restoreControlledState$1(domElement, props);
  8848. return;
  8849. }
  8850. }
  8851. var validateDOMNesting = function () {};
  8852. var updatedAncestorInfo = function () {};
  8853. {
  8854. // This validation code was written based on the HTML5 parsing spec:
  8855. // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
  8856. //
  8857. // Note: this does not catch all invalid nesting, nor does it try to (as it's
  8858. // not clear what practical benefit doing so provides); instead, we warn only
  8859. // for cases where the parser will give a parse tree differing from what React
  8860. // intended. For example, <b><div></div></b> is invalid but we don't warn
  8861. // because it still parses correctly; we do warn for other cases like nested
  8862. // <p> tags where the beginning of the second element implicitly closes the
  8863. // first, causing a confusing mess.
  8864. // https://html.spec.whatwg.org/multipage/syntax.html#special
  8865. var specialTags = ['address', 'applet', 'area', 'article', 'aside', 'base', 'basefont', 'bgsound', 'blockquote', 'body', 'br', 'button', 'caption', 'center', 'col', 'colgroup', 'dd', 'details', 'dir', 'div', 'dl', 'dt', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'iframe', 'img', 'input', 'isindex', 'li', 'link', 'listing', 'main', 'marquee', 'menu', 'menuitem', 'meta', 'nav', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'p', 'param', 'plaintext', 'pre', 'script', 'section', 'select', 'source', 'style', 'summary', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul', 'wbr', 'xmp']; // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
  8866. var inScopeTags = ['applet', 'caption', 'html', 'table', 'td', 'th', 'marquee', 'object', 'template', // https://html.spec.whatwg.org/multipage/syntax.html#html-integration-point
  8867. // TODO: Distinguish by namespace here -- for <title>, including it here
  8868. // errs on the side of fewer warnings
  8869. 'foreignObject', 'desc', 'title']; // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-button-scope
  8870. var buttonScopeTags = inScopeTags.concat(['button']); // https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags
  8871. var impliedEndTags = ['dd', 'dt', 'li', 'option', 'optgroup', 'p', 'rp', 'rt'];
  8872. var emptyAncestorInfo = {
  8873. current: null,
  8874. formTag: null,
  8875. aTagInScope: null,
  8876. buttonTagInScope: null,
  8877. nobrTagInScope: null,
  8878. pTagInButtonScope: null,
  8879. listItemTagAutoclosing: null,
  8880. dlItemTagAutoclosing: null
  8881. };
  8882. updatedAncestorInfo = function (oldInfo, tag) {
  8883. var ancestorInfo = assign({}, oldInfo || emptyAncestorInfo);
  8884. var info = {
  8885. tag: tag
  8886. };
  8887. if (inScopeTags.indexOf(tag) !== -1) {
  8888. ancestorInfo.aTagInScope = null;
  8889. ancestorInfo.buttonTagInScope = null;
  8890. ancestorInfo.nobrTagInScope = null;
  8891. }
  8892. if (buttonScopeTags.indexOf(tag) !== -1) {
  8893. ancestorInfo.pTagInButtonScope = null;
  8894. } // See rules for 'li', 'dd', 'dt' start tags in
  8895. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
  8896. if (specialTags.indexOf(tag) !== -1 && tag !== 'address' && tag !== 'div' && tag !== 'p') {
  8897. ancestorInfo.listItemTagAutoclosing = null;
  8898. ancestorInfo.dlItemTagAutoclosing = null;
  8899. }
  8900. ancestorInfo.current = info;
  8901. if (tag === 'form') {
  8902. ancestorInfo.formTag = info;
  8903. }
  8904. if (tag === 'a') {
  8905. ancestorInfo.aTagInScope = info;
  8906. }
  8907. if (tag === 'button') {
  8908. ancestorInfo.buttonTagInScope = info;
  8909. }
  8910. if (tag === 'nobr') {
  8911. ancestorInfo.nobrTagInScope = info;
  8912. }
  8913. if (tag === 'p') {
  8914. ancestorInfo.pTagInButtonScope = info;
  8915. }
  8916. if (tag === 'li') {
  8917. ancestorInfo.listItemTagAutoclosing = info;
  8918. }
  8919. if (tag === 'dd' || tag === 'dt') {
  8920. ancestorInfo.dlItemTagAutoclosing = info;
  8921. }
  8922. return ancestorInfo;
  8923. };
  8924. /**
  8925. * Returns whether
  8926. */
  8927. var isTagValidWithParent = function (tag, parentTag) {
  8928. // First, let's check if we're in an unusual parsing mode...
  8929. switch (parentTag) {
  8930. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inselect
  8931. case 'select':
  8932. return tag === 'option' || tag === 'optgroup' || tag === '#text';
  8933. case 'optgroup':
  8934. return tag === 'option' || tag === '#text';
  8935. // Strictly speaking, seeing an <option> doesn't mean we're in a <select>
  8936. // but
  8937. case 'option':
  8938. return tag === '#text';
  8939. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd
  8940. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incaption
  8941. // No special behavior since these rules fall back to "in body" mode for
  8942. // all except special table nodes which cause bad parsing behavior anyway.
  8943. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intr
  8944. case 'tr':
  8945. return tag === 'th' || tag === 'td' || tag === 'style' || tag === 'script' || tag === 'template';
  8946. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intbody
  8947. case 'tbody':
  8948. case 'thead':
  8949. case 'tfoot':
  8950. return tag === 'tr' || tag === 'style' || tag === 'script' || tag === 'template';
  8951. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incolgroup
  8952. case 'colgroup':
  8953. return tag === 'col' || tag === 'template';
  8954. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intable
  8955. case 'table':
  8956. return tag === 'caption' || tag === 'colgroup' || tag === 'tbody' || tag === 'tfoot' || tag === 'thead' || tag === 'style' || tag === 'script' || tag === 'template';
  8957. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inhead
  8958. case 'head':
  8959. return tag === 'base' || tag === 'basefont' || tag === 'bgsound' || tag === 'link' || tag === 'meta' || tag === 'title' || tag === 'noscript' || tag === 'noframes' || tag === 'style' || tag === 'script' || tag === 'template';
  8960. // https://html.spec.whatwg.org/multipage/semantics.html#the-html-element
  8961. case 'html':
  8962. return tag === 'head' || tag === 'body' || tag === 'frameset';
  8963. case 'frameset':
  8964. return tag === 'frame';
  8965. case '#document':
  8966. return tag === 'html';
  8967. } // Probably in the "in body" parsing mode, so we outlaw only tag combos
  8968. // where the parsing rules cause implicit opens or closes to be added.
  8969. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
  8970. switch (tag) {
  8971. case 'h1':
  8972. case 'h2':
  8973. case 'h3':
  8974. case 'h4':
  8975. case 'h5':
  8976. case 'h6':
  8977. return parentTag !== 'h1' && parentTag !== 'h2' && parentTag !== 'h3' && parentTag !== 'h4' && parentTag !== 'h5' && parentTag !== 'h6';
  8978. case 'rp':
  8979. case 'rt':
  8980. return impliedEndTags.indexOf(parentTag) === -1;
  8981. case 'body':
  8982. case 'caption':
  8983. case 'col':
  8984. case 'colgroup':
  8985. case 'frameset':
  8986. case 'frame':
  8987. case 'head':
  8988. case 'html':
  8989. case 'tbody':
  8990. case 'td':
  8991. case 'tfoot':
  8992. case 'th':
  8993. case 'thead':
  8994. case 'tr':
  8995. // These tags are only valid with a few parents that have special child
  8996. // parsing rules -- if we're down here, then none of those matched and
  8997. // so we allow it only if we don't know what the parent is, as all other
  8998. // cases are invalid.
  8999. return parentTag == null;
  9000. }
  9001. return true;
  9002. };
  9003. /**
  9004. * Returns whether
  9005. */
  9006. var findInvalidAncestorForTag = function (tag, ancestorInfo) {
  9007. switch (tag) {
  9008. case 'address':
  9009. case 'article':
  9010. case 'aside':
  9011. case 'blockquote':
  9012. case 'center':
  9013. case 'details':
  9014. case 'dialog':
  9015. case 'dir':
  9016. case 'div':
  9017. case 'dl':
  9018. case 'fieldset':
  9019. case 'figcaption':
  9020. case 'figure':
  9021. case 'footer':
  9022. case 'header':
  9023. case 'hgroup':
  9024. case 'main':
  9025. case 'menu':
  9026. case 'nav':
  9027. case 'ol':
  9028. case 'p':
  9029. case 'section':
  9030. case 'summary':
  9031. case 'ul':
  9032. case 'pre':
  9033. case 'listing':
  9034. case 'table':
  9035. case 'hr':
  9036. case 'xmp':
  9037. case 'h1':
  9038. case 'h2':
  9039. case 'h3':
  9040. case 'h4':
  9041. case 'h5':
  9042. case 'h6':
  9043. return ancestorInfo.pTagInButtonScope;
  9044. case 'form':
  9045. return ancestorInfo.formTag || ancestorInfo.pTagInButtonScope;
  9046. case 'li':
  9047. return ancestorInfo.listItemTagAutoclosing;
  9048. case 'dd':
  9049. case 'dt':
  9050. return ancestorInfo.dlItemTagAutoclosing;
  9051. case 'button':
  9052. return ancestorInfo.buttonTagInScope;
  9053. case 'a':
  9054. // Spec says something about storing a list of markers, but it sounds
  9055. // equivalent to this check.
  9056. return ancestorInfo.aTagInScope;
  9057. case 'nobr':
  9058. return ancestorInfo.nobrTagInScope;
  9059. }
  9060. return null;
  9061. };
  9062. var didWarn$1 = {};
  9063. validateDOMNesting = function (childTag, childText, ancestorInfo) {
  9064. ancestorInfo = ancestorInfo || emptyAncestorInfo;
  9065. var parentInfo = ancestorInfo.current;
  9066. var parentTag = parentInfo && parentInfo.tag;
  9067. if (childText != null) {
  9068. if (childTag != null) {
  9069. error('validateDOMNesting: when childText is passed, childTag should be null');
  9070. }
  9071. childTag = '#text';
  9072. }
  9073. var invalidParent = isTagValidWithParent(childTag, parentTag) ? null : parentInfo;
  9074. var invalidAncestor = invalidParent ? null : findInvalidAncestorForTag(childTag, ancestorInfo);
  9075. var invalidParentOrAncestor = invalidParent || invalidAncestor;
  9076. if (!invalidParentOrAncestor) {
  9077. return;
  9078. }
  9079. var ancestorTag = invalidParentOrAncestor.tag;
  9080. var warnKey = !!invalidParent + '|' + childTag + '|' + ancestorTag;
  9081. if (didWarn$1[warnKey]) {
  9082. return;
  9083. }
  9084. didWarn$1[warnKey] = true;
  9085. var tagDisplayName = childTag;
  9086. var whitespaceInfo = '';
  9087. if (childTag === '#text') {
  9088. if (/\S/.test(childText)) {
  9089. tagDisplayName = 'Text nodes';
  9090. } else {
  9091. tagDisplayName = 'Whitespace text nodes';
  9092. whitespaceInfo = " Make sure you don't have any extra whitespace between tags on " + 'each line of your source code.';
  9093. }
  9094. } else {
  9095. tagDisplayName = '<' + childTag + '>';
  9096. }
  9097. if (invalidParent) {
  9098. var info = '';
  9099. if (ancestorTag === 'table' && childTag === 'tr') {
  9100. info += ' Add a <tbody>, <thead> or <tfoot> to your code to match the DOM tree generated by ' + 'the browser.';
  9101. }
  9102. error('validateDOMNesting(...): %s cannot appear as a child of <%s>.%s%s', tagDisplayName, ancestorTag, whitespaceInfo, info);
  9103. } else {
  9104. error('validateDOMNesting(...): %s cannot appear as a descendant of ' + '<%s>.', tagDisplayName, ancestorTag);
  9105. }
  9106. };
  9107. }
  9108. var SUPPRESS_HYDRATION_WARNING$1 = 'suppressHydrationWarning';
  9109. var SUSPENSE_START_DATA = '$';
  9110. var SUSPENSE_END_DATA = '/$';
  9111. var SUSPENSE_PENDING_START_DATA = '$?';
  9112. var SUSPENSE_FALLBACK_START_DATA = '$!';
  9113. var STYLE$1 = 'style';
  9114. var eventsEnabled = null;
  9115. var selectionInformation = null;
  9116. function getRootHostContext(rootContainerInstance) {
  9117. var type;
  9118. var namespace;
  9119. var nodeType = rootContainerInstance.nodeType;
  9120. switch (nodeType) {
  9121. case DOCUMENT_NODE:
  9122. case DOCUMENT_FRAGMENT_NODE:
  9123. {
  9124. type = nodeType === DOCUMENT_NODE ? '#document' : '#fragment';
  9125. var root = rootContainerInstance.documentElement;
  9126. namespace = root ? root.namespaceURI : getChildNamespace(null, '');
  9127. break;
  9128. }
  9129. default:
  9130. {
  9131. var container = nodeType === COMMENT_NODE ? rootContainerInstance.parentNode : rootContainerInstance;
  9132. var ownNamespace = container.namespaceURI || null;
  9133. type = container.tagName;
  9134. namespace = getChildNamespace(ownNamespace, type);
  9135. break;
  9136. }
  9137. }
  9138. {
  9139. var validatedTag = type.toLowerCase();
  9140. var ancestorInfo = updatedAncestorInfo(null, validatedTag);
  9141. return {
  9142. namespace: namespace,
  9143. ancestorInfo: ancestorInfo
  9144. };
  9145. }
  9146. }
  9147. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  9148. {
  9149. var parentHostContextDev = parentHostContext;
  9150. var namespace = getChildNamespace(parentHostContextDev.namespace, type);
  9151. var ancestorInfo = updatedAncestorInfo(parentHostContextDev.ancestorInfo, type);
  9152. return {
  9153. namespace: namespace,
  9154. ancestorInfo: ancestorInfo
  9155. };
  9156. }
  9157. }
  9158. function getPublicInstance(instance) {
  9159. return instance;
  9160. }
  9161. function prepareForCommit(containerInfo) {
  9162. eventsEnabled = isEnabled();
  9163. selectionInformation = getSelectionInformation();
  9164. var activeInstance = null;
  9165. setEnabled(false);
  9166. return activeInstance;
  9167. }
  9168. function resetAfterCommit(containerInfo) {
  9169. restoreSelection(selectionInformation);
  9170. setEnabled(eventsEnabled);
  9171. eventsEnabled = null;
  9172. selectionInformation = null;
  9173. }
  9174. function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
  9175. var parentNamespace;
  9176. {
  9177. // TODO: take namespace into account when validating.
  9178. var hostContextDev = hostContext;
  9179. validateDOMNesting(type, null, hostContextDev.ancestorInfo);
  9180. if (typeof props.children === 'string' || typeof props.children === 'number') {
  9181. var string = '' + props.children;
  9182. var ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type);
  9183. validateDOMNesting(null, string, ownAncestorInfo);
  9184. }
  9185. parentNamespace = hostContextDev.namespace;
  9186. }
  9187. var domElement = createElement(type, props, rootContainerInstance, parentNamespace);
  9188. precacheFiberNode(internalInstanceHandle, domElement);
  9189. updateFiberProps(domElement, props);
  9190. return domElement;
  9191. }
  9192. function appendInitialChild(parentInstance, child) {
  9193. parentInstance.appendChild(child);
  9194. }
  9195. function finalizeInitialChildren(domElement, type, props, rootContainerInstance, hostContext) {
  9196. setInitialProperties(domElement, type, props, rootContainerInstance);
  9197. switch (type) {
  9198. case 'button':
  9199. case 'input':
  9200. case 'select':
  9201. case 'textarea':
  9202. return !!props.autoFocus;
  9203. case 'img':
  9204. return true;
  9205. default:
  9206. return false;
  9207. }
  9208. }
  9209. function prepareUpdate(domElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
  9210. {
  9211. var hostContextDev = hostContext;
  9212. if (typeof newProps.children !== typeof oldProps.children && (typeof newProps.children === 'string' || typeof newProps.children === 'number')) {
  9213. var string = '' + newProps.children;
  9214. var ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type);
  9215. validateDOMNesting(null, string, ownAncestorInfo);
  9216. }
  9217. }
  9218. return diffProperties(domElement, type, oldProps, newProps);
  9219. }
  9220. function shouldSetTextContent(type, props) {
  9221. return type === 'textarea' || type === 'noscript' || typeof props.children === 'string' || typeof props.children === 'number' || typeof props.dangerouslySetInnerHTML === 'object' && props.dangerouslySetInnerHTML !== null && props.dangerouslySetInnerHTML.__html != null;
  9222. }
  9223. function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
  9224. {
  9225. var hostContextDev = hostContext;
  9226. validateDOMNesting(null, text, hostContextDev.ancestorInfo);
  9227. }
  9228. var textNode = createTextNode(text, rootContainerInstance);
  9229. precacheFiberNode(internalInstanceHandle, textNode);
  9230. return textNode;
  9231. }
  9232. function getCurrentEventPriority() {
  9233. var currentEvent = window.event;
  9234. if (currentEvent === undefined) {
  9235. return DefaultEventPriority;
  9236. }
  9237. return getEventPriority(currentEvent.type);
  9238. }
  9239. // if a component just imports ReactDOM (e.g. for findDOMNode).
  9240. // Some environments might not have setTimeout or clearTimeout.
  9241. var scheduleTimeout = typeof setTimeout === 'function' ? setTimeout : undefined;
  9242. var cancelTimeout = typeof clearTimeout === 'function' ? clearTimeout : undefined;
  9243. var noTimeout = -1;
  9244. var localPromise = typeof Promise === 'function' ? Promise : undefined; // -------------------
  9245. var scheduleMicrotask = typeof queueMicrotask === 'function' ? queueMicrotask : typeof localPromise !== 'undefined' ? function (callback) {
  9246. return localPromise.resolve(null).then(callback).catch(handleErrorInNextTick);
  9247. } : scheduleTimeout; // TODO: Determine the best fallback here.
  9248. function handleErrorInNextTick(error) {
  9249. setTimeout(function () {
  9250. throw error;
  9251. });
  9252. } // -------------------
  9253. function commitMount(domElement, type, newProps, internalInstanceHandle) {
  9254. // Despite the naming that might imply otherwise, this method only
  9255. // fires if there is an `Update` effect scheduled during mounting.
  9256. // This happens if `finalizeInitialChildren` returns `true` (which it
  9257. // does to implement the `autoFocus` attribute on the client). But
  9258. // there are also other cases when this might happen (such as patching
  9259. // up text content during hydration mismatch). So we'll check this again.
  9260. switch (type) {
  9261. case 'button':
  9262. case 'input':
  9263. case 'select':
  9264. case 'textarea':
  9265. if (newProps.autoFocus) {
  9266. domElement.focus();
  9267. }
  9268. return;
  9269. case 'img':
  9270. {
  9271. if (newProps.src) {
  9272. domElement.src = newProps.src;
  9273. }
  9274. return;
  9275. }
  9276. }
  9277. }
  9278. function commitUpdate(domElement, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
  9279. // Apply the diff to the DOM node.
  9280. updateProperties(domElement, updatePayload, type, oldProps, newProps); // Update the props handle so that we know which props are the ones with
  9281. // with current event handlers.
  9282. updateFiberProps(domElement, newProps);
  9283. }
  9284. function resetTextContent(domElement) {
  9285. setTextContent(domElement, '');
  9286. }
  9287. function commitTextUpdate(textInstance, oldText, newText) {
  9288. textInstance.nodeValue = newText;
  9289. }
  9290. function appendChild(parentInstance, child) {
  9291. parentInstance.appendChild(child);
  9292. }
  9293. function appendChildToContainer(container, child) {
  9294. var parentNode;
  9295. if (container.nodeType === COMMENT_NODE) {
  9296. parentNode = container.parentNode;
  9297. parentNode.insertBefore(child, container);
  9298. } else {
  9299. parentNode = container;
  9300. parentNode.appendChild(child);
  9301. } // This container might be used for a portal.
  9302. // If something inside a portal is clicked, that click should bubble
  9303. // through the React tree. However, on Mobile Safari the click would
  9304. // never bubble through the *DOM* tree unless an ancestor with onclick
  9305. // event exists. So we wouldn't see it and dispatch it.
  9306. // This is why we ensure that non React root containers have inline onclick
  9307. // defined.
  9308. // https://github.com/facebook/react/issues/11918
  9309. var reactRootContainer = container._reactRootContainer;
  9310. if ((reactRootContainer === null || reactRootContainer === undefined) && parentNode.onclick === null) {
  9311. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  9312. trapClickOnNonInteractiveElement(parentNode);
  9313. }
  9314. }
  9315. function insertBefore(parentInstance, child, beforeChild) {
  9316. parentInstance.insertBefore(child, beforeChild);
  9317. }
  9318. function insertInContainerBefore(container, child, beforeChild) {
  9319. if (container.nodeType === COMMENT_NODE) {
  9320. container.parentNode.insertBefore(child, beforeChild);
  9321. } else {
  9322. container.insertBefore(child, beforeChild);
  9323. }
  9324. }
  9325. function removeChild(parentInstance, child) {
  9326. parentInstance.removeChild(child);
  9327. }
  9328. function removeChildFromContainer(container, child) {
  9329. if (container.nodeType === COMMENT_NODE) {
  9330. container.parentNode.removeChild(child);
  9331. } else {
  9332. container.removeChild(child);
  9333. }
  9334. }
  9335. function clearSuspenseBoundary(parentInstance, suspenseInstance) {
  9336. var node = suspenseInstance; // Delete all nodes within this suspense boundary.
  9337. // There might be nested nodes so we need to keep track of how
  9338. // deep we are and only break out when we're back on top.
  9339. var depth = 0;
  9340. do {
  9341. var nextNode = node.nextSibling;
  9342. parentInstance.removeChild(node);
  9343. if (nextNode && nextNode.nodeType === COMMENT_NODE) {
  9344. var data = nextNode.data;
  9345. if (data === SUSPENSE_END_DATA) {
  9346. if (depth === 0) {
  9347. parentInstance.removeChild(nextNode); // Retry if any event replaying was blocked on this.
  9348. retryIfBlockedOn(suspenseInstance);
  9349. return;
  9350. } else {
  9351. depth--;
  9352. }
  9353. } else if (data === SUSPENSE_START_DATA || data === SUSPENSE_PENDING_START_DATA || data === SUSPENSE_FALLBACK_START_DATA) {
  9354. depth++;
  9355. }
  9356. }
  9357. node = nextNode;
  9358. } while (node); // TODO: Warn, we didn't find the end comment boundary.
  9359. // Retry if any event replaying was blocked on this.
  9360. retryIfBlockedOn(suspenseInstance);
  9361. }
  9362. function clearSuspenseBoundaryFromContainer(container, suspenseInstance) {
  9363. if (container.nodeType === COMMENT_NODE) {
  9364. clearSuspenseBoundary(container.parentNode, suspenseInstance);
  9365. } else if (container.nodeType === ELEMENT_NODE) {
  9366. clearSuspenseBoundary(container, suspenseInstance);
  9367. } // Retry if any event replaying was blocked on this.
  9368. retryIfBlockedOn(container);
  9369. }
  9370. function hideInstance(instance) {
  9371. // TODO: Does this work for all element types? What about MathML? Should we
  9372. // pass host context to this method?
  9373. instance = instance;
  9374. var style = instance.style;
  9375. if (typeof style.setProperty === 'function') {
  9376. style.setProperty('display', 'none', 'important');
  9377. } else {
  9378. style.display = 'none';
  9379. }
  9380. }
  9381. function hideTextInstance(textInstance) {
  9382. textInstance.nodeValue = '';
  9383. }
  9384. function unhideInstance(instance, props) {
  9385. instance = instance;
  9386. var styleProp = props[STYLE$1];
  9387. var display = styleProp !== undefined && styleProp !== null && styleProp.hasOwnProperty('display') ? styleProp.display : null;
  9388. instance.style.display = dangerousStyleValue('display', display);
  9389. }
  9390. function unhideTextInstance(textInstance, text) {
  9391. textInstance.nodeValue = text;
  9392. }
  9393. function clearContainer(container) {
  9394. if (container.nodeType === ELEMENT_NODE) {
  9395. container.textContent = '';
  9396. } else if (container.nodeType === DOCUMENT_NODE) {
  9397. if (container.documentElement) {
  9398. container.removeChild(container.documentElement);
  9399. }
  9400. }
  9401. } // -------------------
  9402. function canHydrateInstance(instance, type, props) {
  9403. if (instance.nodeType !== ELEMENT_NODE || type.toLowerCase() !== instance.nodeName.toLowerCase()) {
  9404. return null;
  9405. } // This has now been refined to an element node.
  9406. return instance;
  9407. }
  9408. function canHydrateTextInstance(instance, text) {
  9409. if (text === '' || instance.nodeType !== TEXT_NODE) {
  9410. // Empty strings are not parsed by HTML so there won't be a correct match here.
  9411. return null;
  9412. } // This has now been refined to a text node.
  9413. return instance;
  9414. }
  9415. function canHydrateSuspenseInstance(instance) {
  9416. if (instance.nodeType !== COMMENT_NODE) {
  9417. // Empty strings are not parsed by HTML so there won't be a correct match here.
  9418. return null;
  9419. } // This has now been refined to a suspense node.
  9420. return instance;
  9421. }
  9422. function isSuspenseInstancePending(instance) {
  9423. return instance.data === SUSPENSE_PENDING_START_DATA;
  9424. }
  9425. function isSuspenseInstanceFallback(instance) {
  9426. return instance.data === SUSPENSE_FALLBACK_START_DATA;
  9427. }
  9428. function getSuspenseInstanceFallbackErrorDetails(instance) {
  9429. var dataset = instance.nextSibling && instance.nextSibling.dataset;
  9430. var digest, message, stack;
  9431. if (dataset) {
  9432. digest = dataset.dgst;
  9433. {
  9434. message = dataset.msg;
  9435. stack = dataset.stck;
  9436. }
  9437. }
  9438. {
  9439. return {
  9440. message: message,
  9441. digest: digest,
  9442. stack: stack
  9443. };
  9444. } // let value = {message: undefined, hash: undefined};
  9445. // const nextSibling = instance.nextSibling;
  9446. // if (nextSibling) {
  9447. // const dataset = ((nextSibling: any): HTMLTemplateElement).dataset;
  9448. // value.message = dataset.msg;
  9449. // value.hash = dataset.hash;
  9450. // if (true) {
  9451. // value.stack = dataset.stack;
  9452. // }
  9453. // }
  9454. // return value;
  9455. }
  9456. function registerSuspenseInstanceRetry(instance, callback) {
  9457. instance._reactRetry = callback;
  9458. }
  9459. function getNextHydratable(node) {
  9460. // Skip non-hydratable nodes.
  9461. for (; node != null; node = node.nextSibling) {
  9462. var nodeType = node.nodeType;
  9463. if (nodeType === ELEMENT_NODE || nodeType === TEXT_NODE) {
  9464. break;
  9465. }
  9466. if (nodeType === COMMENT_NODE) {
  9467. var nodeData = node.data;
  9468. if (nodeData === SUSPENSE_START_DATA || nodeData === SUSPENSE_FALLBACK_START_DATA || nodeData === SUSPENSE_PENDING_START_DATA) {
  9469. break;
  9470. }
  9471. if (nodeData === SUSPENSE_END_DATA) {
  9472. return null;
  9473. }
  9474. }
  9475. }
  9476. return node;
  9477. }
  9478. function getNextHydratableSibling(instance) {
  9479. return getNextHydratable(instance.nextSibling);
  9480. }
  9481. function getFirstHydratableChild(parentInstance) {
  9482. return getNextHydratable(parentInstance.firstChild);
  9483. }
  9484. function getFirstHydratableChildWithinContainer(parentContainer) {
  9485. return getNextHydratable(parentContainer.firstChild);
  9486. }
  9487. function getFirstHydratableChildWithinSuspenseInstance(parentInstance) {
  9488. return getNextHydratable(parentInstance.nextSibling);
  9489. }
  9490. function hydrateInstance(instance, type, props, rootContainerInstance, hostContext, internalInstanceHandle, shouldWarnDev) {
  9491. precacheFiberNode(internalInstanceHandle, instance); // TODO: Possibly defer this until the commit phase where all the events
  9492. // get attached.
  9493. updateFiberProps(instance, props);
  9494. var parentNamespace;
  9495. {
  9496. var hostContextDev = hostContext;
  9497. parentNamespace = hostContextDev.namespace;
  9498. } // TODO: Temporary hack to check if we're in a concurrent root. We can delete
  9499. // when the legacy root API is removed.
  9500. var isConcurrentMode = (internalInstanceHandle.mode & ConcurrentMode) !== NoMode;
  9501. return diffHydratedProperties(instance, type, props, parentNamespace, rootContainerInstance, isConcurrentMode, shouldWarnDev);
  9502. }
  9503. function hydrateTextInstance(textInstance, text, internalInstanceHandle, shouldWarnDev) {
  9504. precacheFiberNode(internalInstanceHandle, textInstance); // TODO: Temporary hack to check if we're in a concurrent root. We can delete
  9505. // when the legacy root API is removed.
  9506. var isConcurrentMode = (internalInstanceHandle.mode & ConcurrentMode) !== NoMode;
  9507. return diffHydratedText(textInstance, text);
  9508. }
  9509. function hydrateSuspenseInstance(suspenseInstance, internalInstanceHandle) {
  9510. precacheFiberNode(internalInstanceHandle, suspenseInstance);
  9511. }
  9512. function getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance) {
  9513. var node = suspenseInstance.nextSibling; // Skip past all nodes within this suspense boundary.
  9514. // There might be nested nodes so we need to keep track of how
  9515. // deep we are and only break out when we're back on top.
  9516. var depth = 0;
  9517. while (node) {
  9518. if (node.nodeType === COMMENT_NODE) {
  9519. var data = node.data;
  9520. if (data === SUSPENSE_END_DATA) {
  9521. if (depth === 0) {
  9522. return getNextHydratableSibling(node);
  9523. } else {
  9524. depth--;
  9525. }
  9526. } else if (data === SUSPENSE_START_DATA || data === SUSPENSE_FALLBACK_START_DATA || data === SUSPENSE_PENDING_START_DATA) {
  9527. depth++;
  9528. }
  9529. }
  9530. node = node.nextSibling;
  9531. } // TODO: Warn, we didn't find the end comment boundary.
  9532. return null;
  9533. } // Returns the SuspenseInstance if this node is a direct child of a
  9534. // SuspenseInstance. I.e. if its previous sibling is a Comment with
  9535. // SUSPENSE_x_START_DATA. Otherwise, null.
  9536. function getParentSuspenseInstance(targetInstance) {
  9537. var node = targetInstance.previousSibling; // Skip past all nodes within this suspense boundary.
  9538. // There might be nested nodes so we need to keep track of how
  9539. // deep we are and only break out when we're back on top.
  9540. var depth = 0;
  9541. while (node) {
  9542. if (node.nodeType === COMMENT_NODE) {
  9543. var data = node.data;
  9544. if (data === SUSPENSE_START_DATA || data === SUSPENSE_FALLBACK_START_DATA || data === SUSPENSE_PENDING_START_DATA) {
  9545. if (depth === 0) {
  9546. return node;
  9547. } else {
  9548. depth--;
  9549. }
  9550. } else if (data === SUSPENSE_END_DATA) {
  9551. depth++;
  9552. }
  9553. }
  9554. node = node.previousSibling;
  9555. }
  9556. return null;
  9557. }
  9558. function commitHydratedContainer(container) {
  9559. // Retry if any event replaying was blocked on this.
  9560. retryIfBlockedOn(container);
  9561. }
  9562. function commitHydratedSuspenseInstance(suspenseInstance) {
  9563. // Retry if any event replaying was blocked on this.
  9564. retryIfBlockedOn(suspenseInstance);
  9565. }
  9566. function shouldDeleteUnhydratedTailInstances(parentType) {
  9567. return parentType !== 'head' && parentType !== 'body';
  9568. }
  9569. function didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, text, isConcurrentMode) {
  9570. var shouldWarnDev = true;
  9571. checkForUnmatchedText(textInstance.nodeValue, text, isConcurrentMode, shouldWarnDev);
  9572. }
  9573. function didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, text, isConcurrentMode) {
  9574. if (parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  9575. var shouldWarnDev = true;
  9576. checkForUnmatchedText(textInstance.nodeValue, text, isConcurrentMode, shouldWarnDev);
  9577. }
  9578. }
  9579. function didNotHydrateInstanceWithinContainer(parentContainer, instance) {
  9580. {
  9581. if (instance.nodeType === ELEMENT_NODE) {
  9582. warnForDeletedHydratableElement(parentContainer, instance);
  9583. } else if (instance.nodeType === COMMENT_NODE) ; else {
  9584. warnForDeletedHydratableText(parentContainer, instance);
  9585. }
  9586. }
  9587. }
  9588. function didNotHydrateInstanceWithinSuspenseInstance(parentInstance, instance) {
  9589. {
  9590. // $FlowFixMe: Only Element or Document can be parent nodes.
  9591. var parentNode = parentInstance.parentNode;
  9592. if (parentNode !== null) {
  9593. if (instance.nodeType === ELEMENT_NODE) {
  9594. warnForDeletedHydratableElement(parentNode, instance);
  9595. } else if (instance.nodeType === COMMENT_NODE) ; else {
  9596. warnForDeletedHydratableText(parentNode, instance);
  9597. }
  9598. }
  9599. }
  9600. }
  9601. function didNotHydrateInstance(parentType, parentProps, parentInstance, instance, isConcurrentMode) {
  9602. {
  9603. if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  9604. if (instance.nodeType === ELEMENT_NODE) {
  9605. warnForDeletedHydratableElement(parentInstance, instance);
  9606. } else if (instance.nodeType === COMMENT_NODE) ; else {
  9607. warnForDeletedHydratableText(parentInstance, instance);
  9608. }
  9609. }
  9610. }
  9611. }
  9612. function didNotFindHydratableInstanceWithinContainer(parentContainer, type, props) {
  9613. {
  9614. warnForInsertedHydratedElement(parentContainer, type);
  9615. }
  9616. }
  9617. function didNotFindHydratableTextInstanceWithinContainer(parentContainer, text) {
  9618. {
  9619. warnForInsertedHydratedText(parentContainer, text);
  9620. }
  9621. }
  9622. function didNotFindHydratableInstanceWithinSuspenseInstance(parentInstance, type, props) {
  9623. {
  9624. // $FlowFixMe: Only Element or Document can be parent nodes.
  9625. var parentNode = parentInstance.parentNode;
  9626. if (parentNode !== null) warnForInsertedHydratedElement(parentNode, type);
  9627. }
  9628. }
  9629. function didNotFindHydratableTextInstanceWithinSuspenseInstance(parentInstance, text) {
  9630. {
  9631. // $FlowFixMe: Only Element or Document can be parent nodes.
  9632. var parentNode = parentInstance.parentNode;
  9633. if (parentNode !== null) warnForInsertedHydratedText(parentNode, text);
  9634. }
  9635. }
  9636. function didNotFindHydratableInstance(parentType, parentProps, parentInstance, type, props, isConcurrentMode) {
  9637. {
  9638. if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  9639. warnForInsertedHydratedElement(parentInstance, type);
  9640. }
  9641. }
  9642. }
  9643. function didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, text, isConcurrentMode) {
  9644. {
  9645. if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  9646. warnForInsertedHydratedText(parentInstance, text);
  9647. }
  9648. }
  9649. }
  9650. function errorHydratingContainer(parentContainer) {
  9651. {
  9652. // TODO: This gets logged by onRecoverableError, too, so we should be
  9653. // able to remove it.
  9654. error('An error occurred during hydration. The server HTML was replaced with client content in <%s>.', parentContainer.nodeName.toLowerCase());
  9655. }
  9656. }
  9657. function preparePortalMount(portalInstance) {
  9658. listenToAllSupportedEvents(portalInstance);
  9659. }
  9660. var randomKey = Math.random().toString(36).slice(2);
  9661. var internalInstanceKey = '__reactFiber$' + randomKey;
  9662. var internalPropsKey = '__reactProps$' + randomKey;
  9663. var internalContainerInstanceKey = '__reactContainer$' + randomKey;
  9664. var internalEventHandlersKey = '__reactEvents$' + randomKey;
  9665. var internalEventHandlerListenersKey = '__reactListeners$' + randomKey;
  9666. var internalEventHandlesSetKey = '__reactHandles$' + randomKey;
  9667. function detachDeletedInstance(node) {
  9668. // TODO: This function is only called on host components. I don't think all of
  9669. // these fields are relevant.
  9670. delete node[internalInstanceKey];
  9671. delete node[internalPropsKey];
  9672. delete node[internalEventHandlersKey];
  9673. delete node[internalEventHandlerListenersKey];
  9674. delete node[internalEventHandlesSetKey];
  9675. }
  9676. function precacheFiberNode(hostInst, node) {
  9677. node[internalInstanceKey] = hostInst;
  9678. }
  9679. function markContainerAsRoot(hostRoot, node) {
  9680. node[internalContainerInstanceKey] = hostRoot;
  9681. }
  9682. function unmarkContainerAsRoot(node) {
  9683. node[internalContainerInstanceKey] = null;
  9684. }
  9685. function isContainerMarkedAsRoot(node) {
  9686. return !!node[internalContainerInstanceKey];
  9687. } // Given a DOM node, return the closest HostComponent or HostText fiber ancestor.
  9688. // If the target node is part of a hydrated or not yet rendered subtree, then
  9689. // this may also return a SuspenseComponent or HostRoot to indicate that.
  9690. // Conceptually the HostRoot fiber is a child of the Container node. So if you
  9691. // pass the Container node as the targetNode, you will not actually get the
  9692. // HostRoot back. To get to the HostRoot, you need to pass a child of it.
  9693. // The same thing applies to Suspense boundaries.
  9694. function getClosestInstanceFromNode(targetNode) {
  9695. var targetInst = targetNode[internalInstanceKey];
  9696. if (targetInst) {
  9697. // Don't return HostRoot or SuspenseComponent here.
  9698. return targetInst;
  9699. } // If the direct event target isn't a React owned DOM node, we need to look
  9700. // to see if one of its parents is a React owned DOM node.
  9701. var parentNode = targetNode.parentNode;
  9702. while (parentNode) {
  9703. // We'll check if this is a container root that could include
  9704. // React nodes in the future. We need to check this first because
  9705. // if we're a child of a dehydrated container, we need to first
  9706. // find that inner container before moving on to finding the parent
  9707. // instance. Note that we don't check this field on the targetNode
  9708. // itself because the fibers are conceptually between the container
  9709. // node and the first child. It isn't surrounding the container node.
  9710. // If it's not a container, we check if it's an instance.
  9711. targetInst = parentNode[internalContainerInstanceKey] || parentNode[internalInstanceKey];
  9712. if (targetInst) {
  9713. // Since this wasn't the direct target of the event, we might have
  9714. // stepped past dehydrated DOM nodes to get here. However they could
  9715. // also have been non-React nodes. We need to answer which one.
  9716. // If we the instance doesn't have any children, then there can't be
  9717. // a nested suspense boundary within it. So we can use this as a fast
  9718. // bailout. Most of the time, when people add non-React children to
  9719. // the tree, it is using a ref to a child-less DOM node.
  9720. // Normally we'd only need to check one of the fibers because if it
  9721. // has ever gone from having children to deleting them or vice versa
  9722. // it would have deleted the dehydrated boundary nested inside already.
  9723. // However, since the HostRoot starts out with an alternate it might
  9724. // have one on the alternate so we need to check in case this was a
  9725. // root.
  9726. var alternate = targetInst.alternate;
  9727. if (targetInst.child !== null || alternate !== null && alternate.child !== null) {
  9728. // Next we need to figure out if the node that skipped past is
  9729. // nested within a dehydrated boundary and if so, which one.
  9730. var suspenseInstance = getParentSuspenseInstance(targetNode);
  9731. while (suspenseInstance !== null) {
  9732. // We found a suspense instance. That means that we haven't
  9733. // hydrated it yet. Even though we leave the comments in the
  9734. // DOM after hydrating, and there are boundaries in the DOM
  9735. // that could already be hydrated, we wouldn't have found them
  9736. // through this pass since if the target is hydrated it would
  9737. // have had an internalInstanceKey on it.
  9738. // Let's get the fiber associated with the SuspenseComponent
  9739. // as the deepest instance.
  9740. var targetSuspenseInst = suspenseInstance[internalInstanceKey];
  9741. if (targetSuspenseInst) {
  9742. return targetSuspenseInst;
  9743. } // If we don't find a Fiber on the comment, it might be because
  9744. // we haven't gotten to hydrate it yet. There might still be a
  9745. // parent boundary that hasn't above this one so we need to find
  9746. // the outer most that is known.
  9747. suspenseInstance = getParentSuspenseInstance(suspenseInstance); // If we don't find one, then that should mean that the parent
  9748. // host component also hasn't hydrated yet. We can return it
  9749. // below since it will bail out on the isMounted check later.
  9750. }
  9751. }
  9752. return targetInst;
  9753. }
  9754. targetNode = parentNode;
  9755. parentNode = targetNode.parentNode;
  9756. }
  9757. return null;
  9758. }
  9759. /**
  9760. * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent
  9761. * instance, or null if the node was not rendered by this React.
  9762. */
  9763. function getInstanceFromNode(node) {
  9764. var inst = node[internalInstanceKey] || node[internalContainerInstanceKey];
  9765. if (inst) {
  9766. if (inst.tag === HostComponent || inst.tag === HostText || inst.tag === SuspenseComponent || inst.tag === HostRoot) {
  9767. return inst;
  9768. } else {
  9769. return null;
  9770. }
  9771. }
  9772. return null;
  9773. }
  9774. /**
  9775. * Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
  9776. * DOM node.
  9777. */
  9778. function getNodeFromInstance(inst) {
  9779. if (inst.tag === HostComponent || inst.tag === HostText) {
  9780. // In Fiber this, is just the state node right now. We assume it will be
  9781. // a host component or host text.
  9782. return inst.stateNode;
  9783. } // Without this first invariant, passing a non-DOM-component triggers the next
  9784. // invariant for a missing parent, which is super confusing.
  9785. throw new Error('getNodeFromInstance: Invalid argument.');
  9786. }
  9787. function getFiberCurrentPropsFromNode(node) {
  9788. return node[internalPropsKey] || null;
  9789. }
  9790. function updateFiberProps(node, props) {
  9791. node[internalPropsKey] = props;
  9792. }
  9793. function getEventListenerSet(node) {
  9794. var elementListenerSet = node[internalEventHandlersKey];
  9795. if (elementListenerSet === undefined) {
  9796. elementListenerSet = node[internalEventHandlersKey] = new Set();
  9797. }
  9798. return elementListenerSet;
  9799. }
  9800. var loggedTypeFailures = {};
  9801. var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
  9802. function setCurrentlyValidatingElement(element) {
  9803. {
  9804. if (element) {
  9805. var owner = element._owner;
  9806. var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
  9807. ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
  9808. } else {
  9809. ReactDebugCurrentFrame$1.setExtraStackFrame(null);
  9810. }
  9811. }
  9812. }
  9813. function checkPropTypes(typeSpecs, values, location, componentName, element) {
  9814. {
  9815. // $FlowFixMe This is okay but Flow doesn't know it.
  9816. var has = Function.call.bind(hasOwnProperty);
  9817. for (var typeSpecName in typeSpecs) {
  9818. if (has(typeSpecs, typeSpecName)) {
  9819. var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
  9820. // fail the render phase where it didn't fail before. So we log it.
  9821. // After these have been cleaned up, we'll let them throw.
  9822. try {
  9823. // This is intentionally an invariant that gets caught. It's the same
  9824. // behavior as without this statement except with a better message.
  9825. if (typeof typeSpecs[typeSpecName] !== 'function') {
  9826. // eslint-disable-next-line react-internal/prod-error-codes
  9827. var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
  9828. err.name = 'Invariant Violation';
  9829. throw err;
  9830. }
  9831. error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
  9832. } catch (ex) {
  9833. error$1 = ex;
  9834. }
  9835. if (error$1 && !(error$1 instanceof Error)) {
  9836. setCurrentlyValidatingElement(element);
  9837. error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
  9838. setCurrentlyValidatingElement(null);
  9839. }
  9840. if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
  9841. // Only monitor this failure once because there tends to be a lot of the
  9842. // same error.
  9843. loggedTypeFailures[error$1.message] = true;
  9844. setCurrentlyValidatingElement(element);
  9845. error('Failed %s type: %s', location, error$1.message);
  9846. setCurrentlyValidatingElement(null);
  9847. }
  9848. }
  9849. }
  9850. }
  9851. }
  9852. var valueStack = [];
  9853. var fiberStack;
  9854. {
  9855. fiberStack = [];
  9856. }
  9857. var index = -1;
  9858. function createCursor(defaultValue) {
  9859. return {
  9860. current: defaultValue
  9861. };
  9862. }
  9863. function pop(cursor, fiber) {
  9864. if (index < 0) {
  9865. {
  9866. error('Unexpected pop.');
  9867. }
  9868. return;
  9869. }
  9870. {
  9871. if (fiber !== fiberStack[index]) {
  9872. error('Unexpected Fiber popped.');
  9873. }
  9874. }
  9875. cursor.current = valueStack[index];
  9876. valueStack[index] = null;
  9877. {
  9878. fiberStack[index] = null;
  9879. }
  9880. index--;
  9881. }
  9882. function push(cursor, value, fiber) {
  9883. index++;
  9884. valueStack[index] = cursor.current;
  9885. {
  9886. fiberStack[index] = fiber;
  9887. }
  9888. cursor.current = value;
  9889. }
  9890. var warnedAboutMissingGetChildContext;
  9891. {
  9892. warnedAboutMissingGetChildContext = {};
  9893. }
  9894. var emptyContextObject = {};
  9895. {
  9896. Object.freeze(emptyContextObject);
  9897. } // A cursor to the current merged context object on the stack.
  9898. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  9899. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  9900. // We use this to get access to the parent context after we have already
  9901. // pushed the next context provider, and now need to merge their contexts.
  9902. var previousContext = emptyContextObject;
  9903. function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
  9904. {
  9905. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  9906. // If the fiber is a context provider itself, when we read its context
  9907. // we may have already pushed its own child context on the stack. A context
  9908. // provider should not "see" its own child context. Therefore we read the
  9909. // previous (parent) context instead for a context provider.
  9910. return previousContext;
  9911. }
  9912. return contextStackCursor.current;
  9913. }
  9914. }
  9915. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  9916. {
  9917. var instance = workInProgress.stateNode;
  9918. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  9919. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  9920. }
  9921. }
  9922. function getMaskedContext(workInProgress, unmaskedContext) {
  9923. {
  9924. var type = workInProgress.type;
  9925. var contextTypes = type.contextTypes;
  9926. if (!contextTypes) {
  9927. return emptyContextObject;
  9928. } // Avoid recreating masked context unless unmasked context has changed.
  9929. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  9930. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  9931. var instance = workInProgress.stateNode;
  9932. if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
  9933. return instance.__reactInternalMemoizedMaskedChildContext;
  9934. }
  9935. var context = {};
  9936. for (var key in contextTypes) {
  9937. context[key] = unmaskedContext[key];
  9938. }
  9939. {
  9940. var name = getComponentNameFromFiber(workInProgress) || 'Unknown';
  9941. checkPropTypes(contextTypes, context, 'context', name);
  9942. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  9943. // Context is created before the class component is instantiated so check for instance.
  9944. if (instance) {
  9945. cacheContext(workInProgress, unmaskedContext, context);
  9946. }
  9947. return context;
  9948. }
  9949. }
  9950. function hasContextChanged() {
  9951. {
  9952. return didPerformWorkStackCursor.current;
  9953. }
  9954. }
  9955. function isContextProvider(type) {
  9956. {
  9957. var childContextTypes = type.childContextTypes;
  9958. return childContextTypes !== null && childContextTypes !== undefined;
  9959. }
  9960. }
  9961. function popContext(fiber) {
  9962. {
  9963. pop(didPerformWorkStackCursor, fiber);
  9964. pop(contextStackCursor, fiber);
  9965. }
  9966. }
  9967. function popTopLevelContextObject(fiber) {
  9968. {
  9969. pop(didPerformWorkStackCursor, fiber);
  9970. pop(contextStackCursor, fiber);
  9971. }
  9972. }
  9973. function pushTopLevelContextObject(fiber, context, didChange) {
  9974. {
  9975. if (contextStackCursor.current !== emptyContextObject) {
  9976. throw new Error('Unexpected context found on stack. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  9977. }
  9978. push(contextStackCursor, context, fiber);
  9979. push(didPerformWorkStackCursor, didChange, fiber);
  9980. }
  9981. }
  9982. function processChildContext(fiber, type, parentContext) {
  9983. {
  9984. var instance = fiber.stateNode;
  9985. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  9986. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  9987. if (typeof instance.getChildContext !== 'function') {
  9988. {
  9989. var componentName = getComponentNameFromFiber(fiber) || 'Unknown';
  9990. if (!warnedAboutMissingGetChildContext[componentName]) {
  9991. warnedAboutMissingGetChildContext[componentName] = true;
  9992. 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);
  9993. }
  9994. }
  9995. return parentContext;
  9996. }
  9997. var childContext = instance.getChildContext();
  9998. for (var contextKey in childContext) {
  9999. if (!(contextKey in childContextTypes)) {
  10000. throw new Error((getComponentNameFromFiber(fiber) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes.");
  10001. }
  10002. }
  10003. {
  10004. var name = getComponentNameFromFiber(fiber) || 'Unknown';
  10005. checkPropTypes(childContextTypes, childContext, 'child context', name);
  10006. }
  10007. return assign({}, parentContext, childContext);
  10008. }
  10009. }
  10010. function pushContextProvider(workInProgress) {
  10011. {
  10012. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  10013. // If the instance does not exist yet, we will push null at first,
  10014. // and replace it on the stack later when invalidating the context.
  10015. var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
  10016. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  10017. previousContext = contextStackCursor.current;
  10018. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  10019. push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
  10020. return true;
  10021. }
  10022. }
  10023. function invalidateContextProvider(workInProgress, type, didChange) {
  10024. {
  10025. var instance = workInProgress.stateNode;
  10026. if (!instance) {
  10027. throw new Error('Expected to have an instance by this point. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  10028. }
  10029. if (didChange) {
  10030. // Merge parent and own context.
  10031. // Skip this if we're not updating due to sCU.
  10032. // This avoids unnecessarily recomputing memoized values.
  10033. var mergedContext = processChildContext(workInProgress, type, previousContext);
  10034. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  10035. // It is important to unwind the context in the reverse order.
  10036. pop(didPerformWorkStackCursor, workInProgress);
  10037. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  10038. push(contextStackCursor, mergedContext, workInProgress);
  10039. push(didPerformWorkStackCursor, didChange, workInProgress);
  10040. } else {
  10041. pop(didPerformWorkStackCursor, workInProgress);
  10042. push(didPerformWorkStackCursor, didChange, workInProgress);
  10043. }
  10044. }
  10045. }
  10046. function findCurrentUnmaskedContext(fiber) {
  10047. {
  10048. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  10049. // makes sense elsewhere
  10050. if (!isFiberMounted(fiber) || fiber.tag !== ClassComponent) {
  10051. throw new Error('Expected subtree parent to be a mounted class component. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  10052. }
  10053. var node = fiber;
  10054. do {
  10055. switch (node.tag) {
  10056. case HostRoot:
  10057. return node.stateNode.context;
  10058. case ClassComponent:
  10059. {
  10060. var Component = node.type;
  10061. if (isContextProvider(Component)) {
  10062. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  10063. }
  10064. break;
  10065. }
  10066. }
  10067. node = node.return;
  10068. } while (node !== null);
  10069. throw new Error('Found unexpected detached subtree parent. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  10070. }
  10071. }
  10072. var LegacyRoot = 0;
  10073. var ConcurrentRoot = 1;
  10074. var syncQueue = null;
  10075. var includesLegacySyncCallbacks = false;
  10076. var isFlushingSyncQueue = false;
  10077. function scheduleSyncCallback(callback) {
  10078. // Push this callback into an internal queue. We'll flush these either in
  10079. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  10080. if (syncQueue === null) {
  10081. syncQueue = [callback];
  10082. } else {
  10083. // Push onto existing queue. Don't need to schedule a callback because
  10084. // we already scheduled one when we created the queue.
  10085. syncQueue.push(callback);
  10086. }
  10087. }
  10088. function scheduleLegacySyncCallback(callback) {
  10089. includesLegacySyncCallbacks = true;
  10090. scheduleSyncCallback(callback);
  10091. }
  10092. function flushSyncCallbacksOnlyInLegacyMode() {
  10093. // Only flushes the queue if there's a legacy sync callback scheduled.
  10094. // TODO: There's only a single type of callback: performSyncOnWorkOnRoot. So
  10095. // it might make more sense for the queue to be a list of roots instead of a
  10096. // list of generic callbacks. Then we can have two: one for legacy roots, one
  10097. // for concurrent roots. And this method would only flush the legacy ones.
  10098. if (includesLegacySyncCallbacks) {
  10099. flushSyncCallbacks();
  10100. }
  10101. }
  10102. function flushSyncCallbacks() {
  10103. if (!isFlushingSyncQueue && syncQueue !== null) {
  10104. // Prevent re-entrance.
  10105. isFlushingSyncQueue = true;
  10106. var i = 0;
  10107. var previousUpdatePriority = getCurrentUpdatePriority();
  10108. try {
  10109. var isSync = true;
  10110. var queue = syncQueue; // TODO: Is this necessary anymore? The only user code that runs in this
  10111. // queue is in the render or commit phases.
  10112. setCurrentUpdatePriority(DiscreteEventPriority);
  10113. for (; i < queue.length; i++) {
  10114. var callback = queue[i];
  10115. do {
  10116. callback = callback(isSync);
  10117. } while (callback !== null);
  10118. }
  10119. syncQueue = null;
  10120. includesLegacySyncCallbacks = false;
  10121. } catch (error) {
  10122. // If something throws, leave the remaining callbacks on the queue.
  10123. if (syncQueue !== null) {
  10124. syncQueue = syncQueue.slice(i + 1);
  10125. } // Resume flushing in the next tick
  10126. scheduleCallback(ImmediatePriority, flushSyncCallbacks);
  10127. throw error;
  10128. } finally {
  10129. setCurrentUpdatePriority(previousUpdatePriority);
  10130. isFlushingSyncQueue = false;
  10131. }
  10132. }
  10133. return null;
  10134. }
  10135. // TODO: Use the unified fiber stack module instead of this local one?
  10136. // Intentionally not using it yet to derisk the initial implementation, because
  10137. // the way we push/pop these values is a bit unusual. If there's a mistake, I'd
  10138. // rather the ids be wrong than crash the whole reconciler.
  10139. var forkStack = [];
  10140. var forkStackIndex = 0;
  10141. var treeForkProvider = null;
  10142. var treeForkCount = 0;
  10143. var idStack = [];
  10144. var idStackIndex = 0;
  10145. var treeContextProvider = null;
  10146. var treeContextId = 1;
  10147. var treeContextOverflow = '';
  10148. function isForkedChild(workInProgress) {
  10149. warnIfNotHydrating();
  10150. return (workInProgress.flags & Forked) !== NoFlags;
  10151. }
  10152. function getForksAtLevel(workInProgress) {
  10153. warnIfNotHydrating();
  10154. return treeForkCount;
  10155. }
  10156. function getTreeId() {
  10157. var overflow = treeContextOverflow;
  10158. var idWithLeadingBit = treeContextId;
  10159. var id = idWithLeadingBit & ~getLeadingBit(idWithLeadingBit);
  10160. return id.toString(32) + overflow;
  10161. }
  10162. function pushTreeFork(workInProgress, totalChildren) {
  10163. // This is called right after we reconcile an array (or iterator) of child
  10164. // fibers, because that's the only place where we know how many children in
  10165. // the whole set without doing extra work later, or storing addtional
  10166. // information on the fiber.
  10167. //
  10168. // That's why this function is separate from pushTreeId — it's called during
  10169. // the render phase of the fork parent, not the child, which is where we push
  10170. // the other context values.
  10171. //
  10172. // In the Fizz implementation this is much simpler because the child is
  10173. // rendered in the same callstack as the parent.
  10174. //
  10175. // It might be better to just add a `forks` field to the Fiber type. It would
  10176. // make this module simpler.
  10177. warnIfNotHydrating();
  10178. forkStack[forkStackIndex++] = treeForkCount;
  10179. forkStack[forkStackIndex++] = treeForkProvider;
  10180. treeForkProvider = workInProgress;
  10181. treeForkCount = totalChildren;
  10182. }
  10183. function pushTreeId(workInProgress, totalChildren, index) {
  10184. warnIfNotHydrating();
  10185. idStack[idStackIndex++] = treeContextId;
  10186. idStack[idStackIndex++] = treeContextOverflow;
  10187. idStack[idStackIndex++] = treeContextProvider;
  10188. treeContextProvider = workInProgress;
  10189. var baseIdWithLeadingBit = treeContextId;
  10190. var baseOverflow = treeContextOverflow; // The leftmost 1 marks the end of the sequence, non-inclusive. It's not part
  10191. // of the id; we use it to account for leading 0s.
  10192. var baseLength = getBitLength(baseIdWithLeadingBit) - 1;
  10193. var baseId = baseIdWithLeadingBit & ~(1 << baseLength);
  10194. var slot = index + 1;
  10195. var length = getBitLength(totalChildren) + baseLength; // 30 is the max length we can store without overflowing, taking into
  10196. // consideration the leading 1 we use to mark the end of the sequence.
  10197. if (length > 30) {
  10198. // We overflowed the bitwise-safe range. Fall back to slower algorithm.
  10199. // This branch assumes the length of the base id is greater than 5; it won't
  10200. // work for smaller ids, because you need 5 bits per character.
  10201. //
  10202. // We encode the id in multiple steps: first the base id, then the
  10203. // remaining digits.
  10204. //
  10205. // Each 5 bit sequence corresponds to a single base 32 character. So for
  10206. // example, if the current id is 23 bits long, we can convert 20 of those
  10207. // bits into a string of 4 characters, with 3 bits left over.
  10208. //
  10209. // First calculate how many bits in the base id represent a complete
  10210. // sequence of characters.
  10211. var numberOfOverflowBits = baseLength - baseLength % 5; // Then create a bitmask that selects only those bits.
  10212. var newOverflowBits = (1 << numberOfOverflowBits) - 1; // Select the bits, and convert them to a base 32 string.
  10213. var newOverflow = (baseId & newOverflowBits).toString(32); // Now we can remove those bits from the base id.
  10214. var restOfBaseId = baseId >> numberOfOverflowBits;
  10215. var restOfBaseLength = baseLength - numberOfOverflowBits; // Finally, encode the rest of the bits using the normal algorithm. Because
  10216. // we made more room, this time it won't overflow.
  10217. var restOfLength = getBitLength(totalChildren) + restOfBaseLength;
  10218. var restOfNewBits = slot << restOfBaseLength;
  10219. var id = restOfNewBits | restOfBaseId;
  10220. var overflow = newOverflow + baseOverflow;
  10221. treeContextId = 1 << restOfLength | id;
  10222. treeContextOverflow = overflow;
  10223. } else {
  10224. // Normal path
  10225. var newBits = slot << baseLength;
  10226. var _id = newBits | baseId;
  10227. var _overflow = baseOverflow;
  10228. treeContextId = 1 << length | _id;
  10229. treeContextOverflow = _overflow;
  10230. }
  10231. }
  10232. function pushMaterializedTreeId(workInProgress) {
  10233. warnIfNotHydrating(); // This component materialized an id. This will affect any ids that appear
  10234. // in its children.
  10235. var returnFiber = workInProgress.return;
  10236. if (returnFiber !== null) {
  10237. var numberOfForks = 1;
  10238. var slotIndex = 0;
  10239. pushTreeFork(workInProgress, numberOfForks);
  10240. pushTreeId(workInProgress, numberOfForks, slotIndex);
  10241. }
  10242. }
  10243. function getBitLength(number) {
  10244. return 32 - clz32(number);
  10245. }
  10246. function getLeadingBit(id) {
  10247. return 1 << getBitLength(id) - 1;
  10248. }
  10249. function popTreeContext(workInProgress) {
  10250. // Restore the previous values.
  10251. // This is a bit more complicated than other context-like modules in Fiber
  10252. // because the same Fiber may appear on the stack multiple times and for
  10253. // different reasons. We have to keep popping until the work-in-progress is
  10254. // no longer at the top of the stack.
  10255. while (workInProgress === treeForkProvider) {
  10256. treeForkProvider = forkStack[--forkStackIndex];
  10257. forkStack[forkStackIndex] = null;
  10258. treeForkCount = forkStack[--forkStackIndex];
  10259. forkStack[forkStackIndex] = null;
  10260. }
  10261. while (workInProgress === treeContextProvider) {
  10262. treeContextProvider = idStack[--idStackIndex];
  10263. idStack[idStackIndex] = null;
  10264. treeContextOverflow = idStack[--idStackIndex];
  10265. idStack[idStackIndex] = null;
  10266. treeContextId = idStack[--idStackIndex];
  10267. idStack[idStackIndex] = null;
  10268. }
  10269. }
  10270. function getSuspendedTreeContext() {
  10271. warnIfNotHydrating();
  10272. if (treeContextProvider !== null) {
  10273. return {
  10274. id: treeContextId,
  10275. overflow: treeContextOverflow
  10276. };
  10277. } else {
  10278. return null;
  10279. }
  10280. }
  10281. function restoreSuspendedTreeContext(workInProgress, suspendedContext) {
  10282. warnIfNotHydrating();
  10283. idStack[idStackIndex++] = treeContextId;
  10284. idStack[idStackIndex++] = treeContextOverflow;
  10285. idStack[idStackIndex++] = treeContextProvider;
  10286. treeContextId = suspendedContext.id;
  10287. treeContextOverflow = suspendedContext.overflow;
  10288. treeContextProvider = workInProgress;
  10289. }
  10290. function warnIfNotHydrating() {
  10291. {
  10292. if (!getIsHydrating()) {
  10293. error('Expected to be hydrating. This is a bug in React. Please file ' + 'an issue.');
  10294. }
  10295. }
  10296. }
  10297. // This may have been an insertion or a hydration.
  10298. var hydrationParentFiber = null;
  10299. var nextHydratableInstance = null;
  10300. var isHydrating = false; // This flag allows for warning supression when we expect there to be mismatches
  10301. // due to earlier mismatches or a suspended fiber.
  10302. var didSuspendOrErrorDEV = false; // Hydration errors that were thrown inside this boundary
  10303. var hydrationErrors = null;
  10304. function warnIfHydrating() {
  10305. {
  10306. if (isHydrating) {
  10307. error('We should not be hydrating here. This is a bug in React. Please file a bug.');
  10308. }
  10309. }
  10310. }
  10311. function markDidThrowWhileHydratingDEV() {
  10312. {
  10313. didSuspendOrErrorDEV = true;
  10314. }
  10315. }
  10316. function didSuspendOrErrorWhileHydratingDEV() {
  10317. {
  10318. return didSuspendOrErrorDEV;
  10319. }
  10320. }
  10321. function enterHydrationState(fiber) {
  10322. var parentInstance = fiber.stateNode.containerInfo;
  10323. nextHydratableInstance = getFirstHydratableChildWithinContainer(parentInstance);
  10324. hydrationParentFiber = fiber;
  10325. isHydrating = true;
  10326. hydrationErrors = null;
  10327. didSuspendOrErrorDEV = false;
  10328. return true;
  10329. }
  10330. function reenterHydrationStateFromDehydratedSuspenseInstance(fiber, suspenseInstance, treeContext) {
  10331. nextHydratableInstance = getFirstHydratableChildWithinSuspenseInstance(suspenseInstance);
  10332. hydrationParentFiber = fiber;
  10333. isHydrating = true;
  10334. hydrationErrors = null;
  10335. didSuspendOrErrorDEV = false;
  10336. if (treeContext !== null) {
  10337. restoreSuspendedTreeContext(fiber, treeContext);
  10338. }
  10339. return true;
  10340. }
  10341. function warnUnhydratedInstance(returnFiber, instance) {
  10342. {
  10343. switch (returnFiber.tag) {
  10344. case HostRoot:
  10345. {
  10346. didNotHydrateInstanceWithinContainer(returnFiber.stateNode.containerInfo, instance);
  10347. break;
  10348. }
  10349. case HostComponent:
  10350. {
  10351. var isConcurrentMode = (returnFiber.mode & ConcurrentMode) !== NoMode;
  10352. didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance, // TODO: Delete this argument when we remove the legacy root API.
  10353. isConcurrentMode);
  10354. break;
  10355. }
  10356. case SuspenseComponent:
  10357. {
  10358. var suspenseState = returnFiber.memoizedState;
  10359. if (suspenseState.dehydrated !== null) didNotHydrateInstanceWithinSuspenseInstance(suspenseState.dehydrated, instance);
  10360. break;
  10361. }
  10362. }
  10363. }
  10364. }
  10365. function deleteHydratableInstance(returnFiber, instance) {
  10366. warnUnhydratedInstance(returnFiber, instance);
  10367. var childToDelete = createFiberFromHostInstanceForDeletion();
  10368. childToDelete.stateNode = instance;
  10369. childToDelete.return = returnFiber;
  10370. var deletions = returnFiber.deletions;
  10371. if (deletions === null) {
  10372. returnFiber.deletions = [childToDelete];
  10373. returnFiber.flags |= ChildDeletion;
  10374. } else {
  10375. deletions.push(childToDelete);
  10376. }
  10377. }
  10378. function warnNonhydratedInstance(returnFiber, fiber) {
  10379. {
  10380. if (didSuspendOrErrorDEV) {
  10381. // Inside a boundary that already suspended. We're currently rendering the
  10382. // siblings of a suspended node. The mismatch may be due to the missing
  10383. // data, so it's probably a false positive.
  10384. return;
  10385. }
  10386. switch (returnFiber.tag) {
  10387. case HostRoot:
  10388. {
  10389. var parentContainer = returnFiber.stateNode.containerInfo;
  10390. switch (fiber.tag) {
  10391. case HostComponent:
  10392. var type = fiber.type;
  10393. var props = fiber.pendingProps;
  10394. didNotFindHydratableInstanceWithinContainer(parentContainer, type);
  10395. break;
  10396. case HostText:
  10397. var text = fiber.pendingProps;
  10398. didNotFindHydratableTextInstanceWithinContainer(parentContainer, text);
  10399. break;
  10400. }
  10401. break;
  10402. }
  10403. case HostComponent:
  10404. {
  10405. var parentType = returnFiber.type;
  10406. var parentProps = returnFiber.memoizedProps;
  10407. var parentInstance = returnFiber.stateNode;
  10408. switch (fiber.tag) {
  10409. case HostComponent:
  10410. {
  10411. var _type = fiber.type;
  10412. var _props = fiber.pendingProps;
  10413. var isConcurrentMode = (returnFiber.mode & ConcurrentMode) !== NoMode;
  10414. didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props, // TODO: Delete this argument when we remove the legacy root API.
  10415. isConcurrentMode);
  10416. break;
  10417. }
  10418. case HostText:
  10419. {
  10420. var _text = fiber.pendingProps;
  10421. var _isConcurrentMode = (returnFiber.mode & ConcurrentMode) !== NoMode;
  10422. didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text, // TODO: Delete this argument when we remove the legacy root API.
  10423. _isConcurrentMode);
  10424. break;
  10425. }
  10426. }
  10427. break;
  10428. }
  10429. case SuspenseComponent:
  10430. {
  10431. var suspenseState = returnFiber.memoizedState;
  10432. var _parentInstance = suspenseState.dehydrated;
  10433. if (_parentInstance !== null) switch (fiber.tag) {
  10434. case HostComponent:
  10435. var _type2 = fiber.type;
  10436. var _props2 = fiber.pendingProps;
  10437. didNotFindHydratableInstanceWithinSuspenseInstance(_parentInstance, _type2);
  10438. break;
  10439. case HostText:
  10440. var _text2 = fiber.pendingProps;
  10441. didNotFindHydratableTextInstanceWithinSuspenseInstance(_parentInstance, _text2);
  10442. break;
  10443. }
  10444. break;
  10445. }
  10446. default:
  10447. return;
  10448. }
  10449. }
  10450. }
  10451. function insertNonHydratedInstance(returnFiber, fiber) {
  10452. fiber.flags = fiber.flags & ~Hydrating | Placement;
  10453. warnNonhydratedInstance(returnFiber, fiber);
  10454. }
  10455. function tryHydrate(fiber, nextInstance) {
  10456. switch (fiber.tag) {
  10457. case HostComponent:
  10458. {
  10459. var type = fiber.type;
  10460. var props = fiber.pendingProps;
  10461. var instance = canHydrateInstance(nextInstance, type);
  10462. if (instance !== null) {
  10463. fiber.stateNode = instance;
  10464. hydrationParentFiber = fiber;
  10465. nextHydratableInstance = getFirstHydratableChild(instance);
  10466. return true;
  10467. }
  10468. return false;
  10469. }
  10470. case HostText:
  10471. {
  10472. var text = fiber.pendingProps;
  10473. var textInstance = canHydrateTextInstance(nextInstance, text);
  10474. if (textInstance !== null) {
  10475. fiber.stateNode = textInstance;
  10476. hydrationParentFiber = fiber; // Text Instances don't have children so there's nothing to hydrate.
  10477. nextHydratableInstance = null;
  10478. return true;
  10479. }
  10480. return false;
  10481. }
  10482. case SuspenseComponent:
  10483. {
  10484. var suspenseInstance = canHydrateSuspenseInstance(nextInstance);
  10485. if (suspenseInstance !== null) {
  10486. var suspenseState = {
  10487. dehydrated: suspenseInstance,
  10488. treeContext: getSuspendedTreeContext(),
  10489. retryLane: OffscreenLane
  10490. };
  10491. fiber.memoizedState = suspenseState; // Store the dehydrated fragment as a child fiber.
  10492. // This simplifies the code for getHostSibling and deleting nodes,
  10493. // since it doesn't have to consider all Suspense boundaries and
  10494. // check if they're dehydrated ones or not.
  10495. var dehydratedFragment = createFiberFromDehydratedFragment(suspenseInstance);
  10496. dehydratedFragment.return = fiber;
  10497. fiber.child = dehydratedFragment;
  10498. hydrationParentFiber = fiber; // While a Suspense Instance does have children, we won't step into
  10499. // it during the first pass. Instead, we'll reenter it later.
  10500. nextHydratableInstance = null;
  10501. return true;
  10502. }
  10503. return false;
  10504. }
  10505. default:
  10506. return false;
  10507. }
  10508. }
  10509. function shouldClientRenderOnMismatch(fiber) {
  10510. return (fiber.mode & ConcurrentMode) !== NoMode && (fiber.flags & DidCapture) === NoFlags;
  10511. }
  10512. function throwOnHydrationMismatch(fiber) {
  10513. throw new Error('Hydration failed because the initial UI does not match what was ' + 'rendered on the server.');
  10514. }
  10515. function tryToClaimNextHydratableInstance(fiber) {
  10516. if (!isHydrating) {
  10517. return;
  10518. }
  10519. var nextInstance = nextHydratableInstance;
  10520. if (!nextInstance) {
  10521. if (shouldClientRenderOnMismatch(fiber)) {
  10522. warnNonhydratedInstance(hydrationParentFiber, fiber);
  10523. throwOnHydrationMismatch();
  10524. } // Nothing to hydrate. Make it an insertion.
  10525. insertNonHydratedInstance(hydrationParentFiber, fiber);
  10526. isHydrating = false;
  10527. hydrationParentFiber = fiber;
  10528. return;
  10529. }
  10530. var firstAttemptedInstance = nextInstance;
  10531. if (!tryHydrate(fiber, nextInstance)) {
  10532. if (shouldClientRenderOnMismatch(fiber)) {
  10533. warnNonhydratedInstance(hydrationParentFiber, fiber);
  10534. throwOnHydrationMismatch();
  10535. } // If we can't hydrate this instance let's try the next one.
  10536. // We use this as a heuristic. It's based on intuition and not data so it
  10537. // might be flawed or unnecessary.
  10538. nextInstance = getNextHydratableSibling(firstAttemptedInstance);
  10539. var prevHydrationParentFiber = hydrationParentFiber;
  10540. if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
  10541. // Nothing to hydrate. Make it an insertion.
  10542. insertNonHydratedInstance(hydrationParentFiber, fiber);
  10543. isHydrating = false;
  10544. hydrationParentFiber = fiber;
  10545. return;
  10546. } // We matched the next one, we'll now assume that the first one was
  10547. // superfluous and we'll delete it. Since we can't eagerly delete it
  10548. // we'll have to schedule a deletion. To do that, this node needs a dummy
  10549. // fiber associated with it.
  10550. deleteHydratableInstance(prevHydrationParentFiber, firstAttemptedInstance);
  10551. }
  10552. }
  10553. function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
  10554. var instance = fiber.stateNode;
  10555. var shouldWarnIfMismatchDev = !didSuspendOrErrorDEV;
  10556. var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber, shouldWarnIfMismatchDev); // TODO: Type this specific to this type of component.
  10557. fiber.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  10558. // is a new ref we mark this as an update.
  10559. if (updatePayload !== null) {
  10560. return true;
  10561. }
  10562. return false;
  10563. }
  10564. function prepareToHydrateHostTextInstance(fiber) {
  10565. var textInstance = fiber.stateNode;
  10566. var textContent = fiber.memoizedProps;
  10567. var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
  10568. if (shouldUpdate) {
  10569. // We assume that prepareToHydrateHostTextInstance is called in a context where the
  10570. // hydration parent is the parent host component of this host text.
  10571. var returnFiber = hydrationParentFiber;
  10572. if (returnFiber !== null) {
  10573. switch (returnFiber.tag) {
  10574. case HostRoot:
  10575. {
  10576. var parentContainer = returnFiber.stateNode.containerInfo;
  10577. var isConcurrentMode = (returnFiber.mode & ConcurrentMode) !== NoMode;
  10578. didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent, // TODO: Delete this argument when we remove the legacy root API.
  10579. isConcurrentMode);
  10580. break;
  10581. }
  10582. case HostComponent:
  10583. {
  10584. var parentType = returnFiber.type;
  10585. var parentProps = returnFiber.memoizedProps;
  10586. var parentInstance = returnFiber.stateNode;
  10587. var _isConcurrentMode2 = (returnFiber.mode & ConcurrentMode) !== NoMode;
  10588. didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent, // TODO: Delete this argument when we remove the legacy root API.
  10589. _isConcurrentMode2);
  10590. break;
  10591. }
  10592. }
  10593. }
  10594. }
  10595. return shouldUpdate;
  10596. }
  10597. function prepareToHydrateHostSuspenseInstance(fiber) {
  10598. var suspenseState = fiber.memoizedState;
  10599. var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
  10600. if (!suspenseInstance) {
  10601. throw new Error('Expected to have a hydrated suspense instance. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  10602. }
  10603. hydrateSuspenseInstance(suspenseInstance, fiber);
  10604. }
  10605. function skipPastDehydratedSuspenseInstance(fiber) {
  10606. var suspenseState = fiber.memoizedState;
  10607. var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
  10608. if (!suspenseInstance) {
  10609. throw new Error('Expected to have a hydrated suspense instance. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  10610. }
  10611. return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
  10612. }
  10613. function popToNextHostParent(fiber) {
  10614. var parent = fiber.return;
  10615. while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== SuspenseComponent) {
  10616. parent = parent.return;
  10617. }
  10618. hydrationParentFiber = parent;
  10619. }
  10620. function popHydrationState(fiber) {
  10621. if (fiber !== hydrationParentFiber) {
  10622. // We're deeper than the current hydration context, inside an inserted
  10623. // tree.
  10624. return false;
  10625. }
  10626. if (!isHydrating) {
  10627. // If we're not currently hydrating but we're in a hydration context, then
  10628. // we were an insertion and now need to pop up reenter hydration of our
  10629. // siblings.
  10630. popToNextHostParent(fiber);
  10631. isHydrating = true;
  10632. return false;
  10633. } // If we have any remaining hydratable nodes, we need to delete them now.
  10634. // We only do this deeper than head and body since they tend to have random
  10635. // other nodes in them. We also ignore components with pure text content in
  10636. // side of them. We also don't delete anything inside the root container.
  10637. if (fiber.tag !== HostRoot && (fiber.tag !== HostComponent || shouldDeleteUnhydratedTailInstances(fiber.type) && !shouldSetTextContent(fiber.type, fiber.memoizedProps))) {
  10638. var nextInstance = nextHydratableInstance;
  10639. if (nextInstance) {
  10640. if (shouldClientRenderOnMismatch(fiber)) {
  10641. warnIfUnhydratedTailNodes(fiber);
  10642. throwOnHydrationMismatch();
  10643. } else {
  10644. while (nextInstance) {
  10645. deleteHydratableInstance(fiber, nextInstance);
  10646. nextInstance = getNextHydratableSibling(nextInstance);
  10647. }
  10648. }
  10649. }
  10650. }
  10651. popToNextHostParent(fiber);
  10652. if (fiber.tag === SuspenseComponent) {
  10653. nextHydratableInstance = skipPastDehydratedSuspenseInstance(fiber);
  10654. } else {
  10655. nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
  10656. }
  10657. return true;
  10658. }
  10659. function hasUnhydratedTailNodes() {
  10660. return isHydrating && nextHydratableInstance !== null;
  10661. }
  10662. function warnIfUnhydratedTailNodes(fiber) {
  10663. var nextInstance = nextHydratableInstance;
  10664. while (nextInstance) {
  10665. warnUnhydratedInstance(fiber, nextInstance);
  10666. nextInstance = getNextHydratableSibling(nextInstance);
  10667. }
  10668. }
  10669. function resetHydrationState() {
  10670. hydrationParentFiber = null;
  10671. nextHydratableInstance = null;
  10672. isHydrating = false;
  10673. didSuspendOrErrorDEV = false;
  10674. }
  10675. function upgradeHydrationErrorsToRecoverable() {
  10676. if (hydrationErrors !== null) {
  10677. // Successfully completed a forced client render. The errors that occurred
  10678. // during the hydration attempt are now recovered. We will log them in
  10679. // commit phase, once the entire tree has finished.
  10680. queueRecoverableErrors(hydrationErrors);
  10681. hydrationErrors = null;
  10682. }
  10683. }
  10684. function getIsHydrating() {
  10685. return isHydrating;
  10686. }
  10687. function queueHydrationError(error) {
  10688. if (hydrationErrors === null) {
  10689. hydrationErrors = [error];
  10690. } else {
  10691. hydrationErrors.push(error);
  10692. }
  10693. }
  10694. var ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  10695. var NoTransition = null;
  10696. function requestCurrentTransition() {
  10697. return ReactCurrentBatchConfig$1.transition;
  10698. }
  10699. var ReactStrictModeWarnings = {
  10700. recordUnsafeLifecycleWarnings: function (fiber, instance) {},
  10701. flushPendingUnsafeLifecycleWarnings: function () {},
  10702. recordLegacyContextWarning: function (fiber, instance) {},
  10703. flushLegacyContextWarning: function () {},
  10704. discardPendingWarnings: function () {}
  10705. };
  10706. {
  10707. var findStrictRoot = function (fiber) {
  10708. var maybeStrictRoot = null;
  10709. var node = fiber;
  10710. while (node !== null) {
  10711. if (node.mode & StrictLegacyMode) {
  10712. maybeStrictRoot = node;
  10713. }
  10714. node = node.return;
  10715. }
  10716. return maybeStrictRoot;
  10717. };
  10718. var setToSortedString = function (set) {
  10719. var array = [];
  10720. set.forEach(function (value) {
  10721. array.push(value);
  10722. });
  10723. return array.sort().join(', ');
  10724. };
  10725. var pendingComponentWillMountWarnings = [];
  10726. var pendingUNSAFE_ComponentWillMountWarnings = [];
  10727. var pendingComponentWillReceivePropsWarnings = [];
  10728. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  10729. var pendingComponentWillUpdateWarnings = [];
  10730. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  10731. var didWarnAboutUnsafeLifecycles = new Set();
  10732. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
  10733. // Dedupe strategy: Warn once per component.
  10734. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  10735. return;
  10736. }
  10737. if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
  10738. instance.componentWillMount.__suppressDeprecationWarning !== true) {
  10739. pendingComponentWillMountWarnings.push(fiber);
  10740. }
  10741. if (fiber.mode & StrictLegacyMode && typeof instance.UNSAFE_componentWillMount === 'function') {
  10742. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  10743. }
  10744. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  10745. pendingComponentWillReceivePropsWarnings.push(fiber);
  10746. }
  10747. if (fiber.mode & StrictLegacyMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  10748. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  10749. }
  10750. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  10751. pendingComponentWillUpdateWarnings.push(fiber);
  10752. }
  10753. if (fiber.mode & StrictLegacyMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
  10754. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  10755. }
  10756. };
  10757. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
  10758. // We do an initial pass to gather component names
  10759. var componentWillMountUniqueNames = new Set();
  10760. if (pendingComponentWillMountWarnings.length > 0) {
  10761. pendingComponentWillMountWarnings.forEach(function (fiber) {
  10762. componentWillMountUniqueNames.add(getComponentNameFromFiber(fiber) || 'Component');
  10763. didWarnAboutUnsafeLifecycles.add(fiber.type);
  10764. });
  10765. pendingComponentWillMountWarnings = [];
  10766. }
  10767. var UNSAFE_componentWillMountUniqueNames = new Set();
  10768. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  10769. pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
  10770. UNSAFE_componentWillMountUniqueNames.add(getComponentNameFromFiber(fiber) || 'Component');
  10771. didWarnAboutUnsafeLifecycles.add(fiber.type);
  10772. });
  10773. pendingUNSAFE_ComponentWillMountWarnings = [];
  10774. }
  10775. var componentWillReceivePropsUniqueNames = new Set();
  10776. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  10777. pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
  10778. componentWillReceivePropsUniqueNames.add(getComponentNameFromFiber(fiber) || 'Component');
  10779. didWarnAboutUnsafeLifecycles.add(fiber.type);
  10780. });
  10781. pendingComponentWillReceivePropsWarnings = [];
  10782. }
  10783. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  10784. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  10785. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
  10786. UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentNameFromFiber(fiber) || 'Component');
  10787. didWarnAboutUnsafeLifecycles.add(fiber.type);
  10788. });
  10789. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  10790. }
  10791. var componentWillUpdateUniqueNames = new Set();
  10792. if (pendingComponentWillUpdateWarnings.length > 0) {
  10793. pendingComponentWillUpdateWarnings.forEach(function (fiber) {
  10794. componentWillUpdateUniqueNames.add(getComponentNameFromFiber(fiber) || 'Component');
  10795. didWarnAboutUnsafeLifecycles.add(fiber.type);
  10796. });
  10797. pendingComponentWillUpdateWarnings = [];
  10798. }
  10799. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  10800. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  10801. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
  10802. UNSAFE_componentWillUpdateUniqueNames.add(getComponentNameFromFiber(fiber) || 'Component');
  10803. didWarnAboutUnsafeLifecycles.add(fiber.type);
  10804. });
  10805. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  10806. } // Finally, we flush all the warnings
  10807. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  10808. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  10809. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  10810. error('Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' + 'See https://reactjs.org/link/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);
  10811. }
  10812. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  10813. var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
  10814. error('Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://reactjs.org/link/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://reactjs.org/link/derived-state\n' + '\nPlease update the following components: %s', _sortedNames);
  10815. }
  10816. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  10817. var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
  10818. error('Using UNSAFE_componentWillUpdate in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + '\nPlease update the following components: %s', _sortedNames2);
  10819. }
  10820. if (componentWillMountUniqueNames.size > 0) {
  10821. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  10822. warn('componentWillMount has been renamed, and is not recommended for use. ' + 'See https://reactjs.org/link/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 18.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);
  10823. }
  10824. if (componentWillReceivePropsUniqueNames.size > 0) {
  10825. var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
  10826. warn('componentWillReceiveProps has been renamed, and is not recommended for use. ' + 'See https://reactjs.org/link/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://reactjs.org/link/derived-state\n' + '* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' + 'this warning in non-strict mode. In React 18.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);
  10827. }
  10828. if (componentWillUpdateUniqueNames.size > 0) {
  10829. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  10830. warn('componentWillUpdate has been renamed, and is not recommended for use. ' + 'See https://reactjs.org/link/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 18.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);
  10831. }
  10832. };
  10833. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  10834. var didWarnAboutLegacyContext = new Set();
  10835. ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
  10836. var strictRoot = findStrictRoot(fiber);
  10837. if (strictRoot === null) {
  10838. 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.');
  10839. return;
  10840. } // Dedup strategy: Warn once per component.
  10841. if (didWarnAboutLegacyContext.has(fiber.type)) {
  10842. return;
  10843. }
  10844. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  10845. if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
  10846. if (warningsForRoot === undefined) {
  10847. warningsForRoot = [];
  10848. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  10849. }
  10850. warningsForRoot.push(fiber);
  10851. }
  10852. };
  10853. ReactStrictModeWarnings.flushLegacyContextWarning = function () {
  10854. pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
  10855. if (fiberArray.length === 0) {
  10856. return;
  10857. }
  10858. var firstFiber = fiberArray[0];
  10859. var uniqueNames = new Set();
  10860. fiberArray.forEach(function (fiber) {
  10861. uniqueNames.add(getComponentNameFromFiber(fiber) || 'Component');
  10862. didWarnAboutLegacyContext.add(fiber.type);
  10863. });
  10864. var sortedNames = setToSortedString(uniqueNames);
  10865. try {
  10866. setCurrentFiber(firstFiber);
  10867. 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://reactjs.org/link/legacy-context', sortedNames);
  10868. } finally {
  10869. resetCurrentFiber();
  10870. }
  10871. });
  10872. };
  10873. ReactStrictModeWarnings.discardPendingWarnings = function () {
  10874. pendingComponentWillMountWarnings = [];
  10875. pendingUNSAFE_ComponentWillMountWarnings = [];
  10876. pendingComponentWillReceivePropsWarnings = [];
  10877. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  10878. pendingComponentWillUpdateWarnings = [];
  10879. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  10880. pendingLegacyContextWarning = new Map();
  10881. };
  10882. }
  10883. function resolveDefaultProps(Component, baseProps) {
  10884. if (Component && Component.defaultProps) {
  10885. // Resolve default props. Taken from ReactElement
  10886. var props = assign({}, baseProps);
  10887. var defaultProps = Component.defaultProps;
  10888. for (var propName in defaultProps) {
  10889. if (props[propName] === undefined) {
  10890. props[propName] = defaultProps[propName];
  10891. }
  10892. }
  10893. return props;
  10894. }
  10895. return baseProps;
  10896. }
  10897. var valueCursor = createCursor(null);
  10898. var rendererSigil;
  10899. {
  10900. // Use this to detect multiple renderers using the same context
  10901. rendererSigil = {};
  10902. }
  10903. var currentlyRenderingFiber = null;
  10904. var lastContextDependency = null;
  10905. var lastFullyObservedContext = null;
  10906. var isDisallowedContextReadInDEV = false;
  10907. function resetContextDependencies() {
  10908. // This is called right before React yields execution, to ensure `readContext`
  10909. // cannot be called outside the render phase.
  10910. currentlyRenderingFiber = null;
  10911. lastContextDependency = null;
  10912. lastFullyObservedContext = null;
  10913. {
  10914. isDisallowedContextReadInDEV = false;
  10915. }
  10916. }
  10917. function enterDisallowedContextReadInDEV() {
  10918. {
  10919. isDisallowedContextReadInDEV = true;
  10920. }
  10921. }
  10922. function exitDisallowedContextReadInDEV() {
  10923. {
  10924. isDisallowedContextReadInDEV = false;
  10925. }
  10926. }
  10927. function pushProvider(providerFiber, context, nextValue) {
  10928. {
  10929. push(valueCursor, context._currentValue, providerFiber);
  10930. context._currentValue = nextValue;
  10931. {
  10932. if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
  10933. error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
  10934. }
  10935. context._currentRenderer = rendererSigil;
  10936. }
  10937. }
  10938. }
  10939. function popProvider(context, providerFiber) {
  10940. var currentValue = valueCursor.current;
  10941. pop(valueCursor, providerFiber);
  10942. {
  10943. {
  10944. context._currentValue = currentValue;
  10945. }
  10946. }
  10947. }
  10948. function scheduleContextWorkOnParentPath(parent, renderLanes, propagationRoot) {
  10949. // Update the child lanes of all the ancestors, including the alternates.
  10950. var node = parent;
  10951. while (node !== null) {
  10952. var alternate = node.alternate;
  10953. if (!isSubsetOfLanes(node.childLanes, renderLanes)) {
  10954. node.childLanes = mergeLanes(node.childLanes, renderLanes);
  10955. if (alternate !== null) {
  10956. alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
  10957. }
  10958. } else if (alternate !== null && !isSubsetOfLanes(alternate.childLanes, renderLanes)) {
  10959. alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
  10960. }
  10961. if (node === propagationRoot) {
  10962. break;
  10963. }
  10964. node = node.return;
  10965. }
  10966. {
  10967. if (node !== propagationRoot) {
  10968. error('Expected to find the propagation root when scheduling context work. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  10969. }
  10970. }
  10971. }
  10972. function propagateContextChange(workInProgress, context, renderLanes) {
  10973. {
  10974. propagateContextChange_eager(workInProgress, context, renderLanes);
  10975. }
  10976. }
  10977. function propagateContextChange_eager(workInProgress, context, renderLanes) {
  10978. var fiber = workInProgress.child;
  10979. if (fiber !== null) {
  10980. // Set the return pointer of the child to the work-in-progress fiber.
  10981. fiber.return = workInProgress;
  10982. }
  10983. while (fiber !== null) {
  10984. var nextFiber = void 0; // Visit this fiber.
  10985. var list = fiber.dependencies;
  10986. if (list !== null) {
  10987. nextFiber = fiber.child;
  10988. var dependency = list.firstContext;
  10989. while (dependency !== null) {
  10990. // Check if the context matches.
  10991. if (dependency.context === context) {
  10992. // Match! Schedule an update on this fiber.
  10993. if (fiber.tag === ClassComponent) {
  10994. // Schedule a force update on the work-in-progress.
  10995. var lane = pickArbitraryLane(renderLanes);
  10996. var update = createUpdate(NoTimestamp, lane);
  10997. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  10998. // update to the current fiber, too, which means it will persist even if
  10999. // this render is thrown away. Since it's a race condition, not sure it's
  11000. // worth fixing.
  11001. // Inlined `enqueueUpdate` to remove interleaved update check
  11002. var updateQueue = fiber.updateQueue;
  11003. if (updateQueue === null) ; else {
  11004. var sharedQueue = updateQueue.shared;
  11005. var pending = sharedQueue.pending;
  11006. if (pending === null) {
  11007. // This is the first update. Create a circular list.
  11008. update.next = update;
  11009. } else {
  11010. update.next = pending.next;
  11011. pending.next = update;
  11012. }
  11013. sharedQueue.pending = update;
  11014. }
  11015. }
  11016. fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
  11017. var alternate = fiber.alternate;
  11018. if (alternate !== null) {
  11019. alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
  11020. }
  11021. scheduleContextWorkOnParentPath(fiber.return, renderLanes, workInProgress); // Mark the updated lanes on the list, too.
  11022. list.lanes = mergeLanes(list.lanes, renderLanes); // Since we already found a match, we can stop traversing the
  11023. // dependency list.
  11024. break;
  11025. }
  11026. dependency = dependency.next;
  11027. }
  11028. } else if (fiber.tag === ContextProvider) {
  11029. // Don't scan deeper if this is a matching provider
  11030. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  11031. } else if (fiber.tag === DehydratedFragment) {
  11032. // If a dehydrated suspense boundary is in this subtree, we don't know
  11033. // if it will have any context consumers in it. The best we can do is
  11034. // mark it as having updates.
  11035. var parentSuspense = fiber.return;
  11036. if (parentSuspense === null) {
  11037. throw new Error('We just came from a parent so we must have had a parent. This is a bug in React.');
  11038. }
  11039. parentSuspense.lanes = mergeLanes(parentSuspense.lanes, renderLanes);
  11040. var _alternate = parentSuspense.alternate;
  11041. if (_alternate !== null) {
  11042. _alternate.lanes = mergeLanes(_alternate.lanes, renderLanes);
  11043. } // This is intentionally passing this fiber as the parent
  11044. // because we want to schedule this fiber as having work
  11045. // on its children. We'll use the childLanes on
  11046. // this fiber to indicate that a context has changed.
  11047. scheduleContextWorkOnParentPath(parentSuspense, renderLanes, workInProgress);
  11048. nextFiber = fiber.sibling;
  11049. } else {
  11050. // Traverse down.
  11051. nextFiber = fiber.child;
  11052. }
  11053. if (nextFiber !== null) {
  11054. // Set the return pointer of the child to the work-in-progress fiber.
  11055. nextFiber.return = fiber;
  11056. } else {
  11057. // No child. Traverse to next sibling.
  11058. nextFiber = fiber;
  11059. while (nextFiber !== null) {
  11060. if (nextFiber === workInProgress) {
  11061. // We're back to the root of this subtree. Exit.
  11062. nextFiber = null;
  11063. break;
  11064. }
  11065. var sibling = nextFiber.sibling;
  11066. if (sibling !== null) {
  11067. // Set the return pointer of the sibling to the work-in-progress fiber.
  11068. sibling.return = nextFiber.return;
  11069. nextFiber = sibling;
  11070. break;
  11071. } // No more siblings. Traverse up.
  11072. nextFiber = nextFiber.return;
  11073. }
  11074. }
  11075. fiber = nextFiber;
  11076. }
  11077. }
  11078. function prepareToReadContext(workInProgress, renderLanes) {
  11079. currentlyRenderingFiber = workInProgress;
  11080. lastContextDependency = null;
  11081. lastFullyObservedContext = null;
  11082. var dependencies = workInProgress.dependencies;
  11083. if (dependencies !== null) {
  11084. {
  11085. var firstContext = dependencies.firstContext;
  11086. if (firstContext !== null) {
  11087. if (includesSomeLane(dependencies.lanes, renderLanes)) {
  11088. // Context list has a pending update. Mark that this fiber performed work.
  11089. markWorkInProgressReceivedUpdate();
  11090. } // Reset the work-in-progress list
  11091. dependencies.firstContext = null;
  11092. }
  11093. }
  11094. }
  11095. }
  11096. function readContext(context) {
  11097. {
  11098. // This warning would fire if you read context inside a Hook like useMemo.
  11099. // Unlike the class check below, it's not enforced in production for perf.
  11100. if (isDisallowedContextReadInDEV) {
  11101. 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().');
  11102. }
  11103. }
  11104. var value = context._currentValue ;
  11105. if (lastFullyObservedContext === context) ; else {
  11106. var contextItem = {
  11107. context: context,
  11108. memoizedValue: value,
  11109. next: null
  11110. };
  11111. if (lastContextDependency === null) {
  11112. if (currentlyRenderingFiber === null) {
  11113. throw new 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().');
  11114. } // This is the first dependency for this component. Create a new list.
  11115. lastContextDependency = contextItem;
  11116. currentlyRenderingFiber.dependencies = {
  11117. lanes: NoLanes,
  11118. firstContext: contextItem
  11119. };
  11120. } else {
  11121. // Append a new context item.
  11122. lastContextDependency = lastContextDependency.next = contextItem;
  11123. }
  11124. }
  11125. return value;
  11126. }
  11127. // render. When this render exits, either because it finishes or because it is
  11128. // interrupted, the interleaved updates will be transferred onto the main part
  11129. // of the queue.
  11130. var concurrentQueues = null;
  11131. function pushConcurrentUpdateQueue(queue) {
  11132. if (concurrentQueues === null) {
  11133. concurrentQueues = [queue];
  11134. } else {
  11135. concurrentQueues.push(queue);
  11136. }
  11137. }
  11138. function finishQueueingConcurrentUpdates() {
  11139. // Transfer the interleaved updates onto the main queue. Each queue has a
  11140. // `pending` field and an `interleaved` field. When they are not null, they
  11141. // point to the last node in a circular linked list. We need to append the
  11142. // interleaved list to the end of the pending list by joining them into a
  11143. // single, circular list.
  11144. if (concurrentQueues !== null) {
  11145. for (var i = 0; i < concurrentQueues.length; i++) {
  11146. var queue = concurrentQueues[i];
  11147. var lastInterleavedUpdate = queue.interleaved;
  11148. if (lastInterleavedUpdate !== null) {
  11149. queue.interleaved = null;
  11150. var firstInterleavedUpdate = lastInterleavedUpdate.next;
  11151. var lastPendingUpdate = queue.pending;
  11152. if (lastPendingUpdate !== null) {
  11153. var firstPendingUpdate = lastPendingUpdate.next;
  11154. lastPendingUpdate.next = firstInterleavedUpdate;
  11155. lastInterleavedUpdate.next = firstPendingUpdate;
  11156. }
  11157. queue.pending = lastInterleavedUpdate;
  11158. }
  11159. }
  11160. concurrentQueues = null;
  11161. }
  11162. }
  11163. function enqueueConcurrentHookUpdate(fiber, queue, update, lane) {
  11164. var interleaved = queue.interleaved;
  11165. if (interleaved === null) {
  11166. // This is the first update. Create a circular list.
  11167. update.next = update; // At the end of the current render, this queue's interleaved updates will
  11168. // be transferred to the pending queue.
  11169. pushConcurrentUpdateQueue(queue);
  11170. } else {
  11171. update.next = interleaved.next;
  11172. interleaved.next = update;
  11173. }
  11174. queue.interleaved = update;
  11175. return markUpdateLaneFromFiberToRoot(fiber, lane);
  11176. }
  11177. function enqueueConcurrentHookUpdateAndEagerlyBailout(fiber, queue, update, lane) {
  11178. var interleaved = queue.interleaved;
  11179. if (interleaved === null) {
  11180. // This is the first update. Create a circular list.
  11181. update.next = update; // At the end of the current render, this queue's interleaved updates will
  11182. // be transferred to the pending queue.
  11183. pushConcurrentUpdateQueue(queue);
  11184. } else {
  11185. update.next = interleaved.next;
  11186. interleaved.next = update;
  11187. }
  11188. queue.interleaved = update;
  11189. }
  11190. function enqueueConcurrentClassUpdate(fiber, queue, update, lane) {
  11191. var interleaved = queue.interleaved;
  11192. if (interleaved === null) {
  11193. // This is the first update. Create a circular list.
  11194. update.next = update; // At the end of the current render, this queue's interleaved updates will
  11195. // be transferred to the pending queue.
  11196. pushConcurrentUpdateQueue(queue);
  11197. } else {
  11198. update.next = interleaved.next;
  11199. interleaved.next = update;
  11200. }
  11201. queue.interleaved = update;
  11202. return markUpdateLaneFromFiberToRoot(fiber, lane);
  11203. }
  11204. function enqueueConcurrentRenderForLane(fiber, lane) {
  11205. return markUpdateLaneFromFiberToRoot(fiber, lane);
  11206. } // Calling this function outside this module should only be done for backwards
  11207. // compatibility and should always be accompanied by a warning.
  11208. var unsafe_markUpdateLaneFromFiberToRoot = markUpdateLaneFromFiberToRoot;
  11209. function markUpdateLaneFromFiberToRoot(sourceFiber, lane) {
  11210. // Update the source fiber's lanes
  11211. sourceFiber.lanes = mergeLanes(sourceFiber.lanes, lane);
  11212. var alternate = sourceFiber.alternate;
  11213. if (alternate !== null) {
  11214. alternate.lanes = mergeLanes(alternate.lanes, lane);
  11215. }
  11216. {
  11217. if (alternate === null && (sourceFiber.flags & (Placement | Hydrating)) !== NoFlags) {
  11218. warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
  11219. }
  11220. } // Walk the parent path to the root and update the child lanes.
  11221. var node = sourceFiber;
  11222. var parent = sourceFiber.return;
  11223. while (parent !== null) {
  11224. parent.childLanes = mergeLanes(parent.childLanes, lane);
  11225. alternate = parent.alternate;
  11226. if (alternate !== null) {
  11227. alternate.childLanes = mergeLanes(alternate.childLanes, lane);
  11228. } else {
  11229. {
  11230. if ((parent.flags & (Placement | Hydrating)) !== NoFlags) {
  11231. warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
  11232. }
  11233. }
  11234. }
  11235. node = parent;
  11236. parent = parent.return;
  11237. }
  11238. if (node.tag === HostRoot) {
  11239. var root = node.stateNode;
  11240. return root;
  11241. } else {
  11242. return null;
  11243. }
  11244. }
  11245. var UpdateState = 0;
  11246. var ReplaceState = 1;
  11247. var ForceUpdate = 2;
  11248. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  11249. // It should only be read right after calling `processUpdateQueue`, via
  11250. // `checkHasForceUpdateAfterProcessing`.
  11251. var hasForceUpdate = false;
  11252. var didWarnUpdateInsideUpdate;
  11253. var currentlyProcessingQueue;
  11254. {
  11255. didWarnUpdateInsideUpdate = false;
  11256. currentlyProcessingQueue = null;
  11257. }
  11258. function initializeUpdateQueue(fiber) {
  11259. var queue = {
  11260. baseState: fiber.memoizedState,
  11261. firstBaseUpdate: null,
  11262. lastBaseUpdate: null,
  11263. shared: {
  11264. pending: null,
  11265. interleaved: null,
  11266. lanes: NoLanes
  11267. },
  11268. effects: null
  11269. };
  11270. fiber.updateQueue = queue;
  11271. }
  11272. function cloneUpdateQueue(current, workInProgress) {
  11273. // Clone the update queue from current. Unless it's already a clone.
  11274. var queue = workInProgress.updateQueue;
  11275. var currentQueue = current.updateQueue;
  11276. if (queue === currentQueue) {
  11277. var clone = {
  11278. baseState: currentQueue.baseState,
  11279. firstBaseUpdate: currentQueue.firstBaseUpdate,
  11280. lastBaseUpdate: currentQueue.lastBaseUpdate,
  11281. shared: currentQueue.shared,
  11282. effects: currentQueue.effects
  11283. };
  11284. workInProgress.updateQueue = clone;
  11285. }
  11286. }
  11287. function createUpdate(eventTime, lane) {
  11288. var update = {
  11289. eventTime: eventTime,
  11290. lane: lane,
  11291. tag: UpdateState,
  11292. payload: null,
  11293. callback: null,
  11294. next: null
  11295. };
  11296. return update;
  11297. }
  11298. function enqueueUpdate(fiber, update, lane) {
  11299. var updateQueue = fiber.updateQueue;
  11300. if (updateQueue === null) {
  11301. // Only occurs if the fiber has been unmounted.
  11302. return null;
  11303. }
  11304. var sharedQueue = updateQueue.shared;
  11305. {
  11306. if (currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate) {
  11307. 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.');
  11308. didWarnUpdateInsideUpdate = true;
  11309. }
  11310. }
  11311. if (isUnsafeClassRenderPhaseUpdate()) {
  11312. // This is an unsafe render phase update. Add directly to the update
  11313. // queue so we can process it immediately during the current render.
  11314. var pending = sharedQueue.pending;
  11315. if (pending === null) {
  11316. // This is the first update. Create a circular list.
  11317. update.next = update;
  11318. } else {
  11319. update.next = pending.next;
  11320. pending.next = update;
  11321. }
  11322. sharedQueue.pending = update; // Update the childLanes even though we're most likely already rendering
  11323. // this fiber. This is for backwards compatibility in the case where you
  11324. // update a different component during render phase than the one that is
  11325. // currently renderings (a pattern that is accompanied by a warning).
  11326. return unsafe_markUpdateLaneFromFiberToRoot(fiber, lane);
  11327. } else {
  11328. return enqueueConcurrentClassUpdate(fiber, sharedQueue, update, lane);
  11329. }
  11330. }
  11331. function entangleTransitions(root, fiber, lane) {
  11332. var updateQueue = fiber.updateQueue;
  11333. if (updateQueue === null) {
  11334. // Only occurs if the fiber has been unmounted.
  11335. return;
  11336. }
  11337. var sharedQueue = updateQueue.shared;
  11338. if (isTransitionLane(lane)) {
  11339. var queueLanes = sharedQueue.lanes; // If any entangled lanes are no longer pending on the root, then they must
  11340. // have finished. We can remove them from the shared queue, which represents
  11341. // a superset of the actually pending lanes. In some cases we may entangle
  11342. // more than we need to, but that's OK. In fact it's worse if we *don't*
  11343. // entangle when we should.
  11344. queueLanes = intersectLanes(queueLanes, root.pendingLanes); // Entangle the new transition lane with the other transition lanes.
  11345. var newQueueLanes = mergeLanes(queueLanes, lane);
  11346. sharedQueue.lanes = newQueueLanes; // Even if queue.lanes already include lane, we don't know for certain if
  11347. // the lane finished since the last time we entangled it. So we need to
  11348. // entangle it again, just to be sure.
  11349. markRootEntangled(root, newQueueLanes);
  11350. }
  11351. }
  11352. function enqueueCapturedUpdate(workInProgress, capturedUpdate) {
  11353. // Captured updates are updates that are thrown by a child during the render
  11354. // phase. They should be discarded if the render is aborted. Therefore,
  11355. // we should only put them on the work-in-progress queue, not the current one.
  11356. var queue = workInProgress.updateQueue; // Check if the work-in-progress queue is a clone.
  11357. var current = workInProgress.alternate;
  11358. if (current !== null) {
  11359. var currentQueue = current.updateQueue;
  11360. if (queue === currentQueue) {
  11361. // The work-in-progress queue is the same as current. This happens when
  11362. // we bail out on a parent fiber that then captures an error thrown by
  11363. // a child. Since we want to append the update only to the work-in
  11364. // -progress queue, we need to clone the updates. We usually clone during
  11365. // processUpdateQueue, but that didn't happen in this case because we
  11366. // skipped over the parent when we bailed out.
  11367. var newFirst = null;
  11368. var newLast = null;
  11369. var firstBaseUpdate = queue.firstBaseUpdate;
  11370. if (firstBaseUpdate !== null) {
  11371. // Loop through the updates and clone them.
  11372. var update = firstBaseUpdate;
  11373. do {
  11374. var clone = {
  11375. eventTime: update.eventTime,
  11376. lane: update.lane,
  11377. tag: update.tag,
  11378. payload: update.payload,
  11379. callback: update.callback,
  11380. next: null
  11381. };
  11382. if (newLast === null) {
  11383. newFirst = newLast = clone;
  11384. } else {
  11385. newLast.next = clone;
  11386. newLast = clone;
  11387. }
  11388. update = update.next;
  11389. } while (update !== null); // Append the captured update the end of the cloned list.
  11390. if (newLast === null) {
  11391. newFirst = newLast = capturedUpdate;
  11392. } else {
  11393. newLast.next = capturedUpdate;
  11394. newLast = capturedUpdate;
  11395. }
  11396. } else {
  11397. // There are no base updates.
  11398. newFirst = newLast = capturedUpdate;
  11399. }
  11400. queue = {
  11401. baseState: currentQueue.baseState,
  11402. firstBaseUpdate: newFirst,
  11403. lastBaseUpdate: newLast,
  11404. shared: currentQueue.shared,
  11405. effects: currentQueue.effects
  11406. };
  11407. workInProgress.updateQueue = queue;
  11408. return;
  11409. }
  11410. } // Append the update to the end of the list.
  11411. var lastBaseUpdate = queue.lastBaseUpdate;
  11412. if (lastBaseUpdate === null) {
  11413. queue.firstBaseUpdate = capturedUpdate;
  11414. } else {
  11415. lastBaseUpdate.next = capturedUpdate;
  11416. }
  11417. queue.lastBaseUpdate = capturedUpdate;
  11418. }
  11419. function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
  11420. switch (update.tag) {
  11421. case ReplaceState:
  11422. {
  11423. var payload = update.payload;
  11424. if (typeof payload === 'function') {
  11425. // Updater function
  11426. {
  11427. enterDisallowedContextReadInDEV();
  11428. }
  11429. var nextState = payload.call(instance, prevState, nextProps);
  11430. {
  11431. if ( workInProgress.mode & StrictLegacyMode) {
  11432. setIsStrictModeForDevtools(true);
  11433. try {
  11434. payload.call(instance, prevState, nextProps);
  11435. } finally {
  11436. setIsStrictModeForDevtools(false);
  11437. }
  11438. }
  11439. exitDisallowedContextReadInDEV();
  11440. }
  11441. return nextState;
  11442. } // State object
  11443. return payload;
  11444. }
  11445. case CaptureUpdate:
  11446. {
  11447. workInProgress.flags = workInProgress.flags & ~ShouldCapture | DidCapture;
  11448. }
  11449. // Intentional fallthrough
  11450. case UpdateState:
  11451. {
  11452. var _payload = update.payload;
  11453. var partialState;
  11454. if (typeof _payload === 'function') {
  11455. // Updater function
  11456. {
  11457. enterDisallowedContextReadInDEV();
  11458. }
  11459. partialState = _payload.call(instance, prevState, nextProps);
  11460. {
  11461. if ( workInProgress.mode & StrictLegacyMode) {
  11462. setIsStrictModeForDevtools(true);
  11463. try {
  11464. _payload.call(instance, prevState, nextProps);
  11465. } finally {
  11466. setIsStrictModeForDevtools(false);
  11467. }
  11468. }
  11469. exitDisallowedContextReadInDEV();
  11470. }
  11471. } else {
  11472. // Partial state object
  11473. partialState = _payload;
  11474. }
  11475. if (partialState === null || partialState === undefined) {
  11476. // Null and undefined are treated as no-ops.
  11477. return prevState;
  11478. } // Merge the partial state and the previous state.
  11479. return assign({}, prevState, partialState);
  11480. }
  11481. case ForceUpdate:
  11482. {
  11483. hasForceUpdate = true;
  11484. return prevState;
  11485. }
  11486. }
  11487. return prevState;
  11488. }
  11489. function processUpdateQueue(workInProgress, props, instance, renderLanes) {
  11490. // This is always non-null on a ClassComponent or HostRoot
  11491. var queue = workInProgress.updateQueue;
  11492. hasForceUpdate = false;
  11493. {
  11494. currentlyProcessingQueue = queue.shared;
  11495. }
  11496. var firstBaseUpdate = queue.firstBaseUpdate;
  11497. var lastBaseUpdate = queue.lastBaseUpdate; // Check if there are pending updates. If so, transfer them to the base queue.
  11498. var pendingQueue = queue.shared.pending;
  11499. if (pendingQueue !== null) {
  11500. queue.shared.pending = null; // The pending queue is circular. Disconnect the pointer between first
  11501. // and last so that it's non-circular.
  11502. var lastPendingUpdate = pendingQueue;
  11503. var firstPendingUpdate = lastPendingUpdate.next;
  11504. lastPendingUpdate.next = null; // Append pending updates to base queue
  11505. if (lastBaseUpdate === null) {
  11506. firstBaseUpdate = firstPendingUpdate;
  11507. } else {
  11508. lastBaseUpdate.next = firstPendingUpdate;
  11509. }
  11510. lastBaseUpdate = lastPendingUpdate; // If there's a current queue, and it's different from the base queue, then
  11511. // we need to transfer the updates to that queue, too. Because the base
  11512. // queue is a singly-linked list with no cycles, we can append to both
  11513. // lists and take advantage of structural sharing.
  11514. // TODO: Pass `current` as argument
  11515. var current = workInProgress.alternate;
  11516. if (current !== null) {
  11517. // This is always non-null on a ClassComponent or HostRoot
  11518. var currentQueue = current.updateQueue;
  11519. var currentLastBaseUpdate = currentQueue.lastBaseUpdate;
  11520. if (currentLastBaseUpdate !== lastBaseUpdate) {
  11521. if (currentLastBaseUpdate === null) {
  11522. currentQueue.firstBaseUpdate = firstPendingUpdate;
  11523. } else {
  11524. currentLastBaseUpdate.next = firstPendingUpdate;
  11525. }
  11526. currentQueue.lastBaseUpdate = lastPendingUpdate;
  11527. }
  11528. }
  11529. } // These values may change as we process the queue.
  11530. if (firstBaseUpdate !== null) {
  11531. // Iterate through the list of updates to compute the result.
  11532. var newState = queue.baseState; // TODO: Don't need to accumulate this. Instead, we can remove renderLanes
  11533. // from the original lanes.
  11534. var newLanes = NoLanes;
  11535. var newBaseState = null;
  11536. var newFirstBaseUpdate = null;
  11537. var newLastBaseUpdate = null;
  11538. var update = firstBaseUpdate;
  11539. do {
  11540. var updateLane = update.lane;
  11541. var updateEventTime = update.eventTime;
  11542. if (!isSubsetOfLanes(renderLanes, updateLane)) {
  11543. // Priority is insufficient. Skip this update. If this is the first
  11544. // skipped update, the previous update/state is the new base
  11545. // update/state.
  11546. var clone = {
  11547. eventTime: updateEventTime,
  11548. lane: updateLane,
  11549. tag: update.tag,
  11550. payload: update.payload,
  11551. callback: update.callback,
  11552. next: null
  11553. };
  11554. if (newLastBaseUpdate === null) {
  11555. newFirstBaseUpdate = newLastBaseUpdate = clone;
  11556. newBaseState = newState;
  11557. } else {
  11558. newLastBaseUpdate = newLastBaseUpdate.next = clone;
  11559. } // Update the remaining priority in the queue.
  11560. newLanes = mergeLanes(newLanes, updateLane);
  11561. } else {
  11562. // This update does have sufficient priority.
  11563. if (newLastBaseUpdate !== null) {
  11564. var _clone = {
  11565. eventTime: updateEventTime,
  11566. // This update is going to be committed so we never want uncommit
  11567. // it. Using NoLane works because 0 is a subset of all bitmasks, so
  11568. // this will never be skipped by the check above.
  11569. lane: NoLane,
  11570. tag: update.tag,
  11571. payload: update.payload,
  11572. callback: update.callback,
  11573. next: null
  11574. };
  11575. newLastBaseUpdate = newLastBaseUpdate.next = _clone;
  11576. } // Process this update.
  11577. newState = getStateFromUpdate(workInProgress, queue, update, newState, props, instance);
  11578. var callback = update.callback;
  11579. if (callback !== null && // If the update was already committed, we should not queue its
  11580. // callback again.
  11581. update.lane !== NoLane) {
  11582. workInProgress.flags |= Callback;
  11583. var effects = queue.effects;
  11584. if (effects === null) {
  11585. queue.effects = [update];
  11586. } else {
  11587. effects.push(update);
  11588. }
  11589. }
  11590. }
  11591. update = update.next;
  11592. if (update === null) {
  11593. pendingQueue = queue.shared.pending;
  11594. if (pendingQueue === null) {
  11595. break;
  11596. } else {
  11597. // An update was scheduled from inside a reducer. Add the new
  11598. // pending updates to the end of the list and keep processing.
  11599. var _lastPendingUpdate = pendingQueue; // Intentionally unsound. Pending updates form a circular list, but we
  11600. // unravel them when transferring them to the base queue.
  11601. var _firstPendingUpdate = _lastPendingUpdate.next;
  11602. _lastPendingUpdate.next = null;
  11603. update = _firstPendingUpdate;
  11604. queue.lastBaseUpdate = _lastPendingUpdate;
  11605. queue.shared.pending = null;
  11606. }
  11607. }
  11608. } while (true);
  11609. if (newLastBaseUpdate === null) {
  11610. newBaseState = newState;
  11611. }
  11612. queue.baseState = newBaseState;
  11613. queue.firstBaseUpdate = newFirstBaseUpdate;
  11614. queue.lastBaseUpdate = newLastBaseUpdate; // Interleaved updates are stored on a separate queue. We aren't going to
  11615. // process them during this render, but we do need to track which lanes
  11616. // are remaining.
  11617. var lastInterleaved = queue.shared.interleaved;
  11618. if (lastInterleaved !== null) {
  11619. var interleaved = lastInterleaved;
  11620. do {
  11621. newLanes = mergeLanes(newLanes, interleaved.lane);
  11622. interleaved = interleaved.next;
  11623. } while (interleaved !== lastInterleaved);
  11624. } else if (firstBaseUpdate === null) {
  11625. // `queue.lanes` is used for entangling transitions. We can set it back to
  11626. // zero once the queue is empty.
  11627. queue.shared.lanes = NoLanes;
  11628. } // Set the remaining expiration time to be whatever is remaining in the queue.
  11629. // This should be fine because the only two other things that contribute to
  11630. // expiration time are props and context. We're already in the middle of the
  11631. // begin phase by the time we start processing the queue, so we've already
  11632. // dealt with the props. Context in components that specify
  11633. // shouldComponentUpdate is tricky; but we'll have to account for
  11634. // that regardless.
  11635. markSkippedUpdateLanes(newLanes);
  11636. workInProgress.lanes = newLanes;
  11637. workInProgress.memoizedState = newState;
  11638. }
  11639. {
  11640. currentlyProcessingQueue = null;
  11641. }
  11642. }
  11643. function callCallback(callback, context) {
  11644. if (typeof callback !== 'function') {
  11645. throw new Error('Invalid argument passed as callback. Expected a function. Instead ' + ("received: " + callback));
  11646. }
  11647. callback.call(context);
  11648. }
  11649. function resetHasForceUpdateBeforeProcessing() {
  11650. hasForceUpdate = false;
  11651. }
  11652. function checkHasForceUpdateAfterProcessing() {
  11653. return hasForceUpdate;
  11654. }
  11655. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  11656. // Commit the effects
  11657. var effects = finishedQueue.effects;
  11658. finishedQueue.effects = null;
  11659. if (effects !== null) {
  11660. for (var i = 0; i < effects.length; i++) {
  11661. var effect = effects[i];
  11662. var callback = effect.callback;
  11663. if (callback !== null) {
  11664. effect.callback = null;
  11665. callCallback(callback, instance);
  11666. }
  11667. }
  11668. }
  11669. }
  11670. var fakeInternalInstance = {}; // React.Component uses a shared frozen object by default.
  11671. // We'll use it to determine whether we need to initialize legacy refs.
  11672. var emptyRefsObject = new React.Component().refs;
  11673. var didWarnAboutStateAssignmentForComponent;
  11674. var didWarnAboutUninitializedState;
  11675. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  11676. var didWarnAboutLegacyLifecyclesAndDerivedState;
  11677. var didWarnAboutUndefinedDerivedState;
  11678. var warnOnUndefinedDerivedState;
  11679. var warnOnInvalidCallback;
  11680. var didWarnAboutDirectlyAssigningPropsToState;
  11681. var didWarnAboutContextTypeAndContextTypes;
  11682. var didWarnAboutInvalidateContextType;
  11683. {
  11684. didWarnAboutStateAssignmentForComponent = new Set();
  11685. didWarnAboutUninitializedState = new Set();
  11686. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  11687. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  11688. didWarnAboutDirectlyAssigningPropsToState = new Set();
  11689. didWarnAboutUndefinedDerivedState = new Set();
  11690. didWarnAboutContextTypeAndContextTypes = new Set();
  11691. didWarnAboutInvalidateContextType = new Set();
  11692. var didWarnOnInvalidCallback = new Set();
  11693. warnOnInvalidCallback = function (callback, callerName) {
  11694. if (callback === null || typeof callback === 'function') {
  11695. return;
  11696. }
  11697. var key = callerName + '_' + callback;
  11698. if (!didWarnOnInvalidCallback.has(key)) {
  11699. didWarnOnInvalidCallback.add(key);
  11700. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  11701. }
  11702. };
  11703. warnOnUndefinedDerivedState = function (type, partialState) {
  11704. if (partialState === undefined) {
  11705. var componentName = getComponentNameFromType(type) || 'Component';
  11706. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  11707. didWarnAboutUndefinedDerivedState.add(componentName);
  11708. error('%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
  11709. }
  11710. }
  11711. }; // This is so gross but it's at least non-critical and can be removed if
  11712. // it causes problems. This is meant to give a nicer error message for
  11713. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  11714. // ...)) which otherwise throws a "_processChildContext is not a function"
  11715. // exception.
  11716. Object.defineProperty(fakeInternalInstance, '_processChildContext', {
  11717. enumerable: false,
  11718. value: function () {
  11719. throw new 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).');
  11720. }
  11721. });
  11722. Object.freeze(fakeInternalInstance);
  11723. }
  11724. function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
  11725. var prevState = workInProgress.memoizedState;
  11726. var partialState = getDerivedStateFromProps(nextProps, prevState);
  11727. {
  11728. if ( workInProgress.mode & StrictLegacyMode) {
  11729. setIsStrictModeForDevtools(true);
  11730. try {
  11731. // Invoke the function an extra time to help detect side-effects.
  11732. partialState = getDerivedStateFromProps(nextProps, prevState);
  11733. } finally {
  11734. setIsStrictModeForDevtools(false);
  11735. }
  11736. }
  11737. warnOnUndefinedDerivedState(ctor, partialState);
  11738. } // Merge the partial state and the previous state.
  11739. var memoizedState = partialState === null || partialState === undefined ? prevState : assign({}, prevState, partialState);
  11740. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  11741. // base state.
  11742. if (workInProgress.lanes === NoLanes) {
  11743. // Queue is always non-null for classes
  11744. var updateQueue = workInProgress.updateQueue;
  11745. updateQueue.baseState = memoizedState;
  11746. }
  11747. }
  11748. var classComponentUpdater = {
  11749. isMounted: isMounted,
  11750. enqueueSetState: function (inst, payload, callback) {
  11751. var fiber = get(inst);
  11752. var eventTime = requestEventTime();
  11753. var lane = requestUpdateLane(fiber);
  11754. var update = createUpdate(eventTime, lane);
  11755. update.payload = payload;
  11756. if (callback !== undefined && callback !== null) {
  11757. {
  11758. warnOnInvalidCallback(callback, 'setState');
  11759. }
  11760. update.callback = callback;
  11761. }
  11762. var root = enqueueUpdate(fiber, update, lane);
  11763. if (root !== null) {
  11764. scheduleUpdateOnFiber(root, fiber, lane, eventTime);
  11765. entangleTransitions(root, fiber, lane);
  11766. }
  11767. {
  11768. markStateUpdateScheduled(fiber, lane);
  11769. }
  11770. },
  11771. enqueueReplaceState: function (inst, payload, callback) {
  11772. var fiber = get(inst);
  11773. var eventTime = requestEventTime();
  11774. var lane = requestUpdateLane(fiber);
  11775. var update = createUpdate(eventTime, lane);
  11776. update.tag = ReplaceState;
  11777. update.payload = payload;
  11778. if (callback !== undefined && callback !== null) {
  11779. {
  11780. warnOnInvalidCallback(callback, 'replaceState');
  11781. }
  11782. update.callback = callback;
  11783. }
  11784. var root = enqueueUpdate(fiber, update, lane);
  11785. if (root !== null) {
  11786. scheduleUpdateOnFiber(root, fiber, lane, eventTime);
  11787. entangleTransitions(root, fiber, lane);
  11788. }
  11789. {
  11790. markStateUpdateScheduled(fiber, lane);
  11791. }
  11792. },
  11793. enqueueForceUpdate: function (inst, callback) {
  11794. var fiber = get(inst);
  11795. var eventTime = requestEventTime();
  11796. var lane = requestUpdateLane(fiber);
  11797. var update = createUpdate(eventTime, lane);
  11798. update.tag = ForceUpdate;
  11799. if (callback !== undefined && callback !== null) {
  11800. {
  11801. warnOnInvalidCallback(callback, 'forceUpdate');
  11802. }
  11803. update.callback = callback;
  11804. }
  11805. var root = enqueueUpdate(fiber, update, lane);
  11806. if (root !== null) {
  11807. scheduleUpdateOnFiber(root, fiber, lane, eventTime);
  11808. entangleTransitions(root, fiber, lane);
  11809. }
  11810. {
  11811. markForceUpdateScheduled(fiber, lane);
  11812. }
  11813. }
  11814. };
  11815. function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
  11816. var instance = workInProgress.stateNode;
  11817. if (typeof instance.shouldComponentUpdate === 'function') {
  11818. var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
  11819. {
  11820. if ( workInProgress.mode & StrictLegacyMode) {
  11821. setIsStrictModeForDevtools(true);
  11822. try {
  11823. // Invoke the function an extra time to help detect side-effects.
  11824. shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
  11825. } finally {
  11826. setIsStrictModeForDevtools(false);
  11827. }
  11828. }
  11829. if (shouldUpdate === undefined) {
  11830. error('%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentNameFromType(ctor) || 'Component');
  11831. }
  11832. }
  11833. return shouldUpdate;
  11834. }
  11835. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  11836. return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
  11837. }
  11838. return true;
  11839. }
  11840. function checkClassInstance(workInProgress, ctor, newProps) {
  11841. var instance = workInProgress.stateNode;
  11842. {
  11843. var name = getComponentNameFromType(ctor) || 'Component';
  11844. var renderPresent = instance.render;
  11845. if (!renderPresent) {
  11846. if (ctor.prototype && typeof ctor.prototype.render === 'function') {
  11847. error('%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
  11848. } else {
  11849. error('%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
  11850. }
  11851. }
  11852. if (instance.getInitialState && !instance.getInitialState.isReactClassApproved && !instance.state) {
  11853. 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);
  11854. }
  11855. if (instance.getDefaultProps && !instance.getDefaultProps.isReactClassApproved) {
  11856. 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);
  11857. }
  11858. if (instance.propTypes) {
  11859. error('propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name);
  11860. }
  11861. if (instance.contextType) {
  11862. error('contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name);
  11863. }
  11864. {
  11865. if (instance.contextTypes) {
  11866. error('contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name);
  11867. }
  11868. if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
  11869. didWarnAboutContextTypeAndContextTypes.add(ctor);
  11870. error('%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
  11871. }
  11872. }
  11873. if (typeof instance.componentShouldUpdate === 'function') {
  11874. 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);
  11875. }
  11876. if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
  11877. error('%s has a method called shouldComponentUpdate(). ' + 'shouldComponentUpdate should not be used when extending React.PureComponent. ' + 'Please extend React.Component if shouldComponentUpdate is used.', getComponentNameFromType(ctor) || 'A pure component');
  11878. }
  11879. if (typeof instance.componentDidUnmount === 'function') {
  11880. error('%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name);
  11881. }
  11882. if (typeof instance.componentDidReceiveProps === 'function') {
  11883. 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);
  11884. }
  11885. if (typeof instance.componentWillRecieveProps === 'function') {
  11886. error('%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name);
  11887. }
  11888. if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') {
  11889. error('%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name);
  11890. }
  11891. var hasMutatedProps = instance.props !== newProps;
  11892. if (instance.props !== undefined && hasMutatedProps) {
  11893. error('%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, name);
  11894. }
  11895. if (instance.defaultProps) {
  11896. 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);
  11897. }
  11898. if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
  11899. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  11900. error('%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentNameFromType(ctor));
  11901. }
  11902. if (typeof instance.getDerivedStateFromProps === 'function') {
  11903. error('%s: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  11904. }
  11905. if (typeof instance.getDerivedStateFromError === 'function') {
  11906. error('%s: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  11907. }
  11908. if (typeof ctor.getSnapshotBeforeUpdate === 'function') {
  11909. error('%s: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', name);
  11910. }
  11911. var _state = instance.state;
  11912. if (_state && (typeof _state !== 'object' || isArray(_state))) {
  11913. error('%s.state: must be set to an object or null', name);
  11914. }
  11915. if (typeof instance.getChildContext === 'function' && typeof ctor.childContextTypes !== 'object') {
  11916. error('%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name);
  11917. }
  11918. }
  11919. }
  11920. function adoptClassInstance(workInProgress, instance) {
  11921. instance.updater = classComponentUpdater;
  11922. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  11923. set(instance, workInProgress);
  11924. {
  11925. instance._reactInternalInstance = fakeInternalInstance;
  11926. }
  11927. }
  11928. function constructClassInstance(workInProgress, ctor, props) {
  11929. var isLegacyContextConsumer = false;
  11930. var unmaskedContext = emptyContextObject;
  11931. var context = emptyContextObject;
  11932. var contextType = ctor.contextType;
  11933. {
  11934. if ('contextType' in ctor) {
  11935. var isValid = // Allow null for conditional declaration
  11936. contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
  11937. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  11938. didWarnAboutInvalidateContextType.add(ctor);
  11939. var addendum = '';
  11940. if (contextType === undefined) {
  11941. 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.';
  11942. } else if (typeof contextType !== 'object') {
  11943. addendum = ' However, it is set to a ' + typeof contextType + '.';
  11944. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  11945. addendum = ' Did you accidentally pass the Context.Provider instead?';
  11946. } else if (contextType._context !== undefined) {
  11947. // <Context.Consumer>
  11948. addendum = ' Did you accidentally pass the Context.Consumer instead?';
  11949. } else {
  11950. addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
  11951. }
  11952. error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentNameFromType(ctor) || 'Component', addendum);
  11953. }
  11954. }
  11955. }
  11956. if (typeof contextType === 'object' && contextType !== null) {
  11957. context = readContext(contextType);
  11958. } else {
  11959. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  11960. var contextTypes = ctor.contextTypes;
  11961. isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
  11962. context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
  11963. }
  11964. var instance = new ctor(props, context); // Instantiate twice to help detect side-effects.
  11965. {
  11966. if ( workInProgress.mode & StrictLegacyMode) {
  11967. setIsStrictModeForDevtools(true);
  11968. try {
  11969. instance = new ctor(props, context); // eslint-disable-line no-new
  11970. } finally {
  11971. setIsStrictModeForDevtools(false);
  11972. }
  11973. }
  11974. }
  11975. var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
  11976. adoptClassInstance(workInProgress, instance);
  11977. {
  11978. if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
  11979. var componentName = getComponentNameFromType(ctor) || 'Component';
  11980. if (!didWarnAboutUninitializedState.has(componentName)) {
  11981. didWarnAboutUninitializedState.add(componentName);
  11982. 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);
  11983. }
  11984. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  11985. // Warn about these lifecycles if they are present.
  11986. // Don't warn about react-lifecycles-compat polyfilled methods though.
  11987. if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
  11988. var foundWillMountName = null;
  11989. var foundWillReceivePropsName = null;
  11990. var foundWillUpdateName = null;
  11991. if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
  11992. foundWillMountName = 'componentWillMount';
  11993. } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
  11994. foundWillMountName = 'UNSAFE_componentWillMount';
  11995. }
  11996. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  11997. foundWillReceivePropsName = 'componentWillReceiveProps';
  11998. } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  11999. foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
  12000. }
  12001. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  12002. foundWillUpdateName = 'componentWillUpdate';
  12003. } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  12004. foundWillUpdateName = 'UNSAFE_componentWillUpdate';
  12005. }
  12006. if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
  12007. var _componentName = getComponentNameFromType(ctor) || 'Component';
  12008. var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
  12009. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  12010. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  12011. 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://reactjs.org/link/unsafe-component-lifecycles', _componentName, newApiName, foundWillMountName !== null ? "\n " + foundWillMountName : '', foundWillReceivePropsName !== null ? "\n " + foundWillReceivePropsName : '', foundWillUpdateName !== null ? "\n " + foundWillUpdateName : '');
  12012. }
  12013. }
  12014. }
  12015. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  12016. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  12017. if (isLegacyContextConsumer) {
  12018. cacheContext(workInProgress, unmaskedContext, context);
  12019. }
  12020. return instance;
  12021. }
  12022. function callComponentWillMount(workInProgress, instance) {
  12023. var oldState = instance.state;
  12024. if (typeof instance.componentWillMount === 'function') {
  12025. instance.componentWillMount();
  12026. }
  12027. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  12028. instance.UNSAFE_componentWillMount();
  12029. }
  12030. if (oldState !== instance.state) {
  12031. {
  12032. error('%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + 'constructor). Use setState instead.', getComponentNameFromFiber(workInProgress) || 'Component');
  12033. }
  12034. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  12035. }
  12036. }
  12037. function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
  12038. var oldState = instance.state;
  12039. if (typeof instance.componentWillReceiveProps === 'function') {
  12040. instance.componentWillReceiveProps(newProps, nextContext);
  12041. }
  12042. if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  12043. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  12044. }
  12045. if (instance.state !== oldState) {
  12046. {
  12047. var componentName = getComponentNameFromFiber(workInProgress) || 'Component';
  12048. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  12049. didWarnAboutStateAssignmentForComponent.add(componentName);
  12050. error('%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
  12051. }
  12052. }
  12053. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  12054. }
  12055. } // Invokes the mount life-cycles on a previously never rendered instance.
  12056. function mountClassInstance(workInProgress, ctor, newProps, renderLanes) {
  12057. {
  12058. checkClassInstance(workInProgress, ctor, newProps);
  12059. }
  12060. var instance = workInProgress.stateNode;
  12061. instance.props = newProps;
  12062. instance.state = workInProgress.memoizedState;
  12063. instance.refs = emptyRefsObject;
  12064. initializeUpdateQueue(workInProgress);
  12065. var contextType = ctor.contextType;
  12066. if (typeof contextType === 'object' && contextType !== null) {
  12067. instance.context = readContext(contextType);
  12068. } else {
  12069. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  12070. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  12071. }
  12072. {
  12073. if (instance.state === newProps) {
  12074. var componentName = getComponentNameFromType(ctor) || 'Component';
  12075. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  12076. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  12077. 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);
  12078. }
  12079. }
  12080. if (workInProgress.mode & StrictLegacyMode) {
  12081. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
  12082. }
  12083. {
  12084. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
  12085. }
  12086. }
  12087. instance.state = workInProgress.memoizedState;
  12088. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  12089. if (typeof getDerivedStateFromProps === 'function') {
  12090. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  12091. instance.state = workInProgress.memoizedState;
  12092. } // In order to support react-lifecycles-compat polyfilled components,
  12093. // Unsafe lifecycles should not be invoked for components using the new APIs.
  12094. if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  12095. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  12096. // process them now.
  12097. processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  12098. instance.state = workInProgress.memoizedState;
  12099. }
  12100. if (typeof instance.componentDidMount === 'function') {
  12101. var fiberFlags = Update;
  12102. {
  12103. fiberFlags |= LayoutStatic;
  12104. }
  12105. if ( (workInProgress.mode & StrictEffectsMode) !== NoMode) {
  12106. fiberFlags |= MountLayoutDev;
  12107. }
  12108. workInProgress.flags |= fiberFlags;
  12109. }
  12110. }
  12111. function resumeMountClassInstance(workInProgress, ctor, newProps, renderLanes) {
  12112. var instance = workInProgress.stateNode;
  12113. var oldProps = workInProgress.memoizedProps;
  12114. instance.props = oldProps;
  12115. var oldContext = instance.context;
  12116. var contextType = ctor.contextType;
  12117. var nextContext = emptyContextObject;
  12118. if (typeof contextType === 'object' && contextType !== null) {
  12119. nextContext = readContext(contextType);
  12120. } else {
  12121. var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  12122. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  12123. }
  12124. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  12125. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  12126. // ever the previously attempted to render - not the "current". However,
  12127. // during componentDidUpdate we pass the "current" props.
  12128. // In order to support react-lifecycles-compat polyfilled components,
  12129. // Unsafe lifecycles should not be invoked for components using the new APIs.
  12130. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  12131. if (oldProps !== newProps || oldContext !== nextContext) {
  12132. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  12133. }
  12134. }
  12135. resetHasForceUpdateBeforeProcessing();
  12136. var oldState = workInProgress.memoizedState;
  12137. var newState = instance.state = oldState;
  12138. processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  12139. newState = workInProgress.memoizedState;
  12140. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  12141. // If an update was already in progress, we should schedule an Update
  12142. // effect even though we're bailing out, so that cWU/cDU are called.
  12143. if (typeof instance.componentDidMount === 'function') {
  12144. var fiberFlags = Update;
  12145. {
  12146. fiberFlags |= LayoutStatic;
  12147. }
  12148. if ( (workInProgress.mode & StrictEffectsMode) !== NoMode) {
  12149. fiberFlags |= MountLayoutDev;
  12150. }
  12151. workInProgress.flags |= fiberFlags;
  12152. }
  12153. return false;
  12154. }
  12155. if (typeof getDerivedStateFromProps === 'function') {
  12156. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  12157. newState = workInProgress.memoizedState;
  12158. }
  12159. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  12160. if (shouldUpdate) {
  12161. // In order to support react-lifecycles-compat polyfilled components,
  12162. // Unsafe lifecycles should not be invoked for components using the new APIs.
  12163. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  12164. if (typeof instance.componentWillMount === 'function') {
  12165. instance.componentWillMount();
  12166. }
  12167. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  12168. instance.UNSAFE_componentWillMount();
  12169. }
  12170. }
  12171. if (typeof instance.componentDidMount === 'function') {
  12172. var _fiberFlags = Update;
  12173. {
  12174. _fiberFlags |= LayoutStatic;
  12175. }
  12176. if ( (workInProgress.mode & StrictEffectsMode) !== NoMode) {
  12177. _fiberFlags |= MountLayoutDev;
  12178. }
  12179. workInProgress.flags |= _fiberFlags;
  12180. }
  12181. } else {
  12182. // If an update was already in progress, we should schedule an Update
  12183. // effect even though we're bailing out, so that cWU/cDU are called.
  12184. if (typeof instance.componentDidMount === 'function') {
  12185. var _fiberFlags2 = Update;
  12186. {
  12187. _fiberFlags2 |= LayoutStatic;
  12188. }
  12189. if ( (workInProgress.mode & StrictEffectsMode) !== NoMode) {
  12190. _fiberFlags2 |= MountLayoutDev;
  12191. }
  12192. workInProgress.flags |= _fiberFlags2;
  12193. } // If shouldComponentUpdate returned false, we should still update the
  12194. // memoized state to indicate that this work can be reused.
  12195. workInProgress.memoizedProps = newProps;
  12196. workInProgress.memoizedState = newState;
  12197. } // Update the existing instance's state, props, and context pointers even
  12198. // if shouldComponentUpdate returns false.
  12199. instance.props = newProps;
  12200. instance.state = newState;
  12201. instance.context = nextContext;
  12202. return shouldUpdate;
  12203. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  12204. function updateClassInstance(current, workInProgress, ctor, newProps, renderLanes) {
  12205. var instance = workInProgress.stateNode;
  12206. cloneUpdateQueue(current, workInProgress);
  12207. var unresolvedOldProps = workInProgress.memoizedProps;
  12208. var oldProps = workInProgress.type === workInProgress.elementType ? unresolvedOldProps : resolveDefaultProps(workInProgress.type, unresolvedOldProps);
  12209. instance.props = oldProps;
  12210. var unresolvedNewProps = workInProgress.pendingProps;
  12211. var oldContext = instance.context;
  12212. var contextType = ctor.contextType;
  12213. var nextContext = emptyContextObject;
  12214. if (typeof contextType === 'object' && contextType !== null) {
  12215. nextContext = readContext(contextType);
  12216. } else {
  12217. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  12218. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  12219. }
  12220. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  12221. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  12222. // ever the previously attempted to render - not the "current". However,
  12223. // during componentDidUpdate we pass the "current" props.
  12224. // In order to support react-lifecycles-compat polyfilled components,
  12225. // Unsafe lifecycles should not be invoked for components using the new APIs.
  12226. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  12227. if (unresolvedOldProps !== unresolvedNewProps || oldContext !== nextContext) {
  12228. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  12229. }
  12230. }
  12231. resetHasForceUpdateBeforeProcessing();
  12232. var oldState = workInProgress.memoizedState;
  12233. var newState = instance.state = oldState;
  12234. processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  12235. newState = workInProgress.memoizedState;
  12236. if (unresolvedOldProps === unresolvedNewProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing() && !(enableLazyContextPropagation )) {
  12237. // If an update was already in progress, we should schedule an Update
  12238. // effect even though we're bailing out, so that cWU/cDU are called.
  12239. if (typeof instance.componentDidUpdate === 'function') {
  12240. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  12241. workInProgress.flags |= Update;
  12242. }
  12243. }
  12244. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  12245. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  12246. workInProgress.flags |= Snapshot;
  12247. }
  12248. }
  12249. return false;
  12250. }
  12251. if (typeof getDerivedStateFromProps === 'function') {
  12252. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  12253. newState = workInProgress.memoizedState;
  12254. }
  12255. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) || // TODO: In some cases, we'll end up checking if context has changed twice,
  12256. // both before and after `shouldComponentUpdate` has been called. Not ideal,
  12257. // but I'm loath to refactor this function. This only happens for memoized
  12258. // components so it's not that common.
  12259. enableLazyContextPropagation ;
  12260. if (shouldUpdate) {
  12261. // In order to support react-lifecycles-compat polyfilled components,
  12262. // Unsafe lifecycles should not be invoked for components using the new APIs.
  12263. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
  12264. if (typeof instance.componentWillUpdate === 'function') {
  12265. instance.componentWillUpdate(newProps, newState, nextContext);
  12266. }
  12267. if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  12268. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  12269. }
  12270. }
  12271. if (typeof instance.componentDidUpdate === 'function') {
  12272. workInProgress.flags |= Update;
  12273. }
  12274. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  12275. workInProgress.flags |= Snapshot;
  12276. }
  12277. } else {
  12278. // If an update was already in progress, we should schedule an Update
  12279. // effect even though we're bailing out, so that cWU/cDU are called.
  12280. if (typeof instance.componentDidUpdate === 'function') {
  12281. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  12282. workInProgress.flags |= Update;
  12283. }
  12284. }
  12285. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  12286. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  12287. workInProgress.flags |= Snapshot;
  12288. }
  12289. } // If shouldComponentUpdate returned false, we should still update the
  12290. // memoized props/state to indicate that this work can be reused.
  12291. workInProgress.memoizedProps = newProps;
  12292. workInProgress.memoizedState = newState;
  12293. } // Update the existing instance's state, props, and context pointers even
  12294. // if shouldComponentUpdate returns false.
  12295. instance.props = newProps;
  12296. instance.state = newState;
  12297. instance.context = nextContext;
  12298. return shouldUpdate;
  12299. }
  12300. var didWarnAboutMaps;
  12301. var didWarnAboutGenerators;
  12302. var didWarnAboutStringRefs;
  12303. var ownerHasKeyUseWarning;
  12304. var ownerHasFunctionTypeWarning;
  12305. var warnForMissingKey = function (child, returnFiber) {};
  12306. {
  12307. didWarnAboutMaps = false;
  12308. didWarnAboutGenerators = false;
  12309. didWarnAboutStringRefs = {};
  12310. /**
  12311. * Warn if there's no key explicitly set on dynamic arrays of children or
  12312. * object keys are not valid. This allows us to keep track of children between
  12313. * updates.
  12314. */
  12315. ownerHasKeyUseWarning = {};
  12316. ownerHasFunctionTypeWarning = {};
  12317. warnForMissingKey = function (child, returnFiber) {
  12318. if (child === null || typeof child !== 'object') {
  12319. return;
  12320. }
  12321. if (!child._store || child._store.validated || child.key != null) {
  12322. return;
  12323. }
  12324. if (typeof child._store !== 'object') {
  12325. throw new Error('React Component in warnForMissingKey should have a _store. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  12326. }
  12327. child._store.validated = true;
  12328. var componentName = getComponentNameFromFiber(returnFiber) || 'Component';
  12329. if (ownerHasKeyUseWarning[componentName]) {
  12330. return;
  12331. }
  12332. ownerHasKeyUseWarning[componentName] = true;
  12333. error('Each child in a list should have a unique ' + '"key" prop. See https://reactjs.org/link/warning-keys for ' + 'more information.');
  12334. };
  12335. }
  12336. function coerceRef(returnFiber, current, element) {
  12337. var mixedRef = element.ref;
  12338. if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
  12339. {
  12340. // TODO: Clean this up once we turn on the string ref warning for
  12341. // everyone, because the strict mode case will no longer be relevant
  12342. if ((returnFiber.mode & StrictLegacyMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  12343. // because these cannot be automatically converted to an arrow function
  12344. // using a codemod. Therefore, we don't have to warn about string refs again.
  12345. !(element._owner && element._self && element._owner.stateNode !== element._self)) {
  12346. var componentName = getComponentNameFromFiber(returnFiber) || 'Component';
  12347. if (!didWarnAboutStringRefs[componentName]) {
  12348. {
  12349. 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://reactjs.org/link/strict-mode-string-ref', mixedRef);
  12350. }
  12351. didWarnAboutStringRefs[componentName] = true;
  12352. }
  12353. }
  12354. }
  12355. if (element._owner) {
  12356. var owner = element._owner;
  12357. var inst;
  12358. if (owner) {
  12359. var ownerFiber = owner;
  12360. if (ownerFiber.tag !== ClassComponent) {
  12361. throw new Error('Function components cannot have string refs. ' + 'We recommend using useRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref');
  12362. }
  12363. inst = ownerFiber.stateNode;
  12364. }
  12365. if (!inst) {
  12366. throw new Error("Missing owner for string ref " + mixedRef + ". This error is likely caused by a " + 'bug in React. Please file an issue.');
  12367. } // Assigning this to a const so Flow knows it won't change in the closure
  12368. var resolvedInst = inst;
  12369. {
  12370. checkPropStringCoercion(mixedRef, 'ref');
  12371. }
  12372. var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
  12373. if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) {
  12374. return current.ref;
  12375. }
  12376. var ref = function (value) {
  12377. var refs = resolvedInst.refs;
  12378. if (refs === emptyRefsObject) {
  12379. // This is a lazy pooled frozen object, so we need to initialize.
  12380. refs = resolvedInst.refs = {};
  12381. }
  12382. if (value === null) {
  12383. delete refs[stringRef];
  12384. } else {
  12385. refs[stringRef] = value;
  12386. }
  12387. };
  12388. ref._stringRef = stringRef;
  12389. return ref;
  12390. } else {
  12391. if (typeof mixedRef !== 'string') {
  12392. throw new Error('Expected ref to be a function, a string, an object returned by React.createRef(), or null.');
  12393. }
  12394. if (!element._owner) {
  12395. throw new Error("Element ref was specified as a string (" + mixedRef + ") but no owner was set. This could happen for one of" + ' the following reasons:\n' + '1. You may be adding a ref to a function component\n' + "2. You may be adding a ref to a component that was not created inside a component's render method\n" + '3. You have multiple copies of React loaded\n' + 'See https://reactjs.org/link/refs-must-have-owner for more information.');
  12396. }
  12397. }
  12398. }
  12399. return mixedRef;
  12400. }
  12401. function throwOnInvalidObjectType(returnFiber, newChild) {
  12402. var childString = Object.prototype.toString.call(newChild);
  12403. throw new Error("Objects are not valid as a React child (found: " + (childString === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : childString) + "). " + 'If you meant to render a collection of children, use an array ' + 'instead.');
  12404. }
  12405. function warnOnFunctionType(returnFiber) {
  12406. {
  12407. var componentName = getComponentNameFromFiber(returnFiber) || 'Component';
  12408. if (ownerHasFunctionTypeWarning[componentName]) {
  12409. return;
  12410. }
  12411. ownerHasFunctionTypeWarning[componentName] = true;
  12412. 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.');
  12413. }
  12414. }
  12415. function resolveLazy(lazyType) {
  12416. var payload = lazyType._payload;
  12417. var init = lazyType._init;
  12418. return init(payload);
  12419. } // This wrapper function exists because I expect to clone the code in each path
  12420. // to be able to optimize each path individually by branching early. This needs
  12421. // a compiler or we can do it manually. Helpers that don't need this branching
  12422. // live outside of this function.
  12423. function ChildReconciler(shouldTrackSideEffects) {
  12424. function deleteChild(returnFiber, childToDelete) {
  12425. if (!shouldTrackSideEffects) {
  12426. // Noop.
  12427. return;
  12428. }
  12429. var deletions = returnFiber.deletions;
  12430. if (deletions === null) {
  12431. returnFiber.deletions = [childToDelete];
  12432. returnFiber.flags |= ChildDeletion;
  12433. } else {
  12434. deletions.push(childToDelete);
  12435. }
  12436. }
  12437. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  12438. if (!shouldTrackSideEffects) {
  12439. // Noop.
  12440. return null;
  12441. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  12442. // assuming that after the first child we've already added everything.
  12443. var childToDelete = currentFirstChild;
  12444. while (childToDelete !== null) {
  12445. deleteChild(returnFiber, childToDelete);
  12446. childToDelete = childToDelete.sibling;
  12447. }
  12448. return null;
  12449. }
  12450. function mapRemainingChildren(returnFiber, currentFirstChild) {
  12451. // Add the remaining children to a temporary map so that we can find them by
  12452. // keys quickly. Implicit (null) keys get added to this set with their index
  12453. // instead.
  12454. var existingChildren = new Map();
  12455. var existingChild = currentFirstChild;
  12456. while (existingChild !== null) {
  12457. if (existingChild.key !== null) {
  12458. existingChildren.set(existingChild.key, existingChild);
  12459. } else {
  12460. existingChildren.set(existingChild.index, existingChild);
  12461. }
  12462. existingChild = existingChild.sibling;
  12463. }
  12464. return existingChildren;
  12465. }
  12466. function useFiber(fiber, pendingProps) {
  12467. // We currently set sibling to null and index to 0 here because it is easy
  12468. // to forget to do before returning it. E.g. for the single child case.
  12469. var clone = createWorkInProgress(fiber, pendingProps);
  12470. clone.index = 0;
  12471. clone.sibling = null;
  12472. return clone;
  12473. }
  12474. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  12475. newFiber.index = newIndex;
  12476. if (!shouldTrackSideEffects) {
  12477. // During hydration, the useId algorithm needs to know which fibers are
  12478. // part of a list of children (arrays, iterators).
  12479. newFiber.flags |= Forked;
  12480. return lastPlacedIndex;
  12481. }
  12482. var current = newFiber.alternate;
  12483. if (current !== null) {
  12484. var oldIndex = current.index;
  12485. if (oldIndex < lastPlacedIndex) {
  12486. // This is a move.
  12487. newFiber.flags |= Placement;
  12488. return lastPlacedIndex;
  12489. } else {
  12490. // This item can stay in place.
  12491. return oldIndex;
  12492. }
  12493. } else {
  12494. // This is an insertion.
  12495. newFiber.flags |= Placement;
  12496. return lastPlacedIndex;
  12497. }
  12498. }
  12499. function placeSingleChild(newFiber) {
  12500. // This is simpler for the single child case. We only need to do a
  12501. // placement for inserting new children.
  12502. if (shouldTrackSideEffects && newFiber.alternate === null) {
  12503. newFiber.flags |= Placement;
  12504. }
  12505. return newFiber;
  12506. }
  12507. function updateTextNode(returnFiber, current, textContent, lanes) {
  12508. if (current === null || current.tag !== HostText) {
  12509. // Insert
  12510. var created = createFiberFromText(textContent, returnFiber.mode, lanes);
  12511. created.return = returnFiber;
  12512. return created;
  12513. } else {
  12514. // Update
  12515. var existing = useFiber(current, textContent);
  12516. existing.return = returnFiber;
  12517. return existing;
  12518. }
  12519. }
  12520. function updateElement(returnFiber, current, element, lanes) {
  12521. var elementType = element.type;
  12522. if (elementType === REACT_FRAGMENT_TYPE) {
  12523. return updateFragment(returnFiber, current, element.props.children, lanes, element.key);
  12524. }
  12525. if (current !== null) {
  12526. if (current.elementType === elementType || ( // Keep this check inline so it only runs on the false path:
  12527. isCompatibleFamilyForHotReloading(current, element) ) || // Lazy types should reconcile their resolved type.
  12528. // We need to do this after the Hot Reloading check above,
  12529. // because hot reloading has different semantics than prod because
  12530. // it doesn't resuspend. So we can't let the call below suspend.
  12531. typeof elementType === 'object' && elementType !== null && elementType.$$typeof === REACT_LAZY_TYPE && resolveLazy(elementType) === current.type) {
  12532. // Move based on index
  12533. var existing = useFiber(current, element.props);
  12534. existing.ref = coerceRef(returnFiber, current, element);
  12535. existing.return = returnFiber;
  12536. {
  12537. existing._debugSource = element._source;
  12538. existing._debugOwner = element._owner;
  12539. }
  12540. return existing;
  12541. }
  12542. } // Insert
  12543. var created = createFiberFromElement(element, returnFiber.mode, lanes);
  12544. created.ref = coerceRef(returnFiber, current, element);
  12545. created.return = returnFiber;
  12546. return created;
  12547. }
  12548. function updatePortal(returnFiber, current, portal, lanes) {
  12549. if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {
  12550. // Insert
  12551. var created = createFiberFromPortal(portal, returnFiber.mode, lanes);
  12552. created.return = returnFiber;
  12553. return created;
  12554. } else {
  12555. // Update
  12556. var existing = useFiber(current, portal.children || []);
  12557. existing.return = returnFiber;
  12558. return existing;
  12559. }
  12560. }
  12561. function updateFragment(returnFiber, current, fragment, lanes, key) {
  12562. if (current === null || current.tag !== Fragment) {
  12563. // Insert
  12564. var created = createFiberFromFragment(fragment, returnFiber.mode, lanes, key);
  12565. created.return = returnFiber;
  12566. return created;
  12567. } else {
  12568. // Update
  12569. var existing = useFiber(current, fragment);
  12570. existing.return = returnFiber;
  12571. return existing;
  12572. }
  12573. }
  12574. function createChild(returnFiber, newChild, lanes) {
  12575. if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
  12576. // Text nodes don't have keys. If the previous node is implicitly keyed
  12577. // we can continue to replace it without aborting even if it is not a text
  12578. // node.
  12579. var created = createFiberFromText('' + newChild, returnFiber.mode, lanes);
  12580. created.return = returnFiber;
  12581. return created;
  12582. }
  12583. if (typeof newChild === 'object' && newChild !== null) {
  12584. switch (newChild.$$typeof) {
  12585. case REACT_ELEMENT_TYPE:
  12586. {
  12587. var _created = createFiberFromElement(newChild, returnFiber.mode, lanes);
  12588. _created.ref = coerceRef(returnFiber, null, newChild);
  12589. _created.return = returnFiber;
  12590. return _created;
  12591. }
  12592. case REACT_PORTAL_TYPE:
  12593. {
  12594. var _created2 = createFiberFromPortal(newChild, returnFiber.mode, lanes);
  12595. _created2.return = returnFiber;
  12596. return _created2;
  12597. }
  12598. case REACT_LAZY_TYPE:
  12599. {
  12600. var payload = newChild._payload;
  12601. var init = newChild._init;
  12602. return createChild(returnFiber, init(payload), lanes);
  12603. }
  12604. }
  12605. if (isArray(newChild) || getIteratorFn(newChild)) {
  12606. var _created3 = createFiberFromFragment(newChild, returnFiber.mode, lanes, null);
  12607. _created3.return = returnFiber;
  12608. return _created3;
  12609. }
  12610. throwOnInvalidObjectType(returnFiber, newChild);
  12611. }
  12612. {
  12613. if (typeof newChild === 'function') {
  12614. warnOnFunctionType(returnFiber);
  12615. }
  12616. }
  12617. return null;
  12618. }
  12619. function updateSlot(returnFiber, oldFiber, newChild, lanes) {
  12620. // Update the fiber if the keys match, otherwise return null.
  12621. var key = oldFiber !== null ? oldFiber.key : null;
  12622. if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
  12623. // Text nodes don't have keys. If the previous node is implicitly keyed
  12624. // we can continue to replace it without aborting even if it is not a text
  12625. // node.
  12626. if (key !== null) {
  12627. return null;
  12628. }
  12629. return updateTextNode(returnFiber, oldFiber, '' + newChild, lanes);
  12630. }
  12631. if (typeof newChild === 'object' && newChild !== null) {
  12632. switch (newChild.$$typeof) {
  12633. case REACT_ELEMENT_TYPE:
  12634. {
  12635. if (newChild.key === key) {
  12636. return updateElement(returnFiber, oldFiber, newChild, lanes);
  12637. } else {
  12638. return null;
  12639. }
  12640. }
  12641. case REACT_PORTAL_TYPE:
  12642. {
  12643. if (newChild.key === key) {
  12644. return updatePortal(returnFiber, oldFiber, newChild, lanes);
  12645. } else {
  12646. return null;
  12647. }
  12648. }
  12649. case REACT_LAZY_TYPE:
  12650. {
  12651. var payload = newChild._payload;
  12652. var init = newChild._init;
  12653. return updateSlot(returnFiber, oldFiber, init(payload), lanes);
  12654. }
  12655. }
  12656. if (isArray(newChild) || getIteratorFn(newChild)) {
  12657. if (key !== null) {
  12658. return null;
  12659. }
  12660. return updateFragment(returnFiber, oldFiber, newChild, lanes, null);
  12661. }
  12662. throwOnInvalidObjectType(returnFiber, newChild);
  12663. }
  12664. {
  12665. if (typeof newChild === 'function') {
  12666. warnOnFunctionType(returnFiber);
  12667. }
  12668. }
  12669. return null;
  12670. }
  12671. function updateFromMap(existingChildren, returnFiber, newIdx, newChild, lanes) {
  12672. if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
  12673. // Text nodes don't have keys, so we neither have to check the old nor
  12674. // new node for the key. If both are text nodes, they match.
  12675. var matchedFiber = existingChildren.get(newIdx) || null;
  12676. return updateTextNode(returnFiber, matchedFiber, '' + newChild, lanes);
  12677. }
  12678. if (typeof newChild === 'object' && newChild !== null) {
  12679. switch (newChild.$$typeof) {
  12680. case REACT_ELEMENT_TYPE:
  12681. {
  12682. var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  12683. return updateElement(returnFiber, _matchedFiber, newChild, lanes);
  12684. }
  12685. case REACT_PORTAL_TYPE:
  12686. {
  12687. var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  12688. return updatePortal(returnFiber, _matchedFiber2, newChild, lanes);
  12689. }
  12690. case REACT_LAZY_TYPE:
  12691. var payload = newChild._payload;
  12692. var init = newChild._init;
  12693. return updateFromMap(existingChildren, returnFiber, newIdx, init(payload), lanes);
  12694. }
  12695. if (isArray(newChild) || getIteratorFn(newChild)) {
  12696. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  12697. return updateFragment(returnFiber, _matchedFiber3, newChild, lanes, null);
  12698. }
  12699. throwOnInvalidObjectType(returnFiber, newChild);
  12700. }
  12701. {
  12702. if (typeof newChild === 'function') {
  12703. warnOnFunctionType(returnFiber);
  12704. }
  12705. }
  12706. return null;
  12707. }
  12708. /**
  12709. * Warns if there is a duplicate or missing key
  12710. */
  12711. function warnOnInvalidKey(child, knownKeys, returnFiber) {
  12712. {
  12713. if (typeof child !== 'object' || child === null) {
  12714. return knownKeys;
  12715. }
  12716. switch (child.$$typeof) {
  12717. case REACT_ELEMENT_TYPE:
  12718. case REACT_PORTAL_TYPE:
  12719. warnForMissingKey(child, returnFiber);
  12720. var key = child.key;
  12721. if (typeof key !== 'string') {
  12722. break;
  12723. }
  12724. if (knownKeys === null) {
  12725. knownKeys = new Set();
  12726. knownKeys.add(key);
  12727. break;
  12728. }
  12729. if (!knownKeys.has(key)) {
  12730. knownKeys.add(key);
  12731. break;
  12732. }
  12733. 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);
  12734. break;
  12735. case REACT_LAZY_TYPE:
  12736. var payload = child._payload;
  12737. var init = child._init;
  12738. warnOnInvalidKey(init(payload), knownKeys, returnFiber);
  12739. break;
  12740. }
  12741. }
  12742. return knownKeys;
  12743. }
  12744. function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, lanes) {
  12745. // This algorithm can't optimize by searching from both ends since we
  12746. // don't have backpointers on fibers. I'm trying to see how far we can get
  12747. // with that model. If it ends up not being worth the tradeoffs, we can
  12748. // add it later.
  12749. // Even with a two ended optimization, we'd want to optimize for the case
  12750. // where there are few changes and brute force the comparison instead of
  12751. // going for the Map. It'd like to explore hitting that path first in
  12752. // forward-only mode and only go for the Map once we notice that we need
  12753. // lots of look ahead. This doesn't handle reversal as well as two ended
  12754. // search but that's unusual. Besides, for the two ended optimization to
  12755. // work on Iterables, we'd need to copy the whole set.
  12756. // In this first iteration, we'll just live with hitting the bad case
  12757. // (adding everything to a Map) in for every insert/move.
  12758. // If you change this code, also update reconcileChildrenIterator() which
  12759. // uses the same algorithm.
  12760. {
  12761. // First, validate keys.
  12762. var knownKeys = null;
  12763. for (var i = 0; i < newChildren.length; i++) {
  12764. var child = newChildren[i];
  12765. knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
  12766. }
  12767. }
  12768. var resultingFirstChild = null;
  12769. var previousNewFiber = null;
  12770. var oldFiber = currentFirstChild;
  12771. var lastPlacedIndex = 0;
  12772. var newIdx = 0;
  12773. var nextOldFiber = null;
  12774. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  12775. if (oldFiber.index > newIdx) {
  12776. nextOldFiber = oldFiber;
  12777. oldFiber = null;
  12778. } else {
  12779. nextOldFiber = oldFiber.sibling;
  12780. }
  12781. var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], lanes);
  12782. if (newFiber === null) {
  12783. // TODO: This breaks on empty slots like null children. That's
  12784. // unfortunate because it triggers the slow path all the time. We need
  12785. // a better way to communicate whether this was a miss or null,
  12786. // boolean, undefined, etc.
  12787. if (oldFiber === null) {
  12788. oldFiber = nextOldFiber;
  12789. }
  12790. break;
  12791. }
  12792. if (shouldTrackSideEffects) {
  12793. if (oldFiber && newFiber.alternate === null) {
  12794. // We matched the slot, but we didn't reuse the existing fiber, so we
  12795. // need to delete the existing child.
  12796. deleteChild(returnFiber, oldFiber);
  12797. }
  12798. }
  12799. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  12800. if (previousNewFiber === null) {
  12801. // TODO: Move out of the loop. This only happens for the first run.
  12802. resultingFirstChild = newFiber;
  12803. } else {
  12804. // TODO: Defer siblings if we're not at the right index for this slot.
  12805. // I.e. if we had null values before, then we want to defer this
  12806. // for each null value. However, we also don't want to call updateSlot
  12807. // with the previous one.
  12808. previousNewFiber.sibling = newFiber;
  12809. }
  12810. previousNewFiber = newFiber;
  12811. oldFiber = nextOldFiber;
  12812. }
  12813. if (newIdx === newChildren.length) {
  12814. // We've reached the end of the new children. We can delete the rest.
  12815. deleteRemainingChildren(returnFiber, oldFiber);
  12816. if (getIsHydrating()) {
  12817. var numberOfForks = newIdx;
  12818. pushTreeFork(returnFiber, numberOfForks);
  12819. }
  12820. return resultingFirstChild;
  12821. }
  12822. if (oldFiber === null) {
  12823. // If we don't have any more existing children we can choose a fast path
  12824. // since the rest will all be insertions.
  12825. for (; newIdx < newChildren.length; newIdx++) {
  12826. var _newFiber = createChild(returnFiber, newChildren[newIdx], lanes);
  12827. if (_newFiber === null) {
  12828. continue;
  12829. }
  12830. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  12831. if (previousNewFiber === null) {
  12832. // TODO: Move out of the loop. This only happens for the first run.
  12833. resultingFirstChild = _newFiber;
  12834. } else {
  12835. previousNewFiber.sibling = _newFiber;
  12836. }
  12837. previousNewFiber = _newFiber;
  12838. }
  12839. if (getIsHydrating()) {
  12840. var _numberOfForks = newIdx;
  12841. pushTreeFork(returnFiber, _numberOfForks);
  12842. }
  12843. return resultingFirstChild;
  12844. } // Add all children to a key map for quick lookups.
  12845. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  12846. for (; newIdx < newChildren.length; newIdx++) {
  12847. var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], lanes);
  12848. if (_newFiber2 !== null) {
  12849. if (shouldTrackSideEffects) {
  12850. if (_newFiber2.alternate !== null) {
  12851. // The new fiber is a work in progress, but if there exists a
  12852. // current, that means that we reused the fiber. We need to delete
  12853. // it from the child list so that we don't add it to the deletion
  12854. // list.
  12855. existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
  12856. }
  12857. }
  12858. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  12859. if (previousNewFiber === null) {
  12860. resultingFirstChild = _newFiber2;
  12861. } else {
  12862. previousNewFiber.sibling = _newFiber2;
  12863. }
  12864. previousNewFiber = _newFiber2;
  12865. }
  12866. }
  12867. if (shouldTrackSideEffects) {
  12868. // Any existing children that weren't consumed above were deleted. We need
  12869. // to add them to the deletion list.
  12870. existingChildren.forEach(function (child) {
  12871. return deleteChild(returnFiber, child);
  12872. });
  12873. }
  12874. if (getIsHydrating()) {
  12875. var _numberOfForks2 = newIdx;
  12876. pushTreeFork(returnFiber, _numberOfForks2);
  12877. }
  12878. return resultingFirstChild;
  12879. }
  12880. function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, lanes) {
  12881. // This is the same implementation as reconcileChildrenArray(),
  12882. // but using the iterator instead.
  12883. var iteratorFn = getIteratorFn(newChildrenIterable);
  12884. if (typeof iteratorFn !== 'function') {
  12885. throw new Error('An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');
  12886. }
  12887. {
  12888. // We don't support rendering Generators because it's a mutation.
  12889. // See https://github.com/facebook/react/issues/12995
  12890. if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
  12891. newChildrenIterable[Symbol.toStringTag] === 'Generator') {
  12892. if (!didWarnAboutGenerators) {
  12893. 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.');
  12894. }
  12895. didWarnAboutGenerators = true;
  12896. } // Warn about using Maps as children
  12897. if (newChildrenIterable.entries === iteratorFn) {
  12898. if (!didWarnAboutMaps) {
  12899. error('Using Maps as children is not supported. ' + 'Use an array of keyed ReactElements instead.');
  12900. }
  12901. didWarnAboutMaps = true;
  12902. } // First, validate keys.
  12903. // We'll get a different iterator later for the main pass.
  12904. var _newChildren = iteratorFn.call(newChildrenIterable);
  12905. if (_newChildren) {
  12906. var knownKeys = null;
  12907. var _step = _newChildren.next();
  12908. for (; !_step.done; _step = _newChildren.next()) {
  12909. var child = _step.value;
  12910. knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
  12911. }
  12912. }
  12913. }
  12914. var newChildren = iteratorFn.call(newChildrenIterable);
  12915. if (newChildren == null) {
  12916. throw new Error('An iterable object provided no iterator.');
  12917. }
  12918. var resultingFirstChild = null;
  12919. var previousNewFiber = null;
  12920. var oldFiber = currentFirstChild;
  12921. var lastPlacedIndex = 0;
  12922. var newIdx = 0;
  12923. var nextOldFiber = null;
  12924. var step = newChildren.next();
  12925. for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
  12926. if (oldFiber.index > newIdx) {
  12927. nextOldFiber = oldFiber;
  12928. oldFiber = null;
  12929. } else {
  12930. nextOldFiber = oldFiber.sibling;
  12931. }
  12932. var newFiber = updateSlot(returnFiber, oldFiber, step.value, lanes);
  12933. if (newFiber === null) {
  12934. // TODO: This breaks on empty slots like null children. That's
  12935. // unfortunate because it triggers the slow path all the time. We need
  12936. // a better way to communicate whether this was a miss or null,
  12937. // boolean, undefined, etc.
  12938. if (oldFiber === null) {
  12939. oldFiber = nextOldFiber;
  12940. }
  12941. break;
  12942. }
  12943. if (shouldTrackSideEffects) {
  12944. if (oldFiber && newFiber.alternate === null) {
  12945. // We matched the slot, but we didn't reuse the existing fiber, so we
  12946. // need to delete the existing child.
  12947. deleteChild(returnFiber, oldFiber);
  12948. }
  12949. }
  12950. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  12951. if (previousNewFiber === null) {
  12952. // TODO: Move out of the loop. This only happens for the first run.
  12953. resultingFirstChild = newFiber;
  12954. } else {
  12955. // TODO: Defer siblings if we're not at the right index for this slot.
  12956. // I.e. if we had null values before, then we want to defer this
  12957. // for each null value. However, we also don't want to call updateSlot
  12958. // with the previous one.
  12959. previousNewFiber.sibling = newFiber;
  12960. }
  12961. previousNewFiber = newFiber;
  12962. oldFiber = nextOldFiber;
  12963. }
  12964. if (step.done) {
  12965. // We've reached the end of the new children. We can delete the rest.
  12966. deleteRemainingChildren(returnFiber, oldFiber);
  12967. if (getIsHydrating()) {
  12968. var numberOfForks = newIdx;
  12969. pushTreeFork(returnFiber, numberOfForks);
  12970. }
  12971. return resultingFirstChild;
  12972. }
  12973. if (oldFiber === null) {
  12974. // If we don't have any more existing children we can choose a fast path
  12975. // since the rest will all be insertions.
  12976. for (; !step.done; newIdx++, step = newChildren.next()) {
  12977. var _newFiber3 = createChild(returnFiber, step.value, lanes);
  12978. if (_newFiber3 === null) {
  12979. continue;
  12980. }
  12981. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  12982. if (previousNewFiber === null) {
  12983. // TODO: Move out of the loop. This only happens for the first run.
  12984. resultingFirstChild = _newFiber3;
  12985. } else {
  12986. previousNewFiber.sibling = _newFiber3;
  12987. }
  12988. previousNewFiber = _newFiber3;
  12989. }
  12990. if (getIsHydrating()) {
  12991. var _numberOfForks3 = newIdx;
  12992. pushTreeFork(returnFiber, _numberOfForks3);
  12993. }
  12994. return resultingFirstChild;
  12995. } // Add all children to a key map for quick lookups.
  12996. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  12997. for (; !step.done; newIdx++, step = newChildren.next()) {
  12998. var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, lanes);
  12999. if (_newFiber4 !== null) {
  13000. if (shouldTrackSideEffects) {
  13001. if (_newFiber4.alternate !== null) {
  13002. // The new fiber is a work in progress, but if there exists a
  13003. // current, that means that we reused the fiber. We need to delete
  13004. // it from the child list so that we don't add it to the deletion
  13005. // list.
  13006. existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
  13007. }
  13008. }
  13009. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  13010. if (previousNewFiber === null) {
  13011. resultingFirstChild = _newFiber4;
  13012. } else {
  13013. previousNewFiber.sibling = _newFiber4;
  13014. }
  13015. previousNewFiber = _newFiber4;
  13016. }
  13017. }
  13018. if (shouldTrackSideEffects) {
  13019. // Any existing children that weren't consumed above were deleted. We need
  13020. // to add them to the deletion list.
  13021. existingChildren.forEach(function (child) {
  13022. return deleteChild(returnFiber, child);
  13023. });
  13024. }
  13025. if (getIsHydrating()) {
  13026. var _numberOfForks4 = newIdx;
  13027. pushTreeFork(returnFiber, _numberOfForks4);
  13028. }
  13029. return resultingFirstChild;
  13030. }
  13031. function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, lanes) {
  13032. // There's no need to check for keys on text nodes since we don't have a
  13033. // way to define them.
  13034. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  13035. // We already have an existing node so let's just update it and delete
  13036. // the rest.
  13037. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  13038. var existing = useFiber(currentFirstChild, textContent);
  13039. existing.return = returnFiber;
  13040. return existing;
  13041. } // The existing first child is not a text node so we need to create one
  13042. // and delete the existing ones.
  13043. deleteRemainingChildren(returnFiber, currentFirstChild);
  13044. var created = createFiberFromText(textContent, returnFiber.mode, lanes);
  13045. created.return = returnFiber;
  13046. return created;
  13047. }
  13048. function reconcileSingleElement(returnFiber, currentFirstChild, element, lanes) {
  13049. var key = element.key;
  13050. var child = currentFirstChild;
  13051. while (child !== null) {
  13052. // TODO: If key === null and child.key === null, then this only applies to
  13053. // the first item in the list.
  13054. if (child.key === key) {
  13055. var elementType = element.type;
  13056. if (elementType === REACT_FRAGMENT_TYPE) {
  13057. if (child.tag === Fragment) {
  13058. deleteRemainingChildren(returnFiber, child.sibling);
  13059. var existing = useFiber(child, element.props.children);
  13060. existing.return = returnFiber;
  13061. {
  13062. existing._debugSource = element._source;
  13063. existing._debugOwner = element._owner;
  13064. }
  13065. return existing;
  13066. }
  13067. } else {
  13068. if (child.elementType === elementType || ( // Keep this check inline so it only runs on the false path:
  13069. isCompatibleFamilyForHotReloading(child, element) ) || // Lazy types should reconcile their resolved type.
  13070. // We need to do this after the Hot Reloading check above,
  13071. // because hot reloading has different semantics than prod because
  13072. // it doesn't resuspend. So we can't let the call below suspend.
  13073. typeof elementType === 'object' && elementType !== null && elementType.$$typeof === REACT_LAZY_TYPE && resolveLazy(elementType) === child.type) {
  13074. deleteRemainingChildren(returnFiber, child.sibling);
  13075. var _existing = useFiber(child, element.props);
  13076. _existing.ref = coerceRef(returnFiber, child, element);
  13077. _existing.return = returnFiber;
  13078. {
  13079. _existing._debugSource = element._source;
  13080. _existing._debugOwner = element._owner;
  13081. }
  13082. return _existing;
  13083. }
  13084. } // Didn't match.
  13085. deleteRemainingChildren(returnFiber, child);
  13086. break;
  13087. } else {
  13088. deleteChild(returnFiber, child);
  13089. }
  13090. child = child.sibling;
  13091. }
  13092. if (element.type === REACT_FRAGMENT_TYPE) {
  13093. var created = createFiberFromFragment(element.props.children, returnFiber.mode, lanes, element.key);
  13094. created.return = returnFiber;
  13095. return created;
  13096. } else {
  13097. var _created4 = createFiberFromElement(element, returnFiber.mode, lanes);
  13098. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  13099. _created4.return = returnFiber;
  13100. return _created4;
  13101. }
  13102. }
  13103. function reconcileSinglePortal(returnFiber, currentFirstChild, portal, lanes) {
  13104. var key = portal.key;
  13105. var child = currentFirstChild;
  13106. while (child !== null) {
  13107. // TODO: If key === null and child.key === null, then this only applies to
  13108. // the first item in the list.
  13109. if (child.key === key) {
  13110. if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
  13111. deleteRemainingChildren(returnFiber, child.sibling);
  13112. var existing = useFiber(child, portal.children || []);
  13113. existing.return = returnFiber;
  13114. return existing;
  13115. } else {
  13116. deleteRemainingChildren(returnFiber, child);
  13117. break;
  13118. }
  13119. } else {
  13120. deleteChild(returnFiber, child);
  13121. }
  13122. child = child.sibling;
  13123. }
  13124. var created = createFiberFromPortal(portal, returnFiber.mode, lanes);
  13125. created.return = returnFiber;
  13126. return created;
  13127. } // This API will tag the children with the side-effect of the reconciliation
  13128. // itself. They will be added to the side-effect list as we pass through the
  13129. // children and the parent.
  13130. function reconcileChildFibers(returnFiber, currentFirstChild, newChild, lanes) {
  13131. // This function is not recursive.
  13132. // If the top level item is an array, we treat it as a set of children,
  13133. // not as a fragment. Nested arrays on the other hand will be treated as
  13134. // fragment nodes. Recursion happens at the normal flow.
  13135. // Handle top level unkeyed fragments as if they were arrays.
  13136. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  13137. // We treat the ambiguous cases above the same.
  13138. var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
  13139. if (isUnkeyedTopLevelFragment) {
  13140. newChild = newChild.props.children;
  13141. } // Handle object types
  13142. if (typeof newChild === 'object' && newChild !== null) {
  13143. switch (newChild.$$typeof) {
  13144. case REACT_ELEMENT_TYPE:
  13145. return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, lanes));
  13146. case REACT_PORTAL_TYPE:
  13147. return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, lanes));
  13148. case REACT_LAZY_TYPE:
  13149. var payload = newChild._payload;
  13150. var init = newChild._init; // TODO: This function is supposed to be non-recursive.
  13151. return reconcileChildFibers(returnFiber, currentFirstChild, init(payload), lanes);
  13152. }
  13153. if (isArray(newChild)) {
  13154. return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, lanes);
  13155. }
  13156. if (getIteratorFn(newChild)) {
  13157. return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, lanes);
  13158. }
  13159. throwOnInvalidObjectType(returnFiber, newChild);
  13160. }
  13161. if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
  13162. return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, lanes));
  13163. }
  13164. {
  13165. if (typeof newChild === 'function') {
  13166. warnOnFunctionType(returnFiber);
  13167. }
  13168. } // Remaining cases are all treated as empty.
  13169. return deleteRemainingChildren(returnFiber, currentFirstChild);
  13170. }
  13171. return reconcileChildFibers;
  13172. }
  13173. var reconcileChildFibers = ChildReconciler(true);
  13174. var mountChildFibers = ChildReconciler(false);
  13175. function cloneChildFibers(current, workInProgress) {
  13176. if (current !== null && workInProgress.child !== current.child) {
  13177. throw new Error('Resuming work not yet implemented.');
  13178. }
  13179. if (workInProgress.child === null) {
  13180. return;
  13181. }
  13182. var currentChild = workInProgress.child;
  13183. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  13184. workInProgress.child = newChild;
  13185. newChild.return = workInProgress;
  13186. while (currentChild.sibling !== null) {
  13187. currentChild = currentChild.sibling;
  13188. newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps);
  13189. newChild.return = workInProgress;
  13190. }
  13191. newChild.sibling = null;
  13192. } // Reset a workInProgress child set to prepare it for a second pass.
  13193. function resetChildFibers(workInProgress, lanes) {
  13194. var child = workInProgress.child;
  13195. while (child !== null) {
  13196. resetWorkInProgress(child, lanes);
  13197. child = child.sibling;
  13198. }
  13199. }
  13200. var NO_CONTEXT = {};
  13201. var contextStackCursor$1 = createCursor(NO_CONTEXT);
  13202. var contextFiberStackCursor = createCursor(NO_CONTEXT);
  13203. var rootInstanceStackCursor = createCursor(NO_CONTEXT);
  13204. function requiredContext(c) {
  13205. if (c === NO_CONTEXT) {
  13206. throw new Error('Expected host context to exist. This error is likely caused by a bug ' + 'in React. Please file an issue.');
  13207. }
  13208. return c;
  13209. }
  13210. function getRootHostContainer() {
  13211. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  13212. return rootInstance;
  13213. }
  13214. function pushHostContainer(fiber, nextRootInstance) {
  13215. // Push current root instance onto the stack;
  13216. // This allows us to reset root when portals are popped.
  13217. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  13218. // This enables us to pop only Fibers that provide unique contexts.
  13219. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  13220. // However, we can't just call getRootHostContext() and push it because
  13221. // we'd have a different number of entries on the stack depending on
  13222. // whether getRootHostContext() throws somewhere in renderer code or not.
  13223. // So we push an empty value first. This lets us safely unwind on errors.
  13224. push(contextStackCursor$1, NO_CONTEXT, fiber);
  13225. var nextRootContext = getRootHostContext(nextRootInstance); // Now that we know this function doesn't throw, replace it.
  13226. pop(contextStackCursor$1, fiber);
  13227. push(contextStackCursor$1, nextRootContext, fiber);
  13228. }
  13229. function popHostContainer(fiber) {
  13230. pop(contextStackCursor$1, fiber);
  13231. pop(contextFiberStackCursor, fiber);
  13232. pop(rootInstanceStackCursor, fiber);
  13233. }
  13234. function getHostContext() {
  13235. var context = requiredContext(contextStackCursor$1.current);
  13236. return context;
  13237. }
  13238. function pushHostContext(fiber) {
  13239. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  13240. var context = requiredContext(contextStackCursor$1.current);
  13241. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  13242. if (context === nextContext) {
  13243. return;
  13244. } // Track the context and the Fiber that provided it.
  13245. // This enables us to pop only Fibers that provide unique contexts.
  13246. push(contextFiberStackCursor, fiber, fiber);
  13247. push(contextStackCursor$1, nextContext, fiber);
  13248. }
  13249. function popHostContext(fiber) {
  13250. // Do not pop unless this Fiber provided the current context.
  13251. // pushHostContext() only pushes Fibers that provide unique contexts.
  13252. if (contextFiberStackCursor.current !== fiber) {
  13253. return;
  13254. }
  13255. pop(contextStackCursor$1, fiber);
  13256. pop(contextFiberStackCursor, fiber);
  13257. }
  13258. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  13259. // inherited deeply down the subtree. The upper bits only affect
  13260. // this immediate suspense boundary and gets reset each new
  13261. // boundary or suspense list.
  13262. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  13263. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  13264. // boundaries is not currently showing visible main content.
  13265. // Either because it is already showing a fallback or is not mounted at all.
  13266. // We can use this to determine if it is desirable to trigger a fallback at
  13267. // the parent. If not, then we might need to trigger undesirable boundaries
  13268. // and/or suspend the commit to avoid hiding the parent content.
  13269. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  13270. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  13271. // items into their fallback state during one of the render passes.
  13272. var ForceSuspenseFallback = 2;
  13273. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  13274. function hasSuspenseContext(parentContext, flag) {
  13275. return (parentContext & flag) !== 0;
  13276. }
  13277. function setDefaultShallowSuspenseContext(parentContext) {
  13278. return parentContext & SubtreeSuspenseContextMask;
  13279. }
  13280. function setShallowSuspenseContext(parentContext, shallowContext) {
  13281. return parentContext & SubtreeSuspenseContextMask | shallowContext;
  13282. }
  13283. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  13284. return parentContext | subtreeContext;
  13285. }
  13286. function pushSuspenseContext(fiber, newContext) {
  13287. push(suspenseStackCursor, newContext, fiber);
  13288. }
  13289. function popSuspenseContext(fiber) {
  13290. pop(suspenseStackCursor, fiber);
  13291. }
  13292. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  13293. // If it was the primary children that just suspended, capture and render the
  13294. // fallback. Otherwise, don't capture and bubble to the next boundary.
  13295. var nextState = workInProgress.memoizedState;
  13296. if (nextState !== null) {
  13297. if (nextState.dehydrated !== null) {
  13298. // A dehydrated boundary always captures.
  13299. return true;
  13300. }
  13301. return false;
  13302. }
  13303. var props = workInProgress.memoizedProps; // Regular boundaries always capture.
  13304. {
  13305. return true;
  13306. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  13307. }
  13308. function findFirstSuspended(row) {
  13309. var node = row;
  13310. while (node !== null) {
  13311. if (node.tag === SuspenseComponent) {
  13312. var state = node.memoizedState;
  13313. if (state !== null) {
  13314. var dehydrated = state.dehydrated;
  13315. if (dehydrated === null || isSuspenseInstancePending(dehydrated) || isSuspenseInstanceFallback(dehydrated)) {
  13316. return node;
  13317. }
  13318. }
  13319. } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  13320. // keep track of whether it suspended or not.
  13321. node.memoizedProps.revealOrder !== undefined) {
  13322. var didSuspend = (node.flags & DidCapture) !== NoFlags;
  13323. if (didSuspend) {
  13324. return node;
  13325. }
  13326. } else if (node.child !== null) {
  13327. node.child.return = node;
  13328. node = node.child;
  13329. continue;
  13330. }
  13331. if (node === row) {
  13332. return null;
  13333. }
  13334. while (node.sibling === null) {
  13335. if (node.return === null || node.return === row) {
  13336. return null;
  13337. }
  13338. node = node.return;
  13339. }
  13340. node.sibling.return = node.return;
  13341. node = node.sibling;
  13342. }
  13343. return null;
  13344. }
  13345. var NoFlags$1 =
  13346. /* */
  13347. 0; // Represents whether effect should fire.
  13348. var HasEffect =
  13349. /* */
  13350. 1; // Represents the phase in which the effect (not the clean-up) fires.
  13351. var Insertion =
  13352. /* */
  13353. 2;
  13354. var Layout =
  13355. /* */
  13356. 4;
  13357. var Passive$1 =
  13358. /* */
  13359. 8;
  13360. // and should be reset before starting a new render.
  13361. // This tracks which mutable sources need to be reset after a render.
  13362. var workInProgressSources = [];
  13363. function resetWorkInProgressVersions() {
  13364. for (var i = 0; i < workInProgressSources.length; i++) {
  13365. var mutableSource = workInProgressSources[i];
  13366. {
  13367. mutableSource._workInProgressVersionPrimary = null;
  13368. }
  13369. }
  13370. workInProgressSources.length = 0;
  13371. }
  13372. // This ensures that the version used for server rendering matches the one
  13373. // that is eventually read during hydration.
  13374. // If they don't match there's a potential tear and a full deopt render is required.
  13375. function registerMutableSourceForHydration(root, mutableSource) {
  13376. var getVersion = mutableSource._getVersion;
  13377. var version = getVersion(mutableSource._source); // TODO Clear this data once all pending hydration work is finished.
  13378. // Retaining it forever may interfere with GC.
  13379. if (root.mutableSourceEagerHydrationData == null) {
  13380. root.mutableSourceEagerHydrationData = [mutableSource, version];
  13381. } else {
  13382. root.mutableSourceEagerHydrationData.push(mutableSource, version);
  13383. }
  13384. }
  13385. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  13386. ReactCurrentBatchConfig$2 = ReactSharedInternals.ReactCurrentBatchConfig;
  13387. var didWarnAboutMismatchedHooksForComponent;
  13388. var didWarnUncachedGetSnapshot;
  13389. {
  13390. didWarnAboutMismatchedHooksForComponent = new Set();
  13391. }
  13392. // These are set right before calling the component.
  13393. var renderLanes = NoLanes; // The work-in-progress fiber. I've named it differently to distinguish it from
  13394. // the work-in-progress hook.
  13395. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  13396. // current hook list is the list that belongs to the current fiber. The
  13397. // work-in-progress hook list is a new list that will be added to the
  13398. // work-in-progress fiber.
  13399. var currentHook = null;
  13400. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  13401. // does not get reset if we do another render pass; only when we're completely
  13402. // finished evaluating this component. This is an optimization so we know
  13403. // whether we need to clear render phase updates after a throw.
  13404. var didScheduleRenderPhaseUpdate = false; // Where an update was scheduled only during the current render pass. This
  13405. // gets reset after each attempt.
  13406. // TODO: Maybe there's some way to consolidate this with
  13407. // `didScheduleRenderPhaseUpdate`. Or with `numberOfReRenders`.
  13408. var didScheduleRenderPhaseUpdateDuringThisPass = false; // Counts the number of useId hooks in this component.
  13409. var localIdCounter = 0; // Used for ids that are generated completely client-side (i.e. not during
  13410. // hydration). This counter is global, so client ids are not stable across
  13411. // render attempts.
  13412. var globalClientIdCounter = 0;
  13413. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  13414. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  13415. // The list stores the order of hooks used during the initial render (mount).
  13416. // Subsequent renders (updates) reference this list.
  13417. var hookTypesDev = null;
  13418. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  13419. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  13420. // When true, such Hooks will always be "remounted". Only used during hot reload.
  13421. var ignorePreviousDependencies = false;
  13422. function mountHookTypesDev() {
  13423. {
  13424. var hookName = currentHookNameInDev;
  13425. if (hookTypesDev === null) {
  13426. hookTypesDev = [hookName];
  13427. } else {
  13428. hookTypesDev.push(hookName);
  13429. }
  13430. }
  13431. }
  13432. function updateHookTypesDev() {
  13433. {
  13434. var hookName = currentHookNameInDev;
  13435. if (hookTypesDev !== null) {
  13436. hookTypesUpdateIndexDev++;
  13437. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  13438. warnOnHookMismatchInDev(hookName);
  13439. }
  13440. }
  13441. }
  13442. }
  13443. function checkDepsAreArrayDev(deps) {
  13444. {
  13445. if (deps !== undefined && deps !== null && !isArray(deps)) {
  13446. // Verify deps, but only on mount to avoid extra checks.
  13447. // It's unlikely their type would change as usually you define them inline.
  13448. 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);
  13449. }
  13450. }
  13451. }
  13452. function warnOnHookMismatchInDev(currentHookName) {
  13453. {
  13454. var componentName = getComponentNameFromFiber(currentlyRenderingFiber$1);
  13455. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  13456. didWarnAboutMismatchedHooksForComponent.add(componentName);
  13457. if (hookTypesDev !== null) {
  13458. var table = '';
  13459. var secondColumnStart = 30;
  13460. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  13461. var oldHookName = hookTypesDev[i];
  13462. var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  13463. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  13464. // lol @ IE not supporting String#repeat
  13465. while (row.length < secondColumnStart) {
  13466. row += ' ';
  13467. }
  13468. row += newHookName + '\n';
  13469. table += row;
  13470. }
  13471. 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://reactjs.org/link/rules-of-hooks\n\n' + ' Previous render Next render\n' + ' ------------------------------------------------------\n' + '%s' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', componentName, table);
  13472. }
  13473. }
  13474. }
  13475. }
  13476. function throwInvalidHookError() {
  13477. throw new 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:\n' + '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' + '2. You might be breaking the Rules of Hooks\n' + '3. You might have more than one copy of React in the same app\n' + 'See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.');
  13478. }
  13479. function areHookInputsEqual(nextDeps, prevDeps) {
  13480. {
  13481. if (ignorePreviousDependencies) {
  13482. // Only true when this component is being hot reloaded.
  13483. return false;
  13484. }
  13485. }
  13486. if (prevDeps === null) {
  13487. {
  13488. 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);
  13489. }
  13490. return false;
  13491. }
  13492. {
  13493. // Don't bother comparing lengths in prod because these arrays should be
  13494. // passed inline.
  13495. if (nextDeps.length !== prevDeps.length) {
  13496. 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(', ') + "]");
  13497. }
  13498. }
  13499. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  13500. if (objectIs(nextDeps[i], prevDeps[i])) {
  13501. continue;
  13502. }
  13503. return false;
  13504. }
  13505. return true;
  13506. }
  13507. function renderWithHooks(current, workInProgress, Component, props, secondArg, nextRenderLanes) {
  13508. renderLanes = nextRenderLanes;
  13509. currentlyRenderingFiber$1 = workInProgress;
  13510. {
  13511. hookTypesDev = current !== null ? current._debugHookTypes : null;
  13512. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  13513. ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
  13514. }
  13515. workInProgress.memoizedState = null;
  13516. workInProgress.updateQueue = null;
  13517. workInProgress.lanes = NoLanes; // The following should have already been reset
  13518. // currentHook = null;
  13519. // workInProgressHook = null;
  13520. // didScheduleRenderPhaseUpdate = false;
  13521. // localIdCounter = 0;
  13522. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  13523. // Currently we will identify the update render as a mount because memoizedState === null.
  13524. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  13525. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  13526. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  13527. // so memoizedState would be null during updates and mounts.
  13528. {
  13529. if (current !== null && current.memoizedState !== null) {
  13530. ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
  13531. } else if (hookTypesDev !== null) {
  13532. // This dispatcher handles an edge case where a component is updating,
  13533. // but no stateful hooks have been used.
  13534. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  13535. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  13536. // This dispatcher does that.
  13537. ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
  13538. } else {
  13539. ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
  13540. }
  13541. }
  13542. var children = Component(props, secondArg); // Check if there was a render phase update
  13543. if (didScheduleRenderPhaseUpdateDuringThisPass) {
  13544. // Keep rendering in a loop for as long as render phase updates continue to
  13545. // be scheduled. Use a counter to prevent infinite loops.
  13546. var numberOfReRenders = 0;
  13547. do {
  13548. didScheduleRenderPhaseUpdateDuringThisPass = false;
  13549. localIdCounter = 0;
  13550. if (numberOfReRenders >= RE_RENDER_LIMIT) {
  13551. throw new Error('Too many re-renders. React limits the number of renders to prevent ' + 'an infinite loop.');
  13552. }
  13553. numberOfReRenders += 1;
  13554. {
  13555. // Even when hot reloading, allow dependencies to stabilize
  13556. // after first render to prevent infinite render phase updates.
  13557. ignorePreviousDependencies = false;
  13558. } // Start over from the beginning of the list
  13559. currentHook = null;
  13560. workInProgressHook = null;
  13561. workInProgress.updateQueue = null;
  13562. {
  13563. // Also validate hook order for cascading updates.
  13564. hookTypesUpdateIndexDev = -1;
  13565. }
  13566. ReactCurrentDispatcher$1.current = HooksDispatcherOnRerenderInDEV ;
  13567. children = Component(props, secondArg);
  13568. } while (didScheduleRenderPhaseUpdateDuringThisPass);
  13569. } // We can assume the previous dispatcher is always this one, since we set it
  13570. // at the beginning of the render phase and there's no re-entrance.
  13571. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  13572. {
  13573. workInProgress._debugHookTypes = hookTypesDev;
  13574. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  13575. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  13576. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  13577. renderLanes = NoLanes;
  13578. currentlyRenderingFiber$1 = null;
  13579. currentHook = null;
  13580. workInProgressHook = null;
  13581. {
  13582. currentHookNameInDev = null;
  13583. hookTypesDev = null;
  13584. hookTypesUpdateIndexDev = -1; // Confirm that a static flag was not added or removed since the last
  13585. // render. If this fires, it suggests that we incorrectly reset the static
  13586. // flags in some other part of the codebase. This has happened before, for
  13587. // example, in the SuspenseList implementation.
  13588. if (current !== null && (current.flags & StaticMask) !== (workInProgress.flags & StaticMask) && // Disable this warning in legacy mode, because legacy Suspense is weird
  13589. // and creates false positives. To make this work in legacy mode, we'd
  13590. // need to mark fibers that commit in an incomplete state, somehow. For
  13591. // now I'll disable the warning that most of the bugs that would trigger
  13592. // it are either exclusive to concurrent mode or exist in both.
  13593. (current.mode & ConcurrentMode) !== NoMode) {
  13594. error('Internal React error: Expected static flag was missing. Please ' + 'notify the React team.');
  13595. }
  13596. }
  13597. didScheduleRenderPhaseUpdate = false; // This is reset by checkDidRenderIdHook
  13598. // localIdCounter = 0;
  13599. if (didRenderTooFewHooks) {
  13600. throw new Error('Rendered fewer hooks than expected. This may be caused by an accidental ' + 'early return statement.');
  13601. }
  13602. return children;
  13603. }
  13604. function checkDidRenderIdHook() {
  13605. // This should be called immediately after every renderWithHooks call.
  13606. // Conceptually, it's part of the return value of renderWithHooks; it's only a
  13607. // separate function to avoid using an array tuple.
  13608. var didRenderIdHook = localIdCounter !== 0;
  13609. localIdCounter = 0;
  13610. return didRenderIdHook;
  13611. }
  13612. function bailoutHooks(current, workInProgress, lanes) {
  13613. workInProgress.updateQueue = current.updateQueue; // TODO: Don't need to reset the flags here, because they're reset in the
  13614. // complete phase (bubbleProperties).
  13615. if ( (workInProgress.mode & StrictEffectsMode) !== NoMode) {
  13616. workInProgress.flags &= ~(MountPassiveDev | MountLayoutDev | Passive | Update);
  13617. } else {
  13618. workInProgress.flags &= ~(Passive | Update);
  13619. }
  13620. current.lanes = removeLanes(current.lanes, lanes);
  13621. }
  13622. function resetHooksAfterThrow() {
  13623. // We can assume the previous dispatcher is always this one, since we set it
  13624. // at the beginning of the render phase and there's no re-entrance.
  13625. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  13626. if (didScheduleRenderPhaseUpdate) {
  13627. // There were render phase updates. These are only valid for this render
  13628. // phase, which we are now aborting. Remove the updates from the queues so
  13629. // they do not persist to the next render. Do not remove updates from hooks
  13630. // that weren't processed.
  13631. //
  13632. // Only reset the updates from the queue if it has a clone. If it does
  13633. // not have a clone, that means it wasn't processed, and the updates were
  13634. // scheduled before we entered the render phase.
  13635. var hook = currentlyRenderingFiber$1.memoizedState;
  13636. while (hook !== null) {
  13637. var queue = hook.queue;
  13638. if (queue !== null) {
  13639. queue.pending = null;
  13640. }
  13641. hook = hook.next;
  13642. }
  13643. didScheduleRenderPhaseUpdate = false;
  13644. }
  13645. renderLanes = NoLanes;
  13646. currentlyRenderingFiber$1 = null;
  13647. currentHook = null;
  13648. workInProgressHook = null;
  13649. {
  13650. hookTypesDev = null;
  13651. hookTypesUpdateIndexDev = -1;
  13652. currentHookNameInDev = null;
  13653. isUpdatingOpaqueValueInRenderPhase = false;
  13654. }
  13655. didScheduleRenderPhaseUpdateDuringThisPass = false;
  13656. localIdCounter = 0;
  13657. }
  13658. function mountWorkInProgressHook() {
  13659. var hook = {
  13660. memoizedState: null,
  13661. baseState: null,
  13662. baseQueue: null,
  13663. queue: null,
  13664. next: null
  13665. };
  13666. if (workInProgressHook === null) {
  13667. // This is the first hook in the list
  13668. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  13669. } else {
  13670. // Append to the end of the list
  13671. workInProgressHook = workInProgressHook.next = hook;
  13672. }
  13673. return workInProgressHook;
  13674. }
  13675. function updateWorkInProgressHook() {
  13676. // This function is used both for updates and for re-renders triggered by a
  13677. // render phase update. It assumes there is either a current hook we can
  13678. // clone, or a work-in-progress hook from a previous render pass that we can
  13679. // use as a base. When we reach the end of the base list, we must switch to
  13680. // the dispatcher used for mounts.
  13681. var nextCurrentHook;
  13682. if (currentHook === null) {
  13683. var current = currentlyRenderingFiber$1.alternate;
  13684. if (current !== null) {
  13685. nextCurrentHook = current.memoizedState;
  13686. } else {
  13687. nextCurrentHook = null;
  13688. }
  13689. } else {
  13690. nextCurrentHook = currentHook.next;
  13691. }
  13692. var nextWorkInProgressHook;
  13693. if (workInProgressHook === null) {
  13694. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  13695. } else {
  13696. nextWorkInProgressHook = workInProgressHook.next;
  13697. }
  13698. if (nextWorkInProgressHook !== null) {
  13699. // There's already a work-in-progress. Reuse it.
  13700. workInProgressHook = nextWorkInProgressHook;
  13701. nextWorkInProgressHook = workInProgressHook.next;
  13702. currentHook = nextCurrentHook;
  13703. } else {
  13704. // Clone from the current hook.
  13705. if (nextCurrentHook === null) {
  13706. throw new Error('Rendered more hooks than during the previous render.');
  13707. }
  13708. currentHook = nextCurrentHook;
  13709. var newHook = {
  13710. memoizedState: currentHook.memoizedState,
  13711. baseState: currentHook.baseState,
  13712. baseQueue: currentHook.baseQueue,
  13713. queue: currentHook.queue,
  13714. next: null
  13715. };
  13716. if (workInProgressHook === null) {
  13717. // This is the first hook in the list.
  13718. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  13719. } else {
  13720. // Append to the end of the list.
  13721. workInProgressHook = workInProgressHook.next = newHook;
  13722. }
  13723. }
  13724. return workInProgressHook;
  13725. }
  13726. function createFunctionComponentUpdateQueue() {
  13727. return {
  13728. lastEffect: null,
  13729. stores: null
  13730. };
  13731. }
  13732. function basicStateReducer(state, action) {
  13733. // $FlowFixMe: Flow doesn't like mixed types
  13734. return typeof action === 'function' ? action(state) : action;
  13735. }
  13736. function mountReducer(reducer, initialArg, init) {
  13737. var hook = mountWorkInProgressHook();
  13738. var initialState;
  13739. if (init !== undefined) {
  13740. initialState = init(initialArg);
  13741. } else {
  13742. initialState = initialArg;
  13743. }
  13744. hook.memoizedState = hook.baseState = initialState;
  13745. var queue = {
  13746. pending: null,
  13747. interleaved: null,
  13748. lanes: NoLanes,
  13749. dispatch: null,
  13750. lastRenderedReducer: reducer,
  13751. lastRenderedState: initialState
  13752. };
  13753. hook.queue = queue;
  13754. var dispatch = queue.dispatch = dispatchReducerAction.bind(null, currentlyRenderingFiber$1, queue);
  13755. return [hook.memoizedState, dispatch];
  13756. }
  13757. function updateReducer(reducer, initialArg, init) {
  13758. var hook = updateWorkInProgressHook();
  13759. var queue = hook.queue;
  13760. if (queue === null) {
  13761. throw new Error('Should have a queue. This is likely a bug in React. Please file an issue.');
  13762. }
  13763. queue.lastRenderedReducer = reducer;
  13764. var current = currentHook; // The last rebase update that is NOT part of the base state.
  13765. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  13766. var pendingQueue = queue.pending;
  13767. if (pendingQueue !== null) {
  13768. // We have new updates that haven't been processed yet.
  13769. // We'll add them to the base queue.
  13770. if (baseQueue !== null) {
  13771. // Merge the pending queue and the base queue.
  13772. var baseFirst = baseQueue.next;
  13773. var pendingFirst = pendingQueue.next;
  13774. baseQueue.next = pendingFirst;
  13775. pendingQueue.next = baseFirst;
  13776. }
  13777. {
  13778. if (current.baseQueue !== baseQueue) {
  13779. // Internal invariant that should never happen, but feasibly could in
  13780. // the future if we implement resuming, or some form of that.
  13781. error('Internal error: Expected work-in-progress queue to be a clone. ' + 'This is a bug in React.');
  13782. }
  13783. }
  13784. current.baseQueue = baseQueue = pendingQueue;
  13785. queue.pending = null;
  13786. }
  13787. if (baseQueue !== null) {
  13788. // We have a queue to process.
  13789. var first = baseQueue.next;
  13790. var newState = current.baseState;
  13791. var newBaseState = null;
  13792. var newBaseQueueFirst = null;
  13793. var newBaseQueueLast = null;
  13794. var update = first;
  13795. do {
  13796. var updateLane = update.lane;
  13797. if (!isSubsetOfLanes(renderLanes, updateLane)) {
  13798. // Priority is insufficient. Skip this update. If this is the first
  13799. // skipped update, the previous update/state is the new base
  13800. // update/state.
  13801. var clone = {
  13802. lane: updateLane,
  13803. action: update.action,
  13804. hasEagerState: update.hasEagerState,
  13805. eagerState: update.eagerState,
  13806. next: null
  13807. };
  13808. if (newBaseQueueLast === null) {
  13809. newBaseQueueFirst = newBaseQueueLast = clone;
  13810. newBaseState = newState;
  13811. } else {
  13812. newBaseQueueLast = newBaseQueueLast.next = clone;
  13813. } // Update the remaining priority in the queue.
  13814. // TODO: Don't need to accumulate this. Instead, we can remove
  13815. // renderLanes from the original lanes.
  13816. currentlyRenderingFiber$1.lanes = mergeLanes(currentlyRenderingFiber$1.lanes, updateLane);
  13817. markSkippedUpdateLanes(updateLane);
  13818. } else {
  13819. // This update does have sufficient priority.
  13820. if (newBaseQueueLast !== null) {
  13821. var _clone = {
  13822. // This update is going to be committed so we never want uncommit
  13823. // it. Using NoLane works because 0 is a subset of all bitmasks, so
  13824. // this will never be skipped by the check above.
  13825. lane: NoLane,
  13826. action: update.action,
  13827. hasEagerState: update.hasEagerState,
  13828. eagerState: update.eagerState,
  13829. next: null
  13830. };
  13831. newBaseQueueLast = newBaseQueueLast.next = _clone;
  13832. } // Process this update.
  13833. if (update.hasEagerState) {
  13834. // If this update is a state update (not a reducer) and was processed eagerly,
  13835. // we can use the eagerly computed state
  13836. newState = update.eagerState;
  13837. } else {
  13838. var action = update.action;
  13839. newState = reducer(newState, action);
  13840. }
  13841. }
  13842. update = update.next;
  13843. } while (update !== null && update !== first);
  13844. if (newBaseQueueLast === null) {
  13845. newBaseState = newState;
  13846. } else {
  13847. newBaseQueueLast.next = newBaseQueueFirst;
  13848. } // Mark that the fiber performed work, but only if the new state is
  13849. // different from the current state.
  13850. if (!objectIs(newState, hook.memoizedState)) {
  13851. markWorkInProgressReceivedUpdate();
  13852. }
  13853. hook.memoizedState = newState;
  13854. hook.baseState = newBaseState;
  13855. hook.baseQueue = newBaseQueueLast;
  13856. queue.lastRenderedState = newState;
  13857. } // Interleaved updates are stored on a separate queue. We aren't going to
  13858. // process them during this render, but we do need to track which lanes
  13859. // are remaining.
  13860. var lastInterleaved = queue.interleaved;
  13861. if (lastInterleaved !== null) {
  13862. var interleaved = lastInterleaved;
  13863. do {
  13864. var interleavedLane = interleaved.lane;
  13865. currentlyRenderingFiber$1.lanes = mergeLanes(currentlyRenderingFiber$1.lanes, interleavedLane);
  13866. markSkippedUpdateLanes(interleavedLane);
  13867. interleaved = interleaved.next;
  13868. } while (interleaved !== lastInterleaved);
  13869. } else if (baseQueue === null) {
  13870. // `queue.lanes` is used for entangling transitions. We can set it back to
  13871. // zero once the queue is empty.
  13872. queue.lanes = NoLanes;
  13873. }
  13874. var dispatch = queue.dispatch;
  13875. return [hook.memoizedState, dispatch];
  13876. }
  13877. function rerenderReducer(reducer, initialArg, init) {
  13878. var hook = updateWorkInProgressHook();
  13879. var queue = hook.queue;
  13880. if (queue === null) {
  13881. throw new Error('Should have a queue. This is likely a bug in React. Please file an issue.');
  13882. }
  13883. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  13884. // work-in-progress hook.
  13885. var dispatch = queue.dispatch;
  13886. var lastRenderPhaseUpdate = queue.pending;
  13887. var newState = hook.memoizedState;
  13888. if (lastRenderPhaseUpdate !== null) {
  13889. // The queue doesn't persist past this render pass.
  13890. queue.pending = null;
  13891. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  13892. var update = firstRenderPhaseUpdate;
  13893. do {
  13894. // Process this render phase update. We don't have to check the
  13895. // priority because it will always be the same as the current
  13896. // render's.
  13897. var action = update.action;
  13898. newState = reducer(newState, action);
  13899. update = update.next;
  13900. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  13901. // different from the current state.
  13902. if (!objectIs(newState, hook.memoizedState)) {
  13903. markWorkInProgressReceivedUpdate();
  13904. }
  13905. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  13906. // the base state unless the queue is empty.
  13907. // TODO: Not sure if this is the desired semantics, but it's what we
  13908. // do for gDSFP. I can't remember why.
  13909. if (hook.baseQueue === null) {
  13910. hook.baseState = newState;
  13911. }
  13912. queue.lastRenderedState = newState;
  13913. }
  13914. return [newState, dispatch];
  13915. }
  13916. function mountMutableSource(source, getSnapshot, subscribe) {
  13917. {
  13918. return undefined;
  13919. }
  13920. }
  13921. function updateMutableSource(source, getSnapshot, subscribe) {
  13922. {
  13923. return undefined;
  13924. }
  13925. }
  13926. function mountSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
  13927. var fiber = currentlyRenderingFiber$1;
  13928. var hook = mountWorkInProgressHook();
  13929. var nextSnapshot;
  13930. var isHydrating = getIsHydrating();
  13931. if (isHydrating) {
  13932. if (getServerSnapshot === undefined) {
  13933. throw new Error('Missing getServerSnapshot, which is required for ' + 'server-rendered content. Will revert to client rendering.');
  13934. }
  13935. nextSnapshot = getServerSnapshot();
  13936. {
  13937. if (!didWarnUncachedGetSnapshot) {
  13938. if (nextSnapshot !== getServerSnapshot()) {
  13939. error('The result of getServerSnapshot should be cached to avoid an infinite loop');
  13940. didWarnUncachedGetSnapshot = true;
  13941. }
  13942. }
  13943. }
  13944. } else {
  13945. nextSnapshot = getSnapshot();
  13946. {
  13947. if (!didWarnUncachedGetSnapshot) {
  13948. var cachedSnapshot = getSnapshot();
  13949. if (!objectIs(nextSnapshot, cachedSnapshot)) {
  13950. error('The result of getSnapshot should be cached to avoid an infinite loop');
  13951. didWarnUncachedGetSnapshot = true;
  13952. }
  13953. }
  13954. } // Unless we're rendering a blocking lane, schedule a consistency check.
  13955. // Right before committing, we will walk the tree and check if any of the
  13956. // stores were mutated.
  13957. //
  13958. // We won't do this if we're hydrating server-rendered content, because if
  13959. // the content is stale, it's already visible anyway. Instead we'll patch
  13960. // it up in a passive effect.
  13961. var root = getWorkInProgressRoot();
  13962. if (root === null) {
  13963. throw new Error('Expected a work-in-progress root. This is a bug in React. Please file an issue.');
  13964. }
  13965. if (!includesBlockingLane(root, renderLanes)) {
  13966. pushStoreConsistencyCheck(fiber, getSnapshot, nextSnapshot);
  13967. }
  13968. } // Read the current snapshot from the store on every render. This breaks the
  13969. // normal rules of React, and only works because store updates are
  13970. // always synchronous.
  13971. hook.memoizedState = nextSnapshot;
  13972. var inst = {
  13973. value: nextSnapshot,
  13974. getSnapshot: getSnapshot
  13975. };
  13976. hook.queue = inst; // Schedule an effect to subscribe to the store.
  13977. mountEffect(subscribeToStore.bind(null, fiber, inst, subscribe), [subscribe]); // Schedule an effect to update the mutable instance fields. We will update
  13978. // this whenever subscribe, getSnapshot, or value changes. Because there's no
  13979. // clean-up function, and we track the deps correctly, we can call pushEffect
  13980. // directly, without storing any additional state. For the same reason, we
  13981. // don't need to set a static flag, either.
  13982. // TODO: We can move this to the passive phase once we add a pre-commit
  13983. // consistency check. See the next comment.
  13984. fiber.flags |= Passive;
  13985. pushEffect(HasEffect | Passive$1, updateStoreInstance.bind(null, fiber, inst, nextSnapshot, getSnapshot), undefined, null);
  13986. return nextSnapshot;
  13987. }
  13988. function updateSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
  13989. var fiber = currentlyRenderingFiber$1;
  13990. var hook = updateWorkInProgressHook(); // Read the current snapshot from the store on every render. This breaks the
  13991. // normal rules of React, and only works because store updates are
  13992. // always synchronous.
  13993. var nextSnapshot = getSnapshot();
  13994. {
  13995. if (!didWarnUncachedGetSnapshot) {
  13996. var cachedSnapshot = getSnapshot();
  13997. if (!objectIs(nextSnapshot, cachedSnapshot)) {
  13998. error('The result of getSnapshot should be cached to avoid an infinite loop');
  13999. didWarnUncachedGetSnapshot = true;
  14000. }
  14001. }
  14002. }
  14003. var prevSnapshot = hook.memoizedState;
  14004. var snapshotChanged = !objectIs(prevSnapshot, nextSnapshot);
  14005. if (snapshotChanged) {
  14006. hook.memoizedState = nextSnapshot;
  14007. markWorkInProgressReceivedUpdate();
  14008. }
  14009. var inst = hook.queue;
  14010. updateEffect(subscribeToStore.bind(null, fiber, inst, subscribe), [subscribe]); // Whenever getSnapshot or subscribe changes, we need to check in the
  14011. // commit phase if there was an interleaved mutation. In concurrent mode
  14012. // this can happen all the time, but even in synchronous mode, an earlier
  14013. // effect may have mutated the store.
  14014. if (inst.getSnapshot !== getSnapshot || snapshotChanged || // Check if the susbcribe function changed. We can save some memory by
  14015. // checking whether we scheduled a subscription effect above.
  14016. workInProgressHook !== null && workInProgressHook.memoizedState.tag & HasEffect) {
  14017. fiber.flags |= Passive;
  14018. pushEffect(HasEffect | Passive$1, updateStoreInstance.bind(null, fiber, inst, nextSnapshot, getSnapshot), undefined, null); // Unless we're rendering a blocking lane, schedule a consistency check.
  14019. // Right before committing, we will walk the tree and check if any of the
  14020. // stores were mutated.
  14021. var root = getWorkInProgressRoot();
  14022. if (root === null) {
  14023. throw new Error('Expected a work-in-progress root. This is a bug in React. Please file an issue.');
  14024. }
  14025. if (!includesBlockingLane(root, renderLanes)) {
  14026. pushStoreConsistencyCheck(fiber, getSnapshot, nextSnapshot);
  14027. }
  14028. }
  14029. return nextSnapshot;
  14030. }
  14031. function pushStoreConsistencyCheck(fiber, getSnapshot, renderedSnapshot) {
  14032. fiber.flags |= StoreConsistency;
  14033. var check = {
  14034. getSnapshot: getSnapshot,
  14035. value: renderedSnapshot
  14036. };
  14037. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  14038. if (componentUpdateQueue === null) {
  14039. componentUpdateQueue = createFunctionComponentUpdateQueue();
  14040. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  14041. componentUpdateQueue.stores = [check];
  14042. } else {
  14043. var stores = componentUpdateQueue.stores;
  14044. if (stores === null) {
  14045. componentUpdateQueue.stores = [check];
  14046. } else {
  14047. stores.push(check);
  14048. }
  14049. }
  14050. }
  14051. function updateStoreInstance(fiber, inst, nextSnapshot, getSnapshot) {
  14052. // These are updated in the passive phase
  14053. inst.value = nextSnapshot;
  14054. inst.getSnapshot = getSnapshot; // Something may have been mutated in between render and commit. This could
  14055. // have been in an event that fired before the passive effects, or it could
  14056. // have been in a layout effect. In that case, we would have used the old
  14057. // snapsho and getSnapshot values to bail out. We need to check one more time.
  14058. if (checkIfSnapshotChanged(inst)) {
  14059. // Force a re-render.
  14060. forceStoreRerender(fiber);
  14061. }
  14062. }
  14063. function subscribeToStore(fiber, inst, subscribe) {
  14064. var handleStoreChange = function () {
  14065. // The store changed. Check if the snapshot changed since the last time we
  14066. // read from the store.
  14067. if (checkIfSnapshotChanged(inst)) {
  14068. // Force a re-render.
  14069. forceStoreRerender(fiber);
  14070. }
  14071. }; // Subscribe to the store and return a clean-up function.
  14072. return subscribe(handleStoreChange);
  14073. }
  14074. function checkIfSnapshotChanged(inst) {
  14075. var latestGetSnapshot = inst.getSnapshot;
  14076. var prevValue = inst.value;
  14077. try {
  14078. var nextValue = latestGetSnapshot();
  14079. return !objectIs(prevValue, nextValue);
  14080. } catch (error) {
  14081. return true;
  14082. }
  14083. }
  14084. function forceStoreRerender(fiber) {
  14085. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  14086. if (root !== null) {
  14087. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  14088. }
  14089. }
  14090. function mountState(initialState) {
  14091. var hook = mountWorkInProgressHook();
  14092. if (typeof initialState === 'function') {
  14093. // $FlowFixMe: Flow doesn't like mixed types
  14094. initialState = initialState();
  14095. }
  14096. hook.memoizedState = hook.baseState = initialState;
  14097. var queue = {
  14098. pending: null,
  14099. interleaved: null,
  14100. lanes: NoLanes,
  14101. dispatch: null,
  14102. lastRenderedReducer: basicStateReducer,
  14103. lastRenderedState: initialState
  14104. };
  14105. hook.queue = queue;
  14106. var dispatch = queue.dispatch = dispatchSetState.bind(null, currentlyRenderingFiber$1, queue);
  14107. return [hook.memoizedState, dispatch];
  14108. }
  14109. function updateState(initialState) {
  14110. return updateReducer(basicStateReducer);
  14111. }
  14112. function rerenderState(initialState) {
  14113. return rerenderReducer(basicStateReducer);
  14114. }
  14115. function pushEffect(tag, create, destroy, deps) {
  14116. var effect = {
  14117. tag: tag,
  14118. create: create,
  14119. destroy: destroy,
  14120. deps: deps,
  14121. // Circular
  14122. next: null
  14123. };
  14124. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  14125. if (componentUpdateQueue === null) {
  14126. componentUpdateQueue = createFunctionComponentUpdateQueue();
  14127. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  14128. componentUpdateQueue.lastEffect = effect.next = effect;
  14129. } else {
  14130. var lastEffect = componentUpdateQueue.lastEffect;
  14131. if (lastEffect === null) {
  14132. componentUpdateQueue.lastEffect = effect.next = effect;
  14133. } else {
  14134. var firstEffect = lastEffect.next;
  14135. lastEffect.next = effect;
  14136. effect.next = firstEffect;
  14137. componentUpdateQueue.lastEffect = effect;
  14138. }
  14139. }
  14140. return effect;
  14141. }
  14142. function mountRef(initialValue) {
  14143. var hook = mountWorkInProgressHook();
  14144. {
  14145. var _ref2 = {
  14146. current: initialValue
  14147. };
  14148. hook.memoizedState = _ref2;
  14149. return _ref2;
  14150. }
  14151. }
  14152. function updateRef(initialValue) {
  14153. var hook = updateWorkInProgressHook();
  14154. return hook.memoizedState;
  14155. }
  14156. function mountEffectImpl(fiberFlags, hookFlags, create, deps) {
  14157. var hook = mountWorkInProgressHook();
  14158. var nextDeps = deps === undefined ? null : deps;
  14159. currentlyRenderingFiber$1.flags |= fiberFlags;
  14160. hook.memoizedState = pushEffect(HasEffect | hookFlags, create, undefined, nextDeps);
  14161. }
  14162. function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
  14163. var hook = updateWorkInProgressHook();
  14164. var nextDeps = deps === undefined ? null : deps;
  14165. var destroy = undefined;
  14166. if (currentHook !== null) {
  14167. var prevEffect = currentHook.memoizedState;
  14168. destroy = prevEffect.destroy;
  14169. if (nextDeps !== null) {
  14170. var prevDeps = prevEffect.deps;
  14171. if (areHookInputsEqual(nextDeps, prevDeps)) {
  14172. hook.memoizedState = pushEffect(hookFlags, create, destroy, nextDeps);
  14173. return;
  14174. }
  14175. }
  14176. }
  14177. currentlyRenderingFiber$1.flags |= fiberFlags;
  14178. hook.memoizedState = pushEffect(HasEffect | hookFlags, create, destroy, nextDeps);
  14179. }
  14180. function mountEffect(create, deps) {
  14181. if ( (currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
  14182. return mountEffectImpl(MountPassiveDev | Passive | PassiveStatic, Passive$1, create, deps);
  14183. } else {
  14184. return mountEffectImpl(Passive | PassiveStatic, Passive$1, create, deps);
  14185. }
  14186. }
  14187. function updateEffect(create, deps) {
  14188. return updateEffectImpl(Passive, Passive$1, create, deps);
  14189. }
  14190. function mountInsertionEffect(create, deps) {
  14191. return mountEffectImpl(Update, Insertion, create, deps);
  14192. }
  14193. function updateInsertionEffect(create, deps) {
  14194. return updateEffectImpl(Update, Insertion, create, deps);
  14195. }
  14196. function mountLayoutEffect(create, deps) {
  14197. var fiberFlags = Update;
  14198. {
  14199. fiberFlags |= LayoutStatic;
  14200. }
  14201. if ( (currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
  14202. fiberFlags |= MountLayoutDev;
  14203. }
  14204. return mountEffectImpl(fiberFlags, Layout, create, deps);
  14205. }
  14206. function updateLayoutEffect(create, deps) {
  14207. return updateEffectImpl(Update, Layout, create, deps);
  14208. }
  14209. function imperativeHandleEffect(create, ref) {
  14210. if (typeof ref === 'function') {
  14211. var refCallback = ref;
  14212. var _inst = create();
  14213. refCallback(_inst);
  14214. return function () {
  14215. refCallback(null);
  14216. };
  14217. } else if (ref !== null && ref !== undefined) {
  14218. var refObject = ref;
  14219. {
  14220. if (!refObject.hasOwnProperty('current')) {
  14221. 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(', ') + '}');
  14222. }
  14223. }
  14224. var _inst2 = create();
  14225. refObject.current = _inst2;
  14226. return function () {
  14227. refObject.current = null;
  14228. };
  14229. }
  14230. }
  14231. function mountImperativeHandle(ref, create, deps) {
  14232. {
  14233. if (typeof create !== 'function') {
  14234. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  14235. }
  14236. } // TODO: If deps are provided, should we skip comparing the ref itself?
  14237. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  14238. var fiberFlags = Update;
  14239. {
  14240. fiberFlags |= LayoutStatic;
  14241. }
  14242. if ( (currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
  14243. fiberFlags |= MountLayoutDev;
  14244. }
  14245. return mountEffectImpl(fiberFlags, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  14246. }
  14247. function updateImperativeHandle(ref, create, deps) {
  14248. {
  14249. if (typeof create !== 'function') {
  14250. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  14251. }
  14252. } // TODO: If deps are provided, should we skip comparing the ref itself?
  14253. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  14254. return updateEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  14255. }
  14256. function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
  14257. // The react-debug-hooks package injects its own implementation
  14258. // so that e.g. DevTools can display custom hook values.
  14259. }
  14260. var updateDebugValue = mountDebugValue;
  14261. function mountCallback(callback, deps) {
  14262. var hook = mountWorkInProgressHook();
  14263. var nextDeps = deps === undefined ? null : deps;
  14264. hook.memoizedState = [callback, nextDeps];
  14265. return callback;
  14266. }
  14267. function updateCallback(callback, deps) {
  14268. var hook = updateWorkInProgressHook();
  14269. var nextDeps = deps === undefined ? null : deps;
  14270. var prevState = hook.memoizedState;
  14271. if (prevState !== null) {
  14272. if (nextDeps !== null) {
  14273. var prevDeps = prevState[1];
  14274. if (areHookInputsEqual(nextDeps, prevDeps)) {
  14275. return prevState[0];
  14276. }
  14277. }
  14278. }
  14279. hook.memoizedState = [callback, nextDeps];
  14280. return callback;
  14281. }
  14282. function mountMemo(nextCreate, deps) {
  14283. var hook = mountWorkInProgressHook();
  14284. var nextDeps = deps === undefined ? null : deps;
  14285. var nextValue = nextCreate();
  14286. hook.memoizedState = [nextValue, nextDeps];
  14287. return nextValue;
  14288. }
  14289. function updateMemo(nextCreate, deps) {
  14290. var hook = updateWorkInProgressHook();
  14291. var nextDeps = deps === undefined ? null : deps;
  14292. var prevState = hook.memoizedState;
  14293. if (prevState !== null) {
  14294. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  14295. if (nextDeps !== null) {
  14296. var prevDeps = prevState[1];
  14297. if (areHookInputsEqual(nextDeps, prevDeps)) {
  14298. return prevState[0];
  14299. }
  14300. }
  14301. }
  14302. var nextValue = nextCreate();
  14303. hook.memoizedState = [nextValue, nextDeps];
  14304. return nextValue;
  14305. }
  14306. function mountDeferredValue(value) {
  14307. var hook = mountWorkInProgressHook();
  14308. hook.memoizedState = value;
  14309. return value;
  14310. }
  14311. function updateDeferredValue(value) {
  14312. var hook = updateWorkInProgressHook();
  14313. var resolvedCurrentHook = currentHook;
  14314. var prevValue = resolvedCurrentHook.memoizedState;
  14315. return updateDeferredValueImpl(hook, prevValue, value);
  14316. }
  14317. function rerenderDeferredValue(value) {
  14318. var hook = updateWorkInProgressHook();
  14319. if (currentHook === null) {
  14320. // This is a rerender during a mount.
  14321. hook.memoizedState = value;
  14322. return value;
  14323. } else {
  14324. // This is a rerender during an update.
  14325. var prevValue = currentHook.memoizedState;
  14326. return updateDeferredValueImpl(hook, prevValue, value);
  14327. }
  14328. }
  14329. function updateDeferredValueImpl(hook, prevValue, value) {
  14330. var shouldDeferValue = !includesOnlyNonUrgentLanes(renderLanes);
  14331. if (shouldDeferValue) {
  14332. // This is an urgent update. If the value has changed, keep using the
  14333. // previous value and spawn a deferred render to update it later.
  14334. if (!objectIs(value, prevValue)) {
  14335. // Schedule a deferred render
  14336. var deferredLane = claimNextTransitionLane();
  14337. currentlyRenderingFiber$1.lanes = mergeLanes(currentlyRenderingFiber$1.lanes, deferredLane);
  14338. markSkippedUpdateLanes(deferredLane); // Set this to true to indicate that the rendered value is inconsistent
  14339. // from the latest value. The name "baseState" doesn't really match how we
  14340. // use it because we're reusing a state hook field instead of creating a
  14341. // new one.
  14342. hook.baseState = true;
  14343. } // Reuse the previous value
  14344. return prevValue;
  14345. } else {
  14346. // This is not an urgent update, so we can use the latest value regardless
  14347. // of what it is. No need to defer it.
  14348. // However, if we're currently inside a spawned render, then we need to mark
  14349. // this as an update to prevent the fiber from bailing out.
  14350. //
  14351. // `baseState` is true when the current value is different from the rendered
  14352. // value. The name doesn't really match how we use it because we're reusing
  14353. // a state hook field instead of creating a new one.
  14354. if (hook.baseState) {
  14355. // Flip this back to false.
  14356. hook.baseState = false;
  14357. markWorkInProgressReceivedUpdate();
  14358. }
  14359. hook.memoizedState = value;
  14360. return value;
  14361. }
  14362. }
  14363. function startTransition(setPending, callback, options) {
  14364. var previousPriority = getCurrentUpdatePriority();
  14365. setCurrentUpdatePriority(higherEventPriority(previousPriority, ContinuousEventPriority));
  14366. setPending(true);
  14367. var prevTransition = ReactCurrentBatchConfig$2.transition;
  14368. ReactCurrentBatchConfig$2.transition = {};
  14369. var currentTransition = ReactCurrentBatchConfig$2.transition;
  14370. {
  14371. ReactCurrentBatchConfig$2.transition._updatedFibers = new Set();
  14372. }
  14373. try {
  14374. setPending(false);
  14375. callback();
  14376. } finally {
  14377. setCurrentUpdatePriority(previousPriority);
  14378. ReactCurrentBatchConfig$2.transition = prevTransition;
  14379. {
  14380. if (prevTransition === null && currentTransition._updatedFibers) {
  14381. var updatedFibersCount = currentTransition._updatedFibers.size;
  14382. if (updatedFibersCount > 10) {
  14383. warn('Detected a large number of updates inside startTransition. ' + 'If this is due to a subscription please re-write it to use React provided hooks. ' + 'Otherwise concurrent mode guarantees are off the table.');
  14384. }
  14385. currentTransition._updatedFibers.clear();
  14386. }
  14387. }
  14388. }
  14389. }
  14390. function mountTransition() {
  14391. var _mountState = mountState(false),
  14392. isPending = _mountState[0],
  14393. setPending = _mountState[1]; // The `start` method never changes.
  14394. var start = startTransition.bind(null, setPending);
  14395. var hook = mountWorkInProgressHook();
  14396. hook.memoizedState = start;
  14397. return [isPending, start];
  14398. }
  14399. function updateTransition() {
  14400. var _updateState = updateState(),
  14401. isPending = _updateState[0];
  14402. var hook = updateWorkInProgressHook();
  14403. var start = hook.memoizedState;
  14404. return [isPending, start];
  14405. }
  14406. function rerenderTransition() {
  14407. var _rerenderState = rerenderState(),
  14408. isPending = _rerenderState[0];
  14409. var hook = updateWorkInProgressHook();
  14410. var start = hook.memoizedState;
  14411. return [isPending, start];
  14412. }
  14413. var isUpdatingOpaqueValueInRenderPhase = false;
  14414. function getIsUpdatingOpaqueValueInRenderPhaseInDEV() {
  14415. {
  14416. return isUpdatingOpaqueValueInRenderPhase;
  14417. }
  14418. }
  14419. function mountId() {
  14420. var hook = mountWorkInProgressHook();
  14421. var root = getWorkInProgressRoot(); // TODO: In Fizz, id generation is specific to each server config. Maybe we
  14422. // should do this in Fiber, too? Deferring this decision for now because
  14423. // there's no other place to store the prefix except for an internal field on
  14424. // the public createRoot object, which the fiber tree does not currently have
  14425. // a reference to.
  14426. var identifierPrefix = root.identifierPrefix;
  14427. var id;
  14428. if (getIsHydrating()) {
  14429. var treeId = getTreeId(); // Use a captial R prefix for server-generated ids.
  14430. id = ':' + identifierPrefix + 'R' + treeId; // Unless this is the first id at this level, append a number at the end
  14431. // that represents the position of this useId hook among all the useId
  14432. // hooks for this fiber.
  14433. var localId = localIdCounter++;
  14434. if (localId > 0) {
  14435. id += 'H' + localId.toString(32);
  14436. }
  14437. id += ':';
  14438. } else {
  14439. // Use a lowercase r prefix for client-generated ids.
  14440. var globalClientId = globalClientIdCounter++;
  14441. id = ':' + identifierPrefix + 'r' + globalClientId.toString(32) + ':';
  14442. }
  14443. hook.memoizedState = id;
  14444. return id;
  14445. }
  14446. function updateId() {
  14447. var hook = updateWorkInProgressHook();
  14448. var id = hook.memoizedState;
  14449. return id;
  14450. }
  14451. function dispatchReducerAction(fiber, queue, action) {
  14452. {
  14453. if (typeof arguments[3] === 'function') {
  14454. 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().');
  14455. }
  14456. }
  14457. var lane = requestUpdateLane(fiber);
  14458. var update = {
  14459. lane: lane,
  14460. action: action,
  14461. hasEagerState: false,
  14462. eagerState: null,
  14463. next: null
  14464. };
  14465. if (isRenderPhaseUpdate(fiber)) {
  14466. enqueueRenderPhaseUpdate(queue, update);
  14467. } else {
  14468. var root = enqueueConcurrentHookUpdate(fiber, queue, update, lane);
  14469. if (root !== null) {
  14470. var eventTime = requestEventTime();
  14471. scheduleUpdateOnFiber(root, fiber, lane, eventTime);
  14472. entangleTransitionUpdate(root, queue, lane);
  14473. }
  14474. }
  14475. markUpdateInDevTools(fiber, lane);
  14476. }
  14477. function dispatchSetState(fiber, queue, action) {
  14478. {
  14479. if (typeof arguments[3] === 'function') {
  14480. 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().');
  14481. }
  14482. }
  14483. var lane = requestUpdateLane(fiber);
  14484. var update = {
  14485. lane: lane,
  14486. action: action,
  14487. hasEagerState: false,
  14488. eagerState: null,
  14489. next: null
  14490. };
  14491. if (isRenderPhaseUpdate(fiber)) {
  14492. enqueueRenderPhaseUpdate(queue, update);
  14493. } else {
  14494. var alternate = fiber.alternate;
  14495. if (fiber.lanes === NoLanes && (alternate === null || alternate.lanes === NoLanes)) {
  14496. // The queue is currently empty, which means we can eagerly compute the
  14497. // next state before entering the render phase. If the new state is the
  14498. // same as the current state, we may be able to bail out entirely.
  14499. var lastRenderedReducer = queue.lastRenderedReducer;
  14500. if (lastRenderedReducer !== null) {
  14501. var prevDispatcher;
  14502. {
  14503. prevDispatcher = ReactCurrentDispatcher$1.current;
  14504. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  14505. }
  14506. try {
  14507. var currentState = queue.lastRenderedState;
  14508. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  14509. // it, on the update object. If the reducer hasn't changed by the
  14510. // time we enter the render phase, then the eager state can be used
  14511. // without calling the reducer again.
  14512. update.hasEagerState = true;
  14513. update.eagerState = eagerState;
  14514. if (objectIs(eagerState, currentState)) {
  14515. // Fast path. We can bail out without scheduling React to re-render.
  14516. // It's still possible that we'll need to rebase this update later,
  14517. // if the component re-renders for a different reason and by that
  14518. // time the reducer has changed.
  14519. // TODO: Do we still need to entangle transitions in this case?
  14520. enqueueConcurrentHookUpdateAndEagerlyBailout(fiber, queue, update, lane);
  14521. return;
  14522. }
  14523. } catch (error) {// Suppress the error. It will throw again in the render phase.
  14524. } finally {
  14525. {
  14526. ReactCurrentDispatcher$1.current = prevDispatcher;
  14527. }
  14528. }
  14529. }
  14530. }
  14531. var root = enqueueConcurrentHookUpdate(fiber, queue, update, lane);
  14532. if (root !== null) {
  14533. var eventTime = requestEventTime();
  14534. scheduleUpdateOnFiber(root, fiber, lane, eventTime);
  14535. entangleTransitionUpdate(root, queue, lane);
  14536. }
  14537. }
  14538. markUpdateInDevTools(fiber, lane);
  14539. }
  14540. function isRenderPhaseUpdate(fiber) {
  14541. var alternate = fiber.alternate;
  14542. return fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1;
  14543. }
  14544. function enqueueRenderPhaseUpdate(queue, update) {
  14545. // This is a render phase update. Stash it in a lazily-created map of
  14546. // queue -> linked list of updates. After this render pass, we'll restart
  14547. // and apply the stashed updates on top of the work-in-progress hook.
  14548. didScheduleRenderPhaseUpdateDuringThisPass = didScheduleRenderPhaseUpdate = true;
  14549. var pending = queue.pending;
  14550. if (pending === null) {
  14551. // This is the first update. Create a circular list.
  14552. update.next = update;
  14553. } else {
  14554. update.next = pending.next;
  14555. pending.next = update;
  14556. }
  14557. queue.pending = update;
  14558. } // TODO: Move to ReactFiberConcurrentUpdates?
  14559. function entangleTransitionUpdate(root, queue, lane) {
  14560. if (isTransitionLane(lane)) {
  14561. var queueLanes = queue.lanes; // If any entangled lanes are no longer pending on the root, then they
  14562. // must have finished. We can remove them from the shared queue, which
  14563. // represents a superset of the actually pending lanes. In some cases we
  14564. // may entangle more than we need to, but that's OK. In fact it's worse if
  14565. // we *don't* entangle when we should.
  14566. queueLanes = intersectLanes(queueLanes, root.pendingLanes); // Entangle the new transition lane with the other transition lanes.
  14567. var newQueueLanes = mergeLanes(queueLanes, lane);
  14568. queue.lanes = newQueueLanes; // Even if queue.lanes already include lane, we don't know for certain if
  14569. // the lane finished since the last time we entangled it. So we need to
  14570. // entangle it again, just to be sure.
  14571. markRootEntangled(root, newQueueLanes);
  14572. }
  14573. }
  14574. function markUpdateInDevTools(fiber, lane, action) {
  14575. {
  14576. markStateUpdateScheduled(fiber, lane);
  14577. }
  14578. }
  14579. var ContextOnlyDispatcher = {
  14580. readContext: readContext,
  14581. useCallback: throwInvalidHookError,
  14582. useContext: throwInvalidHookError,
  14583. useEffect: throwInvalidHookError,
  14584. useImperativeHandle: throwInvalidHookError,
  14585. useInsertionEffect: throwInvalidHookError,
  14586. useLayoutEffect: throwInvalidHookError,
  14587. useMemo: throwInvalidHookError,
  14588. useReducer: throwInvalidHookError,
  14589. useRef: throwInvalidHookError,
  14590. useState: throwInvalidHookError,
  14591. useDebugValue: throwInvalidHookError,
  14592. useDeferredValue: throwInvalidHookError,
  14593. useTransition: throwInvalidHookError,
  14594. useMutableSource: throwInvalidHookError,
  14595. useSyncExternalStore: throwInvalidHookError,
  14596. useId: throwInvalidHookError,
  14597. unstable_isNewReconciler: enableNewReconciler
  14598. };
  14599. var HooksDispatcherOnMountInDEV = null;
  14600. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  14601. var HooksDispatcherOnUpdateInDEV = null;
  14602. var HooksDispatcherOnRerenderInDEV = null;
  14603. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  14604. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  14605. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  14606. {
  14607. var warnInvalidContextAccess = function () {
  14608. 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().');
  14609. };
  14610. var warnInvalidHookAccess = function () {
  14611. 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://reactjs.org/link/rules-of-hooks');
  14612. };
  14613. HooksDispatcherOnMountInDEV = {
  14614. readContext: function (context) {
  14615. return readContext(context);
  14616. },
  14617. useCallback: function (callback, deps) {
  14618. currentHookNameInDev = 'useCallback';
  14619. mountHookTypesDev();
  14620. checkDepsAreArrayDev(deps);
  14621. return mountCallback(callback, deps);
  14622. },
  14623. useContext: function (context) {
  14624. currentHookNameInDev = 'useContext';
  14625. mountHookTypesDev();
  14626. return readContext(context);
  14627. },
  14628. useEffect: function (create, deps) {
  14629. currentHookNameInDev = 'useEffect';
  14630. mountHookTypesDev();
  14631. checkDepsAreArrayDev(deps);
  14632. return mountEffect(create, deps);
  14633. },
  14634. useImperativeHandle: function (ref, create, deps) {
  14635. currentHookNameInDev = 'useImperativeHandle';
  14636. mountHookTypesDev();
  14637. checkDepsAreArrayDev(deps);
  14638. return mountImperativeHandle(ref, create, deps);
  14639. },
  14640. useInsertionEffect: function (create, deps) {
  14641. currentHookNameInDev = 'useInsertionEffect';
  14642. mountHookTypesDev();
  14643. checkDepsAreArrayDev(deps);
  14644. return mountInsertionEffect(create, deps);
  14645. },
  14646. useLayoutEffect: function (create, deps) {
  14647. currentHookNameInDev = 'useLayoutEffect';
  14648. mountHookTypesDev();
  14649. checkDepsAreArrayDev(deps);
  14650. return mountLayoutEffect(create, deps);
  14651. },
  14652. useMemo: function (create, deps) {
  14653. currentHookNameInDev = 'useMemo';
  14654. mountHookTypesDev();
  14655. checkDepsAreArrayDev(deps);
  14656. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14657. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  14658. try {
  14659. return mountMemo(create, deps);
  14660. } finally {
  14661. ReactCurrentDispatcher$1.current = prevDispatcher;
  14662. }
  14663. },
  14664. useReducer: function (reducer, initialArg, init) {
  14665. currentHookNameInDev = 'useReducer';
  14666. mountHookTypesDev();
  14667. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14668. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  14669. try {
  14670. return mountReducer(reducer, initialArg, init);
  14671. } finally {
  14672. ReactCurrentDispatcher$1.current = prevDispatcher;
  14673. }
  14674. },
  14675. useRef: function (initialValue) {
  14676. currentHookNameInDev = 'useRef';
  14677. mountHookTypesDev();
  14678. return mountRef(initialValue);
  14679. },
  14680. useState: function (initialState) {
  14681. currentHookNameInDev = 'useState';
  14682. mountHookTypesDev();
  14683. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14684. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  14685. try {
  14686. return mountState(initialState);
  14687. } finally {
  14688. ReactCurrentDispatcher$1.current = prevDispatcher;
  14689. }
  14690. },
  14691. useDebugValue: function (value, formatterFn) {
  14692. currentHookNameInDev = 'useDebugValue';
  14693. mountHookTypesDev();
  14694. return mountDebugValue();
  14695. },
  14696. useDeferredValue: function (value) {
  14697. currentHookNameInDev = 'useDeferredValue';
  14698. mountHookTypesDev();
  14699. return mountDeferredValue(value);
  14700. },
  14701. useTransition: function () {
  14702. currentHookNameInDev = 'useTransition';
  14703. mountHookTypesDev();
  14704. return mountTransition();
  14705. },
  14706. useMutableSource: function (source, getSnapshot, subscribe) {
  14707. currentHookNameInDev = 'useMutableSource';
  14708. mountHookTypesDev();
  14709. return mountMutableSource();
  14710. },
  14711. useSyncExternalStore: function (subscribe, getSnapshot, getServerSnapshot) {
  14712. currentHookNameInDev = 'useSyncExternalStore';
  14713. mountHookTypesDev();
  14714. return mountSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
  14715. },
  14716. useId: function () {
  14717. currentHookNameInDev = 'useId';
  14718. mountHookTypesDev();
  14719. return mountId();
  14720. },
  14721. unstable_isNewReconciler: enableNewReconciler
  14722. };
  14723. HooksDispatcherOnMountWithHookTypesInDEV = {
  14724. readContext: function (context) {
  14725. return readContext(context);
  14726. },
  14727. useCallback: function (callback, deps) {
  14728. currentHookNameInDev = 'useCallback';
  14729. updateHookTypesDev();
  14730. return mountCallback(callback, deps);
  14731. },
  14732. useContext: function (context) {
  14733. currentHookNameInDev = 'useContext';
  14734. updateHookTypesDev();
  14735. return readContext(context);
  14736. },
  14737. useEffect: function (create, deps) {
  14738. currentHookNameInDev = 'useEffect';
  14739. updateHookTypesDev();
  14740. return mountEffect(create, deps);
  14741. },
  14742. useImperativeHandle: function (ref, create, deps) {
  14743. currentHookNameInDev = 'useImperativeHandle';
  14744. updateHookTypesDev();
  14745. return mountImperativeHandle(ref, create, deps);
  14746. },
  14747. useInsertionEffect: function (create, deps) {
  14748. currentHookNameInDev = 'useInsertionEffect';
  14749. updateHookTypesDev();
  14750. return mountInsertionEffect(create, deps);
  14751. },
  14752. useLayoutEffect: function (create, deps) {
  14753. currentHookNameInDev = 'useLayoutEffect';
  14754. updateHookTypesDev();
  14755. return mountLayoutEffect(create, deps);
  14756. },
  14757. useMemo: function (create, deps) {
  14758. currentHookNameInDev = 'useMemo';
  14759. updateHookTypesDev();
  14760. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14761. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  14762. try {
  14763. return mountMemo(create, deps);
  14764. } finally {
  14765. ReactCurrentDispatcher$1.current = prevDispatcher;
  14766. }
  14767. },
  14768. useReducer: function (reducer, initialArg, init) {
  14769. currentHookNameInDev = 'useReducer';
  14770. updateHookTypesDev();
  14771. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14772. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  14773. try {
  14774. return mountReducer(reducer, initialArg, init);
  14775. } finally {
  14776. ReactCurrentDispatcher$1.current = prevDispatcher;
  14777. }
  14778. },
  14779. useRef: function (initialValue) {
  14780. currentHookNameInDev = 'useRef';
  14781. updateHookTypesDev();
  14782. return mountRef(initialValue);
  14783. },
  14784. useState: function (initialState) {
  14785. currentHookNameInDev = 'useState';
  14786. updateHookTypesDev();
  14787. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14788. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  14789. try {
  14790. return mountState(initialState);
  14791. } finally {
  14792. ReactCurrentDispatcher$1.current = prevDispatcher;
  14793. }
  14794. },
  14795. useDebugValue: function (value, formatterFn) {
  14796. currentHookNameInDev = 'useDebugValue';
  14797. updateHookTypesDev();
  14798. return mountDebugValue();
  14799. },
  14800. useDeferredValue: function (value) {
  14801. currentHookNameInDev = 'useDeferredValue';
  14802. updateHookTypesDev();
  14803. return mountDeferredValue(value);
  14804. },
  14805. useTransition: function () {
  14806. currentHookNameInDev = 'useTransition';
  14807. updateHookTypesDev();
  14808. return mountTransition();
  14809. },
  14810. useMutableSource: function (source, getSnapshot, subscribe) {
  14811. currentHookNameInDev = 'useMutableSource';
  14812. updateHookTypesDev();
  14813. return mountMutableSource();
  14814. },
  14815. useSyncExternalStore: function (subscribe, getSnapshot, getServerSnapshot) {
  14816. currentHookNameInDev = 'useSyncExternalStore';
  14817. updateHookTypesDev();
  14818. return mountSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
  14819. },
  14820. useId: function () {
  14821. currentHookNameInDev = 'useId';
  14822. updateHookTypesDev();
  14823. return mountId();
  14824. },
  14825. unstable_isNewReconciler: enableNewReconciler
  14826. };
  14827. HooksDispatcherOnUpdateInDEV = {
  14828. readContext: function (context) {
  14829. return readContext(context);
  14830. },
  14831. useCallback: function (callback, deps) {
  14832. currentHookNameInDev = 'useCallback';
  14833. updateHookTypesDev();
  14834. return updateCallback(callback, deps);
  14835. },
  14836. useContext: function (context) {
  14837. currentHookNameInDev = 'useContext';
  14838. updateHookTypesDev();
  14839. return readContext(context);
  14840. },
  14841. useEffect: function (create, deps) {
  14842. currentHookNameInDev = 'useEffect';
  14843. updateHookTypesDev();
  14844. return updateEffect(create, deps);
  14845. },
  14846. useImperativeHandle: function (ref, create, deps) {
  14847. currentHookNameInDev = 'useImperativeHandle';
  14848. updateHookTypesDev();
  14849. return updateImperativeHandle(ref, create, deps);
  14850. },
  14851. useInsertionEffect: function (create, deps) {
  14852. currentHookNameInDev = 'useInsertionEffect';
  14853. updateHookTypesDev();
  14854. return updateInsertionEffect(create, deps);
  14855. },
  14856. useLayoutEffect: function (create, deps) {
  14857. currentHookNameInDev = 'useLayoutEffect';
  14858. updateHookTypesDev();
  14859. return updateLayoutEffect(create, deps);
  14860. },
  14861. useMemo: function (create, deps) {
  14862. currentHookNameInDev = 'useMemo';
  14863. updateHookTypesDev();
  14864. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14865. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  14866. try {
  14867. return updateMemo(create, deps);
  14868. } finally {
  14869. ReactCurrentDispatcher$1.current = prevDispatcher;
  14870. }
  14871. },
  14872. useReducer: function (reducer, initialArg, init) {
  14873. currentHookNameInDev = 'useReducer';
  14874. updateHookTypesDev();
  14875. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14876. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  14877. try {
  14878. return updateReducer(reducer, initialArg, init);
  14879. } finally {
  14880. ReactCurrentDispatcher$1.current = prevDispatcher;
  14881. }
  14882. },
  14883. useRef: function (initialValue) {
  14884. currentHookNameInDev = 'useRef';
  14885. updateHookTypesDev();
  14886. return updateRef();
  14887. },
  14888. useState: function (initialState) {
  14889. currentHookNameInDev = 'useState';
  14890. updateHookTypesDev();
  14891. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14892. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  14893. try {
  14894. return updateState(initialState);
  14895. } finally {
  14896. ReactCurrentDispatcher$1.current = prevDispatcher;
  14897. }
  14898. },
  14899. useDebugValue: function (value, formatterFn) {
  14900. currentHookNameInDev = 'useDebugValue';
  14901. updateHookTypesDev();
  14902. return updateDebugValue();
  14903. },
  14904. useDeferredValue: function (value) {
  14905. currentHookNameInDev = 'useDeferredValue';
  14906. updateHookTypesDev();
  14907. return updateDeferredValue(value);
  14908. },
  14909. useTransition: function () {
  14910. currentHookNameInDev = 'useTransition';
  14911. updateHookTypesDev();
  14912. return updateTransition();
  14913. },
  14914. useMutableSource: function (source, getSnapshot, subscribe) {
  14915. currentHookNameInDev = 'useMutableSource';
  14916. updateHookTypesDev();
  14917. return updateMutableSource();
  14918. },
  14919. useSyncExternalStore: function (subscribe, getSnapshot, getServerSnapshot) {
  14920. currentHookNameInDev = 'useSyncExternalStore';
  14921. updateHookTypesDev();
  14922. return updateSyncExternalStore(subscribe, getSnapshot);
  14923. },
  14924. useId: function () {
  14925. currentHookNameInDev = 'useId';
  14926. updateHookTypesDev();
  14927. return updateId();
  14928. },
  14929. unstable_isNewReconciler: enableNewReconciler
  14930. };
  14931. HooksDispatcherOnRerenderInDEV = {
  14932. readContext: function (context) {
  14933. return readContext(context);
  14934. },
  14935. useCallback: function (callback, deps) {
  14936. currentHookNameInDev = 'useCallback';
  14937. updateHookTypesDev();
  14938. return updateCallback(callback, deps);
  14939. },
  14940. useContext: function (context) {
  14941. currentHookNameInDev = 'useContext';
  14942. updateHookTypesDev();
  14943. return readContext(context);
  14944. },
  14945. useEffect: function (create, deps) {
  14946. currentHookNameInDev = 'useEffect';
  14947. updateHookTypesDev();
  14948. return updateEffect(create, deps);
  14949. },
  14950. useImperativeHandle: function (ref, create, deps) {
  14951. currentHookNameInDev = 'useImperativeHandle';
  14952. updateHookTypesDev();
  14953. return updateImperativeHandle(ref, create, deps);
  14954. },
  14955. useInsertionEffect: function (create, deps) {
  14956. currentHookNameInDev = 'useInsertionEffect';
  14957. updateHookTypesDev();
  14958. return updateInsertionEffect(create, deps);
  14959. },
  14960. useLayoutEffect: function (create, deps) {
  14961. currentHookNameInDev = 'useLayoutEffect';
  14962. updateHookTypesDev();
  14963. return updateLayoutEffect(create, deps);
  14964. },
  14965. useMemo: function (create, deps) {
  14966. currentHookNameInDev = 'useMemo';
  14967. updateHookTypesDev();
  14968. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14969. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  14970. try {
  14971. return updateMemo(create, deps);
  14972. } finally {
  14973. ReactCurrentDispatcher$1.current = prevDispatcher;
  14974. }
  14975. },
  14976. useReducer: function (reducer, initialArg, init) {
  14977. currentHookNameInDev = 'useReducer';
  14978. updateHookTypesDev();
  14979. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14980. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  14981. try {
  14982. return rerenderReducer(reducer, initialArg, init);
  14983. } finally {
  14984. ReactCurrentDispatcher$1.current = prevDispatcher;
  14985. }
  14986. },
  14987. useRef: function (initialValue) {
  14988. currentHookNameInDev = 'useRef';
  14989. updateHookTypesDev();
  14990. return updateRef();
  14991. },
  14992. useState: function (initialState) {
  14993. currentHookNameInDev = 'useState';
  14994. updateHookTypesDev();
  14995. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14996. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  14997. try {
  14998. return rerenderState(initialState);
  14999. } finally {
  15000. ReactCurrentDispatcher$1.current = prevDispatcher;
  15001. }
  15002. },
  15003. useDebugValue: function (value, formatterFn) {
  15004. currentHookNameInDev = 'useDebugValue';
  15005. updateHookTypesDev();
  15006. return updateDebugValue();
  15007. },
  15008. useDeferredValue: function (value) {
  15009. currentHookNameInDev = 'useDeferredValue';
  15010. updateHookTypesDev();
  15011. return rerenderDeferredValue(value);
  15012. },
  15013. useTransition: function () {
  15014. currentHookNameInDev = 'useTransition';
  15015. updateHookTypesDev();
  15016. return rerenderTransition();
  15017. },
  15018. useMutableSource: function (source, getSnapshot, subscribe) {
  15019. currentHookNameInDev = 'useMutableSource';
  15020. updateHookTypesDev();
  15021. return updateMutableSource();
  15022. },
  15023. useSyncExternalStore: function (subscribe, getSnapshot, getServerSnapshot) {
  15024. currentHookNameInDev = 'useSyncExternalStore';
  15025. updateHookTypesDev();
  15026. return updateSyncExternalStore(subscribe, getSnapshot);
  15027. },
  15028. useId: function () {
  15029. currentHookNameInDev = 'useId';
  15030. updateHookTypesDev();
  15031. return updateId();
  15032. },
  15033. unstable_isNewReconciler: enableNewReconciler
  15034. };
  15035. InvalidNestedHooksDispatcherOnMountInDEV = {
  15036. readContext: function (context) {
  15037. warnInvalidContextAccess();
  15038. return readContext(context);
  15039. },
  15040. useCallback: function (callback, deps) {
  15041. currentHookNameInDev = 'useCallback';
  15042. warnInvalidHookAccess();
  15043. mountHookTypesDev();
  15044. return mountCallback(callback, deps);
  15045. },
  15046. useContext: function (context) {
  15047. currentHookNameInDev = 'useContext';
  15048. warnInvalidHookAccess();
  15049. mountHookTypesDev();
  15050. return readContext(context);
  15051. },
  15052. useEffect: function (create, deps) {
  15053. currentHookNameInDev = 'useEffect';
  15054. warnInvalidHookAccess();
  15055. mountHookTypesDev();
  15056. return mountEffect(create, deps);
  15057. },
  15058. useImperativeHandle: function (ref, create, deps) {
  15059. currentHookNameInDev = 'useImperativeHandle';
  15060. warnInvalidHookAccess();
  15061. mountHookTypesDev();
  15062. return mountImperativeHandle(ref, create, deps);
  15063. },
  15064. useInsertionEffect: function (create, deps) {
  15065. currentHookNameInDev = 'useInsertionEffect';
  15066. warnInvalidHookAccess();
  15067. mountHookTypesDev();
  15068. return mountInsertionEffect(create, deps);
  15069. },
  15070. useLayoutEffect: function (create, deps) {
  15071. currentHookNameInDev = 'useLayoutEffect';
  15072. warnInvalidHookAccess();
  15073. mountHookTypesDev();
  15074. return mountLayoutEffect(create, deps);
  15075. },
  15076. useMemo: function (create, deps) {
  15077. currentHookNameInDev = 'useMemo';
  15078. warnInvalidHookAccess();
  15079. mountHookTypesDev();
  15080. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15081. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  15082. try {
  15083. return mountMemo(create, deps);
  15084. } finally {
  15085. ReactCurrentDispatcher$1.current = prevDispatcher;
  15086. }
  15087. },
  15088. useReducer: function (reducer, initialArg, init) {
  15089. currentHookNameInDev = 'useReducer';
  15090. warnInvalidHookAccess();
  15091. mountHookTypesDev();
  15092. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15093. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  15094. try {
  15095. return mountReducer(reducer, initialArg, init);
  15096. } finally {
  15097. ReactCurrentDispatcher$1.current = prevDispatcher;
  15098. }
  15099. },
  15100. useRef: function (initialValue) {
  15101. currentHookNameInDev = 'useRef';
  15102. warnInvalidHookAccess();
  15103. mountHookTypesDev();
  15104. return mountRef(initialValue);
  15105. },
  15106. useState: function (initialState) {
  15107. currentHookNameInDev = 'useState';
  15108. warnInvalidHookAccess();
  15109. mountHookTypesDev();
  15110. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15111. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  15112. try {
  15113. return mountState(initialState);
  15114. } finally {
  15115. ReactCurrentDispatcher$1.current = prevDispatcher;
  15116. }
  15117. },
  15118. useDebugValue: function (value, formatterFn) {
  15119. currentHookNameInDev = 'useDebugValue';
  15120. warnInvalidHookAccess();
  15121. mountHookTypesDev();
  15122. return mountDebugValue();
  15123. },
  15124. useDeferredValue: function (value) {
  15125. currentHookNameInDev = 'useDeferredValue';
  15126. warnInvalidHookAccess();
  15127. mountHookTypesDev();
  15128. return mountDeferredValue(value);
  15129. },
  15130. useTransition: function () {
  15131. currentHookNameInDev = 'useTransition';
  15132. warnInvalidHookAccess();
  15133. mountHookTypesDev();
  15134. return mountTransition();
  15135. },
  15136. useMutableSource: function (source, getSnapshot, subscribe) {
  15137. currentHookNameInDev = 'useMutableSource';
  15138. warnInvalidHookAccess();
  15139. mountHookTypesDev();
  15140. return mountMutableSource();
  15141. },
  15142. useSyncExternalStore: function (subscribe, getSnapshot, getServerSnapshot) {
  15143. currentHookNameInDev = 'useSyncExternalStore';
  15144. warnInvalidHookAccess();
  15145. mountHookTypesDev();
  15146. return mountSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
  15147. },
  15148. useId: function () {
  15149. currentHookNameInDev = 'useId';
  15150. warnInvalidHookAccess();
  15151. mountHookTypesDev();
  15152. return mountId();
  15153. },
  15154. unstable_isNewReconciler: enableNewReconciler
  15155. };
  15156. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  15157. readContext: function (context) {
  15158. warnInvalidContextAccess();
  15159. return readContext(context);
  15160. },
  15161. useCallback: function (callback, deps) {
  15162. currentHookNameInDev = 'useCallback';
  15163. warnInvalidHookAccess();
  15164. updateHookTypesDev();
  15165. return updateCallback(callback, deps);
  15166. },
  15167. useContext: function (context) {
  15168. currentHookNameInDev = 'useContext';
  15169. warnInvalidHookAccess();
  15170. updateHookTypesDev();
  15171. return readContext(context);
  15172. },
  15173. useEffect: function (create, deps) {
  15174. currentHookNameInDev = 'useEffect';
  15175. warnInvalidHookAccess();
  15176. updateHookTypesDev();
  15177. return updateEffect(create, deps);
  15178. },
  15179. useImperativeHandle: function (ref, create, deps) {
  15180. currentHookNameInDev = 'useImperativeHandle';
  15181. warnInvalidHookAccess();
  15182. updateHookTypesDev();
  15183. return updateImperativeHandle(ref, create, deps);
  15184. },
  15185. useInsertionEffect: function (create, deps) {
  15186. currentHookNameInDev = 'useInsertionEffect';
  15187. warnInvalidHookAccess();
  15188. updateHookTypesDev();
  15189. return updateInsertionEffect(create, deps);
  15190. },
  15191. useLayoutEffect: function (create, deps) {
  15192. currentHookNameInDev = 'useLayoutEffect';
  15193. warnInvalidHookAccess();
  15194. updateHookTypesDev();
  15195. return updateLayoutEffect(create, deps);
  15196. },
  15197. useMemo: function (create, deps) {
  15198. currentHookNameInDev = 'useMemo';
  15199. warnInvalidHookAccess();
  15200. updateHookTypesDev();
  15201. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15202. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  15203. try {
  15204. return updateMemo(create, deps);
  15205. } finally {
  15206. ReactCurrentDispatcher$1.current = prevDispatcher;
  15207. }
  15208. },
  15209. useReducer: function (reducer, initialArg, init) {
  15210. currentHookNameInDev = 'useReducer';
  15211. warnInvalidHookAccess();
  15212. updateHookTypesDev();
  15213. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15214. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  15215. try {
  15216. return updateReducer(reducer, initialArg, init);
  15217. } finally {
  15218. ReactCurrentDispatcher$1.current = prevDispatcher;
  15219. }
  15220. },
  15221. useRef: function (initialValue) {
  15222. currentHookNameInDev = 'useRef';
  15223. warnInvalidHookAccess();
  15224. updateHookTypesDev();
  15225. return updateRef();
  15226. },
  15227. useState: function (initialState) {
  15228. currentHookNameInDev = 'useState';
  15229. warnInvalidHookAccess();
  15230. updateHookTypesDev();
  15231. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15232. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  15233. try {
  15234. return updateState(initialState);
  15235. } finally {
  15236. ReactCurrentDispatcher$1.current = prevDispatcher;
  15237. }
  15238. },
  15239. useDebugValue: function (value, formatterFn) {
  15240. currentHookNameInDev = 'useDebugValue';
  15241. warnInvalidHookAccess();
  15242. updateHookTypesDev();
  15243. return updateDebugValue();
  15244. },
  15245. useDeferredValue: function (value) {
  15246. currentHookNameInDev = 'useDeferredValue';
  15247. warnInvalidHookAccess();
  15248. updateHookTypesDev();
  15249. return updateDeferredValue(value);
  15250. },
  15251. useTransition: function () {
  15252. currentHookNameInDev = 'useTransition';
  15253. warnInvalidHookAccess();
  15254. updateHookTypesDev();
  15255. return updateTransition();
  15256. },
  15257. useMutableSource: function (source, getSnapshot, subscribe) {
  15258. currentHookNameInDev = 'useMutableSource';
  15259. warnInvalidHookAccess();
  15260. updateHookTypesDev();
  15261. return updateMutableSource();
  15262. },
  15263. useSyncExternalStore: function (subscribe, getSnapshot, getServerSnapshot) {
  15264. currentHookNameInDev = 'useSyncExternalStore';
  15265. warnInvalidHookAccess();
  15266. updateHookTypesDev();
  15267. return updateSyncExternalStore(subscribe, getSnapshot);
  15268. },
  15269. useId: function () {
  15270. currentHookNameInDev = 'useId';
  15271. warnInvalidHookAccess();
  15272. updateHookTypesDev();
  15273. return updateId();
  15274. },
  15275. unstable_isNewReconciler: enableNewReconciler
  15276. };
  15277. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  15278. readContext: function (context) {
  15279. warnInvalidContextAccess();
  15280. return readContext(context);
  15281. },
  15282. useCallback: function (callback, deps) {
  15283. currentHookNameInDev = 'useCallback';
  15284. warnInvalidHookAccess();
  15285. updateHookTypesDev();
  15286. return updateCallback(callback, deps);
  15287. },
  15288. useContext: function (context) {
  15289. currentHookNameInDev = 'useContext';
  15290. warnInvalidHookAccess();
  15291. updateHookTypesDev();
  15292. return readContext(context);
  15293. },
  15294. useEffect: function (create, deps) {
  15295. currentHookNameInDev = 'useEffect';
  15296. warnInvalidHookAccess();
  15297. updateHookTypesDev();
  15298. return updateEffect(create, deps);
  15299. },
  15300. useImperativeHandle: function (ref, create, deps) {
  15301. currentHookNameInDev = 'useImperativeHandle';
  15302. warnInvalidHookAccess();
  15303. updateHookTypesDev();
  15304. return updateImperativeHandle(ref, create, deps);
  15305. },
  15306. useInsertionEffect: function (create, deps) {
  15307. currentHookNameInDev = 'useInsertionEffect';
  15308. warnInvalidHookAccess();
  15309. updateHookTypesDev();
  15310. return updateInsertionEffect(create, deps);
  15311. },
  15312. useLayoutEffect: function (create, deps) {
  15313. currentHookNameInDev = 'useLayoutEffect';
  15314. warnInvalidHookAccess();
  15315. updateHookTypesDev();
  15316. return updateLayoutEffect(create, deps);
  15317. },
  15318. useMemo: function (create, deps) {
  15319. currentHookNameInDev = 'useMemo';
  15320. warnInvalidHookAccess();
  15321. updateHookTypesDev();
  15322. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15323. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  15324. try {
  15325. return updateMemo(create, deps);
  15326. } finally {
  15327. ReactCurrentDispatcher$1.current = prevDispatcher;
  15328. }
  15329. },
  15330. useReducer: function (reducer, initialArg, init) {
  15331. currentHookNameInDev = 'useReducer';
  15332. warnInvalidHookAccess();
  15333. updateHookTypesDev();
  15334. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15335. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  15336. try {
  15337. return rerenderReducer(reducer, initialArg, init);
  15338. } finally {
  15339. ReactCurrentDispatcher$1.current = prevDispatcher;
  15340. }
  15341. },
  15342. useRef: function (initialValue) {
  15343. currentHookNameInDev = 'useRef';
  15344. warnInvalidHookAccess();
  15345. updateHookTypesDev();
  15346. return updateRef();
  15347. },
  15348. useState: function (initialState) {
  15349. currentHookNameInDev = 'useState';
  15350. warnInvalidHookAccess();
  15351. updateHookTypesDev();
  15352. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15353. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  15354. try {
  15355. return rerenderState(initialState);
  15356. } finally {
  15357. ReactCurrentDispatcher$1.current = prevDispatcher;
  15358. }
  15359. },
  15360. useDebugValue: function (value, formatterFn) {
  15361. currentHookNameInDev = 'useDebugValue';
  15362. warnInvalidHookAccess();
  15363. updateHookTypesDev();
  15364. return updateDebugValue();
  15365. },
  15366. useDeferredValue: function (value) {
  15367. currentHookNameInDev = 'useDeferredValue';
  15368. warnInvalidHookAccess();
  15369. updateHookTypesDev();
  15370. return rerenderDeferredValue(value);
  15371. },
  15372. useTransition: function () {
  15373. currentHookNameInDev = 'useTransition';
  15374. warnInvalidHookAccess();
  15375. updateHookTypesDev();
  15376. return rerenderTransition();
  15377. },
  15378. useMutableSource: function (source, getSnapshot, subscribe) {
  15379. currentHookNameInDev = 'useMutableSource';
  15380. warnInvalidHookAccess();
  15381. updateHookTypesDev();
  15382. return updateMutableSource();
  15383. },
  15384. useSyncExternalStore: function (subscribe, getSnapshot, getServerSnapshot) {
  15385. currentHookNameInDev = 'useSyncExternalStore';
  15386. warnInvalidHookAccess();
  15387. updateHookTypesDev();
  15388. return updateSyncExternalStore(subscribe, getSnapshot);
  15389. },
  15390. useId: function () {
  15391. currentHookNameInDev = 'useId';
  15392. warnInvalidHookAccess();
  15393. updateHookTypesDev();
  15394. return updateId();
  15395. },
  15396. unstable_isNewReconciler: enableNewReconciler
  15397. };
  15398. }
  15399. var now$1 = Scheduler.unstable_now;
  15400. var commitTime = 0;
  15401. var layoutEffectStartTime = -1;
  15402. var profilerStartTime = -1;
  15403. var passiveEffectStartTime = -1;
  15404. /**
  15405. * Tracks whether the current update was a nested/cascading update (scheduled from a layout effect).
  15406. *
  15407. * The overall sequence is:
  15408. * 1. render
  15409. * 2. commit (and call `onRender`, `onCommit`)
  15410. * 3. check for nested updates
  15411. * 4. flush passive effects (and call `onPostCommit`)
  15412. *
  15413. * Nested updates are identified in step 3 above,
  15414. * but step 4 still applies to the work that was just committed.
  15415. * We use two flags to track nested updates then:
  15416. * one tracks whether the upcoming update is a nested update,
  15417. * and the other tracks whether the current update was a nested update.
  15418. * The first value gets synced to the second at the start of the render phase.
  15419. */
  15420. var currentUpdateIsNested = false;
  15421. var nestedUpdateScheduled = false;
  15422. function isCurrentUpdateNested() {
  15423. return currentUpdateIsNested;
  15424. }
  15425. function markNestedUpdateScheduled() {
  15426. {
  15427. nestedUpdateScheduled = true;
  15428. }
  15429. }
  15430. function resetNestedUpdateFlag() {
  15431. {
  15432. currentUpdateIsNested = false;
  15433. nestedUpdateScheduled = false;
  15434. }
  15435. }
  15436. function syncNestedUpdateFlag() {
  15437. {
  15438. currentUpdateIsNested = nestedUpdateScheduled;
  15439. nestedUpdateScheduled = false;
  15440. }
  15441. }
  15442. function getCommitTime() {
  15443. return commitTime;
  15444. }
  15445. function recordCommitTime() {
  15446. commitTime = now$1();
  15447. }
  15448. function startProfilerTimer(fiber) {
  15449. profilerStartTime = now$1();
  15450. if (fiber.actualStartTime < 0) {
  15451. fiber.actualStartTime = now$1();
  15452. }
  15453. }
  15454. function stopProfilerTimerIfRunning(fiber) {
  15455. profilerStartTime = -1;
  15456. }
  15457. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  15458. if (profilerStartTime >= 0) {
  15459. var elapsedTime = now$1() - profilerStartTime;
  15460. fiber.actualDuration += elapsedTime;
  15461. if (overrideBaseTime) {
  15462. fiber.selfBaseDuration = elapsedTime;
  15463. }
  15464. profilerStartTime = -1;
  15465. }
  15466. }
  15467. function recordLayoutEffectDuration(fiber) {
  15468. if (layoutEffectStartTime >= 0) {
  15469. var elapsedTime = now$1() - layoutEffectStartTime;
  15470. layoutEffectStartTime = -1; // Store duration on the next nearest Profiler ancestor
  15471. // Or the root (for the DevTools Profiler to read)
  15472. var parentFiber = fiber.return;
  15473. while (parentFiber !== null) {
  15474. switch (parentFiber.tag) {
  15475. case HostRoot:
  15476. var root = parentFiber.stateNode;
  15477. root.effectDuration += elapsedTime;
  15478. return;
  15479. case Profiler:
  15480. var parentStateNode = parentFiber.stateNode;
  15481. parentStateNode.effectDuration += elapsedTime;
  15482. return;
  15483. }
  15484. parentFiber = parentFiber.return;
  15485. }
  15486. }
  15487. }
  15488. function recordPassiveEffectDuration(fiber) {
  15489. if (passiveEffectStartTime >= 0) {
  15490. var elapsedTime = now$1() - passiveEffectStartTime;
  15491. passiveEffectStartTime = -1; // Store duration on the next nearest Profiler ancestor
  15492. // Or the root (for the DevTools Profiler to read)
  15493. var parentFiber = fiber.return;
  15494. while (parentFiber !== null) {
  15495. switch (parentFiber.tag) {
  15496. case HostRoot:
  15497. var root = parentFiber.stateNode;
  15498. if (root !== null) {
  15499. root.passiveEffectDuration += elapsedTime;
  15500. }
  15501. return;
  15502. case Profiler:
  15503. var parentStateNode = parentFiber.stateNode;
  15504. if (parentStateNode !== null) {
  15505. // Detached fibers have their state node cleared out.
  15506. // In this case, the return pointer is also cleared out,
  15507. // so we won't be able to report the time spent in this Profiler's subtree.
  15508. parentStateNode.passiveEffectDuration += elapsedTime;
  15509. }
  15510. return;
  15511. }
  15512. parentFiber = parentFiber.return;
  15513. }
  15514. }
  15515. }
  15516. function startLayoutEffectTimer() {
  15517. layoutEffectStartTime = now$1();
  15518. }
  15519. function startPassiveEffectTimer() {
  15520. passiveEffectStartTime = now$1();
  15521. }
  15522. function transferActualDuration(fiber) {
  15523. // Transfer time spent rendering these children so we don't lose it
  15524. // after we rerender. This is used as a helper in special cases
  15525. // where we should count the work of multiple passes.
  15526. var child = fiber.child;
  15527. while (child) {
  15528. fiber.actualDuration += child.actualDuration;
  15529. child = child.sibling;
  15530. }
  15531. }
  15532. function createCapturedValueAtFiber(value, source) {
  15533. // If the value is an error, call this function immediately after it is thrown
  15534. // so the stack is accurate.
  15535. return {
  15536. value: value,
  15537. source: source,
  15538. stack: getStackByFiberInDevAndProd(source),
  15539. digest: null
  15540. };
  15541. }
  15542. function createCapturedValue(value, digest, stack) {
  15543. return {
  15544. value: value,
  15545. source: null,
  15546. stack: stack != null ? stack : null,
  15547. digest: digest != null ? digest : null
  15548. };
  15549. }
  15550. // This module is forked in different environments.
  15551. // By default, return `true` to log errors to the console.
  15552. // Forks can return `false` if this isn't desirable.
  15553. function showErrorDialog(boundary, errorInfo) {
  15554. return true;
  15555. }
  15556. function logCapturedError(boundary, errorInfo) {
  15557. try {
  15558. var logError = showErrorDialog(boundary, errorInfo); // Allow injected showErrorDialog() to prevent default console.error logging.
  15559. // This enables renderers like ReactNative to better manage redbox behavior.
  15560. if (logError === false) {
  15561. return;
  15562. }
  15563. var error = errorInfo.value;
  15564. if (true) {
  15565. var source = errorInfo.source;
  15566. var stack = errorInfo.stack;
  15567. var componentStack = stack !== null ? stack : ''; // Browsers support silencing uncaught errors by calling
  15568. // `preventDefault()` in window `error` handler.
  15569. // We record this information as an expando on the error.
  15570. if (error != null && error._suppressLogging) {
  15571. if (boundary.tag === ClassComponent) {
  15572. // The error is recoverable and was silenced.
  15573. // Ignore it and don't print the stack addendum.
  15574. // This is handy for testing error boundaries without noise.
  15575. return;
  15576. } // The error is fatal. Since the silencing might have
  15577. // been accidental, we'll surface it anyway.
  15578. // However, the browser would have silenced the original error
  15579. // so we'll print it first, and then print the stack addendum.
  15580. console['error'](error); // Don't transform to our wrapper
  15581. // For a more detailed description of this block, see:
  15582. // https://github.com/facebook/react/pull/13384
  15583. }
  15584. var componentName = source ? getComponentNameFromFiber(source) : null;
  15585. var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
  15586. var errorBoundaryMessage;
  15587. if (boundary.tag === HostRoot) {
  15588. errorBoundaryMessage = 'Consider adding an error boundary to your tree to customize error handling behavior.\n' + 'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.';
  15589. } else {
  15590. var errorBoundaryName = getComponentNameFromFiber(boundary) || 'Anonymous';
  15591. errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
  15592. }
  15593. var combinedMessage = componentNameMessage + "\n" + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  15594. // We don't include the original error message and JS stack because the browser
  15595. // has already printed it. Even if the application swallows the error, it is still
  15596. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  15597. console['error'](combinedMessage); // Don't transform to our wrapper
  15598. } else {
  15599. // In production, we print the error directly.
  15600. // This will include the message, the JS stack, and anything the browser wants to show.
  15601. // We pass the error object instead of custom message so that the browser displays the error natively.
  15602. console['error'](error); // Don't transform to our wrapper
  15603. }
  15604. } catch (e) {
  15605. // This method must not throw, or React internal state will get messed up.
  15606. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  15607. // we want to report this error outside of the normal stack as a last resort.
  15608. // https://github.com/facebook/react/issues/13188
  15609. setTimeout(function () {
  15610. throw e;
  15611. });
  15612. }
  15613. }
  15614. var PossiblyWeakMap$1 = typeof WeakMap === 'function' ? WeakMap : Map;
  15615. function createRootErrorUpdate(fiber, errorInfo, lane) {
  15616. var update = createUpdate(NoTimestamp, lane); // Unmount the root by rendering null.
  15617. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  15618. // being called "element".
  15619. update.payload = {
  15620. element: null
  15621. };
  15622. var error = errorInfo.value;
  15623. update.callback = function () {
  15624. onUncaughtError(error);
  15625. logCapturedError(fiber, errorInfo);
  15626. };
  15627. return update;
  15628. }
  15629. function createClassErrorUpdate(fiber, errorInfo, lane) {
  15630. var update = createUpdate(NoTimestamp, lane);
  15631. update.tag = CaptureUpdate;
  15632. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  15633. if (typeof getDerivedStateFromError === 'function') {
  15634. var error$1 = errorInfo.value;
  15635. update.payload = function () {
  15636. return getDerivedStateFromError(error$1);
  15637. };
  15638. update.callback = function () {
  15639. {
  15640. markFailedErrorBoundaryForHotReloading(fiber);
  15641. }
  15642. logCapturedError(fiber, errorInfo);
  15643. };
  15644. }
  15645. var inst = fiber.stateNode;
  15646. if (inst !== null && typeof inst.componentDidCatch === 'function') {
  15647. update.callback = function callback() {
  15648. {
  15649. markFailedErrorBoundaryForHotReloading(fiber);
  15650. }
  15651. logCapturedError(fiber, errorInfo);
  15652. if (typeof getDerivedStateFromError !== 'function') {
  15653. // To preserve the preexisting retry behavior of error boundaries,
  15654. // we keep track of which ones already failed during this batch.
  15655. // This gets reset before we yield back to the browser.
  15656. // TODO: Warn in strict mode if getDerivedStateFromError is
  15657. // not defined.
  15658. markLegacyErrorBoundaryAsFailed(this);
  15659. }
  15660. var error$1 = errorInfo.value;
  15661. var stack = errorInfo.stack;
  15662. this.componentDidCatch(error$1, {
  15663. componentStack: stack !== null ? stack : ''
  15664. });
  15665. {
  15666. if (typeof getDerivedStateFromError !== 'function') {
  15667. // If componentDidCatch is the only error boundary method defined,
  15668. // then it needs to call setState to recover from errors.
  15669. // If no state update is scheduled then the boundary will swallow the error.
  15670. if (!includesSomeLane(fiber.lanes, SyncLane)) {
  15671. error('%s: Error boundaries should implement getDerivedStateFromError(). ' + 'In that method, return a state update to display an error message or fallback UI.', getComponentNameFromFiber(fiber) || 'Unknown');
  15672. }
  15673. }
  15674. }
  15675. };
  15676. }
  15677. return update;
  15678. }
  15679. function attachPingListener(root, wakeable, lanes) {
  15680. // Attach a ping listener
  15681. //
  15682. // The data might resolve before we have a chance to commit the fallback. Or,
  15683. // in the case of a refresh, we'll never commit a fallback. So we need to
  15684. // attach a listener now. When it resolves ("pings"), we can decide whether to
  15685. // try rendering the tree again.
  15686. //
  15687. // Only attach a listener if one does not already exist for the lanes
  15688. // we're currently rendering (which acts like a "thread ID" here).
  15689. //
  15690. // We only need to do this in concurrent mode. Legacy Suspense always
  15691. // commits fallbacks synchronously, so there are no pings.
  15692. var pingCache = root.pingCache;
  15693. var threadIDs;
  15694. if (pingCache === null) {
  15695. pingCache = root.pingCache = new PossiblyWeakMap$1();
  15696. threadIDs = new Set();
  15697. pingCache.set(wakeable, threadIDs);
  15698. } else {
  15699. threadIDs = pingCache.get(wakeable);
  15700. if (threadIDs === undefined) {
  15701. threadIDs = new Set();
  15702. pingCache.set(wakeable, threadIDs);
  15703. }
  15704. }
  15705. if (!threadIDs.has(lanes)) {
  15706. // Memoize using the thread ID to prevent redundant listeners.
  15707. threadIDs.add(lanes);
  15708. var ping = pingSuspendedRoot.bind(null, root, wakeable, lanes);
  15709. {
  15710. if (isDevToolsPresent) {
  15711. // If we have pending work still, restore the original updaters
  15712. restorePendingUpdaters(root, lanes);
  15713. }
  15714. }
  15715. wakeable.then(ping, ping);
  15716. }
  15717. }
  15718. function attachRetryListener(suspenseBoundary, root, wakeable, lanes) {
  15719. // Retry listener
  15720. //
  15721. // If the fallback does commit, we need to attach a different type of
  15722. // listener. This one schedules an update on the Suspense boundary to turn
  15723. // the fallback state off.
  15724. //
  15725. // Stash the wakeable on the boundary fiber so we can access it in the
  15726. // commit phase.
  15727. //
  15728. // When the wakeable resolves, we'll attempt to render the boundary
  15729. // again ("retry").
  15730. var wakeables = suspenseBoundary.updateQueue;
  15731. if (wakeables === null) {
  15732. var updateQueue = new Set();
  15733. updateQueue.add(wakeable);
  15734. suspenseBoundary.updateQueue = updateQueue;
  15735. } else {
  15736. wakeables.add(wakeable);
  15737. }
  15738. }
  15739. function resetSuspendedComponent(sourceFiber, rootRenderLanes) {
  15740. // A legacy mode Suspense quirk, only relevant to hook components.
  15741. var tag = sourceFiber.tag;
  15742. if ((sourceFiber.mode & ConcurrentMode) === NoMode && (tag === FunctionComponent || tag === ForwardRef || tag === SimpleMemoComponent)) {
  15743. var currentSource = sourceFiber.alternate;
  15744. if (currentSource) {
  15745. sourceFiber.updateQueue = currentSource.updateQueue;
  15746. sourceFiber.memoizedState = currentSource.memoizedState;
  15747. sourceFiber.lanes = currentSource.lanes;
  15748. } else {
  15749. sourceFiber.updateQueue = null;
  15750. sourceFiber.memoizedState = null;
  15751. }
  15752. }
  15753. }
  15754. function getNearestSuspenseBoundaryToCapture(returnFiber) {
  15755. var node = returnFiber;
  15756. do {
  15757. if (node.tag === SuspenseComponent && shouldCaptureSuspense(node)) {
  15758. return node;
  15759. } // This boundary already captured during this render. Continue to the next
  15760. // boundary.
  15761. node = node.return;
  15762. } while (node !== null);
  15763. return null;
  15764. }
  15765. function markSuspenseBoundaryShouldCapture(suspenseBoundary, returnFiber, sourceFiber, root, rootRenderLanes) {
  15766. // This marks a Suspense boundary so that when we're unwinding the stack,
  15767. // it captures the suspended "exception" and does a second (fallback) pass.
  15768. if ((suspenseBoundary.mode & ConcurrentMode) === NoMode) {
  15769. // Legacy Mode Suspense
  15770. //
  15771. // If the boundary is in legacy mode, we should *not*
  15772. // suspend the commit. Pretend as if the suspended component rendered
  15773. // null and keep rendering. When the Suspense boundary completes,
  15774. // we'll do a second pass to render the fallback.
  15775. if (suspenseBoundary === returnFiber) {
  15776. // Special case where we suspended while reconciling the children of
  15777. // a Suspense boundary's inner Offscreen wrapper fiber. This happens
  15778. // when a React.lazy component is a direct child of a
  15779. // Suspense boundary.
  15780. //
  15781. // Suspense boundaries are implemented as multiple fibers, but they
  15782. // are a single conceptual unit. The legacy mode behavior where we
  15783. // pretend the suspended fiber committed as `null` won't work,
  15784. // because in this case the "suspended" fiber is the inner
  15785. // Offscreen wrapper.
  15786. //
  15787. // Because the contents of the boundary haven't started rendering
  15788. // yet (i.e. nothing in the tree has partially rendered) we can
  15789. // switch to the regular, concurrent mode behavior: mark the
  15790. // boundary with ShouldCapture and enter the unwind phase.
  15791. suspenseBoundary.flags |= ShouldCapture;
  15792. } else {
  15793. suspenseBoundary.flags |= DidCapture;
  15794. sourceFiber.flags |= ForceUpdateForLegacySuspense; // We're going to commit this fiber even though it didn't complete.
  15795. // But we shouldn't call any lifecycle methods or callbacks. Remove
  15796. // all lifecycle effect tags.
  15797. sourceFiber.flags &= ~(LifecycleEffectMask | Incomplete);
  15798. if (sourceFiber.tag === ClassComponent) {
  15799. var currentSourceFiber = sourceFiber.alternate;
  15800. if (currentSourceFiber === null) {
  15801. // This is a new mount. Change the tag so it's not mistaken for a
  15802. // completed class component. For example, we should not call
  15803. // componentWillUnmount if it is deleted.
  15804. sourceFiber.tag = IncompleteClassComponent;
  15805. } else {
  15806. // When we try rendering again, we should not reuse the current fiber,
  15807. // since it's known to be in an inconsistent state. Use a force update to
  15808. // prevent a bail out.
  15809. var update = createUpdate(NoTimestamp, SyncLane);
  15810. update.tag = ForceUpdate;
  15811. enqueueUpdate(sourceFiber, update, SyncLane);
  15812. }
  15813. } // The source fiber did not complete. Mark it with Sync priority to
  15814. // indicate that it still has pending work.
  15815. sourceFiber.lanes = mergeLanes(sourceFiber.lanes, SyncLane);
  15816. }
  15817. return suspenseBoundary;
  15818. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  15819. // with the normal suspend path.
  15820. //
  15821. // After this we'll use a set of heuristics to determine whether this
  15822. // render pass will run to completion or restart or "suspend" the commit.
  15823. // The actual logic for this is spread out in different places.
  15824. //
  15825. // This first principle is that if we're going to suspend when we complete
  15826. // a root, then we should also restart if we get an update or ping that
  15827. // might unsuspend it, and vice versa. The only reason to suspend is
  15828. // because you think you might want to restart before committing. However,
  15829. // it doesn't make sense to restart only while in the period we're suspended.
  15830. //
  15831. // Restarting too aggressively is also not good because it starves out any
  15832. // intermediate loading state. So we use heuristics to determine when.
  15833. // Suspense Heuristics
  15834. //
  15835. // If nothing threw a Promise or all the same fallbacks are already showing,
  15836. // then don't suspend/restart.
  15837. //
  15838. // If this is an initial render of a new tree of Suspense boundaries and
  15839. // those trigger a fallback, then don't suspend/restart. We want to ensure
  15840. // that we can show the initial loading state as quickly as possible.
  15841. //
  15842. // If we hit a "Delayed" case, such as when we'd switch from content back into
  15843. // a fallback, then we should always suspend/restart. Transitions apply
  15844. // to this case. If none is defined, JND is used instead.
  15845. //
  15846. // If we're already showing a fallback and it gets "retried", allowing us to show
  15847. // another level, but there's still an inner boundary that would show a fallback,
  15848. // then we suspend/restart for 500ms since the last time we showed a fallback
  15849. // anywhere in the tree. This effectively throttles progressive loading into a
  15850. // consistent train of commits. This also gives us an opportunity to restart to
  15851. // get to the completed state slightly earlier.
  15852. //
  15853. // If there's ambiguity due to batching it's resolved in preference of:
  15854. // 1) "delayed", 2) "initial render", 3) "retry".
  15855. //
  15856. // We want to ensure that a "busy" state doesn't get force committed. We want to
  15857. // ensure that new initial loading states can commit as soon as possible.
  15858. suspenseBoundary.flags |= ShouldCapture; // TODO: I think we can remove this, since we now use `DidCapture` in
  15859. // the begin phase to prevent an early bailout.
  15860. suspenseBoundary.lanes = rootRenderLanes;
  15861. return suspenseBoundary;
  15862. }
  15863. function throwException(root, returnFiber, sourceFiber, value, rootRenderLanes) {
  15864. // The source fiber did not complete.
  15865. sourceFiber.flags |= Incomplete;
  15866. {
  15867. if (isDevToolsPresent) {
  15868. // If we have pending work still, restore the original updaters
  15869. restorePendingUpdaters(root, rootRenderLanes);
  15870. }
  15871. }
  15872. if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
  15873. // This is a wakeable. The component suspended.
  15874. var wakeable = value;
  15875. resetSuspendedComponent(sourceFiber);
  15876. {
  15877. if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
  15878. markDidThrowWhileHydratingDEV();
  15879. }
  15880. }
  15881. var suspenseBoundary = getNearestSuspenseBoundaryToCapture(returnFiber);
  15882. if (suspenseBoundary !== null) {
  15883. suspenseBoundary.flags &= ~ForceClientRender;
  15884. markSuspenseBoundaryShouldCapture(suspenseBoundary, returnFiber, sourceFiber, root, rootRenderLanes); // We only attach ping listeners in concurrent mode. Legacy Suspense always
  15885. // commits fallbacks synchronously, so there are no pings.
  15886. if (suspenseBoundary.mode & ConcurrentMode) {
  15887. attachPingListener(root, wakeable, rootRenderLanes);
  15888. }
  15889. attachRetryListener(suspenseBoundary, root, wakeable);
  15890. return;
  15891. } else {
  15892. // No boundary was found. Unless this is a sync update, this is OK.
  15893. // We can suspend and wait for more data to arrive.
  15894. if (!includesSyncLane(rootRenderLanes)) {
  15895. // This is not a sync update. Suspend. Since we're not activating a
  15896. // Suspense boundary, this will unwind all the way to the root without
  15897. // performing a second pass to render a fallback. (This is arguably how
  15898. // refresh transitions should work, too, since we're not going to commit
  15899. // the fallbacks anyway.)
  15900. //
  15901. // This case also applies to initial hydration.
  15902. attachPingListener(root, wakeable, rootRenderLanes);
  15903. renderDidSuspendDelayIfPossible();
  15904. return;
  15905. } // This is a sync/discrete update. We treat this case like an error
  15906. // because discrete renders are expected to produce a complete tree
  15907. // synchronously to maintain consistency with external state.
  15908. var uncaughtSuspenseError = new Error('A component suspended while responding to synchronous input. This ' + 'will cause the UI to be replaced with a loading indicator. To ' + 'fix, updates that suspend should be wrapped ' + 'with startTransition.'); // If we're outside a transition, fall through to the regular error path.
  15909. // The error will be caught by the nearest suspense boundary.
  15910. value = uncaughtSuspenseError;
  15911. }
  15912. } else {
  15913. // This is a regular error, not a Suspense wakeable.
  15914. if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
  15915. markDidThrowWhileHydratingDEV();
  15916. var _suspenseBoundary = getNearestSuspenseBoundaryToCapture(returnFiber); // If the error was thrown during hydration, we may be able to recover by
  15917. // discarding the dehydrated content and switching to a client render.
  15918. // Instead of surfacing the error, find the nearest Suspense boundary
  15919. // and render it again without hydration.
  15920. if (_suspenseBoundary !== null) {
  15921. if ((_suspenseBoundary.flags & ShouldCapture) === NoFlags) {
  15922. // Set a flag to indicate that we should try rendering the normal
  15923. // children again, not the fallback.
  15924. _suspenseBoundary.flags |= ForceClientRender;
  15925. }
  15926. markSuspenseBoundaryShouldCapture(_suspenseBoundary, returnFiber, sourceFiber, root, rootRenderLanes); // Even though the user may not be affected by this error, we should
  15927. // still log it so it can be fixed.
  15928. queueHydrationError(createCapturedValueAtFiber(value, sourceFiber));
  15929. return;
  15930. }
  15931. }
  15932. }
  15933. value = createCapturedValueAtFiber(value, sourceFiber);
  15934. renderDidError(value); // We didn't find a boundary that could handle this type of exception. Start
  15935. // over and traverse parent path again, this time treating the exception
  15936. // as an error.
  15937. var workInProgress = returnFiber;
  15938. do {
  15939. switch (workInProgress.tag) {
  15940. case HostRoot:
  15941. {
  15942. var _errorInfo = value;
  15943. workInProgress.flags |= ShouldCapture;
  15944. var lane = pickArbitraryLane(rootRenderLanes);
  15945. workInProgress.lanes = mergeLanes(workInProgress.lanes, lane);
  15946. var update = createRootErrorUpdate(workInProgress, _errorInfo, lane);
  15947. enqueueCapturedUpdate(workInProgress, update);
  15948. return;
  15949. }
  15950. case ClassComponent:
  15951. // Capture and retry
  15952. var errorInfo = value;
  15953. var ctor = workInProgress.type;
  15954. var instance = workInProgress.stateNode;
  15955. if ((workInProgress.flags & DidCapture) === NoFlags && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
  15956. workInProgress.flags |= ShouldCapture;
  15957. var _lane = pickArbitraryLane(rootRenderLanes);
  15958. workInProgress.lanes = mergeLanes(workInProgress.lanes, _lane); // Schedule the error boundary to re-render using updated state
  15959. var _update = createClassErrorUpdate(workInProgress, errorInfo, _lane);
  15960. enqueueCapturedUpdate(workInProgress, _update);
  15961. return;
  15962. }
  15963. break;
  15964. }
  15965. workInProgress = workInProgress.return;
  15966. } while (workInProgress !== null);
  15967. }
  15968. function getSuspendedCache() {
  15969. {
  15970. return null;
  15971. } // This function is called when a Suspense boundary suspends. It returns the
  15972. }
  15973. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  15974. var didReceiveUpdate = false;
  15975. var didWarnAboutBadClass;
  15976. var didWarnAboutModulePatternComponent;
  15977. var didWarnAboutContextTypeOnFunctionComponent;
  15978. var didWarnAboutGetDerivedStateOnFunctionComponent;
  15979. var didWarnAboutFunctionRefs;
  15980. var didWarnAboutReassigningProps;
  15981. var didWarnAboutRevealOrder;
  15982. var didWarnAboutTailOptions;
  15983. {
  15984. didWarnAboutBadClass = {};
  15985. didWarnAboutModulePatternComponent = {};
  15986. didWarnAboutContextTypeOnFunctionComponent = {};
  15987. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  15988. didWarnAboutFunctionRefs = {};
  15989. didWarnAboutReassigningProps = false;
  15990. didWarnAboutRevealOrder = {};
  15991. didWarnAboutTailOptions = {};
  15992. }
  15993. function reconcileChildren(current, workInProgress, nextChildren, renderLanes) {
  15994. if (current === null) {
  15995. // If this is a fresh new component that hasn't been rendered yet, we
  15996. // won't update its child set by applying minimal side-effects. Instead,
  15997. // we will add them all to the child before it gets rendered. That means
  15998. // we can optimize this reconciliation pass by not tracking side-effects.
  15999. workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderLanes);
  16000. } else {
  16001. // If the current child is the same as the work in progress, it means that
  16002. // we haven't yet started any work on these children. Therefore, we use
  16003. // the clone algorithm to create a copy of all the current children.
  16004. // If we had any progressed work already, that is invalid at this point so
  16005. // let's throw it out.
  16006. workInProgress.child = reconcileChildFibers(workInProgress, current.child, nextChildren, renderLanes);
  16007. }
  16008. }
  16009. function forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderLanes) {
  16010. // This function is fork of reconcileChildren. It's used in cases where we
  16011. // want to reconcile without matching against the existing set. This has the
  16012. // effect of all current children being unmounted; even if the type and key
  16013. // are the same, the old child is unmounted and a new child is created.
  16014. //
  16015. // To do this, we're going to go through the reconcile algorithm twice. In
  16016. // the first pass, we schedule a deletion for all the current children by
  16017. // passing null.
  16018. workInProgress.child = reconcileChildFibers(workInProgress, current.child, null, renderLanes); // In the second pass, we mount the new children. The trick here is that we
  16019. // pass null in place of where we usually pass the current child set. This has
  16020. // the effect of remounting all children regardless of whether their
  16021. // identities match.
  16022. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderLanes);
  16023. }
  16024. function updateForwardRef(current, workInProgress, Component, nextProps, renderLanes) {
  16025. // TODO: current can be non-null here even if the component
  16026. // hasn't yet mounted. This happens after the first render suspends.
  16027. // We'll need to figure out if this is fine or can cause issues.
  16028. {
  16029. if (workInProgress.type !== workInProgress.elementType) {
  16030. // Lazy component props can't be validated in createElement
  16031. // because they're only guaranteed to be resolved here.
  16032. var innerPropTypes = Component.propTypes;
  16033. if (innerPropTypes) {
  16034. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  16035. 'prop', getComponentNameFromType(Component));
  16036. }
  16037. }
  16038. }
  16039. var render = Component.render;
  16040. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  16041. var nextChildren;
  16042. var hasId;
  16043. prepareToReadContext(workInProgress, renderLanes);
  16044. {
  16045. markComponentRenderStarted(workInProgress);
  16046. }
  16047. {
  16048. ReactCurrentOwner$1.current = workInProgress;
  16049. setIsRendering(true);
  16050. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderLanes);
  16051. hasId = checkDidRenderIdHook();
  16052. if ( workInProgress.mode & StrictLegacyMode) {
  16053. setIsStrictModeForDevtools(true);
  16054. try {
  16055. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderLanes);
  16056. hasId = checkDidRenderIdHook();
  16057. } finally {
  16058. setIsStrictModeForDevtools(false);
  16059. }
  16060. }
  16061. setIsRendering(false);
  16062. }
  16063. {
  16064. markComponentRenderStopped();
  16065. }
  16066. if (current !== null && !didReceiveUpdate) {
  16067. bailoutHooks(current, workInProgress, renderLanes);
  16068. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  16069. }
  16070. if (getIsHydrating() && hasId) {
  16071. pushMaterializedTreeId(workInProgress);
  16072. } // React DevTools reads this flag.
  16073. workInProgress.flags |= PerformedWork;
  16074. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16075. return workInProgress.child;
  16076. }
  16077. function updateMemoComponent(current, workInProgress, Component, nextProps, renderLanes) {
  16078. if (current === null) {
  16079. var type = Component.type;
  16080. if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  16081. Component.defaultProps === undefined) {
  16082. var resolvedType = type;
  16083. {
  16084. resolvedType = resolveFunctionForHotReloading(type);
  16085. } // If this is a plain function component without default props,
  16086. // and with only the default shallow comparison, we upgrade it
  16087. // to a SimpleMemoComponent to allow fast path updates.
  16088. workInProgress.tag = SimpleMemoComponent;
  16089. workInProgress.type = resolvedType;
  16090. {
  16091. validateFunctionComponentInDev(workInProgress, type);
  16092. }
  16093. return updateSimpleMemoComponent(current, workInProgress, resolvedType, nextProps, renderLanes);
  16094. }
  16095. {
  16096. var innerPropTypes = type.propTypes;
  16097. if (innerPropTypes) {
  16098. // Inner memo component props aren't currently validated in createElement.
  16099. // We could move it there, but we'd still need this for lazy code path.
  16100. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  16101. 'prop', getComponentNameFromType(type));
  16102. }
  16103. }
  16104. var child = createFiberFromTypeAndProps(Component.type, null, nextProps, workInProgress, workInProgress.mode, renderLanes);
  16105. child.ref = workInProgress.ref;
  16106. child.return = workInProgress;
  16107. workInProgress.child = child;
  16108. return child;
  16109. }
  16110. {
  16111. var _type = Component.type;
  16112. var _innerPropTypes = _type.propTypes;
  16113. if (_innerPropTypes) {
  16114. // Inner memo component props aren't currently validated in createElement.
  16115. // We could move it there, but we'd still need this for lazy code path.
  16116. checkPropTypes(_innerPropTypes, nextProps, // Resolved props
  16117. 'prop', getComponentNameFromType(_type));
  16118. }
  16119. }
  16120. var currentChild = current.child; // This is always exactly one child
  16121. var hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(current, renderLanes);
  16122. if (!hasScheduledUpdateOrContext) {
  16123. // This will be the props with resolved defaultProps,
  16124. // unlike current.memoizedProps which will be the unresolved ones.
  16125. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  16126. var compare = Component.compare;
  16127. compare = compare !== null ? compare : shallowEqual;
  16128. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  16129. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  16130. }
  16131. } // React DevTools reads this flag.
  16132. workInProgress.flags |= PerformedWork;
  16133. var newChild = createWorkInProgress(currentChild, nextProps);
  16134. newChild.ref = workInProgress.ref;
  16135. newChild.return = workInProgress;
  16136. workInProgress.child = newChild;
  16137. return newChild;
  16138. }
  16139. function updateSimpleMemoComponent(current, workInProgress, Component, nextProps, renderLanes) {
  16140. // TODO: current can be non-null here even if the component
  16141. // hasn't yet mounted. This happens when the inner render suspends.
  16142. // We'll need to figure out if this is fine or can cause issues.
  16143. {
  16144. if (workInProgress.type !== workInProgress.elementType) {
  16145. // Lazy component props can't be validated in createElement
  16146. // because they're only guaranteed to be resolved here.
  16147. var outerMemoType = workInProgress.elementType;
  16148. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  16149. // We warn when you define propTypes on lazy()
  16150. // so let's just skip over it to find memo() outer wrapper.
  16151. // Inner props for memo are validated later.
  16152. var lazyComponent = outerMemoType;
  16153. var payload = lazyComponent._payload;
  16154. var init = lazyComponent._init;
  16155. try {
  16156. outerMemoType = init(payload);
  16157. } catch (x) {
  16158. outerMemoType = null;
  16159. } // Inner propTypes will be validated in the function component path.
  16160. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  16161. if (outerPropTypes) {
  16162. checkPropTypes(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  16163. 'prop', getComponentNameFromType(outerMemoType));
  16164. }
  16165. }
  16166. }
  16167. }
  16168. if (current !== null) {
  16169. var prevProps = current.memoizedProps;
  16170. if (shallowEqual(prevProps, nextProps) && current.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload.
  16171. workInProgress.type === current.type )) {
  16172. didReceiveUpdate = false; // The props are shallowly equal. Reuse the previous props object, like we
  16173. // would during a normal fiber bailout.
  16174. //
  16175. // We don't have strong guarantees that the props object is referentially
  16176. // equal during updates where we can't bail out anyway — like if the props
  16177. // are shallowly equal, but there's a local state or context update in the
  16178. // same batch.
  16179. //
  16180. // However, as a principle, we should aim to make the behavior consistent
  16181. // across different ways of memoizing a component. For example, React.memo
  16182. // has a different internal Fiber layout if you pass a normal function
  16183. // component (SimpleMemoComponent) versus if you pass a different type
  16184. // like forwardRef (MemoComponent). But this is an implementation detail.
  16185. // Wrapping a component in forwardRef (or React.lazy, etc) shouldn't
  16186. // affect whether the props object is reused during a bailout.
  16187. workInProgress.pendingProps = nextProps = prevProps;
  16188. if (!checkScheduledUpdateOrContext(current, renderLanes)) {
  16189. // The pending lanes were cleared at the beginning of beginWork. We're
  16190. // about to bail out, but there might be other lanes that weren't
  16191. // included in the current render. Usually, the priority level of the
  16192. // remaining updates is accumulated during the evaluation of the
  16193. // component (i.e. when processing the update queue). But since since
  16194. // we're bailing out early *without* evaluating the component, we need
  16195. // to account for it here, too. Reset to the value of the current fiber.
  16196. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  16197. // because a MemoComponent fiber does not have hooks or an update queue;
  16198. // rather, it wraps around an inner component, which may or may not
  16199. // contains hooks.
  16200. // TODO: Move the reset at in beginWork out of the common path so that
  16201. // this is no longer necessary.
  16202. workInProgress.lanes = current.lanes;
  16203. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  16204. } else if ((current.flags & ForceUpdateForLegacySuspense) !== NoFlags) {
  16205. // This is a special case that only exists for legacy mode.
  16206. // See https://github.com/facebook/react/pull/19216.
  16207. didReceiveUpdate = true;
  16208. }
  16209. }
  16210. }
  16211. return updateFunctionComponent(current, workInProgress, Component, nextProps, renderLanes);
  16212. }
  16213. function updateOffscreenComponent(current, workInProgress, renderLanes) {
  16214. var nextProps = workInProgress.pendingProps;
  16215. var nextChildren = nextProps.children;
  16216. var prevState = current !== null ? current.memoizedState : null;
  16217. if (nextProps.mode === 'hidden' || enableLegacyHidden ) {
  16218. // Rendering a hidden tree.
  16219. if ((workInProgress.mode & ConcurrentMode) === NoMode) {
  16220. // In legacy sync mode, don't defer the subtree. Render it now.
  16221. // TODO: Consider how Offscreen should work with transitions in the future
  16222. var nextState = {
  16223. baseLanes: NoLanes,
  16224. cachePool: null,
  16225. transitions: null
  16226. };
  16227. workInProgress.memoizedState = nextState;
  16228. pushRenderLanes(workInProgress, renderLanes);
  16229. } else if (!includesSomeLane(renderLanes, OffscreenLane)) {
  16230. var spawnedCachePool = null; // We're hidden, and we're not rendering at Offscreen. We will bail out
  16231. // and resume this tree later.
  16232. var nextBaseLanes;
  16233. if (prevState !== null) {
  16234. var prevBaseLanes = prevState.baseLanes;
  16235. nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
  16236. } else {
  16237. nextBaseLanes = renderLanes;
  16238. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  16239. workInProgress.lanes = workInProgress.childLanes = laneToLanes(OffscreenLane);
  16240. var _nextState = {
  16241. baseLanes: nextBaseLanes,
  16242. cachePool: spawnedCachePool,
  16243. transitions: null
  16244. };
  16245. workInProgress.memoizedState = _nextState;
  16246. workInProgress.updateQueue = null;
  16247. // to avoid a push/pop misalignment.
  16248. pushRenderLanes(workInProgress, nextBaseLanes);
  16249. return null;
  16250. } else {
  16251. // This is the second render. The surrounding visible content has already
  16252. // committed. Now we resume rendering the hidden tree.
  16253. // Rendering at offscreen, so we can clear the base lanes.
  16254. var _nextState2 = {
  16255. baseLanes: NoLanes,
  16256. cachePool: null,
  16257. transitions: null
  16258. };
  16259. workInProgress.memoizedState = _nextState2; // Push the lanes that were skipped when we bailed out.
  16260. var subtreeRenderLanes = prevState !== null ? prevState.baseLanes : renderLanes;
  16261. pushRenderLanes(workInProgress, subtreeRenderLanes);
  16262. }
  16263. } else {
  16264. // Rendering a visible tree.
  16265. var _subtreeRenderLanes;
  16266. if (prevState !== null) {
  16267. // We're going from hidden -> visible.
  16268. _subtreeRenderLanes = mergeLanes(prevState.baseLanes, renderLanes);
  16269. workInProgress.memoizedState = null;
  16270. } else {
  16271. // We weren't previously hidden, and we still aren't, so there's nothing
  16272. // special to do. Need to push to the stack regardless, though, to avoid
  16273. // a push/pop misalignment.
  16274. _subtreeRenderLanes = renderLanes;
  16275. }
  16276. pushRenderLanes(workInProgress, _subtreeRenderLanes);
  16277. }
  16278. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16279. return workInProgress.child;
  16280. } // Note: These happen to have identical begin phases, for now. We shouldn't hold
  16281. function updateFragment(current, workInProgress, renderLanes) {
  16282. var nextChildren = workInProgress.pendingProps;
  16283. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16284. return workInProgress.child;
  16285. }
  16286. function updateMode(current, workInProgress, renderLanes) {
  16287. var nextChildren = workInProgress.pendingProps.children;
  16288. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16289. return workInProgress.child;
  16290. }
  16291. function updateProfiler(current, workInProgress, renderLanes) {
  16292. {
  16293. workInProgress.flags |= Update;
  16294. {
  16295. // Reset effect durations for the next eventual effect phase.
  16296. // These are reset during render to allow the DevTools commit hook a chance to read them,
  16297. var stateNode = workInProgress.stateNode;
  16298. stateNode.effectDuration = 0;
  16299. stateNode.passiveEffectDuration = 0;
  16300. }
  16301. }
  16302. var nextProps = workInProgress.pendingProps;
  16303. var nextChildren = nextProps.children;
  16304. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16305. return workInProgress.child;
  16306. }
  16307. function markRef(current, workInProgress) {
  16308. var ref = workInProgress.ref;
  16309. if (current === null && ref !== null || current !== null && current.ref !== ref) {
  16310. // Schedule a Ref effect
  16311. workInProgress.flags |= Ref;
  16312. {
  16313. workInProgress.flags |= RefStatic;
  16314. }
  16315. }
  16316. }
  16317. function updateFunctionComponent(current, workInProgress, Component, nextProps, renderLanes) {
  16318. {
  16319. if (workInProgress.type !== workInProgress.elementType) {
  16320. // Lazy component props can't be validated in createElement
  16321. // because they're only guaranteed to be resolved here.
  16322. var innerPropTypes = Component.propTypes;
  16323. if (innerPropTypes) {
  16324. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  16325. 'prop', getComponentNameFromType(Component));
  16326. }
  16327. }
  16328. }
  16329. var context;
  16330. {
  16331. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  16332. context = getMaskedContext(workInProgress, unmaskedContext);
  16333. }
  16334. var nextChildren;
  16335. var hasId;
  16336. prepareToReadContext(workInProgress, renderLanes);
  16337. {
  16338. markComponentRenderStarted(workInProgress);
  16339. }
  16340. {
  16341. ReactCurrentOwner$1.current = workInProgress;
  16342. setIsRendering(true);
  16343. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderLanes);
  16344. hasId = checkDidRenderIdHook();
  16345. if ( workInProgress.mode & StrictLegacyMode) {
  16346. setIsStrictModeForDevtools(true);
  16347. try {
  16348. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderLanes);
  16349. hasId = checkDidRenderIdHook();
  16350. } finally {
  16351. setIsStrictModeForDevtools(false);
  16352. }
  16353. }
  16354. setIsRendering(false);
  16355. }
  16356. {
  16357. markComponentRenderStopped();
  16358. }
  16359. if (current !== null && !didReceiveUpdate) {
  16360. bailoutHooks(current, workInProgress, renderLanes);
  16361. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  16362. }
  16363. if (getIsHydrating() && hasId) {
  16364. pushMaterializedTreeId(workInProgress);
  16365. } // React DevTools reads this flag.
  16366. workInProgress.flags |= PerformedWork;
  16367. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16368. return workInProgress.child;
  16369. }
  16370. function updateClassComponent(current, workInProgress, Component, nextProps, renderLanes) {
  16371. {
  16372. // This is used by DevTools to force a boundary to error.
  16373. switch (shouldError(workInProgress)) {
  16374. case false:
  16375. {
  16376. var _instance = workInProgress.stateNode;
  16377. var ctor = workInProgress.type; // TODO This way of resetting the error boundary state is a hack.
  16378. // Is there a better way to do this?
  16379. var tempInstance = new ctor(workInProgress.memoizedProps, _instance.context);
  16380. var state = tempInstance.state;
  16381. _instance.updater.enqueueSetState(_instance, state, null);
  16382. break;
  16383. }
  16384. case true:
  16385. {
  16386. workInProgress.flags |= DidCapture;
  16387. workInProgress.flags |= ShouldCapture; // eslint-disable-next-line react-internal/prod-error-codes
  16388. var error$1 = new Error('Simulated error coming from DevTools');
  16389. var lane = pickArbitraryLane(renderLanes);
  16390. workInProgress.lanes = mergeLanes(workInProgress.lanes, lane); // Schedule the error boundary to re-render using updated state
  16391. var update = createClassErrorUpdate(workInProgress, createCapturedValueAtFiber(error$1, workInProgress), lane);
  16392. enqueueCapturedUpdate(workInProgress, update);
  16393. break;
  16394. }
  16395. }
  16396. if (workInProgress.type !== workInProgress.elementType) {
  16397. // Lazy component props can't be validated in createElement
  16398. // because they're only guaranteed to be resolved here.
  16399. var innerPropTypes = Component.propTypes;
  16400. if (innerPropTypes) {
  16401. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  16402. 'prop', getComponentNameFromType(Component));
  16403. }
  16404. }
  16405. } // Push context providers early to prevent context stack mismatches.
  16406. // During mounting we don't know the child context yet as the instance doesn't exist.
  16407. // We will invalidate the child context in finishClassComponent() right after rendering.
  16408. var hasContext;
  16409. if (isContextProvider(Component)) {
  16410. hasContext = true;
  16411. pushContextProvider(workInProgress);
  16412. } else {
  16413. hasContext = false;
  16414. }
  16415. prepareToReadContext(workInProgress, renderLanes);
  16416. var instance = workInProgress.stateNode;
  16417. var shouldUpdate;
  16418. if (instance === null) {
  16419. resetSuspendedCurrentOnMountInLegacyMode(current, workInProgress); // In the initial pass we might need to construct the instance.
  16420. constructClassInstance(workInProgress, Component, nextProps);
  16421. mountClassInstance(workInProgress, Component, nextProps, renderLanes);
  16422. shouldUpdate = true;
  16423. } else if (current === null) {
  16424. // In a resume, we'll already have an instance we can reuse.
  16425. shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderLanes);
  16426. } else {
  16427. shouldUpdate = updateClassInstance(current, workInProgress, Component, nextProps, renderLanes);
  16428. }
  16429. var nextUnitOfWork = finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderLanes);
  16430. {
  16431. var inst = workInProgress.stateNode;
  16432. if (shouldUpdate && inst.props !== nextProps) {
  16433. if (!didWarnAboutReassigningProps) {
  16434. error('It looks like %s is reassigning its own `this.props` while rendering. ' + 'This is not supported and can lead to confusing bugs.', getComponentNameFromFiber(workInProgress) || 'a component');
  16435. }
  16436. didWarnAboutReassigningProps = true;
  16437. }
  16438. }
  16439. return nextUnitOfWork;
  16440. }
  16441. function finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderLanes) {
  16442. // Refs should update even if shouldComponentUpdate returns false
  16443. markRef(current, workInProgress);
  16444. var didCaptureError = (workInProgress.flags & DidCapture) !== NoFlags;
  16445. if (!shouldUpdate && !didCaptureError) {
  16446. // Context providers should defer to sCU for rendering
  16447. if (hasContext) {
  16448. invalidateContextProvider(workInProgress, Component, false);
  16449. }
  16450. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  16451. }
  16452. var instance = workInProgress.stateNode; // Rerender
  16453. ReactCurrentOwner$1.current = workInProgress;
  16454. var nextChildren;
  16455. if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
  16456. // If we captured an error, but getDerivedStateFromError is not defined,
  16457. // unmount all the children. componentDidCatch will schedule an update to
  16458. // re-render a fallback. This is temporary until we migrate everyone to
  16459. // the new API.
  16460. // TODO: Warn in a future release.
  16461. nextChildren = null;
  16462. {
  16463. stopProfilerTimerIfRunning();
  16464. }
  16465. } else {
  16466. {
  16467. markComponentRenderStarted(workInProgress);
  16468. }
  16469. {
  16470. setIsRendering(true);
  16471. nextChildren = instance.render();
  16472. if ( workInProgress.mode & StrictLegacyMode) {
  16473. setIsStrictModeForDevtools(true);
  16474. try {
  16475. instance.render();
  16476. } finally {
  16477. setIsStrictModeForDevtools(false);
  16478. }
  16479. }
  16480. setIsRendering(false);
  16481. }
  16482. {
  16483. markComponentRenderStopped();
  16484. }
  16485. } // React DevTools reads this flag.
  16486. workInProgress.flags |= PerformedWork;
  16487. if (current !== null && didCaptureError) {
  16488. // If we're recovering from an error, reconcile without reusing any of
  16489. // the existing children. Conceptually, the normal children and the children
  16490. // that are shown on error are two different sets, so we shouldn't reuse
  16491. // normal children even if their identities match.
  16492. forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderLanes);
  16493. } else {
  16494. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16495. } // Memoize state using the values we just used to render.
  16496. // TODO: Restructure so we never read values from the instance.
  16497. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  16498. if (hasContext) {
  16499. invalidateContextProvider(workInProgress, Component, true);
  16500. }
  16501. return workInProgress.child;
  16502. }
  16503. function pushHostRootContext(workInProgress) {
  16504. var root = workInProgress.stateNode;
  16505. if (root.pendingContext) {
  16506. pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
  16507. } else if (root.context) {
  16508. // Should always be set
  16509. pushTopLevelContextObject(workInProgress, root.context, false);
  16510. }
  16511. pushHostContainer(workInProgress, root.containerInfo);
  16512. }
  16513. function updateHostRoot(current, workInProgress, renderLanes) {
  16514. pushHostRootContext(workInProgress);
  16515. if (current === null) {
  16516. throw new Error('Should have a current fiber. This is a bug in React.');
  16517. }
  16518. var nextProps = workInProgress.pendingProps;
  16519. var prevState = workInProgress.memoizedState;
  16520. var prevChildren = prevState.element;
  16521. cloneUpdateQueue(current, workInProgress);
  16522. processUpdateQueue(workInProgress, nextProps, null, renderLanes);
  16523. var nextState = workInProgress.memoizedState;
  16524. var root = workInProgress.stateNode;
  16525. // being called "element".
  16526. var nextChildren = nextState.element;
  16527. if ( prevState.isDehydrated) {
  16528. // This is a hydration root whose shell has not yet hydrated. We should
  16529. // attempt to hydrate.
  16530. // Flip isDehydrated to false to indicate that when this render
  16531. // finishes, the root will no longer be dehydrated.
  16532. var overrideState = {
  16533. element: nextChildren,
  16534. isDehydrated: false,
  16535. cache: nextState.cache,
  16536. pendingSuspenseBoundaries: nextState.pendingSuspenseBoundaries,
  16537. transitions: nextState.transitions
  16538. };
  16539. var updateQueue = workInProgress.updateQueue; // `baseState` can always be the last state because the root doesn't
  16540. // have reducer functions so it doesn't need rebasing.
  16541. updateQueue.baseState = overrideState;
  16542. workInProgress.memoizedState = overrideState;
  16543. if (workInProgress.flags & ForceClientRender) {
  16544. // Something errored during a previous attempt to hydrate the shell, so we
  16545. // forced a client render.
  16546. var recoverableError = createCapturedValueAtFiber(new Error('There was an error while hydrating. Because the error happened outside ' + 'of a Suspense boundary, the entire root will switch to ' + 'client rendering.'), workInProgress);
  16547. return mountHostRootWithoutHydrating(current, workInProgress, nextChildren, renderLanes, recoverableError);
  16548. } else if (nextChildren !== prevChildren) {
  16549. var _recoverableError = createCapturedValueAtFiber(new Error('This root received an early update, before anything was able ' + 'hydrate. Switched the entire root to client rendering.'), workInProgress);
  16550. return mountHostRootWithoutHydrating(current, workInProgress, nextChildren, renderLanes, _recoverableError);
  16551. } else {
  16552. // The outermost shell has not hydrated yet. Start hydrating.
  16553. enterHydrationState(workInProgress);
  16554. var child = mountChildFibers(workInProgress, null, nextChildren, renderLanes);
  16555. workInProgress.child = child;
  16556. var node = child;
  16557. while (node) {
  16558. // Mark each child as hydrating. This is a fast path to know whether this
  16559. // tree is part of a hydrating tree. This is used to determine if a child
  16560. // node has fully mounted yet, and for scheduling event replaying.
  16561. // Conceptually this is similar to Placement in that a new subtree is
  16562. // inserted into the React tree here. It just happens to not need DOM
  16563. // mutations because it already exists.
  16564. node.flags = node.flags & ~Placement | Hydrating;
  16565. node = node.sibling;
  16566. }
  16567. }
  16568. } else {
  16569. // Root is not dehydrated. Either this is a client-only root, or it
  16570. // already hydrated.
  16571. resetHydrationState();
  16572. if (nextChildren === prevChildren) {
  16573. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  16574. }
  16575. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16576. }
  16577. return workInProgress.child;
  16578. }
  16579. function mountHostRootWithoutHydrating(current, workInProgress, nextChildren, renderLanes, recoverableError) {
  16580. // Revert to client rendering.
  16581. resetHydrationState();
  16582. queueHydrationError(recoverableError);
  16583. workInProgress.flags |= ForceClientRender;
  16584. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16585. return workInProgress.child;
  16586. }
  16587. function updateHostComponent(current, workInProgress, renderLanes) {
  16588. pushHostContext(workInProgress);
  16589. if (current === null) {
  16590. tryToClaimNextHydratableInstance(workInProgress);
  16591. }
  16592. var type = workInProgress.type;
  16593. var nextProps = workInProgress.pendingProps;
  16594. var prevProps = current !== null ? current.memoizedProps : null;
  16595. var nextChildren = nextProps.children;
  16596. var isDirectTextChild = shouldSetTextContent(type, nextProps);
  16597. if (isDirectTextChild) {
  16598. // We special case a direct text child of a host node. This is a common
  16599. // case. We won't handle it as a reified child. We will instead handle
  16600. // this in the host environment that also has access to this prop. That
  16601. // avoids allocating another HostText fiber and traversing it.
  16602. nextChildren = null;
  16603. } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
  16604. // If we're switching from a direct text child to a normal child, or to
  16605. // empty, we need to schedule the text content to be reset.
  16606. workInProgress.flags |= ContentReset;
  16607. }
  16608. markRef(current, workInProgress);
  16609. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  16610. return workInProgress.child;
  16611. }
  16612. function updateHostText(current, workInProgress) {
  16613. if (current === null) {
  16614. tryToClaimNextHydratableInstance(workInProgress);
  16615. } // Nothing to do here. This is terminal. We'll do the completion step
  16616. // immediately after.
  16617. return null;
  16618. }
  16619. function mountLazyComponent(_current, workInProgress, elementType, renderLanes) {
  16620. resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
  16621. var props = workInProgress.pendingProps;
  16622. var lazyComponent = elementType;
  16623. var payload = lazyComponent._payload;
  16624. var init = lazyComponent._init;
  16625. var Component = init(payload); // Store the unwrapped component in the type.
  16626. workInProgress.type = Component;
  16627. var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
  16628. var resolvedProps = resolveDefaultProps(Component, props);
  16629. var child;
  16630. switch (resolvedTag) {
  16631. case FunctionComponent:
  16632. {
  16633. {
  16634. validateFunctionComponentInDev(workInProgress, Component);
  16635. workInProgress.type = Component = resolveFunctionForHotReloading(Component);
  16636. }
  16637. child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderLanes);
  16638. return child;
  16639. }
  16640. case ClassComponent:
  16641. {
  16642. {
  16643. workInProgress.type = Component = resolveClassForHotReloading(Component);
  16644. }
  16645. child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderLanes);
  16646. return child;
  16647. }
  16648. case ForwardRef:
  16649. {
  16650. {
  16651. workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
  16652. }
  16653. child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderLanes);
  16654. return child;
  16655. }
  16656. case MemoComponent:
  16657. {
  16658. {
  16659. if (workInProgress.type !== workInProgress.elementType) {
  16660. var outerPropTypes = Component.propTypes;
  16661. if (outerPropTypes) {
  16662. checkPropTypes(outerPropTypes, resolvedProps, // Resolved for outer only
  16663. 'prop', getComponentNameFromType(Component));
  16664. }
  16665. }
  16666. }
  16667. child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  16668. renderLanes);
  16669. return child;
  16670. }
  16671. }
  16672. var hint = '';
  16673. {
  16674. if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
  16675. hint = ' Did you wrap a component in React.lazy() more than once?';
  16676. }
  16677. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  16678. // because the fact that it's a separate type of work is an
  16679. // implementation detail.
  16680. throw new Error("Element type is invalid. Received a promise that resolves to: " + Component + ". " + ("Lazy element type must resolve to a class or function." + hint));
  16681. }
  16682. function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderLanes) {
  16683. resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress); // Promote the fiber to a class and try rendering again.
  16684. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  16685. // Push context providers early to prevent context stack mismatches.
  16686. // During mounting we don't know the child context yet as the instance doesn't exist.
  16687. // We will invalidate the child context in finishClassComponent() right after rendering.
  16688. var hasContext;
  16689. if (isContextProvider(Component)) {
  16690. hasContext = true;
  16691. pushContextProvider(workInProgress);
  16692. } else {
  16693. hasContext = false;
  16694. }
  16695. prepareToReadContext(workInProgress, renderLanes);
  16696. constructClassInstance(workInProgress, Component, nextProps);
  16697. mountClassInstance(workInProgress, Component, nextProps, renderLanes);
  16698. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderLanes);
  16699. }
  16700. function mountIndeterminateComponent(_current, workInProgress, Component, renderLanes) {
  16701. resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
  16702. var props = workInProgress.pendingProps;
  16703. var context;
  16704. {
  16705. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  16706. context = getMaskedContext(workInProgress, unmaskedContext);
  16707. }
  16708. prepareToReadContext(workInProgress, renderLanes);
  16709. var value;
  16710. var hasId;
  16711. {
  16712. markComponentRenderStarted(workInProgress);
  16713. }
  16714. {
  16715. if (Component.prototype && typeof Component.prototype.render === 'function') {
  16716. var componentName = getComponentNameFromType(Component) || 'Unknown';
  16717. if (!didWarnAboutBadClass[componentName]) {
  16718. 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);
  16719. didWarnAboutBadClass[componentName] = true;
  16720. }
  16721. }
  16722. if (workInProgress.mode & StrictLegacyMode) {
  16723. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  16724. }
  16725. setIsRendering(true);
  16726. ReactCurrentOwner$1.current = workInProgress;
  16727. value = renderWithHooks(null, workInProgress, Component, props, context, renderLanes);
  16728. hasId = checkDidRenderIdHook();
  16729. setIsRendering(false);
  16730. }
  16731. {
  16732. markComponentRenderStopped();
  16733. } // React DevTools reads this flag.
  16734. workInProgress.flags |= PerformedWork;
  16735. {
  16736. // Support for module components is deprecated and is removed behind a flag.
  16737. // Whether or not it would crash later, we want to show a good message in DEV first.
  16738. if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  16739. var _componentName = getComponentNameFromType(Component) || 'Unknown';
  16740. if (!didWarnAboutModulePatternComponent[_componentName]) {
  16741. 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);
  16742. didWarnAboutModulePatternComponent[_componentName] = true;
  16743. }
  16744. }
  16745. }
  16746. if ( // Run these checks in production only if the flag is off.
  16747. // Eventually we'll delete this branch altogether.
  16748. typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  16749. {
  16750. var _componentName2 = getComponentNameFromType(Component) || 'Unknown';
  16751. if (!didWarnAboutModulePatternComponent[_componentName2]) {
  16752. 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.', _componentName2, _componentName2, _componentName2);
  16753. didWarnAboutModulePatternComponent[_componentName2] = true;
  16754. }
  16755. } // Proceed under the assumption that this is a class instance
  16756. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  16757. workInProgress.memoizedState = null;
  16758. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  16759. // During mounting we don't know the child context yet as the instance doesn't exist.
  16760. // We will invalidate the child context in finishClassComponent() right after rendering.
  16761. var hasContext = false;
  16762. if (isContextProvider(Component)) {
  16763. hasContext = true;
  16764. pushContextProvider(workInProgress);
  16765. } else {
  16766. hasContext = false;
  16767. }
  16768. workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
  16769. initializeUpdateQueue(workInProgress);
  16770. adoptClassInstance(workInProgress, value);
  16771. mountClassInstance(workInProgress, Component, props, renderLanes);
  16772. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderLanes);
  16773. } else {
  16774. // Proceed under the assumption that this is a function component
  16775. workInProgress.tag = FunctionComponent;
  16776. {
  16777. if ( workInProgress.mode & StrictLegacyMode) {
  16778. setIsStrictModeForDevtools(true);
  16779. try {
  16780. value = renderWithHooks(null, workInProgress, Component, props, context, renderLanes);
  16781. hasId = checkDidRenderIdHook();
  16782. } finally {
  16783. setIsStrictModeForDevtools(false);
  16784. }
  16785. }
  16786. }
  16787. if (getIsHydrating() && hasId) {
  16788. pushMaterializedTreeId(workInProgress);
  16789. }
  16790. reconcileChildren(null, workInProgress, value, renderLanes);
  16791. {
  16792. validateFunctionComponentInDev(workInProgress, Component);
  16793. }
  16794. return workInProgress.child;
  16795. }
  16796. }
  16797. function validateFunctionComponentInDev(workInProgress, Component) {
  16798. {
  16799. if (Component) {
  16800. if (Component.childContextTypes) {
  16801. error('%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component');
  16802. }
  16803. }
  16804. if (workInProgress.ref !== null) {
  16805. var info = '';
  16806. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  16807. if (ownerName) {
  16808. info += '\n\nCheck the render method of `' + ownerName + '`.';
  16809. }
  16810. var warningKey = ownerName || '';
  16811. var debugSource = workInProgress._debugSource;
  16812. if (debugSource) {
  16813. warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
  16814. }
  16815. if (!didWarnAboutFunctionRefs[warningKey]) {
  16816. didWarnAboutFunctionRefs[warningKey] = true;
  16817. error('Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
  16818. }
  16819. }
  16820. if (typeof Component.getDerivedStateFromProps === 'function') {
  16821. var _componentName3 = getComponentNameFromType(Component) || 'Unknown';
  16822. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3]) {
  16823. error('%s: Function components do not support getDerivedStateFromProps.', _componentName3);
  16824. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3] = true;
  16825. }
  16826. }
  16827. if (typeof Component.contextType === 'object' && Component.contextType !== null) {
  16828. var _componentName4 = getComponentNameFromType(Component) || 'Unknown';
  16829. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName4]) {
  16830. error('%s: Function components do not support contextType.', _componentName4);
  16831. didWarnAboutContextTypeOnFunctionComponent[_componentName4] = true;
  16832. }
  16833. }
  16834. }
  16835. }
  16836. var SUSPENDED_MARKER = {
  16837. dehydrated: null,
  16838. treeContext: null,
  16839. retryLane: NoLane
  16840. };
  16841. function mountSuspenseOffscreenState(renderLanes) {
  16842. return {
  16843. baseLanes: renderLanes,
  16844. cachePool: getSuspendedCache(),
  16845. transitions: null
  16846. };
  16847. }
  16848. function updateSuspenseOffscreenState(prevOffscreenState, renderLanes) {
  16849. var cachePool = null;
  16850. return {
  16851. baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes),
  16852. cachePool: cachePool,
  16853. transitions: prevOffscreenState.transitions
  16854. };
  16855. } // TODO: Probably should inline this back
  16856. function shouldRemainOnFallback(suspenseContext, current, workInProgress, renderLanes) {
  16857. // If we're already showing a fallback, there are cases where we need to
  16858. // remain on that fallback regardless of whether the content has resolved.
  16859. // For example, SuspenseList coordinates when nested content appears.
  16860. if (current !== null) {
  16861. var suspenseState = current.memoizedState;
  16862. if (suspenseState === null) {
  16863. // Currently showing content. Don't hide it, even if ForceSuspenseFallback
  16864. // is true. More precise name might be "ForceRemainSuspenseFallback".
  16865. // Note: This is a factoring smell. Can't remain on a fallback if there's
  16866. // no fallback to remain on.
  16867. return false;
  16868. }
  16869. } // Not currently showing content. Consult the Suspense context.
  16870. return hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
  16871. }
  16872. function getRemainingWorkInPrimaryTree(current, renderLanes) {
  16873. // TODO: Should not remove render lanes that were pinged during this render
  16874. return removeLanes(current.childLanes, renderLanes);
  16875. }
  16876. function updateSuspenseComponent(current, workInProgress, renderLanes) {
  16877. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  16878. {
  16879. if (shouldSuspend(workInProgress)) {
  16880. workInProgress.flags |= DidCapture;
  16881. }
  16882. }
  16883. var suspenseContext = suspenseStackCursor.current;
  16884. var showFallback = false;
  16885. var didSuspend = (workInProgress.flags & DidCapture) !== NoFlags;
  16886. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  16887. // Something in this boundary's subtree already suspended. Switch to
  16888. // rendering the fallback children.
  16889. showFallback = true;
  16890. workInProgress.flags &= ~DidCapture;
  16891. } else {
  16892. // Attempting the main content
  16893. if (current === null || current.memoizedState !== null) {
  16894. // This is a new mount or this boundary is already showing a fallback state.
  16895. // Mark this subtree context as having at least one invisible parent that could
  16896. // handle the fallback state.
  16897. // Avoided boundaries are not considered since they cannot handle preferred fallback states.
  16898. {
  16899. suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
  16900. }
  16901. }
  16902. }
  16903. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  16904. pushSuspenseContext(workInProgress, suspenseContext); // OK, the next part is confusing. We're about to reconcile the Suspense
  16905. // boundary's children. This involves some custom reconciliation logic. Two
  16906. // main reasons this is so complicated.
  16907. //
  16908. // First, Legacy Mode has different semantics for backwards compatibility. The
  16909. // primary tree will commit in an inconsistent state, so when we do the
  16910. // second pass to render the fallback, we do some exceedingly, uh, clever
  16911. // hacks to make that not totally break. Like transferring effects and
  16912. // deletions from hidden tree. In Concurrent Mode, it's much simpler,
  16913. // because we bailout on the primary tree completely and leave it in its old
  16914. // state, no effects. Same as what we do for Offscreen (except that
  16915. // Offscreen doesn't have the first render pass).
  16916. //
  16917. // Second is hydration. During hydration, the Suspense fiber has a slightly
  16918. // different layout, where the child points to a dehydrated fragment, which
  16919. // contains the DOM rendered by the server.
  16920. //
  16921. // Third, even if you set all that aside, Suspense is like error boundaries in
  16922. // that we first we try to render one tree, and if that fails, we render again
  16923. // and switch to a different tree. Like a try/catch block. So we have to track
  16924. // which branch we're currently rendering. Ideally we would model this using
  16925. // a stack.
  16926. if (current === null) {
  16927. // Initial mount
  16928. // Special path for hydration
  16929. // If we're currently hydrating, try to hydrate this boundary.
  16930. tryToClaimNextHydratableInstance(workInProgress); // This could've been a dehydrated suspense component.
  16931. var suspenseState = workInProgress.memoizedState;
  16932. if (suspenseState !== null) {
  16933. var dehydrated = suspenseState.dehydrated;
  16934. if (dehydrated !== null) {
  16935. return mountDehydratedSuspenseComponent(workInProgress, dehydrated);
  16936. }
  16937. }
  16938. var nextPrimaryChildren = nextProps.children;
  16939. var nextFallbackChildren = nextProps.fallback;
  16940. if (showFallback) {
  16941. var fallbackFragment = mountSuspenseFallbackChildren(workInProgress, nextPrimaryChildren, nextFallbackChildren, renderLanes);
  16942. var primaryChildFragment = workInProgress.child;
  16943. primaryChildFragment.memoizedState = mountSuspenseOffscreenState(renderLanes);
  16944. workInProgress.memoizedState = SUSPENDED_MARKER;
  16945. return fallbackFragment;
  16946. } else {
  16947. return mountSuspensePrimaryChildren(workInProgress, nextPrimaryChildren);
  16948. }
  16949. } else {
  16950. // This is an update.
  16951. // Special path for hydration
  16952. var prevState = current.memoizedState;
  16953. if (prevState !== null) {
  16954. var _dehydrated = prevState.dehydrated;
  16955. if (_dehydrated !== null) {
  16956. return updateDehydratedSuspenseComponent(current, workInProgress, didSuspend, nextProps, _dehydrated, prevState, renderLanes);
  16957. }
  16958. }
  16959. if (showFallback) {
  16960. var _nextFallbackChildren = nextProps.fallback;
  16961. var _nextPrimaryChildren = nextProps.children;
  16962. var fallbackChildFragment = updateSuspenseFallbackChildren(current, workInProgress, _nextPrimaryChildren, _nextFallbackChildren, renderLanes);
  16963. var _primaryChildFragment2 = workInProgress.child;
  16964. var prevOffscreenState = current.child.memoizedState;
  16965. _primaryChildFragment2.memoizedState = prevOffscreenState === null ? mountSuspenseOffscreenState(renderLanes) : updateSuspenseOffscreenState(prevOffscreenState, renderLanes);
  16966. _primaryChildFragment2.childLanes = getRemainingWorkInPrimaryTree(current, renderLanes);
  16967. workInProgress.memoizedState = SUSPENDED_MARKER;
  16968. return fallbackChildFragment;
  16969. } else {
  16970. var _nextPrimaryChildren2 = nextProps.children;
  16971. var _primaryChildFragment3 = updateSuspensePrimaryChildren(current, workInProgress, _nextPrimaryChildren2, renderLanes);
  16972. workInProgress.memoizedState = null;
  16973. return _primaryChildFragment3;
  16974. }
  16975. }
  16976. }
  16977. function mountSuspensePrimaryChildren(workInProgress, primaryChildren, renderLanes) {
  16978. var mode = workInProgress.mode;
  16979. var primaryChildProps = {
  16980. mode: 'visible',
  16981. children: primaryChildren
  16982. };
  16983. var primaryChildFragment = mountWorkInProgressOffscreenFiber(primaryChildProps, mode);
  16984. primaryChildFragment.return = workInProgress;
  16985. workInProgress.child = primaryChildFragment;
  16986. return primaryChildFragment;
  16987. }
  16988. function mountSuspenseFallbackChildren(workInProgress, primaryChildren, fallbackChildren, renderLanes) {
  16989. var mode = workInProgress.mode;
  16990. var progressedPrimaryFragment = workInProgress.child;
  16991. var primaryChildProps = {
  16992. mode: 'hidden',
  16993. children: primaryChildren
  16994. };
  16995. var primaryChildFragment;
  16996. var fallbackChildFragment;
  16997. if ((mode & ConcurrentMode) === NoMode && progressedPrimaryFragment !== null) {
  16998. // In legacy mode, we commit the primary tree as if it successfully
  16999. // completed, even though it's in an inconsistent state.
  17000. primaryChildFragment = progressedPrimaryFragment;
  17001. primaryChildFragment.childLanes = NoLanes;
  17002. primaryChildFragment.pendingProps = primaryChildProps;
  17003. if ( workInProgress.mode & ProfileMode) {
  17004. // Reset the durations from the first pass so they aren't included in the
  17005. // final amounts. This seems counterintuitive, since we're intentionally
  17006. // not measuring part of the render phase, but this makes it match what we
  17007. // do in Concurrent Mode.
  17008. primaryChildFragment.actualDuration = 0;
  17009. primaryChildFragment.actualStartTime = -1;
  17010. primaryChildFragment.selfBaseDuration = 0;
  17011. primaryChildFragment.treeBaseDuration = 0;
  17012. }
  17013. fallbackChildFragment = createFiberFromFragment(fallbackChildren, mode, renderLanes, null);
  17014. } else {
  17015. primaryChildFragment = mountWorkInProgressOffscreenFiber(primaryChildProps, mode);
  17016. fallbackChildFragment = createFiberFromFragment(fallbackChildren, mode, renderLanes, null);
  17017. }
  17018. primaryChildFragment.return = workInProgress;
  17019. fallbackChildFragment.return = workInProgress;
  17020. primaryChildFragment.sibling = fallbackChildFragment;
  17021. workInProgress.child = primaryChildFragment;
  17022. return fallbackChildFragment;
  17023. }
  17024. function mountWorkInProgressOffscreenFiber(offscreenProps, mode, renderLanes) {
  17025. // The props argument to `createFiberFromOffscreen` is `any` typed, so we use
  17026. // this wrapper function to constrain it.
  17027. return createFiberFromOffscreen(offscreenProps, mode, NoLanes, null);
  17028. }
  17029. function updateWorkInProgressOffscreenFiber(current, offscreenProps) {
  17030. // The props argument to `createWorkInProgress` is `any` typed, so we use this
  17031. // wrapper function to constrain it.
  17032. return createWorkInProgress(current, offscreenProps);
  17033. }
  17034. function updateSuspensePrimaryChildren(current, workInProgress, primaryChildren, renderLanes) {
  17035. var currentPrimaryChildFragment = current.child;
  17036. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  17037. var primaryChildFragment = updateWorkInProgressOffscreenFiber(currentPrimaryChildFragment, {
  17038. mode: 'visible',
  17039. children: primaryChildren
  17040. });
  17041. if ((workInProgress.mode & ConcurrentMode) === NoMode) {
  17042. primaryChildFragment.lanes = renderLanes;
  17043. }
  17044. primaryChildFragment.return = workInProgress;
  17045. primaryChildFragment.sibling = null;
  17046. if (currentFallbackChildFragment !== null) {
  17047. // Delete the fallback child fragment
  17048. var deletions = workInProgress.deletions;
  17049. if (deletions === null) {
  17050. workInProgress.deletions = [currentFallbackChildFragment];
  17051. workInProgress.flags |= ChildDeletion;
  17052. } else {
  17053. deletions.push(currentFallbackChildFragment);
  17054. }
  17055. }
  17056. workInProgress.child = primaryChildFragment;
  17057. return primaryChildFragment;
  17058. }
  17059. function updateSuspenseFallbackChildren(current, workInProgress, primaryChildren, fallbackChildren, renderLanes) {
  17060. var mode = workInProgress.mode;
  17061. var currentPrimaryChildFragment = current.child;
  17062. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  17063. var primaryChildProps = {
  17064. mode: 'hidden',
  17065. children: primaryChildren
  17066. };
  17067. var primaryChildFragment;
  17068. if ( // In legacy mode, we commit the primary tree as if it successfully
  17069. // completed, even though it's in an inconsistent state.
  17070. (mode & ConcurrentMode) === NoMode && // Make sure we're on the second pass, i.e. the primary child fragment was
  17071. // already cloned. In legacy mode, the only case where this isn't true is
  17072. // when DevTools forces us to display a fallback; we skip the first render
  17073. // pass entirely and go straight to rendering the fallback. (In Concurrent
  17074. // Mode, SuspenseList can also trigger this scenario, but this is a legacy-
  17075. // only codepath.)
  17076. workInProgress.child !== currentPrimaryChildFragment) {
  17077. var progressedPrimaryFragment = workInProgress.child;
  17078. primaryChildFragment = progressedPrimaryFragment;
  17079. primaryChildFragment.childLanes = NoLanes;
  17080. primaryChildFragment.pendingProps = primaryChildProps;
  17081. if ( workInProgress.mode & ProfileMode) {
  17082. // Reset the durations from the first pass so they aren't included in the
  17083. // final amounts. This seems counterintuitive, since we're intentionally
  17084. // not measuring part of the render phase, but this makes it match what we
  17085. // do in Concurrent Mode.
  17086. primaryChildFragment.actualDuration = 0;
  17087. primaryChildFragment.actualStartTime = -1;
  17088. primaryChildFragment.selfBaseDuration = currentPrimaryChildFragment.selfBaseDuration;
  17089. primaryChildFragment.treeBaseDuration = currentPrimaryChildFragment.treeBaseDuration;
  17090. } // The fallback fiber was added as a deletion during the first pass.
  17091. // However, since we're going to remain on the fallback, we no longer want
  17092. // to delete it.
  17093. workInProgress.deletions = null;
  17094. } else {
  17095. primaryChildFragment = updateWorkInProgressOffscreenFiber(currentPrimaryChildFragment, primaryChildProps); // Since we're reusing a current tree, we need to reuse the flags, too.
  17096. // (We don't do this in legacy mode, because in legacy mode we don't re-use
  17097. // the current tree; see previous branch.)
  17098. primaryChildFragment.subtreeFlags = currentPrimaryChildFragment.subtreeFlags & StaticMask;
  17099. }
  17100. var fallbackChildFragment;
  17101. if (currentFallbackChildFragment !== null) {
  17102. fallbackChildFragment = createWorkInProgress(currentFallbackChildFragment, fallbackChildren);
  17103. } else {
  17104. fallbackChildFragment = createFiberFromFragment(fallbackChildren, mode, renderLanes, null); // Needs a placement effect because the parent (the Suspense boundary) already
  17105. // mounted but this is a new fiber.
  17106. fallbackChildFragment.flags |= Placement;
  17107. }
  17108. fallbackChildFragment.return = workInProgress;
  17109. primaryChildFragment.return = workInProgress;
  17110. primaryChildFragment.sibling = fallbackChildFragment;
  17111. workInProgress.child = primaryChildFragment;
  17112. return fallbackChildFragment;
  17113. }
  17114. function retrySuspenseComponentWithoutHydrating(current, workInProgress, renderLanes, recoverableError) {
  17115. // Falling back to client rendering. Because this has performance
  17116. // implications, it's considered a recoverable error, even though the user
  17117. // likely won't observe anything wrong with the UI.
  17118. //
  17119. // The error is passed in as an argument to enforce that every caller provide
  17120. // a custom message, or explicitly opt out (currently the only path that opts
  17121. // out is legacy mode; every concurrent path provides an error).
  17122. if (recoverableError !== null) {
  17123. queueHydrationError(recoverableError);
  17124. } // This will add the old fiber to the deletion list
  17125. reconcileChildFibers(workInProgress, current.child, null, renderLanes); // We're now not suspended nor dehydrated.
  17126. var nextProps = workInProgress.pendingProps;
  17127. var primaryChildren = nextProps.children;
  17128. var primaryChildFragment = mountSuspensePrimaryChildren(workInProgress, primaryChildren); // Needs a placement effect because the parent (the Suspense boundary) already
  17129. // mounted but this is a new fiber.
  17130. primaryChildFragment.flags |= Placement;
  17131. workInProgress.memoizedState = null;
  17132. return primaryChildFragment;
  17133. }
  17134. function mountSuspenseFallbackAfterRetryWithoutHydrating(current, workInProgress, primaryChildren, fallbackChildren, renderLanes) {
  17135. var fiberMode = workInProgress.mode;
  17136. var primaryChildProps = {
  17137. mode: 'visible',
  17138. children: primaryChildren
  17139. };
  17140. var primaryChildFragment = mountWorkInProgressOffscreenFiber(primaryChildProps, fiberMode);
  17141. var fallbackChildFragment = createFiberFromFragment(fallbackChildren, fiberMode, renderLanes, null); // Needs a placement effect because the parent (the Suspense
  17142. // boundary) already mounted but this is a new fiber.
  17143. fallbackChildFragment.flags |= Placement;
  17144. primaryChildFragment.return = workInProgress;
  17145. fallbackChildFragment.return = workInProgress;
  17146. primaryChildFragment.sibling = fallbackChildFragment;
  17147. workInProgress.child = primaryChildFragment;
  17148. if ((workInProgress.mode & ConcurrentMode) !== NoMode) {
  17149. // We will have dropped the effect list which contains the
  17150. // deletion. We need to reconcile to delete the current child.
  17151. reconcileChildFibers(workInProgress, current.child, null, renderLanes);
  17152. }
  17153. return fallbackChildFragment;
  17154. }
  17155. function mountDehydratedSuspenseComponent(workInProgress, suspenseInstance, renderLanes) {
  17156. // During the first pass, we'll bail out and not drill into the children.
  17157. // Instead, we'll leave the content in place and try to hydrate it later.
  17158. if ((workInProgress.mode & ConcurrentMode) === NoMode) {
  17159. {
  17160. error('Cannot hydrate Suspense in legacy mode. Switch from ' + 'ReactDOM.hydrate(element, container) to ' + 'ReactDOMClient.hydrateRoot(container, <App />)' + '.render(element) or remove the Suspense components from ' + 'the server rendered components.');
  17161. }
  17162. workInProgress.lanes = laneToLanes(SyncLane);
  17163. } else if (isSuspenseInstanceFallback(suspenseInstance)) {
  17164. // This is a client-only boundary. Since we won't get any content from the server
  17165. // for this, we need to schedule that at a higher priority based on when it would
  17166. // have timed out. In theory we could render it in this pass but it would have the
  17167. // wrong priority associated with it and will prevent hydration of parent path.
  17168. // Instead, we'll leave work left on it to render it in a separate commit.
  17169. // TODO This time should be the time at which the server rendered response that is
  17170. // a parent to this boundary was displayed. However, since we currently don't have
  17171. // a protocol to transfer that time, we'll just estimate it by using the current
  17172. // time. This will mean that Suspense timeouts are slightly shifted to later than
  17173. // they should be.
  17174. // Schedule a normal pri update to render this content.
  17175. workInProgress.lanes = laneToLanes(DefaultHydrationLane);
  17176. } else {
  17177. // We'll continue hydrating the rest at offscreen priority since we'll already
  17178. // be showing the right content coming from the server, it is no rush.
  17179. workInProgress.lanes = laneToLanes(OffscreenLane);
  17180. }
  17181. return null;
  17182. }
  17183. function updateDehydratedSuspenseComponent(current, workInProgress, didSuspend, nextProps, suspenseInstance, suspenseState, renderLanes) {
  17184. if (!didSuspend) {
  17185. // This is the first render pass. Attempt to hydrate.
  17186. // We should never be hydrating at this point because it is the first pass,
  17187. // but after we've already committed once.
  17188. warnIfHydrating();
  17189. if ((workInProgress.mode & ConcurrentMode) === NoMode) {
  17190. return retrySuspenseComponentWithoutHydrating(current, workInProgress, renderLanes, // TODO: When we delete legacy mode, we should make this error argument
  17191. // required — every concurrent mode path that causes hydration to
  17192. // de-opt to client rendering should have an error message.
  17193. null);
  17194. }
  17195. if (isSuspenseInstanceFallback(suspenseInstance)) {
  17196. // This boundary is in a permanent fallback state. In this case, we'll never
  17197. // get an update and we'll never be able to hydrate the final content. Let's just try the
  17198. // client side render instead.
  17199. var digest, message, stack;
  17200. {
  17201. var _getSuspenseInstanceF = getSuspenseInstanceFallbackErrorDetails(suspenseInstance);
  17202. digest = _getSuspenseInstanceF.digest;
  17203. message = _getSuspenseInstanceF.message;
  17204. stack = _getSuspenseInstanceF.stack;
  17205. }
  17206. var error;
  17207. if (message) {
  17208. // eslint-disable-next-line react-internal/prod-error-codes
  17209. error = new Error(message);
  17210. } else {
  17211. error = new Error('The server could not finish this Suspense boundary, likely ' + 'due to an error during server rendering. Switched to ' + 'client rendering.');
  17212. }
  17213. var capturedValue = createCapturedValue(error, digest, stack);
  17214. return retrySuspenseComponentWithoutHydrating(current, workInProgress, renderLanes, capturedValue);
  17215. }
  17216. // any context has changed, we need to treat is as if the input might have changed.
  17217. var hasContextChanged = includesSomeLane(renderLanes, current.childLanes);
  17218. if (didReceiveUpdate || hasContextChanged) {
  17219. // This boundary has changed since the first render. This means that we are now unable to
  17220. // hydrate it. We might still be able to hydrate it using a higher priority lane.
  17221. var root = getWorkInProgressRoot();
  17222. if (root !== null) {
  17223. var attemptHydrationAtLane = getBumpedLaneForHydration(root, renderLanes);
  17224. if (attemptHydrationAtLane !== NoLane && attemptHydrationAtLane !== suspenseState.retryLane) {
  17225. // Intentionally mutating since this render will get interrupted. This
  17226. // is one of the very rare times where we mutate the current tree
  17227. // during the render phase.
  17228. suspenseState.retryLane = attemptHydrationAtLane; // TODO: Ideally this would inherit the event time of the current render
  17229. var eventTime = NoTimestamp;
  17230. enqueueConcurrentRenderForLane(current, attemptHydrationAtLane);
  17231. scheduleUpdateOnFiber(root, current, attemptHydrationAtLane, eventTime);
  17232. }
  17233. } // If we have scheduled higher pri work above, this will probably just abort the render
  17234. // since we now have higher priority work, but in case it doesn't, we need to prepare to
  17235. // render something, if we time out. Even if that requires us to delete everything and
  17236. // skip hydration.
  17237. // Delay having to do this as long as the suspense timeout allows us.
  17238. renderDidSuspendDelayIfPossible();
  17239. var _capturedValue = createCapturedValue(new Error('This Suspense boundary received an update before it finished ' + 'hydrating. This caused the boundary to switch to client rendering. ' + 'The usual way to fix this is to wrap the original update ' + 'in startTransition.'));
  17240. return retrySuspenseComponentWithoutHydrating(current, workInProgress, renderLanes, _capturedValue);
  17241. } else if (isSuspenseInstancePending(suspenseInstance)) {
  17242. // This component is still pending more data from the server, so we can't hydrate its
  17243. // content. We treat it as if this component suspended itself. It might seem as if
  17244. // we could just try to render it client-side instead. However, this will perform a
  17245. // lot of unnecessary work and is unlikely to complete since it often will suspend
  17246. // on missing data anyway. Additionally, the server might be able to render more
  17247. // than we can on the client yet. In that case we'd end up with more fallback states
  17248. // on the client than if we just leave it alone. If the server times out or errors
  17249. // these should update this boundary to the permanent Fallback state instead.
  17250. // Mark it as having captured (i.e. suspended).
  17251. workInProgress.flags |= DidCapture; // Leave the child in place. I.e. the dehydrated fragment.
  17252. workInProgress.child = current.child; // Register a callback to retry this boundary once the server has sent the result.
  17253. var retry = retryDehydratedSuspenseBoundary.bind(null, current);
  17254. registerSuspenseInstanceRetry(suspenseInstance, retry);
  17255. return null;
  17256. } else {
  17257. // This is the first attempt.
  17258. reenterHydrationStateFromDehydratedSuspenseInstance(workInProgress, suspenseInstance, suspenseState.treeContext);
  17259. var primaryChildren = nextProps.children;
  17260. var primaryChildFragment = mountSuspensePrimaryChildren(workInProgress, primaryChildren); // Mark the children as hydrating. This is a fast path to know whether this
  17261. // tree is part of a hydrating tree. This is used to determine if a child
  17262. // node has fully mounted yet, and for scheduling event replaying.
  17263. // Conceptually this is similar to Placement in that a new subtree is
  17264. // inserted into the React tree here. It just happens to not need DOM
  17265. // mutations because it already exists.
  17266. primaryChildFragment.flags |= Hydrating;
  17267. return primaryChildFragment;
  17268. }
  17269. } else {
  17270. // This is the second render pass. We already attempted to hydrated, but
  17271. // something either suspended or errored.
  17272. if (workInProgress.flags & ForceClientRender) {
  17273. // Something errored during hydration. Try again without hydrating.
  17274. workInProgress.flags &= ~ForceClientRender;
  17275. var _capturedValue2 = createCapturedValue(new Error('There was an error while hydrating this Suspense boundary. ' + 'Switched to client rendering.'));
  17276. return retrySuspenseComponentWithoutHydrating(current, workInProgress, renderLanes, _capturedValue2);
  17277. } else if (workInProgress.memoizedState !== null) {
  17278. // Something suspended and we should still be in dehydrated mode.
  17279. // Leave the existing child in place.
  17280. workInProgress.child = current.child; // The dehydrated completion pass expects this flag to be there
  17281. // but the normal suspense pass doesn't.
  17282. workInProgress.flags |= DidCapture;
  17283. return null;
  17284. } else {
  17285. // Suspended but we should no longer be in dehydrated mode.
  17286. // Therefore we now have to render the fallback.
  17287. var nextPrimaryChildren = nextProps.children;
  17288. var nextFallbackChildren = nextProps.fallback;
  17289. var fallbackChildFragment = mountSuspenseFallbackAfterRetryWithoutHydrating(current, workInProgress, nextPrimaryChildren, nextFallbackChildren, renderLanes);
  17290. var _primaryChildFragment4 = workInProgress.child;
  17291. _primaryChildFragment4.memoizedState = mountSuspenseOffscreenState(renderLanes);
  17292. workInProgress.memoizedState = SUSPENDED_MARKER;
  17293. return fallbackChildFragment;
  17294. }
  17295. }
  17296. }
  17297. function scheduleSuspenseWorkOnFiber(fiber, renderLanes, propagationRoot) {
  17298. fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
  17299. var alternate = fiber.alternate;
  17300. if (alternate !== null) {
  17301. alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
  17302. }
  17303. scheduleContextWorkOnParentPath(fiber.return, renderLanes, propagationRoot);
  17304. }
  17305. function propagateSuspenseContextChange(workInProgress, firstChild, renderLanes) {
  17306. // Mark any Suspense boundaries with fallbacks as having work to do.
  17307. // If they were previously forced into fallbacks, they may now be able
  17308. // to unblock.
  17309. var node = firstChild;
  17310. while (node !== null) {
  17311. if (node.tag === SuspenseComponent) {
  17312. var state = node.memoizedState;
  17313. if (state !== null) {
  17314. scheduleSuspenseWorkOnFiber(node, renderLanes, workInProgress);
  17315. }
  17316. } else if (node.tag === SuspenseListComponent) {
  17317. // If the tail is hidden there might not be an Suspense boundaries
  17318. // to schedule work on. In this case we have to schedule it on the
  17319. // list itself.
  17320. // We don't have to traverse to the children of the list since
  17321. // the list will propagate the change when it rerenders.
  17322. scheduleSuspenseWorkOnFiber(node, renderLanes, workInProgress);
  17323. } else if (node.child !== null) {
  17324. node.child.return = node;
  17325. node = node.child;
  17326. continue;
  17327. }
  17328. if (node === workInProgress) {
  17329. return;
  17330. }
  17331. while (node.sibling === null) {
  17332. if (node.return === null || node.return === workInProgress) {
  17333. return;
  17334. }
  17335. node = node.return;
  17336. }
  17337. node.sibling.return = node.return;
  17338. node = node.sibling;
  17339. }
  17340. }
  17341. function findLastContentRow(firstChild) {
  17342. // This is going to find the last row among these children that is already
  17343. // showing content on the screen, as opposed to being in fallback state or
  17344. // new. If a row has multiple Suspense boundaries, any of them being in the
  17345. // fallback state, counts as the whole row being in a fallback state.
  17346. // Note that the "rows" will be workInProgress, but any nested children
  17347. // will still be current since we haven't rendered them yet. The mounted
  17348. // order may not be the same as the new order. We use the new order.
  17349. var row = firstChild;
  17350. var lastContentRow = null;
  17351. while (row !== null) {
  17352. var currentRow = row.alternate; // New rows can't be content rows.
  17353. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  17354. lastContentRow = row;
  17355. }
  17356. row = row.sibling;
  17357. }
  17358. return lastContentRow;
  17359. }
  17360. function validateRevealOrder(revealOrder) {
  17361. {
  17362. if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
  17363. didWarnAboutRevealOrder[revealOrder] = true;
  17364. if (typeof revealOrder === 'string') {
  17365. switch (revealOrder.toLowerCase()) {
  17366. case 'together':
  17367. case 'forwards':
  17368. case 'backwards':
  17369. {
  17370. error('"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
  17371. break;
  17372. }
  17373. case 'forward':
  17374. case 'backward':
  17375. {
  17376. 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());
  17377. break;
  17378. }
  17379. default:
  17380. error('"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  17381. break;
  17382. }
  17383. } else {
  17384. error('%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  17385. }
  17386. }
  17387. }
  17388. }
  17389. function validateTailOptions(tailMode, revealOrder) {
  17390. {
  17391. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  17392. if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
  17393. didWarnAboutTailOptions[tailMode] = true;
  17394. error('"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
  17395. } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
  17396. didWarnAboutTailOptions[tailMode] = true;
  17397. error('<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
  17398. }
  17399. }
  17400. }
  17401. }
  17402. function validateSuspenseListNestedChild(childSlot, index) {
  17403. {
  17404. var isAnArray = isArray(childSlot);
  17405. var isIterable = !isAnArray && typeof getIteratorFn(childSlot) === 'function';
  17406. if (isAnArray || isIterable) {
  17407. var type = isAnArray ? 'array' : 'iterable';
  17408. 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);
  17409. return false;
  17410. }
  17411. }
  17412. return true;
  17413. }
  17414. function validateSuspenseListChildren(children, revealOrder) {
  17415. {
  17416. if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
  17417. if (isArray(children)) {
  17418. for (var i = 0; i < children.length; i++) {
  17419. if (!validateSuspenseListNestedChild(children[i], i)) {
  17420. return;
  17421. }
  17422. }
  17423. } else {
  17424. var iteratorFn = getIteratorFn(children);
  17425. if (typeof iteratorFn === 'function') {
  17426. var childrenIterator = iteratorFn.call(children);
  17427. if (childrenIterator) {
  17428. var step = childrenIterator.next();
  17429. var _i = 0;
  17430. for (; !step.done; step = childrenIterator.next()) {
  17431. if (!validateSuspenseListNestedChild(step.value, _i)) {
  17432. return;
  17433. }
  17434. _i++;
  17435. }
  17436. }
  17437. } else {
  17438. 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);
  17439. }
  17440. }
  17441. }
  17442. }
  17443. }
  17444. function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode) {
  17445. var renderState = workInProgress.memoizedState;
  17446. if (renderState === null) {
  17447. workInProgress.memoizedState = {
  17448. isBackwards: isBackwards,
  17449. rendering: null,
  17450. renderingStartTime: 0,
  17451. last: lastContentRow,
  17452. tail: tail,
  17453. tailMode: tailMode
  17454. };
  17455. } else {
  17456. // We can reuse the existing object from previous renders.
  17457. renderState.isBackwards = isBackwards;
  17458. renderState.rendering = null;
  17459. renderState.renderingStartTime = 0;
  17460. renderState.last = lastContentRow;
  17461. renderState.tail = tail;
  17462. renderState.tailMode = tailMode;
  17463. }
  17464. } // This can end up rendering this component multiple passes.
  17465. // The first pass splits the children fibers into two sets. A head and tail.
  17466. // We first render the head. If anything is in fallback state, we do another
  17467. // pass through beginWork to rerender all children (including the tail) with
  17468. // the force suspend context. If the first render didn't have anything in
  17469. // in fallback state. Then we render each row in the tail one-by-one.
  17470. // That happens in the completeWork phase without going back to beginWork.
  17471. function updateSuspenseListComponent(current, workInProgress, renderLanes) {
  17472. var nextProps = workInProgress.pendingProps;
  17473. var revealOrder = nextProps.revealOrder;
  17474. var tailMode = nextProps.tail;
  17475. var newChildren = nextProps.children;
  17476. validateRevealOrder(revealOrder);
  17477. validateTailOptions(tailMode, revealOrder);
  17478. validateSuspenseListChildren(newChildren, revealOrder);
  17479. reconcileChildren(current, workInProgress, newChildren, renderLanes);
  17480. var suspenseContext = suspenseStackCursor.current;
  17481. var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
  17482. if (shouldForceFallback) {
  17483. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  17484. workInProgress.flags |= DidCapture;
  17485. } else {
  17486. var didSuspendBefore = current !== null && (current.flags & DidCapture) !== NoFlags;
  17487. if (didSuspendBefore) {
  17488. // If we previously forced a fallback, we need to schedule work
  17489. // on any nested boundaries to let them know to try to render
  17490. // again. This is the same as context updating.
  17491. propagateSuspenseContextChange(workInProgress, workInProgress.child, renderLanes);
  17492. }
  17493. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  17494. }
  17495. pushSuspenseContext(workInProgress, suspenseContext);
  17496. if ((workInProgress.mode & ConcurrentMode) === NoMode) {
  17497. // In legacy mode, SuspenseList doesn't work so we just
  17498. // use make it a noop by treating it as the default revealOrder.
  17499. workInProgress.memoizedState = null;
  17500. } else {
  17501. switch (revealOrder) {
  17502. case 'forwards':
  17503. {
  17504. var lastContentRow = findLastContentRow(workInProgress.child);
  17505. var tail;
  17506. if (lastContentRow === null) {
  17507. // The whole list is part of the tail.
  17508. // TODO: We could fast path by just rendering the tail now.
  17509. tail = workInProgress.child;
  17510. workInProgress.child = null;
  17511. } else {
  17512. // Disconnect the tail rows after the content row.
  17513. // We're going to render them separately later.
  17514. tail = lastContentRow.sibling;
  17515. lastContentRow.sibling = null;
  17516. }
  17517. initSuspenseListRenderState(workInProgress, false, // isBackwards
  17518. tail, lastContentRow, tailMode);
  17519. break;
  17520. }
  17521. case 'backwards':
  17522. {
  17523. // We're going to find the first row that has existing content.
  17524. // At the same time we're going to reverse the list of everything
  17525. // we pass in the meantime. That's going to be our tail in reverse
  17526. // order.
  17527. var _tail = null;
  17528. var row = workInProgress.child;
  17529. workInProgress.child = null;
  17530. while (row !== null) {
  17531. var currentRow = row.alternate; // New rows can't be content rows.
  17532. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  17533. // This is the beginning of the main content.
  17534. workInProgress.child = row;
  17535. break;
  17536. }
  17537. var nextRow = row.sibling;
  17538. row.sibling = _tail;
  17539. _tail = row;
  17540. row = nextRow;
  17541. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  17542. initSuspenseListRenderState(workInProgress, true, // isBackwards
  17543. _tail, null, // last
  17544. tailMode);
  17545. break;
  17546. }
  17547. case 'together':
  17548. {
  17549. initSuspenseListRenderState(workInProgress, false, // isBackwards
  17550. null, // tail
  17551. null, // last
  17552. undefined);
  17553. break;
  17554. }
  17555. default:
  17556. {
  17557. // The default reveal order is the same as not having
  17558. // a boundary.
  17559. workInProgress.memoizedState = null;
  17560. }
  17561. }
  17562. }
  17563. return workInProgress.child;
  17564. }
  17565. function updatePortalComponent(current, workInProgress, renderLanes) {
  17566. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  17567. var nextChildren = workInProgress.pendingProps;
  17568. if (current === null) {
  17569. // Portals are special because we don't append the children during mount
  17570. // but at commit. Therefore we need to track insertions which the normal
  17571. // flow doesn't do during mount. This doesn't happen at the root because
  17572. // the root always starts with a "current" with a null child.
  17573. // TODO: Consider unifying this with how the root works.
  17574. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderLanes);
  17575. } else {
  17576. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  17577. }
  17578. return workInProgress.child;
  17579. }
  17580. var hasWarnedAboutUsingNoValuePropOnContextProvider = false;
  17581. function updateContextProvider(current, workInProgress, renderLanes) {
  17582. var providerType = workInProgress.type;
  17583. var context = providerType._context;
  17584. var newProps = workInProgress.pendingProps;
  17585. var oldProps = workInProgress.memoizedProps;
  17586. var newValue = newProps.value;
  17587. {
  17588. if (!('value' in newProps)) {
  17589. if (!hasWarnedAboutUsingNoValuePropOnContextProvider) {
  17590. hasWarnedAboutUsingNoValuePropOnContextProvider = true;
  17591. error('The `value` prop is required for the `<Context.Provider>`. Did you misspell it or forget to pass it?');
  17592. }
  17593. }
  17594. var providerPropTypes = workInProgress.type.propTypes;
  17595. if (providerPropTypes) {
  17596. checkPropTypes(providerPropTypes, newProps, 'prop', 'Context.Provider');
  17597. }
  17598. }
  17599. pushProvider(workInProgress, context, newValue);
  17600. {
  17601. if (oldProps !== null) {
  17602. var oldValue = oldProps.value;
  17603. if (objectIs(oldValue, newValue)) {
  17604. // No change. Bailout early if children are the same.
  17605. if (oldProps.children === newProps.children && !hasContextChanged()) {
  17606. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  17607. }
  17608. } else {
  17609. // The context value changed. Search for matching consumers and schedule
  17610. // them to update.
  17611. propagateContextChange(workInProgress, context, renderLanes);
  17612. }
  17613. }
  17614. }
  17615. var newChildren = newProps.children;
  17616. reconcileChildren(current, workInProgress, newChildren, renderLanes);
  17617. return workInProgress.child;
  17618. }
  17619. var hasWarnedAboutUsingContextAsConsumer = false;
  17620. function updateContextConsumer(current, workInProgress, renderLanes) {
  17621. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  17622. // DEV mode, we create a separate object for Context.Consumer that acts
  17623. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  17624. // so we use the old behaviour (Context.Consumer references Context) to
  17625. // reduce size and overhead. The separate object references context via
  17626. // a property called "_context", which also gives us the ability to check
  17627. // in DEV mode if this property exists or not and warn if it does not.
  17628. {
  17629. if (context._context === undefined) {
  17630. // This may be because it's a Context (rather than a Consumer).
  17631. // Or it may be because it's older React where they're the same thing.
  17632. // We only want to warn if we're sure it's a new React.
  17633. if (context !== context.Consumer) {
  17634. if (!hasWarnedAboutUsingContextAsConsumer) {
  17635. hasWarnedAboutUsingContextAsConsumer = true;
  17636. error('Rendering <Context> directly is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
  17637. }
  17638. }
  17639. } else {
  17640. context = context._context;
  17641. }
  17642. }
  17643. var newProps = workInProgress.pendingProps;
  17644. var render = newProps.children;
  17645. {
  17646. if (typeof render !== 'function') {
  17647. 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.');
  17648. }
  17649. }
  17650. prepareToReadContext(workInProgress, renderLanes);
  17651. var newValue = readContext(context);
  17652. {
  17653. markComponentRenderStarted(workInProgress);
  17654. }
  17655. var newChildren;
  17656. {
  17657. ReactCurrentOwner$1.current = workInProgress;
  17658. setIsRendering(true);
  17659. newChildren = render(newValue);
  17660. setIsRendering(false);
  17661. }
  17662. {
  17663. markComponentRenderStopped();
  17664. } // React DevTools reads this flag.
  17665. workInProgress.flags |= PerformedWork;
  17666. reconcileChildren(current, workInProgress, newChildren, renderLanes);
  17667. return workInProgress.child;
  17668. }
  17669. function markWorkInProgressReceivedUpdate() {
  17670. didReceiveUpdate = true;
  17671. }
  17672. function resetSuspendedCurrentOnMountInLegacyMode(current, workInProgress) {
  17673. if ((workInProgress.mode & ConcurrentMode) === NoMode) {
  17674. if (current !== null) {
  17675. // A lazy component only mounts if it suspended inside a non-
  17676. // concurrent tree, in an inconsistent state. We want to treat it like
  17677. // a new mount, even though an empty version of it already committed.
  17678. // Disconnect the alternate pointers.
  17679. current.alternate = null;
  17680. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  17681. workInProgress.flags |= Placement;
  17682. }
  17683. }
  17684. }
  17685. function bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes) {
  17686. if (current !== null) {
  17687. // Reuse previous dependencies
  17688. workInProgress.dependencies = current.dependencies;
  17689. }
  17690. {
  17691. // Don't update "base" render times for bailouts.
  17692. stopProfilerTimerIfRunning();
  17693. }
  17694. markSkippedUpdateLanes(workInProgress.lanes); // Check if the children have any pending work.
  17695. if (!includesSomeLane(renderLanes, workInProgress.childLanes)) {
  17696. // The children don't have any work either. We can skip them.
  17697. // TODO: Once we add back resuming, we should check if the children are
  17698. // a work-in-progress set. If so, we need to transfer their effects.
  17699. {
  17700. return null;
  17701. }
  17702. } // This fiber doesn't have work, but its subtree does. Clone the child
  17703. // fibers and continue.
  17704. cloneChildFibers(current, workInProgress);
  17705. return workInProgress.child;
  17706. }
  17707. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  17708. {
  17709. var returnFiber = oldWorkInProgress.return;
  17710. if (returnFiber === null) {
  17711. // eslint-disable-next-line react-internal/prod-error-codes
  17712. throw new Error('Cannot swap the root fiber.');
  17713. } // Disconnect from the old current.
  17714. // It will get deleted.
  17715. current.alternate = null;
  17716. oldWorkInProgress.alternate = null; // Connect to the new tree.
  17717. newWorkInProgress.index = oldWorkInProgress.index;
  17718. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  17719. newWorkInProgress.return = oldWorkInProgress.return;
  17720. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  17721. if (oldWorkInProgress === returnFiber.child) {
  17722. returnFiber.child = newWorkInProgress;
  17723. } else {
  17724. var prevSibling = returnFiber.child;
  17725. if (prevSibling === null) {
  17726. // eslint-disable-next-line react-internal/prod-error-codes
  17727. throw new Error('Expected parent to have a child.');
  17728. }
  17729. while (prevSibling.sibling !== oldWorkInProgress) {
  17730. prevSibling = prevSibling.sibling;
  17731. if (prevSibling === null) {
  17732. // eslint-disable-next-line react-internal/prod-error-codes
  17733. throw new Error('Expected to find the previous sibling.');
  17734. }
  17735. }
  17736. prevSibling.sibling = newWorkInProgress;
  17737. } // Delete the old fiber and place the new one.
  17738. // Since the old fiber is disconnected, we have to schedule it manually.
  17739. var deletions = returnFiber.deletions;
  17740. if (deletions === null) {
  17741. returnFiber.deletions = [current];
  17742. returnFiber.flags |= ChildDeletion;
  17743. } else {
  17744. deletions.push(current);
  17745. }
  17746. newWorkInProgress.flags |= Placement; // Restart work from the new fiber.
  17747. return newWorkInProgress;
  17748. }
  17749. }
  17750. function checkScheduledUpdateOrContext(current, renderLanes) {
  17751. // Before performing an early bailout, we must check if there are pending
  17752. // updates or context.
  17753. var updateLanes = current.lanes;
  17754. if (includesSomeLane(updateLanes, renderLanes)) {
  17755. return true;
  17756. } // No pending update, but because context is propagated lazily, we need
  17757. return false;
  17758. }
  17759. function attemptEarlyBailoutIfNoScheduledUpdate(current, workInProgress, renderLanes) {
  17760. // This fiber does not have any pending work. Bailout without entering
  17761. // the begin phase. There's still some bookkeeping we that needs to be done
  17762. // in this optimized path, mostly pushing stuff onto the stack.
  17763. switch (workInProgress.tag) {
  17764. case HostRoot:
  17765. pushHostRootContext(workInProgress);
  17766. var root = workInProgress.stateNode;
  17767. resetHydrationState();
  17768. break;
  17769. case HostComponent:
  17770. pushHostContext(workInProgress);
  17771. break;
  17772. case ClassComponent:
  17773. {
  17774. var Component = workInProgress.type;
  17775. if (isContextProvider(Component)) {
  17776. pushContextProvider(workInProgress);
  17777. }
  17778. break;
  17779. }
  17780. case HostPortal:
  17781. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  17782. break;
  17783. case ContextProvider:
  17784. {
  17785. var newValue = workInProgress.memoizedProps.value;
  17786. var context = workInProgress.type._context;
  17787. pushProvider(workInProgress, context, newValue);
  17788. break;
  17789. }
  17790. case Profiler:
  17791. {
  17792. // Profiler should only call onRender when one of its descendants actually rendered.
  17793. var hasChildWork = includesSomeLane(renderLanes, workInProgress.childLanes);
  17794. if (hasChildWork) {
  17795. workInProgress.flags |= Update;
  17796. }
  17797. {
  17798. // Reset effect durations for the next eventual effect phase.
  17799. // These are reset during render to allow the DevTools commit hook a chance to read them,
  17800. var stateNode = workInProgress.stateNode;
  17801. stateNode.effectDuration = 0;
  17802. stateNode.passiveEffectDuration = 0;
  17803. }
  17804. }
  17805. break;
  17806. case SuspenseComponent:
  17807. {
  17808. var state = workInProgress.memoizedState;
  17809. if (state !== null) {
  17810. if (state.dehydrated !== null) {
  17811. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // We know that this component will suspend again because if it has
  17812. // been unsuspended it has committed as a resolved Suspense component.
  17813. // If it needs to be retried, it should have work scheduled on it.
  17814. workInProgress.flags |= DidCapture; // We should never render the children of a dehydrated boundary until we
  17815. // upgrade it. We return null instead of bailoutOnAlreadyFinishedWork.
  17816. return null;
  17817. } // If this boundary is currently timed out, we need to decide
  17818. // whether to retry the primary children, or to skip over it and
  17819. // go straight to the fallback. Check the priority of the primary
  17820. // child fragment.
  17821. var primaryChildFragment = workInProgress.child;
  17822. var primaryChildLanes = primaryChildFragment.childLanes;
  17823. if (includesSomeLane(renderLanes, primaryChildLanes)) {
  17824. // The primary children have pending work. Use the normal path
  17825. // to attempt to render the primary children again.
  17826. return updateSuspenseComponent(current, workInProgress, renderLanes);
  17827. } else {
  17828. // The primary child fragment does not have pending work marked
  17829. // on it
  17830. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
  17831. // priority. Bailout.
  17832. var child = bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  17833. if (child !== null) {
  17834. // The fallback children have pending work. Skip over the
  17835. // primary children and work on the fallback.
  17836. return child.sibling;
  17837. } else {
  17838. // Note: We can return `null` here because we already checked
  17839. // whether there were nested context consumers, via the call to
  17840. // `bailoutOnAlreadyFinishedWork` above.
  17841. return null;
  17842. }
  17843. }
  17844. } else {
  17845. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
  17846. }
  17847. break;
  17848. }
  17849. case SuspenseListComponent:
  17850. {
  17851. var didSuspendBefore = (current.flags & DidCapture) !== NoFlags;
  17852. var _hasChildWork = includesSomeLane(renderLanes, workInProgress.childLanes);
  17853. if (didSuspendBefore) {
  17854. if (_hasChildWork) {
  17855. // If something was in fallback state last time, and we have all the
  17856. // same children then we're still in progressive loading state.
  17857. // Something might get unblocked by state updates or retries in the
  17858. // tree which will affect the tail. So we need to use the normal
  17859. // path to compute the correct tail.
  17860. return updateSuspenseListComponent(current, workInProgress, renderLanes);
  17861. } // If none of the children had any work, that means that none of
  17862. // them got retried so they'll still be blocked in the same way
  17863. // as before. We can fast bail out.
  17864. workInProgress.flags |= DidCapture;
  17865. } // If nothing suspended before and we're rendering the same children,
  17866. // then the tail doesn't matter. Anything new that suspends will work
  17867. // in the "together" mode, so we can continue from the state we had.
  17868. var renderState = workInProgress.memoizedState;
  17869. if (renderState !== null) {
  17870. // Reset to the "together" mode in case we've started a different
  17871. // update in the past but didn't complete it.
  17872. renderState.rendering = null;
  17873. renderState.tail = null;
  17874. renderState.lastEffect = null;
  17875. }
  17876. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  17877. if (_hasChildWork) {
  17878. break;
  17879. } else {
  17880. // If none of the children had any work, that means that none of
  17881. // them got retried so they'll still be blocked in the same way
  17882. // as before. We can fast bail out.
  17883. return null;
  17884. }
  17885. }
  17886. case OffscreenComponent:
  17887. case LegacyHiddenComponent:
  17888. {
  17889. // Need to check if the tree still needs to be deferred. This is
  17890. // almost identical to the logic used in the normal update path,
  17891. // so we'll just enter that. The only difference is we'll bail out
  17892. // at the next level instead of this one, because the child props
  17893. // have not changed. Which is fine.
  17894. // TODO: Probably should refactor `beginWork` to split the bailout
  17895. // path from the normal path. I'm tempted to do a labeled break here
  17896. // but I won't :)
  17897. workInProgress.lanes = NoLanes;
  17898. return updateOffscreenComponent(current, workInProgress, renderLanes);
  17899. }
  17900. }
  17901. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  17902. }
  17903. function beginWork(current, workInProgress, renderLanes) {
  17904. {
  17905. if (workInProgress._debugNeedsRemount && current !== null) {
  17906. // This will restart the begin phase with a new fiber.
  17907. return remountFiber(current, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.lanes));
  17908. }
  17909. }
  17910. if (current !== null) {
  17911. var oldProps = current.memoizedProps;
  17912. var newProps = workInProgress.pendingProps;
  17913. if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
  17914. workInProgress.type !== current.type )) {
  17915. // If props or context changed, mark the fiber as having performed work.
  17916. // This may be unset if the props are determined to be equal later (memo).
  17917. didReceiveUpdate = true;
  17918. } else {
  17919. // Neither props nor legacy context changes. Check if there's a pending
  17920. // update or context change.
  17921. var hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(current, renderLanes);
  17922. if (!hasScheduledUpdateOrContext && // If this is the second pass of an error or suspense boundary, there
  17923. // may not be work scheduled on `current`, so we check for this flag.
  17924. (workInProgress.flags & DidCapture) === NoFlags) {
  17925. // No pending updates or context. Bail out now.
  17926. didReceiveUpdate = false;
  17927. return attemptEarlyBailoutIfNoScheduledUpdate(current, workInProgress, renderLanes);
  17928. }
  17929. if ((current.flags & ForceUpdateForLegacySuspense) !== NoFlags) {
  17930. // This is a special case that only exists for legacy mode.
  17931. // See https://github.com/facebook/react/pull/19216.
  17932. didReceiveUpdate = true;
  17933. } else {
  17934. // An update was scheduled on this fiber, but there are no new props
  17935. // nor legacy context. Set this to false. If an update queue or context
  17936. // consumer produces a changed value, it will set this to true. Otherwise,
  17937. // the component will assume the children have not changed and bail out.
  17938. didReceiveUpdate = false;
  17939. }
  17940. }
  17941. } else {
  17942. didReceiveUpdate = false;
  17943. if (getIsHydrating() && isForkedChild(workInProgress)) {
  17944. // Check if this child belongs to a list of muliple children in
  17945. // its parent.
  17946. //
  17947. // In a true multi-threaded implementation, we would render children on
  17948. // parallel threads. This would represent the beginning of a new render
  17949. // thread for this subtree.
  17950. //
  17951. // We only use this for id generation during hydration, which is why the
  17952. // logic is located in this special branch.
  17953. var slotIndex = workInProgress.index;
  17954. var numberOfForks = getForksAtLevel();
  17955. pushTreeId(workInProgress, numberOfForks, slotIndex);
  17956. }
  17957. } // Before entering the begin phase, clear pending update priority.
  17958. // TODO: This assumes that we're about to evaluate the component and process
  17959. // the update queue. However, there's an exception: SimpleMemoComponent
  17960. // sometimes bails out later in the begin phase. This indicates that we should
  17961. // move this assignment out of the common path and into each branch.
  17962. workInProgress.lanes = NoLanes;
  17963. switch (workInProgress.tag) {
  17964. case IndeterminateComponent:
  17965. {
  17966. return mountIndeterminateComponent(current, workInProgress, workInProgress.type, renderLanes);
  17967. }
  17968. case LazyComponent:
  17969. {
  17970. var elementType = workInProgress.elementType;
  17971. return mountLazyComponent(current, workInProgress, elementType, renderLanes);
  17972. }
  17973. case FunctionComponent:
  17974. {
  17975. var Component = workInProgress.type;
  17976. var unresolvedProps = workInProgress.pendingProps;
  17977. var resolvedProps = workInProgress.elementType === Component ? unresolvedProps : resolveDefaultProps(Component, unresolvedProps);
  17978. return updateFunctionComponent(current, workInProgress, Component, resolvedProps, renderLanes);
  17979. }
  17980. case ClassComponent:
  17981. {
  17982. var _Component = workInProgress.type;
  17983. var _unresolvedProps = workInProgress.pendingProps;
  17984. var _resolvedProps = workInProgress.elementType === _Component ? _unresolvedProps : resolveDefaultProps(_Component, _unresolvedProps);
  17985. return updateClassComponent(current, workInProgress, _Component, _resolvedProps, renderLanes);
  17986. }
  17987. case HostRoot:
  17988. return updateHostRoot(current, workInProgress, renderLanes);
  17989. case HostComponent:
  17990. return updateHostComponent(current, workInProgress, renderLanes);
  17991. case HostText:
  17992. return updateHostText(current, workInProgress);
  17993. case SuspenseComponent:
  17994. return updateSuspenseComponent(current, workInProgress, renderLanes);
  17995. case HostPortal:
  17996. return updatePortalComponent(current, workInProgress, renderLanes);
  17997. case ForwardRef:
  17998. {
  17999. var type = workInProgress.type;
  18000. var _unresolvedProps2 = workInProgress.pendingProps;
  18001. var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
  18002. return updateForwardRef(current, workInProgress, type, _resolvedProps2, renderLanes);
  18003. }
  18004. case Fragment:
  18005. return updateFragment(current, workInProgress, renderLanes);
  18006. case Mode:
  18007. return updateMode(current, workInProgress, renderLanes);
  18008. case Profiler:
  18009. return updateProfiler(current, workInProgress, renderLanes);
  18010. case ContextProvider:
  18011. return updateContextProvider(current, workInProgress, renderLanes);
  18012. case ContextConsumer:
  18013. return updateContextConsumer(current, workInProgress, renderLanes);
  18014. case MemoComponent:
  18015. {
  18016. var _type2 = workInProgress.type;
  18017. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  18018. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  18019. {
  18020. if (workInProgress.type !== workInProgress.elementType) {
  18021. var outerPropTypes = _type2.propTypes;
  18022. if (outerPropTypes) {
  18023. checkPropTypes(outerPropTypes, _resolvedProps3, // Resolved for outer only
  18024. 'prop', getComponentNameFromType(_type2));
  18025. }
  18026. }
  18027. }
  18028. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  18029. return updateMemoComponent(current, workInProgress, _type2, _resolvedProps3, renderLanes);
  18030. }
  18031. case SimpleMemoComponent:
  18032. {
  18033. return updateSimpleMemoComponent(current, workInProgress, workInProgress.type, workInProgress.pendingProps, renderLanes);
  18034. }
  18035. case IncompleteClassComponent:
  18036. {
  18037. var _Component2 = workInProgress.type;
  18038. var _unresolvedProps4 = workInProgress.pendingProps;
  18039. var _resolvedProps4 = workInProgress.elementType === _Component2 ? _unresolvedProps4 : resolveDefaultProps(_Component2, _unresolvedProps4);
  18040. return mountIncompleteClassComponent(current, workInProgress, _Component2, _resolvedProps4, renderLanes);
  18041. }
  18042. case SuspenseListComponent:
  18043. {
  18044. return updateSuspenseListComponent(current, workInProgress, renderLanes);
  18045. }
  18046. case ScopeComponent:
  18047. {
  18048. break;
  18049. }
  18050. case OffscreenComponent:
  18051. {
  18052. return updateOffscreenComponent(current, workInProgress, renderLanes);
  18053. }
  18054. }
  18055. throw new Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in " + 'React. Please file an issue.');
  18056. }
  18057. function markUpdate(workInProgress) {
  18058. // Tag the fiber with an update effect. This turns a Placement into
  18059. // a PlacementAndUpdate.
  18060. workInProgress.flags |= Update;
  18061. }
  18062. function markRef$1(workInProgress) {
  18063. workInProgress.flags |= Ref;
  18064. {
  18065. workInProgress.flags |= RefStatic;
  18066. }
  18067. }
  18068. var appendAllChildren;
  18069. var updateHostContainer;
  18070. var updateHostComponent$1;
  18071. var updateHostText$1;
  18072. {
  18073. // Mutation mode
  18074. appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
  18075. // We only have the top Fiber that was created but we need recurse down its
  18076. // children to find all the terminal nodes.
  18077. var node = workInProgress.child;
  18078. while (node !== null) {
  18079. if (node.tag === HostComponent || node.tag === HostText) {
  18080. appendInitialChild(parent, node.stateNode);
  18081. } else if (node.tag === HostPortal) ; else if (node.child !== null) {
  18082. node.child.return = node;
  18083. node = node.child;
  18084. continue;
  18085. }
  18086. if (node === workInProgress) {
  18087. return;
  18088. }
  18089. while (node.sibling === null) {
  18090. if (node.return === null || node.return === workInProgress) {
  18091. return;
  18092. }
  18093. node = node.return;
  18094. }
  18095. node.sibling.return = node.return;
  18096. node = node.sibling;
  18097. }
  18098. };
  18099. updateHostContainer = function (current, workInProgress) {// Noop
  18100. };
  18101. updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
  18102. // If we have an alternate, that means this is an update and we need to
  18103. // schedule a side-effect to do the updates.
  18104. var oldProps = current.memoizedProps;
  18105. if (oldProps === newProps) {
  18106. // In mutation mode, this is sufficient for a bailout because
  18107. // we won't touch this node even if children changed.
  18108. return;
  18109. } // If we get updated because one of our children updated, we don't
  18110. // have newProps so we'll have to reuse them.
  18111. // TODO: Split the update API as separate for the props vs. children.
  18112. // Even better would be if children weren't special cased at all tho.
  18113. var instance = workInProgress.stateNode;
  18114. var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
  18115. // component is hitting the resume path. Figure out why. Possibly
  18116. // related to `hidden`.
  18117. var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext); // TODO: Type this specific to this type of component.
  18118. workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  18119. // is a new ref we mark this as an update. All the work is done in commitWork.
  18120. if (updatePayload) {
  18121. markUpdate(workInProgress);
  18122. }
  18123. };
  18124. updateHostText$1 = function (current, workInProgress, oldText, newText) {
  18125. // If the text differs, mark it as an update. All the work in done in commitWork.
  18126. if (oldText !== newText) {
  18127. markUpdate(workInProgress);
  18128. }
  18129. };
  18130. }
  18131. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  18132. if (getIsHydrating()) {
  18133. // If we're hydrating, we should consume as many items as we can
  18134. // so we don't leave any behind.
  18135. return;
  18136. }
  18137. switch (renderState.tailMode) {
  18138. case 'hidden':
  18139. {
  18140. // Any insertions at the end of the tail list after this point
  18141. // should be invisible. If there are already mounted boundaries
  18142. // anything before them are not considered for collapsing.
  18143. // Therefore we need to go through the whole tail to find if
  18144. // there are any.
  18145. var tailNode = renderState.tail;
  18146. var lastTailNode = null;
  18147. while (tailNode !== null) {
  18148. if (tailNode.alternate !== null) {
  18149. lastTailNode = tailNode;
  18150. }
  18151. tailNode = tailNode.sibling;
  18152. } // Next we're simply going to delete all insertions after the
  18153. // last rendered item.
  18154. if (lastTailNode === null) {
  18155. // All remaining items in the tail are insertions.
  18156. renderState.tail = null;
  18157. } else {
  18158. // Detach the insertion after the last node that was already
  18159. // inserted.
  18160. lastTailNode.sibling = null;
  18161. }
  18162. break;
  18163. }
  18164. case 'collapsed':
  18165. {
  18166. // Any insertions at the end of the tail list after this point
  18167. // should be invisible. If there are already mounted boundaries
  18168. // anything before them are not considered for collapsing.
  18169. // Therefore we need to go through the whole tail to find if
  18170. // there are any.
  18171. var _tailNode = renderState.tail;
  18172. var _lastTailNode = null;
  18173. while (_tailNode !== null) {
  18174. if (_tailNode.alternate !== null) {
  18175. _lastTailNode = _tailNode;
  18176. }
  18177. _tailNode = _tailNode.sibling;
  18178. } // Next we're simply going to delete all insertions after the
  18179. // last rendered item.
  18180. if (_lastTailNode === null) {
  18181. // All remaining items in the tail are insertions.
  18182. if (!hasRenderedATailFallback && renderState.tail !== null) {
  18183. // We suspended during the head. We want to show at least one
  18184. // row at the tail. So we'll keep on and cut off the rest.
  18185. renderState.tail.sibling = null;
  18186. } else {
  18187. renderState.tail = null;
  18188. }
  18189. } else {
  18190. // Detach the insertion after the last node that was already
  18191. // inserted.
  18192. _lastTailNode.sibling = null;
  18193. }
  18194. break;
  18195. }
  18196. }
  18197. }
  18198. function bubbleProperties(completedWork) {
  18199. var didBailout = completedWork.alternate !== null && completedWork.alternate.child === completedWork.child;
  18200. var newChildLanes = NoLanes;
  18201. var subtreeFlags = NoFlags;
  18202. if (!didBailout) {
  18203. // Bubble up the earliest expiration time.
  18204. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  18205. // In profiling mode, resetChildExpirationTime is also used to reset
  18206. // profiler durations.
  18207. var actualDuration = completedWork.actualDuration;
  18208. var treeBaseDuration = completedWork.selfBaseDuration;
  18209. var child = completedWork.child;
  18210. while (child !== null) {
  18211. newChildLanes = mergeLanes(newChildLanes, mergeLanes(child.lanes, child.childLanes));
  18212. subtreeFlags |= child.subtreeFlags;
  18213. subtreeFlags |= child.flags; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  18214. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  18215. // When work is done, it should bubble to the parent's actualDuration. If
  18216. // the fiber has not been cloned though, (meaning no work was done), then
  18217. // this value will reflect the amount of time spent working on a previous
  18218. // render. In that case it should not bubble. We determine whether it was
  18219. // cloned by comparing the child pointer.
  18220. actualDuration += child.actualDuration;
  18221. treeBaseDuration += child.treeBaseDuration;
  18222. child = child.sibling;
  18223. }
  18224. completedWork.actualDuration = actualDuration;
  18225. completedWork.treeBaseDuration = treeBaseDuration;
  18226. } else {
  18227. var _child = completedWork.child;
  18228. while (_child !== null) {
  18229. newChildLanes = mergeLanes(newChildLanes, mergeLanes(_child.lanes, _child.childLanes));
  18230. subtreeFlags |= _child.subtreeFlags;
  18231. subtreeFlags |= _child.flags; // Update the return pointer so the tree is consistent. This is a code
  18232. // smell because it assumes the commit phase is never concurrent with
  18233. // the render phase. Will address during refactor to alternate model.
  18234. _child.return = completedWork;
  18235. _child = _child.sibling;
  18236. }
  18237. }
  18238. completedWork.subtreeFlags |= subtreeFlags;
  18239. } else {
  18240. // Bubble up the earliest expiration time.
  18241. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  18242. // In profiling mode, resetChildExpirationTime is also used to reset
  18243. // profiler durations.
  18244. var _treeBaseDuration = completedWork.selfBaseDuration;
  18245. var _child2 = completedWork.child;
  18246. while (_child2 !== null) {
  18247. newChildLanes = mergeLanes(newChildLanes, mergeLanes(_child2.lanes, _child2.childLanes)); // "Static" flags share the lifetime of the fiber/hook they belong to,
  18248. // so we should bubble those up even during a bailout. All the other
  18249. // flags have a lifetime only of a single render + commit, so we should
  18250. // ignore them.
  18251. subtreeFlags |= _child2.subtreeFlags & StaticMask;
  18252. subtreeFlags |= _child2.flags & StaticMask;
  18253. _treeBaseDuration += _child2.treeBaseDuration;
  18254. _child2 = _child2.sibling;
  18255. }
  18256. completedWork.treeBaseDuration = _treeBaseDuration;
  18257. } else {
  18258. var _child3 = completedWork.child;
  18259. while (_child3 !== null) {
  18260. newChildLanes = mergeLanes(newChildLanes, mergeLanes(_child3.lanes, _child3.childLanes)); // "Static" flags share the lifetime of the fiber/hook they belong to,
  18261. // so we should bubble those up even during a bailout. All the other
  18262. // flags have a lifetime only of a single render + commit, so we should
  18263. // ignore them.
  18264. subtreeFlags |= _child3.subtreeFlags & StaticMask;
  18265. subtreeFlags |= _child3.flags & StaticMask; // Update the return pointer so the tree is consistent. This is a code
  18266. // smell because it assumes the commit phase is never concurrent with
  18267. // the render phase. Will address during refactor to alternate model.
  18268. _child3.return = completedWork;
  18269. _child3 = _child3.sibling;
  18270. }
  18271. }
  18272. completedWork.subtreeFlags |= subtreeFlags;
  18273. }
  18274. completedWork.childLanes = newChildLanes;
  18275. return didBailout;
  18276. }
  18277. function completeDehydratedSuspenseBoundary(current, workInProgress, nextState) {
  18278. if (hasUnhydratedTailNodes() && (workInProgress.mode & ConcurrentMode) !== NoMode && (workInProgress.flags & DidCapture) === NoFlags) {
  18279. warnIfUnhydratedTailNodes(workInProgress);
  18280. resetHydrationState();
  18281. workInProgress.flags |= ForceClientRender | Incomplete | ShouldCapture;
  18282. return false;
  18283. }
  18284. var wasHydrated = popHydrationState(workInProgress);
  18285. if (nextState !== null && nextState.dehydrated !== null) {
  18286. // We might be inside a hydration state the first time we're picking up this
  18287. // Suspense boundary, and also after we've reentered it for further hydration.
  18288. if (current === null) {
  18289. if (!wasHydrated) {
  18290. throw new Error('A dehydrated suspense component was completed without a hydrated node. ' + 'This is probably a bug in React.');
  18291. }
  18292. prepareToHydrateHostSuspenseInstance(workInProgress);
  18293. bubbleProperties(workInProgress);
  18294. {
  18295. if ((workInProgress.mode & ProfileMode) !== NoMode) {
  18296. var isTimedOutSuspense = nextState !== null;
  18297. if (isTimedOutSuspense) {
  18298. // Don't count time spent in a timed out Suspense subtree as part of the base duration.
  18299. var primaryChildFragment = workInProgress.child;
  18300. if (primaryChildFragment !== null) {
  18301. // $FlowFixMe Flow doesn't support type casting in combination with the -= operator
  18302. workInProgress.treeBaseDuration -= primaryChildFragment.treeBaseDuration;
  18303. }
  18304. }
  18305. }
  18306. }
  18307. return false;
  18308. } else {
  18309. // We might have reentered this boundary to hydrate it. If so, we need to reset the hydration
  18310. // state since we're now exiting out of it. popHydrationState doesn't do that for us.
  18311. resetHydrationState();
  18312. if ((workInProgress.flags & DidCapture) === NoFlags) {
  18313. // This boundary did not suspend so it's now hydrated and unsuspended.
  18314. workInProgress.memoizedState = null;
  18315. } // If nothing suspended, we need to schedule an effect to mark this boundary
  18316. // as having hydrated so events know that they're free to be invoked.
  18317. // It's also a signal to replay events and the suspense callback.
  18318. // If something suspended, schedule an effect to attach retry listeners.
  18319. // So we might as well always mark this.
  18320. workInProgress.flags |= Update;
  18321. bubbleProperties(workInProgress);
  18322. {
  18323. if ((workInProgress.mode & ProfileMode) !== NoMode) {
  18324. var _isTimedOutSuspense = nextState !== null;
  18325. if (_isTimedOutSuspense) {
  18326. // Don't count time spent in a timed out Suspense subtree as part of the base duration.
  18327. var _primaryChildFragment = workInProgress.child;
  18328. if (_primaryChildFragment !== null) {
  18329. // $FlowFixMe Flow doesn't support type casting in combination with the -= operator
  18330. workInProgress.treeBaseDuration -= _primaryChildFragment.treeBaseDuration;
  18331. }
  18332. }
  18333. }
  18334. }
  18335. return false;
  18336. }
  18337. } else {
  18338. // Successfully completed this tree. If this was a forced client render,
  18339. // there may have been recoverable errors during first hydration
  18340. // attempt. If so, add them to a queue so we can log them in the
  18341. // commit phase.
  18342. upgradeHydrationErrorsToRecoverable(); // Fall through to normal Suspense path
  18343. return true;
  18344. }
  18345. }
  18346. function completeWork(current, workInProgress, renderLanes) {
  18347. var newProps = workInProgress.pendingProps; // Note: This intentionally doesn't check if we're hydrating because comparing
  18348. // to the current tree provider fiber is just as fast and less error-prone.
  18349. // Ideally we would have a special version of the work loop only
  18350. // for hydration.
  18351. popTreeContext(workInProgress);
  18352. switch (workInProgress.tag) {
  18353. case IndeterminateComponent:
  18354. case LazyComponent:
  18355. case SimpleMemoComponent:
  18356. case FunctionComponent:
  18357. case ForwardRef:
  18358. case Fragment:
  18359. case Mode:
  18360. case Profiler:
  18361. case ContextConsumer:
  18362. case MemoComponent:
  18363. bubbleProperties(workInProgress);
  18364. return null;
  18365. case ClassComponent:
  18366. {
  18367. var Component = workInProgress.type;
  18368. if (isContextProvider(Component)) {
  18369. popContext(workInProgress);
  18370. }
  18371. bubbleProperties(workInProgress);
  18372. return null;
  18373. }
  18374. case HostRoot:
  18375. {
  18376. var fiberRoot = workInProgress.stateNode;
  18377. popHostContainer(workInProgress);
  18378. popTopLevelContextObject(workInProgress);
  18379. resetWorkInProgressVersions();
  18380. if (fiberRoot.pendingContext) {
  18381. fiberRoot.context = fiberRoot.pendingContext;
  18382. fiberRoot.pendingContext = null;
  18383. }
  18384. if (current === null || current.child === null) {
  18385. // If we hydrated, pop so that we can delete any remaining children
  18386. // that weren't hydrated.
  18387. var wasHydrated = popHydrationState(workInProgress);
  18388. if (wasHydrated) {
  18389. // If we hydrated, then we'll need to schedule an update for
  18390. // the commit side-effects on the root.
  18391. markUpdate(workInProgress);
  18392. } else {
  18393. if (current !== null) {
  18394. var prevState = current.memoizedState;
  18395. if ( // Check if this is a client root
  18396. !prevState.isDehydrated || // Check if we reverted to client rendering (e.g. due to an error)
  18397. (workInProgress.flags & ForceClientRender) !== NoFlags) {
  18398. // Schedule an effect to clear this container at the start of the
  18399. // next commit. This handles the case of React rendering into a
  18400. // container with previous children. It's also safe to do for
  18401. // updates too, because current.child would only be null if the
  18402. // previous render was null (so the container would already
  18403. // be empty).
  18404. workInProgress.flags |= Snapshot; // If this was a forced client render, there may have been
  18405. // recoverable errors during first hydration attempt. If so, add
  18406. // them to a queue so we can log them in the commit phase.
  18407. upgradeHydrationErrorsToRecoverable();
  18408. }
  18409. }
  18410. }
  18411. }
  18412. updateHostContainer(current, workInProgress);
  18413. bubbleProperties(workInProgress);
  18414. return null;
  18415. }
  18416. case HostComponent:
  18417. {
  18418. popHostContext(workInProgress);
  18419. var rootContainerInstance = getRootHostContainer();
  18420. var type = workInProgress.type;
  18421. if (current !== null && workInProgress.stateNode != null) {
  18422. updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
  18423. if (current.ref !== workInProgress.ref) {
  18424. markRef$1(workInProgress);
  18425. }
  18426. } else {
  18427. if (!newProps) {
  18428. if (workInProgress.stateNode === null) {
  18429. throw new Error('We must have new props for new mounts. This error is likely ' + 'caused by a bug in React. Please file an issue.');
  18430. } // This can happen when we abort work.
  18431. bubbleProperties(workInProgress);
  18432. return null;
  18433. }
  18434. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  18435. // "stack" as the parent. Then append children as we go in beginWork
  18436. // or completeWork depending on whether we want to add them top->down or
  18437. // bottom->up. Top->down is faster in IE11.
  18438. var _wasHydrated = popHydrationState(workInProgress);
  18439. if (_wasHydrated) {
  18440. // TODO: Move this and createInstance step into the beginPhase
  18441. // to consolidate.
  18442. if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
  18443. // If changes to the hydrated node need to be applied at the
  18444. // commit-phase we mark this as such.
  18445. markUpdate(workInProgress);
  18446. }
  18447. } else {
  18448. var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
  18449. appendAllChildren(instance, workInProgress, false, false);
  18450. workInProgress.stateNode = instance; // Certain renderers require commit-time effects for initial mount.
  18451. // (eg DOM renderer supports auto-focus for certain elements).
  18452. // Make sure such renderers get scheduled for later work.
  18453. if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance)) {
  18454. markUpdate(workInProgress);
  18455. }
  18456. }
  18457. if (workInProgress.ref !== null) {
  18458. // If there is a ref on a host node we need to schedule a callback
  18459. markRef$1(workInProgress);
  18460. }
  18461. }
  18462. bubbleProperties(workInProgress);
  18463. return null;
  18464. }
  18465. case HostText:
  18466. {
  18467. var newText = newProps;
  18468. if (current && workInProgress.stateNode != null) {
  18469. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  18470. // to schedule a side-effect to do the updates.
  18471. updateHostText$1(current, workInProgress, oldText, newText);
  18472. } else {
  18473. if (typeof newText !== 'string') {
  18474. if (workInProgress.stateNode === null) {
  18475. throw new Error('We must have new props for new mounts. This error is likely ' + 'caused by a bug in React. Please file an issue.');
  18476. } // This can happen when we abort work.
  18477. }
  18478. var _rootContainerInstance = getRootHostContainer();
  18479. var _currentHostContext = getHostContext();
  18480. var _wasHydrated2 = popHydrationState(workInProgress);
  18481. if (_wasHydrated2) {
  18482. if (prepareToHydrateHostTextInstance(workInProgress)) {
  18483. markUpdate(workInProgress);
  18484. }
  18485. } else {
  18486. workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
  18487. }
  18488. }
  18489. bubbleProperties(workInProgress);
  18490. return null;
  18491. }
  18492. case SuspenseComponent:
  18493. {
  18494. popSuspenseContext(workInProgress);
  18495. var nextState = workInProgress.memoizedState; // Special path for dehydrated boundaries. We may eventually move this
  18496. // to its own fiber type so that we can add other kinds of hydration
  18497. // boundaries that aren't associated with a Suspense tree. In anticipation
  18498. // of such a refactor, all the hydration logic is contained in
  18499. // this branch.
  18500. if (current === null || current.memoizedState !== null && current.memoizedState.dehydrated !== null) {
  18501. var fallthroughToNormalSuspensePath = completeDehydratedSuspenseBoundary(current, workInProgress, nextState);
  18502. if (!fallthroughToNormalSuspensePath) {
  18503. if (workInProgress.flags & ShouldCapture) {
  18504. // Special case. There were remaining unhydrated nodes. We treat
  18505. // this as a mismatch. Revert to client rendering.
  18506. return workInProgress;
  18507. } else {
  18508. // Did not finish hydrating, either because this is the initial
  18509. // render or because something suspended.
  18510. return null;
  18511. }
  18512. } // Continue with the normal Suspense path.
  18513. }
  18514. if ((workInProgress.flags & DidCapture) !== NoFlags) {
  18515. // Something suspended. Re-render with the fallback children.
  18516. workInProgress.lanes = renderLanes; // Do not reset the effect list.
  18517. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  18518. transferActualDuration(workInProgress);
  18519. } // Don't bubble properties in this case.
  18520. return workInProgress;
  18521. }
  18522. var nextDidTimeout = nextState !== null;
  18523. var prevDidTimeout = current !== null && current.memoizedState !== null;
  18524. // a passive effect, which is when we process the transitions
  18525. if (nextDidTimeout !== prevDidTimeout) {
  18526. // an effect to toggle the subtree's visibility. When we switch from
  18527. // fallback -> primary, the inner Offscreen fiber schedules this effect
  18528. // as part of its normal complete phase. But when we switch from
  18529. // primary -> fallback, the inner Offscreen fiber does not have a complete
  18530. // phase. So we need to schedule its effect here.
  18531. //
  18532. // We also use this flag to connect/disconnect the effects, but the same
  18533. // logic applies: when re-connecting, the Offscreen fiber's complete
  18534. // phase will handle scheduling the effect. It's only when the fallback
  18535. // is active that we have to do anything special.
  18536. if (nextDidTimeout) {
  18537. var _offscreenFiber2 = workInProgress.child;
  18538. _offscreenFiber2.flags |= Visibility; // TODO: This will still suspend a synchronous tree if anything
  18539. // in the concurrent tree already suspended during this render.
  18540. // This is a known bug.
  18541. if ((workInProgress.mode & ConcurrentMode) !== NoMode) {
  18542. // TODO: Move this back to throwException because this is too late
  18543. // if this is a large tree which is common for initial loads. We
  18544. // don't know if we should restart a render or not until we get
  18545. // this marker, and this is too late.
  18546. // If this render already had a ping or lower pri updates,
  18547. // and this is the first time we know we're going to suspend we
  18548. // should be able to immediately restart from within throwException.
  18549. var hasInvisibleChildContext = current === null && (workInProgress.memoizedProps.unstable_avoidThisFallback !== true || !enableSuspenseAvoidThisFallback);
  18550. if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
  18551. // If this was in an invisible tree or a new render, then showing
  18552. // this boundary is ok.
  18553. renderDidSuspend();
  18554. } else {
  18555. // Otherwise, we're going to have to hide content so we should
  18556. // suspend for longer if possible.
  18557. renderDidSuspendDelayIfPossible();
  18558. }
  18559. }
  18560. }
  18561. }
  18562. var wakeables = workInProgress.updateQueue;
  18563. if (wakeables !== null) {
  18564. // Schedule an effect to attach a retry listener to the promise.
  18565. // TODO: Move to passive phase
  18566. workInProgress.flags |= Update;
  18567. }
  18568. bubbleProperties(workInProgress);
  18569. {
  18570. if ((workInProgress.mode & ProfileMode) !== NoMode) {
  18571. if (nextDidTimeout) {
  18572. // Don't count time spent in a timed out Suspense subtree as part of the base duration.
  18573. var primaryChildFragment = workInProgress.child;
  18574. if (primaryChildFragment !== null) {
  18575. // $FlowFixMe Flow doesn't support type casting in combination with the -= operator
  18576. workInProgress.treeBaseDuration -= primaryChildFragment.treeBaseDuration;
  18577. }
  18578. }
  18579. }
  18580. }
  18581. return null;
  18582. }
  18583. case HostPortal:
  18584. popHostContainer(workInProgress);
  18585. updateHostContainer(current, workInProgress);
  18586. if (current === null) {
  18587. preparePortalMount(workInProgress.stateNode.containerInfo);
  18588. }
  18589. bubbleProperties(workInProgress);
  18590. return null;
  18591. case ContextProvider:
  18592. // Pop provider fiber
  18593. var context = workInProgress.type._context;
  18594. popProvider(context, workInProgress);
  18595. bubbleProperties(workInProgress);
  18596. return null;
  18597. case IncompleteClassComponent:
  18598. {
  18599. // Same as class component case. I put it down here so that the tags are
  18600. // sequential to ensure this switch is compiled to a jump table.
  18601. var _Component = workInProgress.type;
  18602. if (isContextProvider(_Component)) {
  18603. popContext(workInProgress);
  18604. }
  18605. bubbleProperties(workInProgress);
  18606. return null;
  18607. }
  18608. case SuspenseListComponent:
  18609. {
  18610. popSuspenseContext(workInProgress);
  18611. var renderState = workInProgress.memoizedState;
  18612. if (renderState === null) {
  18613. // We're running in the default, "independent" mode.
  18614. // We don't do anything in this mode.
  18615. bubbleProperties(workInProgress);
  18616. return null;
  18617. }
  18618. var didSuspendAlready = (workInProgress.flags & DidCapture) !== NoFlags;
  18619. var renderedTail = renderState.rendering;
  18620. if (renderedTail === null) {
  18621. // We just rendered the head.
  18622. if (!didSuspendAlready) {
  18623. // This is the first pass. We need to figure out if anything is still
  18624. // suspended in the rendered set.
  18625. // If new content unsuspended, but there's still some content that
  18626. // didn't. Then we need to do a second pass that forces everything
  18627. // to keep showing their fallbacks.
  18628. // We might be suspended if something in this render pass suspended, or
  18629. // something in the previous committed pass suspended. Otherwise,
  18630. // there's no chance so we can skip the expensive call to
  18631. // findFirstSuspended.
  18632. var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.flags & DidCapture) === NoFlags);
  18633. if (!cannotBeSuspended) {
  18634. var row = workInProgress.child;
  18635. while (row !== null) {
  18636. var suspended = findFirstSuspended(row);
  18637. if (suspended !== null) {
  18638. didSuspendAlready = true;
  18639. workInProgress.flags |= DidCapture;
  18640. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  18641. // part of the second pass. In that case nothing will subscribe to
  18642. // its thenables. Instead, we'll transfer its thenables to the
  18643. // SuspenseList so that it can retry if they resolve.
  18644. // There might be multiple of these in the list but since we're
  18645. // going to wait for all of them anyway, it doesn't really matter
  18646. // which ones gets to ping. In theory we could get clever and keep
  18647. // track of how many dependencies remain but it gets tricky because
  18648. // in the meantime, we can add/remove/change items and dependencies.
  18649. // We might bail out of the loop before finding any but that
  18650. // doesn't matter since that means that the other boundaries that
  18651. // we did find already has their listeners attached.
  18652. var newThenables = suspended.updateQueue;
  18653. if (newThenables !== null) {
  18654. workInProgress.updateQueue = newThenables;
  18655. workInProgress.flags |= Update;
  18656. } // Rerender the whole list, but this time, we'll force fallbacks
  18657. // to stay in place.
  18658. // Reset the effect flags before doing the second pass since that's now invalid.
  18659. // Reset the child fibers to their original state.
  18660. workInProgress.subtreeFlags = NoFlags;
  18661. resetChildFibers(workInProgress, renderLanes); // Set up the Suspense Context to force suspense and immediately
  18662. // rerender the children.
  18663. pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback)); // Don't bubble properties in this case.
  18664. return workInProgress.child;
  18665. }
  18666. row = row.sibling;
  18667. }
  18668. }
  18669. if (renderState.tail !== null && now() > getRenderTargetTime()) {
  18670. // We have already passed our CPU deadline but we still have rows
  18671. // left in the tail. We'll just give up further attempts to render
  18672. // the main content and only render fallbacks.
  18673. workInProgress.flags |= DidCapture;
  18674. didSuspendAlready = true;
  18675. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  18676. // to get it started back up to attempt the next item. While in terms
  18677. // of priority this work has the same priority as this current render,
  18678. // it's not part of the same transition once the transition has
  18679. // committed. If it's sync, we still want to yield so that it can be
  18680. // painted. Conceptually, this is really the same as pinging.
  18681. // We can use any RetryLane even if it's the one currently rendering
  18682. // since we're leaving it behind on this node.
  18683. workInProgress.lanes = SomeRetryLane;
  18684. }
  18685. } else {
  18686. cutOffTailIfNeeded(renderState, false);
  18687. } // Next we're going to render the tail.
  18688. } else {
  18689. // Append the rendered row to the child list.
  18690. if (!didSuspendAlready) {
  18691. var _suspended = findFirstSuspended(renderedTail);
  18692. if (_suspended !== null) {
  18693. workInProgress.flags |= DidCapture;
  18694. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  18695. // get lost if this row ends up dropped during a second pass.
  18696. var _newThenables = _suspended.updateQueue;
  18697. if (_newThenables !== null) {
  18698. workInProgress.updateQueue = _newThenables;
  18699. workInProgress.flags |= Update;
  18700. }
  18701. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  18702. if (renderState.tail === null && renderState.tailMode === 'hidden' && !renderedTail.alternate && !getIsHydrating() // We don't cut it if we're hydrating.
  18703. ) {
  18704. // We're done.
  18705. bubbleProperties(workInProgress);
  18706. return null;
  18707. }
  18708. } else if ( // The time it took to render last row is greater than the remaining
  18709. // time we have to render. So rendering one more row would likely
  18710. // exceed it.
  18711. now() * 2 - renderState.renderingStartTime > getRenderTargetTime() && renderLanes !== OffscreenLane) {
  18712. // We have now passed our CPU deadline and we'll just give up further
  18713. // attempts to render the main content and only render fallbacks.
  18714. // The assumption is that this is usually faster.
  18715. workInProgress.flags |= DidCapture;
  18716. didSuspendAlready = true;
  18717. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  18718. // to get it started back up to attempt the next item. While in terms
  18719. // of priority this work has the same priority as this current render,
  18720. // it's not part of the same transition once the transition has
  18721. // committed. If it's sync, we still want to yield so that it can be
  18722. // painted. Conceptually, this is really the same as pinging.
  18723. // We can use any RetryLane even if it's the one currently rendering
  18724. // since we're leaving it behind on this node.
  18725. workInProgress.lanes = SomeRetryLane;
  18726. }
  18727. }
  18728. if (renderState.isBackwards) {
  18729. // The effect list of the backwards tail will have been added
  18730. // to the end. This breaks the guarantee that life-cycles fire in
  18731. // sibling order but that isn't a strong guarantee promised by React.
  18732. // Especially since these might also just pop in during future commits.
  18733. // Append to the beginning of the list.
  18734. renderedTail.sibling = workInProgress.child;
  18735. workInProgress.child = renderedTail;
  18736. } else {
  18737. var previousSibling = renderState.last;
  18738. if (previousSibling !== null) {
  18739. previousSibling.sibling = renderedTail;
  18740. } else {
  18741. workInProgress.child = renderedTail;
  18742. }
  18743. renderState.last = renderedTail;
  18744. }
  18745. }
  18746. if (renderState.tail !== null) {
  18747. // We still have tail rows to render.
  18748. // Pop a row.
  18749. var next = renderState.tail;
  18750. renderState.rendering = next;
  18751. renderState.tail = next.sibling;
  18752. renderState.renderingStartTime = now();
  18753. next.sibling = null; // Restore the context.
  18754. // TODO: We can probably just avoid popping it instead and only
  18755. // setting it the first time we go from not suspended to suspended.
  18756. var suspenseContext = suspenseStackCursor.current;
  18757. if (didSuspendAlready) {
  18758. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  18759. } else {
  18760. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  18761. }
  18762. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  18763. // Don't bubble properties in this case.
  18764. return next;
  18765. }
  18766. bubbleProperties(workInProgress);
  18767. return null;
  18768. }
  18769. case ScopeComponent:
  18770. {
  18771. break;
  18772. }
  18773. case OffscreenComponent:
  18774. case LegacyHiddenComponent:
  18775. {
  18776. popRenderLanes(workInProgress);
  18777. var _nextState = workInProgress.memoizedState;
  18778. var nextIsHidden = _nextState !== null;
  18779. if (current !== null) {
  18780. var _prevState = current.memoizedState;
  18781. var prevIsHidden = _prevState !== null;
  18782. if (prevIsHidden !== nextIsHidden && ( // LegacyHidden doesn't do any hiding — it only pre-renders.
  18783. !enableLegacyHidden )) {
  18784. workInProgress.flags |= Visibility;
  18785. }
  18786. }
  18787. if (!nextIsHidden || (workInProgress.mode & ConcurrentMode) === NoMode) {
  18788. bubbleProperties(workInProgress);
  18789. } else {
  18790. // Don't bubble properties for hidden children unless we're rendering
  18791. // at offscreen priority.
  18792. if (includesSomeLane(subtreeRenderLanes, OffscreenLane)) {
  18793. bubbleProperties(workInProgress);
  18794. {
  18795. // Check if there was an insertion or update in the hidden subtree.
  18796. // If so, we need to hide those nodes in the commit phase, so
  18797. // schedule a visibility effect.
  18798. if ( workInProgress.subtreeFlags & (Placement | Update)) {
  18799. workInProgress.flags |= Visibility;
  18800. }
  18801. }
  18802. }
  18803. }
  18804. return null;
  18805. }
  18806. case CacheComponent:
  18807. {
  18808. return null;
  18809. }
  18810. case TracingMarkerComponent:
  18811. {
  18812. return null;
  18813. }
  18814. }
  18815. throw new Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in " + 'React. Please file an issue.');
  18816. }
  18817. function unwindWork(current, workInProgress, renderLanes) {
  18818. // Note: This intentionally doesn't check if we're hydrating because comparing
  18819. // to the current tree provider fiber is just as fast and less error-prone.
  18820. // Ideally we would have a special version of the work loop only
  18821. // for hydration.
  18822. popTreeContext(workInProgress);
  18823. switch (workInProgress.tag) {
  18824. case ClassComponent:
  18825. {
  18826. var Component = workInProgress.type;
  18827. if (isContextProvider(Component)) {
  18828. popContext(workInProgress);
  18829. }
  18830. var flags = workInProgress.flags;
  18831. if (flags & ShouldCapture) {
  18832. workInProgress.flags = flags & ~ShouldCapture | DidCapture;
  18833. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  18834. transferActualDuration(workInProgress);
  18835. }
  18836. return workInProgress;
  18837. }
  18838. return null;
  18839. }
  18840. case HostRoot:
  18841. {
  18842. var root = workInProgress.stateNode;
  18843. popHostContainer(workInProgress);
  18844. popTopLevelContextObject(workInProgress);
  18845. resetWorkInProgressVersions();
  18846. var _flags = workInProgress.flags;
  18847. if ((_flags & ShouldCapture) !== NoFlags && (_flags & DidCapture) === NoFlags) {
  18848. // There was an error during render that wasn't captured by a suspense
  18849. // boundary. Do a second pass on the root to unmount the children.
  18850. workInProgress.flags = _flags & ~ShouldCapture | DidCapture;
  18851. return workInProgress;
  18852. } // We unwound to the root without completing it. Exit.
  18853. return null;
  18854. }
  18855. case HostComponent:
  18856. {
  18857. // TODO: popHydrationState
  18858. popHostContext(workInProgress);
  18859. return null;
  18860. }
  18861. case SuspenseComponent:
  18862. {
  18863. popSuspenseContext(workInProgress);
  18864. var suspenseState = workInProgress.memoizedState;
  18865. if (suspenseState !== null && suspenseState.dehydrated !== null) {
  18866. if (workInProgress.alternate === null) {
  18867. throw new Error('Threw in newly mounted dehydrated component. This is likely a bug in ' + 'React. Please file an issue.');
  18868. }
  18869. resetHydrationState();
  18870. }
  18871. var _flags2 = workInProgress.flags;
  18872. if (_flags2 & ShouldCapture) {
  18873. workInProgress.flags = _flags2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
  18874. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  18875. transferActualDuration(workInProgress);
  18876. }
  18877. return workInProgress;
  18878. }
  18879. return null;
  18880. }
  18881. case SuspenseListComponent:
  18882. {
  18883. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  18884. // caught by a nested boundary. If not, it should bubble through.
  18885. return null;
  18886. }
  18887. case HostPortal:
  18888. popHostContainer(workInProgress);
  18889. return null;
  18890. case ContextProvider:
  18891. var context = workInProgress.type._context;
  18892. popProvider(context, workInProgress);
  18893. return null;
  18894. case OffscreenComponent:
  18895. case LegacyHiddenComponent:
  18896. popRenderLanes(workInProgress);
  18897. return null;
  18898. case CacheComponent:
  18899. return null;
  18900. default:
  18901. return null;
  18902. }
  18903. }
  18904. function unwindInterruptedWork(current, interruptedWork, renderLanes) {
  18905. // Note: This intentionally doesn't check if we're hydrating because comparing
  18906. // to the current tree provider fiber is just as fast and less error-prone.
  18907. // Ideally we would have a special version of the work loop only
  18908. // for hydration.
  18909. popTreeContext(interruptedWork);
  18910. switch (interruptedWork.tag) {
  18911. case ClassComponent:
  18912. {
  18913. var childContextTypes = interruptedWork.type.childContextTypes;
  18914. if (childContextTypes !== null && childContextTypes !== undefined) {
  18915. popContext(interruptedWork);
  18916. }
  18917. break;
  18918. }
  18919. case HostRoot:
  18920. {
  18921. var root = interruptedWork.stateNode;
  18922. popHostContainer(interruptedWork);
  18923. popTopLevelContextObject(interruptedWork);
  18924. resetWorkInProgressVersions();
  18925. break;
  18926. }
  18927. case HostComponent:
  18928. {
  18929. popHostContext(interruptedWork);
  18930. break;
  18931. }
  18932. case HostPortal:
  18933. popHostContainer(interruptedWork);
  18934. break;
  18935. case SuspenseComponent:
  18936. popSuspenseContext(interruptedWork);
  18937. break;
  18938. case SuspenseListComponent:
  18939. popSuspenseContext(interruptedWork);
  18940. break;
  18941. case ContextProvider:
  18942. var context = interruptedWork.type._context;
  18943. popProvider(context, interruptedWork);
  18944. break;
  18945. case OffscreenComponent:
  18946. case LegacyHiddenComponent:
  18947. popRenderLanes(interruptedWork);
  18948. break;
  18949. }
  18950. }
  18951. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  18952. {
  18953. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  18954. } // Used during the commit phase to track the state of the Offscreen component stack.
  18955. // Allows us to avoid traversing the return path to find the nearest Offscreen ancestor.
  18956. // Only used when enableSuspenseLayoutEffectSemantics is enabled.
  18957. var offscreenSubtreeIsHidden = false;
  18958. var offscreenSubtreeWasHidden = false;
  18959. var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
  18960. var nextEffect = null; // Used for Profiling builds to track updaters.
  18961. var inProgressLanes = null;
  18962. var inProgressRoot = null;
  18963. function reportUncaughtErrorInDEV(error) {
  18964. // Wrapping each small part of the commit phase into a guarded
  18965. // callback is a bit too slow (https://github.com/facebook/react/pull/21666).
  18966. // But we rely on it to surface errors to DEV tools like overlays
  18967. // (https://github.com/facebook/react/issues/21712).
  18968. // As a compromise, rethrow only caught errors in a guard.
  18969. {
  18970. invokeGuardedCallback(null, function () {
  18971. throw error;
  18972. });
  18973. clearCaughtError();
  18974. }
  18975. }
  18976. var callComponentWillUnmountWithTimer = function (current, instance) {
  18977. instance.props = current.memoizedProps;
  18978. instance.state = current.memoizedState;
  18979. if ( current.mode & ProfileMode) {
  18980. try {
  18981. startLayoutEffectTimer();
  18982. instance.componentWillUnmount();
  18983. } finally {
  18984. recordLayoutEffectDuration(current);
  18985. }
  18986. } else {
  18987. instance.componentWillUnmount();
  18988. }
  18989. }; // Capture errors so they don't interrupt mounting.
  18990. function safelyCallCommitHookLayoutEffectListMount(current, nearestMountedAncestor) {
  18991. try {
  18992. commitHookEffectListMount(Layout, current);
  18993. } catch (error) {
  18994. captureCommitPhaseError(current, nearestMountedAncestor, error);
  18995. }
  18996. } // Capture errors so they don't interrupt unmounting.
  18997. function safelyCallComponentWillUnmount(current, nearestMountedAncestor, instance) {
  18998. try {
  18999. callComponentWillUnmountWithTimer(current, instance);
  19000. } catch (error) {
  19001. captureCommitPhaseError(current, nearestMountedAncestor, error);
  19002. }
  19003. } // Capture errors so they don't interrupt mounting.
  19004. function safelyCallComponentDidMount(current, nearestMountedAncestor, instance) {
  19005. try {
  19006. instance.componentDidMount();
  19007. } catch (error) {
  19008. captureCommitPhaseError(current, nearestMountedAncestor, error);
  19009. }
  19010. } // Capture errors so they don't interrupt mounting.
  19011. function safelyAttachRef(current, nearestMountedAncestor) {
  19012. try {
  19013. commitAttachRef(current);
  19014. } catch (error) {
  19015. captureCommitPhaseError(current, nearestMountedAncestor, error);
  19016. }
  19017. }
  19018. function safelyDetachRef(current, nearestMountedAncestor) {
  19019. var ref = current.ref;
  19020. if (ref !== null) {
  19021. if (typeof ref === 'function') {
  19022. var retVal;
  19023. try {
  19024. if (enableProfilerTimer && enableProfilerCommitHooks && current.mode & ProfileMode) {
  19025. try {
  19026. startLayoutEffectTimer();
  19027. retVal = ref(null);
  19028. } finally {
  19029. recordLayoutEffectDuration(current);
  19030. }
  19031. } else {
  19032. retVal = ref(null);
  19033. }
  19034. } catch (error) {
  19035. captureCommitPhaseError(current, nearestMountedAncestor, error);
  19036. }
  19037. {
  19038. if (typeof retVal === 'function') {
  19039. error('Unexpected return value from a callback ref in %s. ' + 'A callback ref should not return a function.', getComponentNameFromFiber(current));
  19040. }
  19041. }
  19042. } else {
  19043. ref.current = null;
  19044. }
  19045. }
  19046. }
  19047. function safelyCallDestroy(current, nearestMountedAncestor, destroy) {
  19048. try {
  19049. destroy();
  19050. } catch (error) {
  19051. captureCommitPhaseError(current, nearestMountedAncestor, error);
  19052. }
  19053. }
  19054. var focusedInstanceHandle = null;
  19055. var shouldFireAfterActiveInstanceBlur = false;
  19056. function commitBeforeMutationEffects(root, firstChild) {
  19057. focusedInstanceHandle = prepareForCommit(root.containerInfo);
  19058. nextEffect = firstChild;
  19059. commitBeforeMutationEffects_begin(); // We no longer need to track the active instance fiber
  19060. var shouldFire = shouldFireAfterActiveInstanceBlur;
  19061. shouldFireAfterActiveInstanceBlur = false;
  19062. focusedInstanceHandle = null;
  19063. return shouldFire;
  19064. }
  19065. function commitBeforeMutationEffects_begin() {
  19066. while (nextEffect !== null) {
  19067. var fiber = nextEffect; // This phase is only used for beforeActiveInstanceBlur.
  19068. var child = fiber.child;
  19069. if ((fiber.subtreeFlags & BeforeMutationMask) !== NoFlags && child !== null) {
  19070. child.return = fiber;
  19071. nextEffect = child;
  19072. } else {
  19073. commitBeforeMutationEffects_complete();
  19074. }
  19075. }
  19076. }
  19077. function commitBeforeMutationEffects_complete() {
  19078. while (nextEffect !== null) {
  19079. var fiber = nextEffect;
  19080. setCurrentFiber(fiber);
  19081. try {
  19082. commitBeforeMutationEffectsOnFiber(fiber);
  19083. } catch (error) {
  19084. captureCommitPhaseError(fiber, fiber.return, error);
  19085. }
  19086. resetCurrentFiber();
  19087. var sibling = fiber.sibling;
  19088. if (sibling !== null) {
  19089. sibling.return = fiber.return;
  19090. nextEffect = sibling;
  19091. return;
  19092. }
  19093. nextEffect = fiber.return;
  19094. }
  19095. }
  19096. function commitBeforeMutationEffectsOnFiber(finishedWork) {
  19097. var current = finishedWork.alternate;
  19098. var flags = finishedWork.flags;
  19099. if ((flags & Snapshot) !== NoFlags) {
  19100. setCurrentFiber(finishedWork);
  19101. switch (finishedWork.tag) {
  19102. case FunctionComponent:
  19103. case ForwardRef:
  19104. case SimpleMemoComponent:
  19105. {
  19106. break;
  19107. }
  19108. case ClassComponent:
  19109. {
  19110. if (current !== null) {
  19111. var prevProps = current.memoizedProps;
  19112. var prevState = current.memoizedState;
  19113. var instance = finishedWork.stateNode; // We could update instance props and state here,
  19114. // but instead we rely on them being set during last render.
  19115. // TODO: revisit this when we implement resuming.
  19116. {
  19117. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  19118. if (instance.props !== finishedWork.memoizedProps) {
  19119. 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.', getComponentNameFromFiber(finishedWork) || 'instance');
  19120. }
  19121. if (instance.state !== finishedWork.memoizedState) {
  19122. 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.state`. ' + 'Please file an issue.', getComponentNameFromFiber(finishedWork) || 'instance');
  19123. }
  19124. }
  19125. }
  19126. var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
  19127. {
  19128. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  19129. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  19130. didWarnSet.add(finishedWork.type);
  19131. error('%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentNameFromFiber(finishedWork));
  19132. }
  19133. }
  19134. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  19135. }
  19136. break;
  19137. }
  19138. case HostRoot:
  19139. {
  19140. {
  19141. var root = finishedWork.stateNode;
  19142. clearContainer(root.containerInfo);
  19143. }
  19144. break;
  19145. }
  19146. case HostComponent:
  19147. case HostText:
  19148. case HostPortal:
  19149. case IncompleteClassComponent:
  19150. // Nothing to do for these component types
  19151. break;
  19152. default:
  19153. {
  19154. throw new 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.');
  19155. }
  19156. }
  19157. resetCurrentFiber();
  19158. }
  19159. }
  19160. function commitHookEffectListUnmount(flags, finishedWork, nearestMountedAncestor) {
  19161. var updateQueue = finishedWork.updateQueue;
  19162. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  19163. if (lastEffect !== null) {
  19164. var firstEffect = lastEffect.next;
  19165. var effect = firstEffect;
  19166. do {
  19167. if ((effect.tag & flags) === flags) {
  19168. // Unmount
  19169. var destroy = effect.destroy;
  19170. effect.destroy = undefined;
  19171. if (destroy !== undefined) {
  19172. {
  19173. if ((flags & Passive$1) !== NoFlags$1) {
  19174. markComponentPassiveEffectUnmountStarted(finishedWork);
  19175. } else if ((flags & Layout) !== NoFlags$1) {
  19176. markComponentLayoutEffectUnmountStarted(finishedWork);
  19177. }
  19178. }
  19179. {
  19180. if ((flags & Insertion) !== NoFlags$1) {
  19181. setIsRunningInsertionEffect(true);
  19182. }
  19183. }
  19184. safelyCallDestroy(finishedWork, nearestMountedAncestor, destroy);
  19185. {
  19186. if ((flags & Insertion) !== NoFlags$1) {
  19187. setIsRunningInsertionEffect(false);
  19188. }
  19189. }
  19190. {
  19191. if ((flags & Passive$1) !== NoFlags$1) {
  19192. markComponentPassiveEffectUnmountStopped();
  19193. } else if ((flags & Layout) !== NoFlags$1) {
  19194. markComponentLayoutEffectUnmountStopped();
  19195. }
  19196. }
  19197. }
  19198. }
  19199. effect = effect.next;
  19200. } while (effect !== firstEffect);
  19201. }
  19202. }
  19203. function commitHookEffectListMount(flags, finishedWork) {
  19204. var updateQueue = finishedWork.updateQueue;
  19205. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  19206. if (lastEffect !== null) {
  19207. var firstEffect = lastEffect.next;
  19208. var effect = firstEffect;
  19209. do {
  19210. if ((effect.tag & flags) === flags) {
  19211. {
  19212. if ((flags & Passive$1) !== NoFlags$1) {
  19213. markComponentPassiveEffectMountStarted(finishedWork);
  19214. } else if ((flags & Layout) !== NoFlags$1) {
  19215. markComponentLayoutEffectMountStarted(finishedWork);
  19216. }
  19217. } // Mount
  19218. var create = effect.create;
  19219. {
  19220. if ((flags & Insertion) !== NoFlags$1) {
  19221. setIsRunningInsertionEffect(true);
  19222. }
  19223. }
  19224. effect.destroy = create();
  19225. {
  19226. if ((flags & Insertion) !== NoFlags$1) {
  19227. setIsRunningInsertionEffect(false);
  19228. }
  19229. }
  19230. {
  19231. if ((flags & Passive$1) !== NoFlags$1) {
  19232. markComponentPassiveEffectMountStopped();
  19233. } else if ((flags & Layout) !== NoFlags$1) {
  19234. markComponentLayoutEffectMountStopped();
  19235. }
  19236. }
  19237. {
  19238. var destroy = effect.destroy;
  19239. if (destroy !== undefined && typeof destroy !== 'function') {
  19240. var hookName = void 0;
  19241. if ((effect.tag & Layout) !== NoFlags) {
  19242. hookName = 'useLayoutEffect';
  19243. } else if ((effect.tag & Insertion) !== NoFlags) {
  19244. hookName = 'useInsertionEffect';
  19245. } else {
  19246. hookName = 'useEffect';
  19247. }
  19248. var addendum = void 0;
  19249. if (destroy === null) {
  19250. addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
  19251. } else if (typeof destroy.then === 'function') {
  19252. addendum = '\n\nIt looks like you wrote ' + hookName + '(async () => ...) or returned a Promise. ' + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + hookName + '(() => {\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://reactjs.org/link/hooks-data-fetching';
  19253. } else {
  19254. addendum = ' You returned: ' + destroy;
  19255. }
  19256. error('%s must not return anything besides a function, ' + 'which is used for clean-up.%s', hookName, addendum);
  19257. }
  19258. }
  19259. }
  19260. effect = effect.next;
  19261. } while (effect !== firstEffect);
  19262. }
  19263. }
  19264. function commitPassiveEffectDurations(finishedRoot, finishedWork) {
  19265. {
  19266. // Only Profilers with work in their subtree will have an Update effect scheduled.
  19267. if ((finishedWork.flags & Update) !== NoFlags) {
  19268. switch (finishedWork.tag) {
  19269. case Profiler:
  19270. {
  19271. var passiveEffectDuration = finishedWork.stateNode.passiveEffectDuration;
  19272. var _finishedWork$memoize = finishedWork.memoizedProps,
  19273. id = _finishedWork$memoize.id,
  19274. onPostCommit = _finishedWork$memoize.onPostCommit; // This value will still reflect the previous commit phase.
  19275. // It does not get reset until the start of the next commit phase.
  19276. var commitTime = getCommitTime();
  19277. var phase = finishedWork.alternate === null ? 'mount' : 'update';
  19278. {
  19279. if (isCurrentUpdateNested()) {
  19280. phase = 'nested-update';
  19281. }
  19282. }
  19283. if (typeof onPostCommit === 'function') {
  19284. onPostCommit(id, phase, passiveEffectDuration, commitTime);
  19285. } // Bubble times to the next nearest ancestor Profiler.
  19286. // After we process that Profiler, we'll bubble further up.
  19287. var parentFiber = finishedWork.return;
  19288. outer: while (parentFiber !== null) {
  19289. switch (parentFiber.tag) {
  19290. case HostRoot:
  19291. var root = parentFiber.stateNode;
  19292. root.passiveEffectDuration += passiveEffectDuration;
  19293. break outer;
  19294. case Profiler:
  19295. var parentStateNode = parentFiber.stateNode;
  19296. parentStateNode.passiveEffectDuration += passiveEffectDuration;
  19297. break outer;
  19298. }
  19299. parentFiber = parentFiber.return;
  19300. }
  19301. break;
  19302. }
  19303. }
  19304. }
  19305. }
  19306. }
  19307. function commitLayoutEffectOnFiber(finishedRoot, current, finishedWork, committedLanes) {
  19308. if ((finishedWork.flags & LayoutMask) !== NoFlags) {
  19309. switch (finishedWork.tag) {
  19310. case FunctionComponent:
  19311. case ForwardRef:
  19312. case SimpleMemoComponent:
  19313. {
  19314. if ( !offscreenSubtreeWasHidden) {
  19315. // At this point layout effects have already been destroyed (during mutation phase).
  19316. // This is done to prevent sibling component effects from interfering with each other,
  19317. // e.g. a destroy function in one component should never override a ref set
  19318. // by a create function in another component during the same commit.
  19319. if ( finishedWork.mode & ProfileMode) {
  19320. try {
  19321. startLayoutEffectTimer();
  19322. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  19323. } finally {
  19324. recordLayoutEffectDuration(finishedWork);
  19325. }
  19326. } else {
  19327. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  19328. }
  19329. }
  19330. break;
  19331. }
  19332. case ClassComponent:
  19333. {
  19334. var instance = finishedWork.stateNode;
  19335. if (finishedWork.flags & Update) {
  19336. if (!offscreenSubtreeWasHidden) {
  19337. if (current === null) {
  19338. // We could update instance props and state here,
  19339. // but instead we rely on them being set during last render.
  19340. // TODO: revisit this when we implement resuming.
  19341. {
  19342. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  19343. if (instance.props !== finishedWork.memoizedProps) {
  19344. 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.', getComponentNameFromFiber(finishedWork) || 'instance');
  19345. }
  19346. if (instance.state !== finishedWork.memoizedState) {
  19347. 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.state`. ' + 'Please file an issue.', getComponentNameFromFiber(finishedWork) || 'instance');
  19348. }
  19349. }
  19350. }
  19351. if ( finishedWork.mode & ProfileMode) {
  19352. try {
  19353. startLayoutEffectTimer();
  19354. instance.componentDidMount();
  19355. } finally {
  19356. recordLayoutEffectDuration(finishedWork);
  19357. }
  19358. } else {
  19359. instance.componentDidMount();
  19360. }
  19361. } else {
  19362. var prevProps = finishedWork.elementType === finishedWork.type ? current.memoizedProps : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  19363. var prevState = current.memoizedState; // We could update instance props and state here,
  19364. // but instead we rely on them being set during last render.
  19365. // TODO: revisit this when we implement resuming.
  19366. {
  19367. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  19368. if (instance.props !== finishedWork.memoizedProps) {
  19369. 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.', getComponentNameFromFiber(finishedWork) || 'instance');
  19370. }
  19371. if (instance.state !== finishedWork.memoizedState) {
  19372. 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.state`. ' + 'Please file an issue.', getComponentNameFromFiber(finishedWork) || 'instance');
  19373. }
  19374. }
  19375. }
  19376. if ( finishedWork.mode & ProfileMode) {
  19377. try {
  19378. startLayoutEffectTimer();
  19379. instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
  19380. } finally {
  19381. recordLayoutEffectDuration(finishedWork);
  19382. }
  19383. } else {
  19384. instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
  19385. }
  19386. }
  19387. }
  19388. } // TODO: I think this is now always non-null by the time it reaches the
  19389. // commit phase. Consider removing the type check.
  19390. var updateQueue = finishedWork.updateQueue;
  19391. if (updateQueue !== null) {
  19392. {
  19393. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  19394. if (instance.props !== finishedWork.memoizedProps) {
  19395. 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.', getComponentNameFromFiber(finishedWork) || 'instance');
  19396. }
  19397. if (instance.state !== finishedWork.memoizedState) {
  19398. 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.state`. ' + 'Please file an issue.', getComponentNameFromFiber(finishedWork) || 'instance');
  19399. }
  19400. }
  19401. } // We could update instance props and state here,
  19402. // but instead we rely on them being set during last render.
  19403. // TODO: revisit this when we implement resuming.
  19404. commitUpdateQueue(finishedWork, updateQueue, instance);
  19405. }
  19406. break;
  19407. }
  19408. case HostRoot:
  19409. {
  19410. // TODO: I think this is now always non-null by the time it reaches the
  19411. // commit phase. Consider removing the type check.
  19412. var _updateQueue = finishedWork.updateQueue;
  19413. if (_updateQueue !== null) {
  19414. var _instance = null;
  19415. if (finishedWork.child !== null) {
  19416. switch (finishedWork.child.tag) {
  19417. case HostComponent:
  19418. _instance = getPublicInstance(finishedWork.child.stateNode);
  19419. break;
  19420. case ClassComponent:
  19421. _instance = finishedWork.child.stateNode;
  19422. break;
  19423. }
  19424. }
  19425. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  19426. }
  19427. break;
  19428. }
  19429. case HostComponent:
  19430. {
  19431. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  19432. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  19433. // These effects should only be committed when components are first mounted,
  19434. // aka when there is no current/alternate.
  19435. if (current === null && finishedWork.flags & Update) {
  19436. var type = finishedWork.type;
  19437. var props = finishedWork.memoizedProps;
  19438. commitMount(_instance2, type, props);
  19439. }
  19440. break;
  19441. }
  19442. case HostText:
  19443. {
  19444. // We have no life-cycles associated with text.
  19445. break;
  19446. }
  19447. case HostPortal:
  19448. {
  19449. // We have no life-cycles associated with portals.
  19450. break;
  19451. }
  19452. case Profiler:
  19453. {
  19454. {
  19455. var _finishedWork$memoize2 = finishedWork.memoizedProps,
  19456. onCommit = _finishedWork$memoize2.onCommit,
  19457. onRender = _finishedWork$memoize2.onRender;
  19458. var effectDuration = finishedWork.stateNode.effectDuration;
  19459. var commitTime = getCommitTime();
  19460. var phase = current === null ? 'mount' : 'update';
  19461. {
  19462. if (isCurrentUpdateNested()) {
  19463. phase = 'nested-update';
  19464. }
  19465. }
  19466. if (typeof onRender === 'function') {
  19467. onRender(finishedWork.memoizedProps.id, phase, finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, commitTime);
  19468. }
  19469. {
  19470. if (typeof onCommit === 'function') {
  19471. onCommit(finishedWork.memoizedProps.id, phase, effectDuration, commitTime);
  19472. } // Schedule a passive effect for this Profiler to call onPostCommit hooks.
  19473. // This effect should be scheduled even if there is no onPostCommit callback for this Profiler,
  19474. // because the effect is also where times bubble to parent Profilers.
  19475. enqueuePendingPassiveProfilerEffect(finishedWork); // Propagate layout effect durations to the next nearest Profiler ancestor.
  19476. // Do not reset these values until the next render so DevTools has a chance to read them first.
  19477. var parentFiber = finishedWork.return;
  19478. outer: while (parentFiber !== null) {
  19479. switch (parentFiber.tag) {
  19480. case HostRoot:
  19481. var root = parentFiber.stateNode;
  19482. root.effectDuration += effectDuration;
  19483. break outer;
  19484. case Profiler:
  19485. var parentStateNode = parentFiber.stateNode;
  19486. parentStateNode.effectDuration += effectDuration;
  19487. break outer;
  19488. }
  19489. parentFiber = parentFiber.return;
  19490. }
  19491. }
  19492. }
  19493. break;
  19494. }
  19495. case SuspenseComponent:
  19496. {
  19497. commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);
  19498. break;
  19499. }
  19500. case SuspenseListComponent:
  19501. case IncompleteClassComponent:
  19502. case ScopeComponent:
  19503. case OffscreenComponent:
  19504. case LegacyHiddenComponent:
  19505. case TracingMarkerComponent:
  19506. {
  19507. break;
  19508. }
  19509. default:
  19510. throw new 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.');
  19511. }
  19512. }
  19513. if ( !offscreenSubtreeWasHidden) {
  19514. {
  19515. if (finishedWork.flags & Ref) {
  19516. commitAttachRef(finishedWork);
  19517. }
  19518. }
  19519. }
  19520. }
  19521. function reappearLayoutEffectsOnFiber(node) {
  19522. // Turn on layout effects in a tree that previously disappeared.
  19523. // TODO (Offscreen) Check: flags & LayoutStatic
  19524. switch (node.tag) {
  19525. case FunctionComponent:
  19526. case ForwardRef:
  19527. case SimpleMemoComponent:
  19528. {
  19529. if ( node.mode & ProfileMode) {
  19530. try {
  19531. startLayoutEffectTimer();
  19532. safelyCallCommitHookLayoutEffectListMount(node, node.return);
  19533. } finally {
  19534. recordLayoutEffectDuration(node);
  19535. }
  19536. } else {
  19537. safelyCallCommitHookLayoutEffectListMount(node, node.return);
  19538. }
  19539. break;
  19540. }
  19541. case ClassComponent:
  19542. {
  19543. var instance = node.stateNode;
  19544. if (typeof instance.componentDidMount === 'function') {
  19545. safelyCallComponentDidMount(node, node.return, instance);
  19546. }
  19547. safelyAttachRef(node, node.return);
  19548. break;
  19549. }
  19550. case HostComponent:
  19551. {
  19552. safelyAttachRef(node, node.return);
  19553. break;
  19554. }
  19555. }
  19556. }
  19557. function hideOrUnhideAllChildren(finishedWork, isHidden) {
  19558. // Only hide or unhide the top-most host nodes.
  19559. var hostSubtreeRoot = null;
  19560. {
  19561. // We only have the top Fiber that was inserted but we need to recurse down its
  19562. // children to find all the terminal nodes.
  19563. var node = finishedWork;
  19564. while (true) {
  19565. if (node.tag === HostComponent) {
  19566. if (hostSubtreeRoot === null) {
  19567. hostSubtreeRoot = node;
  19568. try {
  19569. var instance = node.stateNode;
  19570. if (isHidden) {
  19571. hideInstance(instance);
  19572. } else {
  19573. unhideInstance(node.stateNode, node.memoizedProps);
  19574. }
  19575. } catch (error) {
  19576. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  19577. }
  19578. }
  19579. } else if (node.tag === HostText) {
  19580. if (hostSubtreeRoot === null) {
  19581. try {
  19582. var _instance3 = node.stateNode;
  19583. if (isHidden) {
  19584. hideTextInstance(_instance3);
  19585. } else {
  19586. unhideTextInstance(_instance3, node.memoizedProps);
  19587. }
  19588. } catch (error) {
  19589. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  19590. }
  19591. }
  19592. } else if ((node.tag === OffscreenComponent || node.tag === LegacyHiddenComponent) && node.memoizedState !== null && node !== finishedWork) ; else if (node.child !== null) {
  19593. node.child.return = node;
  19594. node = node.child;
  19595. continue;
  19596. }
  19597. if (node === finishedWork) {
  19598. return;
  19599. }
  19600. while (node.sibling === null) {
  19601. if (node.return === null || node.return === finishedWork) {
  19602. return;
  19603. }
  19604. if (hostSubtreeRoot === node) {
  19605. hostSubtreeRoot = null;
  19606. }
  19607. node = node.return;
  19608. }
  19609. if (hostSubtreeRoot === node) {
  19610. hostSubtreeRoot = null;
  19611. }
  19612. node.sibling.return = node.return;
  19613. node = node.sibling;
  19614. }
  19615. }
  19616. }
  19617. function commitAttachRef(finishedWork) {
  19618. var ref = finishedWork.ref;
  19619. if (ref !== null) {
  19620. var instance = finishedWork.stateNode;
  19621. var instanceToUse;
  19622. switch (finishedWork.tag) {
  19623. case HostComponent:
  19624. instanceToUse = getPublicInstance(instance);
  19625. break;
  19626. default:
  19627. instanceToUse = instance;
  19628. } // Moved outside to ensure DCE works with this flag
  19629. if (typeof ref === 'function') {
  19630. var retVal;
  19631. if ( finishedWork.mode & ProfileMode) {
  19632. try {
  19633. startLayoutEffectTimer();
  19634. retVal = ref(instanceToUse);
  19635. } finally {
  19636. recordLayoutEffectDuration(finishedWork);
  19637. }
  19638. } else {
  19639. retVal = ref(instanceToUse);
  19640. }
  19641. {
  19642. if (typeof retVal === 'function') {
  19643. error('Unexpected return value from a callback ref in %s. ' + 'A callback ref should not return a function.', getComponentNameFromFiber(finishedWork));
  19644. }
  19645. }
  19646. } else {
  19647. {
  19648. if (!ref.hasOwnProperty('current')) {
  19649. error('Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().', getComponentNameFromFiber(finishedWork));
  19650. }
  19651. }
  19652. ref.current = instanceToUse;
  19653. }
  19654. }
  19655. }
  19656. function detachFiberMutation(fiber) {
  19657. // Cut off the return pointer to disconnect it from the tree.
  19658. // This enables us to detect and warn against state updates on an unmounted component.
  19659. // It also prevents events from bubbling from within disconnected components.
  19660. //
  19661. // Ideally, we should also clear the child pointer of the parent alternate to let this
  19662. // get GC:ed but we don't know which for sure which parent is the current
  19663. // one so we'll settle for GC:ing the subtree of this child.
  19664. // This child itself will be GC:ed when the parent updates the next time.
  19665. //
  19666. // Note that we can't clear child or sibling pointers yet.
  19667. // They're needed for passive effects and for findDOMNode.
  19668. // We defer those fields, and all other cleanup, to the passive phase (see detachFiberAfterEffects).
  19669. //
  19670. // Don't reset the alternate yet, either. We need that so we can detach the
  19671. // alternate's fields in the passive phase. Clearing the return pointer is
  19672. // sufficient for findDOMNode semantics.
  19673. var alternate = fiber.alternate;
  19674. if (alternate !== null) {
  19675. alternate.return = null;
  19676. }
  19677. fiber.return = null;
  19678. }
  19679. function detachFiberAfterEffects(fiber) {
  19680. var alternate = fiber.alternate;
  19681. if (alternate !== null) {
  19682. fiber.alternate = null;
  19683. detachFiberAfterEffects(alternate);
  19684. } // Note: Defensively using negation instead of < in case
  19685. // `deletedTreeCleanUpLevel` is undefined.
  19686. {
  19687. // Clear cyclical Fiber fields. This level alone is designed to roughly
  19688. // approximate the planned Fiber refactor. In that world, `setState` will be
  19689. // bound to a special "instance" object instead of a Fiber. The Instance
  19690. // object will not have any of these fields. It will only be connected to
  19691. // the fiber tree via a single link at the root. So if this level alone is
  19692. // sufficient to fix memory issues, that bodes well for our plans.
  19693. fiber.child = null;
  19694. fiber.deletions = null;
  19695. fiber.sibling = null; // The `stateNode` is cyclical because on host nodes it points to the host
  19696. // tree, which has its own pointers to children, parents, and siblings.
  19697. // The other host nodes also point back to fibers, so we should detach that
  19698. // one, too.
  19699. if (fiber.tag === HostComponent) {
  19700. var hostInstance = fiber.stateNode;
  19701. if (hostInstance !== null) {
  19702. detachDeletedInstance(hostInstance);
  19703. }
  19704. }
  19705. fiber.stateNode = null; // I'm intentionally not clearing the `return` field in this level. We
  19706. // already disconnect the `return` pointer at the root of the deleted
  19707. // subtree (in `detachFiberMutation`). Besides, `return` by itself is not
  19708. // cyclical — it's only cyclical when combined with `child`, `sibling`, and
  19709. // `alternate`. But we'll clear it in the next level anyway, just in case.
  19710. {
  19711. fiber._debugOwner = null;
  19712. }
  19713. {
  19714. // Theoretically, nothing in here should be necessary, because we already
  19715. // disconnected the fiber from the tree. So even if something leaks this
  19716. // particular fiber, it won't leak anything else
  19717. //
  19718. // The purpose of this branch is to be super aggressive so we can measure
  19719. // if there's any difference in memory impact. If there is, that could
  19720. // indicate a React leak we don't know about.
  19721. fiber.return = null;
  19722. fiber.dependencies = null;
  19723. fiber.memoizedProps = null;
  19724. fiber.memoizedState = null;
  19725. fiber.pendingProps = null;
  19726. fiber.stateNode = null; // TODO: Move to `commitPassiveUnmountInsideDeletedTreeOnFiber` instead.
  19727. fiber.updateQueue = null;
  19728. }
  19729. }
  19730. }
  19731. function getHostParentFiber(fiber) {
  19732. var parent = fiber.return;
  19733. while (parent !== null) {
  19734. if (isHostParent(parent)) {
  19735. return parent;
  19736. }
  19737. parent = parent.return;
  19738. }
  19739. throw new Error('Expected to find a host parent. This error is likely caused by a bug ' + 'in React. Please file an issue.');
  19740. }
  19741. function isHostParent(fiber) {
  19742. return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
  19743. }
  19744. function getHostSibling(fiber) {
  19745. // We're going to search forward into the tree until we find a sibling host
  19746. // node. Unfortunately, if multiple insertions are done in a row we have to
  19747. // search past them. This leads to exponential search for the next sibling.
  19748. // TODO: Find a more efficient way to do this.
  19749. var node = fiber;
  19750. siblings: while (true) {
  19751. // If we didn't find anything, let's try the next sibling.
  19752. while (node.sibling === null) {
  19753. if (node.return === null || isHostParent(node.return)) {
  19754. // If we pop out of the root or hit the parent the fiber we are the
  19755. // last sibling.
  19756. return null;
  19757. }
  19758. node = node.return;
  19759. }
  19760. node.sibling.return = node.return;
  19761. node = node.sibling;
  19762. while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
  19763. // If it is not host node and, we might have a host node inside it.
  19764. // Try to search down until we find one.
  19765. if (node.flags & Placement) {
  19766. // If we don't have a child, try the siblings instead.
  19767. continue siblings;
  19768. } // If we don't have a child, try the siblings instead.
  19769. // We also skip portals because they are not part of this host tree.
  19770. if (node.child === null || node.tag === HostPortal) {
  19771. continue siblings;
  19772. } else {
  19773. node.child.return = node;
  19774. node = node.child;
  19775. }
  19776. } // Check if this host node is stable or about to be placed.
  19777. if (!(node.flags & Placement)) {
  19778. // Found it!
  19779. return node.stateNode;
  19780. }
  19781. }
  19782. }
  19783. function commitPlacement(finishedWork) {
  19784. var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
  19785. switch (parentFiber.tag) {
  19786. case HostComponent:
  19787. {
  19788. var parent = parentFiber.stateNode;
  19789. if (parentFiber.flags & ContentReset) {
  19790. // Reset the text content of the parent before doing any insertions
  19791. resetTextContent(parent); // Clear ContentReset from the effect tag
  19792. parentFiber.flags &= ~ContentReset;
  19793. }
  19794. var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
  19795. // children to find all the terminal nodes.
  19796. insertOrAppendPlacementNode(finishedWork, before, parent);
  19797. break;
  19798. }
  19799. case HostRoot:
  19800. case HostPortal:
  19801. {
  19802. var _parent = parentFiber.stateNode.containerInfo;
  19803. var _before = getHostSibling(finishedWork);
  19804. insertOrAppendPlacementNodeIntoContainer(finishedWork, _before, _parent);
  19805. break;
  19806. }
  19807. // eslint-disable-next-line-no-fallthrough
  19808. default:
  19809. throw new Error('Invalid host parent fiber. This error is likely caused by a bug ' + 'in React. Please file an issue.');
  19810. }
  19811. }
  19812. function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
  19813. var tag = node.tag;
  19814. var isHost = tag === HostComponent || tag === HostText;
  19815. if (isHost) {
  19816. var stateNode = node.stateNode;
  19817. if (before) {
  19818. insertInContainerBefore(parent, stateNode, before);
  19819. } else {
  19820. appendChildToContainer(parent, stateNode);
  19821. }
  19822. } else if (tag === HostPortal) ; else {
  19823. var child = node.child;
  19824. if (child !== null) {
  19825. insertOrAppendPlacementNodeIntoContainer(child, before, parent);
  19826. var sibling = child.sibling;
  19827. while (sibling !== null) {
  19828. insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
  19829. sibling = sibling.sibling;
  19830. }
  19831. }
  19832. }
  19833. }
  19834. function insertOrAppendPlacementNode(node, before, parent) {
  19835. var tag = node.tag;
  19836. var isHost = tag === HostComponent || tag === HostText;
  19837. if (isHost) {
  19838. var stateNode = node.stateNode;
  19839. if (before) {
  19840. insertBefore(parent, stateNode, before);
  19841. } else {
  19842. appendChild(parent, stateNode);
  19843. }
  19844. } else if (tag === HostPortal) ; else {
  19845. var child = node.child;
  19846. if (child !== null) {
  19847. insertOrAppendPlacementNode(child, before, parent);
  19848. var sibling = child.sibling;
  19849. while (sibling !== null) {
  19850. insertOrAppendPlacementNode(sibling, before, parent);
  19851. sibling = sibling.sibling;
  19852. }
  19853. }
  19854. }
  19855. } // These are tracked on the stack as we recursively traverse a
  19856. // deleted subtree.
  19857. // TODO: Update these during the whole mutation phase, not just during
  19858. // a deletion.
  19859. var hostParent = null;
  19860. var hostParentIsContainer = false;
  19861. function commitDeletionEffects(root, returnFiber, deletedFiber) {
  19862. {
  19863. // We only have the top Fiber that was deleted but we need to recurse down its
  19864. // children to find all the terminal nodes.
  19865. // Recursively delete all host nodes from the parent, detach refs, clean
  19866. // up mounted layout effects, and call componentWillUnmount.
  19867. // We only need to remove the topmost host child in each branch. But then we
  19868. // still need to keep traversing to unmount effects, refs, and cWU. TODO: We
  19869. // could split this into two separate traversals functions, where the second
  19870. // one doesn't include any removeChild logic. This is maybe the same
  19871. // function as "disappearLayoutEffects" (or whatever that turns into after
  19872. // the layout phase is refactored to use recursion).
  19873. // Before starting, find the nearest host parent on the stack so we know
  19874. // which instance/container to remove the children from.
  19875. // TODO: Instead of searching up the fiber return path on every deletion, we
  19876. // can track the nearest host component on the JS stack as we traverse the
  19877. // tree during the commit phase. This would make insertions faster, too.
  19878. var parent = returnFiber;
  19879. findParent: while (parent !== null) {
  19880. switch (parent.tag) {
  19881. case HostComponent:
  19882. {
  19883. hostParent = parent.stateNode;
  19884. hostParentIsContainer = false;
  19885. break findParent;
  19886. }
  19887. case HostRoot:
  19888. {
  19889. hostParent = parent.stateNode.containerInfo;
  19890. hostParentIsContainer = true;
  19891. break findParent;
  19892. }
  19893. case HostPortal:
  19894. {
  19895. hostParent = parent.stateNode.containerInfo;
  19896. hostParentIsContainer = true;
  19897. break findParent;
  19898. }
  19899. }
  19900. parent = parent.return;
  19901. }
  19902. if (hostParent === null) {
  19903. throw new Error('Expected to find a host parent. This error is likely caused by ' + 'a bug in React. Please file an issue.');
  19904. }
  19905. commitDeletionEffectsOnFiber(root, returnFiber, deletedFiber);
  19906. hostParent = null;
  19907. hostParentIsContainer = false;
  19908. }
  19909. detachFiberMutation(deletedFiber);
  19910. }
  19911. function recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, parent) {
  19912. // TODO: Use a static flag to skip trees that don't have unmount effects
  19913. var child = parent.child;
  19914. while (child !== null) {
  19915. commitDeletionEffectsOnFiber(finishedRoot, nearestMountedAncestor, child);
  19916. child = child.sibling;
  19917. }
  19918. }
  19919. function commitDeletionEffectsOnFiber(finishedRoot, nearestMountedAncestor, deletedFiber) {
  19920. onCommitUnmount(deletedFiber); // The cases in this outer switch modify the stack before they traverse
  19921. // into their subtree. There are simpler cases in the inner switch
  19922. // that don't modify the stack.
  19923. switch (deletedFiber.tag) {
  19924. case HostComponent:
  19925. {
  19926. if (!offscreenSubtreeWasHidden) {
  19927. safelyDetachRef(deletedFiber, nearestMountedAncestor);
  19928. } // Intentional fallthrough to next branch
  19929. }
  19930. // eslint-disable-next-line-no-fallthrough
  19931. case HostText:
  19932. {
  19933. // We only need to remove the nearest host child. Set the host parent
  19934. // to `null` on the stack to indicate that nested children don't
  19935. // need to be removed.
  19936. {
  19937. var prevHostParent = hostParent;
  19938. var prevHostParentIsContainer = hostParentIsContainer;
  19939. hostParent = null;
  19940. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  19941. hostParent = prevHostParent;
  19942. hostParentIsContainer = prevHostParentIsContainer;
  19943. if (hostParent !== null) {
  19944. // Now that all the child effects have unmounted, we can remove the
  19945. // node from the tree.
  19946. if (hostParentIsContainer) {
  19947. removeChildFromContainer(hostParent, deletedFiber.stateNode);
  19948. } else {
  19949. removeChild(hostParent, deletedFiber.stateNode);
  19950. }
  19951. }
  19952. }
  19953. return;
  19954. }
  19955. case DehydratedFragment:
  19956. {
  19957. // Delete the dehydrated suspense boundary and all of its content.
  19958. {
  19959. if (hostParent !== null) {
  19960. if (hostParentIsContainer) {
  19961. clearSuspenseBoundaryFromContainer(hostParent, deletedFiber.stateNode);
  19962. } else {
  19963. clearSuspenseBoundary(hostParent, deletedFiber.stateNode);
  19964. }
  19965. }
  19966. }
  19967. return;
  19968. }
  19969. case HostPortal:
  19970. {
  19971. {
  19972. // When we go into a portal, it becomes the parent to remove from.
  19973. var _prevHostParent = hostParent;
  19974. var _prevHostParentIsContainer = hostParentIsContainer;
  19975. hostParent = deletedFiber.stateNode.containerInfo;
  19976. hostParentIsContainer = true;
  19977. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  19978. hostParent = _prevHostParent;
  19979. hostParentIsContainer = _prevHostParentIsContainer;
  19980. }
  19981. return;
  19982. }
  19983. case FunctionComponent:
  19984. case ForwardRef:
  19985. case MemoComponent:
  19986. case SimpleMemoComponent:
  19987. {
  19988. if (!offscreenSubtreeWasHidden) {
  19989. var updateQueue = deletedFiber.updateQueue;
  19990. if (updateQueue !== null) {
  19991. var lastEffect = updateQueue.lastEffect;
  19992. if (lastEffect !== null) {
  19993. var firstEffect = lastEffect.next;
  19994. var effect = firstEffect;
  19995. do {
  19996. var _effect = effect,
  19997. destroy = _effect.destroy,
  19998. tag = _effect.tag;
  19999. if (destroy !== undefined) {
  20000. if ((tag & Insertion) !== NoFlags$1) {
  20001. safelyCallDestroy(deletedFiber, nearestMountedAncestor, destroy);
  20002. } else if ((tag & Layout) !== NoFlags$1) {
  20003. {
  20004. markComponentLayoutEffectUnmountStarted(deletedFiber);
  20005. }
  20006. if ( deletedFiber.mode & ProfileMode) {
  20007. startLayoutEffectTimer();
  20008. safelyCallDestroy(deletedFiber, nearestMountedAncestor, destroy);
  20009. recordLayoutEffectDuration(deletedFiber);
  20010. } else {
  20011. safelyCallDestroy(deletedFiber, nearestMountedAncestor, destroy);
  20012. }
  20013. {
  20014. markComponentLayoutEffectUnmountStopped();
  20015. }
  20016. }
  20017. }
  20018. effect = effect.next;
  20019. } while (effect !== firstEffect);
  20020. }
  20021. }
  20022. }
  20023. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  20024. return;
  20025. }
  20026. case ClassComponent:
  20027. {
  20028. if (!offscreenSubtreeWasHidden) {
  20029. safelyDetachRef(deletedFiber, nearestMountedAncestor);
  20030. var instance = deletedFiber.stateNode;
  20031. if (typeof instance.componentWillUnmount === 'function') {
  20032. safelyCallComponentWillUnmount(deletedFiber, nearestMountedAncestor, instance);
  20033. }
  20034. }
  20035. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  20036. return;
  20037. }
  20038. case ScopeComponent:
  20039. {
  20040. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  20041. return;
  20042. }
  20043. case OffscreenComponent:
  20044. {
  20045. if ( // TODO: Remove this dead flag
  20046. deletedFiber.mode & ConcurrentMode) {
  20047. // If this offscreen component is hidden, we already unmounted it. Before
  20048. // deleting the children, track that it's already unmounted so that we
  20049. // don't attempt to unmount the effects again.
  20050. // TODO: If the tree is hidden, in most cases we should be able to skip
  20051. // over the nested children entirely. An exception is we haven't yet found
  20052. // the topmost host node to delete, which we already track on the stack.
  20053. // But the other case is portals, which need to be detached no matter how
  20054. // deeply they are nested. We should use a subtree flag to track whether a
  20055. // subtree includes a nested portal.
  20056. var prevOffscreenSubtreeWasHidden = offscreenSubtreeWasHidden;
  20057. offscreenSubtreeWasHidden = prevOffscreenSubtreeWasHidden || deletedFiber.memoizedState !== null;
  20058. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  20059. offscreenSubtreeWasHidden = prevOffscreenSubtreeWasHidden;
  20060. } else {
  20061. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  20062. }
  20063. break;
  20064. }
  20065. default:
  20066. {
  20067. recursivelyTraverseDeletionEffects(finishedRoot, nearestMountedAncestor, deletedFiber);
  20068. return;
  20069. }
  20070. }
  20071. }
  20072. function commitSuspenseCallback(finishedWork) {
  20073. // TODO: Move this to passive phase
  20074. var newState = finishedWork.memoizedState;
  20075. }
  20076. function commitSuspenseHydrationCallbacks(finishedRoot, finishedWork) {
  20077. var newState = finishedWork.memoizedState;
  20078. if (newState === null) {
  20079. var current = finishedWork.alternate;
  20080. if (current !== null) {
  20081. var prevState = current.memoizedState;
  20082. if (prevState !== null) {
  20083. var suspenseInstance = prevState.dehydrated;
  20084. if (suspenseInstance !== null) {
  20085. commitHydratedSuspenseInstance(suspenseInstance);
  20086. }
  20087. }
  20088. }
  20089. }
  20090. }
  20091. function attachSuspenseRetryListeners(finishedWork) {
  20092. // If this boundary just timed out, then it will have a set of wakeables.
  20093. // For each wakeable, attach a listener so that when it resolves, React
  20094. // attempts to re-render the boundary in the primary (pre-timeout) state.
  20095. var wakeables = finishedWork.updateQueue;
  20096. if (wakeables !== null) {
  20097. finishedWork.updateQueue = null;
  20098. var retryCache = finishedWork.stateNode;
  20099. if (retryCache === null) {
  20100. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  20101. }
  20102. wakeables.forEach(function (wakeable) {
  20103. // Memoize using the boundary fiber to prevent redundant listeners.
  20104. var retry = resolveRetryWakeable.bind(null, finishedWork, wakeable);
  20105. if (!retryCache.has(wakeable)) {
  20106. retryCache.add(wakeable);
  20107. {
  20108. if (isDevToolsPresent) {
  20109. if (inProgressLanes !== null && inProgressRoot !== null) {
  20110. // If we have pending work still, associate the original updaters with it.
  20111. restorePendingUpdaters(inProgressRoot, inProgressLanes);
  20112. } else {
  20113. throw Error('Expected finished root and lanes to be set. This is a bug in React.');
  20114. }
  20115. }
  20116. }
  20117. wakeable.then(retry, retry);
  20118. }
  20119. });
  20120. }
  20121. } // This function detects when a Suspense boundary goes from visible to hidden.
  20122. function commitMutationEffects(root, finishedWork, committedLanes) {
  20123. inProgressLanes = committedLanes;
  20124. inProgressRoot = root;
  20125. setCurrentFiber(finishedWork);
  20126. commitMutationEffectsOnFiber(finishedWork, root);
  20127. setCurrentFiber(finishedWork);
  20128. inProgressLanes = null;
  20129. inProgressRoot = null;
  20130. }
  20131. function recursivelyTraverseMutationEffects(root, parentFiber, lanes) {
  20132. // Deletions effects can be scheduled on any fiber type. They need to happen
  20133. // before the children effects hae fired.
  20134. var deletions = parentFiber.deletions;
  20135. if (deletions !== null) {
  20136. for (var i = 0; i < deletions.length; i++) {
  20137. var childToDelete = deletions[i];
  20138. try {
  20139. commitDeletionEffects(root, parentFiber, childToDelete);
  20140. } catch (error) {
  20141. captureCommitPhaseError(childToDelete, parentFiber, error);
  20142. }
  20143. }
  20144. }
  20145. var prevDebugFiber = getCurrentFiber();
  20146. if (parentFiber.subtreeFlags & MutationMask) {
  20147. var child = parentFiber.child;
  20148. while (child !== null) {
  20149. setCurrentFiber(child);
  20150. commitMutationEffectsOnFiber(child, root);
  20151. child = child.sibling;
  20152. }
  20153. }
  20154. setCurrentFiber(prevDebugFiber);
  20155. }
  20156. function commitMutationEffectsOnFiber(finishedWork, root, lanes) {
  20157. var current = finishedWork.alternate;
  20158. var flags = finishedWork.flags; // The effect flag should be checked *after* we refine the type of fiber,
  20159. // because the fiber tag is more specific. An exception is any flag related
  20160. // to reconcilation, because those can be set on all fiber types.
  20161. switch (finishedWork.tag) {
  20162. case FunctionComponent:
  20163. case ForwardRef:
  20164. case MemoComponent:
  20165. case SimpleMemoComponent:
  20166. {
  20167. recursivelyTraverseMutationEffects(root, finishedWork);
  20168. commitReconciliationEffects(finishedWork);
  20169. if (flags & Update) {
  20170. try {
  20171. commitHookEffectListUnmount(Insertion | HasEffect, finishedWork, finishedWork.return);
  20172. commitHookEffectListMount(Insertion | HasEffect, finishedWork);
  20173. } catch (error) {
  20174. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20175. } // Layout effects are destroyed during the mutation phase so that all
  20176. // destroy functions for all fibers are called before any create functions.
  20177. // This prevents sibling component effects from interfering with each other,
  20178. // e.g. a destroy function in one component should never override a ref set
  20179. // by a create function in another component during the same commit.
  20180. if ( finishedWork.mode & ProfileMode) {
  20181. try {
  20182. startLayoutEffectTimer();
  20183. commitHookEffectListUnmount(Layout | HasEffect, finishedWork, finishedWork.return);
  20184. } catch (error) {
  20185. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20186. }
  20187. recordLayoutEffectDuration(finishedWork);
  20188. } else {
  20189. try {
  20190. commitHookEffectListUnmount(Layout | HasEffect, finishedWork, finishedWork.return);
  20191. } catch (error) {
  20192. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20193. }
  20194. }
  20195. }
  20196. return;
  20197. }
  20198. case ClassComponent:
  20199. {
  20200. recursivelyTraverseMutationEffects(root, finishedWork);
  20201. commitReconciliationEffects(finishedWork);
  20202. if (flags & Ref) {
  20203. if (current !== null) {
  20204. safelyDetachRef(current, current.return);
  20205. }
  20206. }
  20207. return;
  20208. }
  20209. case HostComponent:
  20210. {
  20211. recursivelyTraverseMutationEffects(root, finishedWork);
  20212. commitReconciliationEffects(finishedWork);
  20213. if (flags & Ref) {
  20214. if (current !== null) {
  20215. safelyDetachRef(current, current.return);
  20216. }
  20217. }
  20218. {
  20219. // TODO: ContentReset gets cleared by the children during the commit
  20220. // phase. This is a refactor hazard because it means we must read
  20221. // flags the flags after `commitReconciliationEffects` has already run;
  20222. // the order matters. We should refactor so that ContentReset does not
  20223. // rely on mutating the flag during commit. Like by setting a flag
  20224. // during the render phase instead.
  20225. if (finishedWork.flags & ContentReset) {
  20226. var instance = finishedWork.stateNode;
  20227. try {
  20228. resetTextContent(instance);
  20229. } catch (error) {
  20230. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20231. }
  20232. }
  20233. if (flags & Update) {
  20234. var _instance4 = finishedWork.stateNode;
  20235. if (_instance4 != null) {
  20236. // Commit the work prepared earlier.
  20237. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  20238. // as the newProps. The updatePayload will contain the real change in
  20239. // this case.
  20240. var oldProps = current !== null ? current.memoizedProps : newProps;
  20241. var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
  20242. var updatePayload = finishedWork.updateQueue;
  20243. finishedWork.updateQueue = null;
  20244. if (updatePayload !== null) {
  20245. try {
  20246. commitUpdate(_instance4, updatePayload, type, oldProps, newProps, finishedWork);
  20247. } catch (error) {
  20248. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20249. }
  20250. }
  20251. }
  20252. }
  20253. }
  20254. return;
  20255. }
  20256. case HostText:
  20257. {
  20258. recursivelyTraverseMutationEffects(root, finishedWork);
  20259. commitReconciliationEffects(finishedWork);
  20260. if (flags & Update) {
  20261. {
  20262. if (finishedWork.stateNode === null) {
  20263. throw new Error('This should have a text node initialized. This error is likely ' + 'caused by a bug in React. Please file an issue.');
  20264. }
  20265. var textInstance = finishedWork.stateNode;
  20266. var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  20267. // as the newProps. The updatePayload will contain the real change in
  20268. // this case.
  20269. var oldText = current !== null ? current.memoizedProps : newText;
  20270. try {
  20271. commitTextUpdate(textInstance, oldText, newText);
  20272. } catch (error) {
  20273. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20274. }
  20275. }
  20276. }
  20277. return;
  20278. }
  20279. case HostRoot:
  20280. {
  20281. recursivelyTraverseMutationEffects(root, finishedWork);
  20282. commitReconciliationEffects(finishedWork);
  20283. if (flags & Update) {
  20284. {
  20285. if (current !== null) {
  20286. var prevRootState = current.memoizedState;
  20287. if (prevRootState.isDehydrated) {
  20288. try {
  20289. commitHydratedContainer(root.containerInfo);
  20290. } catch (error) {
  20291. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20292. }
  20293. }
  20294. }
  20295. }
  20296. }
  20297. return;
  20298. }
  20299. case HostPortal:
  20300. {
  20301. recursivelyTraverseMutationEffects(root, finishedWork);
  20302. commitReconciliationEffects(finishedWork);
  20303. return;
  20304. }
  20305. case SuspenseComponent:
  20306. {
  20307. recursivelyTraverseMutationEffects(root, finishedWork);
  20308. commitReconciliationEffects(finishedWork);
  20309. var offscreenFiber = finishedWork.child;
  20310. if (offscreenFiber.flags & Visibility) {
  20311. var offscreenInstance = offscreenFiber.stateNode;
  20312. var newState = offscreenFiber.memoizedState;
  20313. var isHidden = newState !== null; // Track the current state on the Offscreen instance so we can
  20314. // read it during an event
  20315. offscreenInstance.isHidden = isHidden;
  20316. if (isHidden) {
  20317. var wasHidden = offscreenFiber.alternate !== null && offscreenFiber.alternate.memoizedState !== null;
  20318. if (!wasHidden) {
  20319. // TODO: Move to passive phase
  20320. markCommitTimeOfFallback();
  20321. }
  20322. }
  20323. }
  20324. if (flags & Update) {
  20325. try {
  20326. commitSuspenseCallback(finishedWork);
  20327. } catch (error) {
  20328. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20329. }
  20330. attachSuspenseRetryListeners(finishedWork);
  20331. }
  20332. return;
  20333. }
  20334. case OffscreenComponent:
  20335. {
  20336. var _wasHidden = current !== null && current.memoizedState !== null;
  20337. if ( // TODO: Remove this dead flag
  20338. finishedWork.mode & ConcurrentMode) {
  20339. // Before committing the children, track on the stack whether this
  20340. // offscreen subtree was already hidden, so that we don't unmount the
  20341. // effects again.
  20342. var prevOffscreenSubtreeWasHidden = offscreenSubtreeWasHidden;
  20343. offscreenSubtreeWasHidden = prevOffscreenSubtreeWasHidden || _wasHidden;
  20344. recursivelyTraverseMutationEffects(root, finishedWork);
  20345. offscreenSubtreeWasHidden = prevOffscreenSubtreeWasHidden;
  20346. } else {
  20347. recursivelyTraverseMutationEffects(root, finishedWork);
  20348. }
  20349. commitReconciliationEffects(finishedWork);
  20350. if (flags & Visibility) {
  20351. var _offscreenInstance = finishedWork.stateNode;
  20352. var _newState = finishedWork.memoizedState;
  20353. var _isHidden = _newState !== null;
  20354. var offscreenBoundary = finishedWork; // Track the current state on the Offscreen instance so we can
  20355. // read it during an event
  20356. _offscreenInstance.isHidden = _isHidden;
  20357. {
  20358. if (_isHidden) {
  20359. if (!_wasHidden) {
  20360. if ((offscreenBoundary.mode & ConcurrentMode) !== NoMode) {
  20361. nextEffect = offscreenBoundary;
  20362. var offscreenChild = offscreenBoundary.child;
  20363. while (offscreenChild !== null) {
  20364. nextEffect = offscreenChild;
  20365. disappearLayoutEffects_begin(offscreenChild);
  20366. offscreenChild = offscreenChild.sibling;
  20367. }
  20368. }
  20369. }
  20370. }
  20371. }
  20372. {
  20373. // TODO: This needs to run whenever there's an insertion or update
  20374. // inside a hidden Offscreen tree.
  20375. hideOrUnhideAllChildren(offscreenBoundary, _isHidden);
  20376. }
  20377. }
  20378. return;
  20379. }
  20380. case SuspenseListComponent:
  20381. {
  20382. recursivelyTraverseMutationEffects(root, finishedWork);
  20383. commitReconciliationEffects(finishedWork);
  20384. if (flags & Update) {
  20385. attachSuspenseRetryListeners(finishedWork);
  20386. }
  20387. return;
  20388. }
  20389. case ScopeComponent:
  20390. {
  20391. return;
  20392. }
  20393. default:
  20394. {
  20395. recursivelyTraverseMutationEffects(root, finishedWork);
  20396. commitReconciliationEffects(finishedWork);
  20397. return;
  20398. }
  20399. }
  20400. }
  20401. function commitReconciliationEffects(finishedWork) {
  20402. // Placement effects (insertions, reorders) can be scheduled on any fiber
  20403. // type. They needs to happen after the children effects have fired, but
  20404. // before the effects on this fiber have fired.
  20405. var flags = finishedWork.flags;
  20406. if (flags & Placement) {
  20407. try {
  20408. commitPlacement(finishedWork);
  20409. } catch (error) {
  20410. captureCommitPhaseError(finishedWork, finishedWork.return, error);
  20411. } // Clear the "placement" from effect tag so that we know that this is
  20412. // inserted, before any life-cycles like componentDidMount gets called.
  20413. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  20414. // and isMounted is deprecated anyway so we should be able to kill this.
  20415. finishedWork.flags &= ~Placement;
  20416. }
  20417. if (flags & Hydrating) {
  20418. finishedWork.flags &= ~Hydrating;
  20419. }
  20420. }
  20421. function commitLayoutEffects(finishedWork, root, committedLanes) {
  20422. inProgressLanes = committedLanes;
  20423. inProgressRoot = root;
  20424. nextEffect = finishedWork;
  20425. commitLayoutEffects_begin(finishedWork, root, committedLanes);
  20426. inProgressLanes = null;
  20427. inProgressRoot = null;
  20428. }
  20429. function commitLayoutEffects_begin(subtreeRoot, root, committedLanes) {
  20430. // Suspense layout effects semantics don't change for legacy roots.
  20431. var isModernRoot = (subtreeRoot.mode & ConcurrentMode) !== NoMode;
  20432. while (nextEffect !== null) {
  20433. var fiber = nextEffect;
  20434. var firstChild = fiber.child;
  20435. if ( fiber.tag === OffscreenComponent && isModernRoot) {
  20436. // Keep track of the current Offscreen stack's state.
  20437. var isHidden = fiber.memoizedState !== null;
  20438. var newOffscreenSubtreeIsHidden = isHidden || offscreenSubtreeIsHidden;
  20439. if (newOffscreenSubtreeIsHidden) {
  20440. // The Offscreen tree is hidden. Skip over its layout effects.
  20441. commitLayoutMountEffects_complete(subtreeRoot, root, committedLanes);
  20442. continue;
  20443. } else {
  20444. // TODO (Offscreen) Also check: subtreeFlags & LayoutMask
  20445. var current = fiber.alternate;
  20446. var wasHidden = current !== null && current.memoizedState !== null;
  20447. var newOffscreenSubtreeWasHidden = wasHidden || offscreenSubtreeWasHidden;
  20448. var prevOffscreenSubtreeIsHidden = offscreenSubtreeIsHidden;
  20449. var prevOffscreenSubtreeWasHidden = offscreenSubtreeWasHidden; // Traverse the Offscreen subtree with the current Offscreen as the root.
  20450. offscreenSubtreeIsHidden = newOffscreenSubtreeIsHidden;
  20451. offscreenSubtreeWasHidden = newOffscreenSubtreeWasHidden;
  20452. if (offscreenSubtreeWasHidden && !prevOffscreenSubtreeWasHidden) {
  20453. // This is the root of a reappearing boundary. Turn its layout effects
  20454. // back on.
  20455. nextEffect = fiber;
  20456. reappearLayoutEffects_begin(fiber);
  20457. }
  20458. var child = firstChild;
  20459. while (child !== null) {
  20460. nextEffect = child;
  20461. commitLayoutEffects_begin(child, // New root; bubble back up to here and stop.
  20462. root, committedLanes);
  20463. child = child.sibling;
  20464. } // Restore Offscreen state and resume in our-progress traversal.
  20465. nextEffect = fiber;
  20466. offscreenSubtreeIsHidden = prevOffscreenSubtreeIsHidden;
  20467. offscreenSubtreeWasHidden = prevOffscreenSubtreeWasHidden;
  20468. commitLayoutMountEffects_complete(subtreeRoot, root, committedLanes);
  20469. continue;
  20470. }
  20471. }
  20472. if ((fiber.subtreeFlags & LayoutMask) !== NoFlags && firstChild !== null) {
  20473. firstChild.return = fiber;
  20474. nextEffect = firstChild;
  20475. } else {
  20476. commitLayoutMountEffects_complete(subtreeRoot, root, committedLanes);
  20477. }
  20478. }
  20479. }
  20480. function commitLayoutMountEffects_complete(subtreeRoot, root, committedLanes) {
  20481. while (nextEffect !== null) {
  20482. var fiber = nextEffect;
  20483. if ((fiber.flags & LayoutMask) !== NoFlags) {
  20484. var current = fiber.alternate;
  20485. setCurrentFiber(fiber);
  20486. try {
  20487. commitLayoutEffectOnFiber(root, current, fiber, committedLanes);
  20488. } catch (error) {
  20489. captureCommitPhaseError(fiber, fiber.return, error);
  20490. }
  20491. resetCurrentFiber();
  20492. }
  20493. if (fiber === subtreeRoot) {
  20494. nextEffect = null;
  20495. return;
  20496. }
  20497. var sibling = fiber.sibling;
  20498. if (sibling !== null) {
  20499. sibling.return = fiber.return;
  20500. nextEffect = sibling;
  20501. return;
  20502. }
  20503. nextEffect = fiber.return;
  20504. }
  20505. }
  20506. function disappearLayoutEffects_begin(subtreeRoot) {
  20507. while (nextEffect !== null) {
  20508. var fiber = nextEffect;
  20509. var firstChild = fiber.child; // TODO (Offscreen) Check: flags & (RefStatic | LayoutStatic)
  20510. switch (fiber.tag) {
  20511. case FunctionComponent:
  20512. case ForwardRef:
  20513. case MemoComponent:
  20514. case SimpleMemoComponent:
  20515. {
  20516. if ( fiber.mode & ProfileMode) {
  20517. try {
  20518. startLayoutEffectTimer();
  20519. commitHookEffectListUnmount(Layout, fiber, fiber.return);
  20520. } finally {
  20521. recordLayoutEffectDuration(fiber);
  20522. }
  20523. } else {
  20524. commitHookEffectListUnmount(Layout, fiber, fiber.return);
  20525. }
  20526. break;
  20527. }
  20528. case ClassComponent:
  20529. {
  20530. // TODO (Offscreen) Check: flags & RefStatic
  20531. safelyDetachRef(fiber, fiber.return);
  20532. var instance = fiber.stateNode;
  20533. if (typeof instance.componentWillUnmount === 'function') {
  20534. safelyCallComponentWillUnmount(fiber, fiber.return, instance);
  20535. }
  20536. break;
  20537. }
  20538. case HostComponent:
  20539. {
  20540. safelyDetachRef(fiber, fiber.return);
  20541. break;
  20542. }
  20543. case OffscreenComponent:
  20544. {
  20545. // Check if this is a
  20546. var isHidden = fiber.memoizedState !== null;
  20547. if (isHidden) {
  20548. // Nested Offscreen tree is already hidden. Don't disappear
  20549. // its effects.
  20550. disappearLayoutEffects_complete(subtreeRoot);
  20551. continue;
  20552. }
  20553. break;
  20554. }
  20555. } // TODO (Offscreen) Check: subtreeFlags & LayoutStatic
  20556. if (firstChild !== null) {
  20557. firstChild.return = fiber;
  20558. nextEffect = firstChild;
  20559. } else {
  20560. disappearLayoutEffects_complete(subtreeRoot);
  20561. }
  20562. }
  20563. }
  20564. function disappearLayoutEffects_complete(subtreeRoot) {
  20565. while (nextEffect !== null) {
  20566. var fiber = nextEffect;
  20567. if (fiber === subtreeRoot) {
  20568. nextEffect = null;
  20569. return;
  20570. }
  20571. var sibling = fiber.sibling;
  20572. if (sibling !== null) {
  20573. sibling.return = fiber.return;
  20574. nextEffect = sibling;
  20575. return;
  20576. }
  20577. nextEffect = fiber.return;
  20578. }
  20579. }
  20580. function reappearLayoutEffects_begin(subtreeRoot) {
  20581. while (nextEffect !== null) {
  20582. var fiber = nextEffect;
  20583. var firstChild = fiber.child;
  20584. if (fiber.tag === OffscreenComponent) {
  20585. var isHidden = fiber.memoizedState !== null;
  20586. if (isHidden) {
  20587. // Nested Offscreen tree is still hidden. Don't re-appear its effects.
  20588. reappearLayoutEffects_complete(subtreeRoot);
  20589. continue;
  20590. }
  20591. } // TODO (Offscreen) Check: subtreeFlags & LayoutStatic
  20592. if (firstChild !== null) {
  20593. // This node may have been reused from a previous render, so we can't
  20594. // assume its return pointer is correct.
  20595. firstChild.return = fiber;
  20596. nextEffect = firstChild;
  20597. } else {
  20598. reappearLayoutEffects_complete(subtreeRoot);
  20599. }
  20600. }
  20601. }
  20602. function reappearLayoutEffects_complete(subtreeRoot) {
  20603. while (nextEffect !== null) {
  20604. var fiber = nextEffect; // TODO (Offscreen) Check: flags & LayoutStatic
  20605. setCurrentFiber(fiber);
  20606. try {
  20607. reappearLayoutEffectsOnFiber(fiber);
  20608. } catch (error) {
  20609. captureCommitPhaseError(fiber, fiber.return, error);
  20610. }
  20611. resetCurrentFiber();
  20612. if (fiber === subtreeRoot) {
  20613. nextEffect = null;
  20614. return;
  20615. }
  20616. var sibling = fiber.sibling;
  20617. if (sibling !== null) {
  20618. // This node may have been reused from a previous render, so we can't
  20619. // assume its return pointer is correct.
  20620. sibling.return = fiber.return;
  20621. nextEffect = sibling;
  20622. return;
  20623. }
  20624. nextEffect = fiber.return;
  20625. }
  20626. }
  20627. function commitPassiveMountEffects(root, finishedWork, committedLanes, committedTransitions) {
  20628. nextEffect = finishedWork;
  20629. commitPassiveMountEffects_begin(finishedWork, root, committedLanes, committedTransitions);
  20630. }
  20631. function commitPassiveMountEffects_begin(subtreeRoot, root, committedLanes, committedTransitions) {
  20632. while (nextEffect !== null) {
  20633. var fiber = nextEffect;
  20634. var firstChild = fiber.child;
  20635. if ((fiber.subtreeFlags & PassiveMask) !== NoFlags && firstChild !== null) {
  20636. firstChild.return = fiber;
  20637. nextEffect = firstChild;
  20638. } else {
  20639. commitPassiveMountEffects_complete(subtreeRoot, root, committedLanes, committedTransitions);
  20640. }
  20641. }
  20642. }
  20643. function commitPassiveMountEffects_complete(subtreeRoot, root, committedLanes, committedTransitions) {
  20644. while (nextEffect !== null) {
  20645. var fiber = nextEffect;
  20646. if ((fiber.flags & Passive) !== NoFlags) {
  20647. setCurrentFiber(fiber);
  20648. try {
  20649. commitPassiveMountOnFiber(root, fiber, committedLanes, committedTransitions);
  20650. } catch (error) {
  20651. captureCommitPhaseError(fiber, fiber.return, error);
  20652. }
  20653. resetCurrentFiber();
  20654. }
  20655. if (fiber === subtreeRoot) {
  20656. nextEffect = null;
  20657. return;
  20658. }
  20659. var sibling = fiber.sibling;
  20660. if (sibling !== null) {
  20661. sibling.return = fiber.return;
  20662. nextEffect = sibling;
  20663. return;
  20664. }
  20665. nextEffect = fiber.return;
  20666. }
  20667. }
  20668. function commitPassiveMountOnFiber(finishedRoot, finishedWork, committedLanes, committedTransitions) {
  20669. switch (finishedWork.tag) {
  20670. case FunctionComponent:
  20671. case ForwardRef:
  20672. case SimpleMemoComponent:
  20673. {
  20674. if ( finishedWork.mode & ProfileMode) {
  20675. startPassiveEffectTimer();
  20676. try {
  20677. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  20678. } finally {
  20679. recordPassiveEffectDuration(finishedWork);
  20680. }
  20681. } else {
  20682. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  20683. }
  20684. break;
  20685. }
  20686. }
  20687. }
  20688. function commitPassiveUnmountEffects(firstChild) {
  20689. nextEffect = firstChild;
  20690. commitPassiveUnmountEffects_begin();
  20691. }
  20692. function commitPassiveUnmountEffects_begin() {
  20693. while (nextEffect !== null) {
  20694. var fiber = nextEffect;
  20695. var child = fiber.child;
  20696. if ((nextEffect.flags & ChildDeletion) !== NoFlags) {
  20697. var deletions = fiber.deletions;
  20698. if (deletions !== null) {
  20699. for (var i = 0; i < deletions.length; i++) {
  20700. var fiberToDelete = deletions[i];
  20701. nextEffect = fiberToDelete;
  20702. commitPassiveUnmountEffectsInsideOfDeletedTree_begin(fiberToDelete, fiber);
  20703. }
  20704. {
  20705. // A fiber was deleted from this parent fiber, but it's still part of
  20706. // the previous (alternate) parent fiber's list of children. Because
  20707. // children are a linked list, an earlier sibling that's still alive
  20708. // will be connected to the deleted fiber via its `alternate`:
  20709. //
  20710. // live fiber
  20711. // --alternate--> previous live fiber
  20712. // --sibling--> deleted fiber
  20713. //
  20714. // We can't disconnect `alternate` on nodes that haven't been deleted
  20715. // yet, but we can disconnect the `sibling` and `child` pointers.
  20716. var previousFiber = fiber.alternate;
  20717. if (previousFiber !== null) {
  20718. var detachedChild = previousFiber.child;
  20719. if (detachedChild !== null) {
  20720. previousFiber.child = null;
  20721. do {
  20722. var detachedSibling = detachedChild.sibling;
  20723. detachedChild.sibling = null;
  20724. detachedChild = detachedSibling;
  20725. } while (detachedChild !== null);
  20726. }
  20727. }
  20728. }
  20729. nextEffect = fiber;
  20730. }
  20731. }
  20732. if ((fiber.subtreeFlags & PassiveMask) !== NoFlags && child !== null) {
  20733. child.return = fiber;
  20734. nextEffect = child;
  20735. } else {
  20736. commitPassiveUnmountEffects_complete();
  20737. }
  20738. }
  20739. }
  20740. function commitPassiveUnmountEffects_complete() {
  20741. while (nextEffect !== null) {
  20742. var fiber = nextEffect;
  20743. if ((fiber.flags & Passive) !== NoFlags) {
  20744. setCurrentFiber(fiber);
  20745. commitPassiveUnmountOnFiber(fiber);
  20746. resetCurrentFiber();
  20747. }
  20748. var sibling = fiber.sibling;
  20749. if (sibling !== null) {
  20750. sibling.return = fiber.return;
  20751. nextEffect = sibling;
  20752. return;
  20753. }
  20754. nextEffect = fiber.return;
  20755. }
  20756. }
  20757. function commitPassiveUnmountOnFiber(finishedWork) {
  20758. switch (finishedWork.tag) {
  20759. case FunctionComponent:
  20760. case ForwardRef:
  20761. case SimpleMemoComponent:
  20762. {
  20763. if ( finishedWork.mode & ProfileMode) {
  20764. startPassiveEffectTimer();
  20765. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork, finishedWork.return);
  20766. recordPassiveEffectDuration(finishedWork);
  20767. } else {
  20768. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork, finishedWork.return);
  20769. }
  20770. break;
  20771. }
  20772. }
  20773. }
  20774. function commitPassiveUnmountEffectsInsideOfDeletedTree_begin(deletedSubtreeRoot, nearestMountedAncestor) {
  20775. while (nextEffect !== null) {
  20776. var fiber = nextEffect; // Deletion effects fire in parent -> child order
  20777. // TODO: Check if fiber has a PassiveStatic flag
  20778. setCurrentFiber(fiber);
  20779. commitPassiveUnmountInsideDeletedTreeOnFiber(fiber, nearestMountedAncestor);
  20780. resetCurrentFiber();
  20781. var child = fiber.child; // TODO: Only traverse subtree if it has a PassiveStatic flag. (But, if we
  20782. // do this, still need to handle `deletedTreeCleanUpLevel` correctly.)
  20783. if (child !== null) {
  20784. child.return = fiber;
  20785. nextEffect = child;
  20786. } else {
  20787. commitPassiveUnmountEffectsInsideOfDeletedTree_complete(deletedSubtreeRoot);
  20788. }
  20789. }
  20790. }
  20791. function commitPassiveUnmountEffectsInsideOfDeletedTree_complete(deletedSubtreeRoot) {
  20792. while (nextEffect !== null) {
  20793. var fiber = nextEffect;
  20794. var sibling = fiber.sibling;
  20795. var returnFiber = fiber.return;
  20796. {
  20797. // Recursively traverse the entire deleted tree and clean up fiber fields.
  20798. // This is more aggressive than ideal, and the long term goal is to only
  20799. // have to detach the deleted tree at the root.
  20800. detachFiberAfterEffects(fiber);
  20801. if (fiber === deletedSubtreeRoot) {
  20802. nextEffect = null;
  20803. return;
  20804. }
  20805. }
  20806. if (sibling !== null) {
  20807. sibling.return = returnFiber;
  20808. nextEffect = sibling;
  20809. return;
  20810. }
  20811. nextEffect = returnFiber;
  20812. }
  20813. }
  20814. function commitPassiveUnmountInsideDeletedTreeOnFiber(current, nearestMountedAncestor) {
  20815. switch (current.tag) {
  20816. case FunctionComponent:
  20817. case ForwardRef:
  20818. case SimpleMemoComponent:
  20819. {
  20820. if ( current.mode & ProfileMode) {
  20821. startPassiveEffectTimer();
  20822. commitHookEffectListUnmount(Passive$1, current, nearestMountedAncestor);
  20823. recordPassiveEffectDuration(current);
  20824. } else {
  20825. commitHookEffectListUnmount(Passive$1, current, nearestMountedAncestor);
  20826. }
  20827. break;
  20828. }
  20829. }
  20830. } // TODO: Reuse reappearLayoutEffects traversal here?
  20831. function invokeLayoutEffectMountInDEV(fiber) {
  20832. {
  20833. // We don't need to re-check StrictEffectsMode here.
  20834. // This function is only called if that check has already passed.
  20835. switch (fiber.tag) {
  20836. case FunctionComponent:
  20837. case ForwardRef:
  20838. case SimpleMemoComponent:
  20839. {
  20840. try {
  20841. commitHookEffectListMount(Layout | HasEffect, fiber);
  20842. } catch (error) {
  20843. captureCommitPhaseError(fiber, fiber.return, error);
  20844. }
  20845. break;
  20846. }
  20847. case ClassComponent:
  20848. {
  20849. var instance = fiber.stateNode;
  20850. try {
  20851. instance.componentDidMount();
  20852. } catch (error) {
  20853. captureCommitPhaseError(fiber, fiber.return, error);
  20854. }
  20855. break;
  20856. }
  20857. }
  20858. }
  20859. }
  20860. function invokePassiveEffectMountInDEV(fiber) {
  20861. {
  20862. // We don't need to re-check StrictEffectsMode here.
  20863. // This function is only called if that check has already passed.
  20864. switch (fiber.tag) {
  20865. case FunctionComponent:
  20866. case ForwardRef:
  20867. case SimpleMemoComponent:
  20868. {
  20869. try {
  20870. commitHookEffectListMount(Passive$1 | HasEffect, fiber);
  20871. } catch (error) {
  20872. captureCommitPhaseError(fiber, fiber.return, error);
  20873. }
  20874. break;
  20875. }
  20876. }
  20877. }
  20878. }
  20879. function invokeLayoutEffectUnmountInDEV(fiber) {
  20880. {
  20881. // We don't need to re-check StrictEffectsMode here.
  20882. // This function is only called if that check has already passed.
  20883. switch (fiber.tag) {
  20884. case FunctionComponent:
  20885. case ForwardRef:
  20886. case SimpleMemoComponent:
  20887. {
  20888. try {
  20889. commitHookEffectListUnmount(Layout | HasEffect, fiber, fiber.return);
  20890. } catch (error) {
  20891. captureCommitPhaseError(fiber, fiber.return, error);
  20892. }
  20893. break;
  20894. }
  20895. case ClassComponent:
  20896. {
  20897. var instance = fiber.stateNode;
  20898. if (typeof instance.componentWillUnmount === 'function') {
  20899. safelyCallComponentWillUnmount(fiber, fiber.return, instance);
  20900. }
  20901. break;
  20902. }
  20903. }
  20904. }
  20905. }
  20906. function invokePassiveEffectUnmountInDEV(fiber) {
  20907. {
  20908. // We don't need to re-check StrictEffectsMode here.
  20909. // This function is only called if that check has already passed.
  20910. switch (fiber.tag) {
  20911. case FunctionComponent:
  20912. case ForwardRef:
  20913. case SimpleMemoComponent:
  20914. {
  20915. try {
  20916. commitHookEffectListUnmount(Passive$1 | HasEffect, fiber, fiber.return);
  20917. } catch (error) {
  20918. captureCommitPhaseError(fiber, fiber.return, error);
  20919. }
  20920. }
  20921. }
  20922. }
  20923. }
  20924. var COMPONENT_TYPE = 0;
  20925. var HAS_PSEUDO_CLASS_TYPE = 1;
  20926. var ROLE_TYPE = 2;
  20927. var TEST_NAME_TYPE = 3;
  20928. var TEXT_TYPE = 4;
  20929. if (typeof Symbol === 'function' && Symbol.for) {
  20930. var symbolFor = Symbol.for;
  20931. COMPONENT_TYPE = symbolFor('selector.component');
  20932. HAS_PSEUDO_CLASS_TYPE = symbolFor('selector.has_pseudo_class');
  20933. ROLE_TYPE = symbolFor('selector.role');
  20934. TEST_NAME_TYPE = symbolFor('selector.test_id');
  20935. TEXT_TYPE = symbolFor('selector.text');
  20936. }
  20937. var commitHooks = [];
  20938. function onCommitRoot$1() {
  20939. {
  20940. commitHooks.forEach(function (commitHook) {
  20941. return commitHook();
  20942. });
  20943. }
  20944. }
  20945. var ReactCurrentActQueue = ReactSharedInternals.ReactCurrentActQueue;
  20946. function isLegacyActEnvironment(fiber) {
  20947. {
  20948. // Legacy mode. We preserve the behavior of React 17's act. It assumes an
  20949. // act environment whenever `jest` is defined, but you can still turn off
  20950. // spurious warnings by setting IS_REACT_ACT_ENVIRONMENT explicitly
  20951. // to false.
  20952. var isReactActEnvironmentGlobal = // $FlowExpectedError – Flow doesn't know about IS_REACT_ACT_ENVIRONMENT global
  20953. typeof IS_REACT_ACT_ENVIRONMENT !== 'undefined' ? IS_REACT_ACT_ENVIRONMENT : undefined; // $FlowExpectedError - Flow doesn't know about jest
  20954. var jestIsDefined = typeof jest !== 'undefined';
  20955. return jestIsDefined && isReactActEnvironmentGlobal !== false;
  20956. }
  20957. }
  20958. function isConcurrentActEnvironment() {
  20959. {
  20960. var isReactActEnvironmentGlobal = // $FlowExpectedError – Flow doesn't know about IS_REACT_ACT_ENVIRONMENT global
  20961. typeof IS_REACT_ACT_ENVIRONMENT !== 'undefined' ? IS_REACT_ACT_ENVIRONMENT : undefined;
  20962. if (!isReactActEnvironmentGlobal && ReactCurrentActQueue.current !== null) {
  20963. // TODO: Include link to relevant documentation page.
  20964. error('The current testing environment is not configured to support ' + 'act(...)');
  20965. }
  20966. return isReactActEnvironmentGlobal;
  20967. }
  20968. }
  20969. var ceil = Math.ceil;
  20970. var ReactCurrentDispatcher$2 = ReactSharedInternals.ReactCurrentDispatcher,
  20971. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  20972. ReactCurrentBatchConfig$3 = ReactSharedInternals.ReactCurrentBatchConfig,
  20973. ReactCurrentActQueue$1 = ReactSharedInternals.ReactCurrentActQueue;
  20974. var NoContext =
  20975. /* */
  20976. 0;
  20977. var BatchedContext =
  20978. /* */
  20979. 1;
  20980. var RenderContext =
  20981. /* */
  20982. 2;
  20983. var CommitContext =
  20984. /* */
  20985. 4;
  20986. var RootInProgress = 0;
  20987. var RootFatalErrored = 1;
  20988. var RootErrored = 2;
  20989. var RootSuspended = 3;
  20990. var RootSuspendedWithDelay = 4;
  20991. var RootCompleted = 5;
  20992. var RootDidNotComplete = 6; // Describes where we are in the React execution stack
  20993. var executionContext = NoContext; // The root we're working on
  20994. var workInProgressRoot = null; // The fiber we're working on
  20995. var workInProgress = null; // The lanes we're rendering
  20996. var workInProgressRootRenderLanes = NoLanes; // Stack that allows components to change the render lanes for its subtree
  20997. // This is a superset of the lanes we started working on at the root. The only
  20998. // case where it's different from `workInProgressRootRenderLanes` is when we
  20999. // enter a subtree that is hidden and needs to be unhidden: Suspense and
  21000. // Offscreen component.
  21001. //
  21002. // Most things in the work loop should deal with workInProgressRootRenderLanes.
  21003. // Most things in begin/complete phases should deal with subtreeRenderLanes.
  21004. var subtreeRenderLanes = NoLanes;
  21005. var subtreeRenderLanesCursor = createCursor(NoLanes); // Whether to root completed, errored, suspended, etc.
  21006. var workInProgressRootExitStatus = RootInProgress; // A fatal error, if one is thrown
  21007. var workInProgressRootFatalError = null; // "Included" lanes refer to lanes that were worked on during this render. It's
  21008. // slightly different than `renderLanes` because `renderLanes` can change as you
  21009. // enter and exit an Offscreen tree. This value is the combination of all render
  21010. // lanes for the entire render phase.
  21011. var workInProgressRootIncludedLanes = NoLanes; // The work left over by components that were visited during this render. Only
  21012. // includes unprocessed updates, not work in bailed out children.
  21013. var workInProgressRootSkippedLanes = NoLanes; // Lanes that were updated (in an interleaved event) during this render.
  21014. var workInProgressRootInterleavedUpdatedLanes = NoLanes; // Lanes that were updated during the render phase (*not* an interleaved event).
  21015. var workInProgressRootPingedLanes = NoLanes; // Errors that are thrown during the render phase.
  21016. var workInProgressRootConcurrentErrors = null; // These are errors that we recovered from without surfacing them to the UI.
  21017. // We will log them once the tree commits.
  21018. var workInProgressRootRecoverableErrors = null; // The most recent time we committed a fallback. This lets us ensure a train
  21019. // model where we don't commit new loading states in too quick succession.
  21020. var globalMostRecentFallbackTime = 0;
  21021. var FALLBACK_THROTTLE_MS = 500; // The absolute time for when we should start giving up on rendering
  21022. // more and prefer CPU suspense heuristics instead.
  21023. var workInProgressRootRenderTargetTime = Infinity; // How long a render is supposed to take before we start following CPU
  21024. // suspense heuristics and opt out of rendering more content.
  21025. var RENDER_TIMEOUT_MS = 500;
  21026. var workInProgressTransitions = null;
  21027. function resetRenderTimer() {
  21028. workInProgressRootRenderTargetTime = now() + RENDER_TIMEOUT_MS;
  21029. }
  21030. function getRenderTargetTime() {
  21031. return workInProgressRootRenderTargetTime;
  21032. }
  21033. var hasUncaughtError = false;
  21034. var firstUncaughtError = null;
  21035. var legacyErrorBoundariesThatAlreadyFailed = null; // Only used when enableProfilerNestedUpdateScheduledHook is true;
  21036. var rootDoesHavePassiveEffects = false;
  21037. var rootWithPendingPassiveEffects = null;
  21038. var pendingPassiveEffectsLanes = NoLanes;
  21039. var pendingPassiveProfilerEffects = [];
  21040. var pendingPassiveTransitions = null; // Use these to prevent an infinite loop of nested updates
  21041. var NESTED_UPDATE_LIMIT = 50;
  21042. var nestedUpdateCount = 0;
  21043. var rootWithNestedUpdates = null;
  21044. var isFlushingPassiveEffects = false;
  21045. var didScheduleUpdateDuringPassiveEffects = false;
  21046. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  21047. var nestedPassiveUpdateCount = 0;
  21048. var rootWithPassiveNestedUpdates = null; // If two updates are scheduled within the same event, we should treat their
  21049. // event times as simultaneous, even if the actual clock time has advanced
  21050. // between the first and second call.
  21051. var currentEventTime = NoTimestamp;
  21052. var currentEventTransitionLane = NoLanes;
  21053. var isRunningInsertionEffect = false;
  21054. function getWorkInProgressRoot() {
  21055. return workInProgressRoot;
  21056. }
  21057. function requestEventTime() {
  21058. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  21059. // We're inside React, so it's fine to read the actual time.
  21060. return now();
  21061. } // We're not inside React, so we may be in the middle of a browser event.
  21062. if (currentEventTime !== NoTimestamp) {
  21063. // Use the same start time for all updates until we enter React again.
  21064. return currentEventTime;
  21065. } // This is the first update since React yielded. Compute a new start time.
  21066. currentEventTime = now();
  21067. return currentEventTime;
  21068. }
  21069. function requestUpdateLane(fiber) {
  21070. // Special cases
  21071. var mode = fiber.mode;
  21072. if ((mode & ConcurrentMode) === NoMode) {
  21073. return SyncLane;
  21074. } else if ( (executionContext & RenderContext) !== NoContext && workInProgressRootRenderLanes !== NoLanes) {
  21075. // This is a render phase update. These are not officially supported. The
  21076. // old behavior is to give this the same "thread" (lanes) as
  21077. // whatever is currently rendering. So if you call `setState` on a component
  21078. // that happens later in the same render, it will flush. Ideally, we want to
  21079. // remove the special case and treat them as if they came from an
  21080. // interleaved event. Regardless, this pattern is not officially supported.
  21081. // This behavior is only a fallback. The flag only exists until we can roll
  21082. // out the setState warning, since existing code might accidentally rely on
  21083. // the current behavior.
  21084. return pickArbitraryLane(workInProgressRootRenderLanes);
  21085. }
  21086. var isTransition = requestCurrentTransition() !== NoTransition;
  21087. if (isTransition) {
  21088. if ( ReactCurrentBatchConfig$3.transition !== null) {
  21089. var transition = ReactCurrentBatchConfig$3.transition;
  21090. if (!transition._updatedFibers) {
  21091. transition._updatedFibers = new Set();
  21092. }
  21093. transition._updatedFibers.add(fiber);
  21094. } // The algorithm for assigning an update to a lane should be stable for all
  21095. // updates at the same priority within the same event. To do this, the
  21096. // inputs to the algorithm must be the same.
  21097. //
  21098. // The trick we use is to cache the first of each of these inputs within an
  21099. // event. Then reset the cached values once we can be sure the event is
  21100. // over. Our heuristic for that is whenever we enter a concurrent work loop.
  21101. if (currentEventTransitionLane === NoLane) {
  21102. // All transitions within the same event are assigned the same lane.
  21103. currentEventTransitionLane = claimNextTransitionLane();
  21104. }
  21105. return currentEventTransitionLane;
  21106. } // Updates originating inside certain React methods, like flushSync, have
  21107. // their priority set by tracking it with a context variable.
  21108. //
  21109. // The opaque type returned by the host config is internally a lane, so we can
  21110. // use that directly.
  21111. // TODO: Move this type conversion to the event priority module.
  21112. var updateLane = getCurrentUpdatePriority();
  21113. if (updateLane !== NoLane) {
  21114. return updateLane;
  21115. } // This update originated outside React. Ask the host environment for an
  21116. // appropriate priority, based on the type of event.
  21117. //
  21118. // The opaque type returned by the host config is internally a lane, so we can
  21119. // use that directly.
  21120. // TODO: Move this type conversion to the event priority module.
  21121. var eventLane = getCurrentEventPriority();
  21122. return eventLane;
  21123. }
  21124. function requestRetryLane(fiber) {
  21125. // This is a fork of `requestUpdateLane` designed specifically for Suspense
  21126. // "retries" — a special update that attempts to flip a Suspense boundary
  21127. // from its placeholder state to its primary/resolved state.
  21128. // Special cases
  21129. var mode = fiber.mode;
  21130. if ((mode & ConcurrentMode) === NoMode) {
  21131. return SyncLane;
  21132. }
  21133. return claimNextRetryLane();
  21134. }
  21135. function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
  21136. checkForNestedUpdates();
  21137. {
  21138. if (isRunningInsertionEffect) {
  21139. error('useInsertionEffect must not schedule updates.');
  21140. }
  21141. }
  21142. {
  21143. if (isFlushingPassiveEffects) {
  21144. didScheduleUpdateDuringPassiveEffects = true;
  21145. }
  21146. } // Mark that the root has a pending update.
  21147. markRootUpdated(root, lane, eventTime);
  21148. if ((executionContext & RenderContext) !== NoLanes && root === workInProgressRoot) {
  21149. // This update was dispatched during the render phase. This is a mistake
  21150. // if the update originates from user space (with the exception of local
  21151. // hook updates, which are handled differently and don't reach this
  21152. // function), but there are some internal React features that use this as
  21153. // an implementation detail, like selective hydration.
  21154. warnAboutRenderPhaseUpdatesInDEV(fiber); // Track lanes that were updated during the render phase
  21155. } else {
  21156. // This is a normal update, scheduled from outside the render phase. For
  21157. // example, during an input event.
  21158. {
  21159. if (isDevToolsPresent) {
  21160. addFiberToLanesMap(root, fiber, lane);
  21161. }
  21162. }
  21163. warnIfUpdatesNotWrappedWithActDEV(fiber);
  21164. if (root === workInProgressRoot) {
  21165. // Received an update to a tree that's in the middle of rendering. Mark
  21166. // that there was an interleaved update work on this root. Unless the
  21167. // `deferRenderPhaseUpdateToNextBatch` flag is off and this is a render
  21168. // phase update. In that case, we don't treat render phase updates as if
  21169. // they were interleaved, for backwards compat reasons.
  21170. if ( (executionContext & RenderContext) === NoContext) {
  21171. workInProgressRootInterleavedUpdatedLanes = mergeLanes(workInProgressRootInterleavedUpdatedLanes, lane);
  21172. }
  21173. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  21174. // The root already suspended with a delay, which means this render
  21175. // definitely won't finish. Since we have a new update, let's mark it as
  21176. // suspended now, right before marking the incoming update. This has the
  21177. // effect of interrupting the current render and switching to the update.
  21178. // TODO: Make sure this doesn't override pings that happen while we've
  21179. // already started rendering.
  21180. markRootSuspended$1(root, workInProgressRootRenderLanes);
  21181. }
  21182. }
  21183. ensureRootIsScheduled(root, eventTime);
  21184. if (lane === SyncLane && executionContext === NoContext && (fiber.mode & ConcurrentMode) === NoMode && // Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
  21185. !( ReactCurrentActQueue$1.isBatchingLegacy)) {
  21186. // Flush the synchronous work now, unless we're already working or inside
  21187. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  21188. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  21189. // without immediately flushing it. We only do this for user-initiated
  21190. // updates, to preserve historical behavior of legacy mode.
  21191. resetRenderTimer();
  21192. flushSyncCallbacksOnlyInLegacyMode();
  21193. }
  21194. }
  21195. }
  21196. function scheduleInitialHydrationOnRoot(root, lane, eventTime) {
  21197. // This is a special fork of scheduleUpdateOnFiber that is only used to
  21198. // schedule the initial hydration of a root that has just been created. Most
  21199. // of the stuff in scheduleUpdateOnFiber can be skipped.
  21200. //
  21201. // The main reason for this separate path, though, is to distinguish the
  21202. // initial children from subsequent updates. In fully client-rendered roots
  21203. // (createRoot instead of hydrateRoot), all top-level renders are modeled as
  21204. // updates, but hydration roots are special because the initial render must
  21205. // match what was rendered on the server.
  21206. var current = root.current;
  21207. current.lanes = lane;
  21208. markRootUpdated(root, lane, eventTime);
  21209. ensureRootIsScheduled(root, eventTime);
  21210. }
  21211. function isUnsafeClassRenderPhaseUpdate(fiber) {
  21212. // Check if this is a render phase update. Only called by class components,
  21213. // which special (deprecated) behavior for UNSAFE_componentWillReceive props.
  21214. return (// TODO: Remove outdated deferRenderPhaseUpdateToNextBatch experiment. We
  21215. // decided not to enable it.
  21216. (executionContext & RenderContext) !== NoContext
  21217. );
  21218. } // Use this function to schedule a task for a root. There's only one task per
  21219. // root; if a task was already scheduled, we'll check to make sure the priority
  21220. // of the existing task is the same as the priority of the next level that the
  21221. // root has work on. This function is called on every update, and right before
  21222. // exiting a task.
  21223. function ensureRootIsScheduled(root, currentTime) {
  21224. var existingCallbackNode = root.callbackNode; // Check if any lanes are being starved by other work. If so, mark them as
  21225. // expired so we know to work on those next.
  21226. markStarvedLanesAsExpired(root, currentTime); // Determine the next lanes to work on, and their priority.
  21227. var nextLanes = getNextLanes(root, root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes);
  21228. if (nextLanes === NoLanes) {
  21229. // Special case: There's nothing to work on.
  21230. if (existingCallbackNode !== null) {
  21231. cancelCallback$1(existingCallbackNode);
  21232. }
  21233. root.callbackNode = null;
  21234. root.callbackPriority = NoLane;
  21235. return;
  21236. } // We use the highest priority lane to represent the priority of the callback.
  21237. var newCallbackPriority = getHighestPriorityLane(nextLanes); // Check if there's an existing task. We may be able to reuse it.
  21238. var existingCallbackPriority = root.callbackPriority;
  21239. if (existingCallbackPriority === newCallbackPriority && // Special case related to `act`. If the currently scheduled task is a
  21240. // Scheduler task, rather than an `act` task, cancel it and re-scheduled
  21241. // on the `act` queue.
  21242. !( ReactCurrentActQueue$1.current !== null && existingCallbackNode !== fakeActCallbackNode)) {
  21243. {
  21244. // If we're going to re-use an existing task, it needs to exist.
  21245. // Assume that discrete update microtasks are non-cancellable and null.
  21246. // TODO: Temporary until we confirm this warning is not fired.
  21247. if (existingCallbackNode == null && existingCallbackPriority !== SyncLane) {
  21248. error('Expected scheduled callback to exist. This error is likely caused by a bug in React. Please file an issue.');
  21249. }
  21250. } // The priority hasn't changed. We can reuse the existing task. Exit.
  21251. return;
  21252. }
  21253. if (existingCallbackNode != null) {
  21254. // Cancel the existing callback. We'll schedule a new one below.
  21255. cancelCallback$1(existingCallbackNode);
  21256. } // Schedule a new callback.
  21257. var newCallbackNode;
  21258. if (newCallbackPriority === SyncLane) {
  21259. // Special case: Sync React callbacks are scheduled on a special
  21260. // internal queue
  21261. if (root.tag === LegacyRoot) {
  21262. if ( ReactCurrentActQueue$1.isBatchingLegacy !== null) {
  21263. ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
  21264. }
  21265. scheduleLegacySyncCallback(performSyncWorkOnRoot.bind(null, root));
  21266. } else {
  21267. scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  21268. }
  21269. {
  21270. // Flush the queue in a microtask.
  21271. if ( ReactCurrentActQueue$1.current !== null) {
  21272. // Inside `act`, use our internal `act` queue so that these get flushed
  21273. // at the end of the current scope even when using the sync version
  21274. // of `act`.
  21275. ReactCurrentActQueue$1.current.push(flushSyncCallbacks);
  21276. } else {
  21277. scheduleMicrotask(function () {
  21278. // In Safari, appending an iframe forces microtasks to run.
  21279. // https://github.com/facebook/react/issues/22459
  21280. // We don't support running callbacks in the middle of render
  21281. // or commit so we need to check against that.
  21282. if ((executionContext & (RenderContext | CommitContext)) === NoContext) {
  21283. // Note that this would still prematurely flush the callbacks
  21284. // if this happens outside render or commit phase (e.g. in an event).
  21285. flushSyncCallbacks();
  21286. }
  21287. });
  21288. }
  21289. }
  21290. newCallbackNode = null;
  21291. } else {
  21292. var schedulerPriorityLevel;
  21293. switch (lanesToEventPriority(nextLanes)) {
  21294. case DiscreteEventPriority:
  21295. schedulerPriorityLevel = ImmediatePriority;
  21296. break;
  21297. case ContinuousEventPriority:
  21298. schedulerPriorityLevel = UserBlockingPriority;
  21299. break;
  21300. case DefaultEventPriority:
  21301. schedulerPriorityLevel = NormalPriority;
  21302. break;
  21303. case IdleEventPriority:
  21304. schedulerPriorityLevel = IdlePriority;
  21305. break;
  21306. default:
  21307. schedulerPriorityLevel = NormalPriority;
  21308. break;
  21309. }
  21310. newCallbackNode = scheduleCallback$1(schedulerPriorityLevel, performConcurrentWorkOnRoot.bind(null, root));
  21311. }
  21312. root.callbackPriority = newCallbackPriority;
  21313. root.callbackNode = newCallbackNode;
  21314. } // This is the entry point for every concurrent task, i.e. anything that
  21315. // goes through Scheduler.
  21316. function performConcurrentWorkOnRoot(root, didTimeout) {
  21317. {
  21318. resetNestedUpdateFlag();
  21319. } // Since we know we're in a React event, we can clear the current
  21320. // event time. The next update will compute a new event time.
  21321. currentEventTime = NoTimestamp;
  21322. currentEventTransitionLane = NoLanes;
  21323. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  21324. throw new Error('Should not already be working.');
  21325. } // Flush any pending passive effects before deciding which lanes to work on,
  21326. // in case they schedule additional work.
  21327. var originalCallbackNode = root.callbackNode;
  21328. var didFlushPassiveEffects = flushPassiveEffects();
  21329. if (didFlushPassiveEffects) {
  21330. // Something in the passive effect phase may have canceled the current task.
  21331. // Check if the task node for this root was changed.
  21332. if (root.callbackNode !== originalCallbackNode) {
  21333. // The current task was canceled. Exit. We don't need to call
  21334. // `ensureRootIsScheduled` because the check above implies either that
  21335. // there's a new task, or that there's no remaining work on this root.
  21336. return null;
  21337. }
  21338. } // Determine the next lanes to work on, using the fields stored
  21339. // on the root.
  21340. var lanes = getNextLanes(root, root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes);
  21341. if (lanes === NoLanes) {
  21342. // Defensive coding. This is never expected to happen.
  21343. return null;
  21344. } // We disable time-slicing in some cases: if the work has been CPU-bound
  21345. // for too long ("expired" work, to prevent starvation), or we're in
  21346. // sync-updates-by-default mode.
  21347. // TODO: We only check `didTimeout` defensively, to account for a Scheduler
  21348. // bug we're still investigating. Once the bug in Scheduler is fixed,
  21349. // we can remove this, since we track expiration ourselves.
  21350. var shouldTimeSlice = !includesBlockingLane(root, lanes) && !includesExpiredLane(root, lanes) && ( !didTimeout);
  21351. var exitStatus = shouldTimeSlice ? renderRootConcurrent(root, lanes) : renderRootSync(root, lanes);
  21352. if (exitStatus !== RootInProgress) {
  21353. if (exitStatus === RootErrored) {
  21354. // If something threw an error, try rendering one more time. We'll
  21355. // render synchronously to block concurrent data mutations, and we'll
  21356. // includes all pending updates are included. If it still fails after
  21357. // the second attempt, we'll give up and commit the resulting tree.
  21358. var errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);
  21359. if (errorRetryLanes !== NoLanes) {
  21360. lanes = errorRetryLanes;
  21361. exitStatus = recoverFromConcurrentError(root, errorRetryLanes);
  21362. }
  21363. }
  21364. if (exitStatus === RootFatalErrored) {
  21365. var fatalError = workInProgressRootFatalError;
  21366. prepareFreshStack(root, NoLanes);
  21367. markRootSuspended$1(root, lanes);
  21368. ensureRootIsScheduled(root, now());
  21369. throw fatalError;
  21370. }
  21371. if (exitStatus === RootDidNotComplete) {
  21372. // The render unwound without completing the tree. This happens in special
  21373. // cases where need to exit the current render without producing a
  21374. // consistent tree or committing.
  21375. //
  21376. // This should only happen during a concurrent render, not a discrete or
  21377. // synchronous update. We should have already checked for this when we
  21378. // unwound the stack.
  21379. markRootSuspended$1(root, lanes);
  21380. } else {
  21381. // The render completed.
  21382. // Check if this render may have yielded to a concurrent event, and if so,
  21383. // confirm that any newly rendered stores are consistent.
  21384. // TODO: It's possible that even a concurrent render may never have yielded
  21385. // to the main thread, if it was fast enough, or if it expired. We could
  21386. // skip the consistency check in that case, too.
  21387. var renderWasConcurrent = !includesBlockingLane(root, lanes);
  21388. var finishedWork = root.current.alternate;
  21389. if (renderWasConcurrent && !isRenderConsistentWithExternalStores(finishedWork)) {
  21390. // A store was mutated in an interleaved event. Render again,
  21391. // synchronously, to block further mutations.
  21392. exitStatus = renderRootSync(root, lanes); // We need to check again if something threw
  21393. if (exitStatus === RootErrored) {
  21394. var _errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);
  21395. if (_errorRetryLanes !== NoLanes) {
  21396. lanes = _errorRetryLanes;
  21397. exitStatus = recoverFromConcurrentError(root, _errorRetryLanes); // We assume the tree is now consistent because we didn't yield to any
  21398. // concurrent events.
  21399. }
  21400. }
  21401. if (exitStatus === RootFatalErrored) {
  21402. var _fatalError = workInProgressRootFatalError;
  21403. prepareFreshStack(root, NoLanes);
  21404. markRootSuspended$1(root, lanes);
  21405. ensureRootIsScheduled(root, now());
  21406. throw _fatalError;
  21407. }
  21408. } // We now have a consistent tree. The next step is either to commit it,
  21409. // or, if something suspended, wait to commit it after a timeout.
  21410. root.finishedWork = finishedWork;
  21411. root.finishedLanes = lanes;
  21412. finishConcurrentRender(root, exitStatus, lanes);
  21413. }
  21414. }
  21415. ensureRootIsScheduled(root, now());
  21416. if (root.callbackNode === originalCallbackNode) {
  21417. // The task node scheduled for this root is the same one that's
  21418. // currently executed. Need to return a continuation.
  21419. return performConcurrentWorkOnRoot.bind(null, root);
  21420. }
  21421. return null;
  21422. }
  21423. function recoverFromConcurrentError(root, errorRetryLanes) {
  21424. // If an error occurred during hydration, discard server response and fall
  21425. // back to client side render.
  21426. // Before rendering again, save the errors from the previous attempt.
  21427. var errorsFromFirstAttempt = workInProgressRootConcurrentErrors;
  21428. if (isRootDehydrated(root)) {
  21429. // The shell failed to hydrate. Set a flag to force a client rendering
  21430. // during the next attempt. To do this, we call prepareFreshStack now
  21431. // to create the root work-in-progress fiber. This is a bit weird in terms
  21432. // of factoring, because it relies on renderRootSync not calling
  21433. // prepareFreshStack again in the call below, which happens because the
  21434. // root and lanes haven't changed.
  21435. //
  21436. // TODO: I think what we should do is set ForceClientRender inside
  21437. // throwException, like we do for nested Suspense boundaries. The reason
  21438. // it's here instead is so we can switch to the synchronous work loop, too.
  21439. // Something to consider for a future refactor.
  21440. var rootWorkInProgress = prepareFreshStack(root, errorRetryLanes);
  21441. rootWorkInProgress.flags |= ForceClientRender;
  21442. {
  21443. errorHydratingContainer(root.containerInfo);
  21444. }
  21445. }
  21446. var exitStatus = renderRootSync(root, errorRetryLanes);
  21447. if (exitStatus !== RootErrored) {
  21448. // Successfully finished rendering on retry
  21449. // The errors from the failed first attempt have been recovered. Add
  21450. // them to the collection of recoverable errors. We'll log them in the
  21451. // commit phase.
  21452. var errorsFromSecondAttempt = workInProgressRootRecoverableErrors;
  21453. workInProgressRootRecoverableErrors = errorsFromFirstAttempt; // The errors from the second attempt should be queued after the errors
  21454. // from the first attempt, to preserve the causal sequence.
  21455. if (errorsFromSecondAttempt !== null) {
  21456. queueRecoverableErrors(errorsFromSecondAttempt);
  21457. }
  21458. }
  21459. return exitStatus;
  21460. }
  21461. function queueRecoverableErrors(errors) {
  21462. if (workInProgressRootRecoverableErrors === null) {
  21463. workInProgressRootRecoverableErrors = errors;
  21464. } else {
  21465. workInProgressRootRecoverableErrors.push.apply(workInProgressRootRecoverableErrors, errors);
  21466. }
  21467. }
  21468. function finishConcurrentRender(root, exitStatus, lanes) {
  21469. switch (exitStatus) {
  21470. case RootInProgress:
  21471. case RootFatalErrored:
  21472. {
  21473. throw new Error('Root did not complete. This is a bug in React.');
  21474. }
  21475. // Flow knows about invariant, so it complains if I add a break
  21476. // statement, but eslint doesn't know about invariant, so it complains
  21477. // if I do. eslint-disable-next-line no-fallthrough
  21478. case RootErrored:
  21479. {
  21480. // We should have already attempted to retry this tree. If we reached
  21481. // this point, it errored again. Commit it.
  21482. commitRoot(root, workInProgressRootRecoverableErrors, workInProgressTransitions);
  21483. break;
  21484. }
  21485. case RootSuspended:
  21486. {
  21487. markRootSuspended$1(root, lanes); // We have an acceptable loading state. We need to figure out if we
  21488. // should immediately commit it or wait a bit.
  21489. if (includesOnlyRetries(lanes) && // do not delay if we're inside an act() scope
  21490. !shouldForceFlushFallbacksInDEV()) {
  21491. // This render only included retries, no updates. Throttle committing
  21492. // retries so that we don't show too many loading states too quickly.
  21493. var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  21494. if (msUntilTimeout > 10) {
  21495. var nextLanes = getNextLanes(root, NoLanes);
  21496. if (nextLanes !== NoLanes) {
  21497. // There's additional work on this root.
  21498. break;
  21499. }
  21500. var suspendedLanes = root.suspendedLanes;
  21501. if (!isSubsetOfLanes(suspendedLanes, lanes)) {
  21502. // We should prefer to render the fallback of at the last
  21503. // suspended level. Ping the last suspended level to try
  21504. // rendering it again.
  21505. // FIXME: What if the suspended lanes are Idle? Should not restart.
  21506. var eventTime = requestEventTime();
  21507. markRootPinged(root, suspendedLanes);
  21508. break;
  21509. } // The render is suspended, it hasn't timed out, and there's no
  21510. // lower priority work to do. Instead of committing the fallback
  21511. // immediately, wait for more data to arrive.
  21512. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root, workInProgressRootRecoverableErrors, workInProgressTransitions), msUntilTimeout);
  21513. break;
  21514. }
  21515. } // The work expired. Commit immediately.
  21516. commitRoot(root, workInProgressRootRecoverableErrors, workInProgressTransitions);
  21517. break;
  21518. }
  21519. case RootSuspendedWithDelay:
  21520. {
  21521. markRootSuspended$1(root, lanes);
  21522. if (includesOnlyTransitions(lanes)) {
  21523. // This is a transition, so we should exit without committing a
  21524. // placeholder and without scheduling a timeout. Delay indefinitely
  21525. // until we receive more data.
  21526. break;
  21527. }
  21528. if (!shouldForceFlushFallbacksInDEV()) {
  21529. // This is not a transition, but we did trigger an avoided state.
  21530. // Schedule a placeholder to display after a short delay, using the Just
  21531. // Noticeable Difference.
  21532. // TODO: Is the JND optimization worth the added complexity? If this is
  21533. // the only reason we track the event time, then probably not.
  21534. // Consider removing.
  21535. var mostRecentEventTime = getMostRecentEventTime(root, lanes);
  21536. var eventTimeMs = mostRecentEventTime;
  21537. var timeElapsedMs = now() - eventTimeMs;
  21538. var _msUntilTimeout = jnd(timeElapsedMs) - timeElapsedMs; // Don't bother with a very short suspense time.
  21539. if (_msUntilTimeout > 10) {
  21540. // Instead of committing the fallback immediately, wait for more data
  21541. // to arrive.
  21542. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root, workInProgressRootRecoverableErrors, workInProgressTransitions), _msUntilTimeout);
  21543. break;
  21544. }
  21545. } // Commit the placeholder.
  21546. commitRoot(root, workInProgressRootRecoverableErrors, workInProgressTransitions);
  21547. break;
  21548. }
  21549. case RootCompleted:
  21550. {
  21551. // The work completed. Ready to commit.
  21552. commitRoot(root, workInProgressRootRecoverableErrors, workInProgressTransitions);
  21553. break;
  21554. }
  21555. default:
  21556. {
  21557. throw new Error('Unknown root exit status.');
  21558. }
  21559. }
  21560. }
  21561. function isRenderConsistentWithExternalStores(finishedWork) {
  21562. // Search the rendered tree for external store reads, and check whether the
  21563. // stores were mutated in a concurrent event. Intentionally using an iterative
  21564. // loop instead of recursion so we can exit early.
  21565. var node = finishedWork;
  21566. while (true) {
  21567. if (node.flags & StoreConsistency) {
  21568. var updateQueue = node.updateQueue;
  21569. if (updateQueue !== null) {
  21570. var checks = updateQueue.stores;
  21571. if (checks !== null) {
  21572. for (var i = 0; i < checks.length; i++) {
  21573. var check = checks[i];
  21574. var getSnapshot = check.getSnapshot;
  21575. var renderedValue = check.value;
  21576. try {
  21577. if (!objectIs(getSnapshot(), renderedValue)) {
  21578. // Found an inconsistent store.
  21579. return false;
  21580. }
  21581. } catch (error) {
  21582. // If `getSnapshot` throws, return `false`. This will schedule
  21583. // a re-render, and the error will be rethrown during render.
  21584. return false;
  21585. }
  21586. }
  21587. }
  21588. }
  21589. }
  21590. var child = node.child;
  21591. if (node.subtreeFlags & StoreConsistency && child !== null) {
  21592. child.return = node;
  21593. node = child;
  21594. continue;
  21595. }
  21596. if (node === finishedWork) {
  21597. return true;
  21598. }
  21599. while (node.sibling === null) {
  21600. if (node.return === null || node.return === finishedWork) {
  21601. return true;
  21602. }
  21603. node = node.return;
  21604. }
  21605. node.sibling.return = node.return;
  21606. node = node.sibling;
  21607. } // Flow doesn't know this is unreachable, but eslint does
  21608. // eslint-disable-next-line no-unreachable
  21609. return true;
  21610. }
  21611. function markRootSuspended$1(root, suspendedLanes) {
  21612. // When suspending, we should always exclude lanes that were pinged or (more
  21613. // rarely, since we try to avoid it) updated during the render phase.
  21614. // TODO: Lol maybe there's a better way to factor this besides this
  21615. // obnoxiously named function :)
  21616. suspendedLanes = removeLanes(suspendedLanes, workInProgressRootPingedLanes);
  21617. suspendedLanes = removeLanes(suspendedLanes, workInProgressRootInterleavedUpdatedLanes);
  21618. markRootSuspended(root, suspendedLanes);
  21619. } // This is the entry point for synchronous tasks that don't go
  21620. // through Scheduler
  21621. function performSyncWorkOnRoot(root) {
  21622. {
  21623. syncNestedUpdateFlag();
  21624. }
  21625. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  21626. throw new Error('Should not already be working.');
  21627. }
  21628. flushPassiveEffects();
  21629. var lanes = getNextLanes(root, NoLanes);
  21630. if (!includesSomeLane(lanes, SyncLane)) {
  21631. // There's no remaining sync work left.
  21632. ensureRootIsScheduled(root, now());
  21633. return null;
  21634. }
  21635. var exitStatus = renderRootSync(root, lanes);
  21636. if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
  21637. // If something threw an error, try rendering one more time. We'll render
  21638. // synchronously to block concurrent data mutations, and we'll includes
  21639. // all pending updates are included. If it still fails after the second
  21640. // attempt, we'll give up and commit the resulting tree.
  21641. var errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);
  21642. if (errorRetryLanes !== NoLanes) {
  21643. lanes = errorRetryLanes;
  21644. exitStatus = recoverFromConcurrentError(root, errorRetryLanes);
  21645. }
  21646. }
  21647. if (exitStatus === RootFatalErrored) {
  21648. var fatalError = workInProgressRootFatalError;
  21649. prepareFreshStack(root, NoLanes);
  21650. markRootSuspended$1(root, lanes);
  21651. ensureRootIsScheduled(root, now());
  21652. throw fatalError;
  21653. }
  21654. if (exitStatus === RootDidNotComplete) {
  21655. throw new Error('Root did not complete. This is a bug in React.');
  21656. } // We now have a consistent tree. Because this is a sync render, we
  21657. // will commit it even if something suspended.
  21658. var finishedWork = root.current.alternate;
  21659. root.finishedWork = finishedWork;
  21660. root.finishedLanes = lanes;
  21661. commitRoot(root, workInProgressRootRecoverableErrors, workInProgressTransitions); // Before exiting, make sure there's a callback scheduled for the next
  21662. // pending level.
  21663. ensureRootIsScheduled(root, now());
  21664. return null;
  21665. }
  21666. function flushRoot(root, lanes) {
  21667. if (lanes !== NoLanes) {
  21668. markRootEntangled(root, mergeLanes(lanes, SyncLane));
  21669. ensureRootIsScheduled(root, now());
  21670. if ((executionContext & (RenderContext | CommitContext)) === NoContext) {
  21671. resetRenderTimer();
  21672. flushSyncCallbacks();
  21673. }
  21674. }
  21675. }
  21676. function batchedUpdates$1(fn, a) {
  21677. var prevExecutionContext = executionContext;
  21678. executionContext |= BatchedContext;
  21679. try {
  21680. return fn(a);
  21681. } finally {
  21682. executionContext = prevExecutionContext; // If there were legacy sync updates, flush them at the end of the outer
  21683. // most batchedUpdates-like method.
  21684. if (executionContext === NoContext && // Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
  21685. !( ReactCurrentActQueue$1.isBatchingLegacy)) {
  21686. resetRenderTimer();
  21687. flushSyncCallbacksOnlyInLegacyMode();
  21688. }
  21689. }
  21690. }
  21691. function discreteUpdates(fn, a, b, c, d) {
  21692. var previousPriority = getCurrentUpdatePriority();
  21693. var prevTransition = ReactCurrentBatchConfig$3.transition;
  21694. try {
  21695. ReactCurrentBatchConfig$3.transition = null;
  21696. setCurrentUpdatePriority(DiscreteEventPriority);
  21697. return fn(a, b, c, d);
  21698. } finally {
  21699. setCurrentUpdatePriority(previousPriority);
  21700. ReactCurrentBatchConfig$3.transition = prevTransition;
  21701. if (executionContext === NoContext) {
  21702. resetRenderTimer();
  21703. }
  21704. }
  21705. } // Overload the definition to the two valid signatures.
  21706. // Warning, this opts-out of checking the function body.
  21707. // eslint-disable-next-line no-redeclare
  21708. function flushSync(fn) {
  21709. // In legacy mode, we flush pending passive effects at the beginning of the
  21710. // next event, not at the end of the previous one.
  21711. if (rootWithPendingPassiveEffects !== null && rootWithPendingPassiveEffects.tag === LegacyRoot && (executionContext & (RenderContext | CommitContext)) === NoContext) {
  21712. flushPassiveEffects();
  21713. }
  21714. var prevExecutionContext = executionContext;
  21715. executionContext |= BatchedContext;
  21716. var prevTransition = ReactCurrentBatchConfig$3.transition;
  21717. var previousPriority = getCurrentUpdatePriority();
  21718. try {
  21719. ReactCurrentBatchConfig$3.transition = null;
  21720. setCurrentUpdatePriority(DiscreteEventPriority);
  21721. if (fn) {
  21722. return fn();
  21723. } else {
  21724. return undefined;
  21725. }
  21726. } finally {
  21727. setCurrentUpdatePriority(previousPriority);
  21728. ReactCurrentBatchConfig$3.transition = prevTransition;
  21729. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  21730. // Note that this will happen even if batchedUpdates is higher up
  21731. // the stack.
  21732. if ((executionContext & (RenderContext | CommitContext)) === NoContext) {
  21733. flushSyncCallbacks();
  21734. }
  21735. }
  21736. }
  21737. function isAlreadyRendering() {
  21738. // Used by the renderer to print a warning if certain APIs are called from
  21739. // the wrong context.
  21740. return (executionContext & (RenderContext | CommitContext)) !== NoContext;
  21741. }
  21742. function pushRenderLanes(fiber, lanes) {
  21743. push(subtreeRenderLanesCursor, subtreeRenderLanes, fiber);
  21744. subtreeRenderLanes = mergeLanes(subtreeRenderLanes, lanes);
  21745. workInProgressRootIncludedLanes = mergeLanes(workInProgressRootIncludedLanes, lanes);
  21746. }
  21747. function popRenderLanes(fiber) {
  21748. subtreeRenderLanes = subtreeRenderLanesCursor.current;
  21749. pop(subtreeRenderLanesCursor, fiber);
  21750. }
  21751. function prepareFreshStack(root, lanes) {
  21752. root.finishedWork = null;
  21753. root.finishedLanes = NoLanes;
  21754. var timeoutHandle = root.timeoutHandle;
  21755. if (timeoutHandle !== noTimeout) {
  21756. // The root previous suspended and scheduled a timeout to commit a fallback
  21757. // state. Now that we have additional work, cancel the timeout.
  21758. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  21759. cancelTimeout(timeoutHandle);
  21760. }
  21761. if (workInProgress !== null) {
  21762. var interruptedWork = workInProgress.return;
  21763. while (interruptedWork !== null) {
  21764. var current = interruptedWork.alternate;
  21765. unwindInterruptedWork(current, interruptedWork);
  21766. interruptedWork = interruptedWork.return;
  21767. }
  21768. }
  21769. workInProgressRoot = root;
  21770. var rootWorkInProgress = createWorkInProgress(root.current, null);
  21771. workInProgress = rootWorkInProgress;
  21772. workInProgressRootRenderLanes = subtreeRenderLanes = workInProgressRootIncludedLanes = lanes;
  21773. workInProgressRootExitStatus = RootInProgress;
  21774. workInProgressRootFatalError = null;
  21775. workInProgressRootSkippedLanes = NoLanes;
  21776. workInProgressRootInterleavedUpdatedLanes = NoLanes;
  21777. workInProgressRootPingedLanes = NoLanes;
  21778. workInProgressRootConcurrentErrors = null;
  21779. workInProgressRootRecoverableErrors = null;
  21780. finishQueueingConcurrentUpdates();
  21781. {
  21782. ReactStrictModeWarnings.discardPendingWarnings();
  21783. }
  21784. return rootWorkInProgress;
  21785. }
  21786. function handleError(root, thrownValue) {
  21787. do {
  21788. var erroredWork = workInProgress;
  21789. try {
  21790. // Reset module-level state that was set during the render phase.
  21791. resetContextDependencies();
  21792. resetHooksAfterThrow();
  21793. resetCurrentFiber(); // TODO: I found and added this missing line while investigating a
  21794. // separate issue. Write a regression test using string refs.
  21795. ReactCurrentOwner$2.current = null;
  21796. if (erroredWork === null || erroredWork.return === null) {
  21797. // Expected to be working on a non-root fiber. This is a fatal error
  21798. // because there's no ancestor that can handle it; the root is
  21799. // supposed to capture all errors that weren't caught by an error
  21800. // boundary.
  21801. workInProgressRootExitStatus = RootFatalErrored;
  21802. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  21803. // sibling, or the parent if there are no siblings. But since the root
  21804. // has no siblings nor a parent, we set it to null. Usually this is
  21805. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  21806. // intentionally not calling those, we need set it here.
  21807. // TODO: Consider calling `unwindWork` to pop the contexts.
  21808. workInProgress = null;
  21809. return;
  21810. }
  21811. if (enableProfilerTimer && erroredWork.mode & ProfileMode) {
  21812. // Record the time spent rendering before an error was thrown. This
  21813. // avoids inaccurate Profiler durations in the case of a
  21814. // suspended render.
  21815. stopProfilerTimerIfRunningAndRecordDelta(erroredWork, true);
  21816. }
  21817. if (enableSchedulingProfiler) {
  21818. markComponentRenderStopped();
  21819. if (thrownValue !== null && typeof thrownValue === 'object' && typeof thrownValue.then === 'function') {
  21820. var wakeable = thrownValue;
  21821. markComponentSuspended(erroredWork, wakeable, workInProgressRootRenderLanes);
  21822. } else {
  21823. markComponentErrored(erroredWork, thrownValue, workInProgressRootRenderLanes);
  21824. }
  21825. }
  21826. throwException(root, erroredWork.return, erroredWork, thrownValue, workInProgressRootRenderLanes);
  21827. completeUnitOfWork(erroredWork);
  21828. } catch (yetAnotherThrownValue) {
  21829. // Something in the return path also threw.
  21830. thrownValue = yetAnotherThrownValue;
  21831. if (workInProgress === erroredWork && erroredWork !== null) {
  21832. // If this boundary has already errored, then we had trouble processing
  21833. // the error. Bubble it to the next boundary.
  21834. erroredWork = erroredWork.return;
  21835. workInProgress = erroredWork;
  21836. } else {
  21837. erroredWork = workInProgress;
  21838. }
  21839. continue;
  21840. } // Return to the normal work loop.
  21841. return;
  21842. } while (true);
  21843. }
  21844. function pushDispatcher() {
  21845. var prevDispatcher = ReactCurrentDispatcher$2.current;
  21846. ReactCurrentDispatcher$2.current = ContextOnlyDispatcher;
  21847. if (prevDispatcher === null) {
  21848. // The React isomorphic package does not include a default dispatcher.
  21849. // Instead the first renderer will lazily attach one, in order to give
  21850. // nicer error messages.
  21851. return ContextOnlyDispatcher;
  21852. } else {
  21853. return prevDispatcher;
  21854. }
  21855. }
  21856. function popDispatcher(prevDispatcher) {
  21857. ReactCurrentDispatcher$2.current = prevDispatcher;
  21858. }
  21859. function markCommitTimeOfFallback() {
  21860. globalMostRecentFallbackTime = now();
  21861. }
  21862. function markSkippedUpdateLanes(lane) {
  21863. workInProgressRootSkippedLanes = mergeLanes(lane, workInProgressRootSkippedLanes);
  21864. }
  21865. function renderDidSuspend() {
  21866. if (workInProgressRootExitStatus === RootInProgress) {
  21867. workInProgressRootExitStatus = RootSuspended;
  21868. }
  21869. }
  21870. function renderDidSuspendDelayIfPossible() {
  21871. if (workInProgressRootExitStatus === RootInProgress || workInProgressRootExitStatus === RootSuspended || workInProgressRootExitStatus === RootErrored) {
  21872. workInProgressRootExitStatus = RootSuspendedWithDelay;
  21873. } // Check if there are updates that we skipped tree that might have unblocked
  21874. // this render.
  21875. if (workInProgressRoot !== null && (includesNonIdleWork(workInProgressRootSkippedLanes) || includesNonIdleWork(workInProgressRootInterleavedUpdatedLanes))) {
  21876. // Mark the current render as suspended so that we switch to working on
  21877. // the updates that were skipped. Usually we only suspend at the end of
  21878. // the render phase.
  21879. // TODO: We should probably always mark the root as suspended immediately
  21880. // (inside this function), since by suspending at the end of the render
  21881. // phase introduces a potential mistake where we suspend lanes that were
  21882. // pinged or updated while we were rendering.
  21883. markRootSuspended$1(workInProgressRoot, workInProgressRootRenderLanes);
  21884. }
  21885. }
  21886. function renderDidError(error) {
  21887. if (workInProgressRootExitStatus !== RootSuspendedWithDelay) {
  21888. workInProgressRootExitStatus = RootErrored;
  21889. }
  21890. if (workInProgressRootConcurrentErrors === null) {
  21891. workInProgressRootConcurrentErrors = [error];
  21892. } else {
  21893. workInProgressRootConcurrentErrors.push(error);
  21894. }
  21895. } // Called during render to determine if anything has suspended.
  21896. // Returns false if we're not sure.
  21897. function renderHasNotSuspendedYet() {
  21898. // If something errored or completed, we can't really be sure,
  21899. // so those are false.
  21900. return workInProgressRootExitStatus === RootInProgress;
  21901. }
  21902. function renderRootSync(root, lanes) {
  21903. var prevExecutionContext = executionContext;
  21904. executionContext |= RenderContext;
  21905. var prevDispatcher = pushDispatcher(); // If the root or lanes have changed, throw out the existing stack
  21906. // and prepare a fresh one. Otherwise we'll continue where we left off.
  21907. if (workInProgressRoot !== root || workInProgressRootRenderLanes !== lanes) {
  21908. {
  21909. if (isDevToolsPresent) {
  21910. var memoizedUpdaters = root.memoizedUpdaters;
  21911. if (memoizedUpdaters.size > 0) {
  21912. restorePendingUpdaters(root, workInProgressRootRenderLanes);
  21913. memoizedUpdaters.clear();
  21914. } // At this point, move Fibers that scheduled the upcoming work from the Map to the Set.
  21915. // If we bailout on this work, we'll move them back (like above).
  21916. // It's important to move them now in case the work spawns more work at the same priority with different updaters.
  21917. // That way we can keep the current update and future updates separate.
  21918. movePendingFibersToMemoized(root, lanes);
  21919. }
  21920. }
  21921. workInProgressTransitions = getTransitionsForLanes();
  21922. prepareFreshStack(root, lanes);
  21923. }
  21924. {
  21925. markRenderStarted(lanes);
  21926. }
  21927. do {
  21928. try {
  21929. workLoopSync();
  21930. break;
  21931. } catch (thrownValue) {
  21932. handleError(root, thrownValue);
  21933. }
  21934. } while (true);
  21935. resetContextDependencies();
  21936. executionContext = prevExecutionContext;
  21937. popDispatcher(prevDispatcher);
  21938. if (workInProgress !== null) {
  21939. // This is a sync render, so we should have finished the whole tree.
  21940. throw new Error('Cannot commit an incomplete root. This error is likely caused by a ' + 'bug in React. Please file an issue.');
  21941. }
  21942. {
  21943. markRenderStopped();
  21944. } // Set this to null to indicate there's no in-progress render.
  21945. workInProgressRoot = null;
  21946. workInProgressRootRenderLanes = NoLanes;
  21947. return workInProgressRootExitStatus;
  21948. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  21949. /** @noinline */
  21950. function workLoopSync() {
  21951. // Already timed out, so perform work without checking if we need to yield.
  21952. while (workInProgress !== null) {
  21953. performUnitOfWork(workInProgress);
  21954. }
  21955. }
  21956. function renderRootConcurrent(root, lanes) {
  21957. var prevExecutionContext = executionContext;
  21958. executionContext |= RenderContext;
  21959. var prevDispatcher = pushDispatcher(); // If the root or lanes have changed, throw out the existing stack
  21960. // and prepare a fresh one. Otherwise we'll continue where we left off.
  21961. if (workInProgressRoot !== root || workInProgressRootRenderLanes !== lanes) {
  21962. {
  21963. if (isDevToolsPresent) {
  21964. var memoizedUpdaters = root.memoizedUpdaters;
  21965. if (memoizedUpdaters.size > 0) {
  21966. restorePendingUpdaters(root, workInProgressRootRenderLanes);
  21967. memoizedUpdaters.clear();
  21968. } // At this point, move Fibers that scheduled the upcoming work from the Map to the Set.
  21969. // If we bailout on this work, we'll move them back (like above).
  21970. // It's important to move them now in case the work spawns more work at the same priority with different updaters.
  21971. // That way we can keep the current update and future updates separate.
  21972. movePendingFibersToMemoized(root, lanes);
  21973. }
  21974. }
  21975. workInProgressTransitions = getTransitionsForLanes();
  21976. resetRenderTimer();
  21977. prepareFreshStack(root, lanes);
  21978. }
  21979. {
  21980. markRenderStarted(lanes);
  21981. }
  21982. do {
  21983. try {
  21984. workLoopConcurrent();
  21985. break;
  21986. } catch (thrownValue) {
  21987. handleError(root, thrownValue);
  21988. }
  21989. } while (true);
  21990. resetContextDependencies();
  21991. popDispatcher(prevDispatcher);
  21992. executionContext = prevExecutionContext;
  21993. if (workInProgress !== null) {
  21994. // Still work remaining.
  21995. {
  21996. markRenderYielded();
  21997. }
  21998. return RootInProgress;
  21999. } else {
  22000. // Completed the tree.
  22001. {
  22002. markRenderStopped();
  22003. } // Set this to null to indicate there's no in-progress render.
  22004. workInProgressRoot = null;
  22005. workInProgressRootRenderLanes = NoLanes; // Return the final exit status.
  22006. return workInProgressRootExitStatus;
  22007. }
  22008. }
  22009. /** @noinline */
  22010. function workLoopConcurrent() {
  22011. // Perform work until Scheduler asks us to yield
  22012. while (workInProgress !== null && !shouldYield()) {
  22013. performUnitOfWork(workInProgress);
  22014. }
  22015. }
  22016. function performUnitOfWork(unitOfWork) {
  22017. // The current, flushed, state of this fiber is the alternate. Ideally
  22018. // nothing should rely on this, but relying on it here means that we don't
  22019. // need an additional field on the work in progress.
  22020. var current = unitOfWork.alternate;
  22021. setCurrentFiber(unitOfWork);
  22022. var next;
  22023. if ( (unitOfWork.mode & ProfileMode) !== NoMode) {
  22024. startProfilerTimer(unitOfWork);
  22025. next = beginWork$1(current, unitOfWork, subtreeRenderLanes);
  22026. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  22027. } else {
  22028. next = beginWork$1(current, unitOfWork, subtreeRenderLanes);
  22029. }
  22030. resetCurrentFiber();
  22031. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  22032. if (next === null) {
  22033. // If this doesn't spawn new work, complete the current work.
  22034. completeUnitOfWork(unitOfWork);
  22035. } else {
  22036. workInProgress = next;
  22037. }
  22038. ReactCurrentOwner$2.current = null;
  22039. }
  22040. function completeUnitOfWork(unitOfWork) {
  22041. // Attempt to complete the current unit of work, then move to the next
  22042. // sibling. If there are no more siblings, return to the parent fiber.
  22043. var completedWork = unitOfWork;
  22044. do {
  22045. // The current, flushed, state of this fiber is the alternate. Ideally
  22046. // nothing should rely on this, but relying on it here means that we don't
  22047. // need an additional field on the work in progress.
  22048. var current = completedWork.alternate;
  22049. var returnFiber = completedWork.return; // Check if the work completed or if something threw.
  22050. if ((completedWork.flags & Incomplete) === NoFlags) {
  22051. setCurrentFiber(completedWork);
  22052. var next = void 0;
  22053. if ( (completedWork.mode & ProfileMode) === NoMode) {
  22054. next = completeWork(current, completedWork, subtreeRenderLanes);
  22055. } else {
  22056. startProfilerTimer(completedWork);
  22057. next = completeWork(current, completedWork, subtreeRenderLanes); // Update render duration assuming we didn't error.
  22058. stopProfilerTimerIfRunningAndRecordDelta(completedWork, false);
  22059. }
  22060. resetCurrentFiber();
  22061. if (next !== null) {
  22062. // Completing this fiber spawned new work. Work on that next.
  22063. workInProgress = next;
  22064. return;
  22065. }
  22066. } else {
  22067. // This fiber did not complete because something threw. Pop values off
  22068. // the stack without entering the complete phase. If this is a boundary,
  22069. // capture values if possible.
  22070. var _next = unwindWork(current, completedWork); // Because this fiber did not complete, don't reset its lanes.
  22071. if (_next !== null) {
  22072. // If completing this work spawned new work, do that next. We'll come
  22073. // back here again.
  22074. // Since we're restarting, remove anything that is not a host effect
  22075. // from the effect tag.
  22076. _next.flags &= HostEffectMask;
  22077. workInProgress = _next;
  22078. return;
  22079. }
  22080. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  22081. // Record the render duration for the fiber that errored.
  22082. stopProfilerTimerIfRunningAndRecordDelta(completedWork, false); // Include the time spent working on failed children before continuing.
  22083. var actualDuration = completedWork.actualDuration;
  22084. var child = completedWork.child;
  22085. while (child !== null) {
  22086. actualDuration += child.actualDuration;
  22087. child = child.sibling;
  22088. }
  22089. completedWork.actualDuration = actualDuration;
  22090. }
  22091. if (returnFiber !== null) {
  22092. // Mark the parent fiber as incomplete and clear its subtree flags.
  22093. returnFiber.flags |= Incomplete;
  22094. returnFiber.subtreeFlags = NoFlags;
  22095. returnFiber.deletions = null;
  22096. } else {
  22097. // We've unwound all the way to the root.
  22098. workInProgressRootExitStatus = RootDidNotComplete;
  22099. workInProgress = null;
  22100. return;
  22101. }
  22102. }
  22103. var siblingFiber = completedWork.sibling;
  22104. if (siblingFiber !== null) {
  22105. // If there is more work to do in this returnFiber, do that next.
  22106. workInProgress = siblingFiber;
  22107. return;
  22108. } // Otherwise, return to the parent
  22109. completedWork = returnFiber; // Update the next thing we're working on in case something throws.
  22110. workInProgress = completedWork;
  22111. } while (completedWork !== null); // We've reached the root.
  22112. if (workInProgressRootExitStatus === RootInProgress) {
  22113. workInProgressRootExitStatus = RootCompleted;
  22114. }
  22115. }
  22116. function commitRoot(root, recoverableErrors, transitions) {
  22117. // TODO: This no longer makes any sense. We already wrap the mutation and
  22118. // layout phases. Should be able to remove.
  22119. var previousUpdateLanePriority = getCurrentUpdatePriority();
  22120. var prevTransition = ReactCurrentBatchConfig$3.transition;
  22121. try {
  22122. ReactCurrentBatchConfig$3.transition = null;
  22123. setCurrentUpdatePriority(DiscreteEventPriority);
  22124. commitRootImpl(root, recoverableErrors, transitions, previousUpdateLanePriority);
  22125. } finally {
  22126. ReactCurrentBatchConfig$3.transition = prevTransition;
  22127. setCurrentUpdatePriority(previousUpdateLanePriority);
  22128. }
  22129. return null;
  22130. }
  22131. function commitRootImpl(root, recoverableErrors, transitions, renderPriorityLevel) {
  22132. do {
  22133. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  22134. // means `flushPassiveEffects` will sometimes result in additional
  22135. // passive effects. So we need to keep flushing in a loop until there are
  22136. // no more pending effects.
  22137. // TODO: Might be better if `flushPassiveEffects` did not automatically
  22138. // flush synchronous work at the end, to avoid factoring hazards like this.
  22139. flushPassiveEffects();
  22140. } while (rootWithPendingPassiveEffects !== null);
  22141. flushRenderPhaseStrictModeWarningsInDEV();
  22142. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  22143. throw new Error('Should not already be working.');
  22144. }
  22145. var finishedWork = root.finishedWork;
  22146. var lanes = root.finishedLanes;
  22147. {
  22148. markCommitStarted(lanes);
  22149. }
  22150. if (finishedWork === null) {
  22151. {
  22152. markCommitStopped();
  22153. }
  22154. return null;
  22155. } else {
  22156. {
  22157. if (lanes === NoLanes) {
  22158. error('root.finishedLanes should not be empty during a commit. This is a ' + 'bug in React.');
  22159. }
  22160. }
  22161. }
  22162. root.finishedWork = null;
  22163. root.finishedLanes = NoLanes;
  22164. if (finishedWork === root.current) {
  22165. throw new Error('Cannot commit the same tree as before. This error is likely caused by ' + 'a bug in React. Please file an issue.');
  22166. } // commitRoot never returns a continuation; it always finishes synchronously.
  22167. // So we can clear these now to allow a new callback to be scheduled.
  22168. root.callbackNode = null;
  22169. root.callbackPriority = NoLane; // Update the first and last pending times on this root. The new first
  22170. // pending time is whatever is left on the root fiber.
  22171. var remainingLanes = mergeLanes(finishedWork.lanes, finishedWork.childLanes);
  22172. markRootFinished(root, remainingLanes);
  22173. if (root === workInProgressRoot) {
  22174. // We can reset these now that they are finished.
  22175. workInProgressRoot = null;
  22176. workInProgress = null;
  22177. workInProgressRootRenderLanes = NoLanes;
  22178. } // If there are pending passive effects, schedule a callback to process them.
  22179. // Do this as early as possible, so it is queued before anything else that
  22180. // might get scheduled in the commit phase. (See #16714.)
  22181. // TODO: Delete all other places that schedule the passive effect callback
  22182. // They're redundant.
  22183. if ((finishedWork.subtreeFlags & PassiveMask) !== NoFlags || (finishedWork.flags & PassiveMask) !== NoFlags) {
  22184. if (!rootDoesHavePassiveEffects) {
  22185. rootDoesHavePassiveEffects = true;
  22186. // to store it in pendingPassiveTransitions until they get processed
  22187. // We need to pass this through as an argument to commitRoot
  22188. // because workInProgressTransitions might have changed between
  22189. // the previous render and commit if we throttle the commit
  22190. // with setTimeout
  22191. pendingPassiveTransitions = transitions;
  22192. scheduleCallback$1(NormalPriority, function () {
  22193. flushPassiveEffects(); // This render triggered passive effects: release the root cache pool
  22194. // *after* passive effects fire to avoid freeing a cache pool that may
  22195. // be referenced by a node in the tree (HostRoot, Cache boundary etc)
  22196. return null;
  22197. });
  22198. }
  22199. } // Check if there are any effects in the whole tree.
  22200. // TODO: This is left over from the effect list implementation, where we had
  22201. // to check for the existence of `firstEffect` to satisfy Flow. I think the
  22202. // only other reason this optimization exists is because it affects profiling.
  22203. // Reconsider whether this is necessary.
  22204. var subtreeHasEffects = (finishedWork.subtreeFlags & (BeforeMutationMask | MutationMask | LayoutMask | PassiveMask)) !== NoFlags;
  22205. var rootHasEffect = (finishedWork.flags & (BeforeMutationMask | MutationMask | LayoutMask | PassiveMask)) !== NoFlags;
  22206. if (subtreeHasEffects || rootHasEffect) {
  22207. var prevTransition = ReactCurrentBatchConfig$3.transition;
  22208. ReactCurrentBatchConfig$3.transition = null;
  22209. var previousPriority = getCurrentUpdatePriority();
  22210. setCurrentUpdatePriority(DiscreteEventPriority);
  22211. var prevExecutionContext = executionContext;
  22212. executionContext |= CommitContext; // Reset this to null before calling lifecycles
  22213. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  22214. // of the effect list for each phase: all mutation effects come before all
  22215. // layout effects, and so on.
  22216. // The first phase a "before mutation" phase. We use this phase to read the
  22217. // state of the host tree right before we mutate it. This is where
  22218. // getSnapshotBeforeUpdate is called.
  22219. var shouldFireAfterActiveInstanceBlur = commitBeforeMutationEffects(root, finishedWork);
  22220. {
  22221. // Mark the current commit time to be shared by all Profilers in this
  22222. // batch. This enables them to be grouped later.
  22223. recordCommitTime();
  22224. }
  22225. commitMutationEffects(root, finishedWork, lanes);
  22226. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  22227. // the mutation phase, so that the previous tree is still current during
  22228. // componentWillUnmount, but before the layout phase, so that the finished
  22229. // work is current during componentDidMount/Update.
  22230. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  22231. {
  22232. markLayoutEffectsStarted(lanes);
  22233. }
  22234. commitLayoutEffects(finishedWork, root, lanes);
  22235. {
  22236. markLayoutEffectsStopped();
  22237. }
  22238. // opportunity to paint.
  22239. requestPaint();
  22240. executionContext = prevExecutionContext; // Reset the priority to the previous non-sync value.
  22241. setCurrentUpdatePriority(previousPriority);
  22242. ReactCurrentBatchConfig$3.transition = prevTransition;
  22243. } else {
  22244. // No effects.
  22245. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  22246. // no effects.
  22247. // TODO: Maybe there's a better way to report this.
  22248. {
  22249. recordCommitTime();
  22250. }
  22251. }
  22252. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  22253. if (rootDoesHavePassiveEffects) {
  22254. // This commit has passive effects. Stash a reference to them. But don't
  22255. // schedule a callback until after flushing layout work.
  22256. rootDoesHavePassiveEffects = false;
  22257. rootWithPendingPassiveEffects = root;
  22258. pendingPassiveEffectsLanes = lanes;
  22259. } else {
  22260. {
  22261. nestedPassiveUpdateCount = 0;
  22262. rootWithPassiveNestedUpdates = null;
  22263. }
  22264. } // Read this again, since an effect might have updated it
  22265. remainingLanes = root.pendingLanes; // Check if there's remaining work on this root
  22266. // TODO: This is part of the `componentDidCatch` implementation. Its purpose
  22267. // is to detect whether something might have called setState inside
  22268. // `componentDidCatch`. The mechanism is known to be flawed because `setState`
  22269. // inside `componentDidCatch` is itself flawed — that's why we recommend
  22270. // `getDerivedStateFromError` instead. However, it could be improved by
  22271. // checking if remainingLanes includes Sync work, instead of whether there's
  22272. // any work remaining at all (which would also include stuff like Suspense
  22273. // retries or transitions). It's been like this for a while, though, so fixing
  22274. // it probably isn't that urgent.
  22275. if (remainingLanes === NoLanes) {
  22276. // If there's no remaining work, we can clear the set of already failed
  22277. // error boundaries.
  22278. legacyErrorBoundariesThatAlreadyFailed = null;
  22279. }
  22280. {
  22281. if (!rootDidHavePassiveEffects) {
  22282. commitDoubleInvokeEffectsInDEV(root.current, false);
  22283. }
  22284. }
  22285. onCommitRoot(finishedWork.stateNode, renderPriorityLevel);
  22286. {
  22287. if (isDevToolsPresent) {
  22288. root.memoizedUpdaters.clear();
  22289. }
  22290. }
  22291. {
  22292. onCommitRoot$1();
  22293. } // Always call this before exiting `commitRoot`, to ensure that any
  22294. // additional work on this root is scheduled.
  22295. ensureRootIsScheduled(root, now());
  22296. if (recoverableErrors !== null) {
  22297. // There were errors during this render, but recovered from them without
  22298. // needing to surface it to the UI. We log them here.
  22299. var onRecoverableError = root.onRecoverableError;
  22300. for (var i = 0; i < recoverableErrors.length; i++) {
  22301. var recoverableError = recoverableErrors[i];
  22302. var componentStack = recoverableError.stack;
  22303. var digest = recoverableError.digest;
  22304. onRecoverableError(recoverableError.value, {
  22305. componentStack: componentStack,
  22306. digest: digest
  22307. });
  22308. }
  22309. }
  22310. if (hasUncaughtError) {
  22311. hasUncaughtError = false;
  22312. var error$1 = firstUncaughtError;
  22313. firstUncaughtError = null;
  22314. throw error$1;
  22315. } // If the passive effects are the result of a discrete render, flush them
  22316. // synchronously at the end of the current task so that the result is
  22317. // immediately observable. Otherwise, we assume that they are not
  22318. // order-dependent and do not need to be observed by external systems, so we
  22319. // can wait until after paint.
  22320. // TODO: We can optimize this by not scheduling the callback earlier. Since we
  22321. // currently schedule the callback in multiple places, will wait until those
  22322. // are consolidated.
  22323. if (includesSomeLane(pendingPassiveEffectsLanes, SyncLane) && root.tag !== LegacyRoot) {
  22324. flushPassiveEffects();
  22325. } // Read this again, since a passive effect might have updated it
  22326. remainingLanes = root.pendingLanes;
  22327. if (includesSomeLane(remainingLanes, SyncLane)) {
  22328. {
  22329. markNestedUpdateScheduled();
  22330. } // Count the number of times the root synchronously re-renders without
  22331. // finishing. If there are too many, it indicates an infinite update loop.
  22332. if (root === rootWithNestedUpdates) {
  22333. nestedUpdateCount++;
  22334. } else {
  22335. nestedUpdateCount = 0;
  22336. rootWithNestedUpdates = root;
  22337. }
  22338. } else {
  22339. nestedUpdateCount = 0;
  22340. } // If layout work was scheduled, flush it now.
  22341. flushSyncCallbacks();
  22342. {
  22343. markCommitStopped();
  22344. }
  22345. return null;
  22346. }
  22347. function flushPassiveEffects() {
  22348. // Returns whether passive effects were flushed.
  22349. // TODO: Combine this check with the one in flushPassiveEFfectsImpl. We should
  22350. // probably just combine the two functions. I believe they were only separate
  22351. // in the first place because we used to wrap it with
  22352. // `Scheduler.runWithPriority`, which accepts a function. But now we track the
  22353. // priority within React itself, so we can mutate the variable directly.
  22354. if (rootWithPendingPassiveEffects !== null) {
  22355. var renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
  22356. var priority = lowerEventPriority(DefaultEventPriority, renderPriority);
  22357. var prevTransition = ReactCurrentBatchConfig$3.transition;
  22358. var previousPriority = getCurrentUpdatePriority();
  22359. try {
  22360. ReactCurrentBatchConfig$3.transition = null;
  22361. setCurrentUpdatePriority(priority);
  22362. return flushPassiveEffectsImpl();
  22363. } finally {
  22364. setCurrentUpdatePriority(previousPriority);
  22365. ReactCurrentBatchConfig$3.transition = prevTransition; // Once passive effects have run for the tree - giving components a
  22366. }
  22367. }
  22368. return false;
  22369. }
  22370. function enqueuePendingPassiveProfilerEffect(fiber) {
  22371. {
  22372. pendingPassiveProfilerEffects.push(fiber);
  22373. if (!rootDoesHavePassiveEffects) {
  22374. rootDoesHavePassiveEffects = true;
  22375. scheduleCallback$1(NormalPriority, function () {
  22376. flushPassiveEffects();
  22377. return null;
  22378. });
  22379. }
  22380. }
  22381. }
  22382. function flushPassiveEffectsImpl() {
  22383. if (rootWithPendingPassiveEffects === null) {
  22384. return false;
  22385. } // Cache and clear the transitions flag
  22386. var transitions = pendingPassiveTransitions;
  22387. pendingPassiveTransitions = null;
  22388. var root = rootWithPendingPassiveEffects;
  22389. var lanes = pendingPassiveEffectsLanes;
  22390. rootWithPendingPassiveEffects = null; // TODO: This is sometimes out of sync with rootWithPendingPassiveEffects.
  22391. // Figure out why and fix it. It's not causing any known issues (probably
  22392. // because it's only used for profiling), but it's a refactor hazard.
  22393. pendingPassiveEffectsLanes = NoLanes;
  22394. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  22395. throw new Error('Cannot flush passive effects while already rendering.');
  22396. }
  22397. {
  22398. isFlushingPassiveEffects = true;
  22399. didScheduleUpdateDuringPassiveEffects = false;
  22400. }
  22401. {
  22402. markPassiveEffectsStarted(lanes);
  22403. }
  22404. var prevExecutionContext = executionContext;
  22405. executionContext |= CommitContext;
  22406. commitPassiveUnmountEffects(root.current);
  22407. commitPassiveMountEffects(root, root.current, lanes, transitions); // TODO: Move to commitPassiveMountEffects
  22408. {
  22409. var profilerEffects = pendingPassiveProfilerEffects;
  22410. pendingPassiveProfilerEffects = [];
  22411. for (var i = 0; i < profilerEffects.length; i++) {
  22412. var _fiber = profilerEffects[i];
  22413. commitPassiveEffectDurations(root, _fiber);
  22414. }
  22415. }
  22416. {
  22417. markPassiveEffectsStopped();
  22418. }
  22419. {
  22420. commitDoubleInvokeEffectsInDEV(root.current, true);
  22421. }
  22422. executionContext = prevExecutionContext;
  22423. flushSyncCallbacks();
  22424. {
  22425. // If additional passive effects were scheduled, increment a counter. If this
  22426. // exceeds the limit, we'll fire a warning.
  22427. if (didScheduleUpdateDuringPassiveEffects) {
  22428. if (root === rootWithPassiveNestedUpdates) {
  22429. nestedPassiveUpdateCount++;
  22430. } else {
  22431. nestedPassiveUpdateCount = 0;
  22432. rootWithPassiveNestedUpdates = root;
  22433. }
  22434. } else {
  22435. nestedPassiveUpdateCount = 0;
  22436. }
  22437. isFlushingPassiveEffects = false;
  22438. didScheduleUpdateDuringPassiveEffects = false;
  22439. } // TODO: Move to commitPassiveMountEffects
  22440. onPostCommitRoot(root);
  22441. {
  22442. var stateNode = root.current.stateNode;
  22443. stateNode.effectDuration = 0;
  22444. stateNode.passiveEffectDuration = 0;
  22445. }
  22446. return true;
  22447. }
  22448. function isAlreadyFailedLegacyErrorBoundary(instance) {
  22449. return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
  22450. }
  22451. function markLegacyErrorBoundaryAsFailed(instance) {
  22452. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  22453. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  22454. } else {
  22455. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  22456. }
  22457. }
  22458. function prepareToThrowUncaughtError(error) {
  22459. if (!hasUncaughtError) {
  22460. hasUncaughtError = true;
  22461. firstUncaughtError = error;
  22462. }
  22463. }
  22464. var onUncaughtError = prepareToThrowUncaughtError;
  22465. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  22466. var errorInfo = createCapturedValueAtFiber(error, sourceFiber);
  22467. var update = createRootErrorUpdate(rootFiber, errorInfo, SyncLane);
  22468. var root = enqueueUpdate(rootFiber, update, SyncLane);
  22469. var eventTime = requestEventTime();
  22470. if (root !== null) {
  22471. markRootUpdated(root, SyncLane, eventTime);
  22472. ensureRootIsScheduled(root, eventTime);
  22473. }
  22474. }
  22475. function captureCommitPhaseError(sourceFiber, nearestMountedAncestor, error$1) {
  22476. {
  22477. reportUncaughtErrorInDEV(error$1);
  22478. setIsRunningInsertionEffect(false);
  22479. }
  22480. if (sourceFiber.tag === HostRoot) {
  22481. // Error was thrown at the root. There is no parent, so the root
  22482. // itself should capture it.
  22483. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error$1);
  22484. return;
  22485. }
  22486. var fiber = null;
  22487. {
  22488. fiber = nearestMountedAncestor;
  22489. }
  22490. while (fiber !== null) {
  22491. if (fiber.tag === HostRoot) {
  22492. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error$1);
  22493. return;
  22494. } else if (fiber.tag === ClassComponent) {
  22495. var ctor = fiber.type;
  22496. var instance = fiber.stateNode;
  22497. if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
  22498. var errorInfo = createCapturedValueAtFiber(error$1, sourceFiber);
  22499. var update = createClassErrorUpdate(fiber, errorInfo, SyncLane);
  22500. var root = enqueueUpdate(fiber, update, SyncLane);
  22501. var eventTime = requestEventTime();
  22502. if (root !== null) {
  22503. markRootUpdated(root, SyncLane, eventTime);
  22504. ensureRootIsScheduled(root, eventTime);
  22505. }
  22506. return;
  22507. }
  22508. }
  22509. fiber = fiber.return;
  22510. }
  22511. {
  22512. // TODO: Until we re-land skipUnmountedBoundaries (see #20147), this warning
  22513. // will fire for errors that are thrown by destroy functions inside deleted
  22514. // trees. What it should instead do is propagate the error to the parent of
  22515. // the deleted tree. In the meantime, do not add this warning to the
  22516. // allowlist; this is only for our internal use.
  22517. error('Internal React error: Attempted to capture a commit phase error ' + 'inside a detached tree. This indicates a bug in React. Likely ' + 'causes include deleting the same fiber more than once, committing an ' + 'already-finished tree, or an inconsistent return pointer.\n\n' + 'Error message:\n\n%s', error$1);
  22518. }
  22519. }
  22520. function pingSuspendedRoot(root, wakeable, pingedLanes) {
  22521. var pingCache = root.pingCache;
  22522. if (pingCache !== null) {
  22523. // The wakeable resolved, so we no longer need to memoize, because it will
  22524. // never be thrown again.
  22525. pingCache.delete(wakeable);
  22526. }
  22527. var eventTime = requestEventTime();
  22528. markRootPinged(root, pingedLanes);
  22529. warnIfSuspenseResolutionNotWrappedWithActDEV(root);
  22530. if (workInProgressRoot === root && isSubsetOfLanes(workInProgressRootRenderLanes, pingedLanes)) {
  22531. // Received a ping at the same priority level at which we're currently
  22532. // rendering. We might want to restart this render. This should mirror
  22533. // the logic of whether or not a root suspends once it completes.
  22534. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  22535. // we should probably never restart.
  22536. // If we're suspended with delay, or if it's a retry, we'll always suspend
  22537. // so we can always restart.
  22538. if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && includesOnlyRetries(workInProgressRootRenderLanes) && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
  22539. // Restart from the root.
  22540. prepareFreshStack(root, NoLanes);
  22541. } else {
  22542. // Even though we can't restart right now, we might get an
  22543. // opportunity later. So we mark this render as having a ping.
  22544. workInProgressRootPingedLanes = mergeLanes(workInProgressRootPingedLanes, pingedLanes);
  22545. }
  22546. }
  22547. ensureRootIsScheduled(root, eventTime);
  22548. }
  22549. function retryTimedOutBoundary(boundaryFiber, retryLane) {
  22550. // The boundary fiber (a Suspense component or SuspenseList component)
  22551. // previously was rendered in its fallback state. One of the promises that
  22552. // suspended it has resolved, which means at least part of the tree was
  22553. // likely unblocked. Try rendering again, at a new lanes.
  22554. if (retryLane === NoLane) {
  22555. // TODO: Assign this to `suspenseState.retryLane`? to avoid
  22556. // unnecessary entanglement?
  22557. retryLane = requestRetryLane(boundaryFiber);
  22558. } // TODO: Special case idle priority?
  22559. var eventTime = requestEventTime();
  22560. var root = enqueueConcurrentRenderForLane(boundaryFiber, retryLane);
  22561. if (root !== null) {
  22562. markRootUpdated(root, retryLane, eventTime);
  22563. ensureRootIsScheduled(root, eventTime);
  22564. }
  22565. }
  22566. function retryDehydratedSuspenseBoundary(boundaryFiber) {
  22567. var suspenseState = boundaryFiber.memoizedState;
  22568. var retryLane = NoLane;
  22569. if (suspenseState !== null) {
  22570. retryLane = suspenseState.retryLane;
  22571. }
  22572. retryTimedOutBoundary(boundaryFiber, retryLane);
  22573. }
  22574. function resolveRetryWakeable(boundaryFiber, wakeable) {
  22575. var retryLane = NoLane; // Default
  22576. var retryCache;
  22577. switch (boundaryFiber.tag) {
  22578. case SuspenseComponent:
  22579. retryCache = boundaryFiber.stateNode;
  22580. var suspenseState = boundaryFiber.memoizedState;
  22581. if (suspenseState !== null) {
  22582. retryLane = suspenseState.retryLane;
  22583. }
  22584. break;
  22585. case SuspenseListComponent:
  22586. retryCache = boundaryFiber.stateNode;
  22587. break;
  22588. default:
  22589. throw new Error('Pinged unknown suspense boundary type. ' + 'This is probably a bug in React.');
  22590. }
  22591. if (retryCache !== null) {
  22592. // The wakeable resolved, so we no longer need to memoize, because it will
  22593. // never be thrown again.
  22594. retryCache.delete(wakeable);
  22595. }
  22596. retryTimedOutBoundary(boundaryFiber, retryLane);
  22597. } // Computes the next Just Noticeable Difference (JND) boundary.
  22598. // The theory is that a person can't tell the difference between small differences in time.
  22599. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  22600. // difference in the experience. However, waiting for longer might mean that we can avoid
  22601. // showing an intermediate loading state. The longer we have already waited, the harder it
  22602. // is to tell small differences in time. Therefore, the longer we've already waited,
  22603. // the longer we can wait additionally. At some point we have to give up though.
  22604. // We pick a train model where the next boundary commits at a consistent schedule.
  22605. // These particular numbers are vague estimates. We expect to adjust them based on research.
  22606. function jnd(timeElapsed) {
  22607. return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
  22608. }
  22609. function checkForNestedUpdates() {
  22610. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  22611. nestedUpdateCount = 0;
  22612. rootWithNestedUpdates = null;
  22613. throw new 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.');
  22614. }
  22615. {
  22616. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  22617. nestedPassiveUpdateCount = 0;
  22618. rootWithPassiveNestedUpdates = null;
  22619. 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.');
  22620. }
  22621. }
  22622. }
  22623. function flushRenderPhaseStrictModeWarningsInDEV() {
  22624. {
  22625. ReactStrictModeWarnings.flushLegacyContextWarning();
  22626. {
  22627. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  22628. }
  22629. }
  22630. }
  22631. function commitDoubleInvokeEffectsInDEV(fiber, hasPassiveEffects) {
  22632. {
  22633. // TODO (StrictEffects) Should we set a marker on the root if it contains strict effects
  22634. // so we don't traverse unnecessarily? similar to subtreeFlags but just at the root level.
  22635. // Maybe not a big deal since this is DEV only behavior.
  22636. setCurrentFiber(fiber);
  22637. invokeEffectsInDev(fiber, MountLayoutDev, invokeLayoutEffectUnmountInDEV);
  22638. if (hasPassiveEffects) {
  22639. invokeEffectsInDev(fiber, MountPassiveDev, invokePassiveEffectUnmountInDEV);
  22640. }
  22641. invokeEffectsInDev(fiber, MountLayoutDev, invokeLayoutEffectMountInDEV);
  22642. if (hasPassiveEffects) {
  22643. invokeEffectsInDev(fiber, MountPassiveDev, invokePassiveEffectMountInDEV);
  22644. }
  22645. resetCurrentFiber();
  22646. }
  22647. }
  22648. function invokeEffectsInDev(firstChild, fiberFlags, invokeEffectFn) {
  22649. {
  22650. // We don't need to re-check StrictEffectsMode here.
  22651. // This function is only called if that check has already passed.
  22652. var current = firstChild;
  22653. var subtreeRoot = null;
  22654. while (current !== null) {
  22655. var primarySubtreeFlag = current.subtreeFlags & fiberFlags;
  22656. if (current !== subtreeRoot && current.child !== null && primarySubtreeFlag !== NoFlags) {
  22657. current = current.child;
  22658. } else {
  22659. if ((current.flags & fiberFlags) !== NoFlags) {
  22660. invokeEffectFn(current);
  22661. }
  22662. if (current.sibling !== null) {
  22663. current = current.sibling;
  22664. } else {
  22665. current = subtreeRoot = current.return;
  22666. }
  22667. }
  22668. }
  22669. }
  22670. }
  22671. var didWarnStateUpdateForNotYetMountedComponent = null;
  22672. function warnAboutUpdateOnNotYetMountedFiberInDEV(fiber) {
  22673. {
  22674. if ((executionContext & RenderContext) !== NoContext) {
  22675. // We let the other warning about render phase updates deal with this one.
  22676. return;
  22677. }
  22678. if (!(fiber.mode & ConcurrentMode)) {
  22679. return;
  22680. }
  22681. var tag = fiber.tag;
  22682. if (tag !== IndeterminateComponent && tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent) {
  22683. // Only warn for user-defined components, not internal ones like Suspense.
  22684. return;
  22685. } // We show the whole stack but dedupe on the top component's name because
  22686. // the problematic code almost always lies inside that component.
  22687. var componentName = getComponentNameFromFiber(fiber) || 'ReactComponent';
  22688. if (didWarnStateUpdateForNotYetMountedComponent !== null) {
  22689. if (didWarnStateUpdateForNotYetMountedComponent.has(componentName)) {
  22690. return;
  22691. }
  22692. didWarnStateUpdateForNotYetMountedComponent.add(componentName);
  22693. } else {
  22694. didWarnStateUpdateForNotYetMountedComponent = new Set([componentName]);
  22695. }
  22696. var previousFiber = current;
  22697. try {
  22698. setCurrentFiber(fiber);
  22699. error("Can't perform a React state update on a component that hasn't mounted yet. " + 'This indicates that you have a side-effect in your render function that ' + 'asynchronously later calls tries to update the component. Move this work to ' + 'useEffect instead.');
  22700. } finally {
  22701. if (previousFiber) {
  22702. setCurrentFiber(fiber);
  22703. } else {
  22704. resetCurrentFiber();
  22705. }
  22706. }
  22707. }
  22708. }
  22709. var beginWork$1;
  22710. {
  22711. var dummyFiber = null;
  22712. beginWork$1 = function (current, unitOfWork, lanes) {
  22713. // If a component throws an error, we replay it again in a synchronously
  22714. // dispatched event, so that the debugger will treat it as an uncaught
  22715. // error See ReactErrorUtils for more information.
  22716. // Before entering the begin phase, copy the work-in-progress onto a dummy
  22717. // fiber. If beginWork throws, we'll use this to reset the state.
  22718. var originalWorkInProgressCopy = assignFiberPropertiesInDEV(dummyFiber, unitOfWork);
  22719. try {
  22720. return beginWork(current, unitOfWork, lanes);
  22721. } catch (originalError) {
  22722. if (didSuspendOrErrorWhileHydratingDEV() || originalError !== null && typeof originalError === 'object' && typeof originalError.then === 'function') {
  22723. // Don't replay promises.
  22724. // Don't replay errors if we are hydrating and have already suspended or handled an error
  22725. throw originalError;
  22726. } // Keep this code in sync with handleError; any changes here must have
  22727. // corresponding changes there.
  22728. resetContextDependencies();
  22729. resetHooksAfterThrow(); // Don't reset current debug fiber, since we're about to work on the
  22730. // same fiber again.
  22731. // Unwind the failed stack frame
  22732. unwindInterruptedWork(current, unitOfWork); // Restore the original properties of the fiber.
  22733. assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
  22734. if ( unitOfWork.mode & ProfileMode) {
  22735. // Reset the profiler timer.
  22736. startProfilerTimer(unitOfWork);
  22737. } // Run beginWork again.
  22738. invokeGuardedCallback(null, beginWork, null, current, unitOfWork, lanes);
  22739. if (hasCaughtError()) {
  22740. var replayError = clearCaughtError();
  22741. if (typeof replayError === 'object' && replayError !== null && replayError._suppressLogging && typeof originalError === 'object' && originalError !== null && !originalError._suppressLogging) {
  22742. // If suppressed, let the flag carry over to the original error which is the one we'll rethrow.
  22743. originalError._suppressLogging = true;
  22744. }
  22745. } // We always throw the original error in case the second render pass is not idempotent.
  22746. // This can happen if a memoized function or CommonJS module doesn't throw after first invocation.
  22747. throw originalError;
  22748. }
  22749. };
  22750. }
  22751. var didWarnAboutUpdateInRender = false;
  22752. var didWarnAboutUpdateInRenderForAnotherComponent;
  22753. {
  22754. didWarnAboutUpdateInRenderForAnotherComponent = new Set();
  22755. }
  22756. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  22757. {
  22758. if (isRendering && !getIsUpdatingOpaqueValueInRenderPhaseInDEV()) {
  22759. switch (fiber.tag) {
  22760. case FunctionComponent:
  22761. case ForwardRef:
  22762. case SimpleMemoComponent:
  22763. {
  22764. var renderingComponentName = workInProgress && getComponentNameFromFiber(workInProgress) || 'Unknown'; // Dedupe by the rendering component because it's the one that needs to be fixed.
  22765. var dedupeKey = renderingComponentName;
  22766. if (!didWarnAboutUpdateInRenderForAnotherComponent.has(dedupeKey)) {
  22767. didWarnAboutUpdateInRenderForAnotherComponent.add(dedupeKey);
  22768. var setStateComponentName = getComponentNameFromFiber(fiber) || 'Unknown';
  22769. 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://reactjs.org/link/setstate-in-render', setStateComponentName, renderingComponentName, renderingComponentName);
  22770. }
  22771. break;
  22772. }
  22773. case ClassComponent:
  22774. {
  22775. if (!didWarnAboutUpdateInRender) {
  22776. error('Cannot update during an existing state transition (such as ' + 'within `render`). Render methods should be a pure ' + 'function of props and state.');
  22777. didWarnAboutUpdateInRender = true;
  22778. }
  22779. break;
  22780. }
  22781. }
  22782. }
  22783. }
  22784. }
  22785. function restorePendingUpdaters(root, lanes) {
  22786. {
  22787. if (isDevToolsPresent) {
  22788. var memoizedUpdaters = root.memoizedUpdaters;
  22789. memoizedUpdaters.forEach(function (schedulingFiber) {
  22790. addFiberToLanesMap(root, schedulingFiber, lanes);
  22791. }); // This function intentionally does not clear memoized updaters.
  22792. // Those may still be relevant to the current commit
  22793. // and a future one (e.g. Suspense).
  22794. }
  22795. }
  22796. }
  22797. var fakeActCallbackNode = {};
  22798. function scheduleCallback$1(priorityLevel, callback) {
  22799. {
  22800. // If we're currently inside an `act` scope, bypass Scheduler and push to
  22801. // the `act` queue instead.
  22802. var actQueue = ReactCurrentActQueue$1.current;
  22803. if (actQueue !== null) {
  22804. actQueue.push(callback);
  22805. return fakeActCallbackNode;
  22806. } else {
  22807. return scheduleCallback(priorityLevel, callback);
  22808. }
  22809. }
  22810. }
  22811. function cancelCallback$1(callbackNode) {
  22812. if ( callbackNode === fakeActCallbackNode) {
  22813. return;
  22814. } // In production, always call Scheduler. This function will be stripped out.
  22815. return cancelCallback(callbackNode);
  22816. }
  22817. function shouldForceFlushFallbacksInDEV() {
  22818. // Never force flush in production. This function should get stripped out.
  22819. return ReactCurrentActQueue$1.current !== null;
  22820. }
  22821. function warnIfUpdatesNotWrappedWithActDEV(fiber) {
  22822. {
  22823. if (fiber.mode & ConcurrentMode) {
  22824. if (!isConcurrentActEnvironment()) {
  22825. // Not in an act environment. No need to warn.
  22826. return;
  22827. }
  22828. } else {
  22829. // Legacy mode has additional cases where we suppress a warning.
  22830. if (!isLegacyActEnvironment()) {
  22831. // Not in an act environment. No need to warn.
  22832. return;
  22833. }
  22834. if (executionContext !== NoContext) {
  22835. // Legacy mode doesn't warn if the update is batched, i.e.
  22836. // batchedUpdates or flushSync.
  22837. return;
  22838. }
  22839. if (fiber.tag !== FunctionComponent && fiber.tag !== ForwardRef && fiber.tag !== SimpleMemoComponent) {
  22840. // For backwards compatibility with pre-hooks code, legacy mode only
  22841. // warns for updates that originate from a hook.
  22842. return;
  22843. }
  22844. }
  22845. if (ReactCurrentActQueue$1.current === null) {
  22846. var previousFiber = current;
  22847. try {
  22848. setCurrentFiber(fiber);
  22849. 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://reactjs.org/link/wrap-tests-with-act', getComponentNameFromFiber(fiber));
  22850. } finally {
  22851. if (previousFiber) {
  22852. setCurrentFiber(fiber);
  22853. } else {
  22854. resetCurrentFiber();
  22855. }
  22856. }
  22857. }
  22858. }
  22859. }
  22860. function warnIfSuspenseResolutionNotWrappedWithActDEV(root) {
  22861. {
  22862. if (root.tag !== LegacyRoot && isConcurrentActEnvironment() && ReactCurrentActQueue$1.current === null) {
  22863. error('A suspended resource finished loading inside a test, but the event ' + 'was not wrapped in act(...).\n\n' + 'When testing, code that resolves suspended data should be wrapped ' + 'into act(...):\n\n' + 'act(() => {\n' + ' /* finish loading suspended data */\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://reactjs.org/link/wrap-tests-with-act');
  22864. }
  22865. }
  22866. }
  22867. function setIsRunningInsertionEffect(isRunning) {
  22868. {
  22869. isRunningInsertionEffect = isRunning;
  22870. }
  22871. }
  22872. /* eslint-disable react-internal/prod-error-codes */
  22873. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  22874. var failedBoundaries = null;
  22875. var setRefreshHandler = function (handler) {
  22876. {
  22877. resolveFamily = handler;
  22878. }
  22879. };
  22880. function resolveFunctionForHotReloading(type) {
  22881. {
  22882. if (resolveFamily === null) {
  22883. // Hot reloading is disabled.
  22884. return type;
  22885. }
  22886. var family = resolveFamily(type);
  22887. if (family === undefined) {
  22888. return type;
  22889. } // Use the latest known implementation.
  22890. return family.current;
  22891. }
  22892. }
  22893. function resolveClassForHotReloading(type) {
  22894. // No implementation differences.
  22895. return resolveFunctionForHotReloading(type);
  22896. }
  22897. function resolveForwardRefForHotReloading(type) {
  22898. {
  22899. if (resolveFamily === null) {
  22900. // Hot reloading is disabled.
  22901. return type;
  22902. }
  22903. var family = resolveFamily(type);
  22904. if (family === undefined) {
  22905. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  22906. if (type !== null && type !== undefined && typeof type.render === 'function') {
  22907. // ForwardRef is special because its resolved .type is an object,
  22908. // but it's possible that we only have its inner render function in the map.
  22909. // If that inner render function is different, we'll build a new forwardRef type.
  22910. var currentRender = resolveFunctionForHotReloading(type.render);
  22911. if (type.render !== currentRender) {
  22912. var syntheticType = {
  22913. $$typeof: REACT_FORWARD_REF_TYPE,
  22914. render: currentRender
  22915. };
  22916. if (type.displayName !== undefined) {
  22917. syntheticType.displayName = type.displayName;
  22918. }
  22919. return syntheticType;
  22920. }
  22921. }
  22922. return type;
  22923. } // Use the latest known implementation.
  22924. return family.current;
  22925. }
  22926. }
  22927. function isCompatibleFamilyForHotReloading(fiber, element) {
  22928. {
  22929. if (resolveFamily === null) {
  22930. // Hot reloading is disabled.
  22931. return false;
  22932. }
  22933. var prevType = fiber.elementType;
  22934. var nextType = element.type; // If we got here, we know types aren't === equal.
  22935. var needsCompareFamilies = false;
  22936. var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
  22937. switch (fiber.tag) {
  22938. case ClassComponent:
  22939. {
  22940. if (typeof nextType === 'function') {
  22941. needsCompareFamilies = true;
  22942. }
  22943. break;
  22944. }
  22945. case FunctionComponent:
  22946. {
  22947. if (typeof nextType === 'function') {
  22948. needsCompareFamilies = true;
  22949. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  22950. // We don't know the inner type yet.
  22951. // We're going to assume that the lazy inner type is stable,
  22952. // and so it is sufficient to avoid reconciling it away.
  22953. // We're not going to unwrap or actually use the new lazy type.
  22954. needsCompareFamilies = true;
  22955. }
  22956. break;
  22957. }
  22958. case ForwardRef:
  22959. {
  22960. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  22961. needsCompareFamilies = true;
  22962. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  22963. needsCompareFamilies = true;
  22964. }
  22965. break;
  22966. }
  22967. case MemoComponent:
  22968. case SimpleMemoComponent:
  22969. {
  22970. if ($$typeofNextType === REACT_MEMO_TYPE) {
  22971. // TODO: if it was but can no longer be simple,
  22972. // we shouldn't set this.
  22973. needsCompareFamilies = true;
  22974. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  22975. needsCompareFamilies = true;
  22976. }
  22977. break;
  22978. }
  22979. default:
  22980. return false;
  22981. } // Check if both types have a family and it's the same one.
  22982. if (needsCompareFamilies) {
  22983. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  22984. // This means both of them need to be registered to preserve state.
  22985. // If we unwrapped and compared the inner types for wrappers instead,
  22986. // then we would risk falsely saying two separate memo(Foo)
  22987. // calls are equivalent because they wrap the same Foo function.
  22988. var prevFamily = resolveFamily(prevType);
  22989. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  22990. return true;
  22991. }
  22992. }
  22993. return false;
  22994. }
  22995. }
  22996. function markFailedErrorBoundaryForHotReloading(fiber) {
  22997. {
  22998. if (resolveFamily === null) {
  22999. // Hot reloading is disabled.
  23000. return;
  23001. }
  23002. if (typeof WeakSet !== 'function') {
  23003. return;
  23004. }
  23005. if (failedBoundaries === null) {
  23006. failedBoundaries = new WeakSet();
  23007. }
  23008. failedBoundaries.add(fiber);
  23009. }
  23010. }
  23011. var scheduleRefresh = function (root, update) {
  23012. {
  23013. if (resolveFamily === null) {
  23014. // Hot reloading is disabled.
  23015. return;
  23016. }
  23017. var staleFamilies = update.staleFamilies,
  23018. updatedFamilies = update.updatedFamilies;
  23019. flushPassiveEffects();
  23020. flushSync(function () {
  23021. scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
  23022. });
  23023. }
  23024. };
  23025. var scheduleRoot = function (root, element) {
  23026. {
  23027. if (root.context !== emptyContextObject) {
  23028. // Super edge case: root has a legacy _renderSubtree context
  23029. // but we don't know the parentComponent so we can't pass it.
  23030. // Just ignore. We'll delete this with _renderSubtree code path later.
  23031. return;
  23032. }
  23033. flushPassiveEffects();
  23034. flushSync(function () {
  23035. updateContainer(element, root, null, null);
  23036. });
  23037. }
  23038. };
  23039. function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
  23040. {
  23041. var alternate = fiber.alternate,
  23042. child = fiber.child,
  23043. sibling = fiber.sibling,
  23044. tag = fiber.tag,
  23045. type = fiber.type;
  23046. var candidateType = null;
  23047. switch (tag) {
  23048. case FunctionComponent:
  23049. case SimpleMemoComponent:
  23050. case ClassComponent:
  23051. candidateType = type;
  23052. break;
  23053. case ForwardRef:
  23054. candidateType = type.render;
  23055. break;
  23056. }
  23057. if (resolveFamily === null) {
  23058. throw new Error('Expected resolveFamily to be set during hot reload.');
  23059. }
  23060. var needsRender = false;
  23061. var needsRemount = false;
  23062. if (candidateType !== null) {
  23063. var family = resolveFamily(candidateType);
  23064. if (family !== undefined) {
  23065. if (staleFamilies.has(family)) {
  23066. needsRemount = true;
  23067. } else if (updatedFamilies.has(family)) {
  23068. if (tag === ClassComponent) {
  23069. needsRemount = true;
  23070. } else {
  23071. needsRender = true;
  23072. }
  23073. }
  23074. }
  23075. }
  23076. if (failedBoundaries !== null) {
  23077. if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
  23078. needsRemount = true;
  23079. }
  23080. }
  23081. if (needsRemount) {
  23082. fiber._debugNeedsRemount = true;
  23083. }
  23084. if (needsRemount || needsRender) {
  23085. var _root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  23086. if (_root !== null) {
  23087. scheduleUpdateOnFiber(_root, fiber, SyncLane, NoTimestamp);
  23088. }
  23089. }
  23090. if (child !== null && !needsRemount) {
  23091. scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
  23092. }
  23093. if (sibling !== null) {
  23094. scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
  23095. }
  23096. }
  23097. }
  23098. var findHostInstancesForRefresh = function (root, families) {
  23099. {
  23100. var hostInstances = new Set();
  23101. var types = new Set(families.map(function (family) {
  23102. return family.current;
  23103. }));
  23104. findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
  23105. return hostInstances;
  23106. }
  23107. };
  23108. function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
  23109. {
  23110. var child = fiber.child,
  23111. sibling = fiber.sibling,
  23112. tag = fiber.tag,
  23113. type = fiber.type;
  23114. var candidateType = null;
  23115. switch (tag) {
  23116. case FunctionComponent:
  23117. case SimpleMemoComponent:
  23118. case ClassComponent:
  23119. candidateType = type;
  23120. break;
  23121. case ForwardRef:
  23122. candidateType = type.render;
  23123. break;
  23124. }
  23125. var didMatch = false;
  23126. if (candidateType !== null) {
  23127. if (types.has(candidateType)) {
  23128. didMatch = true;
  23129. }
  23130. }
  23131. if (didMatch) {
  23132. // We have a match. This only drills down to the closest host components.
  23133. // There's no need to search deeper because for the purpose of giving
  23134. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  23135. findHostInstancesForFiberShallowly(fiber, hostInstances);
  23136. } else {
  23137. // If there's no match, maybe there will be one further down in the child tree.
  23138. if (child !== null) {
  23139. findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
  23140. }
  23141. }
  23142. if (sibling !== null) {
  23143. findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
  23144. }
  23145. }
  23146. }
  23147. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  23148. {
  23149. var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
  23150. if (foundHostInstances) {
  23151. return;
  23152. } // If we didn't find any host children, fallback to closest host parent.
  23153. var node = fiber;
  23154. while (true) {
  23155. switch (node.tag) {
  23156. case HostComponent:
  23157. hostInstances.add(node.stateNode);
  23158. return;
  23159. case HostPortal:
  23160. hostInstances.add(node.stateNode.containerInfo);
  23161. return;
  23162. case HostRoot:
  23163. hostInstances.add(node.stateNode.containerInfo);
  23164. return;
  23165. }
  23166. if (node.return === null) {
  23167. throw new Error('Expected to reach root first.');
  23168. }
  23169. node = node.return;
  23170. }
  23171. }
  23172. }
  23173. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  23174. {
  23175. var node = fiber;
  23176. var foundHostInstances = false;
  23177. while (true) {
  23178. if (node.tag === HostComponent) {
  23179. // We got a match.
  23180. foundHostInstances = true;
  23181. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  23182. } else if (node.child !== null) {
  23183. node.child.return = node;
  23184. node = node.child;
  23185. continue;
  23186. }
  23187. if (node === fiber) {
  23188. return foundHostInstances;
  23189. }
  23190. while (node.sibling === null) {
  23191. if (node.return === null || node.return === fiber) {
  23192. return foundHostInstances;
  23193. }
  23194. node = node.return;
  23195. }
  23196. node.sibling.return = node.return;
  23197. node = node.sibling;
  23198. }
  23199. }
  23200. return false;
  23201. }
  23202. var hasBadMapPolyfill;
  23203. {
  23204. hasBadMapPolyfill = false;
  23205. try {
  23206. var nonExtensibleObject = Object.preventExtensions({});
  23207. /* eslint-disable no-new */
  23208. new Map([[nonExtensibleObject, null]]);
  23209. new Set([nonExtensibleObject]);
  23210. /* eslint-enable no-new */
  23211. } catch (e) {
  23212. // TODO: Consider warning about bad polyfills
  23213. hasBadMapPolyfill = true;
  23214. }
  23215. }
  23216. function FiberNode(tag, pendingProps, key, mode) {
  23217. // Instance
  23218. this.tag = tag;
  23219. this.key = key;
  23220. this.elementType = null;
  23221. this.type = null;
  23222. this.stateNode = null; // Fiber
  23223. this.return = null;
  23224. this.child = null;
  23225. this.sibling = null;
  23226. this.index = 0;
  23227. this.ref = null;
  23228. this.pendingProps = pendingProps;
  23229. this.memoizedProps = null;
  23230. this.updateQueue = null;
  23231. this.memoizedState = null;
  23232. this.dependencies = null;
  23233. this.mode = mode; // Effects
  23234. this.flags = NoFlags;
  23235. this.subtreeFlags = NoFlags;
  23236. this.deletions = null;
  23237. this.lanes = NoLanes;
  23238. this.childLanes = NoLanes;
  23239. this.alternate = null;
  23240. {
  23241. // Note: The following is done to avoid a v8 performance cliff.
  23242. //
  23243. // Initializing the fields below to smis and later updating them with
  23244. // double values will cause Fibers to end up having separate shapes.
  23245. // This behavior/bug has something to do with Object.preventExtension().
  23246. // Fortunately this only impacts DEV builds.
  23247. // Unfortunately it makes React unusably slow for some applications.
  23248. // To work around this, initialize the fields below with doubles.
  23249. //
  23250. // Learn more about this here:
  23251. // https://github.com/facebook/react/issues/14365
  23252. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  23253. this.actualDuration = Number.NaN;
  23254. this.actualStartTime = Number.NaN;
  23255. this.selfBaseDuration = Number.NaN;
  23256. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  23257. // This won't trigger the performance cliff mentioned above,
  23258. // and it simplifies other profiler code (including DevTools).
  23259. this.actualDuration = 0;
  23260. this.actualStartTime = -1;
  23261. this.selfBaseDuration = 0;
  23262. this.treeBaseDuration = 0;
  23263. }
  23264. {
  23265. // This isn't directly used but is handy for debugging internals:
  23266. this._debugSource = null;
  23267. this._debugOwner = null;
  23268. this._debugNeedsRemount = false;
  23269. this._debugHookTypes = null;
  23270. if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
  23271. Object.preventExtensions(this);
  23272. }
  23273. }
  23274. } // This is a constructor function, rather than a POJO constructor, still
  23275. // please ensure we do the following:
  23276. // 1) Nobody should add any instance methods on this. Instance methods can be
  23277. // more difficult to predict when they get optimized and they are almost
  23278. // never inlined properly in static compilers.
  23279. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  23280. // always know when it is a fiber.
  23281. // 3) We might want to experiment with using numeric keys since they are easier
  23282. // to optimize in a non-JIT environment.
  23283. // 4) We can easily go from a constructor to a createFiber object literal if that
  23284. // is faster.
  23285. // 5) It should be easy to port this to a C struct and keep a C implementation
  23286. // compatible.
  23287. var createFiber = function (tag, pendingProps, key, mode) {
  23288. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  23289. return new FiberNode(tag, pendingProps, key, mode);
  23290. };
  23291. function shouldConstruct$1(Component) {
  23292. var prototype = Component.prototype;
  23293. return !!(prototype && prototype.isReactComponent);
  23294. }
  23295. function isSimpleFunctionComponent(type) {
  23296. return typeof type === 'function' && !shouldConstruct$1(type) && type.defaultProps === undefined;
  23297. }
  23298. function resolveLazyComponentTag(Component) {
  23299. if (typeof Component === 'function') {
  23300. return shouldConstruct$1(Component) ? ClassComponent : FunctionComponent;
  23301. } else if (Component !== undefined && Component !== null) {
  23302. var $$typeof = Component.$$typeof;
  23303. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  23304. return ForwardRef;
  23305. }
  23306. if ($$typeof === REACT_MEMO_TYPE) {
  23307. return MemoComponent;
  23308. }
  23309. }
  23310. return IndeterminateComponent;
  23311. } // This is used to create an alternate fiber to do work on.
  23312. function createWorkInProgress(current, pendingProps) {
  23313. var workInProgress = current.alternate;
  23314. if (workInProgress === null) {
  23315. // We use a double buffering pooling technique because we know that we'll
  23316. // only ever need at most two versions of a tree. We pool the "other" unused
  23317. // node that we're free to reuse. This is lazily created to avoid allocating
  23318. // extra objects for things that are never updated. It also allow us to
  23319. // reclaim the extra memory if needed.
  23320. workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
  23321. workInProgress.elementType = current.elementType;
  23322. workInProgress.type = current.type;
  23323. workInProgress.stateNode = current.stateNode;
  23324. {
  23325. // DEV-only fields
  23326. workInProgress._debugSource = current._debugSource;
  23327. workInProgress._debugOwner = current._debugOwner;
  23328. workInProgress._debugHookTypes = current._debugHookTypes;
  23329. }
  23330. workInProgress.alternate = current;
  23331. current.alternate = workInProgress;
  23332. } else {
  23333. workInProgress.pendingProps = pendingProps; // Needed because Blocks store data on type.
  23334. workInProgress.type = current.type; // We already have an alternate.
  23335. // Reset the effect tag.
  23336. workInProgress.flags = NoFlags; // The effects are no longer valid.
  23337. workInProgress.subtreeFlags = NoFlags;
  23338. workInProgress.deletions = null;
  23339. {
  23340. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  23341. // This prevents time from endlessly accumulating in new commits.
  23342. // This has the downside of resetting values for different priority renders,
  23343. // But works for yielding (the common case) and should support resuming.
  23344. workInProgress.actualDuration = 0;
  23345. workInProgress.actualStartTime = -1;
  23346. }
  23347. } // Reset all effects except static ones.
  23348. // Static effects are not specific to a render.
  23349. workInProgress.flags = current.flags & StaticMask;
  23350. workInProgress.childLanes = current.childLanes;
  23351. workInProgress.lanes = current.lanes;
  23352. workInProgress.child = current.child;
  23353. workInProgress.memoizedProps = current.memoizedProps;
  23354. workInProgress.memoizedState = current.memoizedState;
  23355. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  23356. // it cannot be shared with the current fiber.
  23357. var currentDependencies = current.dependencies;
  23358. workInProgress.dependencies = currentDependencies === null ? null : {
  23359. lanes: currentDependencies.lanes,
  23360. firstContext: currentDependencies.firstContext
  23361. }; // These will be overridden during the parent's reconciliation
  23362. workInProgress.sibling = current.sibling;
  23363. workInProgress.index = current.index;
  23364. workInProgress.ref = current.ref;
  23365. {
  23366. workInProgress.selfBaseDuration = current.selfBaseDuration;
  23367. workInProgress.treeBaseDuration = current.treeBaseDuration;
  23368. }
  23369. {
  23370. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  23371. switch (workInProgress.tag) {
  23372. case IndeterminateComponent:
  23373. case FunctionComponent:
  23374. case SimpleMemoComponent:
  23375. workInProgress.type = resolveFunctionForHotReloading(current.type);
  23376. break;
  23377. case ClassComponent:
  23378. workInProgress.type = resolveClassForHotReloading(current.type);
  23379. break;
  23380. case ForwardRef:
  23381. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  23382. break;
  23383. }
  23384. }
  23385. return workInProgress;
  23386. } // Used to reuse a Fiber for a second pass.
  23387. function resetWorkInProgress(workInProgress, renderLanes) {
  23388. // This resets the Fiber to what createFiber or createWorkInProgress would
  23389. // have set the values to before during the first pass. Ideally this wouldn't
  23390. // be necessary but unfortunately many code paths reads from the workInProgress
  23391. // when they should be reading from current and writing to workInProgress.
  23392. // We assume pendingProps, index, key, ref, return are still untouched to
  23393. // avoid doing another reconciliation.
  23394. // Reset the effect flags but keep any Placement tags, since that's something
  23395. // that child fiber is setting, not the reconciliation.
  23396. workInProgress.flags &= StaticMask | Placement; // The effects are no longer valid.
  23397. var current = workInProgress.alternate;
  23398. if (current === null) {
  23399. // Reset to createFiber's initial values.
  23400. workInProgress.childLanes = NoLanes;
  23401. workInProgress.lanes = renderLanes;
  23402. workInProgress.child = null;
  23403. workInProgress.subtreeFlags = NoFlags;
  23404. workInProgress.memoizedProps = null;
  23405. workInProgress.memoizedState = null;
  23406. workInProgress.updateQueue = null;
  23407. workInProgress.dependencies = null;
  23408. workInProgress.stateNode = null;
  23409. {
  23410. // Note: We don't reset the actualTime counts. It's useful to accumulate
  23411. // actual time across multiple render passes.
  23412. workInProgress.selfBaseDuration = 0;
  23413. workInProgress.treeBaseDuration = 0;
  23414. }
  23415. } else {
  23416. // Reset to the cloned values that createWorkInProgress would've.
  23417. workInProgress.childLanes = current.childLanes;
  23418. workInProgress.lanes = current.lanes;
  23419. workInProgress.child = current.child;
  23420. workInProgress.subtreeFlags = NoFlags;
  23421. workInProgress.deletions = null;
  23422. workInProgress.memoizedProps = current.memoizedProps;
  23423. workInProgress.memoizedState = current.memoizedState;
  23424. workInProgress.updateQueue = current.updateQueue; // Needed because Blocks store data on type.
  23425. workInProgress.type = current.type; // Clone the dependencies object. This is mutated during the render phase, so
  23426. // it cannot be shared with the current fiber.
  23427. var currentDependencies = current.dependencies;
  23428. workInProgress.dependencies = currentDependencies === null ? null : {
  23429. lanes: currentDependencies.lanes,
  23430. firstContext: currentDependencies.firstContext
  23431. };
  23432. {
  23433. // Note: We don't reset the actualTime counts. It's useful to accumulate
  23434. // actual time across multiple render passes.
  23435. workInProgress.selfBaseDuration = current.selfBaseDuration;
  23436. workInProgress.treeBaseDuration = current.treeBaseDuration;
  23437. }
  23438. }
  23439. return workInProgress;
  23440. }
  23441. function createHostRootFiber(tag, isStrictMode, concurrentUpdatesByDefaultOverride) {
  23442. var mode;
  23443. if (tag === ConcurrentRoot) {
  23444. mode = ConcurrentMode;
  23445. if (isStrictMode === true) {
  23446. mode |= StrictLegacyMode;
  23447. {
  23448. mode |= StrictEffectsMode;
  23449. }
  23450. }
  23451. } else {
  23452. mode = NoMode;
  23453. }
  23454. if ( isDevToolsPresent) {
  23455. // Always collect profile timings when DevTools are present.
  23456. // This enables DevTools to start capturing timing at any point–
  23457. // Without some nodes in the tree having empty base times.
  23458. mode |= ProfileMode;
  23459. }
  23460. return createFiber(HostRoot, null, null, mode);
  23461. }
  23462. function createFiberFromTypeAndProps(type, // React$ElementType
  23463. key, pendingProps, owner, mode, lanes) {
  23464. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  23465. var resolvedType = type;
  23466. if (typeof type === 'function') {
  23467. if (shouldConstruct$1(type)) {
  23468. fiberTag = ClassComponent;
  23469. {
  23470. resolvedType = resolveClassForHotReloading(resolvedType);
  23471. }
  23472. } else {
  23473. {
  23474. resolvedType = resolveFunctionForHotReloading(resolvedType);
  23475. }
  23476. }
  23477. } else if (typeof type === 'string') {
  23478. fiberTag = HostComponent;
  23479. } else {
  23480. getTag: switch (type) {
  23481. case REACT_FRAGMENT_TYPE:
  23482. return createFiberFromFragment(pendingProps.children, mode, lanes, key);
  23483. case REACT_STRICT_MODE_TYPE:
  23484. fiberTag = Mode;
  23485. mode |= StrictLegacyMode;
  23486. if ( (mode & ConcurrentMode) !== NoMode) {
  23487. // Strict effects should never run on legacy roots
  23488. mode |= StrictEffectsMode;
  23489. }
  23490. break;
  23491. case REACT_PROFILER_TYPE:
  23492. return createFiberFromProfiler(pendingProps, mode, lanes, key);
  23493. case REACT_SUSPENSE_TYPE:
  23494. return createFiberFromSuspense(pendingProps, mode, lanes, key);
  23495. case REACT_SUSPENSE_LIST_TYPE:
  23496. return createFiberFromSuspenseList(pendingProps, mode, lanes, key);
  23497. case REACT_OFFSCREEN_TYPE:
  23498. return createFiberFromOffscreen(pendingProps, mode, lanes, key);
  23499. case REACT_LEGACY_HIDDEN_TYPE:
  23500. // eslint-disable-next-line no-fallthrough
  23501. case REACT_SCOPE_TYPE:
  23502. // eslint-disable-next-line no-fallthrough
  23503. case REACT_CACHE_TYPE:
  23504. // eslint-disable-next-line no-fallthrough
  23505. case REACT_TRACING_MARKER_TYPE:
  23506. // eslint-disable-next-line no-fallthrough
  23507. case REACT_DEBUG_TRACING_MODE_TYPE:
  23508. // eslint-disable-next-line no-fallthrough
  23509. default:
  23510. {
  23511. if (typeof type === 'object' && type !== null) {
  23512. switch (type.$$typeof) {
  23513. case REACT_PROVIDER_TYPE:
  23514. fiberTag = ContextProvider;
  23515. break getTag;
  23516. case REACT_CONTEXT_TYPE:
  23517. // This is a consumer
  23518. fiberTag = ContextConsumer;
  23519. break getTag;
  23520. case REACT_FORWARD_REF_TYPE:
  23521. fiberTag = ForwardRef;
  23522. {
  23523. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  23524. }
  23525. break getTag;
  23526. case REACT_MEMO_TYPE:
  23527. fiberTag = MemoComponent;
  23528. break getTag;
  23529. case REACT_LAZY_TYPE:
  23530. fiberTag = LazyComponent;
  23531. resolvedType = null;
  23532. break getTag;
  23533. }
  23534. }
  23535. var info = '';
  23536. {
  23537. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  23538. 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.';
  23539. }
  23540. var ownerName = owner ? getComponentNameFromFiber(owner) : null;
  23541. if (ownerName) {
  23542. info += '\n\nCheck the render method of `' + ownerName + '`.';
  23543. }
  23544. }
  23545. throw new 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));
  23546. }
  23547. }
  23548. }
  23549. var fiber = createFiber(fiberTag, pendingProps, key, mode);
  23550. fiber.elementType = type;
  23551. fiber.type = resolvedType;
  23552. fiber.lanes = lanes;
  23553. {
  23554. fiber._debugOwner = owner;
  23555. }
  23556. return fiber;
  23557. }
  23558. function createFiberFromElement(element, mode, lanes) {
  23559. var owner = null;
  23560. {
  23561. owner = element._owner;
  23562. }
  23563. var type = element.type;
  23564. var key = element.key;
  23565. var pendingProps = element.props;
  23566. var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, lanes);
  23567. {
  23568. fiber._debugSource = element._source;
  23569. fiber._debugOwner = element._owner;
  23570. }
  23571. return fiber;
  23572. }
  23573. function createFiberFromFragment(elements, mode, lanes, key) {
  23574. var fiber = createFiber(Fragment, elements, key, mode);
  23575. fiber.lanes = lanes;
  23576. return fiber;
  23577. }
  23578. function createFiberFromProfiler(pendingProps, mode, lanes, key) {
  23579. {
  23580. if (typeof pendingProps.id !== 'string') {
  23581. error('Profiler must specify an "id" of type `string` as a prop. Received the type `%s` instead.', typeof pendingProps.id);
  23582. }
  23583. }
  23584. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode);
  23585. fiber.elementType = REACT_PROFILER_TYPE;
  23586. fiber.lanes = lanes;
  23587. {
  23588. fiber.stateNode = {
  23589. effectDuration: 0,
  23590. passiveEffectDuration: 0
  23591. };
  23592. }
  23593. return fiber;
  23594. }
  23595. function createFiberFromSuspense(pendingProps, mode, lanes, key) {
  23596. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode);
  23597. fiber.elementType = REACT_SUSPENSE_TYPE;
  23598. fiber.lanes = lanes;
  23599. return fiber;
  23600. }
  23601. function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
  23602. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  23603. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  23604. fiber.lanes = lanes;
  23605. return fiber;
  23606. }
  23607. function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
  23608. var fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
  23609. fiber.elementType = REACT_OFFSCREEN_TYPE;
  23610. fiber.lanes = lanes;
  23611. var primaryChildInstance = {
  23612. isHidden: false
  23613. };
  23614. fiber.stateNode = primaryChildInstance;
  23615. return fiber;
  23616. }
  23617. function createFiberFromText(content, mode, lanes) {
  23618. var fiber = createFiber(HostText, content, null, mode);
  23619. fiber.lanes = lanes;
  23620. return fiber;
  23621. }
  23622. function createFiberFromHostInstanceForDeletion() {
  23623. var fiber = createFiber(HostComponent, null, null, NoMode);
  23624. fiber.elementType = 'DELETED';
  23625. return fiber;
  23626. }
  23627. function createFiberFromDehydratedFragment(dehydratedNode) {
  23628. var fiber = createFiber(DehydratedFragment, null, null, NoMode);
  23629. fiber.stateNode = dehydratedNode;
  23630. return fiber;
  23631. }
  23632. function createFiberFromPortal(portal, mode, lanes) {
  23633. var pendingProps = portal.children !== null ? portal.children : [];
  23634. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  23635. fiber.lanes = lanes;
  23636. fiber.stateNode = {
  23637. containerInfo: portal.containerInfo,
  23638. pendingChildren: null,
  23639. // Used by persistent updates
  23640. implementation: portal.implementation
  23641. };
  23642. return fiber;
  23643. } // Used for stashing WIP properties to replay failed work in DEV.
  23644. function assignFiberPropertiesInDEV(target, source) {
  23645. if (target === null) {
  23646. // This Fiber's initial properties will always be overwritten.
  23647. // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
  23648. target = createFiber(IndeterminateComponent, null, null, NoMode);
  23649. } // This is intentionally written as a list of all properties.
  23650. // We tried to use Object.assign() instead but this is called in
  23651. // the hottest path, and Object.assign() was too slow:
  23652. // https://github.com/facebook/react/issues/12502
  23653. // This code is DEV-only so size is not a concern.
  23654. target.tag = source.tag;
  23655. target.key = source.key;
  23656. target.elementType = source.elementType;
  23657. target.type = source.type;
  23658. target.stateNode = source.stateNode;
  23659. target.return = source.return;
  23660. target.child = source.child;
  23661. target.sibling = source.sibling;
  23662. target.index = source.index;
  23663. target.ref = source.ref;
  23664. target.pendingProps = source.pendingProps;
  23665. target.memoizedProps = source.memoizedProps;
  23666. target.updateQueue = source.updateQueue;
  23667. target.memoizedState = source.memoizedState;
  23668. target.dependencies = source.dependencies;
  23669. target.mode = source.mode;
  23670. target.flags = source.flags;
  23671. target.subtreeFlags = source.subtreeFlags;
  23672. target.deletions = source.deletions;
  23673. target.lanes = source.lanes;
  23674. target.childLanes = source.childLanes;
  23675. target.alternate = source.alternate;
  23676. {
  23677. target.actualDuration = source.actualDuration;
  23678. target.actualStartTime = source.actualStartTime;
  23679. target.selfBaseDuration = source.selfBaseDuration;
  23680. target.treeBaseDuration = source.treeBaseDuration;
  23681. }
  23682. target._debugSource = source._debugSource;
  23683. target._debugOwner = source._debugOwner;
  23684. target._debugNeedsRemount = source._debugNeedsRemount;
  23685. target._debugHookTypes = source._debugHookTypes;
  23686. return target;
  23687. }
  23688. function FiberRootNode(containerInfo, tag, hydrate, identifierPrefix, onRecoverableError) {
  23689. this.tag = tag;
  23690. this.containerInfo = containerInfo;
  23691. this.pendingChildren = null;
  23692. this.current = null;
  23693. this.pingCache = null;
  23694. this.finishedWork = null;
  23695. this.timeoutHandle = noTimeout;
  23696. this.context = null;
  23697. this.pendingContext = null;
  23698. this.callbackNode = null;
  23699. this.callbackPriority = NoLane;
  23700. this.eventTimes = createLaneMap(NoLanes);
  23701. this.expirationTimes = createLaneMap(NoTimestamp);
  23702. this.pendingLanes = NoLanes;
  23703. this.suspendedLanes = NoLanes;
  23704. this.pingedLanes = NoLanes;
  23705. this.expiredLanes = NoLanes;
  23706. this.mutableReadLanes = NoLanes;
  23707. this.finishedLanes = NoLanes;
  23708. this.entangledLanes = NoLanes;
  23709. this.entanglements = createLaneMap(NoLanes);
  23710. this.identifierPrefix = identifierPrefix;
  23711. this.onRecoverableError = onRecoverableError;
  23712. {
  23713. this.mutableSourceEagerHydrationData = null;
  23714. }
  23715. {
  23716. this.effectDuration = 0;
  23717. this.passiveEffectDuration = 0;
  23718. }
  23719. {
  23720. this.memoizedUpdaters = new Set();
  23721. var pendingUpdatersLaneMap = this.pendingUpdatersLaneMap = [];
  23722. for (var _i = 0; _i < TotalLanes; _i++) {
  23723. pendingUpdatersLaneMap.push(new Set());
  23724. }
  23725. }
  23726. {
  23727. switch (tag) {
  23728. case ConcurrentRoot:
  23729. this._debugRootType = hydrate ? 'hydrateRoot()' : 'createRoot()';
  23730. break;
  23731. case LegacyRoot:
  23732. this._debugRootType = hydrate ? 'hydrate()' : 'render()';
  23733. break;
  23734. }
  23735. }
  23736. }
  23737. function createFiberRoot(containerInfo, tag, hydrate, initialChildren, hydrationCallbacks, isStrictMode, concurrentUpdatesByDefaultOverride, // TODO: We have several of these arguments that are conceptually part of the
  23738. // host config, but because they are passed in at runtime, we have to thread
  23739. // them through the root constructor. Perhaps we should put them all into a
  23740. // single type, like a DynamicHostConfig that is defined by the renderer.
  23741. identifierPrefix, onRecoverableError, transitionCallbacks) {
  23742. var root = new FiberRootNode(containerInfo, tag, hydrate, identifierPrefix, onRecoverableError);
  23743. // stateNode is any.
  23744. var uninitializedFiber = createHostRootFiber(tag, isStrictMode);
  23745. root.current = uninitializedFiber;
  23746. uninitializedFiber.stateNode = root;
  23747. {
  23748. var _initialState = {
  23749. element: initialChildren,
  23750. isDehydrated: hydrate,
  23751. cache: null,
  23752. // not enabled yet
  23753. transitions: null,
  23754. pendingSuspenseBoundaries: null
  23755. };
  23756. uninitializedFiber.memoizedState = _initialState;
  23757. }
  23758. initializeUpdateQueue(uninitializedFiber);
  23759. return root;
  23760. }
  23761. var ReactVersion = '18.2.0';
  23762. function createPortal(children, containerInfo, // TODO: figure out the API for cross-renderer implementation.
  23763. implementation) {
  23764. var key = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  23765. {
  23766. checkKeyStringCoercion(key);
  23767. }
  23768. return {
  23769. // This tag allow us to uniquely identify this as a React Portal
  23770. $$typeof: REACT_PORTAL_TYPE,
  23771. key: key == null ? null : '' + key,
  23772. children: children,
  23773. containerInfo: containerInfo,
  23774. implementation: implementation
  23775. };
  23776. }
  23777. var didWarnAboutNestedUpdates;
  23778. var didWarnAboutFindNodeInStrictMode;
  23779. {
  23780. didWarnAboutNestedUpdates = false;
  23781. didWarnAboutFindNodeInStrictMode = {};
  23782. }
  23783. function getContextForSubtree(parentComponent) {
  23784. if (!parentComponent) {
  23785. return emptyContextObject;
  23786. }
  23787. var fiber = get(parentComponent);
  23788. var parentContext = findCurrentUnmaskedContext(fiber);
  23789. if (fiber.tag === ClassComponent) {
  23790. var Component = fiber.type;
  23791. if (isContextProvider(Component)) {
  23792. return processChildContext(fiber, Component, parentContext);
  23793. }
  23794. }
  23795. return parentContext;
  23796. }
  23797. function findHostInstanceWithWarning(component, methodName) {
  23798. {
  23799. var fiber = get(component);
  23800. if (fiber === undefined) {
  23801. if (typeof component.render === 'function') {
  23802. throw new Error('Unable to find node on an unmounted component.');
  23803. } else {
  23804. var keys = Object.keys(component).join(',');
  23805. throw new Error("Argument appears to not be a ReactComponent. Keys: " + keys);
  23806. }
  23807. }
  23808. var hostFiber = findCurrentHostFiber(fiber);
  23809. if (hostFiber === null) {
  23810. return null;
  23811. }
  23812. if (hostFiber.mode & StrictLegacyMode) {
  23813. var componentName = getComponentNameFromFiber(fiber) || 'Component';
  23814. if (!didWarnAboutFindNodeInStrictMode[componentName]) {
  23815. didWarnAboutFindNodeInStrictMode[componentName] = true;
  23816. var previousFiber = current;
  23817. try {
  23818. setCurrentFiber(hostFiber);
  23819. if (fiber.mode & StrictLegacyMode) {
  23820. error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which is inside StrictMode. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-find-node', methodName, methodName, componentName);
  23821. } else {
  23822. error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which renders StrictMode children. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-find-node', methodName, methodName, componentName);
  23823. }
  23824. } finally {
  23825. // Ideally this should reset to previous but this shouldn't be called in
  23826. // render and there's another warning for that anyway.
  23827. if (previousFiber) {
  23828. setCurrentFiber(previousFiber);
  23829. } else {
  23830. resetCurrentFiber();
  23831. }
  23832. }
  23833. }
  23834. }
  23835. return hostFiber.stateNode;
  23836. }
  23837. }
  23838. function createContainer(containerInfo, tag, hydrationCallbacks, isStrictMode, concurrentUpdatesByDefaultOverride, identifierPrefix, onRecoverableError, transitionCallbacks) {
  23839. var hydrate = false;
  23840. var initialChildren = null;
  23841. return createFiberRoot(containerInfo, tag, hydrate, initialChildren, hydrationCallbacks, isStrictMode, concurrentUpdatesByDefaultOverride, identifierPrefix, onRecoverableError);
  23842. }
  23843. function createHydrationContainer(initialChildren, // TODO: Remove `callback` when we delete legacy mode.
  23844. callback, containerInfo, tag, hydrationCallbacks, isStrictMode, concurrentUpdatesByDefaultOverride, identifierPrefix, onRecoverableError, transitionCallbacks) {
  23845. var hydrate = true;
  23846. var root = createFiberRoot(containerInfo, tag, hydrate, initialChildren, hydrationCallbacks, isStrictMode, concurrentUpdatesByDefaultOverride, identifierPrefix, onRecoverableError); // TODO: Move this to FiberRoot constructor
  23847. root.context = getContextForSubtree(null); // Schedule the initial render. In a hydration root, this is different from
  23848. // a regular update because the initial render must match was was rendered
  23849. // on the server.
  23850. // NOTE: This update intentionally doesn't have a payload. We're only using
  23851. // the update to schedule work on the root fiber (and, for legacy roots, to
  23852. // enqueue the callback if one is provided).
  23853. var current = root.current;
  23854. var eventTime = requestEventTime();
  23855. var lane = requestUpdateLane(current);
  23856. var update = createUpdate(eventTime, lane);
  23857. update.callback = callback !== undefined && callback !== null ? callback : null;
  23858. enqueueUpdate(current, update, lane);
  23859. scheduleInitialHydrationOnRoot(root, lane, eventTime);
  23860. return root;
  23861. }
  23862. function updateContainer(element, container, parentComponent, callback) {
  23863. {
  23864. onScheduleRoot(container, element);
  23865. }
  23866. var current$1 = container.current;
  23867. var eventTime = requestEventTime();
  23868. var lane = requestUpdateLane(current$1);
  23869. {
  23870. markRenderScheduled(lane);
  23871. }
  23872. var context = getContextForSubtree(parentComponent);
  23873. if (container.context === null) {
  23874. container.context = context;
  23875. } else {
  23876. container.pendingContext = context;
  23877. }
  23878. {
  23879. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  23880. didWarnAboutNestedUpdates = true;
  23881. 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.', getComponentNameFromFiber(current) || 'Unknown');
  23882. }
  23883. }
  23884. var update = createUpdate(eventTime, lane); // Caution: React DevTools currently depends on this property
  23885. // being called "element".
  23886. update.payload = {
  23887. element: element
  23888. };
  23889. callback = callback === undefined ? null : callback;
  23890. if (callback !== null) {
  23891. {
  23892. if (typeof callback !== 'function') {
  23893. error('render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback);
  23894. }
  23895. }
  23896. update.callback = callback;
  23897. }
  23898. var root = enqueueUpdate(current$1, update, lane);
  23899. if (root !== null) {
  23900. scheduleUpdateOnFiber(root, current$1, lane, eventTime);
  23901. entangleTransitions(root, current$1, lane);
  23902. }
  23903. return lane;
  23904. }
  23905. function getPublicRootInstance(container) {
  23906. var containerFiber = container.current;
  23907. if (!containerFiber.child) {
  23908. return null;
  23909. }
  23910. switch (containerFiber.child.tag) {
  23911. case HostComponent:
  23912. return getPublicInstance(containerFiber.child.stateNode);
  23913. default:
  23914. return containerFiber.child.stateNode;
  23915. }
  23916. }
  23917. function attemptSynchronousHydration$1(fiber) {
  23918. switch (fiber.tag) {
  23919. case HostRoot:
  23920. {
  23921. var root = fiber.stateNode;
  23922. if (isRootDehydrated(root)) {
  23923. // Flush the first scheduled "update".
  23924. var lanes = getHighestPriorityPendingLanes(root);
  23925. flushRoot(root, lanes);
  23926. }
  23927. break;
  23928. }
  23929. case SuspenseComponent:
  23930. {
  23931. flushSync(function () {
  23932. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  23933. if (root !== null) {
  23934. var eventTime = requestEventTime();
  23935. scheduleUpdateOnFiber(root, fiber, SyncLane, eventTime);
  23936. }
  23937. }); // If we're still blocked after this, we need to increase
  23938. // the priority of any promises resolving within this
  23939. // boundary so that they next attempt also has higher pri.
  23940. var retryLane = SyncLane;
  23941. markRetryLaneIfNotHydrated(fiber, retryLane);
  23942. break;
  23943. }
  23944. }
  23945. }
  23946. function markRetryLaneImpl(fiber, retryLane) {
  23947. var suspenseState = fiber.memoizedState;
  23948. if (suspenseState !== null && suspenseState.dehydrated !== null) {
  23949. suspenseState.retryLane = higherPriorityLane(suspenseState.retryLane, retryLane);
  23950. }
  23951. } // Increases the priority of thenables when they resolve within this boundary.
  23952. function markRetryLaneIfNotHydrated(fiber, retryLane) {
  23953. markRetryLaneImpl(fiber, retryLane);
  23954. var alternate = fiber.alternate;
  23955. if (alternate) {
  23956. markRetryLaneImpl(alternate, retryLane);
  23957. }
  23958. }
  23959. function attemptContinuousHydration$1(fiber) {
  23960. if (fiber.tag !== SuspenseComponent) {
  23961. // We ignore HostRoots here because we can't increase
  23962. // their priority and they should not suspend on I/O,
  23963. // since you have to wrap anything that might suspend in
  23964. // Suspense.
  23965. return;
  23966. }
  23967. var lane = SelectiveHydrationLane;
  23968. var root = enqueueConcurrentRenderForLane(fiber, lane);
  23969. if (root !== null) {
  23970. var eventTime = requestEventTime();
  23971. scheduleUpdateOnFiber(root, fiber, lane, eventTime);
  23972. }
  23973. markRetryLaneIfNotHydrated(fiber, lane);
  23974. }
  23975. function attemptHydrationAtCurrentPriority$1(fiber) {
  23976. if (fiber.tag !== SuspenseComponent) {
  23977. // We ignore HostRoots here because we can't increase
  23978. // their priority other than synchronously flush it.
  23979. return;
  23980. }
  23981. var lane = requestUpdateLane(fiber);
  23982. var root = enqueueConcurrentRenderForLane(fiber, lane);
  23983. if (root !== null) {
  23984. var eventTime = requestEventTime();
  23985. scheduleUpdateOnFiber(root, fiber, lane, eventTime);
  23986. }
  23987. markRetryLaneIfNotHydrated(fiber, lane);
  23988. }
  23989. function findHostInstanceWithNoPortals(fiber) {
  23990. var hostFiber = findCurrentHostFiberWithNoPortals(fiber);
  23991. if (hostFiber === null) {
  23992. return null;
  23993. }
  23994. return hostFiber.stateNode;
  23995. }
  23996. var shouldErrorImpl = function (fiber) {
  23997. return null;
  23998. };
  23999. function shouldError(fiber) {
  24000. return shouldErrorImpl(fiber);
  24001. }
  24002. var shouldSuspendImpl = function (fiber) {
  24003. return false;
  24004. };
  24005. function shouldSuspend(fiber) {
  24006. return shouldSuspendImpl(fiber);
  24007. }
  24008. var overrideHookState = null;
  24009. var overrideHookStateDeletePath = null;
  24010. var overrideHookStateRenamePath = null;
  24011. var overrideProps = null;
  24012. var overridePropsDeletePath = null;
  24013. var overridePropsRenamePath = null;
  24014. var scheduleUpdate = null;
  24015. var setErrorHandler = null;
  24016. var setSuspenseHandler = null;
  24017. {
  24018. var copyWithDeleteImpl = function (obj, path, index) {
  24019. var key = path[index];
  24020. var updated = isArray(obj) ? obj.slice() : assign({}, obj);
  24021. if (index + 1 === path.length) {
  24022. if (isArray(updated)) {
  24023. updated.splice(key, 1);
  24024. } else {
  24025. delete updated[key];
  24026. }
  24027. return updated;
  24028. } // $FlowFixMe number or string is fine here
  24029. updated[key] = copyWithDeleteImpl(obj[key], path, index + 1);
  24030. return updated;
  24031. };
  24032. var copyWithDelete = function (obj, path) {
  24033. return copyWithDeleteImpl(obj, path, 0);
  24034. };
  24035. var copyWithRenameImpl = function (obj, oldPath, newPath, index) {
  24036. var oldKey = oldPath[index];
  24037. var updated = isArray(obj) ? obj.slice() : assign({}, obj);
  24038. if (index + 1 === oldPath.length) {
  24039. var newKey = newPath[index]; // $FlowFixMe number or string is fine here
  24040. updated[newKey] = updated[oldKey];
  24041. if (isArray(updated)) {
  24042. updated.splice(oldKey, 1);
  24043. } else {
  24044. delete updated[oldKey];
  24045. }
  24046. } else {
  24047. // $FlowFixMe number or string is fine here
  24048. updated[oldKey] = copyWithRenameImpl( // $FlowFixMe number or string is fine here
  24049. obj[oldKey], oldPath, newPath, index + 1);
  24050. }
  24051. return updated;
  24052. };
  24053. var copyWithRename = function (obj, oldPath, newPath) {
  24054. if (oldPath.length !== newPath.length) {
  24055. warn('copyWithRename() expects paths of the same length');
  24056. return;
  24057. } else {
  24058. for (var i = 0; i < newPath.length - 1; i++) {
  24059. if (oldPath[i] !== newPath[i]) {
  24060. warn('copyWithRename() expects paths to be the same except for the deepest key');
  24061. return;
  24062. }
  24063. }
  24064. }
  24065. return copyWithRenameImpl(obj, oldPath, newPath, 0);
  24066. };
  24067. var copyWithSetImpl = function (obj, path, index, value) {
  24068. if (index >= path.length) {
  24069. return value;
  24070. }
  24071. var key = path[index];
  24072. var updated = isArray(obj) ? obj.slice() : assign({}, obj); // $FlowFixMe number or string is fine here
  24073. updated[key] = copyWithSetImpl(obj[key], path, index + 1, value);
  24074. return updated;
  24075. };
  24076. var copyWithSet = function (obj, path, value) {
  24077. return copyWithSetImpl(obj, path, 0, value);
  24078. };
  24079. var findHook = function (fiber, id) {
  24080. // For now, the "id" of stateful hooks is just the stateful hook index.
  24081. // This may change in the future with e.g. nested hooks.
  24082. var currentHook = fiber.memoizedState;
  24083. while (currentHook !== null && id > 0) {
  24084. currentHook = currentHook.next;
  24085. id--;
  24086. }
  24087. return currentHook;
  24088. }; // Support DevTools editable values for useState and useReducer.
  24089. overrideHookState = function (fiber, id, path, value) {
  24090. var hook = findHook(fiber, id);
  24091. if (hook !== null) {
  24092. var newState = copyWithSet(hook.memoizedState, path, value);
  24093. hook.memoizedState = newState;
  24094. hook.baseState = newState; // We aren't actually adding an update to the queue,
  24095. // because there is no update we can add for useReducer hooks that won't trigger an error.
  24096. // (There's no appropriate action type for DevTools overrides.)
  24097. // As a result though, React will see the scheduled update as a noop and bailout.
  24098. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  24099. fiber.memoizedProps = assign({}, fiber.memoizedProps);
  24100. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  24101. if (root !== null) {
  24102. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  24103. }
  24104. }
  24105. };
  24106. overrideHookStateDeletePath = function (fiber, id, path) {
  24107. var hook = findHook(fiber, id);
  24108. if (hook !== null) {
  24109. var newState = copyWithDelete(hook.memoizedState, path);
  24110. hook.memoizedState = newState;
  24111. hook.baseState = newState; // We aren't actually adding an update to the queue,
  24112. // because there is no update we can add for useReducer hooks that won't trigger an error.
  24113. // (There's no appropriate action type for DevTools overrides.)
  24114. // As a result though, React will see the scheduled update as a noop and bailout.
  24115. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  24116. fiber.memoizedProps = assign({}, fiber.memoizedProps);
  24117. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  24118. if (root !== null) {
  24119. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  24120. }
  24121. }
  24122. };
  24123. overrideHookStateRenamePath = function (fiber, id, oldPath, newPath) {
  24124. var hook = findHook(fiber, id);
  24125. if (hook !== null) {
  24126. var newState = copyWithRename(hook.memoizedState, oldPath, newPath);
  24127. hook.memoizedState = newState;
  24128. hook.baseState = newState; // We aren't actually adding an update to the queue,
  24129. // because there is no update we can add for useReducer hooks that won't trigger an error.
  24130. // (There's no appropriate action type for DevTools overrides.)
  24131. // As a result though, React will see the scheduled update as a noop and bailout.
  24132. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  24133. fiber.memoizedProps = assign({}, fiber.memoizedProps);
  24134. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  24135. if (root !== null) {
  24136. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  24137. }
  24138. }
  24139. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  24140. overrideProps = function (fiber, path, value) {
  24141. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  24142. if (fiber.alternate) {
  24143. fiber.alternate.pendingProps = fiber.pendingProps;
  24144. }
  24145. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  24146. if (root !== null) {
  24147. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  24148. }
  24149. };
  24150. overridePropsDeletePath = function (fiber, path) {
  24151. fiber.pendingProps = copyWithDelete(fiber.memoizedProps, path);
  24152. if (fiber.alternate) {
  24153. fiber.alternate.pendingProps = fiber.pendingProps;
  24154. }
  24155. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  24156. if (root !== null) {
  24157. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  24158. }
  24159. };
  24160. overridePropsRenamePath = function (fiber, oldPath, newPath) {
  24161. fiber.pendingProps = copyWithRename(fiber.memoizedProps, oldPath, newPath);
  24162. if (fiber.alternate) {
  24163. fiber.alternate.pendingProps = fiber.pendingProps;
  24164. }
  24165. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  24166. if (root !== null) {
  24167. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  24168. }
  24169. };
  24170. scheduleUpdate = function (fiber) {
  24171. var root = enqueueConcurrentRenderForLane(fiber, SyncLane);
  24172. if (root !== null) {
  24173. scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
  24174. }
  24175. };
  24176. setErrorHandler = function (newShouldErrorImpl) {
  24177. shouldErrorImpl = newShouldErrorImpl;
  24178. };
  24179. setSuspenseHandler = function (newShouldSuspendImpl) {
  24180. shouldSuspendImpl = newShouldSuspendImpl;
  24181. };
  24182. }
  24183. function findHostInstanceByFiber(fiber) {
  24184. var hostFiber = findCurrentHostFiber(fiber);
  24185. if (hostFiber === null) {
  24186. return null;
  24187. }
  24188. return hostFiber.stateNode;
  24189. }
  24190. function emptyFindFiberByHostInstance(instance) {
  24191. return null;
  24192. }
  24193. function getCurrentFiberForDevTools() {
  24194. return current;
  24195. }
  24196. function injectIntoDevTools(devToolsConfig) {
  24197. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  24198. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  24199. return injectInternals({
  24200. bundleType: devToolsConfig.bundleType,
  24201. version: devToolsConfig.version,
  24202. rendererPackageName: devToolsConfig.rendererPackageName,
  24203. rendererConfig: devToolsConfig.rendererConfig,
  24204. overrideHookState: overrideHookState,
  24205. overrideHookStateDeletePath: overrideHookStateDeletePath,
  24206. overrideHookStateRenamePath: overrideHookStateRenamePath,
  24207. overrideProps: overrideProps,
  24208. overridePropsDeletePath: overridePropsDeletePath,
  24209. overridePropsRenamePath: overridePropsRenamePath,
  24210. setErrorHandler: setErrorHandler,
  24211. setSuspenseHandler: setSuspenseHandler,
  24212. scheduleUpdate: scheduleUpdate,
  24213. currentDispatcherRef: ReactCurrentDispatcher,
  24214. findHostInstanceByFiber: findHostInstanceByFiber,
  24215. findFiberByHostInstance: findFiberByHostInstance || emptyFindFiberByHostInstance,
  24216. // React Refresh
  24217. findHostInstancesForRefresh: findHostInstancesForRefresh ,
  24218. scheduleRefresh: scheduleRefresh ,
  24219. scheduleRoot: scheduleRoot ,
  24220. setRefreshHandler: setRefreshHandler ,
  24221. // Enables DevTools to append owner stacks to error messages in DEV mode.
  24222. getCurrentFiber: getCurrentFiberForDevTools ,
  24223. // Enables DevTools to detect reconciler version rather than renderer version
  24224. // which may not match for third party renderers.
  24225. reconcilerVersion: ReactVersion
  24226. });
  24227. }
  24228. /* global reportError */
  24229. var defaultOnRecoverableError = typeof reportError === 'function' ? // In modern browsers, reportError will dispatch an error event,
  24230. // emulating an uncaught JavaScript error.
  24231. reportError : function (error) {
  24232. // In older browsers and test environments, fallback to console.error.
  24233. // eslint-disable-next-line react-internal/no-production-logging
  24234. console['error'](error);
  24235. };
  24236. function ReactDOMRoot(internalRoot) {
  24237. this._internalRoot = internalRoot;
  24238. }
  24239. ReactDOMHydrationRoot.prototype.render = ReactDOMRoot.prototype.render = function (children) {
  24240. var root = this._internalRoot;
  24241. if (root === null) {
  24242. throw new Error('Cannot update an unmounted root.');
  24243. }
  24244. {
  24245. if (typeof arguments[1] === 'function') {
  24246. error('render(...): does not support the second callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().');
  24247. } else if (isValidContainer(arguments[1])) {
  24248. error('You passed a container to the second argument of root.render(...). ' + "You don't need to pass it again since you already passed it to create the root.");
  24249. } else if (typeof arguments[1] !== 'undefined') {
  24250. error('You passed a second argument to root.render(...) but it only accepts ' + 'one argument.');
  24251. }
  24252. var container = root.containerInfo;
  24253. if (container.nodeType !== COMMENT_NODE) {
  24254. var hostInstance = findHostInstanceWithNoPortals(root.current);
  24255. if (hostInstance) {
  24256. if (hostInstance.parentNode !== container) {
  24257. error('render(...): It looks like the React-rendered content of the ' + 'root container was removed without using React. This is not ' + 'supported and will cause errors. Instead, call ' + "root.unmount() to empty a root's container.");
  24258. }
  24259. }
  24260. }
  24261. }
  24262. updateContainer(children, root, null, null);
  24263. };
  24264. ReactDOMHydrationRoot.prototype.unmount = ReactDOMRoot.prototype.unmount = function () {
  24265. {
  24266. if (typeof arguments[0] === 'function') {
  24267. error('unmount(...): does not support a callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().');
  24268. }
  24269. }
  24270. var root = this._internalRoot;
  24271. if (root !== null) {
  24272. this._internalRoot = null;
  24273. var container = root.containerInfo;
  24274. {
  24275. if (isAlreadyRendering()) {
  24276. error('Attempted to synchronously unmount a root while React was already ' + 'rendering. React cannot finish unmounting the root until the ' + 'current render has completed, which may lead to a race condition.');
  24277. }
  24278. }
  24279. flushSync(function () {
  24280. updateContainer(null, root, null, null);
  24281. });
  24282. unmarkContainerAsRoot(container);
  24283. }
  24284. };
  24285. function createRoot(container, options) {
  24286. if (!isValidContainer(container)) {
  24287. throw new Error('createRoot(...): Target container is not a DOM element.');
  24288. }
  24289. warnIfReactDOMContainerInDEV(container);
  24290. var isStrictMode = false;
  24291. var concurrentUpdatesByDefaultOverride = false;
  24292. var identifierPrefix = '';
  24293. var onRecoverableError = defaultOnRecoverableError;
  24294. var transitionCallbacks = null;
  24295. if (options !== null && options !== undefined) {
  24296. {
  24297. if (options.hydrate) {
  24298. warn('hydrate through createRoot is deprecated. Use ReactDOMClient.hydrateRoot(container, <App />) instead.');
  24299. } else {
  24300. if (typeof options === 'object' && options !== null && options.$$typeof === REACT_ELEMENT_TYPE) {
  24301. error('You passed a JSX element to createRoot. You probably meant to ' + 'call root.render instead. ' + 'Example usage:\n\n' + ' let root = createRoot(domContainer);\n' + ' root.render(<App />);');
  24302. }
  24303. }
  24304. }
  24305. if (options.unstable_strictMode === true) {
  24306. isStrictMode = true;
  24307. }
  24308. if (options.identifierPrefix !== undefined) {
  24309. identifierPrefix = options.identifierPrefix;
  24310. }
  24311. if (options.onRecoverableError !== undefined) {
  24312. onRecoverableError = options.onRecoverableError;
  24313. }
  24314. if (options.transitionCallbacks !== undefined) {
  24315. transitionCallbacks = options.transitionCallbacks;
  24316. }
  24317. }
  24318. var root = createContainer(container, ConcurrentRoot, null, isStrictMode, concurrentUpdatesByDefaultOverride, identifierPrefix, onRecoverableError);
  24319. markContainerAsRoot(root.current, container);
  24320. var rootContainerElement = container.nodeType === COMMENT_NODE ? container.parentNode : container;
  24321. listenToAllSupportedEvents(rootContainerElement);
  24322. return new ReactDOMRoot(root);
  24323. }
  24324. function ReactDOMHydrationRoot(internalRoot) {
  24325. this._internalRoot = internalRoot;
  24326. }
  24327. function scheduleHydration(target) {
  24328. if (target) {
  24329. queueExplicitHydrationTarget(target);
  24330. }
  24331. }
  24332. ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = scheduleHydration;
  24333. function hydrateRoot(container, initialChildren, options) {
  24334. if (!isValidContainer(container)) {
  24335. throw new Error('hydrateRoot(...): Target container is not a DOM element.');
  24336. }
  24337. warnIfReactDOMContainerInDEV(container);
  24338. {
  24339. if (initialChildren === undefined) {
  24340. error('Must provide initial children as second argument to hydrateRoot. ' + 'Example usage: hydrateRoot(domContainer, <App />)');
  24341. }
  24342. } // For now we reuse the whole bag of options since they contain
  24343. // the hydration callbacks.
  24344. var hydrationCallbacks = options != null ? options : null; // TODO: Delete this option
  24345. var mutableSources = options != null && options.hydratedSources || null;
  24346. var isStrictMode = false;
  24347. var concurrentUpdatesByDefaultOverride = false;
  24348. var identifierPrefix = '';
  24349. var onRecoverableError = defaultOnRecoverableError;
  24350. if (options !== null && options !== undefined) {
  24351. if (options.unstable_strictMode === true) {
  24352. isStrictMode = true;
  24353. }
  24354. if (options.identifierPrefix !== undefined) {
  24355. identifierPrefix = options.identifierPrefix;
  24356. }
  24357. if (options.onRecoverableError !== undefined) {
  24358. onRecoverableError = options.onRecoverableError;
  24359. }
  24360. }
  24361. var root = createHydrationContainer(initialChildren, null, container, ConcurrentRoot, hydrationCallbacks, isStrictMode, concurrentUpdatesByDefaultOverride, identifierPrefix, onRecoverableError);
  24362. markContainerAsRoot(root.current, container); // This can't be a comment node since hydration doesn't work on comment nodes anyway.
  24363. listenToAllSupportedEvents(container);
  24364. if (mutableSources) {
  24365. for (var i = 0; i < mutableSources.length; i++) {
  24366. var mutableSource = mutableSources[i];
  24367. registerMutableSourceForHydration(root, mutableSource);
  24368. }
  24369. }
  24370. return new ReactDOMHydrationRoot(root);
  24371. }
  24372. function isValidContainer(node) {
  24373. return !!(node && (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE || !disableCommentsAsDOMContainers ));
  24374. } // TODO: Remove this function which also includes comment nodes.
  24375. // We only use it in places that are currently more relaxed.
  24376. function isValidContainerLegacy(node) {
  24377. return !!(node && (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE || node.nodeType === COMMENT_NODE && node.nodeValue === ' react-mount-point-unstable '));
  24378. }
  24379. function warnIfReactDOMContainerInDEV(container) {
  24380. {
  24381. if (container.nodeType === ELEMENT_NODE && container.tagName && container.tagName.toUpperCase() === 'BODY') {
  24382. error('createRoot(): Creating roots directly with document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + 'reconciliation issues. Try using a container element created ' + 'for your app.');
  24383. }
  24384. if (isContainerMarkedAsRoot(container)) {
  24385. if (container._reactRootContainer) {
  24386. error('You are calling ReactDOMClient.createRoot() on a container that was previously ' + 'passed to ReactDOM.render(). This is not supported.');
  24387. } else {
  24388. error('You are calling ReactDOMClient.createRoot() on a container that ' + 'has already been passed to createRoot() before. Instead, call ' + 'root.render() on the existing root instead if you want to update it.');
  24389. }
  24390. }
  24391. }
  24392. }
  24393. var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
  24394. var topLevelUpdateWarnings;
  24395. {
  24396. topLevelUpdateWarnings = function (container) {
  24397. if (container._reactRootContainer && container.nodeType !== COMMENT_NODE) {
  24398. var hostInstance = findHostInstanceWithNoPortals(container._reactRootContainer.current);
  24399. if (hostInstance) {
  24400. if (hostInstance.parentNode !== container) {
  24401. error('render(...): It looks like the React-rendered content of this ' + 'container was removed without using React. This is not ' + 'supported and will cause errors. Instead, call ' + 'ReactDOM.unmountComponentAtNode to empty a container.');
  24402. }
  24403. }
  24404. }
  24405. var isRootRenderedBySomeReact = !!container._reactRootContainer;
  24406. var rootEl = getReactRootElementInContainer(container);
  24407. var hasNonRootReactChild = !!(rootEl && getInstanceFromNode(rootEl));
  24408. if (hasNonRootReactChild && !isRootRenderedBySomeReact) {
  24409. error('render(...): Replacing React-rendered children with a new root ' + 'component. If you intended to update the children of this node, ' + 'you should instead have the existing children update their state ' + 'and render the new components instead of calling ReactDOM.render.');
  24410. }
  24411. if (container.nodeType === ELEMENT_NODE && container.tagName && container.tagName.toUpperCase() === 'BODY') {
  24412. error('render(): Rendering components directly into document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + 'reconciliation issues. Try rendering into a container element created ' + 'for your app.');
  24413. }
  24414. };
  24415. }
  24416. function getReactRootElementInContainer(container) {
  24417. if (!container) {
  24418. return null;
  24419. }
  24420. if (container.nodeType === DOCUMENT_NODE) {
  24421. return container.documentElement;
  24422. } else {
  24423. return container.firstChild;
  24424. }
  24425. }
  24426. function noopOnRecoverableError() {// This isn't reachable because onRecoverableError isn't called in the
  24427. // legacy API.
  24428. }
  24429. function legacyCreateRootFromDOMContainer(container, initialChildren, parentComponent, callback, isHydrationContainer) {
  24430. if (isHydrationContainer) {
  24431. if (typeof callback === 'function') {
  24432. var originalCallback = callback;
  24433. callback = function () {
  24434. var instance = getPublicRootInstance(root);
  24435. originalCallback.call(instance);
  24436. };
  24437. }
  24438. var root = createHydrationContainer(initialChildren, callback, container, LegacyRoot, null, // hydrationCallbacks
  24439. false, // isStrictMode
  24440. false, // concurrentUpdatesByDefaultOverride,
  24441. '', // identifierPrefix
  24442. noopOnRecoverableError);
  24443. container._reactRootContainer = root;
  24444. markContainerAsRoot(root.current, container);
  24445. var rootContainerElement = container.nodeType === COMMENT_NODE ? container.parentNode : container;
  24446. listenToAllSupportedEvents(rootContainerElement);
  24447. flushSync();
  24448. return root;
  24449. } else {
  24450. // First clear any existing content.
  24451. var rootSibling;
  24452. while (rootSibling = container.lastChild) {
  24453. container.removeChild(rootSibling);
  24454. }
  24455. if (typeof callback === 'function') {
  24456. var _originalCallback = callback;
  24457. callback = function () {
  24458. var instance = getPublicRootInstance(_root);
  24459. _originalCallback.call(instance);
  24460. };
  24461. }
  24462. var _root = createContainer(container, LegacyRoot, null, // hydrationCallbacks
  24463. false, // isStrictMode
  24464. false, // concurrentUpdatesByDefaultOverride,
  24465. '', // identifierPrefix
  24466. noopOnRecoverableError);
  24467. container._reactRootContainer = _root;
  24468. markContainerAsRoot(_root.current, container);
  24469. var _rootContainerElement = container.nodeType === COMMENT_NODE ? container.parentNode : container;
  24470. listenToAllSupportedEvents(_rootContainerElement); // Initial mount should not be batched.
  24471. flushSync(function () {
  24472. updateContainer(initialChildren, _root, parentComponent, callback);
  24473. });
  24474. return _root;
  24475. }
  24476. }
  24477. function warnOnInvalidCallback$1(callback, callerName) {
  24478. {
  24479. if (callback !== null && typeof callback !== 'function') {
  24480. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  24481. }
  24482. }
  24483. }
  24484. function legacyRenderSubtreeIntoContainer(parentComponent, children, container, forceHydrate, callback) {
  24485. {
  24486. topLevelUpdateWarnings(container);
  24487. warnOnInvalidCallback$1(callback === undefined ? null : callback, 'render');
  24488. }
  24489. var maybeRoot = container._reactRootContainer;
  24490. var root;
  24491. if (!maybeRoot) {
  24492. // Initial mount
  24493. root = legacyCreateRootFromDOMContainer(container, children, parentComponent, callback, forceHydrate);
  24494. } else {
  24495. root = maybeRoot;
  24496. if (typeof callback === 'function') {
  24497. var originalCallback = callback;
  24498. callback = function () {
  24499. var instance = getPublicRootInstance(root);
  24500. originalCallback.call(instance);
  24501. };
  24502. } // Update
  24503. updateContainer(children, root, parentComponent, callback);
  24504. }
  24505. return getPublicRootInstance(root);
  24506. }
  24507. function findDOMNode(componentOrElement) {
  24508. {
  24509. var owner = ReactCurrentOwner$3.current;
  24510. if (owner !== null && owner.stateNode !== null) {
  24511. var warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;
  24512. if (!warnedAboutRefsInRender) {
  24513. error('%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentNameFromType(owner.type) || 'A component');
  24514. }
  24515. owner.stateNode._warnedAboutRefsInRender = true;
  24516. }
  24517. }
  24518. if (componentOrElement == null) {
  24519. return null;
  24520. }
  24521. if (componentOrElement.nodeType === ELEMENT_NODE) {
  24522. return componentOrElement;
  24523. }
  24524. {
  24525. return findHostInstanceWithWarning(componentOrElement, 'findDOMNode');
  24526. }
  24527. }
  24528. function hydrate(element, container, callback) {
  24529. {
  24530. error('ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot ' + 'instead. Until you switch to the new API, your app will behave as ' + "if it's running React 17. Learn " + 'more: https://reactjs.org/link/switch-to-createroot');
  24531. }
  24532. if (!isValidContainerLegacy(container)) {
  24533. throw new Error('Target container is not a DOM element.');
  24534. }
  24535. {
  24536. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  24537. if (isModernRoot) {
  24538. error('You are calling ReactDOM.hydrate() on a container that was previously ' + 'passed to ReactDOMClient.createRoot(). This is not supported. ' + 'Did you mean to call hydrateRoot(container, element)?');
  24539. }
  24540. } // TODO: throw or warn if we couldn't hydrate?
  24541. return legacyRenderSubtreeIntoContainer(null, element, container, true, callback);
  24542. }
  24543. function render(element, container, callback) {
  24544. {
  24545. error('ReactDOM.render is no longer supported in React 18. Use createRoot ' + 'instead. Until you switch to the new API, your app will behave as ' + "if it's running React 17. Learn " + 'more: https://reactjs.org/link/switch-to-createroot');
  24546. }
  24547. if (!isValidContainerLegacy(container)) {
  24548. throw new Error('Target container is not a DOM element.');
  24549. }
  24550. {
  24551. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  24552. if (isModernRoot) {
  24553. error('You are calling ReactDOM.render() on a container that was previously ' + 'passed to ReactDOMClient.createRoot(). This is not supported. ' + 'Did you mean to call root.render(element)?');
  24554. }
  24555. }
  24556. return legacyRenderSubtreeIntoContainer(null, element, container, false, callback);
  24557. }
  24558. function unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
  24559. {
  24560. error('ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported ' + 'in React 18. Consider using a portal instead. Until you switch to ' + "the createRoot API, your app will behave as if it's running React " + '17. Learn more: https://reactjs.org/link/switch-to-createroot');
  24561. }
  24562. if (!isValidContainerLegacy(containerNode)) {
  24563. throw new Error('Target container is not a DOM element.');
  24564. }
  24565. if (parentComponent == null || !has(parentComponent)) {
  24566. throw new Error('parentComponent must be a valid React Component');
  24567. }
  24568. return legacyRenderSubtreeIntoContainer(parentComponent, element, containerNode, false, callback);
  24569. }
  24570. function unmountComponentAtNode(container) {
  24571. if (!isValidContainerLegacy(container)) {
  24572. throw new Error('unmountComponentAtNode(...): Target container is not a DOM element.');
  24573. }
  24574. {
  24575. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  24576. if (isModernRoot) {
  24577. error('You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' + 'passed to ReactDOMClient.createRoot(). This is not supported. Did you mean to call root.unmount()?');
  24578. }
  24579. }
  24580. if (container._reactRootContainer) {
  24581. {
  24582. var rootEl = getReactRootElementInContainer(container);
  24583. var renderedByDifferentReact = rootEl && !getInstanceFromNode(rootEl);
  24584. if (renderedByDifferentReact) {
  24585. error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by another copy of React.');
  24586. }
  24587. } // Unmount should not be batched.
  24588. flushSync(function () {
  24589. legacyRenderSubtreeIntoContainer(null, null, container, false, function () {
  24590. // $FlowFixMe This should probably use `delete container._reactRootContainer`
  24591. container._reactRootContainer = null;
  24592. unmarkContainerAsRoot(container);
  24593. });
  24594. }); // If you call unmountComponentAtNode twice in quick succession, you'll
  24595. // get `true` twice. That's probably fine?
  24596. return true;
  24597. } else {
  24598. {
  24599. var _rootEl = getReactRootElementInContainer(container);
  24600. var hasNonRootReactChild = !!(_rootEl && getInstanceFromNode(_rootEl)); // Check if the container itself is a React root node.
  24601. var isContainerReactRoot = container.nodeType === ELEMENT_NODE && isValidContainerLegacy(container.parentNode) && !!container.parentNode._reactRootContainer;
  24602. if (hasNonRootReactChild) {
  24603. error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot ? 'You may have accidentally passed in a React root node instead ' + 'of its container.' : 'Instead, have the parent component update its state and ' + 'rerender in order to remove this component.');
  24604. }
  24605. }
  24606. return false;
  24607. }
  24608. }
  24609. setAttemptSynchronousHydration(attemptSynchronousHydration$1);
  24610. setAttemptContinuousHydration(attemptContinuousHydration$1);
  24611. setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority$1);
  24612. setGetCurrentUpdatePriority(getCurrentUpdatePriority);
  24613. setAttemptHydrationAtPriority(runWithPriority);
  24614. {
  24615. if (typeof Map !== 'function' || // $FlowIssue Flow incorrectly thinks Map has no prototype
  24616. Map.prototype == null || typeof Map.prototype.forEach !== 'function' || typeof Set !== 'function' || // $FlowIssue Flow incorrectly thinks Set has no prototype
  24617. Set.prototype == null || typeof Set.prototype.clear !== 'function' || typeof Set.prototype.forEach !== 'function') {
  24618. error('React depends on Map and Set built-in types. Make sure that you load a ' + 'polyfill in older browsers. https://reactjs.org/link/react-polyfills');
  24619. }
  24620. }
  24621. setRestoreImplementation(restoreControlledState$3);
  24622. setBatchingImplementation(batchedUpdates$1, discreteUpdates, flushSync);
  24623. function createPortal$1(children, container) {
  24624. var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  24625. if (!isValidContainer(container)) {
  24626. throw new Error('Target container is not a DOM element.');
  24627. } // TODO: pass ReactDOM portal implementation as third argument
  24628. // $FlowFixMe The Flow type is opaque but there's no way to actually create it.
  24629. return createPortal(children, container, null, key);
  24630. }
  24631. function renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
  24632. return unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback);
  24633. }
  24634. var Internals = {
  24635. usingClientEntryPoint: false,
  24636. // Keep in sync with ReactTestUtils.js.
  24637. // This is an array for better minification.
  24638. Events: [getInstanceFromNode, getNodeFromInstance, getFiberCurrentPropsFromNode, enqueueStateRestore, restoreStateIfNeeded, batchedUpdates$1]
  24639. };
  24640. function createRoot$1(container, options) {
  24641. {
  24642. if (!Internals.usingClientEntryPoint && !false) {
  24643. error('You are importing createRoot from "react-dom" which is not supported. ' + 'You should instead import it from "react-dom/client".');
  24644. }
  24645. }
  24646. return createRoot(container, options);
  24647. }
  24648. function hydrateRoot$1(container, initialChildren, options) {
  24649. {
  24650. if (!Internals.usingClientEntryPoint && !false) {
  24651. error('You are importing hydrateRoot from "react-dom" which is not supported. ' + 'You should instead import it from "react-dom/client".');
  24652. }
  24653. }
  24654. return hydrateRoot(container, initialChildren, options);
  24655. } // Overload the definition to the two valid signatures.
  24656. // Warning, this opts-out of checking the function body.
  24657. // eslint-disable-next-line no-redeclare
  24658. function flushSync$1(fn) {
  24659. {
  24660. if (isAlreadyRendering()) {
  24661. error('flushSync was called from inside a lifecycle method. React cannot ' + 'flush when React is already rendering. Consider moving this call to ' + 'a scheduler task or micro task.');
  24662. }
  24663. }
  24664. return flushSync(fn);
  24665. }
  24666. var foundDevTools = injectIntoDevTools({
  24667. findFiberByHostInstance: getClosestInstanceFromNode,
  24668. bundleType: 1 ,
  24669. version: ReactVersion,
  24670. rendererPackageName: 'react-dom'
  24671. });
  24672. {
  24673. if (!foundDevTools && canUseDOM && window.top === window.self) {
  24674. // If we're in Chrome or Firefox, provide a download link if not installed.
  24675. if (navigator.userAgent.indexOf('Chrome') > -1 && navigator.userAgent.indexOf('Edge') === -1 || navigator.userAgent.indexOf('Firefox') > -1) {
  24676. var protocol = window.location.protocol; // Don't warn in exotic cases like chrome-extension://.
  24677. if (/^(https?|file):$/.test(protocol)) {
  24678. // eslint-disable-next-line react-internal/no-production-logging
  24679. console.info('%cDownload the React DevTools ' + 'for a better development experience: ' + 'https://reactjs.org/link/react-devtools' + (protocol === 'file:' ? '\nYou might need to use a local HTTP server (instead of file://): ' + 'https://reactjs.org/link/react-devtools-faq' : ''), 'font-weight:bold');
  24680. }
  24681. }
  24682. }
  24683. }
  24684. exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = Internals;
  24685. exports.createPortal = createPortal$1;
  24686. exports.createRoot = createRoot$1;
  24687. exports.findDOMNode = findDOMNode;
  24688. exports.flushSync = flushSync$1;
  24689. exports.hydrate = hydrate;
  24690. exports.hydrateRoot = hydrateRoot$1;
  24691. exports.render = render;
  24692. exports.unmountComponentAtNode = unmountComponentAtNode;
  24693. exports.unstable_batchedUpdates = batchedUpdates$1;
  24694. exports.unstable_renderSubtreeIntoContainer = renderSubtreeIntoContainer;
  24695. exports.version = ReactVersion;
  24696. /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  24697. if (
  24698. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
  24699. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
  24700. 'function'
  24701. ) {
  24702. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
  24703. }
  24704. })();
  24705. }