ReactNativeRenderer-dev.fb.js 642 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @noflow
  8. * @nolint
  9. * @preventMunge
  10. * @generated
  11. */
  12. 'use strict';
  13. if (__DEV__) {
  14. (function() {
  15. "use strict";
  16. var React = require("react");
  17. require("react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore");
  18. var ReactNativePrivateInterface = require("react-native/Libraries/ReactPrivate/ReactNativePrivateInterface");
  19. var Scheduler = require("scheduler");
  20. var tracing = require("scheduler/tracing");
  21. var ReactSharedInternals =
  22. React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
  23. // Current owner and dispatcher used to share the same ref,
  24. // but PR #14548 split them out to better support the react-debug-tools package.
  25. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher")) {
  26. ReactSharedInternals.ReactCurrentDispatcher = {
  27. current: null
  28. };
  29. }
  30. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentBatchConfig")) {
  31. ReactSharedInternals.ReactCurrentBatchConfig = {
  32. suspense: null
  33. };
  34. }
  35. // by calls to these methods by a Babel plugin.
  36. //
  37. // In PROD (or in packages without access to React internals),
  38. // they are left as they are instead.
  39. function warn(format) {
  40. {
  41. for (
  42. var _len = arguments.length,
  43. args = new Array(_len > 1 ? _len - 1 : 0),
  44. _key = 1;
  45. _key < _len;
  46. _key++
  47. ) {
  48. args[_key - 1] = arguments[_key];
  49. }
  50. printWarning("warn", format, args);
  51. }
  52. }
  53. function error(format) {
  54. {
  55. for (
  56. var _len2 = arguments.length,
  57. args = new Array(_len2 > 1 ? _len2 - 1 : 0),
  58. _key2 = 1;
  59. _key2 < _len2;
  60. _key2++
  61. ) {
  62. args[_key2 - 1] = arguments[_key2];
  63. }
  64. printWarning("error", format, args);
  65. }
  66. }
  67. function printWarning(level, format, args) {
  68. // When changing this logic, you might want to also
  69. // update consoleWithStackDev.www.js as well.
  70. {
  71. var hasExistingStack =
  72. args.length > 0 &&
  73. typeof args[args.length - 1] === "string" &&
  74. args[args.length - 1].indexOf("\n in") === 0;
  75. if (!hasExistingStack) {
  76. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  77. var stack = ReactDebugCurrentFrame.getStackAddendum();
  78. if (stack !== "") {
  79. format += "%s";
  80. args = args.concat([stack]);
  81. }
  82. }
  83. var argsWithFormat = args.map(function(item) {
  84. return "" + item;
  85. }); // Careful: RN currently depends on this prefix
  86. argsWithFormat.unshift("Warning: " + format); // We intentionally don't use spread (or .apply) directly because it
  87. // breaks IE9: https://github.com/facebook/react/issues/13610
  88. // eslint-disable-next-line react-internal/no-production-logging
  89. Function.prototype.apply.call(console[level], console, argsWithFormat);
  90. try {
  91. // --- Welcome to debugging React ---
  92. // This error was thrown as a convenience so that you can use this stack
  93. // to find the callsite that caused this warning to fire.
  94. var argIndex = 0;
  95. var message =
  96. "Warning: " +
  97. format.replace(/%s/g, function() {
  98. return args[argIndex++];
  99. });
  100. throw new Error(message);
  101. } catch (x) {}
  102. }
  103. }
  104. var FunctionComponent = 0;
  105. var ClassComponent = 1;
  106. var IndeterminateComponent = 2; // Before we know whether it is function or class
  107. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  108. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  109. var HostComponent = 5;
  110. var HostText = 6;
  111. var Fragment = 7;
  112. var Mode = 8;
  113. var ContextConsumer = 9;
  114. var ContextProvider = 10;
  115. var ForwardRef = 11;
  116. var Profiler = 12;
  117. var SuspenseComponent = 13;
  118. var MemoComponent = 14;
  119. var SimpleMemoComponent = 15;
  120. var LazyComponent = 16;
  121. var IncompleteClassComponent = 17;
  122. var DehydratedFragment = 18;
  123. var SuspenseListComponent = 19;
  124. var FundamentalComponent = 20;
  125. var ScopeComponent = 21;
  126. var Block = 22;
  127. function getParent(inst) {
  128. do {
  129. inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
  130. // That is depending on if we want nested subtrees (layers) to bubble
  131. // events to their parent. We could also go through parentNode on the
  132. // host node but that wouldn't work for React Native and doesn't let us
  133. // do the portal feature.
  134. } while (inst && inst.tag !== HostComponent);
  135. if (inst) {
  136. return inst;
  137. }
  138. return null;
  139. }
  140. /**
  141. * Return the lowest common ancestor of A and B, or null if they are in
  142. * different trees.
  143. */
  144. function getLowestCommonAncestor(instA, instB) {
  145. var depthA = 0;
  146. for (var tempA = instA; tempA; tempA = getParent(tempA)) {
  147. depthA++;
  148. }
  149. var depthB = 0;
  150. for (var tempB = instB; tempB; tempB = getParent(tempB)) {
  151. depthB++;
  152. } // If A is deeper, crawl up.
  153. while (depthA - depthB > 0) {
  154. instA = getParent(instA);
  155. depthA--;
  156. } // If B is deeper, crawl up.
  157. while (depthB - depthA > 0) {
  158. instB = getParent(instB);
  159. depthB--;
  160. } // Walk in lockstep until we find a match.
  161. var depth = depthA;
  162. while (depth--) {
  163. if (instA === instB || instA === instB.alternate) {
  164. return instA;
  165. }
  166. instA = getParent(instA);
  167. instB = getParent(instB);
  168. }
  169. return null;
  170. }
  171. /**
  172. * Return if A is an ancestor of B.
  173. */
  174. function isAncestor(instA, instB) {
  175. while (instB) {
  176. if (instA === instB || instA === instB.alternate) {
  177. return true;
  178. }
  179. instB = getParent(instB);
  180. }
  181. return false;
  182. }
  183. /**
  184. * Return the parent instance of the passed-in instance.
  185. */
  186. function getParentInstance(inst) {
  187. return getParent(inst);
  188. }
  189. /**
  190. * Simulates the traversal of a two-phase, capture/bubble event dispatch.
  191. */
  192. function traverseTwoPhase(inst, fn, arg) {
  193. var path = [];
  194. while (inst) {
  195. path.push(inst);
  196. inst = getParent(inst);
  197. }
  198. var i;
  199. for (i = path.length; i-- > 0; ) {
  200. fn(path[i], "captured", arg);
  201. }
  202. for (i = 0; i < path.length; i++) {
  203. fn(path[i], "bubbled", arg);
  204. }
  205. }
  206. var invokeGuardedCallbackImpl = function(
  207. name,
  208. func,
  209. context,
  210. a,
  211. b,
  212. c,
  213. d,
  214. e,
  215. f
  216. ) {
  217. var funcArgs = Array.prototype.slice.call(arguments, 3);
  218. try {
  219. func.apply(context, funcArgs);
  220. } catch (error) {
  221. this.onError(error);
  222. }
  223. };
  224. {
  225. // In DEV mode, we swap out invokeGuardedCallback for a special version
  226. // that plays more nicely with the browser's DevTools. The idea is to preserve
  227. // "Pause on exceptions" behavior. Because React wraps all user-provided
  228. // functions in invokeGuardedCallback, and the production version of
  229. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  230. // like caught exceptions, and the DevTools won't pause unless the developer
  231. // takes the extra step of enabling pause on caught exceptions. This is
  232. // unintuitive, though, because even though React has caught the error, from
  233. // the developer's perspective, the error is uncaught.
  234. //
  235. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  236. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  237. // DOM node, and call the user-provided callback from inside an event handler
  238. // for that fake event. If the callback throws, the error is "captured" using
  239. // a global event handler. But because the error happens in a different
  240. // event loop context, it does not interrupt the normal program flow.
  241. // Effectively, this gives us try-catch behavior without actually using
  242. // try-catch. Neat!
  243. // Check that the browser supports the APIs we need to implement our special
  244. // DEV version of invokeGuardedCallback
  245. if (
  246. typeof window !== "undefined" &&
  247. typeof window.dispatchEvent === "function" &&
  248. typeof document !== "undefined" &&
  249. typeof document.createEvent === "function"
  250. ) {
  251. var fakeNode = document.createElement("react");
  252. var invokeGuardedCallbackDev = function(
  253. name,
  254. func,
  255. context,
  256. a,
  257. b,
  258. c,
  259. d,
  260. e,
  261. f
  262. ) {
  263. // If document doesn't exist we know for sure we will crash in this method
  264. // when we call document.createEvent(). However this can cause confusing
  265. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  266. // So we preemptively throw with a better message instead.
  267. if (!(typeof document !== "undefined")) {
  268. throw Error(
  269. "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."
  270. );
  271. }
  272. var evt = document.createEvent("Event"); // Keeps track of whether the user-provided callback threw an error. We
  273. // set this to true at the beginning, then set it to false right after
  274. // calling the function. If the function errors, `didError` will never be
  275. // set to false. This strategy works even if the browser is flaky and
  276. // fails to call our global error handler, because it doesn't rely on
  277. // the error event at all.
  278. var didError = true; // Keeps track of the value of window.event so that we can reset it
  279. // during the callback to let user code access window.event in the
  280. // browsers that support it.
  281. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  282. // dispatching: https://github.com/facebook/react/issues/13688
  283. var windowEventDescriptor = Object.getOwnPropertyDescriptor(
  284. window,
  285. "event"
  286. ); // Create an event handler for our fake event. We will synchronously
  287. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  288. // call the user-provided callback.
  289. var funcArgs = Array.prototype.slice.call(arguments, 3);
  290. function callCallback() {
  291. // We immediately remove the callback from event listeners so that
  292. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  293. // nested call would trigger the fake event handlers of any call higher
  294. // in the stack.
  295. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  296. // window.event assignment in both IE <= 10 as they throw an error
  297. // "Member not found" in strict mode, and in Firefox which does not
  298. // support window.event.
  299. if (
  300. typeof window.event !== "undefined" &&
  301. window.hasOwnProperty("event")
  302. ) {
  303. window.event = windowEvent;
  304. }
  305. func.apply(context, funcArgs);
  306. didError = false;
  307. } // Create a global error event handler. We use this to capture the value
  308. // that was thrown. It's possible that this error handler will fire more
  309. // than once; for example, if non-React code also calls `dispatchEvent`
  310. // and a handler for that event throws. We should be resilient to most of
  311. // those cases. Even if our error event handler fires more than once, the
  312. // last error event is always used. If the callback actually does error,
  313. // we know that the last error event is the correct one, because it's not
  314. // possible for anything else to have happened in between our callback
  315. // erroring and the code that follows the `dispatchEvent` call below. If
  316. // the callback doesn't error, but the error event was fired, we know to
  317. // ignore it because `didError` will be false, as described above.
  318. var error; // Use this to track whether the error event is ever called.
  319. var didSetError = false;
  320. var isCrossOriginError = false;
  321. function handleWindowError(event) {
  322. error = event.error;
  323. didSetError = true;
  324. if (error === null && event.colno === 0 && event.lineno === 0) {
  325. isCrossOriginError = true;
  326. }
  327. if (event.defaultPrevented) {
  328. // Some other error handler has prevented default.
  329. // Browsers silence the error report if this happens.
  330. // We'll remember this to later decide whether to log it or not.
  331. if (error != null && typeof error === "object") {
  332. try {
  333. error._suppressLogging = true;
  334. } catch (inner) {
  335. // Ignore.
  336. }
  337. }
  338. }
  339. } // Create a fake event type.
  340. var evtType = "react-" + (name ? name : "invokeguardedcallback"); // Attach our event handlers
  341. window.addEventListener("error", handleWindowError);
  342. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  343. // errors, it will trigger our global error handler.
  344. evt.initEvent(evtType, false, false);
  345. fakeNode.dispatchEvent(evt);
  346. if (windowEventDescriptor) {
  347. Object.defineProperty(window, "event", windowEventDescriptor);
  348. }
  349. if (didError) {
  350. if (!didSetError) {
  351. // The callback errored, but the error event never fired.
  352. error = new Error(
  353. "An error was thrown inside one of your components, but React " +
  354. "doesn't know what it was. This is likely due to browser " +
  355. 'flakiness. React does its best to preserve the "Pause on ' +
  356. 'exceptions" behavior of the DevTools, which requires some ' +
  357. "DEV-mode only tricks. It's possible that these don't work in " +
  358. "your browser. Try triggering the error in production mode, " +
  359. "or switching to a modern browser. If you suspect that this is " +
  360. "actually an issue with React, please file an issue."
  361. );
  362. } else if (isCrossOriginError) {
  363. error = new Error(
  364. "A cross-origin error was thrown. React doesn't have access to " +
  365. "the actual error object in development. " +
  366. "See https://fb.me/react-crossorigin-error for more information."
  367. );
  368. }
  369. this.onError(error);
  370. } // Remove our event listeners
  371. window.removeEventListener("error", handleWindowError);
  372. };
  373. invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
  374. }
  375. }
  376. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  377. var hasError = false;
  378. var caughtError = null; // Used by event system to capture/rethrow the first error.
  379. var hasRethrowError = false;
  380. var rethrowError = null;
  381. var reporter = {
  382. onError: function(error) {
  383. hasError = true;
  384. caughtError = error;
  385. }
  386. };
  387. /**
  388. * Call a function while guarding against errors that happens within it.
  389. * Returns an error if it throws, otherwise null.
  390. *
  391. * In production, this is implemented using a try-catch. The reason we don't
  392. * use a try-catch directly is so that we can swap out a different
  393. * implementation in DEV mode.
  394. *
  395. * @param {String} name of the guard to use for logging or debugging
  396. * @param {Function} func The function to invoke
  397. * @param {*} context The context to use when calling the function
  398. * @param {...*} args Arguments for function
  399. */
  400. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  401. hasError = false;
  402. caughtError = null;
  403. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  404. }
  405. /**
  406. * Same as invokeGuardedCallback, but instead of returning an error, it stores
  407. * it in a global so it can be rethrown by `rethrowCaughtError` later.
  408. * TODO: See if caughtError and rethrowError can be unified.
  409. *
  410. * @param {String} name of the guard to use for logging or debugging
  411. * @param {Function} func The function to invoke
  412. * @param {*} context The context to use when calling the function
  413. * @param {...*} args Arguments for function
  414. */
  415. function invokeGuardedCallbackAndCatchFirstError(
  416. name,
  417. func,
  418. context,
  419. a,
  420. b,
  421. c,
  422. d,
  423. e,
  424. f
  425. ) {
  426. invokeGuardedCallback.apply(this, arguments);
  427. if (hasError) {
  428. var error = clearCaughtError();
  429. if (!hasRethrowError) {
  430. hasRethrowError = true;
  431. rethrowError = error;
  432. }
  433. }
  434. }
  435. /**
  436. * During execution of guarded functions we will capture the first error which
  437. * we will rethrow to be handled by the top level error handler.
  438. */
  439. function rethrowCaughtError() {
  440. if (hasRethrowError) {
  441. var error = rethrowError;
  442. hasRethrowError = false;
  443. rethrowError = null;
  444. throw error;
  445. }
  446. }
  447. function hasCaughtError() {
  448. return hasError;
  449. }
  450. function clearCaughtError() {
  451. if (hasError) {
  452. var error = caughtError;
  453. hasError = false;
  454. caughtError = null;
  455. return error;
  456. } else {
  457. {
  458. throw Error(
  459. "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue."
  460. );
  461. }
  462. }
  463. }
  464. var getFiberCurrentPropsFromNode = null;
  465. var getInstanceFromNode = null;
  466. var getNodeFromInstance = null;
  467. function setComponentTree(
  468. getFiberCurrentPropsFromNodeImpl,
  469. getInstanceFromNodeImpl,
  470. getNodeFromInstanceImpl
  471. ) {
  472. getFiberCurrentPropsFromNode = getFiberCurrentPropsFromNodeImpl;
  473. getInstanceFromNode = getInstanceFromNodeImpl;
  474. getNodeFromInstance = getNodeFromInstanceImpl;
  475. {
  476. if (!getNodeFromInstance || !getInstanceFromNode) {
  477. error(
  478. "EventPluginUtils.setComponentTree(...): Injected " +
  479. "module is missing getNodeFromInstance or getInstanceFromNode."
  480. );
  481. }
  482. }
  483. }
  484. var validateEventDispatches;
  485. {
  486. validateEventDispatches = function(event) {
  487. var dispatchListeners = event._dispatchListeners;
  488. var dispatchInstances = event._dispatchInstances;
  489. var listenersIsArr = Array.isArray(dispatchListeners);
  490. var listenersLen = listenersIsArr
  491. ? dispatchListeners.length
  492. : dispatchListeners
  493. ? 1
  494. : 0;
  495. var instancesIsArr = Array.isArray(dispatchInstances);
  496. var instancesLen = instancesIsArr
  497. ? dispatchInstances.length
  498. : dispatchInstances
  499. ? 1
  500. : 0;
  501. if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
  502. error("EventPluginUtils: Invalid `event`.");
  503. }
  504. };
  505. }
  506. /**
  507. * Dispatch the event to the listener.
  508. * @param {SyntheticEvent} event SyntheticEvent to handle
  509. * @param {function} listener Application-level callback
  510. * @param {*} inst Internal component instance
  511. */
  512. function executeDispatch(event, listener, inst) {
  513. var type = event.type || "unknown-event";
  514. event.currentTarget = getNodeFromInstance(inst);
  515. invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
  516. event.currentTarget = null;
  517. }
  518. /**
  519. * Standard/simple iteration through an event's collected dispatches.
  520. */
  521. function executeDispatchesInOrder(event) {
  522. var dispatchListeners = event._dispatchListeners;
  523. var dispatchInstances = event._dispatchInstances;
  524. {
  525. validateEventDispatches(event);
  526. }
  527. if (Array.isArray(dispatchListeners)) {
  528. for (var i = 0; i < dispatchListeners.length; i++) {
  529. if (event.isPropagationStopped()) {
  530. break;
  531. } // Listeners and Instances are two parallel arrays that are always in sync.
  532. executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
  533. }
  534. } else if (dispatchListeners) {
  535. executeDispatch(event, dispatchListeners, dispatchInstances);
  536. }
  537. event._dispatchListeners = null;
  538. event._dispatchInstances = null;
  539. }
  540. /**
  541. * Standard/simple iteration through an event's collected dispatches, but stops
  542. * at the first dispatch execution returning true, and returns that id.
  543. *
  544. * @return {?string} id of the first dispatch execution who's listener returns
  545. * true, or null if no listener returned true.
  546. */
  547. function executeDispatchesInOrderStopAtTrueImpl(event) {
  548. var dispatchListeners = event._dispatchListeners;
  549. var dispatchInstances = event._dispatchInstances;
  550. {
  551. validateEventDispatches(event);
  552. }
  553. if (Array.isArray(dispatchListeners)) {
  554. for (var i = 0; i < dispatchListeners.length; i++) {
  555. if (event.isPropagationStopped()) {
  556. break;
  557. } // Listeners and Instances are two parallel arrays that are always in sync.
  558. if (dispatchListeners[i](event, dispatchInstances[i])) {
  559. return dispatchInstances[i];
  560. }
  561. }
  562. } else if (dispatchListeners) {
  563. if (dispatchListeners(event, dispatchInstances)) {
  564. return dispatchInstances;
  565. }
  566. }
  567. return null;
  568. }
  569. /**
  570. * @see executeDispatchesInOrderStopAtTrueImpl
  571. */
  572. function executeDispatchesInOrderStopAtTrue(event) {
  573. var ret = executeDispatchesInOrderStopAtTrueImpl(event);
  574. event._dispatchInstances = null;
  575. event._dispatchListeners = null;
  576. return ret;
  577. }
  578. /**
  579. * Execution of a "direct" dispatch - there must be at most one dispatch
  580. * accumulated on the event or it is considered an error. It doesn't really make
  581. * sense for an event with multiple dispatches (bubbled) to keep track of the
  582. * return values at each dispatch execution, but it does tend to make sense when
  583. * dealing with "direct" dispatches.
  584. *
  585. * @return {*} The return value of executing the single dispatch.
  586. */
  587. function executeDirectDispatch(event) {
  588. {
  589. validateEventDispatches(event);
  590. }
  591. var dispatchListener = event._dispatchListeners;
  592. var dispatchInstance = event._dispatchInstances;
  593. if (!!Array.isArray(dispatchListener)) {
  594. throw Error("executeDirectDispatch(...): Invalid `event`.");
  595. }
  596. event.currentTarget = dispatchListener
  597. ? getNodeFromInstance(dispatchInstance)
  598. : null;
  599. var res = dispatchListener ? dispatchListener(event) : null;
  600. event.currentTarget = null;
  601. event._dispatchListeners = null;
  602. event._dispatchInstances = null;
  603. return res;
  604. }
  605. /**
  606. * @param {SyntheticEvent} event
  607. * @return {boolean} True iff number of dispatches accumulated is greater than 0.
  608. */
  609. function hasDispatches(event) {
  610. return !!event._dispatchListeners;
  611. }
  612. function isInteractive(tag) {
  613. return (
  614. tag === "button" ||
  615. tag === "input" ||
  616. tag === "select" ||
  617. tag === "textarea"
  618. );
  619. }
  620. function shouldPreventMouseEvent(name, type, props) {
  621. switch (name) {
  622. case "onClick":
  623. case "onClickCapture":
  624. case "onDoubleClick":
  625. case "onDoubleClickCapture":
  626. case "onMouseDown":
  627. case "onMouseDownCapture":
  628. case "onMouseMove":
  629. case "onMouseMoveCapture":
  630. case "onMouseUp":
  631. case "onMouseUpCapture":
  632. case "onMouseEnter":
  633. return !!(props.disabled && isInteractive(type));
  634. default:
  635. return false;
  636. }
  637. }
  638. /**
  639. * @param {object} inst The instance, which is the source of events.
  640. * @param {string} registrationName Name of listener (e.g. `onClick`).
  641. * @return {?function} The stored callback.
  642. */
  643. function getListener(inst, registrationName) {
  644. var listener; // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
  645. // live here; needs to be moved to a better place soon
  646. var stateNode = inst.stateNode;
  647. if (!stateNode) {
  648. // Work in progress (ex: onload events in incremental mode).
  649. return null;
  650. }
  651. var props = getFiberCurrentPropsFromNode(stateNode);
  652. if (!props) {
  653. // Work in progress.
  654. return null;
  655. }
  656. listener = props[registrationName];
  657. if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
  658. return null;
  659. }
  660. if (!(!listener || typeof listener === "function")) {
  661. throw Error(
  662. "Expected `" +
  663. registrationName +
  664. "` listener to be a function, instead got a value of `" +
  665. typeof listener +
  666. "` type."
  667. );
  668. }
  669. return listener;
  670. }
  671. /**
  672. * Accumulates items that must not be null or undefined into the first one. This
  673. * is used to conserve memory by avoiding array allocations, and thus sacrifices
  674. * API cleanness. Since `current` can be null before being passed in and not
  675. * null after this function, make sure to assign it back to `current`:
  676. *
  677. * `a = accumulateInto(a, b);`
  678. *
  679. * This API should be sparingly used. Try `accumulate` for something cleaner.
  680. *
  681. * @return {*|array<*>} An accumulation of items.
  682. */
  683. function accumulateInto(current, next) {
  684. if (!(next != null)) {
  685. throw Error(
  686. "accumulateInto(...): Accumulated items must not be null or undefined."
  687. );
  688. }
  689. if (current == null) {
  690. return next;
  691. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  692. // certain that x is an Array (x could be a string with concat method).
  693. if (Array.isArray(current)) {
  694. if (Array.isArray(next)) {
  695. current.push.apply(current, next);
  696. return current;
  697. }
  698. current.push(next);
  699. return current;
  700. }
  701. if (Array.isArray(next)) {
  702. // A bit too dangerous to mutate `next`.
  703. return [current].concat(next);
  704. }
  705. return [current, next];
  706. }
  707. /**
  708. * @param {array} arr an "accumulation" of items which is either an Array or
  709. * a single item. Useful when paired with the `accumulate` module. This is a
  710. * simple utility that allows us to reason about a collection of items, but
  711. * handling the case when there is exactly one item (and we do not need to
  712. * allocate an array).
  713. * @param {function} cb Callback invoked with each element or a collection.
  714. * @param {?} [scope] Scope used as `this` in a callback.
  715. */
  716. function forEachAccumulated(arr, cb, scope) {
  717. if (Array.isArray(arr)) {
  718. arr.forEach(cb, scope);
  719. } else if (arr) {
  720. cb.call(scope, arr);
  721. }
  722. }
  723. /**
  724. * Some event types have a notion of different registration names for different
  725. * "phases" of propagation. This finds listeners by a given phase.
  726. */
  727. function listenerAtPhase(inst, event, propagationPhase) {
  728. var registrationName =
  729. event.dispatchConfig.phasedRegistrationNames[propagationPhase];
  730. return getListener(inst, registrationName);
  731. }
  732. /**
  733. * A small set of propagation patterns, each of which will accept a small amount
  734. * of information, and generate a set of "dispatch ready event objects" - which
  735. * are sets of events that have already been annotated with a set of dispatched
  736. * listener functions/ids. The API is designed this way to discourage these
  737. * propagation strategies from actually executing the dispatches, since we
  738. * always want to collect the entire set of dispatches before executing even a
  739. * single one.
  740. */
  741. /**
  742. * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
  743. * here, allows us to not have to bind or create functions for each event.
  744. * Mutating the event's members allows us to not have to create a wrapping
  745. * "dispatch" object that pairs the event with the listener.
  746. */
  747. function accumulateDirectionalDispatches(inst, phase, event) {
  748. {
  749. if (!inst) {
  750. error("Dispatching inst must not be null");
  751. }
  752. }
  753. var listener = listenerAtPhase(inst, event, phase);
  754. if (listener) {
  755. event._dispatchListeners = accumulateInto(
  756. event._dispatchListeners,
  757. listener
  758. );
  759. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  760. }
  761. }
  762. /**
  763. * Collect dispatches (must be entirely collected before dispatching - see unit
  764. * tests). Lazily allocate the array to conserve memory. We must loop through
  765. * each event and perform the traversal for each one. We cannot perform a
  766. * single traversal for the entire collection of events because each event may
  767. * have a different target.
  768. */
  769. function accumulateTwoPhaseDispatchesSingle(event) {
  770. if (event && event.dispatchConfig.phasedRegistrationNames) {
  771. traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
  772. }
  773. }
  774. /**
  775. * Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
  776. */
  777. function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
  778. if (event && event.dispatchConfig.phasedRegistrationNames) {
  779. var targetInst = event._targetInst;
  780. var parentInst = targetInst ? getParentInstance(targetInst) : null;
  781. traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
  782. }
  783. }
  784. /**
  785. * Accumulates without regard to direction, does not look for phased
  786. * registration names. Same as `accumulateDirectDispatchesSingle` but without
  787. * requiring that the `dispatchMarker` be the same as the dispatched ID.
  788. */
  789. function accumulateDispatches(inst, ignoredDirection, event) {
  790. if (inst && event && event.dispatchConfig.registrationName) {
  791. var registrationName = event.dispatchConfig.registrationName;
  792. var listener = getListener(inst, registrationName);
  793. if (listener) {
  794. event._dispatchListeners = accumulateInto(
  795. event._dispatchListeners,
  796. listener
  797. );
  798. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  799. }
  800. }
  801. }
  802. /**
  803. * Accumulates dispatches on an `SyntheticEvent`, but only for the
  804. * `dispatchMarker`.
  805. * @param {SyntheticEvent} event
  806. */
  807. function accumulateDirectDispatchesSingle(event) {
  808. if (event && event.dispatchConfig.registrationName) {
  809. accumulateDispatches(event._targetInst, null, event);
  810. }
  811. }
  812. function accumulateTwoPhaseDispatches(events) {
  813. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
  814. }
  815. function accumulateTwoPhaseDispatchesSkipTarget(events) {
  816. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
  817. }
  818. function accumulateDirectDispatches(events) {
  819. forEachAccumulated(events, accumulateDirectDispatchesSingle);
  820. }
  821. var EVENT_POOL_SIZE = 10;
  822. /**
  823. * @interface Event
  824. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  825. */
  826. var EventInterface = {
  827. type: null,
  828. target: null,
  829. // currentTarget is set when dispatching; no use in copying it here
  830. currentTarget: function() {
  831. return null;
  832. },
  833. eventPhase: null,
  834. bubbles: null,
  835. cancelable: null,
  836. timeStamp: function(event) {
  837. return event.timeStamp || Date.now();
  838. },
  839. defaultPrevented: null,
  840. isTrusted: null
  841. };
  842. function functionThatReturnsTrue() {
  843. return true;
  844. }
  845. function functionThatReturnsFalse() {
  846. return false;
  847. }
  848. /**
  849. * Synthetic events are dispatched by event plugins, typically in response to a
  850. * top-level event delegation handler.
  851. *
  852. * These systems should generally use pooling to reduce the frequency of garbage
  853. * collection. The system should check `isPersistent` to determine whether the
  854. * event should be released into the pool after being dispatched. Users that
  855. * need a persisted event should invoke `persist`.
  856. *
  857. * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
  858. * normalizing browser quirks. Subclasses do not necessarily have to implement a
  859. * DOM interface; custom application-specific events can also subclass this.
  860. *
  861. * @param {object} dispatchConfig Configuration used to dispatch this event.
  862. * @param {*} targetInst Marker identifying the event target.
  863. * @param {object} nativeEvent Native browser event.
  864. * @param {DOMEventTarget} nativeEventTarget Target node.
  865. */
  866. function SyntheticEvent(
  867. dispatchConfig,
  868. targetInst,
  869. nativeEvent,
  870. nativeEventTarget
  871. ) {
  872. {
  873. // these have a getter/setter for warnings
  874. delete this.nativeEvent;
  875. delete this.preventDefault;
  876. delete this.stopPropagation;
  877. delete this.isDefaultPrevented;
  878. delete this.isPropagationStopped;
  879. }
  880. this.dispatchConfig = dispatchConfig;
  881. this._targetInst = targetInst;
  882. this.nativeEvent = nativeEvent;
  883. var Interface = this.constructor.Interface;
  884. for (var propName in Interface) {
  885. if (!Interface.hasOwnProperty(propName)) {
  886. continue;
  887. }
  888. {
  889. delete this[propName]; // this has a getter/setter for warnings
  890. }
  891. var normalize = Interface[propName];
  892. if (normalize) {
  893. this[propName] = normalize(nativeEvent);
  894. } else {
  895. if (propName === "target") {
  896. this.target = nativeEventTarget;
  897. } else {
  898. this[propName] = nativeEvent[propName];
  899. }
  900. }
  901. }
  902. var defaultPrevented =
  903. nativeEvent.defaultPrevented != null
  904. ? nativeEvent.defaultPrevented
  905. : nativeEvent.returnValue === false;
  906. if (defaultPrevented) {
  907. this.isDefaultPrevented = functionThatReturnsTrue;
  908. } else {
  909. this.isDefaultPrevented = functionThatReturnsFalse;
  910. }
  911. this.isPropagationStopped = functionThatReturnsFalse;
  912. return this;
  913. }
  914. Object.assign(SyntheticEvent.prototype, {
  915. preventDefault: function() {
  916. this.defaultPrevented = true;
  917. var event = this.nativeEvent;
  918. if (!event) {
  919. return;
  920. }
  921. if (event.preventDefault) {
  922. event.preventDefault();
  923. } else if (typeof event.returnValue !== "unknown") {
  924. event.returnValue = false;
  925. }
  926. this.isDefaultPrevented = functionThatReturnsTrue;
  927. },
  928. stopPropagation: function() {
  929. var event = this.nativeEvent;
  930. if (!event) {
  931. return;
  932. }
  933. if (event.stopPropagation) {
  934. event.stopPropagation();
  935. } else if (typeof event.cancelBubble !== "unknown") {
  936. // The ChangeEventPlugin registers a "propertychange" event for
  937. // IE. This event does not support bubbling or cancelling, and
  938. // any references to cancelBubble throw "Member not found". A
  939. // typeof check of "unknown" circumvents this issue (and is also
  940. // IE specific).
  941. event.cancelBubble = true;
  942. }
  943. this.isPropagationStopped = functionThatReturnsTrue;
  944. },
  945. /**
  946. * We release all dispatched `SyntheticEvent`s after each event loop, adding
  947. * them back into the pool. This allows a way to hold onto a reference that
  948. * won't be added back into the pool.
  949. */
  950. persist: function() {
  951. this.isPersistent = functionThatReturnsTrue;
  952. },
  953. /**
  954. * Checks if this event should be released back into the pool.
  955. *
  956. * @return {boolean} True if this should not be released, false otherwise.
  957. */
  958. isPersistent: functionThatReturnsFalse,
  959. /**
  960. * `PooledClass` looks for `destructor` on each instance it releases.
  961. */
  962. destructor: function() {
  963. var Interface = this.constructor.Interface;
  964. for (var propName in Interface) {
  965. {
  966. Object.defineProperty(
  967. this,
  968. propName,
  969. getPooledWarningPropertyDefinition(propName, Interface[propName])
  970. );
  971. }
  972. }
  973. this.dispatchConfig = null;
  974. this._targetInst = null;
  975. this.nativeEvent = null;
  976. this.isDefaultPrevented = functionThatReturnsFalse;
  977. this.isPropagationStopped = functionThatReturnsFalse;
  978. this._dispatchListeners = null;
  979. this._dispatchInstances = null;
  980. {
  981. Object.defineProperty(
  982. this,
  983. "nativeEvent",
  984. getPooledWarningPropertyDefinition("nativeEvent", null)
  985. );
  986. Object.defineProperty(
  987. this,
  988. "isDefaultPrevented",
  989. getPooledWarningPropertyDefinition(
  990. "isDefaultPrevented",
  991. functionThatReturnsFalse
  992. )
  993. );
  994. Object.defineProperty(
  995. this,
  996. "isPropagationStopped",
  997. getPooledWarningPropertyDefinition(
  998. "isPropagationStopped",
  999. functionThatReturnsFalse
  1000. )
  1001. );
  1002. Object.defineProperty(
  1003. this,
  1004. "preventDefault",
  1005. getPooledWarningPropertyDefinition("preventDefault", function() {})
  1006. );
  1007. Object.defineProperty(
  1008. this,
  1009. "stopPropagation",
  1010. getPooledWarningPropertyDefinition("stopPropagation", function() {})
  1011. );
  1012. }
  1013. }
  1014. });
  1015. SyntheticEvent.Interface = EventInterface;
  1016. /**
  1017. * Helper to reduce boilerplate when creating subclasses.
  1018. */
  1019. SyntheticEvent.extend = function(Interface) {
  1020. var Super = this;
  1021. var E = function() {};
  1022. E.prototype = Super.prototype;
  1023. var prototype = new E();
  1024. function Class() {
  1025. return Super.apply(this, arguments);
  1026. }
  1027. Object.assign(prototype, Class.prototype);
  1028. Class.prototype = prototype;
  1029. Class.prototype.constructor = Class;
  1030. Class.Interface = Object.assign({}, Super.Interface, Interface);
  1031. Class.extend = Super.extend;
  1032. addEventPoolingTo(Class);
  1033. return Class;
  1034. };
  1035. addEventPoolingTo(SyntheticEvent);
  1036. /**
  1037. * Helper to nullify syntheticEvent instance properties when destructing
  1038. *
  1039. * @param {String} propName
  1040. * @param {?object} getVal
  1041. * @return {object} defineProperty object
  1042. */
  1043. function getPooledWarningPropertyDefinition(propName, getVal) {
  1044. var isFunction = typeof getVal === "function";
  1045. return {
  1046. configurable: true,
  1047. set: set,
  1048. get: get
  1049. };
  1050. function set(val) {
  1051. var action = isFunction ? "setting the method" : "setting the property";
  1052. warn(action, "This is effectively a no-op");
  1053. return val;
  1054. }
  1055. function get() {
  1056. var action = isFunction ? "accessing the method" : "accessing the property";
  1057. var result = isFunction
  1058. ? "This is a no-op function"
  1059. : "This is set to null";
  1060. warn(action, result);
  1061. return getVal;
  1062. }
  1063. function warn(action, result) {
  1064. {
  1065. error(
  1066. "This synthetic event is reused for performance reasons. If you're seeing this, " +
  1067. "you're %s `%s` on a released/nullified synthetic event. %s. " +
  1068. "If you must keep the original synthetic event around, use event.persist(). " +
  1069. "See https://fb.me/react-event-pooling for more information.",
  1070. action,
  1071. propName,
  1072. result
  1073. );
  1074. }
  1075. }
  1076. }
  1077. function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
  1078. var EventConstructor = this;
  1079. if (EventConstructor.eventPool.length) {
  1080. var instance = EventConstructor.eventPool.pop();
  1081. EventConstructor.call(
  1082. instance,
  1083. dispatchConfig,
  1084. targetInst,
  1085. nativeEvent,
  1086. nativeInst
  1087. );
  1088. return instance;
  1089. }
  1090. return new EventConstructor(
  1091. dispatchConfig,
  1092. targetInst,
  1093. nativeEvent,
  1094. nativeInst
  1095. );
  1096. }
  1097. function releasePooledEvent(event) {
  1098. var EventConstructor = this;
  1099. if (!(event instanceof EventConstructor)) {
  1100. throw Error(
  1101. "Trying to release an event instance into a pool of a different type."
  1102. );
  1103. }
  1104. event.destructor();
  1105. if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
  1106. EventConstructor.eventPool.push(event);
  1107. }
  1108. }
  1109. function addEventPoolingTo(EventConstructor) {
  1110. EventConstructor.eventPool = [];
  1111. EventConstructor.getPooled = getPooledEvent;
  1112. EventConstructor.release = releasePooledEvent;
  1113. }
  1114. /**
  1115. * `touchHistory` isn't actually on the native event, but putting it in the
  1116. * interface will ensure that it is cleaned up when pooled/destroyed. The
  1117. * `ResponderEventPlugin` will populate it appropriately.
  1118. */
  1119. var ResponderSyntheticEvent = SyntheticEvent.extend({
  1120. touchHistory: function(nativeEvent) {
  1121. return null; // Actually doesn't even look at the native event.
  1122. }
  1123. });
  1124. var TOP_TOUCH_START = "topTouchStart";
  1125. var TOP_TOUCH_MOVE = "topTouchMove";
  1126. var TOP_TOUCH_END = "topTouchEnd";
  1127. var TOP_TOUCH_CANCEL = "topTouchCancel";
  1128. var TOP_SCROLL = "topScroll";
  1129. var TOP_SELECTION_CHANGE = "topSelectionChange";
  1130. function isStartish(topLevelType) {
  1131. return topLevelType === TOP_TOUCH_START;
  1132. }
  1133. function isMoveish(topLevelType) {
  1134. return topLevelType === TOP_TOUCH_MOVE;
  1135. }
  1136. function isEndish(topLevelType) {
  1137. return topLevelType === TOP_TOUCH_END || topLevelType === TOP_TOUCH_CANCEL;
  1138. }
  1139. var startDependencies = [TOP_TOUCH_START];
  1140. var moveDependencies = [TOP_TOUCH_MOVE];
  1141. var endDependencies = [TOP_TOUCH_CANCEL, TOP_TOUCH_END];
  1142. /**
  1143. * Tracks the position and time of each active touch by `touch.identifier`. We
  1144. * should typically only see IDs in the range of 1-20 because IDs get recycled
  1145. * when touches end and start again.
  1146. */
  1147. var MAX_TOUCH_BANK = 20;
  1148. var touchBank = [];
  1149. var touchHistory = {
  1150. touchBank: touchBank,
  1151. numberActiveTouches: 0,
  1152. // If there is only one active touch, we remember its location. This prevents
  1153. // us having to loop through all of the touches all the time in the most
  1154. // common case.
  1155. indexOfSingleActiveTouch: -1,
  1156. mostRecentTimeStamp: 0
  1157. };
  1158. function timestampForTouch(touch) {
  1159. // The legacy internal implementation provides "timeStamp", which has been
  1160. // renamed to "timestamp". Let both work for now while we iron it out
  1161. // TODO (evv): rename timeStamp to timestamp in internal code
  1162. return touch.timeStamp || touch.timestamp;
  1163. }
  1164. /**
  1165. * TODO: Instead of making gestures recompute filtered velocity, we could
  1166. * include a built in velocity computation that can be reused globally.
  1167. */
  1168. function createTouchRecord(touch) {
  1169. return {
  1170. touchActive: true,
  1171. startPageX: touch.pageX,
  1172. startPageY: touch.pageY,
  1173. startTimeStamp: timestampForTouch(touch),
  1174. currentPageX: touch.pageX,
  1175. currentPageY: touch.pageY,
  1176. currentTimeStamp: timestampForTouch(touch),
  1177. previousPageX: touch.pageX,
  1178. previousPageY: touch.pageY,
  1179. previousTimeStamp: timestampForTouch(touch)
  1180. };
  1181. }
  1182. function resetTouchRecord(touchRecord, touch) {
  1183. touchRecord.touchActive = true;
  1184. touchRecord.startPageX = touch.pageX;
  1185. touchRecord.startPageY = touch.pageY;
  1186. touchRecord.startTimeStamp = timestampForTouch(touch);
  1187. touchRecord.currentPageX = touch.pageX;
  1188. touchRecord.currentPageY = touch.pageY;
  1189. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1190. touchRecord.previousPageX = touch.pageX;
  1191. touchRecord.previousPageY = touch.pageY;
  1192. touchRecord.previousTimeStamp = timestampForTouch(touch);
  1193. }
  1194. function getTouchIdentifier(_ref) {
  1195. var identifier = _ref.identifier;
  1196. if (!(identifier != null)) {
  1197. throw Error("Touch object is missing identifier.");
  1198. }
  1199. {
  1200. if (identifier > MAX_TOUCH_BANK) {
  1201. error(
  1202. "Touch identifier %s is greater than maximum supported %s which causes " +
  1203. "performance issues backfilling array locations for all of the indices.",
  1204. identifier,
  1205. MAX_TOUCH_BANK
  1206. );
  1207. }
  1208. }
  1209. return identifier;
  1210. }
  1211. function recordTouchStart(touch) {
  1212. var identifier = getTouchIdentifier(touch);
  1213. var touchRecord = touchBank[identifier];
  1214. if (touchRecord) {
  1215. resetTouchRecord(touchRecord, touch);
  1216. } else {
  1217. touchBank[identifier] = createTouchRecord(touch);
  1218. }
  1219. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1220. }
  1221. function recordTouchMove(touch) {
  1222. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1223. if (touchRecord) {
  1224. touchRecord.touchActive = true;
  1225. touchRecord.previousPageX = touchRecord.currentPageX;
  1226. touchRecord.previousPageY = touchRecord.currentPageY;
  1227. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1228. touchRecord.currentPageX = touch.pageX;
  1229. touchRecord.currentPageY = touch.pageY;
  1230. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1231. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1232. } else {
  1233. {
  1234. warn(
  1235. "Cannot record touch move without a touch start.\n" +
  1236. "Touch Move: %s\n" +
  1237. "Touch Bank: %s",
  1238. printTouch(touch),
  1239. printTouchBank()
  1240. );
  1241. }
  1242. }
  1243. }
  1244. function recordTouchEnd(touch) {
  1245. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1246. if (touchRecord) {
  1247. touchRecord.touchActive = false;
  1248. touchRecord.previousPageX = touchRecord.currentPageX;
  1249. touchRecord.previousPageY = touchRecord.currentPageY;
  1250. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1251. touchRecord.currentPageX = touch.pageX;
  1252. touchRecord.currentPageY = touch.pageY;
  1253. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1254. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1255. } else {
  1256. {
  1257. warn(
  1258. "Cannot record touch end without a touch start.\n" +
  1259. "Touch End: %s\n" +
  1260. "Touch Bank: %s",
  1261. printTouch(touch),
  1262. printTouchBank()
  1263. );
  1264. }
  1265. }
  1266. }
  1267. function printTouch(touch) {
  1268. return JSON.stringify({
  1269. identifier: touch.identifier,
  1270. pageX: touch.pageX,
  1271. pageY: touch.pageY,
  1272. timestamp: timestampForTouch(touch)
  1273. });
  1274. }
  1275. function printTouchBank() {
  1276. var printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK));
  1277. if (touchBank.length > MAX_TOUCH_BANK) {
  1278. printed += " (original size: " + touchBank.length + ")";
  1279. }
  1280. return printed;
  1281. }
  1282. var ResponderTouchHistoryStore = {
  1283. recordTouchTrack: function(topLevelType, nativeEvent) {
  1284. if (isMoveish(topLevelType)) {
  1285. nativeEvent.changedTouches.forEach(recordTouchMove);
  1286. } else if (isStartish(topLevelType)) {
  1287. nativeEvent.changedTouches.forEach(recordTouchStart);
  1288. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1289. if (touchHistory.numberActiveTouches === 1) {
  1290. touchHistory.indexOfSingleActiveTouch =
  1291. nativeEvent.touches[0].identifier;
  1292. }
  1293. } else if (isEndish(topLevelType)) {
  1294. nativeEvent.changedTouches.forEach(recordTouchEnd);
  1295. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1296. if (touchHistory.numberActiveTouches === 1) {
  1297. for (var i = 0; i < touchBank.length; i++) {
  1298. var touchTrackToCheck = touchBank[i];
  1299. if (touchTrackToCheck != null && touchTrackToCheck.touchActive) {
  1300. touchHistory.indexOfSingleActiveTouch = i;
  1301. break;
  1302. }
  1303. }
  1304. {
  1305. var activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
  1306. if (activeRecord == null || !activeRecord.touchActive) {
  1307. error("Cannot find single active touch.");
  1308. }
  1309. }
  1310. }
  1311. }
  1312. },
  1313. touchHistory: touchHistory
  1314. };
  1315. /**
  1316. * Accumulates items that must not be null or undefined.
  1317. *
  1318. * This is used to conserve memory by avoiding array allocations.
  1319. *
  1320. * @return {*|array<*>} An accumulation of items.
  1321. */
  1322. function accumulate(current, next) {
  1323. if (!(next != null)) {
  1324. throw Error(
  1325. "accumulate(...): Accumulated items must not be null or undefined."
  1326. );
  1327. }
  1328. if (current == null) {
  1329. return next;
  1330. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  1331. // certain that x is an Array (x could be a string with concat method).
  1332. if (Array.isArray(current)) {
  1333. return current.concat(next);
  1334. }
  1335. if (Array.isArray(next)) {
  1336. return [current].concat(next);
  1337. }
  1338. return [current, next];
  1339. }
  1340. /**
  1341. * Instance of element that should respond to touch/move types of interactions,
  1342. * as indicated explicitly by relevant callbacks.
  1343. */
  1344. var responderInst = null;
  1345. /**
  1346. * Count of current touches. A textInput should become responder iff the
  1347. * selection changes while there is a touch on the screen.
  1348. */
  1349. var trackedTouchCount = 0;
  1350. var changeResponder = function(nextResponderInst, blockHostResponder) {
  1351. var oldResponderInst = responderInst;
  1352. responderInst = nextResponderInst;
  1353. if (ResponderEventPlugin.GlobalResponderHandler !== null) {
  1354. ResponderEventPlugin.GlobalResponderHandler.onChange(
  1355. oldResponderInst,
  1356. nextResponderInst,
  1357. blockHostResponder
  1358. );
  1359. }
  1360. };
  1361. var eventTypes = {
  1362. /**
  1363. * On a `touchStart`/`mouseDown`, is it desired that this element become the
  1364. * responder?
  1365. */
  1366. startShouldSetResponder: {
  1367. phasedRegistrationNames: {
  1368. bubbled: "onStartShouldSetResponder",
  1369. captured: "onStartShouldSetResponderCapture"
  1370. },
  1371. dependencies: startDependencies
  1372. },
  1373. /**
  1374. * On a `scroll`, is it desired that this element become the responder? This
  1375. * is usually not needed, but should be used to retroactively infer that a
  1376. * `touchStart` had occurred during momentum scroll. During a momentum scroll,
  1377. * a touch start will be immediately followed by a scroll event if the view is
  1378. * currently scrolling.
  1379. *
  1380. * TODO: This shouldn't bubble.
  1381. */
  1382. scrollShouldSetResponder: {
  1383. phasedRegistrationNames: {
  1384. bubbled: "onScrollShouldSetResponder",
  1385. captured: "onScrollShouldSetResponderCapture"
  1386. },
  1387. dependencies: [TOP_SCROLL]
  1388. },
  1389. /**
  1390. * On text selection change, should this element become the responder? This
  1391. * is needed for text inputs or other views with native selection, so the
  1392. * JS view can claim the responder.
  1393. *
  1394. * TODO: This shouldn't bubble.
  1395. */
  1396. selectionChangeShouldSetResponder: {
  1397. phasedRegistrationNames: {
  1398. bubbled: "onSelectionChangeShouldSetResponder",
  1399. captured: "onSelectionChangeShouldSetResponderCapture"
  1400. },
  1401. dependencies: [TOP_SELECTION_CHANGE]
  1402. },
  1403. /**
  1404. * On a `touchMove`/`mouseMove`, is it desired that this element become the
  1405. * responder?
  1406. */
  1407. moveShouldSetResponder: {
  1408. phasedRegistrationNames: {
  1409. bubbled: "onMoveShouldSetResponder",
  1410. captured: "onMoveShouldSetResponderCapture"
  1411. },
  1412. dependencies: moveDependencies
  1413. },
  1414. /**
  1415. * Direct responder events dispatched directly to responder. Do not bubble.
  1416. */
  1417. responderStart: {
  1418. registrationName: "onResponderStart",
  1419. dependencies: startDependencies
  1420. },
  1421. responderMove: {
  1422. registrationName: "onResponderMove",
  1423. dependencies: moveDependencies
  1424. },
  1425. responderEnd: {
  1426. registrationName: "onResponderEnd",
  1427. dependencies: endDependencies
  1428. },
  1429. responderRelease: {
  1430. registrationName: "onResponderRelease",
  1431. dependencies: endDependencies
  1432. },
  1433. responderTerminationRequest: {
  1434. registrationName: "onResponderTerminationRequest",
  1435. dependencies: []
  1436. },
  1437. responderGrant: {
  1438. registrationName: "onResponderGrant",
  1439. dependencies: []
  1440. },
  1441. responderReject: {
  1442. registrationName: "onResponderReject",
  1443. dependencies: []
  1444. },
  1445. responderTerminate: {
  1446. registrationName: "onResponderTerminate",
  1447. dependencies: []
  1448. }
  1449. };
  1450. /**
  1451. *
  1452. * Responder System:
  1453. * ----------------
  1454. *
  1455. * - A global, solitary "interaction lock" on a view.
  1456. * - If a node becomes the responder, it should convey visual feedback
  1457. * immediately to indicate so, either by highlighting or moving accordingly.
  1458. * - To be the responder means, that touches are exclusively important to that
  1459. * responder view, and no other view.
  1460. * - While touches are still occurring, the responder lock can be transferred to
  1461. * a new view, but only to increasingly "higher" views (meaning ancestors of
  1462. * the current responder).
  1463. *
  1464. * Responder being granted:
  1465. * ------------------------
  1466. *
  1467. * - Touch starts, moves, and scrolls can cause an ID to become the responder.
  1468. * - We capture/bubble `startShouldSetResponder`/`moveShouldSetResponder` to
  1469. * the "appropriate place".
  1470. * - If nothing is currently the responder, the "appropriate place" is the
  1471. * initiating event's `targetID`.
  1472. * - If something *is* already the responder, the "appropriate place" is the
  1473. * first common ancestor of the event target and the current `responderInst`.
  1474. * - Some negotiation happens: See the timing diagram below.
  1475. * - Scrolled views automatically become responder. The reasoning is that a
  1476. * platform scroll view that isn't built on top of the responder system has
  1477. * began scrolling, and the active responder must now be notified that the
  1478. * interaction is no longer locked to it - the system has taken over.
  1479. *
  1480. * - Responder being released:
  1481. * As soon as no more touches that *started* inside of descendants of the
  1482. * *current* responderInst, an `onResponderRelease` event is dispatched to the
  1483. * current responder, and the responder lock is released.
  1484. *
  1485. * TODO:
  1486. * - on "end", a callback hook for `onResponderEndShouldRemainResponder` that
  1487. * determines if the responder lock should remain.
  1488. * - If a view shouldn't "remain" the responder, any active touches should by
  1489. * default be considered "dead" and do not influence future negotiations or
  1490. * bubble paths. It should be as if those touches do not exist.
  1491. * -- For multitouch: Usually a translate-z will choose to "remain" responder
  1492. * after one out of many touches ended. For translate-y, usually the view
  1493. * doesn't wish to "remain" responder after one of many touches end.
  1494. * - Consider building this on top of a `stopPropagation` model similar to
  1495. * `W3C` events.
  1496. * - Ensure that `onResponderTerminate` is called on touch cancels, whether or
  1497. * not `onResponderTerminationRequest` returns `true` or `false`.
  1498. *
  1499. */
  1500. /* Negotiation Performed
  1501. +-----------------------+
  1502. / \
  1503. Process low level events to + Current Responder + wantsResponderID
  1504. determine who to perform negot-| (if any exists at all) |
  1505. iation/transition | Otherwise just pass through|
  1506. -------------------------------+----------------------------+------------------+
  1507. Bubble to find first ID | |
  1508. to return true:wantsResponderID| |
  1509. | |
  1510. +-------------+ | |
  1511. | onTouchStart| | |
  1512. +------+------+ none | |
  1513. | return| |
  1514. +-----------v-------------+true| +------------------------+ |
  1515. |onStartShouldSetResponder|----->|onResponderStart (cur) |<-----------+
  1516. +-----------+-------------+ | +------------------------+ | |
  1517. | | | +--------+-------+
  1518. | returned true for| false:REJECT +-------->|onResponderReject
  1519. | wantsResponderID | | | +----------------+
  1520. | (now attempt | +------------------+-----+ |
  1521. | handoff) | | onResponder | |
  1522. +------------------->| TerminationRequest| |
  1523. | +------------------+-----+ |
  1524. | | | +----------------+
  1525. | true:GRANT +-------->|onResponderGrant|
  1526. | | +--------+-------+
  1527. | +------------------------+ | |
  1528. | | onResponderTerminate |<-----------+
  1529. | +------------------+-----+ |
  1530. | | | +----------------+
  1531. | +-------->|onResponderStart|
  1532. | | +----------------+
  1533. Bubble to find first ID | |
  1534. to return true:wantsResponderID| |
  1535. | |
  1536. +-------------+ | |
  1537. | onTouchMove | | |
  1538. +------+------+ none | |
  1539. | return| |
  1540. +-----------v-------------+true| +------------------------+ |
  1541. |onMoveShouldSetResponder |----->|onResponderMove (cur) |<-----------+
  1542. +-----------+-------------+ | +------------------------+ | |
  1543. | | | +--------+-------+
  1544. | returned true for| false:REJECT +-------->|onResponderRejec|
  1545. | wantsResponderID | | | +----------------+
  1546. | (now attempt | +------------------+-----+ |
  1547. | handoff) | | onResponder | |
  1548. +------------------->| TerminationRequest| |
  1549. | +------------------+-----+ |
  1550. | | | +----------------+
  1551. | true:GRANT +-------->|onResponderGrant|
  1552. | | +--------+-------+
  1553. | +------------------------+ | |
  1554. | | onResponderTerminate |<-----------+
  1555. | +------------------+-----+ |
  1556. | | | +----------------+
  1557. | +-------->|onResponderMove |
  1558. | | +----------------+
  1559. | |
  1560. | |
  1561. Some active touch started| |
  1562. inside current responder | +------------------------+ |
  1563. +------------------------->| onResponderEnd | |
  1564. | | +------------------------+ |
  1565. +---+---------+ | |
  1566. | onTouchEnd | | |
  1567. +---+---------+ | |
  1568. | | +------------------------+ |
  1569. +------------------------->| onResponderEnd | |
  1570. No active touches started| +-----------+------------+ |
  1571. inside current responder | | |
  1572. | v |
  1573. | +------------------------+ |
  1574. | | onResponderRelease | |
  1575. | +------------------------+ |
  1576. | |
  1577. + + */
  1578. /**
  1579. * A note about event ordering in the `EventPluginRegistry`.
  1580. *
  1581. * Suppose plugins are injected in the following order:
  1582. *
  1583. * `[R, S, C]`
  1584. *
  1585. * To help illustrate the example, assume `S` is `SimpleEventPlugin` (for
  1586. * `onClick` etc) and `R` is `ResponderEventPlugin`.
  1587. *
  1588. * "Deferred-Dispatched Events":
  1589. *
  1590. * - The current event plugin system will traverse the list of injected plugins,
  1591. * in order, and extract events by collecting the plugin's return value of
  1592. * `extractEvents()`.
  1593. * - These events that are returned from `extractEvents` are "deferred
  1594. * dispatched events".
  1595. * - When returned from `extractEvents`, deferred-dispatched events contain an
  1596. * "accumulation" of deferred dispatches.
  1597. * - These deferred dispatches are accumulated/collected before they are
  1598. * returned, but processed at a later time by the `EventPluginRegistry` (hence the
  1599. * name deferred).
  1600. *
  1601. * In the process of returning their deferred-dispatched events, event plugins
  1602. * themselves can dispatch events on-demand without returning them from
  1603. * `extractEvents`. Plugins might want to do this, so that they can use event
  1604. * dispatching as a tool that helps them decide which events should be extracted
  1605. * in the first place.
  1606. *
  1607. * "On-Demand-Dispatched Events":
  1608. *
  1609. * - On-demand-dispatched events are not returned from `extractEvents`.
  1610. * - On-demand-dispatched events are dispatched during the process of returning
  1611. * the deferred-dispatched events.
  1612. * - They should not have side effects.
  1613. * - They should be avoided, and/or eventually be replaced with another
  1614. * abstraction that allows event plugins to perform multiple "rounds" of event
  1615. * extraction.
  1616. *
  1617. * Therefore, the sequence of event dispatches becomes:
  1618. *
  1619. * - `R`s on-demand events (if any) (dispatched by `R` on-demand)
  1620. * - `S`s on-demand events (if any) (dispatched by `S` on-demand)
  1621. * - `C`s on-demand events (if any) (dispatched by `C` on-demand)
  1622. * - `R`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1623. * - `S`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1624. * - `C`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1625. *
  1626. * In the case of `ResponderEventPlugin`: If the `startShouldSetResponder`
  1627. * on-demand dispatch returns `true` (and some other details are satisfied) the
  1628. * `onResponderGrant` deferred dispatched event is returned from
  1629. * `extractEvents`. The sequence of dispatch executions in this case
  1630. * will appear as follows:
  1631. *
  1632. * - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand)
  1633. * - `touchStartCapture` (`EventPluginRegistry` dispatches as usual)
  1634. * - `touchStart` (`EventPluginRegistry` dispatches as usual)
  1635. * - `responderGrant/Reject` (`EventPluginRegistry` dispatches as usual)
  1636. */
  1637. function setResponderAndExtractTransfer(
  1638. topLevelType,
  1639. targetInst,
  1640. nativeEvent,
  1641. nativeEventTarget
  1642. ) {
  1643. var shouldSetEventType = isStartish(topLevelType)
  1644. ? eventTypes.startShouldSetResponder
  1645. : isMoveish(topLevelType)
  1646. ? eventTypes.moveShouldSetResponder
  1647. : topLevelType === TOP_SELECTION_CHANGE
  1648. ? eventTypes.selectionChangeShouldSetResponder
  1649. : eventTypes.scrollShouldSetResponder; // TODO: stop one short of the current responder.
  1650. var bubbleShouldSetFrom = !responderInst
  1651. ? targetInst
  1652. : getLowestCommonAncestor(responderInst, targetInst); // When capturing/bubbling the "shouldSet" event, we want to skip the target
  1653. // (deepest ID) if it happens to be the current responder. The reasoning:
  1654. // It's strange to get an `onMoveShouldSetResponder` when you're *already*
  1655. // the responder.
  1656. var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
  1657. var shouldSetEvent = ResponderSyntheticEvent.getPooled(
  1658. shouldSetEventType,
  1659. bubbleShouldSetFrom,
  1660. nativeEvent,
  1661. nativeEventTarget
  1662. );
  1663. shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1664. if (skipOverBubbleShouldSetFrom) {
  1665. accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);
  1666. } else {
  1667. accumulateTwoPhaseDispatches(shouldSetEvent);
  1668. }
  1669. var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
  1670. if (!shouldSetEvent.isPersistent()) {
  1671. shouldSetEvent.constructor.release(shouldSetEvent);
  1672. }
  1673. if (!wantsResponderInst || wantsResponderInst === responderInst) {
  1674. return null;
  1675. }
  1676. var extracted;
  1677. var grantEvent = ResponderSyntheticEvent.getPooled(
  1678. eventTypes.responderGrant,
  1679. wantsResponderInst,
  1680. nativeEvent,
  1681. nativeEventTarget
  1682. );
  1683. grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1684. accumulateDirectDispatches(grantEvent);
  1685. var blockHostResponder = executeDirectDispatch(grantEvent) === true;
  1686. if (responderInst) {
  1687. var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
  1688. eventTypes.responderTerminationRequest,
  1689. responderInst,
  1690. nativeEvent,
  1691. nativeEventTarget
  1692. );
  1693. terminationRequestEvent.touchHistory =
  1694. ResponderTouchHistoryStore.touchHistory;
  1695. accumulateDirectDispatches(terminationRequestEvent);
  1696. var shouldSwitch =
  1697. !hasDispatches(terminationRequestEvent) ||
  1698. executeDirectDispatch(terminationRequestEvent);
  1699. if (!terminationRequestEvent.isPersistent()) {
  1700. terminationRequestEvent.constructor.release(terminationRequestEvent);
  1701. }
  1702. if (shouldSwitch) {
  1703. var terminateEvent = ResponderSyntheticEvent.getPooled(
  1704. eventTypes.responderTerminate,
  1705. responderInst,
  1706. nativeEvent,
  1707. nativeEventTarget
  1708. );
  1709. terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1710. accumulateDirectDispatches(terminateEvent);
  1711. extracted = accumulate(extracted, [grantEvent, terminateEvent]);
  1712. changeResponder(wantsResponderInst, blockHostResponder);
  1713. } else {
  1714. var rejectEvent = ResponderSyntheticEvent.getPooled(
  1715. eventTypes.responderReject,
  1716. wantsResponderInst,
  1717. nativeEvent,
  1718. nativeEventTarget
  1719. );
  1720. rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1721. accumulateDirectDispatches(rejectEvent);
  1722. extracted = accumulate(extracted, rejectEvent);
  1723. }
  1724. } else {
  1725. extracted = accumulate(extracted, grantEvent);
  1726. changeResponder(wantsResponderInst, blockHostResponder);
  1727. }
  1728. return extracted;
  1729. }
  1730. /**
  1731. * A transfer is a negotiation between a currently set responder and the next
  1732. * element to claim responder status. Any start event could trigger a transfer
  1733. * of responderInst. Any move event could trigger a transfer.
  1734. *
  1735. * @param {string} topLevelType Record from `BrowserEventConstants`.
  1736. * @return {boolean} True if a transfer of responder could possibly occur.
  1737. */
  1738. function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
  1739. return (
  1740. topLevelInst && // responderIgnoreScroll: We are trying to migrate away from specifically
  1741. // tracking native scroll events here and responderIgnoreScroll indicates we
  1742. // will send topTouchCancel to handle canceling touch events instead
  1743. ((topLevelType === TOP_SCROLL && !nativeEvent.responderIgnoreScroll) ||
  1744. (trackedTouchCount > 0 && topLevelType === TOP_SELECTION_CHANGE) ||
  1745. isStartish(topLevelType) ||
  1746. isMoveish(topLevelType))
  1747. );
  1748. }
  1749. /**
  1750. * Returns whether or not this touch end event makes it such that there are no
  1751. * longer any touches that started inside of the current `responderInst`.
  1752. *
  1753. * @param {NativeEvent} nativeEvent Native touch end event.
  1754. * @return {boolean} Whether or not this touch end event ends the responder.
  1755. */
  1756. function noResponderTouches(nativeEvent) {
  1757. var touches = nativeEvent.touches;
  1758. if (!touches || touches.length === 0) {
  1759. return true;
  1760. }
  1761. for (var i = 0; i < touches.length; i++) {
  1762. var activeTouch = touches[i];
  1763. var target = activeTouch.target;
  1764. if (target !== null && target !== undefined && target !== 0) {
  1765. // Is the original touch location inside of the current responder?
  1766. var targetInst = getInstanceFromNode(target);
  1767. if (isAncestor(responderInst, targetInst)) {
  1768. return false;
  1769. }
  1770. }
  1771. }
  1772. return true;
  1773. }
  1774. var ResponderEventPlugin = {
  1775. /* For unit testing only */
  1776. _getResponder: function() {
  1777. return responderInst;
  1778. },
  1779. eventTypes: eventTypes,
  1780. /**
  1781. * We must be resilient to `targetInst` being `null` on `touchMove` or
  1782. * `touchEnd`. On certain platforms, this means that a native scroll has
  1783. * assumed control and the original touch targets are destroyed.
  1784. */
  1785. extractEvents: function(
  1786. topLevelType,
  1787. targetInst,
  1788. nativeEvent,
  1789. nativeEventTarget,
  1790. eventSystemFlags
  1791. ) {
  1792. if (isStartish(topLevelType)) {
  1793. trackedTouchCount += 1;
  1794. } else if (isEndish(topLevelType)) {
  1795. if (trackedTouchCount >= 0) {
  1796. trackedTouchCount -= 1;
  1797. } else {
  1798. {
  1799. warn(
  1800. "Ended a touch event which was not counted in `trackedTouchCount`."
  1801. );
  1802. }
  1803. return null;
  1804. }
  1805. }
  1806. ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
  1807. var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
  1808. ? setResponderAndExtractTransfer(
  1809. topLevelType,
  1810. targetInst,
  1811. nativeEvent,
  1812. nativeEventTarget
  1813. )
  1814. : null; // Responder may or may not have transferred on a new touch start/move.
  1815. // Regardless, whoever is the responder after any potential transfer, we
  1816. // direct all touch start/move/ends to them in the form of
  1817. // `onResponderMove/Start/End`. These will be called for *every* additional
  1818. // finger that move/start/end, dispatched directly to whoever is the
  1819. // current responder at that moment, until the responder is "released".
  1820. //
  1821. // These multiple individual change touch events are are always bookended
  1822. // by `onResponderGrant`, and one of
  1823. // (`onResponderRelease/onResponderTerminate`).
  1824. var isResponderTouchStart = responderInst && isStartish(topLevelType);
  1825. var isResponderTouchMove = responderInst && isMoveish(topLevelType);
  1826. var isResponderTouchEnd = responderInst && isEndish(topLevelType);
  1827. var incrementalTouch = isResponderTouchStart
  1828. ? eventTypes.responderStart
  1829. : isResponderTouchMove
  1830. ? eventTypes.responderMove
  1831. : isResponderTouchEnd
  1832. ? eventTypes.responderEnd
  1833. : null;
  1834. if (incrementalTouch) {
  1835. var gesture = ResponderSyntheticEvent.getPooled(
  1836. incrementalTouch,
  1837. responderInst,
  1838. nativeEvent,
  1839. nativeEventTarget
  1840. );
  1841. gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1842. accumulateDirectDispatches(gesture);
  1843. extracted = accumulate(extracted, gesture);
  1844. }
  1845. var isResponderTerminate =
  1846. responderInst && topLevelType === TOP_TOUCH_CANCEL;
  1847. var isResponderRelease =
  1848. responderInst &&
  1849. !isResponderTerminate &&
  1850. isEndish(topLevelType) &&
  1851. noResponderTouches(nativeEvent);
  1852. var finalTouch = isResponderTerminate
  1853. ? eventTypes.responderTerminate
  1854. : isResponderRelease
  1855. ? eventTypes.responderRelease
  1856. : null;
  1857. if (finalTouch) {
  1858. var finalEvent = ResponderSyntheticEvent.getPooled(
  1859. finalTouch,
  1860. responderInst,
  1861. nativeEvent,
  1862. nativeEventTarget
  1863. );
  1864. finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1865. accumulateDirectDispatches(finalEvent);
  1866. extracted = accumulate(extracted, finalEvent);
  1867. changeResponder(null);
  1868. }
  1869. return extracted;
  1870. },
  1871. GlobalResponderHandler: null,
  1872. injection: {
  1873. /**
  1874. * @param {{onChange: (ReactID, ReactID) => void} GlobalResponderHandler
  1875. * Object that handles any change in responder. Use this to inject
  1876. * integration with an existing touch handling system etc.
  1877. */
  1878. injectGlobalResponderHandler: function(GlobalResponderHandler) {
  1879. ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler;
  1880. }
  1881. }
  1882. };
  1883. /**
  1884. * Injectable ordering of event plugins.
  1885. */
  1886. var eventPluginOrder = null;
  1887. /**
  1888. * Injectable mapping from names to event plugin modules.
  1889. */
  1890. var namesToPlugins = {};
  1891. /**
  1892. * Recomputes the plugin list using the injected plugins and plugin ordering.
  1893. *
  1894. * @private
  1895. */
  1896. function recomputePluginOrdering() {
  1897. if (!eventPluginOrder) {
  1898. // Wait until an `eventPluginOrder` is injected.
  1899. return;
  1900. }
  1901. for (var pluginName in namesToPlugins) {
  1902. var pluginModule = namesToPlugins[pluginName];
  1903. var pluginIndex = eventPluginOrder.indexOf(pluginName);
  1904. if (!(pluginIndex > -1)) {
  1905. throw Error(
  1906. "EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `" +
  1907. pluginName +
  1908. "`."
  1909. );
  1910. }
  1911. if (plugins[pluginIndex]) {
  1912. continue;
  1913. }
  1914. if (!pluginModule.extractEvents) {
  1915. throw Error(
  1916. "EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `" +
  1917. pluginName +
  1918. "` does not."
  1919. );
  1920. }
  1921. plugins[pluginIndex] = pluginModule;
  1922. var publishedEvents = pluginModule.eventTypes;
  1923. for (var eventName in publishedEvents) {
  1924. if (
  1925. !publishEventForPlugin(
  1926. publishedEvents[eventName],
  1927. pluginModule,
  1928. eventName
  1929. )
  1930. ) {
  1931. throw Error(
  1932. "EventPluginRegistry: Failed to publish event `" +
  1933. eventName +
  1934. "` for plugin `" +
  1935. pluginName +
  1936. "`."
  1937. );
  1938. }
  1939. }
  1940. }
  1941. }
  1942. /**
  1943. * Publishes an event so that it can be dispatched by the supplied plugin.
  1944. *
  1945. * @param {object} dispatchConfig Dispatch configuration for the event.
  1946. * @param {object} PluginModule Plugin publishing the event.
  1947. * @return {boolean} True if the event was successfully published.
  1948. * @private
  1949. */
  1950. function publishEventForPlugin(dispatchConfig, pluginModule, eventName) {
  1951. if (!!eventNameDispatchConfigs.hasOwnProperty(eventName)) {
  1952. throw Error(
  1953. "EventPluginRegistry: More than one plugin attempted to publish the same event name, `" +
  1954. eventName +
  1955. "`."
  1956. );
  1957. }
  1958. eventNameDispatchConfigs[eventName] = dispatchConfig;
  1959. var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
  1960. if (phasedRegistrationNames) {
  1961. for (var phaseName in phasedRegistrationNames) {
  1962. if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
  1963. var phasedRegistrationName = phasedRegistrationNames[phaseName];
  1964. publishRegistrationName(
  1965. phasedRegistrationName,
  1966. pluginModule,
  1967. eventName
  1968. );
  1969. }
  1970. }
  1971. return true;
  1972. } else if (dispatchConfig.registrationName) {
  1973. publishRegistrationName(
  1974. dispatchConfig.registrationName,
  1975. pluginModule,
  1976. eventName
  1977. );
  1978. return true;
  1979. }
  1980. return false;
  1981. }
  1982. /**
  1983. * Publishes a registration name that is used to identify dispatched events.
  1984. *
  1985. * @param {string} registrationName Registration name to add.
  1986. * @param {object} PluginModule Plugin publishing the event.
  1987. * @private
  1988. */
  1989. function publishRegistrationName(registrationName, pluginModule, eventName) {
  1990. if (!!registrationNameModules[registrationName]) {
  1991. throw Error(
  1992. "EventPluginRegistry: More than one plugin attempted to publish the same registration name, `" +
  1993. registrationName +
  1994. "`."
  1995. );
  1996. }
  1997. registrationNameModules[registrationName] = pluginModule;
  1998. registrationNameDependencies[registrationName] =
  1999. pluginModule.eventTypes[eventName].dependencies;
  2000. {
  2001. var lowerCasedName = registrationName.toLowerCase();
  2002. }
  2003. }
  2004. /**
  2005. * Registers plugins so that they can extract and dispatch events.
  2006. */
  2007. /**
  2008. * Ordered list of injected plugins.
  2009. */
  2010. var plugins = [];
  2011. /**
  2012. * Mapping from event name to dispatch config
  2013. */
  2014. var eventNameDispatchConfigs = {};
  2015. /**
  2016. * Mapping from registration name to plugin module
  2017. */
  2018. var registrationNameModules = {};
  2019. /**
  2020. * Mapping from registration name to event name
  2021. */
  2022. var registrationNameDependencies = {};
  2023. /**
  2024. * Injects an ordering of plugins (by plugin name). This allows the ordering
  2025. * to be decoupled from injection of the actual plugins so that ordering is
  2026. * always deterministic regardless of packaging, on-the-fly injection, etc.
  2027. *
  2028. * @param {array} InjectedEventPluginOrder
  2029. * @internal
  2030. */
  2031. function injectEventPluginOrder(injectedEventPluginOrder) {
  2032. if (!!eventPluginOrder) {
  2033. throw Error(
  2034. "EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React."
  2035. );
  2036. } // Clone the ordering so it cannot be dynamically mutated.
  2037. eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
  2038. recomputePluginOrdering();
  2039. }
  2040. /**
  2041. * Injects plugins to be used by plugin event system. The plugin names must be
  2042. * in the ordering injected by `injectEventPluginOrder`.
  2043. *
  2044. * Plugins can be injected as part of page initialization or on-the-fly.
  2045. *
  2046. * @param {object} injectedNamesToPlugins Map from names to plugin modules.
  2047. * @internal
  2048. */
  2049. function injectEventPluginsByName(injectedNamesToPlugins) {
  2050. var isOrderingDirty = false;
  2051. for (var pluginName in injectedNamesToPlugins) {
  2052. if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
  2053. continue;
  2054. }
  2055. var pluginModule = injectedNamesToPlugins[pluginName];
  2056. if (
  2057. !namesToPlugins.hasOwnProperty(pluginName) ||
  2058. namesToPlugins[pluginName] !== pluginModule
  2059. ) {
  2060. if (!!namesToPlugins[pluginName]) {
  2061. throw Error(
  2062. "EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
  2063. pluginName +
  2064. "`."
  2065. );
  2066. }
  2067. namesToPlugins[pluginName] = pluginModule;
  2068. isOrderingDirty = true;
  2069. }
  2070. }
  2071. if (isOrderingDirty) {
  2072. recomputePluginOrdering();
  2073. }
  2074. }
  2075. var customBubblingEventTypes =
  2076. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2077. .customBubblingEventTypes,
  2078. customDirectEventTypes =
  2079. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2080. .customDirectEventTypes;
  2081. var ReactNativeBridgeEventPlugin = {
  2082. eventTypes: {},
  2083. extractEvents: function(
  2084. topLevelType,
  2085. targetInst,
  2086. nativeEvent,
  2087. nativeEventTarget,
  2088. eventSystemFlags
  2089. ) {
  2090. if (targetInst == null) {
  2091. // Probably a node belonging to another renderer's tree.
  2092. return null;
  2093. }
  2094. var bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
  2095. var directDispatchConfig = customDirectEventTypes[topLevelType];
  2096. if (!(bubbleDispatchConfig || directDispatchConfig)) {
  2097. throw Error(
  2098. 'Unsupported top level event type "' + topLevelType + '" dispatched'
  2099. );
  2100. }
  2101. var event = SyntheticEvent.getPooled(
  2102. bubbleDispatchConfig || directDispatchConfig,
  2103. targetInst,
  2104. nativeEvent,
  2105. nativeEventTarget
  2106. );
  2107. if (bubbleDispatchConfig) {
  2108. accumulateTwoPhaseDispatches(event);
  2109. } else if (directDispatchConfig) {
  2110. accumulateDirectDispatches(event);
  2111. } else {
  2112. return null;
  2113. }
  2114. return event;
  2115. }
  2116. };
  2117. var ReactNativeEventPluginOrder = [
  2118. "ResponderEventPlugin",
  2119. "ReactNativeBridgeEventPlugin"
  2120. ];
  2121. /**
  2122. * Make sure essential globals are available and are patched correctly. Please don't remove this
  2123. * line. Bundles created by react-packager `require` it before executing any application code. This
  2124. * ensures it exists in the dependency graph and can be `require`d.
  2125. * TODO: require this in packager, not in React #10932517
  2126. */
  2127. /**
  2128. * Inject module for resolving DOM hierarchy and plugin ordering.
  2129. */
  2130. injectEventPluginOrder(ReactNativeEventPluginOrder);
  2131. /**
  2132. * Some important event plugins included by default (without having to require
  2133. * them).
  2134. */
  2135. injectEventPluginsByName({
  2136. ResponderEventPlugin: ResponderEventPlugin,
  2137. ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin
  2138. });
  2139. var instanceCache = new Map();
  2140. var instanceProps = new Map();
  2141. function precacheFiberNode(hostInst, tag) {
  2142. instanceCache.set(tag, hostInst);
  2143. }
  2144. function uncacheFiberNode(tag) {
  2145. instanceCache.delete(tag);
  2146. instanceProps.delete(tag);
  2147. }
  2148. function getInstanceFromTag(tag) {
  2149. return instanceCache.get(tag) || null;
  2150. }
  2151. function getTagFromInstance(inst) {
  2152. var nativeInstance = inst.stateNode;
  2153. var tag = nativeInstance._nativeTag;
  2154. if (tag === undefined) {
  2155. nativeInstance = nativeInstance.canonical;
  2156. tag = nativeInstance._nativeTag;
  2157. }
  2158. if (!tag) {
  2159. throw Error("All native instances should have a tag.");
  2160. }
  2161. return nativeInstance;
  2162. }
  2163. function getFiberCurrentPropsFromNode$1(stateNode) {
  2164. return instanceProps.get(stateNode._nativeTag) || null;
  2165. }
  2166. function updateFiberProps(tag, props) {
  2167. instanceProps.set(tag, props);
  2168. }
  2169. var PLUGIN_EVENT_SYSTEM = 1;
  2170. var enableProfilerTimer = true;
  2171. var enableFundamentalAPI = false;
  2172. var warnAboutStringRefs = false;
  2173. // the renderer. Such as when we're dispatching events or if third party
  2174. // libraries need to call batchedUpdates. Eventually, this API will go away when
  2175. // everything is batched by default. We'll then have a similar API to opt-out of
  2176. // scheduled work and instead do synchronous work.
  2177. // Defaults
  2178. var batchedUpdatesImpl = function(fn, bookkeeping) {
  2179. return fn(bookkeeping);
  2180. };
  2181. var isInsideEventHandler = false;
  2182. function batchedUpdates(fn, bookkeeping) {
  2183. if (isInsideEventHandler) {
  2184. // If we are currently inside another batch, we need to wait until it
  2185. // fully completes before restoring state.
  2186. return fn(bookkeeping);
  2187. }
  2188. isInsideEventHandler = true;
  2189. try {
  2190. return batchedUpdatesImpl(fn, bookkeeping);
  2191. } finally {
  2192. isInsideEventHandler = false;
  2193. }
  2194. }
  2195. function setBatchingImplementation(
  2196. _batchedUpdatesImpl,
  2197. _discreteUpdatesImpl,
  2198. _flushDiscreteUpdatesImpl,
  2199. _batchedEventUpdatesImpl
  2200. ) {
  2201. batchedUpdatesImpl = _batchedUpdatesImpl;
  2202. }
  2203. /**
  2204. * Internal queue of events that have accumulated their dispatches and are
  2205. * waiting to have their dispatches executed.
  2206. */
  2207. var eventQueue = null;
  2208. /**
  2209. * Dispatches an event and releases it back into the pool, unless persistent.
  2210. *
  2211. * @param {?object} event Synthetic event to be dispatched.
  2212. * @private
  2213. */
  2214. var executeDispatchesAndRelease = function(event) {
  2215. if (event) {
  2216. executeDispatchesInOrder(event);
  2217. if (!event.isPersistent()) {
  2218. event.constructor.release(event);
  2219. }
  2220. }
  2221. };
  2222. var executeDispatchesAndReleaseTopLevel = function(e) {
  2223. return executeDispatchesAndRelease(e);
  2224. };
  2225. function runEventsInBatch(events) {
  2226. if (events !== null) {
  2227. eventQueue = accumulateInto(eventQueue, events);
  2228. } // Set `eventQueue` to null before processing it so that we can tell if more
  2229. // events get enqueued while processing.
  2230. var processingEventQueue = eventQueue;
  2231. eventQueue = null;
  2232. if (!processingEventQueue) {
  2233. return;
  2234. }
  2235. forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
  2236. if (!!eventQueue) {
  2237. throw Error(
  2238. "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented."
  2239. );
  2240. } // This would be a good time to rethrow if any of the event handlers threw.
  2241. rethrowCaughtError();
  2242. }
  2243. /**
  2244. * Version of `ReactBrowserEventEmitter` that works on the receiving side of a
  2245. * serialized worker boundary.
  2246. */
  2247. // Shared default empty native event - conserve memory.
  2248. var EMPTY_NATIVE_EVENT = {};
  2249. /**
  2250. * Selects a subsequence of `Touch`es, without destroying `touches`.
  2251. *
  2252. * @param {Array<Touch>} touches Deserialized touch objects.
  2253. * @param {Array<number>} indices Indices by which to pull subsequence.
  2254. * @return {Array<Touch>} Subsequence of touch objects.
  2255. */
  2256. var touchSubsequence = function(touches, indices) {
  2257. var ret = [];
  2258. for (var i = 0; i < indices.length; i++) {
  2259. ret.push(touches[indices[i]]);
  2260. }
  2261. return ret;
  2262. };
  2263. /**
  2264. * TODO: Pool all of this.
  2265. *
  2266. * Destroys `touches` by removing touch objects at indices `indices`. This is
  2267. * to maintain compatibility with W3C touch "end" events, where the active
  2268. * touches don't include the set that has just been "ended".
  2269. *
  2270. * @param {Array<Touch>} touches Deserialized touch objects.
  2271. * @param {Array<number>} indices Indices to remove from `touches`.
  2272. * @return {Array<Touch>} Subsequence of removed touch objects.
  2273. */
  2274. var removeTouchesAtIndices = function(touches, indices) {
  2275. var rippedOut = []; // use an unsafe downcast to alias to nullable elements,
  2276. // so we can delete and then compact.
  2277. var temp = touches;
  2278. for (var i = 0; i < indices.length; i++) {
  2279. var index = indices[i];
  2280. rippedOut.push(touches[index]);
  2281. temp[index] = null;
  2282. }
  2283. var fillAt = 0;
  2284. for (var j = 0; j < temp.length; j++) {
  2285. var cur = temp[j];
  2286. if (cur !== null) {
  2287. temp[fillAt++] = cur;
  2288. }
  2289. }
  2290. temp.length = fillAt;
  2291. return rippedOut;
  2292. };
  2293. /**
  2294. * Internal version of `receiveEvent` in terms of normalized (non-tag)
  2295. * `rootNodeID`.
  2296. *
  2297. * @see receiveEvent.
  2298. *
  2299. * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
  2300. * @param {TopLevelType} topLevelType Top level type of event.
  2301. * @param {?object} nativeEventParam Object passed from native.
  2302. */
  2303. function _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam) {
  2304. var nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT;
  2305. var inst = getInstanceFromTag(rootNodeID);
  2306. var target = null;
  2307. if (inst != null) {
  2308. target = inst.stateNode;
  2309. }
  2310. batchedUpdates(function() {
  2311. runExtractedPluginEventsInBatch(
  2312. topLevelType,
  2313. inst,
  2314. nativeEvent,
  2315. target,
  2316. PLUGIN_EVENT_SYSTEM
  2317. );
  2318. }); // React Native doesn't use ReactControlledComponent but if it did, here's
  2319. // where it would do it.
  2320. }
  2321. /**
  2322. * Allows registered plugins an opportunity to extract events from top-level
  2323. * native browser events.
  2324. *
  2325. * @return {*} An accumulation of synthetic events.
  2326. * @internal
  2327. */
  2328. function extractPluginEvents(
  2329. topLevelType,
  2330. targetInst,
  2331. nativeEvent,
  2332. nativeEventTarget,
  2333. eventSystemFlags
  2334. ) {
  2335. var events = null;
  2336. for (var i = 0; i < plugins.length; i++) {
  2337. // Not every plugin in the ordering may be loaded at runtime.
  2338. var possiblePlugin = plugins[i];
  2339. if (possiblePlugin) {
  2340. var extractedEvents = possiblePlugin.extractEvents(
  2341. topLevelType,
  2342. targetInst,
  2343. nativeEvent,
  2344. nativeEventTarget,
  2345. eventSystemFlags
  2346. );
  2347. if (extractedEvents) {
  2348. events = accumulateInto(events, extractedEvents);
  2349. }
  2350. }
  2351. }
  2352. return events;
  2353. }
  2354. function runExtractedPluginEventsInBatch(
  2355. topLevelType,
  2356. targetInst,
  2357. nativeEvent,
  2358. nativeEventTarget,
  2359. eventSystemFlags
  2360. ) {
  2361. var events = extractPluginEvents(
  2362. topLevelType,
  2363. targetInst,
  2364. nativeEvent,
  2365. nativeEventTarget,
  2366. eventSystemFlags
  2367. );
  2368. runEventsInBatch(events);
  2369. }
  2370. /**
  2371. * Publicly exposed method on module for native objc to invoke when a top
  2372. * level event is extracted.
  2373. * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
  2374. * @param {TopLevelType} topLevelType Top level type of event.
  2375. * @param {object} nativeEventParam Object passed from native.
  2376. */
  2377. function receiveEvent(rootNodeID, topLevelType, nativeEventParam) {
  2378. _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam);
  2379. }
  2380. /**
  2381. * Simple multi-wrapper around `receiveEvent` that is intended to receive an
  2382. * efficient representation of `Touch` objects, and other information that
  2383. * can be used to construct W3C compliant `Event` and `Touch` lists.
  2384. *
  2385. * This may create dispatch behavior that differs than web touch handling. We
  2386. * loop through each of the changed touches and receive it as a single event.
  2387. * So two `touchStart`/`touchMove`s that occur simultaneously are received as
  2388. * two separate touch event dispatches - when they arguably should be one.
  2389. *
  2390. * This implementation reuses the `Touch` objects themselves as the `Event`s
  2391. * since we dispatch an event for each touch (though that might not be spec
  2392. * compliant). The main purpose of reusing them is to save allocations.
  2393. *
  2394. * TODO: Dispatch multiple changed touches in one event. The bubble path
  2395. * could be the first common ancestor of all the `changedTouches`.
  2396. *
  2397. * One difference between this behavior and W3C spec: cancelled touches will
  2398. * not appear in `.touches`, or in any future `.touches`, though they may
  2399. * still be "actively touching the surface".
  2400. *
  2401. * Web desktop polyfills only need to construct a fake touch event with
  2402. * identifier 0, also abandoning traditional click handlers.
  2403. */
  2404. function receiveTouches(eventTopLevelType, touches, changedIndices) {
  2405. var changedTouches =
  2406. eventTopLevelType === "topTouchEnd" ||
  2407. eventTopLevelType === "topTouchCancel"
  2408. ? removeTouchesAtIndices(touches, changedIndices)
  2409. : touchSubsequence(touches, changedIndices);
  2410. for (var jj = 0; jj < changedTouches.length; jj++) {
  2411. var touch = changedTouches[jj]; // Touch objects can fulfill the role of `DOM` `Event` objects if we set
  2412. // the `changedTouches`/`touches`. This saves allocations.
  2413. touch.changedTouches = changedTouches;
  2414. touch.touches = touches;
  2415. var nativeEvent = touch;
  2416. var rootNodeID = null;
  2417. var target = nativeEvent.target;
  2418. if (target !== null && target !== undefined) {
  2419. if (target < 1) {
  2420. {
  2421. error("A view is reporting that a touch occurred on tag zero.");
  2422. }
  2423. } else {
  2424. rootNodeID = target;
  2425. }
  2426. } // $FlowFixMe Shouldn't we *not* call it if rootNodeID is null?
  2427. _receiveRootNodeIDEvent(rootNodeID, eventTopLevelType, nativeEvent);
  2428. }
  2429. }
  2430. // Module provided by RN:
  2431. var ReactNativeGlobalResponderHandler = {
  2432. onChange: function(from, to, blockNativeResponder) {
  2433. if (to !== null) {
  2434. var tag = to.stateNode._nativeTag;
  2435. ReactNativePrivateInterface.UIManager.setJSResponder(
  2436. tag,
  2437. blockNativeResponder
  2438. );
  2439. } else {
  2440. ReactNativePrivateInterface.UIManager.clearJSResponder();
  2441. }
  2442. }
  2443. };
  2444. /**
  2445. * Register the event emitter with the native bridge
  2446. */
  2447. ReactNativePrivateInterface.RCTEventEmitter.register({
  2448. receiveEvent: receiveEvent,
  2449. receiveTouches: receiveTouches
  2450. });
  2451. setComponentTree(
  2452. getFiberCurrentPropsFromNode$1,
  2453. getInstanceFromTag,
  2454. getTagFromInstance
  2455. );
  2456. ResponderEventPlugin.injection.injectGlobalResponderHandler(
  2457. ReactNativeGlobalResponderHandler
  2458. );
  2459. /**
  2460. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  2461. * instance (key) and the internal representation (value). This allows public
  2462. * methods to accept the user facing instance as an argument and map them back
  2463. * to internal methods.
  2464. *
  2465. * Note that this module is currently shared and assumed to be stateless.
  2466. * If this becomes an actual Map, that will break.
  2467. */
  2468. function get(key) {
  2469. return key._reactInternalFiber;
  2470. }
  2471. function set(key, value) {
  2472. key._reactInternalFiber = value;
  2473. }
  2474. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  2475. // nor polyfill, then a plain number is used for performance.
  2476. var hasSymbol = typeof Symbol === "function" && Symbol.for;
  2477. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 0xeac7;
  2478. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 0xeaca;
  2479. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 0xeacb;
  2480. var REACT_STRICT_MODE_TYPE = hasSymbol
  2481. ? Symbol.for("react.strict_mode")
  2482. : 0xeacc;
  2483. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 0xead2;
  2484. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for("react.provider") : 0xeacd;
  2485. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for("react.context") : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  2486. var REACT_CONCURRENT_MODE_TYPE = hasSymbol
  2487. ? Symbol.for("react.concurrent_mode")
  2488. : 0xeacf;
  2489. var REACT_FORWARD_REF_TYPE = hasSymbol
  2490. ? Symbol.for("react.forward_ref")
  2491. : 0xead0;
  2492. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for("react.suspense") : 0xead1;
  2493. var REACT_SUSPENSE_LIST_TYPE = hasSymbol
  2494. ? Symbol.for("react.suspense_list")
  2495. : 0xead8;
  2496. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for("react.memo") : 0xead3;
  2497. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for("react.lazy") : 0xead4;
  2498. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for("react.block") : 0xead9;
  2499. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === "function" && Symbol.iterator;
  2500. var FAUX_ITERATOR_SYMBOL = "@@iterator";
  2501. function getIteratorFn(maybeIterable) {
  2502. if (maybeIterable === null || typeof maybeIterable !== "object") {
  2503. return null;
  2504. }
  2505. var maybeIterator =
  2506. (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
  2507. maybeIterable[FAUX_ITERATOR_SYMBOL];
  2508. if (typeof maybeIterator === "function") {
  2509. return maybeIterator;
  2510. }
  2511. return null;
  2512. }
  2513. // TODO: Move this to "react" once we can import from externals.
  2514. var Uninitialized = -1;
  2515. var Pending = 0;
  2516. var Resolved = 1;
  2517. var Rejected = 2;
  2518. function refineResolvedLazyComponent(lazyComponent) {
  2519. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  2520. }
  2521. function initializeLazyComponentType(lazyComponent) {
  2522. if (lazyComponent._status === Uninitialized) {
  2523. var ctor = lazyComponent._result;
  2524. if (!ctor) {
  2525. // TODO: Remove this later. THis only exists in case you use an older "react" package.
  2526. ctor = lazyComponent._ctor;
  2527. }
  2528. var thenable = ctor(); // Transition to the next state.
  2529. var pending = lazyComponent;
  2530. pending._status = Pending;
  2531. pending._result = thenable;
  2532. thenable.then(
  2533. function(moduleObject) {
  2534. if (lazyComponent._status === Pending) {
  2535. var defaultExport = moduleObject.default;
  2536. {
  2537. if (defaultExport === undefined) {
  2538. error(
  2539. "lazy: Expected the result of a dynamic import() call. " +
  2540. "Instead received: %s\n\nYour code should look like: \n " + // Break up imports to avoid accidentally parsing them as dependencies.
  2541. "const MyComponent = lazy(() => imp" +
  2542. "ort('./MyComponent'))",
  2543. moduleObject
  2544. );
  2545. }
  2546. } // Transition to the next state.
  2547. var resolved = lazyComponent;
  2548. resolved._status = Resolved;
  2549. resolved._result = defaultExport;
  2550. }
  2551. },
  2552. function(error) {
  2553. if (lazyComponent._status === Pending) {
  2554. // Transition to the next state.
  2555. var rejected = lazyComponent;
  2556. rejected._status = Rejected;
  2557. rejected._result = error;
  2558. }
  2559. }
  2560. );
  2561. }
  2562. }
  2563. function getWrappedName(outerType, innerType, wrapperName) {
  2564. var functionName = innerType.displayName || innerType.name || "";
  2565. return (
  2566. outerType.displayName ||
  2567. (functionName !== "" ? wrapperName + "(" + functionName + ")" : wrapperName)
  2568. );
  2569. }
  2570. function getContextName(type) {
  2571. return type.displayName || "Context";
  2572. }
  2573. function getComponentName(type) {
  2574. if (type == null) {
  2575. // Host root, text node or just invalid type.
  2576. return null;
  2577. }
  2578. {
  2579. if (typeof type.tag === "number") {
  2580. error(
  2581. "Received an unexpected object in getComponentName(). " +
  2582. "This is likely a bug in React. Please file an issue."
  2583. );
  2584. }
  2585. }
  2586. if (typeof type === "function") {
  2587. return type.displayName || type.name || null;
  2588. }
  2589. if (typeof type === "string") {
  2590. return type;
  2591. }
  2592. switch (type) {
  2593. case REACT_FRAGMENT_TYPE:
  2594. return "Fragment";
  2595. case REACT_PORTAL_TYPE:
  2596. return "Portal";
  2597. case REACT_PROFILER_TYPE:
  2598. return "Profiler";
  2599. case REACT_STRICT_MODE_TYPE:
  2600. return "StrictMode";
  2601. case REACT_SUSPENSE_TYPE:
  2602. return "Suspense";
  2603. case REACT_SUSPENSE_LIST_TYPE:
  2604. return "SuspenseList";
  2605. }
  2606. if (typeof type === "object") {
  2607. switch (type.$$typeof) {
  2608. case REACT_CONTEXT_TYPE:
  2609. var context = type;
  2610. return getContextName(context) + ".Consumer";
  2611. case REACT_PROVIDER_TYPE:
  2612. var provider = type;
  2613. return getContextName(provider._context) + ".Provider";
  2614. case REACT_FORWARD_REF_TYPE:
  2615. return getWrappedName(type, type.render, "ForwardRef");
  2616. case REACT_MEMO_TYPE:
  2617. return getComponentName(type.type);
  2618. case REACT_BLOCK_TYPE:
  2619. return getComponentName(type.render);
  2620. case REACT_LAZY_TYPE: {
  2621. var thenable = type;
  2622. var resolvedThenable = refineResolvedLazyComponent(thenable);
  2623. if (resolvedThenable) {
  2624. return getComponentName(resolvedThenable);
  2625. }
  2626. break;
  2627. }
  2628. }
  2629. }
  2630. return null;
  2631. }
  2632. // Don't change these two values. They're used by React Dev Tools.
  2633. var NoEffect =
  2634. /* */
  2635. 0;
  2636. var PerformedWork =
  2637. /* */
  2638. 1; // You can change the rest (and add more).
  2639. var Placement =
  2640. /* */
  2641. 2;
  2642. var Update =
  2643. /* */
  2644. 4;
  2645. var PlacementAndUpdate =
  2646. /* */
  2647. 6;
  2648. var Deletion =
  2649. /* */
  2650. 8;
  2651. var ContentReset =
  2652. /* */
  2653. 16;
  2654. var Callback =
  2655. /* */
  2656. 32;
  2657. var DidCapture =
  2658. /* */
  2659. 64;
  2660. var Ref =
  2661. /* */
  2662. 128;
  2663. var Snapshot =
  2664. /* */
  2665. 256;
  2666. var Passive =
  2667. /* */
  2668. 512;
  2669. var Hydrating =
  2670. /* */
  2671. 1024;
  2672. var HydratingAndUpdate =
  2673. /* */
  2674. 1028; // Passive & Update & Callback & Ref & Snapshot
  2675. var LifecycleEffectMask =
  2676. /* */
  2677. 932; // Union of all host effects
  2678. var HostEffectMask =
  2679. /* */
  2680. 2047;
  2681. var Incomplete =
  2682. /* */
  2683. 2048;
  2684. var ShouldCapture =
  2685. /* */
  2686. 4096;
  2687. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  2688. function getNearestMountedFiber(fiber) {
  2689. var node = fiber;
  2690. var nearestMounted = fiber;
  2691. if (!fiber.alternate) {
  2692. // If there is no alternate, this might be a new tree that isn't inserted
  2693. // yet. If it is, then it will have a pending insertion effect on it.
  2694. var nextNode = node;
  2695. do {
  2696. node = nextNode;
  2697. if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
  2698. // This is an insertion or in-progress hydration. The nearest possible
  2699. // mounted fiber is the parent but we need to continue to figure out
  2700. // if that one is still mounted.
  2701. nearestMounted = node.return;
  2702. }
  2703. nextNode = node.return;
  2704. } while (nextNode);
  2705. } else {
  2706. while (node.return) {
  2707. node = node.return;
  2708. }
  2709. }
  2710. if (node.tag === HostRoot) {
  2711. // TODO: Check if this was a nested HostRoot when used with
  2712. // renderContainerIntoSubtree.
  2713. return nearestMounted;
  2714. } // If we didn't hit the root, that means that we're in an disconnected tree
  2715. // that has been unmounted.
  2716. return null;
  2717. }
  2718. function isFiberMounted(fiber) {
  2719. return getNearestMountedFiber(fiber) === fiber;
  2720. }
  2721. function isMounted(component) {
  2722. {
  2723. var owner = ReactCurrentOwner.current;
  2724. if (owner !== null && owner.tag === ClassComponent) {
  2725. var ownerFiber = owner;
  2726. var instance = ownerFiber.stateNode;
  2727. if (!instance._warnedAboutRefsInRender) {
  2728. error(
  2729. "%s is accessing isMounted inside its render() function. " +
  2730. "render() should be a pure function of props and state. It should " +
  2731. "never access something that requires stale data from the previous " +
  2732. "render, such as refs. Move this logic to componentDidMount and " +
  2733. "componentDidUpdate instead.",
  2734. getComponentName(ownerFiber.type) || "A component"
  2735. );
  2736. }
  2737. instance._warnedAboutRefsInRender = true;
  2738. }
  2739. }
  2740. var fiber = get(component);
  2741. if (!fiber) {
  2742. return false;
  2743. }
  2744. return getNearestMountedFiber(fiber) === fiber;
  2745. }
  2746. function assertIsMounted(fiber) {
  2747. if (!(getNearestMountedFiber(fiber) === fiber)) {
  2748. throw Error("Unable to find node on an unmounted component.");
  2749. }
  2750. }
  2751. function findCurrentFiberUsingSlowPath(fiber) {
  2752. var alternate = fiber.alternate;
  2753. if (!alternate) {
  2754. // If there is no alternate, then we only need to check if it is mounted.
  2755. var nearestMounted = getNearestMountedFiber(fiber);
  2756. if (!(nearestMounted !== null)) {
  2757. throw Error("Unable to find node on an unmounted component.");
  2758. }
  2759. if (nearestMounted !== fiber) {
  2760. return null;
  2761. }
  2762. return fiber;
  2763. } // If we have two possible branches, we'll walk backwards up to the root
  2764. // to see what path the root points to. On the way we may hit one of the
  2765. // special cases and we'll deal with them.
  2766. var a = fiber;
  2767. var b = alternate;
  2768. while (true) {
  2769. var parentA = a.return;
  2770. if (parentA === null) {
  2771. // We're at the root.
  2772. break;
  2773. }
  2774. var parentB = parentA.alternate;
  2775. if (parentB === null) {
  2776. // There is no alternate. This is an unusual case. Currently, it only
  2777. // happens when a Suspense component is hidden. An extra fragment fiber
  2778. // is inserted in between the Suspense fiber and its children. Skip
  2779. // over this extra fragment fiber and proceed to the next parent.
  2780. var nextParent = parentA.return;
  2781. if (nextParent !== null) {
  2782. a = b = nextParent;
  2783. continue;
  2784. } // If there's no parent, we're at the root.
  2785. break;
  2786. } // If both copies of the parent fiber point to the same child, we can
  2787. // assume that the child is current. This happens when we bailout on low
  2788. // priority: the bailed out fiber's child reuses the current child.
  2789. if (parentA.child === parentB.child) {
  2790. var child = parentA.child;
  2791. while (child) {
  2792. if (child === a) {
  2793. // We've determined that A is the current branch.
  2794. assertIsMounted(parentA);
  2795. return fiber;
  2796. }
  2797. if (child === b) {
  2798. // We've determined that B is the current branch.
  2799. assertIsMounted(parentA);
  2800. return alternate;
  2801. }
  2802. child = child.sibling;
  2803. } // We should never have an alternate for any mounting node. So the only
  2804. // way this could possibly happen is if this was unmounted, if at all.
  2805. {
  2806. throw Error("Unable to find node on an unmounted component.");
  2807. }
  2808. }
  2809. if (a.return !== b.return) {
  2810. // The return pointer of A and the return pointer of B point to different
  2811. // fibers. We assume that return pointers never criss-cross, so A must
  2812. // belong to the child set of A.return, and B must belong to the child
  2813. // set of B.return.
  2814. a = parentA;
  2815. b = parentB;
  2816. } else {
  2817. // The return pointers point to the same fiber. We'll have to use the
  2818. // default, slow path: scan the child sets of each parent alternate to see
  2819. // which child belongs to which set.
  2820. //
  2821. // Search parent A's child set
  2822. var didFindChild = false;
  2823. var _child = parentA.child;
  2824. while (_child) {
  2825. if (_child === a) {
  2826. didFindChild = true;
  2827. a = parentA;
  2828. b = parentB;
  2829. break;
  2830. }
  2831. if (_child === b) {
  2832. didFindChild = true;
  2833. b = parentA;
  2834. a = parentB;
  2835. break;
  2836. }
  2837. _child = _child.sibling;
  2838. }
  2839. if (!didFindChild) {
  2840. // Search parent B's child set
  2841. _child = parentB.child;
  2842. while (_child) {
  2843. if (_child === a) {
  2844. didFindChild = true;
  2845. a = parentB;
  2846. b = parentA;
  2847. break;
  2848. }
  2849. if (_child === b) {
  2850. didFindChild = true;
  2851. b = parentB;
  2852. a = parentA;
  2853. break;
  2854. }
  2855. _child = _child.sibling;
  2856. }
  2857. if (!didFindChild) {
  2858. throw Error(
  2859. "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue."
  2860. );
  2861. }
  2862. }
  2863. }
  2864. if (!(a.alternate === b)) {
  2865. throw Error(
  2866. "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue."
  2867. );
  2868. }
  2869. } // If the root is not a host container, we're in a disconnected tree. I.e.
  2870. // unmounted.
  2871. if (!(a.tag === HostRoot)) {
  2872. throw Error("Unable to find node on an unmounted component.");
  2873. }
  2874. if (a.stateNode.current === a) {
  2875. // We've determined that A is the current branch.
  2876. return fiber;
  2877. } // Otherwise B has to be current branch.
  2878. return alternate;
  2879. }
  2880. function findCurrentHostFiber(parent) {
  2881. var currentParent = findCurrentFiberUsingSlowPath(parent);
  2882. if (!currentParent) {
  2883. return null;
  2884. } // Next we'll drill down this component to find the first HostComponent/Text.
  2885. var node = currentParent;
  2886. while (true) {
  2887. if (node.tag === HostComponent || node.tag === HostText) {
  2888. return node;
  2889. } else if (node.child) {
  2890. node.child.return = node;
  2891. node = node.child;
  2892. continue;
  2893. }
  2894. if (node === currentParent) {
  2895. return null;
  2896. }
  2897. while (!node.sibling) {
  2898. if (!node.return || node.return === currentParent) {
  2899. return null;
  2900. }
  2901. node = node.return;
  2902. }
  2903. node.sibling.return = node.return;
  2904. node = node.sibling;
  2905. } // Flow needs the return null here, but ESLint complains about it.
  2906. // eslint-disable-next-line no-unreachable
  2907. return null;
  2908. }
  2909. // Modules provided by RN:
  2910. var emptyObject = {};
  2911. /**
  2912. * Create a payload that contains all the updates between two sets of props.
  2913. *
  2914. * These helpers are all encapsulated into a single module, because they use
  2915. * mutation as a performance optimization which leads to subtle shared
  2916. * dependencies between the code paths. To avoid this mutable state leaking
  2917. * across modules, I've kept them isolated to this module.
  2918. */
  2919. // Tracks removed keys
  2920. var removedKeys = null;
  2921. var removedKeyCount = 0;
  2922. var deepDifferOptions = {
  2923. unsafelyIgnoreFunctions: true
  2924. };
  2925. function defaultDiffer(prevProp, nextProp) {
  2926. if (typeof nextProp !== "object" || nextProp === null) {
  2927. // Scalars have already been checked for equality
  2928. return true;
  2929. } else {
  2930. // For objects and arrays, the default diffing algorithm is a deep compare
  2931. return ReactNativePrivateInterface.deepDiffer(
  2932. prevProp,
  2933. nextProp,
  2934. deepDifferOptions
  2935. );
  2936. }
  2937. }
  2938. function restoreDeletedValuesInNestedArray(
  2939. updatePayload,
  2940. node,
  2941. validAttributes
  2942. ) {
  2943. if (Array.isArray(node)) {
  2944. var i = node.length;
  2945. while (i-- && removedKeyCount > 0) {
  2946. restoreDeletedValuesInNestedArray(
  2947. updatePayload,
  2948. node[i],
  2949. validAttributes
  2950. );
  2951. }
  2952. } else if (node && removedKeyCount > 0) {
  2953. var obj = node;
  2954. for (var propKey in removedKeys) {
  2955. if (!removedKeys[propKey]) {
  2956. continue;
  2957. }
  2958. var nextProp = obj[propKey];
  2959. if (nextProp === undefined) {
  2960. continue;
  2961. }
  2962. var attributeConfig = validAttributes[propKey];
  2963. if (!attributeConfig) {
  2964. continue; // not a valid native prop
  2965. }
  2966. if (typeof nextProp === "function") {
  2967. nextProp = true;
  2968. }
  2969. if (typeof nextProp === "undefined") {
  2970. nextProp = null;
  2971. }
  2972. if (typeof attributeConfig !== "object") {
  2973. // case: !Object is the default case
  2974. updatePayload[propKey] = nextProp;
  2975. } else if (
  2976. typeof attributeConfig.diff === "function" ||
  2977. typeof attributeConfig.process === "function"
  2978. ) {
  2979. // case: CustomAttributeConfiguration
  2980. var nextValue =
  2981. typeof attributeConfig.process === "function"
  2982. ? attributeConfig.process(nextProp)
  2983. : nextProp;
  2984. updatePayload[propKey] = nextValue;
  2985. }
  2986. removedKeys[propKey] = false;
  2987. removedKeyCount--;
  2988. }
  2989. }
  2990. }
  2991. function diffNestedArrayProperty(
  2992. updatePayload,
  2993. prevArray,
  2994. nextArray,
  2995. validAttributes
  2996. ) {
  2997. var minLength =
  2998. prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
  2999. var i;
  3000. for (i = 0; i < minLength; i++) {
  3001. // Diff any items in the array in the forward direction. Repeated keys
  3002. // will be overwritten by later values.
  3003. updatePayload = diffNestedProperty(
  3004. updatePayload,
  3005. prevArray[i],
  3006. nextArray[i],
  3007. validAttributes
  3008. );
  3009. }
  3010. for (; i < prevArray.length; i++) {
  3011. // Clear out all remaining properties.
  3012. updatePayload = clearNestedProperty(
  3013. updatePayload,
  3014. prevArray[i],
  3015. validAttributes
  3016. );
  3017. }
  3018. for (; i < nextArray.length; i++) {
  3019. // Add all remaining properties.
  3020. updatePayload = addNestedProperty(
  3021. updatePayload,
  3022. nextArray[i],
  3023. validAttributes
  3024. );
  3025. }
  3026. return updatePayload;
  3027. }
  3028. function diffNestedProperty(
  3029. updatePayload,
  3030. prevProp,
  3031. nextProp,
  3032. validAttributes
  3033. ) {
  3034. if (!updatePayload && prevProp === nextProp) {
  3035. // If no properties have been added, then we can bail out quickly on object
  3036. // equality.
  3037. return updatePayload;
  3038. }
  3039. if (!prevProp || !nextProp) {
  3040. if (nextProp) {
  3041. return addNestedProperty(updatePayload, nextProp, validAttributes);
  3042. }
  3043. if (prevProp) {
  3044. return clearNestedProperty(updatePayload, prevProp, validAttributes);
  3045. }
  3046. return updatePayload;
  3047. }
  3048. if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
  3049. // Both are leaves, we can diff the leaves.
  3050. return diffProperties(updatePayload, prevProp, nextProp, validAttributes);
  3051. }
  3052. if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
  3053. // Both are arrays, we can diff the arrays.
  3054. return diffNestedArrayProperty(
  3055. updatePayload,
  3056. prevProp,
  3057. nextProp,
  3058. validAttributes
  3059. );
  3060. }
  3061. if (Array.isArray(prevProp)) {
  3062. return diffProperties(
  3063. updatePayload, // $FlowFixMe - We know that this is always an object when the input is.
  3064. ReactNativePrivateInterface.flattenStyle(prevProp), // $FlowFixMe - We know that this isn't an array because of above flow.
  3065. nextProp,
  3066. validAttributes
  3067. );
  3068. }
  3069. return diffProperties(
  3070. updatePayload,
  3071. prevProp, // $FlowFixMe - We know that this is always an object when the input is.
  3072. ReactNativePrivateInterface.flattenStyle(nextProp),
  3073. validAttributes
  3074. );
  3075. }
  3076. /**
  3077. * addNestedProperty takes a single set of props and valid attribute
  3078. * attribute configurations. It processes each prop and adds it to the
  3079. * updatePayload.
  3080. */
  3081. function addNestedProperty(updatePayload, nextProp, validAttributes) {
  3082. if (!nextProp) {
  3083. return updatePayload;
  3084. }
  3085. if (!Array.isArray(nextProp)) {
  3086. // Add each property of the leaf.
  3087. return addProperties(updatePayload, nextProp, validAttributes);
  3088. }
  3089. for (var i = 0; i < nextProp.length; i++) {
  3090. // Add all the properties of the array.
  3091. updatePayload = addNestedProperty(
  3092. updatePayload,
  3093. nextProp[i],
  3094. validAttributes
  3095. );
  3096. }
  3097. return updatePayload;
  3098. }
  3099. /**
  3100. * clearNestedProperty takes a single set of props and valid attributes. It
  3101. * adds a null sentinel to the updatePayload, for each prop key.
  3102. */
  3103. function clearNestedProperty(updatePayload, prevProp, validAttributes) {
  3104. if (!prevProp) {
  3105. return updatePayload;
  3106. }
  3107. if (!Array.isArray(prevProp)) {
  3108. // Add each property of the leaf.
  3109. return clearProperties(updatePayload, prevProp, validAttributes);
  3110. }
  3111. for (var i = 0; i < prevProp.length; i++) {
  3112. // Add all the properties of the array.
  3113. updatePayload = clearNestedProperty(
  3114. updatePayload,
  3115. prevProp[i],
  3116. validAttributes
  3117. );
  3118. }
  3119. return updatePayload;
  3120. }
  3121. /**
  3122. * diffProperties takes two sets of props and a set of valid attributes
  3123. * and write to updatePayload the values that changed or were deleted.
  3124. * If no updatePayload is provided, a new one is created and returned if
  3125. * anything changed.
  3126. */
  3127. function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
  3128. var attributeConfig;
  3129. var nextProp;
  3130. var prevProp;
  3131. for (var propKey in nextProps) {
  3132. attributeConfig = validAttributes[propKey];
  3133. if (!attributeConfig) {
  3134. continue; // not a valid native prop
  3135. }
  3136. prevProp = prevProps[propKey];
  3137. nextProp = nextProps[propKey]; // functions are converted to booleans as markers that the associated
  3138. // events should be sent from native.
  3139. if (typeof nextProp === "function") {
  3140. nextProp = true; // If nextProp is not a function, then don't bother changing prevProp
  3141. // since nextProp will win and go into the updatePayload regardless.
  3142. if (typeof prevProp === "function") {
  3143. prevProp = true;
  3144. }
  3145. } // An explicit value of undefined is treated as a null because it overrides
  3146. // any other preceding value.
  3147. if (typeof nextProp === "undefined") {
  3148. nextProp = null;
  3149. if (typeof prevProp === "undefined") {
  3150. prevProp = null;
  3151. }
  3152. }
  3153. if (removedKeys) {
  3154. removedKeys[propKey] = false;
  3155. }
  3156. if (updatePayload && updatePayload[propKey] !== undefined) {
  3157. // Something else already triggered an update to this key because another
  3158. // value diffed. Since we're now later in the nested arrays our value is
  3159. // more important so we need to calculate it and override the existing
  3160. // value. It doesn't matter if nothing changed, we'll set it anyway.
  3161. // Pattern match on: attributeConfig
  3162. if (typeof attributeConfig !== "object") {
  3163. // case: !Object is the default case
  3164. updatePayload[propKey] = nextProp;
  3165. } else if (
  3166. typeof attributeConfig.diff === "function" ||
  3167. typeof attributeConfig.process === "function"
  3168. ) {
  3169. // case: CustomAttributeConfiguration
  3170. var nextValue =
  3171. typeof attributeConfig.process === "function"
  3172. ? attributeConfig.process(nextProp)
  3173. : nextProp;
  3174. updatePayload[propKey] = nextValue;
  3175. }
  3176. continue;
  3177. }
  3178. if (prevProp === nextProp) {
  3179. continue; // nothing changed
  3180. } // Pattern match on: attributeConfig
  3181. if (typeof attributeConfig !== "object") {
  3182. // case: !Object is the default case
  3183. if (defaultDiffer(prevProp, nextProp)) {
  3184. // a normal leaf has changed
  3185. (updatePayload || (updatePayload = {}))[propKey] = nextProp;
  3186. }
  3187. } else if (
  3188. typeof attributeConfig.diff === "function" ||
  3189. typeof attributeConfig.process === "function"
  3190. ) {
  3191. // case: CustomAttributeConfiguration
  3192. var shouldUpdate =
  3193. prevProp === undefined ||
  3194. (typeof attributeConfig.diff === "function"
  3195. ? attributeConfig.diff(prevProp, nextProp)
  3196. : defaultDiffer(prevProp, nextProp));
  3197. if (shouldUpdate) {
  3198. var _nextValue =
  3199. typeof attributeConfig.process === "function"
  3200. ? attributeConfig.process(nextProp)
  3201. : nextProp;
  3202. (updatePayload || (updatePayload = {}))[propKey] = _nextValue;
  3203. }
  3204. } else {
  3205. // default: fallthrough case when nested properties are defined
  3206. removedKeys = null;
  3207. removedKeyCount = 0; // We think that attributeConfig is not CustomAttributeConfiguration at
  3208. // this point so we assume it must be AttributeConfiguration.
  3209. updatePayload = diffNestedProperty(
  3210. updatePayload,
  3211. prevProp,
  3212. nextProp,
  3213. attributeConfig
  3214. );
  3215. if (removedKeyCount > 0 && updatePayload) {
  3216. restoreDeletedValuesInNestedArray(
  3217. updatePayload,
  3218. nextProp,
  3219. attributeConfig
  3220. );
  3221. removedKeys = null;
  3222. }
  3223. }
  3224. } // Also iterate through all the previous props to catch any that have been
  3225. // removed and make sure native gets the signal so it can reset them to the
  3226. // default.
  3227. for (var _propKey in prevProps) {
  3228. if (nextProps[_propKey] !== undefined) {
  3229. continue; // we've already covered this key in the previous pass
  3230. }
  3231. attributeConfig = validAttributes[_propKey];
  3232. if (!attributeConfig) {
  3233. continue; // not a valid native prop
  3234. }
  3235. if (updatePayload && updatePayload[_propKey] !== undefined) {
  3236. // This was already updated to a diff result earlier.
  3237. continue;
  3238. }
  3239. prevProp = prevProps[_propKey];
  3240. if (prevProp === undefined) {
  3241. continue; // was already empty anyway
  3242. } // Pattern match on: attributeConfig
  3243. if (
  3244. typeof attributeConfig !== "object" ||
  3245. typeof attributeConfig.diff === "function" ||
  3246. typeof attributeConfig.process === "function"
  3247. ) {
  3248. // case: CustomAttributeConfiguration | !Object
  3249. // Flag the leaf property for removal by sending a sentinel.
  3250. (updatePayload || (updatePayload = {}))[_propKey] = null;
  3251. if (!removedKeys) {
  3252. removedKeys = {};
  3253. }
  3254. if (!removedKeys[_propKey]) {
  3255. removedKeys[_propKey] = true;
  3256. removedKeyCount++;
  3257. }
  3258. } else {
  3259. // default:
  3260. // This is a nested attribute configuration where all the properties
  3261. // were removed so we need to go through and clear out all of them.
  3262. updatePayload = clearNestedProperty(
  3263. updatePayload,
  3264. prevProp,
  3265. attributeConfig
  3266. );
  3267. }
  3268. }
  3269. return updatePayload;
  3270. }
  3271. /**
  3272. * addProperties adds all the valid props to the payload after being processed.
  3273. */
  3274. function addProperties(updatePayload, props, validAttributes) {
  3275. // TODO: Fast path
  3276. return diffProperties(updatePayload, emptyObject, props, validAttributes);
  3277. }
  3278. /**
  3279. * clearProperties clears all the previous props by adding a null sentinel
  3280. * to the payload for each valid key.
  3281. */
  3282. function clearProperties(updatePayload, prevProps, validAttributes) {
  3283. // TODO: Fast path
  3284. return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
  3285. }
  3286. function create(props, validAttributes) {
  3287. return addProperties(
  3288. null, // updatePayload
  3289. props,
  3290. validAttributes
  3291. );
  3292. }
  3293. function diff(prevProps, nextProps, validAttributes) {
  3294. return diffProperties(
  3295. null, // updatePayload
  3296. prevProps,
  3297. nextProps,
  3298. validAttributes
  3299. );
  3300. }
  3301. /**
  3302. * In the future, we should cleanup callbacks by cancelling them instead of
  3303. * using this.
  3304. */
  3305. function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
  3306. return function() {
  3307. if (!callback) {
  3308. return undefined;
  3309. } // This protects against createClass() components.
  3310. // We don't know if there is code depending on it.
  3311. // We intentionally don't use isMounted() because even accessing
  3312. // isMounted property on a React ES6 class will trigger a warning.
  3313. if (typeof context.__isMounted === "boolean") {
  3314. if (!context.__isMounted) {
  3315. return undefined;
  3316. }
  3317. } // FIXME: there used to be other branches that protected
  3318. // against unmounted host components. But RN host components don't
  3319. // define isMounted() anymore, so those checks didn't do anything.
  3320. // They caused false positive warning noise so we removed them:
  3321. // https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
  3322. // However, this means that the callback is NOT guaranteed to be safe
  3323. // for host components. The solution we should implement is to make
  3324. // UIManager.measure() and similar calls truly cancelable. Then we
  3325. // can change our own code calling them to cancel when something unmounts.
  3326. return callback.apply(context, arguments);
  3327. };
  3328. }
  3329. function warnForStyleProps(props, validAttributes) {
  3330. {
  3331. for (var key in validAttributes.style) {
  3332. if (!(validAttributes[key] || props[key] === undefined)) {
  3333. error(
  3334. "You are setting the style `{ %s" +
  3335. ": ... }` as a prop. You " +
  3336. "should nest it in a style object. " +
  3337. "E.g. `{ style: { %s" +
  3338. ": ... } }`",
  3339. key,
  3340. key
  3341. );
  3342. }
  3343. }
  3344. }
  3345. }
  3346. var ReactNativeFiberHostComponent =
  3347. /*#__PURE__*/
  3348. (function() {
  3349. function ReactNativeFiberHostComponent(
  3350. tag,
  3351. viewConfig,
  3352. internalInstanceHandleDEV
  3353. ) {
  3354. this._nativeTag = tag;
  3355. this._children = [];
  3356. this.viewConfig = viewConfig;
  3357. {
  3358. this._internalFiberInstanceHandleDEV = internalInstanceHandleDEV;
  3359. }
  3360. }
  3361. var _proto = ReactNativeFiberHostComponent.prototype;
  3362. _proto.blur = function blur() {
  3363. ReactNativePrivateInterface.TextInputState.blurTextInput(this);
  3364. };
  3365. _proto.focus = function focus() {
  3366. ReactNativePrivateInterface.TextInputState.focusTextInput(this);
  3367. };
  3368. _proto.measure = function measure(callback) {
  3369. ReactNativePrivateInterface.UIManager.measure(
  3370. this._nativeTag,
  3371. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3372. );
  3373. };
  3374. _proto.measureInWindow = function measureInWindow(callback) {
  3375. ReactNativePrivateInterface.UIManager.measureInWindow(
  3376. this._nativeTag,
  3377. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3378. );
  3379. };
  3380. _proto.measureLayout = function measureLayout(
  3381. relativeToNativeNode,
  3382. onSuccess,
  3383. onFail
  3384. ) /* currently unused */
  3385. {
  3386. var relativeNode;
  3387. if (typeof relativeToNativeNode === "number") {
  3388. // Already a node handle
  3389. relativeNode = relativeToNativeNode;
  3390. } else {
  3391. var nativeNode = relativeToNativeNode;
  3392. if (nativeNode._nativeTag) {
  3393. relativeNode = nativeNode._nativeTag;
  3394. }
  3395. }
  3396. if (relativeNode == null) {
  3397. {
  3398. error(
  3399. "Warning: ref.measureLayout must be called with a node handle or a ref to a native component."
  3400. );
  3401. }
  3402. return;
  3403. }
  3404. ReactNativePrivateInterface.UIManager.measureLayout(
  3405. this._nativeTag,
  3406. relativeNode,
  3407. mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
  3408. mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess)
  3409. );
  3410. };
  3411. _proto.setNativeProps = function setNativeProps(nativeProps) {
  3412. {
  3413. warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
  3414. }
  3415. var updatePayload = create(nativeProps, this.viewConfig.validAttributes); // Avoid the overhead of bridge calls if there's no update.
  3416. // This is an expensive no-op for Android, and causes an unnecessary
  3417. // view invalidation for certain components (eg RCTTextInput) on iOS.
  3418. if (updatePayload != null) {
  3419. ReactNativePrivateInterface.UIManager.updateView(
  3420. this._nativeTag,
  3421. this.viewConfig.uiViewClassName,
  3422. updatePayload
  3423. );
  3424. }
  3425. };
  3426. return ReactNativeFiberHostComponent;
  3427. })(); // eslint-disable-next-line no-unused-expressions
  3428. // can re-export everything from this module.
  3429. function shim() {
  3430. {
  3431. throw Error(
  3432. "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue."
  3433. );
  3434. }
  3435. } // Hydration (when unsupported)
  3436. var isSuspenseInstancePending = shim;
  3437. var isSuspenseInstanceFallback = shim;
  3438. var hydrateTextInstance = shim;
  3439. var getViewConfigForType =
  3440. ReactNativePrivateInterface.ReactNativeViewConfigRegistry.get;
  3441. var UPDATE_SIGNAL = {};
  3442. {
  3443. Object.freeze(UPDATE_SIGNAL);
  3444. } // Counter for uniquely identifying views.
  3445. // % 10 === 1 means it is a rootTag.
  3446. // % 2 === 0 means it is a Fabric tag.
  3447. var nextReactTag = 3;
  3448. function allocateTag() {
  3449. var tag = nextReactTag;
  3450. if (tag % 10 === 1) {
  3451. tag += 2;
  3452. }
  3453. nextReactTag = tag + 2;
  3454. return tag;
  3455. }
  3456. function recursivelyUncacheFiberNode(node) {
  3457. if (typeof node === "number") {
  3458. // Leaf node (eg text)
  3459. uncacheFiberNode(node);
  3460. } else {
  3461. uncacheFiberNode(node._nativeTag);
  3462. node._children.forEach(recursivelyUncacheFiberNode);
  3463. }
  3464. }
  3465. function appendInitialChild(parentInstance, child) {
  3466. parentInstance._children.push(child);
  3467. }
  3468. function createInstance(
  3469. type,
  3470. props,
  3471. rootContainerInstance,
  3472. hostContext,
  3473. internalInstanceHandle
  3474. ) {
  3475. var tag = allocateTag();
  3476. var viewConfig = getViewConfigForType(type);
  3477. {
  3478. for (var key in viewConfig.validAttributes) {
  3479. if (props.hasOwnProperty(key)) {
  3480. ReactNativePrivateInterface.deepFreezeAndThrowOnMutationInDev(
  3481. props[key]
  3482. );
  3483. }
  3484. }
  3485. }
  3486. var updatePayload = create(props, viewConfig.validAttributes);
  3487. ReactNativePrivateInterface.UIManager.createView(
  3488. tag, // reactTag
  3489. viewConfig.uiViewClassName, // viewName
  3490. rootContainerInstance, // rootTag
  3491. updatePayload // props
  3492. );
  3493. var component = new ReactNativeFiberHostComponent(
  3494. tag,
  3495. viewConfig,
  3496. internalInstanceHandle
  3497. );
  3498. precacheFiberNode(internalInstanceHandle, tag);
  3499. updateFiberProps(tag, props); // Not sure how to avoid this cast. Flow is okay if the component is defined
  3500. // in the same file but if it's external it can't see the types.
  3501. return component;
  3502. }
  3503. function createTextInstance(
  3504. text,
  3505. rootContainerInstance,
  3506. hostContext,
  3507. internalInstanceHandle
  3508. ) {
  3509. if (!hostContext.isInAParentText) {
  3510. throw Error("Text strings must be rendered within a <Text> component.");
  3511. }
  3512. var tag = allocateTag();
  3513. ReactNativePrivateInterface.UIManager.createView(
  3514. tag, // reactTag
  3515. "RCTRawText", // viewName
  3516. rootContainerInstance, // rootTag
  3517. {
  3518. text: text
  3519. } // props
  3520. );
  3521. precacheFiberNode(internalInstanceHandle, tag);
  3522. return tag;
  3523. }
  3524. function finalizeInitialChildren(
  3525. parentInstance,
  3526. type,
  3527. props,
  3528. rootContainerInstance,
  3529. hostContext
  3530. ) {
  3531. // Don't send a no-op message over the bridge.
  3532. if (parentInstance._children.length === 0) {
  3533. return false;
  3534. } // Map from child objects to native tags.
  3535. // Either way we need to pass a copy of the Array to prevent it from being frozen.
  3536. var nativeTags = parentInstance._children.map(function(child) {
  3537. return typeof child === "number"
  3538. ? child // Leaf node (eg text)
  3539. : child._nativeTag;
  3540. });
  3541. ReactNativePrivateInterface.UIManager.setChildren(
  3542. parentInstance._nativeTag, // containerTag
  3543. nativeTags // reactTags
  3544. );
  3545. return false;
  3546. }
  3547. function getRootHostContext(rootContainerInstance) {
  3548. return {
  3549. isInAParentText: false
  3550. };
  3551. }
  3552. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  3553. var prevIsInAParentText = parentHostContext.isInAParentText;
  3554. var isInAParentText =
  3555. type === "AndroidTextInput" || // Android
  3556. type === "RCTMultilineTextInputView" || // iOS
  3557. type === "RCTSinglelineTextInputView" || // iOS
  3558. type === "RCTText" ||
  3559. type === "RCTVirtualText";
  3560. if (prevIsInAParentText !== isInAParentText) {
  3561. return {
  3562. isInAParentText: isInAParentText
  3563. };
  3564. } else {
  3565. return parentHostContext;
  3566. }
  3567. }
  3568. function getPublicInstance(instance) {
  3569. return instance;
  3570. }
  3571. function prepareForCommit(containerInfo) {
  3572. // Noop
  3573. }
  3574. function prepareUpdate(
  3575. instance,
  3576. type,
  3577. oldProps,
  3578. newProps,
  3579. rootContainerInstance,
  3580. hostContext
  3581. ) {
  3582. return UPDATE_SIGNAL;
  3583. }
  3584. function resetAfterCommit(containerInfo) {
  3585. // Noop
  3586. }
  3587. var scheduleTimeout = setTimeout;
  3588. var cancelTimeout = clearTimeout;
  3589. var noTimeout = -1;
  3590. function shouldDeprioritizeSubtree(type, props) {
  3591. return false;
  3592. }
  3593. function shouldSetTextContent(type, props) {
  3594. // TODO (bvaughn) Revisit this decision.
  3595. // Always returning false simplifies the createInstance() implementation,
  3596. // But creates an additional child Fiber for raw text children.
  3597. // No additional native views are created though.
  3598. // It's not clear to me which is better so I'm deferring for now.
  3599. // More context @ github.com/facebook/react/pull/8560#discussion_r92111303
  3600. return false;
  3601. } // -------------------
  3602. function appendChild(parentInstance, child) {
  3603. var childTag = typeof child === "number" ? child : child._nativeTag;
  3604. var children = parentInstance._children;
  3605. var index = children.indexOf(child);
  3606. if (index >= 0) {
  3607. children.splice(index, 1);
  3608. children.push(child);
  3609. ReactNativePrivateInterface.UIManager.manageChildren(
  3610. parentInstance._nativeTag, // containerTag
  3611. [index], // moveFromIndices
  3612. [children.length - 1], // moveToIndices
  3613. [], // addChildReactTags
  3614. [], // addAtIndices
  3615. [] // removeAtIndices
  3616. );
  3617. } else {
  3618. children.push(child);
  3619. ReactNativePrivateInterface.UIManager.manageChildren(
  3620. parentInstance._nativeTag, // containerTag
  3621. [], // moveFromIndices
  3622. [], // moveToIndices
  3623. [childTag], // addChildReactTags
  3624. [children.length - 1], // addAtIndices
  3625. [] // removeAtIndices
  3626. );
  3627. }
  3628. }
  3629. function appendChildToContainer(parentInstance, child) {
  3630. var childTag = typeof child === "number" ? child : child._nativeTag;
  3631. ReactNativePrivateInterface.UIManager.setChildren(
  3632. parentInstance, // containerTag
  3633. [childTag] // reactTags
  3634. );
  3635. }
  3636. function commitTextUpdate(textInstance, oldText, newText) {
  3637. ReactNativePrivateInterface.UIManager.updateView(
  3638. textInstance, // reactTag
  3639. "RCTRawText", // viewName
  3640. {
  3641. text: newText
  3642. } // props
  3643. );
  3644. }
  3645. function commitUpdate(
  3646. instance,
  3647. updatePayloadTODO,
  3648. type,
  3649. oldProps,
  3650. newProps,
  3651. internalInstanceHandle
  3652. ) {
  3653. var viewConfig = instance.viewConfig;
  3654. updateFiberProps(instance._nativeTag, newProps);
  3655. var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); // Avoid the overhead of bridge calls if there's no update.
  3656. // This is an expensive no-op for Android, and causes an unnecessary
  3657. // view invalidation for certain components (eg RCTTextInput) on iOS.
  3658. if (updatePayload != null) {
  3659. ReactNativePrivateInterface.UIManager.updateView(
  3660. instance._nativeTag, // reactTag
  3661. viewConfig.uiViewClassName, // viewName
  3662. updatePayload // props
  3663. );
  3664. }
  3665. }
  3666. function insertBefore(parentInstance, child, beforeChild) {
  3667. var children = parentInstance._children;
  3668. var index = children.indexOf(child); // Move existing child or add new child?
  3669. if (index >= 0) {
  3670. children.splice(index, 1);
  3671. var beforeChildIndex = children.indexOf(beforeChild);
  3672. children.splice(beforeChildIndex, 0, child);
  3673. ReactNativePrivateInterface.UIManager.manageChildren(
  3674. parentInstance._nativeTag, // containerID
  3675. [index], // moveFromIndices
  3676. [beforeChildIndex], // moveToIndices
  3677. [], // addChildReactTags
  3678. [], // addAtIndices
  3679. [] // removeAtIndices
  3680. );
  3681. } else {
  3682. var _beforeChildIndex = children.indexOf(beforeChild);
  3683. children.splice(_beforeChildIndex, 0, child);
  3684. var childTag = typeof child === "number" ? child : child._nativeTag;
  3685. ReactNativePrivateInterface.UIManager.manageChildren(
  3686. parentInstance._nativeTag, // containerID
  3687. [], // moveFromIndices
  3688. [], // moveToIndices
  3689. [childTag], // addChildReactTags
  3690. [_beforeChildIndex], // addAtIndices
  3691. [] // removeAtIndices
  3692. );
  3693. }
  3694. }
  3695. function insertInContainerBefore(parentInstance, child, beforeChild) {
  3696. // TODO (bvaughn): Remove this check when...
  3697. // We create a wrapper object for the container in ReactNative render()
  3698. // Or we refactor to remove wrapper objects entirely.
  3699. // For more info on pros/cons see PR #8560 description.
  3700. if (!(typeof parentInstance !== "number")) {
  3701. throw Error("Container does not support insertBefore operation");
  3702. }
  3703. }
  3704. function removeChild(parentInstance, child) {
  3705. recursivelyUncacheFiberNode(child);
  3706. var children = parentInstance._children;
  3707. var index = children.indexOf(child);
  3708. children.splice(index, 1);
  3709. ReactNativePrivateInterface.UIManager.manageChildren(
  3710. parentInstance._nativeTag, // containerID
  3711. [], // moveFromIndices
  3712. [], // moveToIndices
  3713. [], // addChildReactTags
  3714. [], // addAtIndices
  3715. [index] // removeAtIndices
  3716. );
  3717. }
  3718. function removeChildFromContainer(parentInstance, child) {
  3719. recursivelyUncacheFiberNode(child);
  3720. ReactNativePrivateInterface.UIManager.manageChildren(
  3721. parentInstance, // containerID
  3722. [], // moveFromIndices
  3723. [], // moveToIndices
  3724. [], // addChildReactTags
  3725. [], // addAtIndices
  3726. [0] // removeAtIndices
  3727. );
  3728. }
  3729. function resetTextContent(instance) {
  3730. // Noop
  3731. }
  3732. function hideInstance(instance) {
  3733. var viewConfig = instance.viewConfig;
  3734. var updatePayload = create(
  3735. {
  3736. style: {
  3737. display: "none"
  3738. }
  3739. },
  3740. viewConfig.validAttributes
  3741. );
  3742. ReactNativePrivateInterface.UIManager.updateView(
  3743. instance._nativeTag,
  3744. viewConfig.uiViewClassName,
  3745. updatePayload
  3746. );
  3747. }
  3748. function hideTextInstance(textInstance) {
  3749. throw new Error("Not yet implemented.");
  3750. }
  3751. function unhideInstance(instance, props) {
  3752. var viewConfig = instance.viewConfig;
  3753. var updatePayload = diff(
  3754. Object.assign({}, props, {
  3755. style: [
  3756. props.style,
  3757. {
  3758. display: "none"
  3759. }
  3760. ]
  3761. }),
  3762. props,
  3763. viewConfig.validAttributes
  3764. );
  3765. ReactNativePrivateInterface.UIManager.updateView(
  3766. instance._nativeTag,
  3767. viewConfig.uiViewClassName,
  3768. updatePayload
  3769. );
  3770. }
  3771. function unhideTextInstance(textInstance, text) {
  3772. throw new Error("Not yet implemented.");
  3773. }
  3774. var loggedTypeFailures = {};
  3775. function checkPropTypes(typeSpecs, values, location, componentName) {
  3776. {
  3777. // $FlowFixMe This is okay but Flow doesn't know it.
  3778. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  3779. for (var typeSpecName in typeSpecs) {
  3780. if (has(typeSpecs, typeSpecName)) {
  3781. var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
  3782. // fail the render phase where it didn't fail before. So we log it.
  3783. // After these have been cleaned up, we'll let them throw.
  3784. try {
  3785. // This is intentionally an invariant that gets caught. It's the same
  3786. // behavior as without this statement except with a better message.
  3787. if (typeof typeSpecs[typeSpecName] !== "function") {
  3788. var err = Error(
  3789. (componentName || "React class") +
  3790. ": " +
  3791. location +
  3792. " type `" +
  3793. typeSpecName +
  3794. "` is invalid; " +
  3795. "it must be a function, usually from the `prop-types` package, but received `" +
  3796. typeof typeSpecs[typeSpecName] +
  3797. "`." +
  3798. "This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."
  3799. );
  3800. err.name = "Invariant Violation";
  3801. throw err;
  3802. }
  3803. error$1 = typeSpecs[typeSpecName](
  3804. values,
  3805. typeSpecName,
  3806. componentName,
  3807. location,
  3808. null,
  3809. "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"
  3810. );
  3811. } catch (ex) {
  3812. error$1 = ex;
  3813. }
  3814. if (error$1 && !(error$1 instanceof Error)) {
  3815. error(
  3816. "%s: type specification of %s" +
  3817. " `%s` is invalid; the type checker " +
  3818. "function must return `null` or an `Error` but returned a %s. " +
  3819. "You may have forgotten to pass an argument to the type checker " +
  3820. "creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and " +
  3821. "shape all require an argument).",
  3822. componentName || "React class",
  3823. location,
  3824. typeSpecName,
  3825. typeof error$1
  3826. );
  3827. }
  3828. if (
  3829. error$1 instanceof Error &&
  3830. !(error$1.message in loggedTypeFailures)
  3831. ) {
  3832. // Only monitor this failure once because there tends to be a lot of the
  3833. // same error.
  3834. loggedTypeFailures[error$1.message] = true;
  3835. error("Failed %s type: %s", location, error$1.message);
  3836. }
  3837. }
  3838. }
  3839. }
  3840. }
  3841. // Prefix measurements so that it's possible to filter them.
  3842. // Longer prefixes are hard to read in DevTools.
  3843. var reactEmoji = "\u269B";
  3844. var warningEmoji = "\u26D4";
  3845. var supportsUserTiming =
  3846. typeof performance !== "undefined" &&
  3847. typeof performance.mark === "function" &&
  3848. typeof performance.clearMarks === "function" &&
  3849. typeof performance.measure === "function" &&
  3850. typeof performance.clearMeasures === "function"; // Keep track of current fiber so that we know the path to unwind on pause.
  3851. // TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
  3852. var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
  3853. // Reusing `currentFiber` would be confusing for this because user code fiber
  3854. // can change during commit phase too, but we don't need to unwind it (since
  3855. // lifecycles in the commit phase don't resemble a tree).
  3856. var currentPhase = null;
  3857. var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
  3858. // so we will keep track of it, and include it in the report.
  3859. // Track commits caused by cascading updates.
  3860. var isCommitting = false;
  3861. var hasScheduledUpdateInCurrentCommit = false;
  3862. var hasScheduledUpdateInCurrentPhase = false;
  3863. var commitCountInCurrentWorkLoop = 0;
  3864. var effectCountInCurrentCommit = 0;
  3865. // to avoid stretch the commit phase with measurement overhead.
  3866. var labelsInCurrentCommit = new Set();
  3867. var formatMarkName = function(markName) {
  3868. return reactEmoji + " " + markName;
  3869. };
  3870. var formatLabel = function(label, warning) {
  3871. var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
  3872. var suffix = warning ? " Warning: " + warning : "";
  3873. return "" + prefix + label + suffix;
  3874. };
  3875. var beginMark = function(markName) {
  3876. performance.mark(formatMarkName(markName));
  3877. };
  3878. var clearMark = function(markName) {
  3879. performance.clearMarks(formatMarkName(markName));
  3880. };
  3881. var endMark = function(label, markName, warning) {
  3882. var formattedMarkName = formatMarkName(markName);
  3883. var formattedLabel = formatLabel(label, warning);
  3884. try {
  3885. performance.measure(formattedLabel, formattedMarkName);
  3886. } catch (err) {} // If previous mark was missing for some reason, this will throw.
  3887. // This could only happen if React crashed in an unexpected place earlier.
  3888. // Don't pile on with more errors.
  3889. // Clear marks immediately to avoid growing buffer.
  3890. performance.clearMarks(formattedMarkName);
  3891. performance.clearMeasures(formattedLabel);
  3892. };
  3893. var getFiberMarkName = function(label, debugID) {
  3894. return label + " (#" + debugID + ")";
  3895. };
  3896. var getFiberLabel = function(componentName, isMounted, phase) {
  3897. if (phase === null) {
  3898. // These are composite component total time measurements.
  3899. return componentName + " [" + (isMounted ? "update" : "mount") + "]";
  3900. } else {
  3901. // Composite component methods.
  3902. return componentName + "." + phase;
  3903. }
  3904. };
  3905. var beginFiberMark = function(fiber, phase) {
  3906. var componentName = getComponentName(fiber.type) || "Unknown";
  3907. var debugID = fiber._debugID;
  3908. var isMounted = fiber.alternate !== null;
  3909. var label = getFiberLabel(componentName, isMounted, phase);
  3910. if (isCommitting && labelsInCurrentCommit.has(label)) {
  3911. // During the commit phase, we don't show duplicate labels because
  3912. // there is a fixed overhead for every measurement, and we don't
  3913. // want to stretch the commit phase beyond necessary.
  3914. return false;
  3915. }
  3916. labelsInCurrentCommit.add(label);
  3917. var markName = getFiberMarkName(label, debugID);
  3918. beginMark(markName);
  3919. return true;
  3920. };
  3921. var clearFiberMark = function(fiber, phase) {
  3922. var componentName = getComponentName(fiber.type) || "Unknown";
  3923. var debugID = fiber._debugID;
  3924. var isMounted = fiber.alternate !== null;
  3925. var label = getFiberLabel(componentName, isMounted, phase);
  3926. var markName = getFiberMarkName(label, debugID);
  3927. clearMark(markName);
  3928. };
  3929. var endFiberMark = function(fiber, phase, warning) {
  3930. var componentName = getComponentName(fiber.type) || "Unknown";
  3931. var debugID = fiber._debugID;
  3932. var isMounted = fiber.alternate !== null;
  3933. var label = getFiberLabel(componentName, isMounted, phase);
  3934. var markName = getFiberMarkName(label, debugID);
  3935. endMark(label, markName, warning);
  3936. };
  3937. var shouldIgnoreFiber = function(fiber) {
  3938. // Host components should be skipped in the timeline.
  3939. // We could check typeof fiber.type, but does this work with RN?
  3940. switch (fiber.tag) {
  3941. case HostRoot:
  3942. case HostComponent:
  3943. case HostText:
  3944. case HostPortal:
  3945. case Fragment:
  3946. case ContextProvider:
  3947. case ContextConsumer:
  3948. case Mode:
  3949. return true;
  3950. default:
  3951. return false;
  3952. }
  3953. };
  3954. var clearPendingPhaseMeasurement = function() {
  3955. if (currentPhase !== null && currentPhaseFiber !== null) {
  3956. clearFiberMark(currentPhaseFiber, currentPhase);
  3957. }
  3958. currentPhaseFiber = null;
  3959. currentPhase = null;
  3960. hasScheduledUpdateInCurrentPhase = false;
  3961. };
  3962. var pauseTimers = function() {
  3963. // Stops all currently active measurements so that they can be resumed
  3964. // if we continue in a later deferred loop from the same unit of work.
  3965. var fiber = currentFiber;
  3966. while (fiber) {
  3967. if (fiber._debugIsCurrentlyTiming) {
  3968. endFiberMark(fiber, null, null);
  3969. }
  3970. fiber = fiber.return;
  3971. }
  3972. };
  3973. var resumeTimersRecursively = function(fiber) {
  3974. if (fiber.return !== null) {
  3975. resumeTimersRecursively(fiber.return);
  3976. }
  3977. if (fiber._debugIsCurrentlyTiming) {
  3978. beginFiberMark(fiber, null);
  3979. }
  3980. };
  3981. var resumeTimers = function() {
  3982. // Resumes all measurements that were active during the last deferred loop.
  3983. if (currentFiber !== null) {
  3984. resumeTimersRecursively(currentFiber);
  3985. }
  3986. };
  3987. function recordEffect() {
  3988. {
  3989. effectCountInCurrentCommit++;
  3990. }
  3991. }
  3992. function recordScheduleUpdate() {
  3993. {
  3994. if (isCommitting) {
  3995. hasScheduledUpdateInCurrentCommit = true;
  3996. }
  3997. if (
  3998. currentPhase !== null &&
  3999. currentPhase !== "componentWillMount" &&
  4000. currentPhase !== "componentWillReceiveProps"
  4001. ) {
  4002. hasScheduledUpdateInCurrentPhase = true;
  4003. }
  4004. }
  4005. }
  4006. function startWorkTimer(fiber) {
  4007. {
  4008. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4009. return;
  4010. } // If we pause, this is the fiber to unwind from.
  4011. currentFiber = fiber;
  4012. if (!beginFiberMark(fiber, null)) {
  4013. return;
  4014. }
  4015. fiber._debugIsCurrentlyTiming = true;
  4016. }
  4017. }
  4018. function cancelWorkTimer(fiber) {
  4019. {
  4020. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4021. return;
  4022. } // Remember we shouldn't complete measurement for this fiber.
  4023. // Otherwise flamechart will be deep even for small updates.
  4024. fiber._debugIsCurrentlyTiming = false;
  4025. clearFiberMark(fiber, null);
  4026. }
  4027. }
  4028. function stopWorkTimer(fiber) {
  4029. {
  4030. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4031. return;
  4032. } // If we pause, its parent is the fiber to unwind from.
  4033. currentFiber = fiber.return;
  4034. if (!fiber._debugIsCurrentlyTiming) {
  4035. return;
  4036. }
  4037. fiber._debugIsCurrentlyTiming = false;
  4038. endFiberMark(fiber, null, null);
  4039. }
  4040. }
  4041. function stopFailedWorkTimer(fiber) {
  4042. {
  4043. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4044. return;
  4045. } // If we pause, its parent is the fiber to unwind from.
  4046. currentFiber = fiber.return;
  4047. if (!fiber._debugIsCurrentlyTiming) {
  4048. return;
  4049. }
  4050. fiber._debugIsCurrentlyTiming = false;
  4051. var warning =
  4052. fiber.tag === SuspenseComponent
  4053. ? "Rendering was suspended"
  4054. : "An error was thrown inside this error boundary";
  4055. endFiberMark(fiber, null, warning);
  4056. }
  4057. }
  4058. function startPhaseTimer(fiber, phase) {
  4059. {
  4060. if (!supportsUserTiming) {
  4061. return;
  4062. }
  4063. clearPendingPhaseMeasurement();
  4064. if (!beginFiberMark(fiber, phase)) {
  4065. return;
  4066. }
  4067. currentPhaseFiber = fiber;
  4068. currentPhase = phase;
  4069. }
  4070. }
  4071. function stopPhaseTimer() {
  4072. {
  4073. if (!supportsUserTiming) {
  4074. return;
  4075. }
  4076. if (currentPhase !== null && currentPhaseFiber !== null) {
  4077. var warning = hasScheduledUpdateInCurrentPhase
  4078. ? "Scheduled a cascading update"
  4079. : null;
  4080. endFiberMark(currentPhaseFiber, currentPhase, warning);
  4081. }
  4082. currentPhase = null;
  4083. currentPhaseFiber = null;
  4084. }
  4085. }
  4086. function startWorkLoopTimer(nextUnitOfWork) {
  4087. {
  4088. currentFiber = nextUnitOfWork;
  4089. if (!supportsUserTiming) {
  4090. return;
  4091. }
  4092. commitCountInCurrentWorkLoop = 0; // This is top level call.
  4093. // Any other measurements are performed within.
  4094. beginMark("(React Tree Reconciliation)"); // Resume any measurements that were in progress during the last loop.
  4095. resumeTimers();
  4096. }
  4097. }
  4098. function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
  4099. {
  4100. if (!supportsUserTiming) {
  4101. return;
  4102. }
  4103. var warning = null;
  4104. if (interruptedBy !== null) {
  4105. if (interruptedBy.tag === HostRoot) {
  4106. warning = "A top-level update interrupted the previous render";
  4107. } else {
  4108. var componentName = getComponentName(interruptedBy.type) || "Unknown";
  4109. warning =
  4110. "An update to " + componentName + " interrupted the previous render";
  4111. }
  4112. } else if (commitCountInCurrentWorkLoop > 1) {
  4113. warning = "There were cascading updates";
  4114. }
  4115. commitCountInCurrentWorkLoop = 0;
  4116. var label = didCompleteRoot
  4117. ? "(React Tree Reconciliation: Completed Root)"
  4118. : "(React Tree Reconciliation: Yielded)"; // Pause any measurements until the next loop.
  4119. pauseTimers();
  4120. endMark(label, "(React Tree Reconciliation)", warning);
  4121. }
  4122. }
  4123. function startCommitTimer() {
  4124. {
  4125. if (!supportsUserTiming) {
  4126. return;
  4127. }
  4128. isCommitting = true;
  4129. hasScheduledUpdateInCurrentCommit = false;
  4130. labelsInCurrentCommit.clear();
  4131. beginMark("(Committing Changes)");
  4132. }
  4133. }
  4134. function stopCommitTimer() {
  4135. {
  4136. if (!supportsUserTiming) {
  4137. return;
  4138. }
  4139. var warning = null;
  4140. if (hasScheduledUpdateInCurrentCommit) {
  4141. warning = "Lifecycle hook scheduled a cascading update";
  4142. } else if (commitCountInCurrentWorkLoop > 0) {
  4143. warning = "Caused by a cascading update in earlier commit";
  4144. }
  4145. hasScheduledUpdateInCurrentCommit = false;
  4146. commitCountInCurrentWorkLoop++;
  4147. isCommitting = false;
  4148. labelsInCurrentCommit.clear();
  4149. endMark("(Committing Changes)", "(Committing Changes)", warning);
  4150. }
  4151. }
  4152. function startCommitSnapshotEffectsTimer() {
  4153. {
  4154. if (!supportsUserTiming) {
  4155. return;
  4156. }
  4157. effectCountInCurrentCommit = 0;
  4158. beginMark("(Committing Snapshot Effects)");
  4159. }
  4160. }
  4161. function stopCommitSnapshotEffectsTimer() {
  4162. {
  4163. if (!supportsUserTiming) {
  4164. return;
  4165. }
  4166. var count = effectCountInCurrentCommit;
  4167. effectCountInCurrentCommit = 0;
  4168. endMark(
  4169. "(Committing Snapshot Effects: " + count + " Total)",
  4170. "(Committing Snapshot Effects)",
  4171. null
  4172. );
  4173. }
  4174. }
  4175. function startCommitHostEffectsTimer() {
  4176. {
  4177. if (!supportsUserTiming) {
  4178. return;
  4179. }
  4180. effectCountInCurrentCommit = 0;
  4181. beginMark("(Committing Host Effects)");
  4182. }
  4183. }
  4184. function stopCommitHostEffectsTimer() {
  4185. {
  4186. if (!supportsUserTiming) {
  4187. return;
  4188. }
  4189. var count = effectCountInCurrentCommit;
  4190. effectCountInCurrentCommit = 0;
  4191. endMark(
  4192. "(Committing Host Effects: " + count + " Total)",
  4193. "(Committing Host Effects)",
  4194. null
  4195. );
  4196. }
  4197. }
  4198. function startCommitLifeCyclesTimer() {
  4199. {
  4200. if (!supportsUserTiming) {
  4201. return;
  4202. }
  4203. effectCountInCurrentCommit = 0;
  4204. beginMark("(Calling Lifecycle Methods)");
  4205. }
  4206. }
  4207. function stopCommitLifeCyclesTimer() {
  4208. {
  4209. if (!supportsUserTiming) {
  4210. return;
  4211. }
  4212. var count = effectCountInCurrentCommit;
  4213. effectCountInCurrentCommit = 0;
  4214. endMark(
  4215. "(Calling Lifecycle Methods: " + count + " Total)",
  4216. "(Calling Lifecycle Methods)",
  4217. null
  4218. );
  4219. }
  4220. }
  4221. var valueStack = [];
  4222. var fiberStack;
  4223. {
  4224. fiberStack = [];
  4225. }
  4226. var index = -1;
  4227. function createCursor(defaultValue) {
  4228. return {
  4229. current: defaultValue
  4230. };
  4231. }
  4232. function pop(cursor, fiber) {
  4233. if (index < 0) {
  4234. {
  4235. error("Unexpected pop.");
  4236. }
  4237. return;
  4238. }
  4239. {
  4240. if (fiber !== fiberStack[index]) {
  4241. error("Unexpected Fiber popped.");
  4242. }
  4243. }
  4244. cursor.current = valueStack[index];
  4245. valueStack[index] = null;
  4246. {
  4247. fiberStack[index] = null;
  4248. }
  4249. index--;
  4250. }
  4251. function push(cursor, value, fiber) {
  4252. index++;
  4253. valueStack[index] = cursor.current;
  4254. {
  4255. fiberStack[index] = fiber;
  4256. }
  4257. cursor.current = value;
  4258. }
  4259. var warnedAboutMissingGetChildContext;
  4260. {
  4261. warnedAboutMissingGetChildContext = {};
  4262. }
  4263. var emptyContextObject = {};
  4264. {
  4265. Object.freeze(emptyContextObject);
  4266. } // A cursor to the current merged context object on the stack.
  4267. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  4268. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  4269. // We use this to get access to the parent context after we have already
  4270. // pushed the next context provider, and now need to merge their contexts.
  4271. var previousContext = emptyContextObject;
  4272. function getUnmaskedContext(
  4273. workInProgress,
  4274. Component,
  4275. didPushOwnContextIfProvider
  4276. ) {
  4277. {
  4278. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  4279. // If the fiber is a context provider itself, when we read its context
  4280. // we may have already pushed its own child context on the stack. A context
  4281. // provider should not "see" its own child context. Therefore we read the
  4282. // previous (parent) context instead for a context provider.
  4283. return previousContext;
  4284. }
  4285. return contextStackCursor.current;
  4286. }
  4287. }
  4288. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  4289. {
  4290. var instance = workInProgress.stateNode;
  4291. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  4292. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  4293. }
  4294. }
  4295. function getMaskedContext(workInProgress, unmaskedContext) {
  4296. {
  4297. var type = workInProgress.type;
  4298. var contextTypes = type.contextTypes;
  4299. if (!contextTypes) {
  4300. return emptyContextObject;
  4301. } // Avoid recreating masked context unless unmasked context has changed.
  4302. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  4303. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  4304. var instance = workInProgress.stateNode;
  4305. if (
  4306. instance &&
  4307. instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
  4308. ) {
  4309. return instance.__reactInternalMemoizedMaskedChildContext;
  4310. }
  4311. var context = {};
  4312. for (var key in contextTypes) {
  4313. context[key] = unmaskedContext[key];
  4314. }
  4315. {
  4316. var name = getComponentName(type) || "Unknown";
  4317. checkPropTypes(contextTypes, context, "context", name);
  4318. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  4319. // Context is created before the class component is instantiated so check for instance.
  4320. if (instance) {
  4321. cacheContext(workInProgress, unmaskedContext, context);
  4322. }
  4323. return context;
  4324. }
  4325. }
  4326. function hasContextChanged() {
  4327. {
  4328. return didPerformWorkStackCursor.current;
  4329. }
  4330. }
  4331. function isContextProvider(type) {
  4332. {
  4333. var childContextTypes = type.childContextTypes;
  4334. return childContextTypes !== null && childContextTypes !== undefined;
  4335. }
  4336. }
  4337. function popContext(fiber) {
  4338. {
  4339. pop(didPerformWorkStackCursor, fiber);
  4340. pop(contextStackCursor, fiber);
  4341. }
  4342. }
  4343. function popTopLevelContextObject(fiber) {
  4344. {
  4345. pop(didPerformWorkStackCursor, fiber);
  4346. pop(contextStackCursor, fiber);
  4347. }
  4348. }
  4349. function pushTopLevelContextObject(fiber, context, didChange) {
  4350. {
  4351. if (!(contextStackCursor.current === emptyContextObject)) {
  4352. throw Error(
  4353. "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
  4354. );
  4355. }
  4356. push(contextStackCursor, context, fiber);
  4357. push(didPerformWorkStackCursor, didChange, fiber);
  4358. }
  4359. }
  4360. function processChildContext(fiber, type, parentContext) {
  4361. {
  4362. var instance = fiber.stateNode;
  4363. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  4364. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  4365. if (typeof instance.getChildContext !== "function") {
  4366. {
  4367. var componentName = getComponentName(type) || "Unknown";
  4368. if (!warnedAboutMissingGetChildContext[componentName]) {
  4369. warnedAboutMissingGetChildContext[componentName] = true;
  4370. error(
  4371. "%s.childContextTypes is specified but there is no getChildContext() method " +
  4372. "on the instance. You can either define getChildContext() on %s or remove " +
  4373. "childContextTypes from it.",
  4374. componentName,
  4375. componentName
  4376. );
  4377. }
  4378. }
  4379. return parentContext;
  4380. }
  4381. var childContext;
  4382. startPhaseTimer(fiber, "getChildContext");
  4383. childContext = instance.getChildContext();
  4384. stopPhaseTimer();
  4385. for (var contextKey in childContext) {
  4386. if (!(contextKey in childContextTypes)) {
  4387. throw Error(
  4388. (getComponentName(type) || "Unknown") +
  4389. '.getChildContext(): key "' +
  4390. contextKey +
  4391. '" is not defined in childContextTypes.'
  4392. );
  4393. }
  4394. }
  4395. {
  4396. var name = getComponentName(type) || "Unknown";
  4397. checkPropTypes(childContextTypes, childContext, "child context", name);
  4398. }
  4399. return Object.assign({}, parentContext, {}, childContext);
  4400. }
  4401. }
  4402. function pushContextProvider(workInProgress) {
  4403. {
  4404. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  4405. // If the instance does not exist yet, we will push null at first,
  4406. // and replace it on the stack later when invalidating the context.
  4407. var memoizedMergedChildContext =
  4408. (instance && instance.__reactInternalMemoizedMergedChildContext) ||
  4409. emptyContextObject; // Remember the parent context so we can merge with it later.
  4410. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  4411. previousContext = contextStackCursor.current;
  4412. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  4413. push(
  4414. didPerformWorkStackCursor,
  4415. didPerformWorkStackCursor.current,
  4416. workInProgress
  4417. );
  4418. return true;
  4419. }
  4420. }
  4421. function invalidateContextProvider(workInProgress, type, didChange) {
  4422. {
  4423. var instance = workInProgress.stateNode;
  4424. if (!instance) {
  4425. throw Error(
  4426. "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
  4427. );
  4428. }
  4429. if (didChange) {
  4430. // Merge parent and own context.
  4431. // Skip this if we're not updating due to sCU.
  4432. // This avoids unnecessarily recomputing memoized values.
  4433. var mergedContext = processChildContext(
  4434. workInProgress,
  4435. type,
  4436. previousContext
  4437. );
  4438. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  4439. // It is important to unwind the context in the reverse order.
  4440. pop(didPerformWorkStackCursor, workInProgress);
  4441. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  4442. push(contextStackCursor, mergedContext, workInProgress);
  4443. push(didPerformWorkStackCursor, didChange, workInProgress);
  4444. } else {
  4445. pop(didPerformWorkStackCursor, workInProgress);
  4446. push(didPerformWorkStackCursor, didChange, workInProgress);
  4447. }
  4448. }
  4449. }
  4450. function findCurrentUnmaskedContext(fiber) {
  4451. {
  4452. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  4453. // makes sense elsewhere
  4454. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  4455. throw Error(
  4456. "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
  4457. );
  4458. }
  4459. var node = fiber;
  4460. do {
  4461. switch (node.tag) {
  4462. case HostRoot:
  4463. return node.stateNode.context;
  4464. case ClassComponent: {
  4465. var Component = node.type;
  4466. if (isContextProvider(Component)) {
  4467. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  4468. }
  4469. break;
  4470. }
  4471. }
  4472. node = node.return;
  4473. } while (node !== null);
  4474. {
  4475. throw Error(
  4476. "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
  4477. );
  4478. }
  4479. }
  4480. }
  4481. var LegacyRoot = 0;
  4482. var BlockingRoot = 1;
  4483. var ConcurrentRoot = 2;
  4484. // Intentionally not named imports because Rollup would use dynamic dispatch for
  4485. var Scheduler_runWithPriority = Scheduler.unstable_runWithPriority,
  4486. Scheduler_scheduleCallback = Scheduler.unstable_scheduleCallback,
  4487. Scheduler_cancelCallback = Scheduler.unstable_cancelCallback,
  4488. Scheduler_shouldYield = Scheduler.unstable_shouldYield,
  4489. Scheduler_requestPaint = Scheduler.unstable_requestPaint,
  4490. Scheduler_now = Scheduler.unstable_now,
  4491. Scheduler_getCurrentPriorityLevel =
  4492. Scheduler.unstable_getCurrentPriorityLevel,
  4493. Scheduler_ImmediatePriority = Scheduler.unstable_ImmediatePriority,
  4494. Scheduler_UserBlockingPriority = Scheduler.unstable_UserBlockingPriority,
  4495. Scheduler_NormalPriority = Scheduler.unstable_NormalPriority,
  4496. Scheduler_LowPriority = Scheduler.unstable_LowPriority,
  4497. Scheduler_IdlePriority = Scheduler.unstable_IdlePriority;
  4498. {
  4499. // Provide explicit error message when production+profiling bundle of e.g.
  4500. // react-dom is used with production (non-profiling) bundle of
  4501. // scheduler/tracing
  4502. if (
  4503. !(
  4504. tracing.__interactionsRef != null &&
  4505. tracing.__interactionsRef.current != null
  4506. )
  4507. ) {
  4508. throw Error(
  4509. "It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `scheduler/tracing` module with `scheduler/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling"
  4510. );
  4511. }
  4512. }
  4513. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  4514. // ascending numbers so we can compare them like numbers. They start at 90 to
  4515. // avoid clashing with Scheduler's priorities.
  4516. var ImmediatePriority = 99;
  4517. var UserBlockingPriority = 98;
  4518. var NormalPriority = 97;
  4519. var LowPriority = 96;
  4520. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  4521. var NoPriority = 90;
  4522. var shouldYield = Scheduler_shouldYield;
  4523. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  4524. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function() {};
  4525. var syncQueue = null;
  4526. var immediateQueueCallbackNode = null;
  4527. var isFlushingSyncQueue = false;
  4528. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  4529. // This will be the case for modern browsers that support `performance.now`. In
  4530. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  4531. // timestamp. In that case, subtract the module initialization time to simulate
  4532. // the behavior of performance.now and keep our times small enough to fit
  4533. // within 32 bits.
  4534. // TODO: Consider lifting this into Scheduler.
  4535. var now =
  4536. initialTimeMs < 10000
  4537. ? Scheduler_now
  4538. : function() {
  4539. return Scheduler_now() - initialTimeMs;
  4540. };
  4541. function getCurrentPriorityLevel() {
  4542. switch (Scheduler_getCurrentPriorityLevel()) {
  4543. case Scheduler_ImmediatePriority:
  4544. return ImmediatePriority;
  4545. case Scheduler_UserBlockingPriority:
  4546. return UserBlockingPriority;
  4547. case Scheduler_NormalPriority:
  4548. return NormalPriority;
  4549. case Scheduler_LowPriority:
  4550. return LowPriority;
  4551. case Scheduler_IdlePriority:
  4552. return IdlePriority;
  4553. default: {
  4554. throw Error("Unknown priority level.");
  4555. }
  4556. }
  4557. }
  4558. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  4559. switch (reactPriorityLevel) {
  4560. case ImmediatePriority:
  4561. return Scheduler_ImmediatePriority;
  4562. case UserBlockingPriority:
  4563. return Scheduler_UserBlockingPriority;
  4564. case NormalPriority:
  4565. return Scheduler_NormalPriority;
  4566. case LowPriority:
  4567. return Scheduler_LowPriority;
  4568. case IdlePriority:
  4569. return Scheduler_IdlePriority;
  4570. default: {
  4571. throw Error("Unknown priority level.");
  4572. }
  4573. }
  4574. }
  4575. function runWithPriority(reactPriorityLevel, fn) {
  4576. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4577. return Scheduler_runWithPriority(priorityLevel, fn);
  4578. }
  4579. function scheduleCallback(reactPriorityLevel, callback, options) {
  4580. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4581. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  4582. }
  4583. function scheduleSyncCallback(callback) {
  4584. // Push this callback into an internal queue. We'll flush these either in
  4585. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  4586. if (syncQueue === null) {
  4587. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  4588. immediateQueueCallbackNode = Scheduler_scheduleCallback(
  4589. Scheduler_ImmediatePriority,
  4590. flushSyncCallbackQueueImpl
  4591. );
  4592. } else {
  4593. // Push onto existing queue. Don't need to schedule a callback because
  4594. // we already scheduled one when we created the queue.
  4595. syncQueue.push(callback);
  4596. }
  4597. return fakeCallbackNode;
  4598. }
  4599. function cancelCallback(callbackNode) {
  4600. if (callbackNode !== fakeCallbackNode) {
  4601. Scheduler_cancelCallback(callbackNode);
  4602. }
  4603. }
  4604. function flushSyncCallbackQueue() {
  4605. if (immediateQueueCallbackNode !== null) {
  4606. var node = immediateQueueCallbackNode;
  4607. immediateQueueCallbackNode = null;
  4608. Scheduler_cancelCallback(node);
  4609. }
  4610. flushSyncCallbackQueueImpl();
  4611. }
  4612. function flushSyncCallbackQueueImpl() {
  4613. if (!isFlushingSyncQueue && syncQueue !== null) {
  4614. // Prevent re-entrancy.
  4615. isFlushingSyncQueue = true;
  4616. var i = 0;
  4617. try {
  4618. var _isSync = true;
  4619. var queue = syncQueue;
  4620. runWithPriority(ImmediatePriority, function() {
  4621. for (; i < queue.length; i++) {
  4622. var callback = queue[i];
  4623. do {
  4624. callback = callback(_isSync);
  4625. } while (callback !== null);
  4626. }
  4627. });
  4628. syncQueue = null;
  4629. } catch (error) {
  4630. // If something throws, leave the remaining callbacks on the queue.
  4631. if (syncQueue !== null) {
  4632. syncQueue = syncQueue.slice(i + 1);
  4633. } // Resume flushing in the next tick
  4634. Scheduler_scheduleCallback(
  4635. Scheduler_ImmediatePriority,
  4636. flushSyncCallbackQueue
  4637. );
  4638. throw error;
  4639. } finally {
  4640. isFlushingSyncQueue = false;
  4641. }
  4642. }
  4643. }
  4644. var NoMode = 0;
  4645. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  4646. // tag instead
  4647. var BlockingMode = 2;
  4648. var ConcurrentMode = 4;
  4649. var ProfileMode = 8;
  4650. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  4651. // Math.pow(2, 30) - 1
  4652. // 0b111111111111111111111111111111
  4653. var MAX_SIGNED_31_BIT_INT = 1073741823;
  4654. var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
  4655. // Never work can be committed in an inconsistent state without tearing the UI.
  4656. // The main example is offscreen content, like a hidden subtree. So one possible
  4657. // name is Offscreen. However, it also includes dehydrated Suspense boundaries,
  4658. // which are inconsistent in the sense that they haven't finished yet, but
  4659. // aren't visibly inconsistent because the server rendered HTML matches what the
  4660. // hydrated tree would look like.
  4661. var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
  4662. // order to be consistent.
  4663. var Idle = 2; // Continuous Hydration is slightly higher than Idle and is used to increase
  4664. var Sync = MAX_SIGNED_31_BIT_INT;
  4665. var Batched = Sync - 1;
  4666. var UNIT_SIZE = 10;
  4667. var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
  4668. function msToExpirationTime(ms) {
  4669. // Always subtract from the offset so that we don't clash with the magic number for NoWork.
  4670. return MAGIC_NUMBER_OFFSET - ((ms / UNIT_SIZE) | 0);
  4671. }
  4672. function expirationTimeToMs(expirationTime) {
  4673. return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
  4674. }
  4675. function ceiling(num, precision) {
  4676. return (((num / precision) | 0) + 1) * precision;
  4677. }
  4678. function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
  4679. return (
  4680. MAGIC_NUMBER_OFFSET -
  4681. ceiling(
  4682. MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE,
  4683. bucketSizeMs / UNIT_SIZE
  4684. )
  4685. );
  4686. } // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
  4687. // the names to reflect.
  4688. var LOW_PRIORITY_EXPIRATION = 5000;
  4689. var LOW_PRIORITY_BATCH_SIZE = 250;
  4690. function computeAsyncExpiration(currentTime) {
  4691. return computeExpirationBucket(
  4692. currentTime,
  4693. LOW_PRIORITY_EXPIRATION,
  4694. LOW_PRIORITY_BATCH_SIZE
  4695. );
  4696. }
  4697. function computeSuspenseExpiration(currentTime, timeoutMs) {
  4698. // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
  4699. return computeExpirationBucket(
  4700. currentTime,
  4701. timeoutMs,
  4702. LOW_PRIORITY_BATCH_SIZE
  4703. );
  4704. } // We intentionally set a higher expiration time for interactive updates in
  4705. // dev than in production.
  4706. //
  4707. // If the main thread is being blocked so long that you hit the expiration,
  4708. // it's a problem that could be solved with better scheduling.
  4709. //
  4710. // People will be more likely to notice this and fix it with the long
  4711. // expiration time in development.
  4712. //
  4713. // In production we opt for better UX at the risk of masking scheduling
  4714. // problems, by expiring fast.
  4715. var HIGH_PRIORITY_EXPIRATION = 500;
  4716. var HIGH_PRIORITY_BATCH_SIZE = 100;
  4717. function computeInteractiveExpiration(currentTime) {
  4718. return computeExpirationBucket(
  4719. currentTime,
  4720. HIGH_PRIORITY_EXPIRATION,
  4721. HIGH_PRIORITY_BATCH_SIZE
  4722. );
  4723. }
  4724. function inferPriorityFromExpirationTime(currentTime, expirationTime) {
  4725. if (expirationTime === Sync) {
  4726. return ImmediatePriority;
  4727. }
  4728. if (expirationTime === Never || expirationTime === Idle) {
  4729. return IdlePriority;
  4730. }
  4731. var msUntil =
  4732. expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
  4733. if (msUntil <= 0) {
  4734. return ImmediatePriority;
  4735. }
  4736. if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
  4737. return UserBlockingPriority;
  4738. }
  4739. if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
  4740. return NormalPriority;
  4741. } // TODO: Handle LowPriority
  4742. // Assume anything lower has idle priority
  4743. return IdlePriority;
  4744. }
  4745. /**
  4746. * inlined Object.is polyfill to avoid requiring consumers ship their own
  4747. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  4748. */
  4749. function is(x, y) {
  4750. return (
  4751. (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare
  4752. );
  4753. }
  4754. var objectIs = typeof Object.is === "function" ? Object.is : is;
  4755. var hasOwnProperty = Object.prototype.hasOwnProperty;
  4756. /**
  4757. * Performs equality by iterating through keys on an object and returning false
  4758. * when any key has values which are not strictly equal between the arguments.
  4759. * Returns true when the values of all keys are strictly equal.
  4760. */
  4761. function shallowEqual(objA, objB) {
  4762. if (objectIs(objA, objB)) {
  4763. return true;
  4764. }
  4765. if (
  4766. typeof objA !== "object" ||
  4767. objA === null ||
  4768. typeof objB !== "object" ||
  4769. objB === null
  4770. ) {
  4771. return false;
  4772. }
  4773. var keysA = Object.keys(objA);
  4774. var keysB = Object.keys(objB);
  4775. if (keysA.length !== keysB.length) {
  4776. return false;
  4777. } // Test for A's keys different from B.
  4778. for (var i = 0; i < keysA.length; i++) {
  4779. if (
  4780. !hasOwnProperty.call(objB, keysA[i]) ||
  4781. !objectIs(objA[keysA[i]], objB[keysA[i]])
  4782. ) {
  4783. return false;
  4784. }
  4785. }
  4786. return true;
  4787. }
  4788. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  4789. function describeComponentFrame(name, source, ownerName) {
  4790. var sourceInfo = "";
  4791. if (source) {
  4792. var path = source.fileName;
  4793. var fileName = path.replace(BEFORE_SLASH_RE, "");
  4794. {
  4795. // In DEV, include code for a common special case:
  4796. // prefer "folder/index.js" instead of just "index.js".
  4797. if (/^index\./.test(fileName)) {
  4798. var match = path.match(BEFORE_SLASH_RE);
  4799. if (match) {
  4800. var pathBeforeSlash = match[1];
  4801. if (pathBeforeSlash) {
  4802. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, "");
  4803. fileName = folderName + "/" + fileName;
  4804. }
  4805. }
  4806. }
  4807. }
  4808. sourceInfo = " (at " + fileName + ":" + source.lineNumber + ")";
  4809. } else if (ownerName) {
  4810. sourceInfo = " (created by " + ownerName + ")";
  4811. }
  4812. return "\n in " + (name || "Unknown") + sourceInfo;
  4813. }
  4814. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  4815. function describeFiber(fiber) {
  4816. switch (fiber.tag) {
  4817. case HostRoot:
  4818. case HostPortal:
  4819. case HostText:
  4820. case Fragment:
  4821. case ContextProvider:
  4822. case ContextConsumer:
  4823. return "";
  4824. default:
  4825. var owner = fiber._debugOwner;
  4826. var source = fiber._debugSource;
  4827. var name = getComponentName(fiber.type);
  4828. var ownerName = null;
  4829. if (owner) {
  4830. ownerName = getComponentName(owner.type);
  4831. }
  4832. return describeComponentFrame(name, source, ownerName);
  4833. }
  4834. }
  4835. function getStackByFiberInDevAndProd(workInProgress) {
  4836. var info = "";
  4837. var node = workInProgress;
  4838. do {
  4839. info += describeFiber(node);
  4840. node = node.return;
  4841. } while (node);
  4842. return info;
  4843. }
  4844. var current = null;
  4845. var isRendering = false;
  4846. function getCurrentFiberOwnerNameInDevOrNull() {
  4847. {
  4848. if (current === null) {
  4849. return null;
  4850. }
  4851. var owner = current._debugOwner;
  4852. if (owner !== null && typeof owner !== "undefined") {
  4853. return getComponentName(owner.type);
  4854. }
  4855. }
  4856. return null;
  4857. }
  4858. function getCurrentFiberStackInDev() {
  4859. {
  4860. if (current === null) {
  4861. return "";
  4862. } // Safe because if current fiber exists, we are reconciling,
  4863. // and it is guaranteed to be the work-in-progress version.
  4864. return getStackByFiberInDevAndProd(current);
  4865. }
  4866. }
  4867. function resetCurrentFiber() {
  4868. {
  4869. ReactDebugCurrentFrame.getCurrentStack = null;
  4870. current = null;
  4871. isRendering = false;
  4872. }
  4873. }
  4874. function setCurrentFiber(fiber) {
  4875. {
  4876. ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
  4877. current = fiber;
  4878. isRendering = false;
  4879. }
  4880. }
  4881. function setIsRendering(rendering) {
  4882. {
  4883. isRendering = rendering;
  4884. }
  4885. }
  4886. var ReactStrictModeWarnings = {
  4887. recordUnsafeLifecycleWarnings: function(fiber, instance) {},
  4888. flushPendingUnsafeLifecycleWarnings: function() {},
  4889. recordLegacyContextWarning: function(fiber, instance) {},
  4890. flushLegacyContextWarning: function() {},
  4891. discardPendingWarnings: function() {}
  4892. };
  4893. {
  4894. var findStrictRoot = function(fiber) {
  4895. var maybeStrictRoot = null;
  4896. var node = fiber;
  4897. while (node !== null) {
  4898. if (node.mode & StrictMode) {
  4899. maybeStrictRoot = node;
  4900. }
  4901. node = node.return;
  4902. }
  4903. return maybeStrictRoot;
  4904. };
  4905. var setToSortedString = function(set) {
  4906. var array = [];
  4907. set.forEach(function(value) {
  4908. array.push(value);
  4909. });
  4910. return array.sort().join(", ");
  4911. };
  4912. var pendingComponentWillMountWarnings = [];
  4913. var pendingUNSAFE_ComponentWillMountWarnings = [];
  4914. var pendingComponentWillReceivePropsWarnings = [];
  4915. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4916. var pendingComponentWillUpdateWarnings = [];
  4917. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  4918. var didWarnAboutUnsafeLifecycles = new Set();
  4919. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function(
  4920. fiber,
  4921. instance
  4922. ) {
  4923. // Dedup strategy: Warn once per component.
  4924. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  4925. return;
  4926. }
  4927. if (
  4928. typeof instance.componentWillMount === "function" && // Don't warn about react-lifecycles-compat polyfilled components.
  4929. instance.componentWillMount.__suppressDeprecationWarning !== true
  4930. ) {
  4931. pendingComponentWillMountWarnings.push(fiber);
  4932. }
  4933. if (
  4934. fiber.mode & StrictMode &&
  4935. typeof instance.UNSAFE_componentWillMount === "function"
  4936. ) {
  4937. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  4938. }
  4939. if (
  4940. typeof instance.componentWillReceiveProps === "function" &&
  4941. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  4942. ) {
  4943. pendingComponentWillReceivePropsWarnings.push(fiber);
  4944. }
  4945. if (
  4946. fiber.mode & StrictMode &&
  4947. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  4948. ) {
  4949. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  4950. }
  4951. if (
  4952. typeof instance.componentWillUpdate === "function" &&
  4953. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  4954. ) {
  4955. pendingComponentWillUpdateWarnings.push(fiber);
  4956. }
  4957. if (
  4958. fiber.mode & StrictMode &&
  4959. typeof instance.UNSAFE_componentWillUpdate === "function"
  4960. ) {
  4961. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  4962. }
  4963. };
  4964. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() {
  4965. // We do an initial pass to gather component names
  4966. var componentWillMountUniqueNames = new Set();
  4967. if (pendingComponentWillMountWarnings.length > 0) {
  4968. pendingComponentWillMountWarnings.forEach(function(fiber) {
  4969. componentWillMountUniqueNames.add(
  4970. getComponentName(fiber.type) || "Component"
  4971. );
  4972. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4973. });
  4974. pendingComponentWillMountWarnings = [];
  4975. }
  4976. var UNSAFE_componentWillMountUniqueNames = new Set();
  4977. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  4978. pendingUNSAFE_ComponentWillMountWarnings.forEach(function(fiber) {
  4979. UNSAFE_componentWillMountUniqueNames.add(
  4980. getComponentName(fiber.type) || "Component"
  4981. );
  4982. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4983. });
  4984. pendingUNSAFE_ComponentWillMountWarnings = [];
  4985. }
  4986. var componentWillReceivePropsUniqueNames = new Set();
  4987. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  4988. pendingComponentWillReceivePropsWarnings.forEach(function(fiber) {
  4989. componentWillReceivePropsUniqueNames.add(
  4990. getComponentName(fiber.type) || "Component"
  4991. );
  4992. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4993. });
  4994. pendingComponentWillReceivePropsWarnings = [];
  4995. }
  4996. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  4997. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  4998. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function(fiber) {
  4999. UNSAFE_componentWillReceivePropsUniqueNames.add(
  5000. getComponentName(fiber.type) || "Component"
  5001. );
  5002. didWarnAboutUnsafeLifecycles.add(fiber.type);
  5003. });
  5004. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  5005. }
  5006. var componentWillUpdateUniqueNames = new Set();
  5007. if (pendingComponentWillUpdateWarnings.length > 0) {
  5008. pendingComponentWillUpdateWarnings.forEach(function(fiber) {
  5009. componentWillUpdateUniqueNames.add(
  5010. getComponentName(fiber.type) || "Component"
  5011. );
  5012. didWarnAboutUnsafeLifecycles.add(fiber.type);
  5013. });
  5014. pendingComponentWillUpdateWarnings = [];
  5015. }
  5016. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  5017. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  5018. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function(fiber) {
  5019. UNSAFE_componentWillUpdateUniqueNames.add(
  5020. getComponentName(fiber.type) || "Component"
  5021. );
  5022. didWarnAboutUnsafeLifecycles.add(fiber.type);
  5023. });
  5024. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  5025. } // Finally, we flush all the warnings
  5026. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  5027. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  5028. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  5029. error(
  5030. "Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. " +
  5031. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5032. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  5033. "\nPlease update the following components: %s",
  5034. sortedNames
  5035. );
  5036. }
  5037. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  5038. var _sortedNames = setToSortedString(
  5039. UNSAFE_componentWillReceivePropsUniqueNames
  5040. );
  5041. error(
  5042. "Using UNSAFE_componentWillReceiveProps in strict mode is not recommended " +
  5043. "and may indicate bugs in your code. " +
  5044. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5045. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5046. "* If you're updating state whenever props change, " +
  5047. "refactor your code to use memoization techniques or move it to " +
  5048. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  5049. "\nPlease update the following components: %s",
  5050. _sortedNames
  5051. );
  5052. }
  5053. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  5054. var _sortedNames2 = setToSortedString(
  5055. UNSAFE_componentWillUpdateUniqueNames
  5056. );
  5057. error(
  5058. "Using UNSAFE_componentWillUpdate in strict mode is not recommended " +
  5059. "and may indicate bugs in your code. " +
  5060. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5061. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5062. "\nPlease update the following components: %s",
  5063. _sortedNames2
  5064. );
  5065. }
  5066. if (componentWillMountUniqueNames.size > 0) {
  5067. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  5068. warn(
  5069. "componentWillMount has been renamed, and is not recommended for use. " +
  5070. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5071. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  5072. "* Rename componentWillMount to UNSAFE_componentWillMount to suppress " +
  5073. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  5074. "To rename all deprecated lifecycles to their new names, you can run " +
  5075. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  5076. "\nPlease update the following components: %s",
  5077. _sortedNames3
  5078. );
  5079. }
  5080. if (componentWillReceivePropsUniqueNames.size > 0) {
  5081. var _sortedNames4 = setToSortedString(
  5082. componentWillReceivePropsUniqueNames
  5083. );
  5084. warn(
  5085. "componentWillReceiveProps has been renamed, and is not recommended for use. " +
  5086. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5087. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5088. "* If you're updating state whenever props change, refactor your " +
  5089. "code to use memoization techniques or move it to " +
  5090. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  5091. "* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress " +
  5092. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  5093. "To rename all deprecated lifecycles to their new names, you can run " +
  5094. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  5095. "\nPlease update the following components: %s",
  5096. _sortedNames4
  5097. );
  5098. }
  5099. if (componentWillUpdateUniqueNames.size > 0) {
  5100. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  5101. warn(
  5102. "componentWillUpdate has been renamed, and is not recommended for use. " +
  5103. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5104. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5105. "* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress " +
  5106. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  5107. "To rename all deprecated lifecycles to their new names, you can run " +
  5108. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  5109. "\nPlease update the following components: %s",
  5110. _sortedNames5
  5111. );
  5112. }
  5113. };
  5114. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  5115. var didWarnAboutLegacyContext = new Set();
  5116. ReactStrictModeWarnings.recordLegacyContextWarning = function(
  5117. fiber,
  5118. instance
  5119. ) {
  5120. var strictRoot = findStrictRoot(fiber);
  5121. if (strictRoot === null) {
  5122. error(
  5123. "Expected to find a StrictMode component in a strict mode tree. " +
  5124. "This error is likely caused by a bug in React. Please file an issue."
  5125. );
  5126. return;
  5127. } // Dedup strategy: Warn once per component.
  5128. if (didWarnAboutLegacyContext.has(fiber.type)) {
  5129. return;
  5130. }
  5131. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  5132. if (
  5133. fiber.type.contextTypes != null ||
  5134. fiber.type.childContextTypes != null ||
  5135. (instance !== null && typeof instance.getChildContext === "function")
  5136. ) {
  5137. if (warningsForRoot === undefined) {
  5138. warningsForRoot = [];
  5139. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  5140. }
  5141. warningsForRoot.push(fiber);
  5142. }
  5143. };
  5144. ReactStrictModeWarnings.flushLegacyContextWarning = function() {
  5145. pendingLegacyContextWarning.forEach(function(fiberArray, strictRoot) {
  5146. if (fiberArray.length === 0) {
  5147. return;
  5148. }
  5149. var firstFiber = fiberArray[0];
  5150. var uniqueNames = new Set();
  5151. fiberArray.forEach(function(fiber) {
  5152. uniqueNames.add(getComponentName(fiber.type) || "Component");
  5153. didWarnAboutLegacyContext.add(fiber.type);
  5154. });
  5155. var sortedNames = setToSortedString(uniqueNames);
  5156. var firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
  5157. error(
  5158. "Legacy context API has been detected within a strict-mode tree." +
  5159. "\n\nThe old API will be supported in all 16.x releases, but applications " +
  5160. "using it should migrate to the new version." +
  5161. "\n\nPlease update the following components: %s" +
  5162. "\n\nLearn more about this warning here: https://fb.me/react-legacy-context" +
  5163. "%s",
  5164. sortedNames,
  5165. firstComponentStack
  5166. );
  5167. });
  5168. };
  5169. ReactStrictModeWarnings.discardPendingWarnings = function() {
  5170. pendingComponentWillMountWarnings = [];
  5171. pendingUNSAFE_ComponentWillMountWarnings = [];
  5172. pendingComponentWillReceivePropsWarnings = [];
  5173. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  5174. pendingComponentWillUpdateWarnings = [];
  5175. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  5176. pendingLegacyContextWarning = new Map();
  5177. };
  5178. }
  5179. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  5180. var failedBoundaries = null;
  5181. var setRefreshHandler = function(handler) {
  5182. {
  5183. resolveFamily = handler;
  5184. }
  5185. };
  5186. function resolveFunctionForHotReloading(type) {
  5187. {
  5188. if (resolveFamily === null) {
  5189. // Hot reloading is disabled.
  5190. return type;
  5191. }
  5192. var family = resolveFamily(type);
  5193. if (family === undefined) {
  5194. return type;
  5195. } // Use the latest known implementation.
  5196. return family.current;
  5197. }
  5198. }
  5199. function resolveClassForHotReloading(type) {
  5200. // No implementation differences.
  5201. return resolveFunctionForHotReloading(type);
  5202. }
  5203. function resolveForwardRefForHotReloading(type) {
  5204. {
  5205. if (resolveFamily === null) {
  5206. // Hot reloading is disabled.
  5207. return type;
  5208. }
  5209. var family = resolveFamily(type);
  5210. if (family === undefined) {
  5211. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  5212. if (
  5213. type !== null &&
  5214. type !== undefined &&
  5215. typeof type.render === "function"
  5216. ) {
  5217. // ForwardRef is special because its resolved .type is an object,
  5218. // but it's possible that we only have its inner render function in the map.
  5219. // If that inner render function is different, we'll build a new forwardRef type.
  5220. var currentRender = resolveFunctionForHotReloading(type.render);
  5221. if (type.render !== currentRender) {
  5222. var syntheticType = {
  5223. $$typeof: REACT_FORWARD_REF_TYPE,
  5224. render: currentRender
  5225. };
  5226. if (type.displayName !== undefined) {
  5227. syntheticType.displayName = type.displayName;
  5228. }
  5229. return syntheticType;
  5230. }
  5231. }
  5232. return type;
  5233. } // Use the latest known implementation.
  5234. return family.current;
  5235. }
  5236. }
  5237. function isCompatibleFamilyForHotReloading(fiber, element) {
  5238. {
  5239. if (resolveFamily === null) {
  5240. // Hot reloading is disabled.
  5241. return false;
  5242. }
  5243. var prevType = fiber.elementType;
  5244. var nextType = element.type; // If we got here, we know types aren't === equal.
  5245. var needsCompareFamilies = false;
  5246. var $$typeofNextType =
  5247. typeof nextType === "object" && nextType !== null
  5248. ? nextType.$$typeof
  5249. : null;
  5250. switch (fiber.tag) {
  5251. case ClassComponent: {
  5252. if (typeof nextType === "function") {
  5253. needsCompareFamilies = true;
  5254. }
  5255. break;
  5256. }
  5257. case FunctionComponent: {
  5258. if (typeof nextType === "function") {
  5259. needsCompareFamilies = true;
  5260. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  5261. // We don't know the inner type yet.
  5262. // We're going to assume that the lazy inner type is stable,
  5263. // and so it is sufficient to avoid reconciling it away.
  5264. // We're not going to unwrap or actually use the new lazy type.
  5265. needsCompareFamilies = true;
  5266. }
  5267. break;
  5268. }
  5269. case ForwardRef: {
  5270. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  5271. needsCompareFamilies = true;
  5272. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  5273. needsCompareFamilies = true;
  5274. }
  5275. break;
  5276. }
  5277. case MemoComponent:
  5278. case SimpleMemoComponent: {
  5279. if ($$typeofNextType === REACT_MEMO_TYPE) {
  5280. // TODO: if it was but can no longer be simple,
  5281. // we shouldn't set this.
  5282. needsCompareFamilies = true;
  5283. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  5284. needsCompareFamilies = true;
  5285. }
  5286. break;
  5287. }
  5288. default:
  5289. return false;
  5290. } // Check if both types have a family and it's the same one.
  5291. if (needsCompareFamilies) {
  5292. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  5293. // This means both of them need to be registered to preserve state.
  5294. // If we unwrapped and compared the inner types for wrappers instead,
  5295. // then we would risk falsely saying two separate memo(Foo)
  5296. // calls are equivalent because they wrap the same Foo function.
  5297. var prevFamily = resolveFamily(prevType);
  5298. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  5299. return true;
  5300. }
  5301. }
  5302. return false;
  5303. }
  5304. }
  5305. function markFailedErrorBoundaryForHotReloading(fiber) {
  5306. {
  5307. if (resolveFamily === null) {
  5308. // Hot reloading is disabled.
  5309. return;
  5310. }
  5311. if (typeof WeakSet !== "function") {
  5312. return;
  5313. }
  5314. if (failedBoundaries === null) {
  5315. failedBoundaries = new WeakSet();
  5316. }
  5317. failedBoundaries.add(fiber);
  5318. }
  5319. }
  5320. var scheduleRefresh = function(root, update) {
  5321. {
  5322. if (resolveFamily === null) {
  5323. // Hot reloading is disabled.
  5324. return;
  5325. }
  5326. var staleFamilies = update.staleFamilies,
  5327. updatedFamilies = update.updatedFamilies;
  5328. flushPassiveEffects();
  5329. flushSync(function() {
  5330. scheduleFibersWithFamiliesRecursively(
  5331. root.current,
  5332. updatedFamilies,
  5333. staleFamilies
  5334. );
  5335. });
  5336. }
  5337. };
  5338. var scheduleRoot = function(root, element) {
  5339. {
  5340. if (root.context !== emptyContextObject) {
  5341. // Super edge case: root has a legacy _renderSubtree context
  5342. // but we don't know the parentComponent so we can't pass it.
  5343. // Just ignore. We'll delete this with _renderSubtree code path later.
  5344. return;
  5345. }
  5346. flushPassiveEffects();
  5347. syncUpdates(function() {
  5348. updateContainer(element, root, null, null);
  5349. });
  5350. }
  5351. };
  5352. function scheduleFibersWithFamiliesRecursively(
  5353. fiber,
  5354. updatedFamilies,
  5355. staleFamilies
  5356. ) {
  5357. {
  5358. var alternate = fiber.alternate,
  5359. child = fiber.child,
  5360. sibling = fiber.sibling,
  5361. tag = fiber.tag,
  5362. type = fiber.type;
  5363. var candidateType = null;
  5364. switch (tag) {
  5365. case FunctionComponent:
  5366. case SimpleMemoComponent:
  5367. case ClassComponent:
  5368. candidateType = type;
  5369. break;
  5370. case ForwardRef:
  5371. candidateType = type.render;
  5372. break;
  5373. }
  5374. if (resolveFamily === null) {
  5375. throw new Error("Expected resolveFamily to be set during hot reload.");
  5376. }
  5377. var needsRender = false;
  5378. var needsRemount = false;
  5379. if (candidateType !== null) {
  5380. var family = resolveFamily(candidateType);
  5381. if (family !== undefined) {
  5382. if (staleFamilies.has(family)) {
  5383. needsRemount = true;
  5384. } else if (updatedFamilies.has(family)) {
  5385. if (tag === ClassComponent) {
  5386. needsRemount = true;
  5387. } else {
  5388. needsRender = true;
  5389. }
  5390. }
  5391. }
  5392. }
  5393. if (failedBoundaries !== null) {
  5394. if (
  5395. failedBoundaries.has(fiber) ||
  5396. (alternate !== null && failedBoundaries.has(alternate))
  5397. ) {
  5398. needsRemount = true;
  5399. }
  5400. }
  5401. if (needsRemount) {
  5402. fiber._debugNeedsRemount = true;
  5403. }
  5404. if (needsRemount || needsRender) {
  5405. scheduleWork(fiber, Sync);
  5406. }
  5407. if (child !== null && !needsRemount) {
  5408. scheduleFibersWithFamiliesRecursively(
  5409. child,
  5410. updatedFamilies,
  5411. staleFamilies
  5412. );
  5413. }
  5414. if (sibling !== null) {
  5415. scheduleFibersWithFamiliesRecursively(
  5416. sibling,
  5417. updatedFamilies,
  5418. staleFamilies
  5419. );
  5420. }
  5421. }
  5422. }
  5423. var findHostInstancesForRefresh = function(root, families) {
  5424. {
  5425. var hostInstances = new Set();
  5426. var types = new Set(
  5427. families.map(function(family) {
  5428. return family.current;
  5429. })
  5430. );
  5431. findHostInstancesForMatchingFibersRecursively(
  5432. root.current,
  5433. types,
  5434. hostInstances
  5435. );
  5436. return hostInstances;
  5437. }
  5438. };
  5439. function findHostInstancesForMatchingFibersRecursively(
  5440. fiber,
  5441. types,
  5442. hostInstances
  5443. ) {
  5444. {
  5445. var child = fiber.child,
  5446. sibling = fiber.sibling,
  5447. tag = fiber.tag,
  5448. type = fiber.type;
  5449. var candidateType = null;
  5450. switch (tag) {
  5451. case FunctionComponent:
  5452. case SimpleMemoComponent:
  5453. case ClassComponent:
  5454. candidateType = type;
  5455. break;
  5456. case ForwardRef:
  5457. candidateType = type.render;
  5458. break;
  5459. }
  5460. var didMatch = false;
  5461. if (candidateType !== null) {
  5462. if (types.has(candidateType)) {
  5463. didMatch = true;
  5464. }
  5465. }
  5466. if (didMatch) {
  5467. // We have a match. This only drills down to the closest host components.
  5468. // There's no need to search deeper because for the purpose of giving
  5469. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  5470. findHostInstancesForFiberShallowly(fiber, hostInstances);
  5471. } else {
  5472. // If there's no match, maybe there will be one further down in the child tree.
  5473. if (child !== null) {
  5474. findHostInstancesForMatchingFibersRecursively(
  5475. child,
  5476. types,
  5477. hostInstances
  5478. );
  5479. }
  5480. }
  5481. if (sibling !== null) {
  5482. findHostInstancesForMatchingFibersRecursively(
  5483. sibling,
  5484. types,
  5485. hostInstances
  5486. );
  5487. }
  5488. }
  5489. }
  5490. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  5491. {
  5492. var foundHostInstances = findChildHostInstancesForFiberShallowly(
  5493. fiber,
  5494. hostInstances
  5495. );
  5496. if (foundHostInstances) {
  5497. return;
  5498. } // If we didn't find any host children, fallback to closest host parent.
  5499. var node = fiber;
  5500. while (true) {
  5501. switch (node.tag) {
  5502. case HostComponent:
  5503. hostInstances.add(node.stateNode);
  5504. return;
  5505. case HostPortal:
  5506. hostInstances.add(node.stateNode.containerInfo);
  5507. return;
  5508. case HostRoot:
  5509. hostInstances.add(node.stateNode.containerInfo);
  5510. return;
  5511. }
  5512. if (node.return === null) {
  5513. throw new Error("Expected to reach root first.");
  5514. }
  5515. node = node.return;
  5516. }
  5517. }
  5518. }
  5519. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  5520. {
  5521. var node = fiber;
  5522. var foundHostInstances = false;
  5523. while (true) {
  5524. if (node.tag === HostComponent) {
  5525. // We got a match.
  5526. foundHostInstances = true;
  5527. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  5528. } else if (node.child !== null) {
  5529. node.child.return = node;
  5530. node = node.child;
  5531. continue;
  5532. }
  5533. if (node === fiber) {
  5534. return foundHostInstances;
  5535. }
  5536. while (node.sibling === null) {
  5537. if (node.return === null || node.return === fiber) {
  5538. return foundHostInstances;
  5539. }
  5540. node = node.return;
  5541. }
  5542. node.sibling.return = node.return;
  5543. node = node.sibling;
  5544. }
  5545. }
  5546. return false;
  5547. }
  5548. function resolveDefaultProps(Component, baseProps) {
  5549. if (Component && Component.defaultProps) {
  5550. // Resolve default props. Taken from ReactElement
  5551. var props = Object.assign({}, baseProps);
  5552. var defaultProps = Component.defaultProps;
  5553. for (var propName in defaultProps) {
  5554. if (props[propName] === undefined) {
  5555. props[propName] = defaultProps[propName];
  5556. }
  5557. }
  5558. return props;
  5559. }
  5560. return baseProps;
  5561. }
  5562. function readLazyComponentType(lazyComponent) {
  5563. initializeLazyComponentType(lazyComponent);
  5564. if (lazyComponent._status !== Resolved) {
  5565. throw lazyComponent._result;
  5566. }
  5567. return lazyComponent._result;
  5568. }
  5569. var valueCursor = createCursor(null);
  5570. var rendererSigil;
  5571. {
  5572. // Use this to detect multiple renderers using the same context
  5573. rendererSigil = {};
  5574. }
  5575. var currentlyRenderingFiber = null;
  5576. var lastContextDependency = null;
  5577. var lastContextWithAllBitsObserved = null;
  5578. var isDisallowedContextReadInDEV = false;
  5579. function resetContextDependencies() {
  5580. // This is called right before React yields execution, to ensure `readContext`
  5581. // cannot be called outside the render phase.
  5582. currentlyRenderingFiber = null;
  5583. lastContextDependency = null;
  5584. lastContextWithAllBitsObserved = null;
  5585. {
  5586. isDisallowedContextReadInDEV = false;
  5587. }
  5588. }
  5589. function enterDisallowedContextReadInDEV() {
  5590. {
  5591. isDisallowedContextReadInDEV = true;
  5592. }
  5593. }
  5594. function exitDisallowedContextReadInDEV() {
  5595. {
  5596. isDisallowedContextReadInDEV = false;
  5597. }
  5598. }
  5599. function pushProvider(providerFiber, nextValue) {
  5600. var context = providerFiber.type._context;
  5601. {
  5602. push(valueCursor, context._currentValue, providerFiber);
  5603. context._currentValue = nextValue;
  5604. {
  5605. if (
  5606. context._currentRenderer !== undefined &&
  5607. context._currentRenderer !== null &&
  5608. context._currentRenderer !== rendererSigil
  5609. ) {
  5610. error(
  5611. "Detected multiple renderers concurrently rendering the " +
  5612. "same context provider. This is currently unsupported."
  5613. );
  5614. }
  5615. context._currentRenderer = rendererSigil;
  5616. }
  5617. }
  5618. }
  5619. function popProvider(providerFiber) {
  5620. var currentValue = valueCursor.current;
  5621. pop(valueCursor, providerFiber);
  5622. var context = providerFiber.type._context;
  5623. {
  5624. context._currentValue = currentValue;
  5625. }
  5626. }
  5627. function calculateChangedBits(context, newValue, oldValue) {
  5628. if (objectIs(oldValue, newValue)) {
  5629. // No change
  5630. return 0;
  5631. } else {
  5632. var changedBits =
  5633. typeof context._calculateChangedBits === "function"
  5634. ? context._calculateChangedBits(oldValue, newValue)
  5635. : MAX_SIGNED_31_BIT_INT;
  5636. {
  5637. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  5638. error(
  5639. "calculateChangedBits: Expected the return value to be a " +
  5640. "31-bit integer. Instead received: %s",
  5641. changedBits
  5642. );
  5643. }
  5644. }
  5645. return changedBits | 0;
  5646. }
  5647. }
  5648. function scheduleWorkOnParentPath(parent, renderExpirationTime) {
  5649. // Update the child expiration time of all the ancestors, including
  5650. // the alternates.
  5651. var node = parent;
  5652. while (node !== null) {
  5653. var alternate = node.alternate;
  5654. if (node.childExpirationTime < renderExpirationTime) {
  5655. node.childExpirationTime = renderExpirationTime;
  5656. if (
  5657. alternate !== null &&
  5658. alternate.childExpirationTime < renderExpirationTime
  5659. ) {
  5660. alternate.childExpirationTime = renderExpirationTime;
  5661. }
  5662. } else if (
  5663. alternate !== null &&
  5664. alternate.childExpirationTime < renderExpirationTime
  5665. ) {
  5666. alternate.childExpirationTime = renderExpirationTime;
  5667. } else {
  5668. // Neither alternate was updated, which means the rest of the
  5669. // ancestor path already has sufficient priority.
  5670. break;
  5671. }
  5672. node = node.return;
  5673. }
  5674. }
  5675. function propagateContextChange(
  5676. workInProgress,
  5677. context,
  5678. changedBits,
  5679. renderExpirationTime
  5680. ) {
  5681. var fiber = workInProgress.child;
  5682. if (fiber !== null) {
  5683. // Set the return pointer of the child to the work-in-progress fiber.
  5684. fiber.return = workInProgress;
  5685. }
  5686. while (fiber !== null) {
  5687. var nextFiber = void 0; // Visit this fiber.
  5688. var list = fiber.dependencies;
  5689. if (list !== null) {
  5690. nextFiber = fiber.child;
  5691. var dependency = list.firstContext;
  5692. while (dependency !== null) {
  5693. // Check if the context matches.
  5694. if (
  5695. dependency.context === context &&
  5696. (dependency.observedBits & changedBits) !== 0
  5697. ) {
  5698. // Match! Schedule an update on this fiber.
  5699. if (fiber.tag === ClassComponent) {
  5700. // Schedule a force update on the work-in-progress.
  5701. var update = createUpdate(renderExpirationTime, null);
  5702. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  5703. // update to the current fiber, too, which means it will persist even if
  5704. // this render is thrown away. Since it's a race condition, not sure it's
  5705. // worth fixing.
  5706. enqueueUpdate(fiber, update);
  5707. }
  5708. if (fiber.expirationTime < renderExpirationTime) {
  5709. fiber.expirationTime = renderExpirationTime;
  5710. }
  5711. var alternate = fiber.alternate;
  5712. if (
  5713. alternate !== null &&
  5714. alternate.expirationTime < renderExpirationTime
  5715. ) {
  5716. alternate.expirationTime = renderExpirationTime;
  5717. }
  5718. scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
  5719. if (list.expirationTime < renderExpirationTime) {
  5720. list.expirationTime = renderExpirationTime;
  5721. } // Since we already found a match, we can stop traversing the
  5722. // dependency list.
  5723. break;
  5724. }
  5725. dependency = dependency.next;
  5726. }
  5727. } else if (fiber.tag === ContextProvider) {
  5728. // Don't scan deeper if this is a matching provider
  5729. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  5730. } else {
  5731. // Traverse down.
  5732. nextFiber = fiber.child;
  5733. }
  5734. if (nextFiber !== null) {
  5735. // Set the return pointer of the child to the work-in-progress fiber.
  5736. nextFiber.return = fiber;
  5737. } else {
  5738. // No child. Traverse to next sibling.
  5739. nextFiber = fiber;
  5740. while (nextFiber !== null) {
  5741. if (nextFiber === workInProgress) {
  5742. // We're back to the root of this subtree. Exit.
  5743. nextFiber = null;
  5744. break;
  5745. }
  5746. var sibling = nextFiber.sibling;
  5747. if (sibling !== null) {
  5748. // Set the return pointer of the sibling to the work-in-progress fiber.
  5749. sibling.return = nextFiber.return;
  5750. nextFiber = sibling;
  5751. break;
  5752. } // No more siblings. Traverse up.
  5753. nextFiber = nextFiber.return;
  5754. }
  5755. }
  5756. fiber = nextFiber;
  5757. }
  5758. }
  5759. function prepareToReadContext(workInProgress, renderExpirationTime) {
  5760. currentlyRenderingFiber = workInProgress;
  5761. lastContextDependency = null;
  5762. lastContextWithAllBitsObserved = null;
  5763. var dependencies = workInProgress.dependencies;
  5764. if (dependencies !== null) {
  5765. var firstContext = dependencies.firstContext;
  5766. if (firstContext !== null) {
  5767. if (dependencies.expirationTime >= renderExpirationTime) {
  5768. // Context list has a pending update. Mark that this fiber performed work.
  5769. markWorkInProgressReceivedUpdate();
  5770. } // Reset the work-in-progress list
  5771. dependencies.firstContext = null;
  5772. }
  5773. }
  5774. }
  5775. function readContext(context, observedBits) {
  5776. {
  5777. // This warning would fire if you read context inside a Hook like useMemo.
  5778. // Unlike the class check below, it's not enforced in production for perf.
  5779. if (isDisallowedContextReadInDEV) {
  5780. error(
  5781. "Context can only be read while React is rendering. " +
  5782. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  5783. "In function components, you can read it directly in the function body, but not " +
  5784. "inside Hooks like useReducer() or useMemo()."
  5785. );
  5786. }
  5787. }
  5788. if (lastContextWithAllBitsObserved === context);
  5789. else if (observedBits === false || observedBits === 0);
  5790. else {
  5791. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  5792. if (
  5793. typeof observedBits !== "number" ||
  5794. observedBits === MAX_SIGNED_31_BIT_INT
  5795. ) {
  5796. // Observe all updates.
  5797. lastContextWithAllBitsObserved = context;
  5798. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  5799. } else {
  5800. resolvedObservedBits = observedBits;
  5801. }
  5802. var contextItem = {
  5803. context: context,
  5804. observedBits: resolvedObservedBits,
  5805. next: null
  5806. };
  5807. if (lastContextDependency === null) {
  5808. if (!(currentlyRenderingFiber !== null)) {
  5809. throw Error(
  5810. "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()."
  5811. );
  5812. } // This is the first dependency for this component. Create a new list.
  5813. lastContextDependency = contextItem;
  5814. currentlyRenderingFiber.dependencies = {
  5815. expirationTime: NoWork,
  5816. firstContext: contextItem,
  5817. responders: null
  5818. };
  5819. } else {
  5820. // Append a new context item.
  5821. lastContextDependency = lastContextDependency.next = contextItem;
  5822. }
  5823. }
  5824. return context._currentValue;
  5825. }
  5826. var UpdateState = 0;
  5827. var ReplaceState = 1;
  5828. var ForceUpdate = 2;
  5829. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  5830. // It should only be read right after calling `processUpdateQueue`, via
  5831. // `checkHasForceUpdateAfterProcessing`.
  5832. var hasForceUpdate = false;
  5833. var didWarnUpdateInsideUpdate;
  5834. var currentlyProcessingQueue;
  5835. {
  5836. didWarnUpdateInsideUpdate = false;
  5837. currentlyProcessingQueue = null;
  5838. }
  5839. function initializeUpdateQueue(fiber) {
  5840. var queue = {
  5841. baseState: fiber.memoizedState,
  5842. baseQueue: null,
  5843. shared: {
  5844. pending: null
  5845. },
  5846. effects: null
  5847. };
  5848. fiber.updateQueue = queue;
  5849. }
  5850. function cloneUpdateQueue(current, workInProgress) {
  5851. // Clone the update queue from current. Unless it's already a clone.
  5852. var queue = workInProgress.updateQueue;
  5853. var currentQueue = current.updateQueue;
  5854. if (queue === currentQueue) {
  5855. var clone = {
  5856. baseState: currentQueue.baseState,
  5857. baseQueue: currentQueue.baseQueue,
  5858. shared: currentQueue.shared,
  5859. effects: currentQueue.effects
  5860. };
  5861. workInProgress.updateQueue = clone;
  5862. }
  5863. }
  5864. function createUpdate(expirationTime, suspenseConfig) {
  5865. var update = {
  5866. expirationTime: expirationTime,
  5867. suspenseConfig: suspenseConfig,
  5868. tag: UpdateState,
  5869. payload: null,
  5870. callback: null,
  5871. next: null
  5872. };
  5873. update.next = update;
  5874. {
  5875. update.priority = getCurrentPriorityLevel();
  5876. }
  5877. return update;
  5878. }
  5879. function enqueueUpdate(fiber, update) {
  5880. var updateQueue = fiber.updateQueue;
  5881. if (updateQueue === null) {
  5882. // Only occurs if the fiber has been unmounted.
  5883. return;
  5884. }
  5885. var sharedQueue = updateQueue.shared;
  5886. var pending = sharedQueue.pending;
  5887. if (pending === null) {
  5888. // This is the first update. Create a circular list.
  5889. update.next = update;
  5890. } else {
  5891. update.next = pending.next;
  5892. pending.next = update;
  5893. }
  5894. sharedQueue.pending = update;
  5895. {
  5896. if (
  5897. currentlyProcessingQueue === sharedQueue &&
  5898. !didWarnUpdateInsideUpdate
  5899. ) {
  5900. error(
  5901. "An update (setState, replaceState, or forceUpdate) was scheduled " +
  5902. "from inside an update function. Update functions should be pure, " +
  5903. "with zero side-effects. Consider using componentDidUpdate or a " +
  5904. "callback."
  5905. );
  5906. didWarnUpdateInsideUpdate = true;
  5907. }
  5908. }
  5909. }
  5910. function enqueueCapturedUpdate(workInProgress, update) {
  5911. var current = workInProgress.alternate;
  5912. if (current !== null) {
  5913. // Ensure the work-in-progress queue is a clone
  5914. cloneUpdateQueue(current, workInProgress);
  5915. } // Captured updates go only on the work-in-progress queue.
  5916. var queue = workInProgress.updateQueue; // Append the update to the end of the list.
  5917. var last = queue.baseQueue;
  5918. if (last === null) {
  5919. queue.baseQueue = update.next = update;
  5920. update.next = update;
  5921. } else {
  5922. update.next = last.next;
  5923. last.next = update;
  5924. }
  5925. }
  5926. function getStateFromUpdate(
  5927. workInProgress,
  5928. queue,
  5929. update,
  5930. prevState,
  5931. nextProps,
  5932. instance
  5933. ) {
  5934. switch (update.tag) {
  5935. case ReplaceState: {
  5936. var payload = update.payload;
  5937. if (typeof payload === "function") {
  5938. // Updater function
  5939. {
  5940. enterDisallowedContextReadInDEV();
  5941. if (workInProgress.mode & StrictMode) {
  5942. payload.call(instance, prevState, nextProps);
  5943. }
  5944. }
  5945. var nextState = payload.call(instance, prevState, nextProps);
  5946. {
  5947. exitDisallowedContextReadInDEV();
  5948. }
  5949. return nextState;
  5950. } // State object
  5951. return payload;
  5952. }
  5953. case CaptureUpdate: {
  5954. workInProgress.effectTag =
  5955. (workInProgress.effectTag & ~ShouldCapture) | DidCapture;
  5956. }
  5957. // Intentional fallthrough
  5958. case UpdateState: {
  5959. var _payload = update.payload;
  5960. var partialState;
  5961. if (typeof _payload === "function") {
  5962. // Updater function
  5963. {
  5964. enterDisallowedContextReadInDEV();
  5965. if (workInProgress.mode & StrictMode) {
  5966. _payload.call(instance, prevState, nextProps);
  5967. }
  5968. }
  5969. partialState = _payload.call(instance, prevState, nextProps);
  5970. {
  5971. exitDisallowedContextReadInDEV();
  5972. }
  5973. } else {
  5974. // Partial state object
  5975. partialState = _payload;
  5976. }
  5977. if (partialState === null || partialState === undefined) {
  5978. // Null and undefined are treated as no-ops.
  5979. return prevState;
  5980. } // Merge the partial state and the previous state.
  5981. return Object.assign({}, prevState, partialState);
  5982. }
  5983. case ForceUpdate: {
  5984. hasForceUpdate = true;
  5985. return prevState;
  5986. }
  5987. }
  5988. return prevState;
  5989. }
  5990. function processUpdateQueue(
  5991. workInProgress,
  5992. props,
  5993. instance,
  5994. renderExpirationTime
  5995. ) {
  5996. // This is always non-null on a ClassComponent or HostRoot
  5997. var queue = workInProgress.updateQueue;
  5998. hasForceUpdate = false;
  5999. {
  6000. currentlyProcessingQueue = queue.shared;
  6001. } // The last rebase update that is NOT part of the base state.
  6002. var baseQueue = queue.baseQueue; // The last pending update that hasn't been processed yet.
  6003. var pendingQueue = queue.shared.pending;
  6004. if (pendingQueue !== null) {
  6005. // We have new updates that haven't been processed yet.
  6006. // We'll add them to the base queue.
  6007. if (baseQueue !== null) {
  6008. // Merge the pending queue and the base queue.
  6009. var baseFirst = baseQueue.next;
  6010. var pendingFirst = pendingQueue.next;
  6011. baseQueue.next = pendingFirst;
  6012. pendingQueue.next = baseFirst;
  6013. }
  6014. baseQueue = pendingQueue;
  6015. queue.shared.pending = null; // TODO: Pass `current` as argument
  6016. var current = workInProgress.alternate;
  6017. if (current !== null) {
  6018. var currentQueue = current.updateQueue;
  6019. if (currentQueue !== null) {
  6020. currentQueue.baseQueue = pendingQueue;
  6021. }
  6022. }
  6023. } // These values may change as we process the queue.
  6024. if (baseQueue !== null) {
  6025. var first = baseQueue.next; // Iterate through the list of updates to compute the result.
  6026. var newState = queue.baseState;
  6027. var newExpirationTime = NoWork;
  6028. var newBaseState = null;
  6029. var newBaseQueueFirst = null;
  6030. var newBaseQueueLast = null;
  6031. if (first !== null) {
  6032. var update = first;
  6033. do {
  6034. var updateExpirationTime = update.expirationTime;
  6035. if (updateExpirationTime < renderExpirationTime) {
  6036. // Priority is insufficient. Skip this update. If this is the first
  6037. // skipped update, the previous update/state is the new base
  6038. // update/state.
  6039. var clone = {
  6040. expirationTime: update.expirationTime,
  6041. suspenseConfig: update.suspenseConfig,
  6042. tag: update.tag,
  6043. payload: update.payload,
  6044. callback: update.callback,
  6045. next: null
  6046. };
  6047. if (newBaseQueueLast === null) {
  6048. newBaseQueueFirst = newBaseQueueLast = clone;
  6049. newBaseState = newState;
  6050. } else {
  6051. newBaseQueueLast = newBaseQueueLast.next = clone;
  6052. } // Update the remaining priority in the queue.
  6053. if (updateExpirationTime > newExpirationTime) {
  6054. newExpirationTime = updateExpirationTime;
  6055. }
  6056. } else {
  6057. // This update does have sufficient priority.
  6058. if (newBaseQueueLast !== null) {
  6059. var _clone = {
  6060. expirationTime: Sync,
  6061. // This update is going to be committed so we never want uncommit it.
  6062. suspenseConfig: update.suspenseConfig,
  6063. tag: update.tag,
  6064. payload: update.payload,
  6065. callback: update.callback,
  6066. next: null
  6067. };
  6068. newBaseQueueLast = newBaseQueueLast.next = _clone;
  6069. } // Mark the event time of this update as relevant to this render pass.
  6070. // TODO: This should ideally use the true event time of this update rather than
  6071. // its priority which is a derived and not reverseable value.
  6072. // TODO: We should skip this update if it was already committed but currently
  6073. // we have no way of detecting the difference between a committed and suspended
  6074. // update here.
  6075. markRenderEventTimeAndConfig(
  6076. updateExpirationTime,
  6077. update.suspenseConfig
  6078. ); // Process this update.
  6079. newState = getStateFromUpdate(
  6080. workInProgress,
  6081. queue,
  6082. update,
  6083. newState,
  6084. props,
  6085. instance
  6086. );
  6087. var callback = update.callback;
  6088. if (callback !== null) {
  6089. workInProgress.effectTag |= Callback;
  6090. var effects = queue.effects;
  6091. if (effects === null) {
  6092. queue.effects = [update];
  6093. } else {
  6094. effects.push(update);
  6095. }
  6096. }
  6097. }
  6098. update = update.next;
  6099. if (update === null || update === first) {
  6100. pendingQueue = queue.shared.pending;
  6101. if (pendingQueue === null) {
  6102. break;
  6103. } else {
  6104. // An update was scheduled from inside a reducer. Add the new
  6105. // pending updates to the end of the list and keep processing.
  6106. update = baseQueue.next = pendingQueue.next;
  6107. pendingQueue.next = first;
  6108. queue.baseQueue = baseQueue = pendingQueue;
  6109. queue.shared.pending = null;
  6110. }
  6111. }
  6112. } while (true);
  6113. }
  6114. if (newBaseQueueLast === null) {
  6115. newBaseState = newState;
  6116. } else {
  6117. newBaseQueueLast.next = newBaseQueueFirst;
  6118. }
  6119. queue.baseState = newBaseState;
  6120. queue.baseQueue = newBaseQueueLast; // Set the remaining expiration time to be whatever is remaining in the queue.
  6121. // This should be fine because the only two other things that contribute to
  6122. // expiration time are props and context. We're already in the middle of the
  6123. // begin phase by the time we start processing the queue, so we've already
  6124. // dealt with the props. Context in components that specify
  6125. // shouldComponentUpdate is tricky; but we'll have to account for
  6126. // that regardless.
  6127. markUnprocessedUpdateTime(newExpirationTime);
  6128. workInProgress.expirationTime = newExpirationTime;
  6129. workInProgress.memoizedState = newState;
  6130. }
  6131. {
  6132. currentlyProcessingQueue = null;
  6133. }
  6134. }
  6135. function callCallback(callback, context) {
  6136. if (!(typeof callback === "function")) {
  6137. throw Error(
  6138. "Invalid argument passed as callback. Expected a function. Instead received: " +
  6139. callback
  6140. );
  6141. }
  6142. callback.call(context);
  6143. }
  6144. function resetHasForceUpdateBeforeProcessing() {
  6145. hasForceUpdate = false;
  6146. }
  6147. function checkHasForceUpdateAfterProcessing() {
  6148. return hasForceUpdate;
  6149. }
  6150. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  6151. // Commit the effects
  6152. var effects = finishedQueue.effects;
  6153. finishedQueue.effects = null;
  6154. if (effects !== null) {
  6155. for (var i = 0; i < effects.length; i++) {
  6156. var effect = effects[i];
  6157. var callback = effect.callback;
  6158. if (callback !== null) {
  6159. effect.callback = null;
  6160. callCallback(callback, instance);
  6161. }
  6162. }
  6163. }
  6164. }
  6165. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  6166. function requestCurrentSuspenseConfig() {
  6167. return ReactCurrentBatchConfig.suspense;
  6168. }
  6169. var fakeInternalInstance = {};
  6170. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  6171. // We'll use it to determine whether we need to initialize legacy refs.
  6172. var emptyRefsObject = new React.Component().refs;
  6173. var didWarnAboutStateAssignmentForComponent;
  6174. var didWarnAboutUninitializedState;
  6175. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  6176. var didWarnAboutLegacyLifecyclesAndDerivedState;
  6177. var didWarnAboutUndefinedDerivedState;
  6178. var warnOnUndefinedDerivedState;
  6179. var warnOnInvalidCallback;
  6180. var didWarnAboutDirectlyAssigningPropsToState;
  6181. var didWarnAboutContextTypeAndContextTypes;
  6182. var didWarnAboutInvalidateContextType;
  6183. {
  6184. didWarnAboutStateAssignmentForComponent = new Set();
  6185. didWarnAboutUninitializedState = new Set();
  6186. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  6187. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  6188. didWarnAboutDirectlyAssigningPropsToState = new Set();
  6189. didWarnAboutUndefinedDerivedState = new Set();
  6190. didWarnAboutContextTypeAndContextTypes = new Set();
  6191. didWarnAboutInvalidateContextType = new Set();
  6192. var didWarnOnInvalidCallback = new Set();
  6193. warnOnInvalidCallback = function(callback, callerName) {
  6194. if (callback === null || typeof callback === "function") {
  6195. return;
  6196. }
  6197. var key = callerName + "_" + callback;
  6198. if (!didWarnOnInvalidCallback.has(key)) {
  6199. didWarnOnInvalidCallback.add(key);
  6200. error(
  6201. "%s(...): Expected the last optional `callback` argument to be a " +
  6202. "function. Instead received: %s.",
  6203. callerName,
  6204. callback
  6205. );
  6206. }
  6207. };
  6208. warnOnUndefinedDerivedState = function(type, partialState) {
  6209. if (partialState === undefined) {
  6210. var componentName = getComponentName(type) || "Component";
  6211. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  6212. didWarnAboutUndefinedDerivedState.add(componentName);
  6213. error(
  6214. "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " +
  6215. "You have returned undefined.",
  6216. componentName
  6217. );
  6218. }
  6219. }
  6220. }; // This is so gross but it's at least non-critical and can be removed if
  6221. // it causes problems. This is meant to give a nicer error message for
  6222. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  6223. // ...)) which otherwise throws a "_processChildContext is not a function"
  6224. // exception.
  6225. Object.defineProperty(fakeInternalInstance, "_processChildContext", {
  6226. enumerable: false,
  6227. value: function() {
  6228. {
  6229. throw Error(
  6230. "_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)."
  6231. );
  6232. }
  6233. }
  6234. });
  6235. Object.freeze(fakeInternalInstance);
  6236. }
  6237. function applyDerivedStateFromProps(
  6238. workInProgress,
  6239. ctor,
  6240. getDerivedStateFromProps,
  6241. nextProps
  6242. ) {
  6243. var prevState = workInProgress.memoizedState;
  6244. {
  6245. if (workInProgress.mode & StrictMode) {
  6246. // Invoke the function an extra time to help detect side-effects.
  6247. getDerivedStateFromProps(nextProps, prevState);
  6248. }
  6249. }
  6250. var partialState = getDerivedStateFromProps(nextProps, prevState);
  6251. {
  6252. warnOnUndefinedDerivedState(ctor, partialState);
  6253. } // Merge the partial state and the previous state.
  6254. var memoizedState =
  6255. partialState === null || partialState === undefined
  6256. ? prevState
  6257. : Object.assign({}, prevState, partialState);
  6258. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  6259. // base state.
  6260. if (workInProgress.expirationTime === NoWork) {
  6261. // Queue is always non-null for classes
  6262. var updateQueue = workInProgress.updateQueue;
  6263. updateQueue.baseState = memoizedState;
  6264. }
  6265. }
  6266. var classComponentUpdater = {
  6267. isMounted: isMounted,
  6268. enqueueSetState: function(inst, payload, callback) {
  6269. var fiber = get(inst);
  6270. var currentTime = requestCurrentTimeForUpdate();
  6271. var suspenseConfig = requestCurrentSuspenseConfig();
  6272. var expirationTime = computeExpirationForFiber(
  6273. currentTime,
  6274. fiber,
  6275. suspenseConfig
  6276. );
  6277. var update = createUpdate(expirationTime, suspenseConfig);
  6278. update.payload = payload;
  6279. if (callback !== undefined && callback !== null) {
  6280. {
  6281. warnOnInvalidCallback(callback, "setState");
  6282. }
  6283. update.callback = callback;
  6284. }
  6285. enqueueUpdate(fiber, update);
  6286. scheduleWork(fiber, expirationTime);
  6287. },
  6288. enqueueReplaceState: function(inst, payload, callback) {
  6289. var fiber = get(inst);
  6290. var currentTime = requestCurrentTimeForUpdate();
  6291. var suspenseConfig = requestCurrentSuspenseConfig();
  6292. var expirationTime = computeExpirationForFiber(
  6293. currentTime,
  6294. fiber,
  6295. suspenseConfig
  6296. );
  6297. var update = createUpdate(expirationTime, suspenseConfig);
  6298. update.tag = ReplaceState;
  6299. update.payload = payload;
  6300. if (callback !== undefined && callback !== null) {
  6301. {
  6302. warnOnInvalidCallback(callback, "replaceState");
  6303. }
  6304. update.callback = callback;
  6305. }
  6306. enqueueUpdate(fiber, update);
  6307. scheduleWork(fiber, expirationTime);
  6308. },
  6309. enqueueForceUpdate: function(inst, callback) {
  6310. var fiber = get(inst);
  6311. var currentTime = requestCurrentTimeForUpdate();
  6312. var suspenseConfig = requestCurrentSuspenseConfig();
  6313. var expirationTime = computeExpirationForFiber(
  6314. currentTime,
  6315. fiber,
  6316. suspenseConfig
  6317. );
  6318. var update = createUpdate(expirationTime, suspenseConfig);
  6319. update.tag = ForceUpdate;
  6320. if (callback !== undefined && callback !== null) {
  6321. {
  6322. warnOnInvalidCallback(callback, "forceUpdate");
  6323. }
  6324. update.callback = callback;
  6325. }
  6326. enqueueUpdate(fiber, update);
  6327. scheduleWork(fiber, expirationTime);
  6328. }
  6329. };
  6330. function checkShouldComponentUpdate(
  6331. workInProgress,
  6332. ctor,
  6333. oldProps,
  6334. newProps,
  6335. oldState,
  6336. newState,
  6337. nextContext
  6338. ) {
  6339. var instance = workInProgress.stateNode;
  6340. if (typeof instance.shouldComponentUpdate === "function") {
  6341. {
  6342. if (workInProgress.mode & StrictMode) {
  6343. // Invoke the function an extra time to help detect side-effects.
  6344. instance.shouldComponentUpdate(newProps, newState, nextContext);
  6345. }
  6346. }
  6347. startPhaseTimer(workInProgress, "shouldComponentUpdate");
  6348. var shouldUpdate = instance.shouldComponentUpdate(
  6349. newProps,
  6350. newState,
  6351. nextContext
  6352. );
  6353. stopPhaseTimer();
  6354. {
  6355. if (shouldUpdate === undefined) {
  6356. error(
  6357. "%s.shouldComponentUpdate(): Returned undefined instead of a " +
  6358. "boolean value. Make sure to return true or false.",
  6359. getComponentName(ctor) || "Component"
  6360. );
  6361. }
  6362. }
  6363. return shouldUpdate;
  6364. }
  6365. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  6366. return (
  6367. !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState)
  6368. );
  6369. }
  6370. return true;
  6371. }
  6372. function checkClassInstance(workInProgress, ctor, newProps) {
  6373. var instance = workInProgress.stateNode;
  6374. {
  6375. var name = getComponentName(ctor) || "Component";
  6376. var renderPresent = instance.render;
  6377. if (!renderPresent) {
  6378. if (ctor.prototype && typeof ctor.prototype.render === "function") {
  6379. error(
  6380. "%s(...): No `render` method found on the returned component " +
  6381. "instance: did you accidentally return an object from the constructor?",
  6382. name
  6383. );
  6384. } else {
  6385. error(
  6386. "%s(...): No `render` method found on the returned component " +
  6387. "instance: you may have forgotten to define `render`.",
  6388. name
  6389. );
  6390. }
  6391. }
  6392. if (
  6393. instance.getInitialState &&
  6394. !instance.getInitialState.isReactClassApproved &&
  6395. !instance.state
  6396. ) {
  6397. error(
  6398. "getInitialState was defined on %s, a plain JavaScript class. " +
  6399. "This is only supported for classes created using React.createClass. " +
  6400. "Did you mean to define a state property instead?",
  6401. name
  6402. );
  6403. }
  6404. if (
  6405. instance.getDefaultProps &&
  6406. !instance.getDefaultProps.isReactClassApproved
  6407. ) {
  6408. error(
  6409. "getDefaultProps was defined on %s, a plain JavaScript class. " +
  6410. "This is only supported for classes created using React.createClass. " +
  6411. "Use a static property to define defaultProps instead.",
  6412. name
  6413. );
  6414. }
  6415. if (instance.propTypes) {
  6416. error(
  6417. "propTypes was defined as an instance property on %s. Use a static " +
  6418. "property to define propTypes instead.",
  6419. name
  6420. );
  6421. }
  6422. if (instance.contextType) {
  6423. error(
  6424. "contextType was defined as an instance property on %s. Use a static " +
  6425. "property to define contextType instead.",
  6426. name
  6427. );
  6428. }
  6429. {
  6430. if (instance.contextTypes) {
  6431. error(
  6432. "contextTypes was defined as an instance property on %s. Use a static " +
  6433. "property to define contextTypes instead.",
  6434. name
  6435. );
  6436. }
  6437. if (
  6438. ctor.contextType &&
  6439. ctor.contextTypes &&
  6440. !didWarnAboutContextTypeAndContextTypes.has(ctor)
  6441. ) {
  6442. didWarnAboutContextTypeAndContextTypes.add(ctor);
  6443. error(
  6444. "%s declares both contextTypes and contextType static properties. " +
  6445. "The legacy contextTypes property will be ignored.",
  6446. name
  6447. );
  6448. }
  6449. }
  6450. if (typeof instance.componentShouldUpdate === "function") {
  6451. error(
  6452. "%s has a method called " +
  6453. "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " +
  6454. "The name is phrased as a question because the function is " +
  6455. "expected to return a value.",
  6456. name
  6457. );
  6458. }
  6459. if (
  6460. ctor.prototype &&
  6461. ctor.prototype.isPureReactComponent &&
  6462. typeof instance.shouldComponentUpdate !== "undefined"
  6463. ) {
  6464. error(
  6465. "%s has a method called shouldComponentUpdate(). " +
  6466. "shouldComponentUpdate should not be used when extending React.PureComponent. " +
  6467. "Please extend React.Component if shouldComponentUpdate is used.",
  6468. getComponentName(ctor) || "A pure component"
  6469. );
  6470. }
  6471. if (typeof instance.componentDidUnmount === "function") {
  6472. error(
  6473. "%s has a method called " +
  6474. "componentDidUnmount(). But there is no such lifecycle method. " +
  6475. "Did you mean componentWillUnmount()?",
  6476. name
  6477. );
  6478. }
  6479. if (typeof instance.componentDidReceiveProps === "function") {
  6480. error(
  6481. "%s has a method called " +
  6482. "componentDidReceiveProps(). But there is no such lifecycle method. " +
  6483. "If you meant to update the state in response to changing props, " +
  6484. "use componentWillReceiveProps(). If you meant to fetch data or " +
  6485. "run side-effects or mutations after React has updated the UI, use componentDidUpdate().",
  6486. name
  6487. );
  6488. }
  6489. if (typeof instance.componentWillRecieveProps === "function") {
  6490. error(
  6491. "%s has a method called " +
  6492. "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?",
  6493. name
  6494. );
  6495. }
  6496. if (typeof instance.UNSAFE_componentWillRecieveProps === "function") {
  6497. error(
  6498. "%s has a method called " +
  6499. "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?",
  6500. name
  6501. );
  6502. }
  6503. var hasMutatedProps = instance.props !== newProps;
  6504. if (instance.props !== undefined && hasMutatedProps) {
  6505. error(
  6506. "%s(...): When calling super() in `%s`, make sure to pass " +
  6507. "up the same props that your component's constructor was passed.",
  6508. name,
  6509. name
  6510. );
  6511. }
  6512. if (instance.defaultProps) {
  6513. error(
  6514. "Setting defaultProps as an instance property on %s is not supported and will be ignored." +
  6515. " Instead, define defaultProps as a static property on %s.",
  6516. name,
  6517. name
  6518. );
  6519. }
  6520. if (
  6521. typeof instance.getSnapshotBeforeUpdate === "function" &&
  6522. typeof instance.componentDidUpdate !== "function" &&
  6523. !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)
  6524. ) {
  6525. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  6526. error(
  6527. "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " +
  6528. "This component defines getSnapshotBeforeUpdate() only.",
  6529. getComponentName(ctor)
  6530. );
  6531. }
  6532. if (typeof instance.getDerivedStateFromProps === "function") {
  6533. error(
  6534. "%s: getDerivedStateFromProps() is defined as an instance method " +
  6535. "and will be ignored. Instead, declare it as a static method.",
  6536. name
  6537. );
  6538. }
  6539. if (typeof instance.getDerivedStateFromError === "function") {
  6540. error(
  6541. "%s: getDerivedStateFromError() is defined as an instance method " +
  6542. "and will be ignored. Instead, declare it as a static method.",
  6543. name
  6544. );
  6545. }
  6546. if (typeof ctor.getSnapshotBeforeUpdate === "function") {
  6547. error(
  6548. "%s: getSnapshotBeforeUpdate() is defined as a static method " +
  6549. "and will be ignored. Instead, declare it as an instance method.",
  6550. name
  6551. );
  6552. }
  6553. var _state = instance.state;
  6554. if (_state && (typeof _state !== "object" || isArray(_state))) {
  6555. error("%s.state: must be set to an object or null", name);
  6556. }
  6557. if (
  6558. typeof instance.getChildContext === "function" &&
  6559. typeof ctor.childContextTypes !== "object"
  6560. ) {
  6561. error(
  6562. "%s.getChildContext(): childContextTypes must be defined in order to " +
  6563. "use getChildContext().",
  6564. name
  6565. );
  6566. }
  6567. }
  6568. }
  6569. function adoptClassInstance(workInProgress, instance) {
  6570. instance.updater = classComponentUpdater;
  6571. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  6572. set(instance, workInProgress);
  6573. {
  6574. instance._reactInternalInstance = fakeInternalInstance;
  6575. }
  6576. }
  6577. function constructClassInstance(workInProgress, ctor, props) {
  6578. var isLegacyContextConsumer = false;
  6579. var unmaskedContext = emptyContextObject;
  6580. var context = emptyContextObject;
  6581. var contextType = ctor.contextType;
  6582. {
  6583. if ("contextType" in ctor) {
  6584. var isValid = // Allow null for conditional declaration
  6585. contextType === null ||
  6586. (contextType !== undefined &&
  6587. contextType.$$typeof === REACT_CONTEXT_TYPE &&
  6588. contextType._context === undefined); // Not a <Context.Consumer>
  6589. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  6590. didWarnAboutInvalidateContextType.add(ctor);
  6591. var addendum = "";
  6592. if (contextType === undefined) {
  6593. addendum =
  6594. " However, it is set to undefined. " +
  6595. "This can be caused by a typo or by mixing up named and default imports. " +
  6596. "This can also happen due to a circular dependency, so " +
  6597. "try moving the createContext() call to a separate file.";
  6598. } else if (typeof contextType !== "object") {
  6599. addendum = " However, it is set to a " + typeof contextType + ".";
  6600. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  6601. addendum = " Did you accidentally pass the Context.Provider instead?";
  6602. } else if (contextType._context !== undefined) {
  6603. // <Context.Consumer>
  6604. addendum = " Did you accidentally pass the Context.Consumer instead?";
  6605. } else {
  6606. addendum =
  6607. " However, it is set to an object with keys {" +
  6608. Object.keys(contextType).join(", ") +
  6609. "}.";
  6610. }
  6611. error(
  6612. "%s defines an invalid contextType. " +
  6613. "contextType should point to the Context object returned by React.createContext().%s",
  6614. getComponentName(ctor) || "Component",
  6615. addendum
  6616. );
  6617. }
  6618. }
  6619. }
  6620. if (typeof contextType === "object" && contextType !== null) {
  6621. context = readContext(contextType);
  6622. } else {
  6623. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6624. var contextTypes = ctor.contextTypes;
  6625. isLegacyContextConsumer =
  6626. contextTypes !== null && contextTypes !== undefined;
  6627. context = isLegacyContextConsumer
  6628. ? getMaskedContext(workInProgress, unmaskedContext)
  6629. : emptyContextObject;
  6630. } // Instantiate twice to help detect side-effects.
  6631. {
  6632. if (workInProgress.mode & StrictMode) {
  6633. new ctor(props, context); // eslint-disable-line no-new
  6634. }
  6635. }
  6636. var instance = new ctor(props, context);
  6637. var state = (workInProgress.memoizedState =
  6638. instance.state !== null && instance.state !== undefined
  6639. ? instance.state
  6640. : null);
  6641. adoptClassInstance(workInProgress, instance);
  6642. {
  6643. if (typeof ctor.getDerivedStateFromProps === "function" && state === null) {
  6644. var componentName = getComponentName(ctor) || "Component";
  6645. if (!didWarnAboutUninitializedState.has(componentName)) {
  6646. didWarnAboutUninitializedState.add(componentName);
  6647. error(
  6648. "`%s` uses `getDerivedStateFromProps` but its initial state is " +
  6649. "%s. This is not recommended. Instead, define the initial state by " +
  6650. "assigning an object to `this.state` in the constructor of `%s`. " +
  6651. "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.",
  6652. componentName,
  6653. instance.state === null ? "null" : "undefined",
  6654. componentName
  6655. );
  6656. }
  6657. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  6658. // Warn about these lifecycles if they are present.
  6659. // Don't warn about react-lifecycles-compat polyfilled methods though.
  6660. if (
  6661. typeof ctor.getDerivedStateFromProps === "function" ||
  6662. typeof instance.getSnapshotBeforeUpdate === "function"
  6663. ) {
  6664. var foundWillMountName = null;
  6665. var foundWillReceivePropsName = null;
  6666. var foundWillUpdateName = null;
  6667. if (
  6668. typeof instance.componentWillMount === "function" &&
  6669. instance.componentWillMount.__suppressDeprecationWarning !== true
  6670. ) {
  6671. foundWillMountName = "componentWillMount";
  6672. } else if (typeof instance.UNSAFE_componentWillMount === "function") {
  6673. foundWillMountName = "UNSAFE_componentWillMount";
  6674. }
  6675. if (
  6676. typeof instance.componentWillReceiveProps === "function" &&
  6677. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  6678. ) {
  6679. foundWillReceivePropsName = "componentWillReceiveProps";
  6680. } else if (
  6681. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  6682. ) {
  6683. foundWillReceivePropsName = "UNSAFE_componentWillReceiveProps";
  6684. }
  6685. if (
  6686. typeof instance.componentWillUpdate === "function" &&
  6687. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  6688. ) {
  6689. foundWillUpdateName = "componentWillUpdate";
  6690. } else if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  6691. foundWillUpdateName = "UNSAFE_componentWillUpdate";
  6692. }
  6693. if (
  6694. foundWillMountName !== null ||
  6695. foundWillReceivePropsName !== null ||
  6696. foundWillUpdateName !== null
  6697. ) {
  6698. var _componentName = getComponentName(ctor) || "Component";
  6699. var newApiName =
  6700. typeof ctor.getDerivedStateFromProps === "function"
  6701. ? "getDerivedStateFromProps()"
  6702. : "getSnapshotBeforeUpdate()";
  6703. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  6704. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  6705. error(
  6706. "Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n" +
  6707. "%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n" +
  6708. "The above lifecycles should be removed. Learn more about this warning here:\n" +
  6709. "https://fb.me/react-unsafe-component-lifecycles",
  6710. _componentName,
  6711. newApiName,
  6712. foundWillMountName !== null ? "\n " + foundWillMountName : "",
  6713. foundWillReceivePropsName !== null
  6714. ? "\n " + foundWillReceivePropsName
  6715. : "",
  6716. foundWillUpdateName !== null ? "\n " + foundWillUpdateName : ""
  6717. );
  6718. }
  6719. }
  6720. }
  6721. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  6722. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  6723. if (isLegacyContextConsumer) {
  6724. cacheContext(workInProgress, unmaskedContext, context);
  6725. }
  6726. return instance;
  6727. }
  6728. function callComponentWillMount(workInProgress, instance) {
  6729. startPhaseTimer(workInProgress, "componentWillMount");
  6730. var oldState = instance.state;
  6731. if (typeof instance.componentWillMount === "function") {
  6732. instance.componentWillMount();
  6733. }
  6734. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6735. instance.UNSAFE_componentWillMount();
  6736. }
  6737. stopPhaseTimer();
  6738. if (oldState !== instance.state) {
  6739. {
  6740. error(
  6741. "%s.componentWillMount(): Assigning directly to this.state is " +
  6742. "deprecated (except inside a component's " +
  6743. "constructor). Use setState instead.",
  6744. getComponentName(workInProgress.type) || "Component"
  6745. );
  6746. }
  6747. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6748. }
  6749. }
  6750. function callComponentWillReceiveProps(
  6751. workInProgress,
  6752. instance,
  6753. newProps,
  6754. nextContext
  6755. ) {
  6756. var oldState = instance.state;
  6757. startPhaseTimer(workInProgress, "componentWillReceiveProps");
  6758. if (typeof instance.componentWillReceiveProps === "function") {
  6759. instance.componentWillReceiveProps(newProps, nextContext);
  6760. }
  6761. if (typeof instance.UNSAFE_componentWillReceiveProps === "function") {
  6762. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  6763. }
  6764. stopPhaseTimer();
  6765. if (instance.state !== oldState) {
  6766. {
  6767. var componentName = getComponentName(workInProgress.type) || "Component";
  6768. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  6769. didWarnAboutStateAssignmentForComponent.add(componentName);
  6770. error(
  6771. "%s.componentWillReceiveProps(): Assigning directly to " +
  6772. "this.state is deprecated (except inside a component's " +
  6773. "constructor). Use setState instead.",
  6774. componentName
  6775. );
  6776. }
  6777. }
  6778. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6779. }
  6780. } // Invokes the mount life-cycles on a previously never rendered instance.
  6781. function mountClassInstance(
  6782. workInProgress,
  6783. ctor,
  6784. newProps,
  6785. renderExpirationTime
  6786. ) {
  6787. {
  6788. checkClassInstance(workInProgress, ctor, newProps);
  6789. }
  6790. var instance = workInProgress.stateNode;
  6791. instance.props = newProps;
  6792. instance.state = workInProgress.memoizedState;
  6793. instance.refs = emptyRefsObject;
  6794. initializeUpdateQueue(workInProgress);
  6795. var contextType = ctor.contextType;
  6796. if (typeof contextType === "object" && contextType !== null) {
  6797. instance.context = readContext(contextType);
  6798. } else {
  6799. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6800. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  6801. }
  6802. {
  6803. if (instance.state === newProps) {
  6804. var componentName = getComponentName(ctor) || "Component";
  6805. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  6806. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  6807. error(
  6808. "%s: It is not recommended to assign props directly to state " +
  6809. "because updates to props won't be reflected in state. " +
  6810. "In most cases, it is better to use props directly.",
  6811. componentName
  6812. );
  6813. }
  6814. }
  6815. if (workInProgress.mode & StrictMode) {
  6816. ReactStrictModeWarnings.recordLegacyContextWarning(
  6817. workInProgress,
  6818. instance
  6819. );
  6820. }
  6821. {
  6822. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(
  6823. workInProgress,
  6824. instance
  6825. );
  6826. }
  6827. }
  6828. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6829. instance.state = workInProgress.memoizedState;
  6830. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6831. if (typeof getDerivedStateFromProps === "function") {
  6832. applyDerivedStateFromProps(
  6833. workInProgress,
  6834. ctor,
  6835. getDerivedStateFromProps,
  6836. newProps
  6837. );
  6838. instance.state = workInProgress.memoizedState;
  6839. } // In order to support react-lifecycles-compat polyfilled components,
  6840. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6841. if (
  6842. typeof ctor.getDerivedStateFromProps !== "function" &&
  6843. typeof instance.getSnapshotBeforeUpdate !== "function" &&
  6844. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6845. typeof instance.componentWillMount === "function")
  6846. ) {
  6847. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  6848. // process them now.
  6849. processUpdateQueue(
  6850. workInProgress,
  6851. newProps,
  6852. instance,
  6853. renderExpirationTime
  6854. );
  6855. instance.state = workInProgress.memoizedState;
  6856. }
  6857. if (typeof instance.componentDidMount === "function") {
  6858. workInProgress.effectTag |= Update;
  6859. }
  6860. }
  6861. function resumeMountClassInstance(
  6862. workInProgress,
  6863. ctor,
  6864. newProps,
  6865. renderExpirationTime
  6866. ) {
  6867. var instance = workInProgress.stateNode;
  6868. var oldProps = workInProgress.memoizedProps;
  6869. instance.props = oldProps;
  6870. var oldContext = instance.context;
  6871. var contextType = ctor.contextType;
  6872. var nextContext = emptyContextObject;
  6873. if (typeof contextType === "object" && contextType !== null) {
  6874. nextContext = readContext(contextType);
  6875. } else {
  6876. var nextLegacyUnmaskedContext = getUnmaskedContext(
  6877. workInProgress,
  6878. ctor,
  6879. true
  6880. );
  6881. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  6882. }
  6883. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6884. var hasNewLifecycles =
  6885. typeof getDerivedStateFromProps === "function" ||
  6886. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  6887. // ever the previously attempted to render - not the "current". However,
  6888. // during componentDidUpdate we pass the "current" props.
  6889. // In order to support react-lifecycles-compat polyfilled components,
  6890. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6891. if (
  6892. !hasNewLifecycles &&
  6893. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  6894. typeof instance.componentWillReceiveProps === "function")
  6895. ) {
  6896. if (oldProps !== newProps || oldContext !== nextContext) {
  6897. callComponentWillReceiveProps(
  6898. workInProgress,
  6899. instance,
  6900. newProps,
  6901. nextContext
  6902. );
  6903. }
  6904. }
  6905. resetHasForceUpdateBeforeProcessing();
  6906. var oldState = workInProgress.memoizedState;
  6907. var newState = (instance.state = oldState);
  6908. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6909. newState = workInProgress.memoizedState;
  6910. if (
  6911. oldProps === newProps &&
  6912. oldState === newState &&
  6913. !hasContextChanged() &&
  6914. !checkHasForceUpdateAfterProcessing()
  6915. ) {
  6916. // If an update was already in progress, we should schedule an Update
  6917. // effect even though we're bailing out, so that cWU/cDU are called.
  6918. if (typeof instance.componentDidMount === "function") {
  6919. workInProgress.effectTag |= Update;
  6920. }
  6921. return false;
  6922. }
  6923. if (typeof getDerivedStateFromProps === "function") {
  6924. applyDerivedStateFromProps(
  6925. workInProgress,
  6926. ctor,
  6927. getDerivedStateFromProps,
  6928. newProps
  6929. );
  6930. newState = workInProgress.memoizedState;
  6931. }
  6932. var shouldUpdate =
  6933. checkHasForceUpdateAfterProcessing() ||
  6934. checkShouldComponentUpdate(
  6935. workInProgress,
  6936. ctor,
  6937. oldProps,
  6938. newProps,
  6939. oldState,
  6940. newState,
  6941. nextContext
  6942. );
  6943. if (shouldUpdate) {
  6944. // In order to support react-lifecycles-compat polyfilled components,
  6945. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6946. if (
  6947. !hasNewLifecycles &&
  6948. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6949. typeof instance.componentWillMount === "function")
  6950. ) {
  6951. startPhaseTimer(workInProgress, "componentWillMount");
  6952. if (typeof instance.componentWillMount === "function") {
  6953. instance.componentWillMount();
  6954. }
  6955. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6956. instance.UNSAFE_componentWillMount();
  6957. }
  6958. stopPhaseTimer();
  6959. }
  6960. if (typeof instance.componentDidMount === "function") {
  6961. workInProgress.effectTag |= Update;
  6962. }
  6963. } else {
  6964. // If an update was already in progress, we should schedule an Update
  6965. // effect even though we're bailing out, so that cWU/cDU are called.
  6966. if (typeof instance.componentDidMount === "function") {
  6967. workInProgress.effectTag |= Update;
  6968. } // If shouldComponentUpdate returned false, we should still update the
  6969. // memoized state to indicate that this work can be reused.
  6970. workInProgress.memoizedProps = newProps;
  6971. workInProgress.memoizedState = newState;
  6972. } // Update the existing instance's state, props, and context pointers even
  6973. // if shouldComponentUpdate returns false.
  6974. instance.props = newProps;
  6975. instance.state = newState;
  6976. instance.context = nextContext;
  6977. return shouldUpdate;
  6978. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  6979. function updateClassInstance(
  6980. current,
  6981. workInProgress,
  6982. ctor,
  6983. newProps,
  6984. renderExpirationTime
  6985. ) {
  6986. var instance = workInProgress.stateNode;
  6987. cloneUpdateQueue(current, workInProgress);
  6988. var oldProps = workInProgress.memoizedProps;
  6989. instance.props =
  6990. workInProgress.type === workInProgress.elementType
  6991. ? oldProps
  6992. : resolveDefaultProps(workInProgress.type, oldProps);
  6993. var oldContext = instance.context;
  6994. var contextType = ctor.contextType;
  6995. var nextContext = emptyContextObject;
  6996. if (typeof contextType === "object" && contextType !== null) {
  6997. nextContext = readContext(contextType);
  6998. } else {
  6999. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  7000. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  7001. }
  7002. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  7003. var hasNewLifecycles =
  7004. typeof getDerivedStateFromProps === "function" ||
  7005. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  7006. // ever the previously attempted to render - not the "current". However,
  7007. // during componentDidUpdate we pass the "current" props.
  7008. // In order to support react-lifecycles-compat polyfilled components,
  7009. // Unsafe lifecycles should not be invoked for components using the new APIs.
  7010. if (
  7011. !hasNewLifecycles &&
  7012. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  7013. typeof instance.componentWillReceiveProps === "function")
  7014. ) {
  7015. if (oldProps !== newProps || oldContext !== nextContext) {
  7016. callComponentWillReceiveProps(
  7017. workInProgress,
  7018. instance,
  7019. newProps,
  7020. nextContext
  7021. );
  7022. }
  7023. }
  7024. resetHasForceUpdateBeforeProcessing();
  7025. var oldState = workInProgress.memoizedState;
  7026. var newState = (instance.state = oldState);
  7027. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  7028. newState = workInProgress.memoizedState;
  7029. if (
  7030. oldProps === newProps &&
  7031. oldState === newState &&
  7032. !hasContextChanged() &&
  7033. !checkHasForceUpdateAfterProcessing()
  7034. ) {
  7035. // If an update was already in progress, we should schedule an Update
  7036. // effect even though we're bailing out, so that cWU/cDU are called.
  7037. if (typeof instance.componentDidUpdate === "function") {
  7038. if (
  7039. oldProps !== current.memoizedProps ||
  7040. oldState !== current.memoizedState
  7041. ) {
  7042. workInProgress.effectTag |= Update;
  7043. }
  7044. }
  7045. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  7046. if (
  7047. oldProps !== current.memoizedProps ||
  7048. oldState !== current.memoizedState
  7049. ) {
  7050. workInProgress.effectTag |= Snapshot;
  7051. }
  7052. }
  7053. return false;
  7054. }
  7055. if (typeof getDerivedStateFromProps === "function") {
  7056. applyDerivedStateFromProps(
  7057. workInProgress,
  7058. ctor,
  7059. getDerivedStateFromProps,
  7060. newProps
  7061. );
  7062. newState = workInProgress.memoizedState;
  7063. }
  7064. var shouldUpdate =
  7065. checkHasForceUpdateAfterProcessing() ||
  7066. checkShouldComponentUpdate(
  7067. workInProgress,
  7068. ctor,
  7069. oldProps,
  7070. newProps,
  7071. oldState,
  7072. newState,
  7073. nextContext
  7074. );
  7075. if (shouldUpdate) {
  7076. // In order to support react-lifecycles-compat polyfilled components,
  7077. // Unsafe lifecycles should not be invoked for components using the new APIs.
  7078. if (
  7079. !hasNewLifecycles &&
  7080. (typeof instance.UNSAFE_componentWillUpdate === "function" ||
  7081. typeof instance.componentWillUpdate === "function")
  7082. ) {
  7083. startPhaseTimer(workInProgress, "componentWillUpdate");
  7084. if (typeof instance.componentWillUpdate === "function") {
  7085. instance.componentWillUpdate(newProps, newState, nextContext);
  7086. }
  7087. if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  7088. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  7089. }
  7090. stopPhaseTimer();
  7091. }
  7092. if (typeof instance.componentDidUpdate === "function") {
  7093. workInProgress.effectTag |= Update;
  7094. }
  7095. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  7096. workInProgress.effectTag |= Snapshot;
  7097. }
  7098. } else {
  7099. // If an update was already in progress, we should schedule an Update
  7100. // effect even though we're bailing out, so that cWU/cDU are called.
  7101. if (typeof instance.componentDidUpdate === "function") {
  7102. if (
  7103. oldProps !== current.memoizedProps ||
  7104. oldState !== current.memoizedState
  7105. ) {
  7106. workInProgress.effectTag |= Update;
  7107. }
  7108. }
  7109. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  7110. if (
  7111. oldProps !== current.memoizedProps ||
  7112. oldState !== current.memoizedState
  7113. ) {
  7114. workInProgress.effectTag |= Snapshot;
  7115. }
  7116. } // If shouldComponentUpdate returned false, we should still update the
  7117. // memoized props/state to indicate that this work can be reused.
  7118. workInProgress.memoizedProps = newProps;
  7119. workInProgress.memoizedState = newState;
  7120. } // Update the existing instance's state, props, and context pointers even
  7121. // if shouldComponentUpdate returns false.
  7122. instance.props = newProps;
  7123. instance.state = newState;
  7124. instance.context = nextContext;
  7125. return shouldUpdate;
  7126. }
  7127. var didWarnAboutMaps;
  7128. var didWarnAboutGenerators;
  7129. var didWarnAboutStringRefs;
  7130. var ownerHasKeyUseWarning;
  7131. var ownerHasFunctionTypeWarning;
  7132. var warnForMissingKey = function(child) {};
  7133. {
  7134. didWarnAboutMaps = false;
  7135. didWarnAboutGenerators = false;
  7136. didWarnAboutStringRefs = {};
  7137. /**
  7138. * Warn if there's no key explicitly set on dynamic arrays of children or
  7139. * object keys are not valid. This allows us to keep track of children between
  7140. * updates.
  7141. */
  7142. ownerHasKeyUseWarning = {};
  7143. ownerHasFunctionTypeWarning = {};
  7144. warnForMissingKey = function(child) {
  7145. if (child === null || typeof child !== "object") {
  7146. return;
  7147. }
  7148. if (!child._store || child._store.validated || child.key != null) {
  7149. return;
  7150. }
  7151. if (!(typeof child._store === "object")) {
  7152. throw Error(
  7153. "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue."
  7154. );
  7155. }
  7156. child._store.validated = true;
  7157. var currentComponentErrorInfo =
  7158. "Each child in a list should have a unique " +
  7159. '"key" prop. See https://fb.me/react-warning-keys for ' +
  7160. "more information." +
  7161. getCurrentFiberStackInDev();
  7162. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  7163. return;
  7164. }
  7165. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  7166. error(
  7167. "Each child in a list should have a unique " +
  7168. '"key" prop. See https://fb.me/react-warning-keys for ' +
  7169. "more information."
  7170. );
  7171. };
  7172. }
  7173. var isArray$1 = Array.isArray;
  7174. function coerceRef(returnFiber, current, element) {
  7175. var mixedRef = element.ref;
  7176. if (
  7177. mixedRef !== null &&
  7178. typeof mixedRef !== "function" &&
  7179. typeof mixedRef !== "object"
  7180. ) {
  7181. {
  7182. // TODO: Clean this up once we turn on the string ref warning for
  7183. // everyone, because the strict mode case will no longer be relevant
  7184. if (
  7185. (returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  7186. // because these cannot be automatically converted to an arrow function
  7187. // using a codemod. Therefore, we don't have to warn about string refs again.
  7188. !(
  7189. element._owner &&
  7190. element._self &&
  7191. element._owner.stateNode !== element._self
  7192. )
  7193. ) {
  7194. var componentName = getComponentName(returnFiber.type) || "Component";
  7195. if (!didWarnAboutStringRefs[componentName]) {
  7196. {
  7197. error(
  7198. 'A string ref, "%s", has been found within a strict mode tree. ' +
  7199. "String refs are a source of potential bugs and should be avoided. " +
  7200. "We recommend using useRef() or createRef() instead. " +
  7201. "Learn more about using refs safely here: " +
  7202. "https://fb.me/react-strict-mode-string-ref%s",
  7203. mixedRef,
  7204. getStackByFiberInDevAndProd(returnFiber)
  7205. );
  7206. }
  7207. didWarnAboutStringRefs[componentName] = true;
  7208. }
  7209. }
  7210. }
  7211. if (element._owner) {
  7212. var owner = element._owner;
  7213. var inst;
  7214. if (owner) {
  7215. var ownerFiber = owner;
  7216. if (!(ownerFiber.tag === ClassComponent)) {
  7217. throw Error(
  7218. "Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref"
  7219. );
  7220. }
  7221. inst = ownerFiber.stateNode;
  7222. }
  7223. if (!inst) {
  7224. throw Error(
  7225. "Missing owner for string ref " +
  7226. mixedRef +
  7227. ". This error is likely caused by a bug in React. Please file an issue."
  7228. );
  7229. }
  7230. var stringRef = "" + mixedRef; // Check if previous string ref matches new string ref
  7231. if (
  7232. current !== null &&
  7233. current.ref !== null &&
  7234. typeof current.ref === "function" &&
  7235. current.ref._stringRef === stringRef
  7236. ) {
  7237. return current.ref;
  7238. }
  7239. var ref = function(value) {
  7240. var refs = inst.refs;
  7241. if (refs === emptyRefsObject) {
  7242. // This is a lazy pooled frozen object, so we need to initialize.
  7243. refs = inst.refs = {};
  7244. }
  7245. if (value === null) {
  7246. delete refs[stringRef];
  7247. } else {
  7248. refs[stringRef] = value;
  7249. }
  7250. };
  7251. ref._stringRef = stringRef;
  7252. return ref;
  7253. } else {
  7254. if (!(typeof mixedRef === "string")) {
  7255. throw Error(
  7256. "Expected ref to be a function, a string, an object returned by React.createRef(), or null."
  7257. );
  7258. }
  7259. if (!element._owner) {
  7260. throw Error(
  7261. "Element ref was specified as a string (" +
  7262. mixedRef +
  7263. ") but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a function component\n2. You may be adding a ref to a component that was not created inside a component's render method\n3. You have multiple copies of React loaded\nSee https://fb.me/react-refs-must-have-owner for more information."
  7264. );
  7265. }
  7266. }
  7267. }
  7268. return mixedRef;
  7269. }
  7270. function throwOnInvalidObjectType(returnFiber, newChild) {
  7271. if (returnFiber.type !== "textarea") {
  7272. var addendum = "";
  7273. {
  7274. addendum =
  7275. " If you meant to render a collection of children, use an array " +
  7276. "instead." +
  7277. getCurrentFiberStackInDev();
  7278. }
  7279. {
  7280. throw Error(
  7281. "Objects are not valid as a React child (found: " +
  7282. (Object.prototype.toString.call(newChild) === "[object Object]"
  7283. ? "object with keys {" + Object.keys(newChild).join(", ") + "}"
  7284. : newChild) +
  7285. ")." +
  7286. addendum
  7287. );
  7288. }
  7289. }
  7290. }
  7291. function warnOnFunctionType() {
  7292. {
  7293. var currentComponentErrorInfo =
  7294. "Functions are not valid as a React child. This may happen if " +
  7295. "you return a Component instead of <Component /> from render. " +
  7296. "Or maybe you meant to call this function rather than return it." +
  7297. getCurrentFiberStackInDev();
  7298. if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
  7299. return;
  7300. }
  7301. ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
  7302. error(
  7303. "Functions are not valid as a React child. This may happen if " +
  7304. "you return a Component instead of <Component /> from render. " +
  7305. "Or maybe you meant to call this function rather than return it."
  7306. );
  7307. }
  7308. } // This wrapper function exists because I expect to clone the code in each path
  7309. // to be able to optimize each path individually by branching early. This needs
  7310. // a compiler or we can do it manually. Helpers that don't need this branching
  7311. // live outside of this function.
  7312. function ChildReconciler(shouldTrackSideEffects) {
  7313. function deleteChild(returnFiber, childToDelete) {
  7314. if (!shouldTrackSideEffects) {
  7315. // Noop.
  7316. return;
  7317. } // Deletions are added in reversed order so we add it to the front.
  7318. // At this point, the return fiber's effect list is empty except for
  7319. // deletions, so we can just append the deletion to the list. The remaining
  7320. // effects aren't added until the complete phase. Once we implement
  7321. // resuming, this may not be true.
  7322. var last = returnFiber.lastEffect;
  7323. if (last !== null) {
  7324. last.nextEffect = childToDelete;
  7325. returnFiber.lastEffect = childToDelete;
  7326. } else {
  7327. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  7328. }
  7329. childToDelete.nextEffect = null;
  7330. childToDelete.effectTag = Deletion;
  7331. }
  7332. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  7333. if (!shouldTrackSideEffects) {
  7334. // Noop.
  7335. return null;
  7336. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  7337. // assuming that after the first child we've already added everything.
  7338. var childToDelete = currentFirstChild;
  7339. while (childToDelete !== null) {
  7340. deleteChild(returnFiber, childToDelete);
  7341. childToDelete = childToDelete.sibling;
  7342. }
  7343. return null;
  7344. }
  7345. function mapRemainingChildren(returnFiber, currentFirstChild) {
  7346. // Add the remaining children to a temporary map so that we can find them by
  7347. // keys quickly. Implicit (null) keys get added to this set with their index
  7348. // instead.
  7349. var existingChildren = new Map();
  7350. var existingChild = currentFirstChild;
  7351. while (existingChild !== null) {
  7352. if (existingChild.key !== null) {
  7353. existingChildren.set(existingChild.key, existingChild);
  7354. } else {
  7355. existingChildren.set(existingChild.index, existingChild);
  7356. }
  7357. existingChild = existingChild.sibling;
  7358. }
  7359. return existingChildren;
  7360. }
  7361. function useFiber(fiber, pendingProps) {
  7362. // We currently set sibling to null and index to 0 here because it is easy
  7363. // to forget to do before returning it. E.g. for the single child case.
  7364. var clone = createWorkInProgress(fiber, pendingProps);
  7365. clone.index = 0;
  7366. clone.sibling = null;
  7367. return clone;
  7368. }
  7369. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  7370. newFiber.index = newIndex;
  7371. if (!shouldTrackSideEffects) {
  7372. // Noop.
  7373. return lastPlacedIndex;
  7374. }
  7375. var current = newFiber.alternate;
  7376. if (current !== null) {
  7377. var oldIndex = current.index;
  7378. if (oldIndex < lastPlacedIndex) {
  7379. // This is a move.
  7380. newFiber.effectTag = Placement;
  7381. return lastPlacedIndex;
  7382. } else {
  7383. // This item can stay in place.
  7384. return oldIndex;
  7385. }
  7386. } else {
  7387. // This is an insertion.
  7388. newFiber.effectTag = Placement;
  7389. return lastPlacedIndex;
  7390. }
  7391. }
  7392. function placeSingleChild(newFiber) {
  7393. // This is simpler for the single child case. We only need to do a
  7394. // placement for inserting new children.
  7395. if (shouldTrackSideEffects && newFiber.alternate === null) {
  7396. newFiber.effectTag = Placement;
  7397. }
  7398. return newFiber;
  7399. }
  7400. function updateTextNode(returnFiber, current, textContent, expirationTime) {
  7401. if (current === null || current.tag !== HostText) {
  7402. // Insert
  7403. var created = createFiberFromText(
  7404. textContent,
  7405. returnFiber.mode,
  7406. expirationTime
  7407. );
  7408. created.return = returnFiber;
  7409. return created;
  7410. } else {
  7411. // Update
  7412. var existing = useFiber(current, textContent);
  7413. existing.return = returnFiber;
  7414. return existing;
  7415. }
  7416. }
  7417. function updateElement(returnFiber, current, element, expirationTime) {
  7418. if (current !== null) {
  7419. if (
  7420. current.elementType === element.type || // Keep this check inline so it only runs on the false path:
  7421. isCompatibleFamilyForHotReloading(current, element)
  7422. ) {
  7423. // Move based on index
  7424. var existing = useFiber(current, element.props);
  7425. existing.ref = coerceRef(returnFiber, current, element);
  7426. existing.return = returnFiber;
  7427. {
  7428. existing._debugSource = element._source;
  7429. existing._debugOwner = element._owner;
  7430. }
  7431. return existing;
  7432. }
  7433. } // Insert
  7434. var created = createFiberFromElement(
  7435. element,
  7436. returnFiber.mode,
  7437. expirationTime
  7438. );
  7439. created.ref = coerceRef(returnFiber, current, element);
  7440. created.return = returnFiber;
  7441. return created;
  7442. }
  7443. function updatePortal(returnFiber, current, portal, expirationTime) {
  7444. if (
  7445. current === null ||
  7446. current.tag !== HostPortal ||
  7447. current.stateNode.containerInfo !== portal.containerInfo ||
  7448. current.stateNode.implementation !== portal.implementation
  7449. ) {
  7450. // Insert
  7451. var created = createFiberFromPortal(
  7452. portal,
  7453. returnFiber.mode,
  7454. expirationTime
  7455. );
  7456. created.return = returnFiber;
  7457. return created;
  7458. } else {
  7459. // Update
  7460. var existing = useFiber(current, portal.children || []);
  7461. existing.return = returnFiber;
  7462. return existing;
  7463. }
  7464. }
  7465. function updateFragment(returnFiber, current, fragment, expirationTime, key) {
  7466. if (current === null || current.tag !== Fragment) {
  7467. // Insert
  7468. var created = createFiberFromFragment(
  7469. fragment,
  7470. returnFiber.mode,
  7471. expirationTime,
  7472. key
  7473. );
  7474. created.return = returnFiber;
  7475. return created;
  7476. } else {
  7477. // Update
  7478. var existing = useFiber(current, fragment);
  7479. existing.return = returnFiber;
  7480. return existing;
  7481. }
  7482. }
  7483. function createChild(returnFiber, newChild, expirationTime) {
  7484. if (typeof newChild === "string" || typeof newChild === "number") {
  7485. // Text nodes don't have keys. If the previous node is implicitly keyed
  7486. // we can continue to replace it without aborting even if it is not a text
  7487. // node.
  7488. var created = createFiberFromText(
  7489. "" + newChild,
  7490. returnFiber.mode,
  7491. expirationTime
  7492. );
  7493. created.return = returnFiber;
  7494. return created;
  7495. }
  7496. if (typeof newChild === "object" && newChild !== null) {
  7497. switch (newChild.$$typeof) {
  7498. case REACT_ELEMENT_TYPE: {
  7499. var _created = createFiberFromElement(
  7500. newChild,
  7501. returnFiber.mode,
  7502. expirationTime
  7503. );
  7504. _created.ref = coerceRef(returnFiber, null, newChild);
  7505. _created.return = returnFiber;
  7506. return _created;
  7507. }
  7508. case REACT_PORTAL_TYPE: {
  7509. var _created2 = createFiberFromPortal(
  7510. newChild,
  7511. returnFiber.mode,
  7512. expirationTime
  7513. );
  7514. _created2.return = returnFiber;
  7515. return _created2;
  7516. }
  7517. }
  7518. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7519. var _created3 = createFiberFromFragment(
  7520. newChild,
  7521. returnFiber.mode,
  7522. expirationTime,
  7523. null
  7524. );
  7525. _created3.return = returnFiber;
  7526. return _created3;
  7527. }
  7528. throwOnInvalidObjectType(returnFiber, newChild);
  7529. }
  7530. {
  7531. if (typeof newChild === "function") {
  7532. warnOnFunctionType();
  7533. }
  7534. }
  7535. return null;
  7536. }
  7537. function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
  7538. // Update the fiber if the keys match, otherwise return null.
  7539. var key = oldFiber !== null ? oldFiber.key : null;
  7540. if (typeof newChild === "string" || typeof newChild === "number") {
  7541. // Text nodes don't have keys. If the previous node is implicitly keyed
  7542. // we can continue to replace it without aborting even if it is not a text
  7543. // node.
  7544. if (key !== null) {
  7545. return null;
  7546. }
  7547. return updateTextNode(
  7548. returnFiber,
  7549. oldFiber,
  7550. "" + newChild,
  7551. expirationTime
  7552. );
  7553. }
  7554. if (typeof newChild === "object" && newChild !== null) {
  7555. switch (newChild.$$typeof) {
  7556. case REACT_ELEMENT_TYPE: {
  7557. if (newChild.key === key) {
  7558. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7559. return updateFragment(
  7560. returnFiber,
  7561. oldFiber,
  7562. newChild.props.children,
  7563. expirationTime,
  7564. key
  7565. );
  7566. }
  7567. return updateElement(
  7568. returnFiber,
  7569. oldFiber,
  7570. newChild,
  7571. expirationTime
  7572. );
  7573. } else {
  7574. return null;
  7575. }
  7576. }
  7577. case REACT_PORTAL_TYPE: {
  7578. if (newChild.key === key) {
  7579. return updatePortal(
  7580. returnFiber,
  7581. oldFiber,
  7582. newChild,
  7583. expirationTime
  7584. );
  7585. } else {
  7586. return null;
  7587. }
  7588. }
  7589. }
  7590. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7591. if (key !== null) {
  7592. return null;
  7593. }
  7594. return updateFragment(
  7595. returnFiber,
  7596. oldFiber,
  7597. newChild,
  7598. expirationTime,
  7599. null
  7600. );
  7601. }
  7602. throwOnInvalidObjectType(returnFiber, newChild);
  7603. }
  7604. {
  7605. if (typeof newChild === "function") {
  7606. warnOnFunctionType();
  7607. }
  7608. }
  7609. return null;
  7610. }
  7611. function updateFromMap(
  7612. existingChildren,
  7613. returnFiber,
  7614. newIdx,
  7615. newChild,
  7616. expirationTime
  7617. ) {
  7618. if (typeof newChild === "string" || typeof newChild === "number") {
  7619. // Text nodes don't have keys, so we neither have to check the old nor
  7620. // new node for the key. If both are text nodes, they match.
  7621. var matchedFiber = existingChildren.get(newIdx) || null;
  7622. return updateTextNode(
  7623. returnFiber,
  7624. matchedFiber,
  7625. "" + newChild,
  7626. expirationTime
  7627. );
  7628. }
  7629. if (typeof newChild === "object" && newChild !== null) {
  7630. switch (newChild.$$typeof) {
  7631. case REACT_ELEMENT_TYPE: {
  7632. var _matchedFiber =
  7633. existingChildren.get(
  7634. newChild.key === null ? newIdx : newChild.key
  7635. ) || null;
  7636. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7637. return updateFragment(
  7638. returnFiber,
  7639. _matchedFiber,
  7640. newChild.props.children,
  7641. expirationTime,
  7642. newChild.key
  7643. );
  7644. }
  7645. return updateElement(
  7646. returnFiber,
  7647. _matchedFiber,
  7648. newChild,
  7649. expirationTime
  7650. );
  7651. }
  7652. case REACT_PORTAL_TYPE: {
  7653. var _matchedFiber2 =
  7654. existingChildren.get(
  7655. newChild.key === null ? newIdx : newChild.key
  7656. ) || null;
  7657. return updatePortal(
  7658. returnFiber,
  7659. _matchedFiber2,
  7660. newChild,
  7661. expirationTime
  7662. );
  7663. }
  7664. }
  7665. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7666. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  7667. return updateFragment(
  7668. returnFiber,
  7669. _matchedFiber3,
  7670. newChild,
  7671. expirationTime,
  7672. null
  7673. );
  7674. }
  7675. throwOnInvalidObjectType(returnFiber, newChild);
  7676. }
  7677. {
  7678. if (typeof newChild === "function") {
  7679. warnOnFunctionType();
  7680. }
  7681. }
  7682. return null;
  7683. }
  7684. /**
  7685. * Warns if there is a duplicate or missing key
  7686. */
  7687. function warnOnInvalidKey(child, knownKeys) {
  7688. {
  7689. if (typeof child !== "object" || child === null) {
  7690. return knownKeys;
  7691. }
  7692. switch (child.$$typeof) {
  7693. case REACT_ELEMENT_TYPE:
  7694. case REACT_PORTAL_TYPE:
  7695. warnForMissingKey(child);
  7696. var key = child.key;
  7697. if (typeof key !== "string") {
  7698. break;
  7699. }
  7700. if (knownKeys === null) {
  7701. knownKeys = new Set();
  7702. knownKeys.add(key);
  7703. break;
  7704. }
  7705. if (!knownKeys.has(key)) {
  7706. knownKeys.add(key);
  7707. break;
  7708. }
  7709. error(
  7710. "Encountered two children with the same key, `%s`. " +
  7711. "Keys should be unique so that components maintain their identity " +
  7712. "across updates. Non-unique keys may cause children to be " +
  7713. "duplicated and/or omitted — the behavior is unsupported and " +
  7714. "could change in a future version.",
  7715. key
  7716. );
  7717. break;
  7718. }
  7719. }
  7720. return knownKeys;
  7721. }
  7722. function reconcileChildrenArray(
  7723. returnFiber,
  7724. currentFirstChild,
  7725. newChildren,
  7726. expirationTime
  7727. ) {
  7728. // This algorithm can't optimize by searching from both ends since we
  7729. // don't have backpointers on fibers. I'm trying to see how far we can get
  7730. // with that model. If it ends up not being worth the tradeoffs, we can
  7731. // add it later.
  7732. // Even with a two ended optimization, we'd want to optimize for the case
  7733. // where there are few changes and brute force the comparison instead of
  7734. // going for the Map. It'd like to explore hitting that path first in
  7735. // forward-only mode and only go for the Map once we notice that we need
  7736. // lots of look ahead. This doesn't handle reversal as well as two ended
  7737. // search but that's unusual. Besides, for the two ended optimization to
  7738. // work on Iterables, we'd need to copy the whole set.
  7739. // In this first iteration, we'll just live with hitting the bad case
  7740. // (adding everything to a Map) in for every insert/move.
  7741. // If you change this code, also update reconcileChildrenIterator() which
  7742. // uses the same algorithm.
  7743. {
  7744. // First, validate keys.
  7745. var knownKeys = null;
  7746. for (var i = 0; i < newChildren.length; i++) {
  7747. var child = newChildren[i];
  7748. knownKeys = warnOnInvalidKey(child, knownKeys);
  7749. }
  7750. }
  7751. var resultingFirstChild = null;
  7752. var previousNewFiber = null;
  7753. var oldFiber = currentFirstChild;
  7754. var lastPlacedIndex = 0;
  7755. var newIdx = 0;
  7756. var nextOldFiber = null;
  7757. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  7758. if (oldFiber.index > newIdx) {
  7759. nextOldFiber = oldFiber;
  7760. oldFiber = null;
  7761. } else {
  7762. nextOldFiber = oldFiber.sibling;
  7763. }
  7764. var newFiber = updateSlot(
  7765. returnFiber,
  7766. oldFiber,
  7767. newChildren[newIdx],
  7768. expirationTime
  7769. );
  7770. if (newFiber === null) {
  7771. // TODO: This breaks on empty slots like null children. That's
  7772. // unfortunate because it triggers the slow path all the time. We need
  7773. // a better way to communicate whether this was a miss or null,
  7774. // boolean, undefined, etc.
  7775. if (oldFiber === null) {
  7776. oldFiber = nextOldFiber;
  7777. }
  7778. break;
  7779. }
  7780. if (shouldTrackSideEffects) {
  7781. if (oldFiber && newFiber.alternate === null) {
  7782. // We matched the slot, but we didn't reuse the existing fiber, so we
  7783. // need to delete the existing child.
  7784. deleteChild(returnFiber, oldFiber);
  7785. }
  7786. }
  7787. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7788. if (previousNewFiber === null) {
  7789. // TODO: Move out of the loop. This only happens for the first run.
  7790. resultingFirstChild = newFiber;
  7791. } else {
  7792. // TODO: Defer siblings if we're not at the right index for this slot.
  7793. // I.e. if we had null values before, then we want to defer this
  7794. // for each null value. However, we also don't want to call updateSlot
  7795. // with the previous one.
  7796. previousNewFiber.sibling = newFiber;
  7797. }
  7798. previousNewFiber = newFiber;
  7799. oldFiber = nextOldFiber;
  7800. }
  7801. if (newIdx === newChildren.length) {
  7802. // We've reached the end of the new children. We can delete the rest.
  7803. deleteRemainingChildren(returnFiber, oldFiber);
  7804. return resultingFirstChild;
  7805. }
  7806. if (oldFiber === null) {
  7807. // If we don't have any more existing children we can choose a fast path
  7808. // since the rest will all be insertions.
  7809. for (; newIdx < newChildren.length; newIdx++) {
  7810. var _newFiber = createChild(
  7811. returnFiber,
  7812. newChildren[newIdx],
  7813. expirationTime
  7814. );
  7815. if (_newFiber === null) {
  7816. continue;
  7817. }
  7818. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  7819. if (previousNewFiber === null) {
  7820. // TODO: Move out of the loop. This only happens for the first run.
  7821. resultingFirstChild = _newFiber;
  7822. } else {
  7823. previousNewFiber.sibling = _newFiber;
  7824. }
  7825. previousNewFiber = _newFiber;
  7826. }
  7827. return resultingFirstChild;
  7828. } // Add all children to a key map for quick lookups.
  7829. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  7830. for (; newIdx < newChildren.length; newIdx++) {
  7831. var _newFiber2 = updateFromMap(
  7832. existingChildren,
  7833. returnFiber,
  7834. newIdx,
  7835. newChildren[newIdx],
  7836. expirationTime
  7837. );
  7838. if (_newFiber2 !== null) {
  7839. if (shouldTrackSideEffects) {
  7840. if (_newFiber2.alternate !== null) {
  7841. // The new fiber is a work in progress, but if there exists a
  7842. // current, that means that we reused the fiber. We need to delete
  7843. // it from the child list so that we don't add it to the deletion
  7844. // list.
  7845. existingChildren.delete(
  7846. _newFiber2.key === null ? newIdx : _newFiber2.key
  7847. );
  7848. }
  7849. }
  7850. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  7851. if (previousNewFiber === null) {
  7852. resultingFirstChild = _newFiber2;
  7853. } else {
  7854. previousNewFiber.sibling = _newFiber2;
  7855. }
  7856. previousNewFiber = _newFiber2;
  7857. }
  7858. }
  7859. if (shouldTrackSideEffects) {
  7860. // Any existing children that weren't consumed above were deleted. We need
  7861. // to add them to the deletion list.
  7862. existingChildren.forEach(function(child) {
  7863. return deleteChild(returnFiber, child);
  7864. });
  7865. }
  7866. return resultingFirstChild;
  7867. }
  7868. function reconcileChildrenIterator(
  7869. returnFiber,
  7870. currentFirstChild,
  7871. newChildrenIterable,
  7872. expirationTime
  7873. ) {
  7874. // This is the same implementation as reconcileChildrenArray(),
  7875. // but using the iterator instead.
  7876. var iteratorFn = getIteratorFn(newChildrenIterable);
  7877. if (!(typeof iteratorFn === "function")) {
  7878. throw Error(
  7879. "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue."
  7880. );
  7881. }
  7882. {
  7883. // We don't support rendering Generators because it's a mutation.
  7884. // See https://github.com/facebook/react/issues/12995
  7885. if (
  7886. typeof Symbol === "function" && // $FlowFixMe Flow doesn't know about toStringTag
  7887. newChildrenIterable[Symbol.toStringTag] === "Generator"
  7888. ) {
  7889. if (!didWarnAboutGenerators) {
  7890. error(
  7891. "Using Generators as children is unsupported and will likely yield " +
  7892. "unexpected results because enumerating a generator mutates it. " +
  7893. "You may convert it to an array with `Array.from()` or the " +
  7894. "`[...spread]` operator before rendering. Keep in mind " +
  7895. "you might need to polyfill these features for older browsers."
  7896. );
  7897. }
  7898. didWarnAboutGenerators = true;
  7899. } // Warn about using Maps as children
  7900. if (newChildrenIterable.entries === iteratorFn) {
  7901. if (!didWarnAboutMaps) {
  7902. error(
  7903. "Using Maps as children is unsupported and will likely yield " +
  7904. "unexpected results. Convert it to a sequence/iterable of keyed " +
  7905. "ReactElements instead."
  7906. );
  7907. }
  7908. didWarnAboutMaps = true;
  7909. } // First, validate keys.
  7910. // We'll get a different iterator later for the main pass.
  7911. var _newChildren = iteratorFn.call(newChildrenIterable);
  7912. if (_newChildren) {
  7913. var knownKeys = null;
  7914. var _step = _newChildren.next();
  7915. for (; !_step.done; _step = _newChildren.next()) {
  7916. var child = _step.value;
  7917. knownKeys = warnOnInvalidKey(child, knownKeys);
  7918. }
  7919. }
  7920. }
  7921. var newChildren = iteratorFn.call(newChildrenIterable);
  7922. if (!(newChildren != null)) {
  7923. throw Error("An iterable object provided no iterator.");
  7924. }
  7925. var resultingFirstChild = null;
  7926. var previousNewFiber = null;
  7927. var oldFiber = currentFirstChild;
  7928. var lastPlacedIndex = 0;
  7929. var newIdx = 0;
  7930. var nextOldFiber = null;
  7931. var step = newChildren.next();
  7932. for (
  7933. ;
  7934. oldFiber !== null && !step.done;
  7935. newIdx++, step = newChildren.next()
  7936. ) {
  7937. if (oldFiber.index > newIdx) {
  7938. nextOldFiber = oldFiber;
  7939. oldFiber = null;
  7940. } else {
  7941. nextOldFiber = oldFiber.sibling;
  7942. }
  7943. var newFiber = updateSlot(
  7944. returnFiber,
  7945. oldFiber,
  7946. step.value,
  7947. expirationTime
  7948. );
  7949. if (newFiber === null) {
  7950. // TODO: This breaks on empty slots like null children. That's
  7951. // unfortunate because it triggers the slow path all the time. We need
  7952. // a better way to communicate whether this was a miss or null,
  7953. // boolean, undefined, etc.
  7954. if (oldFiber === null) {
  7955. oldFiber = nextOldFiber;
  7956. }
  7957. break;
  7958. }
  7959. if (shouldTrackSideEffects) {
  7960. if (oldFiber && newFiber.alternate === null) {
  7961. // We matched the slot, but we didn't reuse the existing fiber, so we
  7962. // need to delete the existing child.
  7963. deleteChild(returnFiber, oldFiber);
  7964. }
  7965. }
  7966. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7967. if (previousNewFiber === null) {
  7968. // TODO: Move out of the loop. This only happens for the first run.
  7969. resultingFirstChild = newFiber;
  7970. } else {
  7971. // TODO: Defer siblings if we're not at the right index for this slot.
  7972. // I.e. if we had null values before, then we want to defer this
  7973. // for each null value. However, we also don't want to call updateSlot
  7974. // with the previous one.
  7975. previousNewFiber.sibling = newFiber;
  7976. }
  7977. previousNewFiber = newFiber;
  7978. oldFiber = nextOldFiber;
  7979. }
  7980. if (step.done) {
  7981. // We've reached the end of the new children. We can delete the rest.
  7982. deleteRemainingChildren(returnFiber, oldFiber);
  7983. return resultingFirstChild;
  7984. }
  7985. if (oldFiber === null) {
  7986. // If we don't have any more existing children we can choose a fast path
  7987. // since the rest will all be insertions.
  7988. for (; !step.done; newIdx++, step = newChildren.next()) {
  7989. var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
  7990. if (_newFiber3 === null) {
  7991. continue;
  7992. }
  7993. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  7994. if (previousNewFiber === null) {
  7995. // TODO: Move out of the loop. This only happens for the first run.
  7996. resultingFirstChild = _newFiber3;
  7997. } else {
  7998. previousNewFiber.sibling = _newFiber3;
  7999. }
  8000. previousNewFiber = _newFiber3;
  8001. }
  8002. return resultingFirstChild;
  8003. } // Add all children to a key map for quick lookups.
  8004. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  8005. for (; !step.done; newIdx++, step = newChildren.next()) {
  8006. var _newFiber4 = updateFromMap(
  8007. existingChildren,
  8008. returnFiber,
  8009. newIdx,
  8010. step.value,
  8011. expirationTime
  8012. );
  8013. if (_newFiber4 !== null) {
  8014. if (shouldTrackSideEffects) {
  8015. if (_newFiber4.alternate !== null) {
  8016. // The new fiber is a work in progress, but if there exists a
  8017. // current, that means that we reused the fiber. We need to delete
  8018. // it from the child list so that we don't add it to the deletion
  8019. // list.
  8020. existingChildren.delete(
  8021. _newFiber4.key === null ? newIdx : _newFiber4.key
  8022. );
  8023. }
  8024. }
  8025. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  8026. if (previousNewFiber === null) {
  8027. resultingFirstChild = _newFiber4;
  8028. } else {
  8029. previousNewFiber.sibling = _newFiber4;
  8030. }
  8031. previousNewFiber = _newFiber4;
  8032. }
  8033. }
  8034. if (shouldTrackSideEffects) {
  8035. // Any existing children that weren't consumed above were deleted. We need
  8036. // to add them to the deletion list.
  8037. existingChildren.forEach(function(child) {
  8038. return deleteChild(returnFiber, child);
  8039. });
  8040. }
  8041. return resultingFirstChild;
  8042. }
  8043. function reconcileSingleTextNode(
  8044. returnFiber,
  8045. currentFirstChild,
  8046. textContent,
  8047. expirationTime
  8048. ) {
  8049. // There's no need to check for keys on text nodes since we don't have a
  8050. // way to define them.
  8051. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  8052. // We already have an existing node so let's just update it and delete
  8053. // the rest.
  8054. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  8055. var existing = useFiber(currentFirstChild, textContent);
  8056. existing.return = returnFiber;
  8057. return existing;
  8058. } // The existing first child is not a text node so we need to create one
  8059. // and delete the existing ones.
  8060. deleteRemainingChildren(returnFiber, currentFirstChild);
  8061. var created = createFiberFromText(
  8062. textContent,
  8063. returnFiber.mode,
  8064. expirationTime
  8065. );
  8066. created.return = returnFiber;
  8067. return created;
  8068. }
  8069. function reconcileSingleElement(
  8070. returnFiber,
  8071. currentFirstChild,
  8072. element,
  8073. expirationTime
  8074. ) {
  8075. var key = element.key;
  8076. var child = currentFirstChild;
  8077. while (child !== null) {
  8078. // TODO: If key === null and child.key === null, then this only applies to
  8079. // the first item in the list.
  8080. if (child.key === key) {
  8081. switch (child.tag) {
  8082. case Fragment: {
  8083. if (element.type === REACT_FRAGMENT_TYPE) {
  8084. deleteRemainingChildren(returnFiber, child.sibling);
  8085. var existing = useFiber(child, element.props.children);
  8086. existing.return = returnFiber;
  8087. {
  8088. existing._debugSource = element._source;
  8089. existing._debugOwner = element._owner;
  8090. }
  8091. return existing;
  8092. }
  8093. break;
  8094. }
  8095. case Block:
  8096. // We intentionally fallthrough here if enableBlocksAPI is not on.
  8097. // eslint-disable-next-lined no-fallthrough
  8098. default: {
  8099. if (
  8100. child.elementType === element.type || // Keep this check inline so it only runs on the false path:
  8101. isCompatibleFamilyForHotReloading(child, element)
  8102. ) {
  8103. deleteRemainingChildren(returnFiber, child.sibling);
  8104. var _existing3 = useFiber(child, element.props);
  8105. _existing3.ref = coerceRef(returnFiber, child, element);
  8106. _existing3.return = returnFiber;
  8107. {
  8108. _existing3._debugSource = element._source;
  8109. _existing3._debugOwner = element._owner;
  8110. }
  8111. return _existing3;
  8112. }
  8113. break;
  8114. }
  8115. } // Didn't match.
  8116. deleteRemainingChildren(returnFiber, child);
  8117. break;
  8118. } else {
  8119. deleteChild(returnFiber, child);
  8120. }
  8121. child = child.sibling;
  8122. }
  8123. if (element.type === REACT_FRAGMENT_TYPE) {
  8124. var created = createFiberFromFragment(
  8125. element.props.children,
  8126. returnFiber.mode,
  8127. expirationTime,
  8128. element.key
  8129. );
  8130. created.return = returnFiber;
  8131. return created;
  8132. } else {
  8133. var _created4 = createFiberFromElement(
  8134. element,
  8135. returnFiber.mode,
  8136. expirationTime
  8137. );
  8138. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  8139. _created4.return = returnFiber;
  8140. return _created4;
  8141. }
  8142. }
  8143. function reconcileSinglePortal(
  8144. returnFiber,
  8145. currentFirstChild,
  8146. portal,
  8147. expirationTime
  8148. ) {
  8149. var key = portal.key;
  8150. var child = currentFirstChild;
  8151. while (child !== null) {
  8152. // TODO: If key === null and child.key === null, then this only applies to
  8153. // the first item in the list.
  8154. if (child.key === key) {
  8155. if (
  8156. child.tag === HostPortal &&
  8157. child.stateNode.containerInfo === portal.containerInfo &&
  8158. child.stateNode.implementation === portal.implementation
  8159. ) {
  8160. deleteRemainingChildren(returnFiber, child.sibling);
  8161. var existing = useFiber(child, portal.children || []);
  8162. existing.return = returnFiber;
  8163. return existing;
  8164. } else {
  8165. deleteRemainingChildren(returnFiber, child);
  8166. break;
  8167. }
  8168. } else {
  8169. deleteChild(returnFiber, child);
  8170. }
  8171. child = child.sibling;
  8172. }
  8173. var created = createFiberFromPortal(
  8174. portal,
  8175. returnFiber.mode,
  8176. expirationTime
  8177. );
  8178. created.return = returnFiber;
  8179. return created;
  8180. } // This API will tag the children with the side-effect of the reconciliation
  8181. // itself. They will be added to the side-effect list as we pass through the
  8182. // children and the parent.
  8183. function reconcileChildFibers(
  8184. returnFiber,
  8185. currentFirstChild,
  8186. newChild,
  8187. expirationTime
  8188. ) {
  8189. // This function is not recursive.
  8190. // If the top level item is an array, we treat it as a set of children,
  8191. // not as a fragment. Nested arrays on the other hand will be treated as
  8192. // fragment nodes. Recursion happens at the normal flow.
  8193. // Handle top level unkeyed fragments as if they were arrays.
  8194. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  8195. // We treat the ambiguous cases above the same.
  8196. var isUnkeyedTopLevelFragment =
  8197. typeof newChild === "object" &&
  8198. newChild !== null &&
  8199. newChild.type === REACT_FRAGMENT_TYPE &&
  8200. newChild.key === null;
  8201. if (isUnkeyedTopLevelFragment) {
  8202. newChild = newChild.props.children;
  8203. } // Handle object types
  8204. var isObject = typeof newChild === "object" && newChild !== null;
  8205. if (isObject) {
  8206. switch (newChild.$$typeof) {
  8207. case REACT_ELEMENT_TYPE:
  8208. return placeSingleChild(
  8209. reconcileSingleElement(
  8210. returnFiber,
  8211. currentFirstChild,
  8212. newChild,
  8213. expirationTime
  8214. )
  8215. );
  8216. case REACT_PORTAL_TYPE:
  8217. return placeSingleChild(
  8218. reconcileSinglePortal(
  8219. returnFiber,
  8220. currentFirstChild,
  8221. newChild,
  8222. expirationTime
  8223. )
  8224. );
  8225. }
  8226. }
  8227. if (typeof newChild === "string" || typeof newChild === "number") {
  8228. return placeSingleChild(
  8229. reconcileSingleTextNode(
  8230. returnFiber,
  8231. currentFirstChild,
  8232. "" + newChild,
  8233. expirationTime
  8234. )
  8235. );
  8236. }
  8237. if (isArray$1(newChild)) {
  8238. return reconcileChildrenArray(
  8239. returnFiber,
  8240. currentFirstChild,
  8241. newChild,
  8242. expirationTime
  8243. );
  8244. }
  8245. if (getIteratorFn(newChild)) {
  8246. return reconcileChildrenIterator(
  8247. returnFiber,
  8248. currentFirstChild,
  8249. newChild,
  8250. expirationTime
  8251. );
  8252. }
  8253. if (isObject) {
  8254. throwOnInvalidObjectType(returnFiber, newChild);
  8255. }
  8256. {
  8257. if (typeof newChild === "function") {
  8258. warnOnFunctionType();
  8259. }
  8260. }
  8261. if (typeof newChild === "undefined" && !isUnkeyedTopLevelFragment) {
  8262. // If the new child is undefined, and the return fiber is a composite
  8263. // component, throw an error. If Fiber return types are disabled,
  8264. // we already threw above.
  8265. switch (returnFiber.tag) {
  8266. case ClassComponent: {
  8267. {
  8268. var instance = returnFiber.stateNode;
  8269. if (instance.render._isMockFunction) {
  8270. // We allow auto-mocks to proceed as if they're returning null.
  8271. break;
  8272. }
  8273. }
  8274. }
  8275. // Intentionally fall through to the next case, which handles both
  8276. // functions and classes
  8277. // eslint-disable-next-lined no-fallthrough
  8278. case FunctionComponent: {
  8279. var Component = returnFiber.type;
  8280. {
  8281. throw Error(
  8282. (Component.displayName || Component.name || "Component") +
  8283. "(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null."
  8284. );
  8285. }
  8286. }
  8287. }
  8288. } // Remaining cases are all treated as empty.
  8289. return deleteRemainingChildren(returnFiber, currentFirstChild);
  8290. }
  8291. return reconcileChildFibers;
  8292. }
  8293. var reconcileChildFibers = ChildReconciler(true);
  8294. var mountChildFibers = ChildReconciler(false);
  8295. function cloneChildFibers(current, workInProgress) {
  8296. if (!(current === null || workInProgress.child === current.child)) {
  8297. throw Error("Resuming work not yet implemented.");
  8298. }
  8299. if (workInProgress.child === null) {
  8300. return;
  8301. }
  8302. var currentChild = workInProgress.child;
  8303. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  8304. workInProgress.child = newChild;
  8305. newChild.return = workInProgress;
  8306. while (currentChild.sibling !== null) {
  8307. currentChild = currentChild.sibling;
  8308. newChild = newChild.sibling = createWorkInProgress(
  8309. currentChild,
  8310. currentChild.pendingProps
  8311. );
  8312. newChild.return = workInProgress;
  8313. }
  8314. newChild.sibling = null;
  8315. } // Reset a workInProgress child set to prepare it for a second pass.
  8316. function resetChildFibers(workInProgress, renderExpirationTime) {
  8317. var child = workInProgress.child;
  8318. while (child !== null) {
  8319. resetWorkInProgress(child, renderExpirationTime);
  8320. child = child.sibling;
  8321. }
  8322. }
  8323. var NO_CONTEXT = {};
  8324. var contextStackCursor$1 = createCursor(NO_CONTEXT);
  8325. var contextFiberStackCursor = createCursor(NO_CONTEXT);
  8326. var rootInstanceStackCursor = createCursor(NO_CONTEXT);
  8327. function requiredContext(c) {
  8328. if (!(c !== NO_CONTEXT)) {
  8329. throw Error(
  8330. "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue."
  8331. );
  8332. }
  8333. return c;
  8334. }
  8335. function getRootHostContainer() {
  8336. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8337. return rootInstance;
  8338. }
  8339. function pushHostContainer(fiber, nextRootInstance) {
  8340. // Push current root instance onto the stack;
  8341. // This allows us to reset root when portals are popped.
  8342. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  8343. // This enables us to pop only Fibers that provide unique contexts.
  8344. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  8345. // However, we can't just call getRootHostContext() and push it because
  8346. // we'd have a different number of entries on the stack depending on
  8347. // whether getRootHostContext() throws somewhere in renderer code or not.
  8348. // So we push an empty value first. This lets us safely unwind on errors.
  8349. push(contextStackCursor$1, NO_CONTEXT, fiber);
  8350. var nextRootContext = getRootHostContext(); // Now that we know this function doesn't throw, replace it.
  8351. pop(contextStackCursor$1, fiber);
  8352. push(contextStackCursor$1, nextRootContext, fiber);
  8353. }
  8354. function popHostContainer(fiber) {
  8355. pop(contextStackCursor$1, fiber);
  8356. pop(contextFiberStackCursor, fiber);
  8357. pop(rootInstanceStackCursor, fiber);
  8358. }
  8359. function getHostContext() {
  8360. var context = requiredContext(contextStackCursor$1.current);
  8361. return context;
  8362. }
  8363. function pushHostContext(fiber) {
  8364. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8365. var context = requiredContext(contextStackCursor$1.current);
  8366. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  8367. if (context === nextContext) {
  8368. return;
  8369. } // Track the context and the Fiber that provided it.
  8370. // This enables us to pop only Fibers that provide unique contexts.
  8371. push(contextFiberStackCursor, fiber, fiber);
  8372. push(contextStackCursor$1, nextContext, fiber);
  8373. }
  8374. function popHostContext(fiber) {
  8375. // Do not pop unless this Fiber provided the current context.
  8376. // pushHostContext() only pushes Fibers that provide unique contexts.
  8377. if (contextFiberStackCursor.current !== fiber) {
  8378. return;
  8379. }
  8380. pop(contextStackCursor$1, fiber);
  8381. pop(contextFiberStackCursor, fiber);
  8382. }
  8383. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  8384. // inherited deeply down the subtree. The upper bits only affect
  8385. // this immediate suspense boundary and gets reset each new
  8386. // boundary or suspense list.
  8387. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  8388. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  8389. // boundaries is not currently showing visible main content.
  8390. // Either because it is already showing a fallback or is not mounted at all.
  8391. // We can use this to determine if it is desirable to trigger a fallback at
  8392. // the parent. If not, then we might need to trigger undesirable boundaries
  8393. // and/or suspend the commit to avoid hiding the parent content.
  8394. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  8395. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  8396. // items into their fallback state during one of the render passes.
  8397. var ForceSuspenseFallback = 2;
  8398. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  8399. function hasSuspenseContext(parentContext, flag) {
  8400. return (parentContext & flag) !== 0;
  8401. }
  8402. function setDefaultShallowSuspenseContext(parentContext) {
  8403. return parentContext & SubtreeSuspenseContextMask;
  8404. }
  8405. function setShallowSuspenseContext(parentContext, shallowContext) {
  8406. return (parentContext & SubtreeSuspenseContextMask) | shallowContext;
  8407. }
  8408. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  8409. return parentContext | subtreeContext;
  8410. }
  8411. function pushSuspenseContext(fiber, newContext) {
  8412. push(suspenseStackCursor, newContext, fiber);
  8413. }
  8414. function popSuspenseContext(fiber) {
  8415. pop(suspenseStackCursor, fiber);
  8416. }
  8417. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  8418. // If it was the primary children that just suspended, capture and render the
  8419. // fallback. Otherwise, don't capture and bubble to the next boundary.
  8420. var nextState = workInProgress.memoizedState;
  8421. if (nextState !== null) {
  8422. if (nextState.dehydrated !== null) {
  8423. // A dehydrated boundary always captures.
  8424. return true;
  8425. }
  8426. return false;
  8427. }
  8428. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  8429. if (props.fallback === undefined) {
  8430. return false;
  8431. } // Regular boundaries always capture.
  8432. if (props.unstable_avoidThisFallback !== true) {
  8433. return true;
  8434. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  8435. // parent boundary if it is currently invisible.
  8436. if (hasInvisibleParent) {
  8437. return false;
  8438. } // If the parent is not able to handle it, we must handle it.
  8439. return true;
  8440. }
  8441. function findFirstSuspended(row) {
  8442. var node = row;
  8443. while (node !== null) {
  8444. if (node.tag === SuspenseComponent) {
  8445. var state = node.memoizedState;
  8446. if (state !== null) {
  8447. var dehydrated = state.dehydrated;
  8448. if (
  8449. dehydrated === null ||
  8450. isSuspenseInstancePending() ||
  8451. isSuspenseInstanceFallback()
  8452. ) {
  8453. return node;
  8454. }
  8455. }
  8456. } else if (
  8457. node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  8458. // keep track of whether it suspended or not.
  8459. node.memoizedProps.revealOrder !== undefined
  8460. ) {
  8461. var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
  8462. if (didSuspend) {
  8463. return node;
  8464. }
  8465. } else if (node.child !== null) {
  8466. node.child.return = node;
  8467. node = node.child;
  8468. continue;
  8469. }
  8470. if (node === row) {
  8471. return null;
  8472. }
  8473. while (node.sibling === null) {
  8474. if (node.return === null || node.return === row) {
  8475. return null;
  8476. }
  8477. node = node.return;
  8478. }
  8479. node.sibling.return = node.return;
  8480. node = node.sibling;
  8481. }
  8482. return null;
  8483. }
  8484. function createDeprecatedResponderListener(responder, props) {
  8485. var eventResponderListener = {
  8486. responder: responder,
  8487. props: props
  8488. };
  8489. {
  8490. Object.freeze(eventResponderListener);
  8491. }
  8492. return eventResponderListener;
  8493. }
  8494. var HasEffect =
  8495. /* */
  8496. 1; // Represents the phase in which the effect (not the clean-up) fires.
  8497. var Layout =
  8498. /* */
  8499. 2;
  8500. var Passive$1 =
  8501. /* */
  8502. 4;
  8503. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
  8504. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  8505. var didWarnAboutMismatchedHooksForComponent;
  8506. {
  8507. didWarnAboutMismatchedHooksForComponent = new Set();
  8508. }
  8509. // These are set right before calling the component.
  8510. var renderExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
  8511. // the work-in-progress hook.
  8512. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  8513. // current hook list is the list that belongs to the current fiber. The
  8514. // work-in-progress hook list is a new list that will be added to the
  8515. // work-in-progress fiber.
  8516. var currentHook = null;
  8517. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  8518. // does not get reset if we do another render pass; only when we're completely
  8519. // finished evaluating this component. This is an optimization so we know
  8520. // whether we need to clear render phase updates after a throw.
  8521. var didScheduleRenderPhaseUpdate = false;
  8522. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  8523. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  8524. // The list stores the order of hooks used during the initial render (mount).
  8525. // Subsequent renders (updates) reference this list.
  8526. var hookTypesDev = null;
  8527. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  8528. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  8529. // When true, such Hooks will always be "remounted". Only used during hot reload.
  8530. var ignorePreviousDependencies = false;
  8531. function mountHookTypesDev() {
  8532. {
  8533. var hookName = currentHookNameInDev;
  8534. if (hookTypesDev === null) {
  8535. hookTypesDev = [hookName];
  8536. } else {
  8537. hookTypesDev.push(hookName);
  8538. }
  8539. }
  8540. }
  8541. function updateHookTypesDev() {
  8542. {
  8543. var hookName = currentHookNameInDev;
  8544. if (hookTypesDev !== null) {
  8545. hookTypesUpdateIndexDev++;
  8546. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  8547. warnOnHookMismatchInDev(hookName);
  8548. }
  8549. }
  8550. }
  8551. }
  8552. function checkDepsAreArrayDev(deps) {
  8553. {
  8554. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  8555. // Verify deps, but only on mount to avoid extra checks.
  8556. // It's unlikely their type would change as usually you define them inline.
  8557. error(
  8558. "%s received a final argument that is not an array (instead, received `%s`). When " +
  8559. "specified, the final argument must be an array.",
  8560. currentHookNameInDev,
  8561. typeof deps
  8562. );
  8563. }
  8564. }
  8565. }
  8566. function warnOnHookMismatchInDev(currentHookName) {
  8567. {
  8568. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  8569. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  8570. didWarnAboutMismatchedHooksForComponent.add(componentName);
  8571. if (hookTypesDev !== null) {
  8572. var table = "";
  8573. var secondColumnStart = 30;
  8574. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  8575. var oldHookName = hookTypesDev[i];
  8576. var newHookName =
  8577. i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  8578. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  8579. // lol @ IE not supporting String#repeat
  8580. while (row.length < secondColumnStart) {
  8581. row += " ";
  8582. }
  8583. row += newHookName + "\n";
  8584. table += row;
  8585. }
  8586. error(
  8587. "React has detected a change in the order of Hooks called by %s. " +
  8588. "This will lead to bugs and errors if not fixed. " +
  8589. "For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n" +
  8590. " Previous render Next render\n" +
  8591. " ------------------------------------------------------\n" +
  8592. "%s" +
  8593. " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
  8594. componentName,
  8595. table
  8596. );
  8597. }
  8598. }
  8599. }
  8600. }
  8601. function throwInvalidHookError() {
  8602. {
  8603. throw Error(
  8604. "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem."
  8605. );
  8606. }
  8607. }
  8608. function areHookInputsEqual(nextDeps, prevDeps) {
  8609. {
  8610. if (ignorePreviousDependencies) {
  8611. // Only true when this component is being hot reloaded.
  8612. return false;
  8613. }
  8614. }
  8615. if (prevDeps === null) {
  8616. {
  8617. error(
  8618. "%s received a final argument during this render, but not during " +
  8619. "the previous render. Even though the final argument is optional, " +
  8620. "its type cannot change between renders.",
  8621. currentHookNameInDev
  8622. );
  8623. }
  8624. return false;
  8625. }
  8626. {
  8627. // Don't bother comparing lengths in prod because these arrays should be
  8628. // passed inline.
  8629. if (nextDeps.length !== prevDeps.length) {
  8630. error(
  8631. "The final argument passed to %s changed size between renders. The " +
  8632. "order and size of this array must remain constant.\n\n" +
  8633. "Previous: %s\n" +
  8634. "Incoming: %s",
  8635. currentHookNameInDev,
  8636. "[" + prevDeps.join(", ") + "]",
  8637. "[" + nextDeps.join(", ") + "]"
  8638. );
  8639. }
  8640. }
  8641. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  8642. if (objectIs(nextDeps[i], prevDeps[i])) {
  8643. continue;
  8644. }
  8645. return false;
  8646. }
  8647. return true;
  8648. }
  8649. function renderWithHooks(
  8650. current,
  8651. workInProgress,
  8652. Component,
  8653. props,
  8654. secondArg,
  8655. nextRenderExpirationTime
  8656. ) {
  8657. renderExpirationTime = nextRenderExpirationTime;
  8658. currentlyRenderingFiber$1 = workInProgress;
  8659. {
  8660. hookTypesDev = current !== null ? current._debugHookTypes : null;
  8661. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  8662. ignorePreviousDependencies =
  8663. current !== null && current.type !== workInProgress.type;
  8664. }
  8665. workInProgress.memoizedState = null;
  8666. workInProgress.updateQueue = null;
  8667. workInProgress.expirationTime = NoWork; // The following should have already been reset
  8668. // currentHook = null;
  8669. // workInProgressHook = null;
  8670. // didScheduleRenderPhaseUpdate = false;
  8671. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  8672. // Currently we will identify the update render as a mount because memoizedState === null.
  8673. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  8674. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  8675. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  8676. // so memoizedState would be null during updates and mounts.
  8677. {
  8678. if (current !== null && current.memoizedState !== null) {
  8679. ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
  8680. } else if (hookTypesDev !== null) {
  8681. // This dispatcher handles an edge case where a component is updating,
  8682. // but no stateful hooks have been used.
  8683. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  8684. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  8685. // This dispatcher does that.
  8686. ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
  8687. } else {
  8688. ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
  8689. }
  8690. }
  8691. var children = Component(props, secondArg); // Check if there was a render phase update
  8692. if (workInProgress.expirationTime === renderExpirationTime) {
  8693. // Keep rendering in a loop for as long as render phase updates continue to
  8694. // be scheduled. Use a counter to prevent infinite loops.
  8695. var numberOfReRenders = 0;
  8696. do {
  8697. workInProgress.expirationTime = NoWork;
  8698. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  8699. throw Error(
  8700. "Too many re-renders. React limits the number of renders to prevent an infinite loop."
  8701. );
  8702. }
  8703. numberOfReRenders += 1;
  8704. {
  8705. // Even when hot reloading, allow dependencies to stabilize
  8706. // after first render to prevent infinite render phase updates.
  8707. ignorePreviousDependencies = false;
  8708. } // Start over from the beginning of the list
  8709. currentHook = null;
  8710. workInProgressHook = null;
  8711. workInProgress.updateQueue = null;
  8712. {
  8713. // Also validate hook order for cascading updates.
  8714. hookTypesUpdateIndexDev = -1;
  8715. }
  8716. ReactCurrentDispatcher.current = HooksDispatcherOnRerenderInDEV;
  8717. children = Component(props, secondArg);
  8718. } while (workInProgress.expirationTime === renderExpirationTime);
  8719. } // We can assume the previous dispatcher is always this one, since we set it
  8720. // at the beginning of the render phase and there's no re-entrancy.
  8721. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8722. {
  8723. workInProgress._debugHookTypes = hookTypesDev;
  8724. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  8725. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  8726. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  8727. renderExpirationTime = NoWork;
  8728. currentlyRenderingFiber$1 = null;
  8729. currentHook = null;
  8730. workInProgressHook = null;
  8731. {
  8732. currentHookNameInDev = null;
  8733. hookTypesDev = null;
  8734. hookTypesUpdateIndexDev = -1;
  8735. }
  8736. didScheduleRenderPhaseUpdate = false;
  8737. if (!!didRenderTooFewHooks) {
  8738. throw Error(
  8739. "Rendered fewer hooks than expected. This may be caused by an accidental early return statement."
  8740. );
  8741. }
  8742. return children;
  8743. }
  8744. function bailoutHooks(current, workInProgress, expirationTime) {
  8745. workInProgress.updateQueue = current.updateQueue;
  8746. workInProgress.effectTag &= ~(Passive | Update);
  8747. if (current.expirationTime <= expirationTime) {
  8748. current.expirationTime = NoWork;
  8749. }
  8750. }
  8751. function resetHooksAfterThrow() {
  8752. // We can assume the previous dispatcher is always this one, since we set it
  8753. // at the beginning of the render phase and there's no re-entrancy.
  8754. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8755. if (didScheduleRenderPhaseUpdate) {
  8756. // There were render phase updates. These are only valid for this render
  8757. // phase, which we are now aborting. Remove the updates from the queues so
  8758. // they do not persist to the next render. Do not remove updates from hooks
  8759. // that weren't processed.
  8760. //
  8761. // Only reset the updates from the queue if it has a clone. If it does
  8762. // not have a clone, that means it wasn't processed, and the updates were
  8763. // scheduled before we entered the render phase.
  8764. var hook = currentlyRenderingFiber$1.memoizedState;
  8765. while (hook !== null) {
  8766. var queue = hook.queue;
  8767. if (queue !== null) {
  8768. queue.pending = null;
  8769. }
  8770. hook = hook.next;
  8771. }
  8772. }
  8773. renderExpirationTime = NoWork;
  8774. currentlyRenderingFiber$1 = null;
  8775. currentHook = null;
  8776. workInProgressHook = null;
  8777. {
  8778. hookTypesDev = null;
  8779. hookTypesUpdateIndexDev = -1;
  8780. currentHookNameInDev = null;
  8781. }
  8782. didScheduleRenderPhaseUpdate = false;
  8783. }
  8784. function mountWorkInProgressHook() {
  8785. var hook = {
  8786. memoizedState: null,
  8787. baseState: null,
  8788. baseQueue: null,
  8789. queue: null,
  8790. next: null
  8791. };
  8792. if (workInProgressHook === null) {
  8793. // This is the first hook in the list
  8794. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  8795. } else {
  8796. // Append to the end of the list
  8797. workInProgressHook = workInProgressHook.next = hook;
  8798. }
  8799. return workInProgressHook;
  8800. }
  8801. function updateWorkInProgressHook() {
  8802. // This function is used both for updates and for re-renders triggered by a
  8803. // render phase update. It assumes there is either a current hook we can
  8804. // clone, or a work-in-progress hook from a previous render pass that we can
  8805. // use as a base. When we reach the end of the base list, we must switch to
  8806. // the dispatcher used for mounts.
  8807. var nextCurrentHook;
  8808. if (currentHook === null) {
  8809. var current = currentlyRenderingFiber$1.alternate;
  8810. if (current !== null) {
  8811. nextCurrentHook = current.memoizedState;
  8812. } else {
  8813. nextCurrentHook = null;
  8814. }
  8815. } else {
  8816. nextCurrentHook = currentHook.next;
  8817. }
  8818. var nextWorkInProgressHook;
  8819. if (workInProgressHook === null) {
  8820. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  8821. } else {
  8822. nextWorkInProgressHook = workInProgressHook.next;
  8823. }
  8824. if (nextWorkInProgressHook !== null) {
  8825. // There's already a work-in-progress. Reuse it.
  8826. workInProgressHook = nextWorkInProgressHook;
  8827. nextWorkInProgressHook = workInProgressHook.next;
  8828. currentHook = nextCurrentHook;
  8829. } else {
  8830. // Clone from the current hook.
  8831. if (!(nextCurrentHook !== null)) {
  8832. throw Error("Rendered more hooks than during the previous render.");
  8833. }
  8834. currentHook = nextCurrentHook;
  8835. var newHook = {
  8836. memoizedState: currentHook.memoizedState,
  8837. baseState: currentHook.baseState,
  8838. baseQueue: currentHook.baseQueue,
  8839. queue: currentHook.queue,
  8840. next: null
  8841. };
  8842. if (workInProgressHook === null) {
  8843. // This is the first hook in the list.
  8844. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  8845. } else {
  8846. // Append to the end of the list.
  8847. workInProgressHook = workInProgressHook.next = newHook;
  8848. }
  8849. }
  8850. return workInProgressHook;
  8851. }
  8852. function createFunctionComponentUpdateQueue() {
  8853. return {
  8854. lastEffect: null
  8855. };
  8856. }
  8857. function basicStateReducer(state, action) {
  8858. // $FlowFixMe: Flow doesn't like mixed types
  8859. return typeof action === "function" ? action(state) : action;
  8860. }
  8861. function mountReducer(reducer, initialArg, init) {
  8862. var hook = mountWorkInProgressHook();
  8863. var initialState;
  8864. if (init !== undefined) {
  8865. initialState = init(initialArg);
  8866. } else {
  8867. initialState = initialArg;
  8868. }
  8869. hook.memoizedState = hook.baseState = initialState;
  8870. var queue = (hook.queue = {
  8871. pending: null,
  8872. dispatch: null,
  8873. lastRenderedReducer: reducer,
  8874. lastRenderedState: initialState
  8875. });
  8876. var dispatch = (queue.dispatch = dispatchAction.bind(
  8877. null,
  8878. currentlyRenderingFiber$1,
  8879. queue
  8880. ));
  8881. return [hook.memoizedState, dispatch];
  8882. }
  8883. function updateReducer(reducer, initialArg, init) {
  8884. var hook = updateWorkInProgressHook();
  8885. var queue = hook.queue;
  8886. if (!(queue !== null)) {
  8887. throw Error(
  8888. "Should have a queue. This is likely a bug in React. Please file an issue."
  8889. );
  8890. }
  8891. queue.lastRenderedReducer = reducer;
  8892. var current = currentHook; // The last rebase update that is NOT part of the base state.
  8893. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  8894. var pendingQueue = queue.pending;
  8895. if (pendingQueue !== null) {
  8896. // We have new updates that haven't been processed yet.
  8897. // We'll add them to the base queue.
  8898. if (baseQueue !== null) {
  8899. // Merge the pending queue and the base queue.
  8900. var baseFirst = baseQueue.next;
  8901. var pendingFirst = pendingQueue.next;
  8902. baseQueue.next = pendingFirst;
  8903. pendingQueue.next = baseFirst;
  8904. }
  8905. current.baseQueue = baseQueue = pendingQueue;
  8906. queue.pending = null;
  8907. }
  8908. if (baseQueue !== null) {
  8909. // We have a queue to process.
  8910. var first = baseQueue.next;
  8911. var newState = current.baseState;
  8912. var newBaseState = null;
  8913. var newBaseQueueFirst = null;
  8914. var newBaseQueueLast = null;
  8915. var update = first;
  8916. do {
  8917. var updateExpirationTime = update.expirationTime;
  8918. if (updateExpirationTime < renderExpirationTime) {
  8919. // Priority is insufficient. Skip this update. If this is the first
  8920. // skipped update, the previous update/state is the new base
  8921. // update/state.
  8922. var clone = {
  8923. expirationTime: update.expirationTime,
  8924. suspenseConfig: update.suspenseConfig,
  8925. action: update.action,
  8926. eagerReducer: update.eagerReducer,
  8927. eagerState: update.eagerState,
  8928. next: null
  8929. };
  8930. if (newBaseQueueLast === null) {
  8931. newBaseQueueFirst = newBaseQueueLast = clone;
  8932. newBaseState = newState;
  8933. } else {
  8934. newBaseQueueLast = newBaseQueueLast.next = clone;
  8935. } // Update the remaining priority in the queue.
  8936. if (updateExpirationTime > currentlyRenderingFiber$1.expirationTime) {
  8937. currentlyRenderingFiber$1.expirationTime = updateExpirationTime;
  8938. markUnprocessedUpdateTime(updateExpirationTime);
  8939. }
  8940. } else {
  8941. // This update does have sufficient priority.
  8942. if (newBaseQueueLast !== null) {
  8943. var _clone = {
  8944. expirationTime: Sync,
  8945. // This update is going to be committed so we never want uncommit it.
  8946. suspenseConfig: update.suspenseConfig,
  8947. action: update.action,
  8948. eagerReducer: update.eagerReducer,
  8949. eagerState: update.eagerState,
  8950. next: null
  8951. };
  8952. newBaseQueueLast = newBaseQueueLast.next = _clone;
  8953. } // Mark the event time of this update as relevant to this render pass.
  8954. // TODO: This should ideally use the true event time of this update rather than
  8955. // its priority which is a derived and not reverseable value.
  8956. // TODO: We should skip this update if it was already committed but currently
  8957. // we have no way of detecting the difference between a committed and suspended
  8958. // update here.
  8959. markRenderEventTimeAndConfig(
  8960. updateExpirationTime,
  8961. update.suspenseConfig
  8962. ); // Process this update.
  8963. if (update.eagerReducer === reducer) {
  8964. // If this update was processed eagerly, and its reducer matches the
  8965. // current reducer, we can use the eagerly computed state.
  8966. newState = update.eagerState;
  8967. } else {
  8968. var action = update.action;
  8969. newState = reducer(newState, action);
  8970. }
  8971. }
  8972. update = update.next;
  8973. } while (update !== null && update !== first);
  8974. if (newBaseQueueLast === null) {
  8975. newBaseState = newState;
  8976. } else {
  8977. newBaseQueueLast.next = newBaseQueueFirst;
  8978. } // Mark that the fiber performed work, but only if the new state is
  8979. // different from the current state.
  8980. if (!objectIs(newState, hook.memoizedState)) {
  8981. markWorkInProgressReceivedUpdate();
  8982. }
  8983. hook.memoizedState = newState;
  8984. hook.baseState = newBaseState;
  8985. hook.baseQueue = newBaseQueueLast;
  8986. queue.lastRenderedState = newState;
  8987. }
  8988. var dispatch = queue.dispatch;
  8989. return [hook.memoizedState, dispatch];
  8990. }
  8991. function rerenderReducer(reducer, initialArg, init) {
  8992. var hook = updateWorkInProgressHook();
  8993. var queue = hook.queue;
  8994. if (!(queue !== null)) {
  8995. throw Error(
  8996. "Should have a queue. This is likely a bug in React. Please file an issue."
  8997. );
  8998. }
  8999. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  9000. // work-in-progress hook.
  9001. var dispatch = queue.dispatch;
  9002. var lastRenderPhaseUpdate = queue.pending;
  9003. var newState = hook.memoizedState;
  9004. if (lastRenderPhaseUpdate !== null) {
  9005. // The queue doesn't persist past this render pass.
  9006. queue.pending = null;
  9007. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  9008. var update = firstRenderPhaseUpdate;
  9009. do {
  9010. // Process this render phase update. We don't have to check the
  9011. // priority because it will always be the same as the current
  9012. // render's.
  9013. var action = update.action;
  9014. newState = reducer(newState, action);
  9015. update = update.next;
  9016. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  9017. // different from the current state.
  9018. if (!objectIs(newState, hook.memoizedState)) {
  9019. markWorkInProgressReceivedUpdate();
  9020. }
  9021. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  9022. // the base state unless the queue is empty.
  9023. // TODO: Not sure if this is the desired semantics, but it's what we
  9024. // do for gDSFP. I can't remember why.
  9025. if (hook.baseQueue === null) {
  9026. hook.baseState = newState;
  9027. }
  9028. queue.lastRenderedState = newState;
  9029. }
  9030. return [newState, dispatch];
  9031. }
  9032. function mountState(initialState) {
  9033. var hook = mountWorkInProgressHook();
  9034. if (typeof initialState === "function") {
  9035. // $FlowFixMe: Flow doesn't like mixed types
  9036. initialState = initialState();
  9037. }
  9038. hook.memoizedState = hook.baseState = initialState;
  9039. var queue = (hook.queue = {
  9040. pending: null,
  9041. dispatch: null,
  9042. lastRenderedReducer: basicStateReducer,
  9043. lastRenderedState: initialState
  9044. });
  9045. var dispatch = (queue.dispatch = dispatchAction.bind(
  9046. null,
  9047. currentlyRenderingFiber$1,
  9048. queue
  9049. ));
  9050. return [hook.memoizedState, dispatch];
  9051. }
  9052. function updateState(initialState) {
  9053. return updateReducer(basicStateReducer);
  9054. }
  9055. function rerenderState(initialState) {
  9056. return rerenderReducer(basicStateReducer);
  9057. }
  9058. function pushEffect(tag, create, destroy, deps) {
  9059. var effect = {
  9060. tag: tag,
  9061. create: create,
  9062. destroy: destroy,
  9063. deps: deps,
  9064. // Circular
  9065. next: null
  9066. };
  9067. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  9068. if (componentUpdateQueue === null) {
  9069. componentUpdateQueue = createFunctionComponentUpdateQueue();
  9070. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  9071. componentUpdateQueue.lastEffect = effect.next = effect;
  9072. } else {
  9073. var lastEffect = componentUpdateQueue.lastEffect;
  9074. if (lastEffect === null) {
  9075. componentUpdateQueue.lastEffect = effect.next = effect;
  9076. } else {
  9077. var firstEffect = lastEffect.next;
  9078. lastEffect.next = effect;
  9079. effect.next = firstEffect;
  9080. componentUpdateQueue.lastEffect = effect;
  9081. }
  9082. }
  9083. return effect;
  9084. }
  9085. function mountRef(initialValue) {
  9086. var hook = mountWorkInProgressHook();
  9087. var ref = {
  9088. current: initialValue
  9089. };
  9090. {
  9091. Object.seal(ref);
  9092. }
  9093. hook.memoizedState = ref;
  9094. return ref;
  9095. }
  9096. function updateRef(initialValue) {
  9097. var hook = updateWorkInProgressHook();
  9098. return hook.memoizedState;
  9099. }
  9100. function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  9101. var hook = mountWorkInProgressHook();
  9102. var nextDeps = deps === undefined ? null : deps;
  9103. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  9104. hook.memoizedState = pushEffect(
  9105. HasEffect | hookEffectTag,
  9106. create,
  9107. undefined,
  9108. nextDeps
  9109. );
  9110. }
  9111. function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  9112. var hook = updateWorkInProgressHook();
  9113. var nextDeps = deps === undefined ? null : deps;
  9114. var destroy = undefined;
  9115. if (currentHook !== null) {
  9116. var prevEffect = currentHook.memoizedState;
  9117. destroy = prevEffect.destroy;
  9118. if (nextDeps !== null) {
  9119. var prevDeps = prevEffect.deps;
  9120. if (areHookInputsEqual(nextDeps, prevDeps)) {
  9121. pushEffect(hookEffectTag, create, destroy, nextDeps);
  9122. return;
  9123. }
  9124. }
  9125. }
  9126. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  9127. hook.memoizedState = pushEffect(
  9128. HasEffect | hookEffectTag,
  9129. create,
  9130. destroy,
  9131. nextDeps
  9132. );
  9133. }
  9134. function mountEffect(create, deps) {
  9135. {
  9136. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  9137. if ("undefined" !== typeof jest) {
  9138. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  9139. }
  9140. }
  9141. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  9142. }
  9143. function updateEffect(create, deps) {
  9144. {
  9145. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  9146. if ("undefined" !== typeof jest) {
  9147. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  9148. }
  9149. }
  9150. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  9151. }
  9152. function mountLayoutEffect(create, deps) {
  9153. return mountEffectImpl(Update, Layout, create, deps);
  9154. }
  9155. function updateLayoutEffect(create, deps) {
  9156. return updateEffectImpl(Update, Layout, create, deps);
  9157. }
  9158. function imperativeHandleEffect(create, ref) {
  9159. if (typeof ref === "function") {
  9160. var refCallback = ref;
  9161. var _inst = create();
  9162. refCallback(_inst);
  9163. return function() {
  9164. refCallback(null);
  9165. };
  9166. } else if (ref !== null && ref !== undefined) {
  9167. var refObject = ref;
  9168. {
  9169. if (!refObject.hasOwnProperty("current")) {
  9170. error(
  9171. "Expected useImperativeHandle() first argument to either be a " +
  9172. "ref callback or React.createRef() object. Instead received: %s.",
  9173. "an object with keys {" + Object.keys(refObject).join(", ") + "}"
  9174. );
  9175. }
  9176. }
  9177. var _inst2 = create();
  9178. refObject.current = _inst2;
  9179. return function() {
  9180. refObject.current = null;
  9181. };
  9182. }
  9183. }
  9184. function mountImperativeHandle(ref, create, deps) {
  9185. {
  9186. if (typeof create !== "function") {
  9187. error(
  9188. "Expected useImperativeHandle() second argument to be a function " +
  9189. "that creates a handle. Instead received: %s.",
  9190. create !== null ? typeof create : "null"
  9191. );
  9192. }
  9193. } // TODO: If deps are provided, should we skip comparing the ref itself?
  9194. var effectDeps =
  9195. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  9196. return mountEffectImpl(
  9197. Update,
  9198. Layout,
  9199. imperativeHandleEffect.bind(null, create, ref),
  9200. effectDeps
  9201. );
  9202. }
  9203. function updateImperativeHandle(ref, create, deps) {
  9204. {
  9205. if (typeof create !== "function") {
  9206. error(
  9207. "Expected useImperativeHandle() second argument to be a function " +
  9208. "that creates a handle. Instead received: %s.",
  9209. create !== null ? typeof create : "null"
  9210. );
  9211. }
  9212. } // TODO: If deps are provided, should we skip comparing the ref itself?
  9213. var effectDeps =
  9214. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  9215. return updateEffectImpl(
  9216. Update,
  9217. Layout,
  9218. imperativeHandleEffect.bind(null, create, ref),
  9219. effectDeps
  9220. );
  9221. }
  9222. function mountDebugValue(value, formatterFn) {
  9223. // This hook is normally a no-op.
  9224. // The react-debug-hooks package injects its own implementation
  9225. // so that e.g. DevTools can display custom hook values.
  9226. }
  9227. var updateDebugValue = mountDebugValue;
  9228. function mountCallback(callback, deps) {
  9229. var hook = mountWorkInProgressHook();
  9230. var nextDeps = deps === undefined ? null : deps;
  9231. hook.memoizedState = [callback, nextDeps];
  9232. return callback;
  9233. }
  9234. function updateCallback(callback, deps) {
  9235. var hook = updateWorkInProgressHook();
  9236. var nextDeps = deps === undefined ? null : deps;
  9237. var prevState = hook.memoizedState;
  9238. if (prevState !== null) {
  9239. if (nextDeps !== null) {
  9240. var prevDeps = prevState[1];
  9241. if (areHookInputsEqual(nextDeps, prevDeps)) {
  9242. return prevState[0];
  9243. }
  9244. }
  9245. }
  9246. hook.memoizedState = [callback, nextDeps];
  9247. return callback;
  9248. }
  9249. function mountMemo(nextCreate, deps) {
  9250. var hook = mountWorkInProgressHook();
  9251. var nextDeps = deps === undefined ? null : deps;
  9252. var nextValue = nextCreate();
  9253. hook.memoizedState = [nextValue, nextDeps];
  9254. return nextValue;
  9255. }
  9256. function updateMemo(nextCreate, deps) {
  9257. var hook = updateWorkInProgressHook();
  9258. var nextDeps = deps === undefined ? null : deps;
  9259. var prevState = hook.memoizedState;
  9260. if (prevState !== null) {
  9261. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  9262. if (nextDeps !== null) {
  9263. var prevDeps = prevState[1];
  9264. if (areHookInputsEqual(nextDeps, prevDeps)) {
  9265. return prevState[0];
  9266. }
  9267. }
  9268. }
  9269. var nextValue = nextCreate();
  9270. hook.memoizedState = [nextValue, nextDeps];
  9271. return nextValue;
  9272. }
  9273. function mountDeferredValue(value, config) {
  9274. var _mountState = mountState(value),
  9275. prevValue = _mountState[0],
  9276. setValue = _mountState[1];
  9277. mountEffect(
  9278. function() {
  9279. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9280. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9281. try {
  9282. setValue(value);
  9283. } finally {
  9284. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9285. }
  9286. },
  9287. [value, config]
  9288. );
  9289. return prevValue;
  9290. }
  9291. function updateDeferredValue(value, config) {
  9292. var _updateState = updateState(),
  9293. prevValue = _updateState[0],
  9294. setValue = _updateState[1];
  9295. updateEffect(
  9296. function() {
  9297. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9298. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9299. try {
  9300. setValue(value);
  9301. } finally {
  9302. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9303. }
  9304. },
  9305. [value, config]
  9306. );
  9307. return prevValue;
  9308. }
  9309. function rerenderDeferredValue(value, config) {
  9310. var _rerenderState = rerenderState(),
  9311. prevValue = _rerenderState[0],
  9312. setValue = _rerenderState[1];
  9313. updateEffect(
  9314. function() {
  9315. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9316. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9317. try {
  9318. setValue(value);
  9319. } finally {
  9320. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9321. }
  9322. },
  9323. [value, config]
  9324. );
  9325. return prevValue;
  9326. }
  9327. function startTransition(setPending, config, callback) {
  9328. var priorityLevel = getCurrentPriorityLevel();
  9329. runWithPriority(
  9330. priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
  9331. function() {
  9332. setPending(true);
  9333. }
  9334. );
  9335. runWithPriority(
  9336. priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
  9337. function() {
  9338. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9339. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9340. try {
  9341. setPending(false);
  9342. callback();
  9343. } finally {
  9344. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9345. }
  9346. }
  9347. );
  9348. }
  9349. function mountTransition(config) {
  9350. var _mountState2 = mountState(false),
  9351. isPending = _mountState2[0],
  9352. setPending = _mountState2[1];
  9353. var start = mountCallback(startTransition.bind(null, setPending, config), [
  9354. setPending,
  9355. config
  9356. ]);
  9357. return [start, isPending];
  9358. }
  9359. function updateTransition(config) {
  9360. var _updateState2 = updateState(),
  9361. isPending = _updateState2[0],
  9362. setPending = _updateState2[1];
  9363. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9364. setPending,
  9365. config
  9366. ]);
  9367. return [start, isPending];
  9368. }
  9369. function rerenderTransition(config) {
  9370. var _rerenderState2 = rerenderState(),
  9371. isPending = _rerenderState2[0],
  9372. setPending = _rerenderState2[1];
  9373. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9374. setPending,
  9375. config
  9376. ]);
  9377. return [start, isPending];
  9378. }
  9379. function dispatchAction(fiber, queue, action) {
  9380. {
  9381. if (typeof arguments[3] === "function") {
  9382. error(
  9383. "State updates from the useState() and useReducer() Hooks don't support the " +
  9384. "second callback argument. To execute a side effect after " +
  9385. "rendering, declare it in the component body with useEffect()."
  9386. );
  9387. }
  9388. }
  9389. var currentTime = requestCurrentTimeForUpdate();
  9390. var suspenseConfig = requestCurrentSuspenseConfig();
  9391. var expirationTime = computeExpirationForFiber(
  9392. currentTime,
  9393. fiber,
  9394. suspenseConfig
  9395. );
  9396. var update = {
  9397. expirationTime: expirationTime,
  9398. suspenseConfig: suspenseConfig,
  9399. action: action,
  9400. eagerReducer: null,
  9401. eagerState: null,
  9402. next: null
  9403. };
  9404. {
  9405. update.priority = getCurrentPriorityLevel();
  9406. } // Append the update to the end of the list.
  9407. var pending = queue.pending;
  9408. if (pending === null) {
  9409. // This is the first update. Create a circular list.
  9410. update.next = update;
  9411. } else {
  9412. update.next = pending.next;
  9413. pending.next = update;
  9414. }
  9415. queue.pending = update;
  9416. var alternate = fiber.alternate;
  9417. if (
  9418. fiber === currentlyRenderingFiber$1 ||
  9419. (alternate !== null && alternate === currentlyRenderingFiber$1)
  9420. ) {
  9421. // This is a render phase update. Stash it in a lazily-created map of
  9422. // queue -> linked list of updates. After this render pass, we'll restart
  9423. // and apply the stashed updates on top of the work-in-progress hook.
  9424. didScheduleRenderPhaseUpdate = true;
  9425. update.expirationTime = renderExpirationTime;
  9426. currentlyRenderingFiber$1.expirationTime = renderExpirationTime;
  9427. } else {
  9428. if (
  9429. fiber.expirationTime === NoWork &&
  9430. (alternate === null || alternate.expirationTime === NoWork)
  9431. ) {
  9432. // The queue is currently empty, which means we can eagerly compute the
  9433. // next state before entering the render phase. If the new state is the
  9434. // same as the current state, we may be able to bail out entirely.
  9435. var lastRenderedReducer = queue.lastRenderedReducer;
  9436. if (lastRenderedReducer !== null) {
  9437. var prevDispatcher;
  9438. {
  9439. prevDispatcher = ReactCurrentDispatcher.current;
  9440. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9441. }
  9442. try {
  9443. var currentState = queue.lastRenderedState;
  9444. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  9445. // it, on the update object. If the reducer hasn't changed by the
  9446. // time we enter the render phase, then the eager state can be used
  9447. // without calling the reducer again.
  9448. update.eagerReducer = lastRenderedReducer;
  9449. update.eagerState = eagerState;
  9450. if (objectIs(eagerState, currentState)) {
  9451. // Fast path. We can bail out without scheduling React to re-render.
  9452. // It's still possible that we'll need to rebase this update later,
  9453. // if the component re-renders for a different reason and by that
  9454. // time the reducer has changed.
  9455. return;
  9456. }
  9457. } catch (error) {
  9458. // Suppress the error. It will throw again in the render phase.
  9459. } finally {
  9460. {
  9461. ReactCurrentDispatcher.current = prevDispatcher;
  9462. }
  9463. }
  9464. }
  9465. }
  9466. {
  9467. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  9468. if ("undefined" !== typeof jest) {
  9469. warnIfNotScopedWithMatchingAct(fiber);
  9470. warnIfNotCurrentlyActingUpdatesInDev(fiber);
  9471. }
  9472. }
  9473. scheduleWork(fiber, expirationTime);
  9474. }
  9475. }
  9476. function mountEventListener(event) {
  9477. return undefined;
  9478. }
  9479. function updateEventListener(event) {
  9480. return undefined;
  9481. }
  9482. var ContextOnlyDispatcher = {
  9483. readContext: readContext,
  9484. useCallback: throwInvalidHookError,
  9485. useContext: throwInvalidHookError,
  9486. useEffect: throwInvalidHookError,
  9487. useImperativeHandle: throwInvalidHookError,
  9488. useLayoutEffect: throwInvalidHookError,
  9489. useMemo: throwInvalidHookError,
  9490. useReducer: throwInvalidHookError,
  9491. useRef: throwInvalidHookError,
  9492. useState: throwInvalidHookError,
  9493. useDebugValue: throwInvalidHookError,
  9494. useResponder: throwInvalidHookError,
  9495. useDeferredValue: throwInvalidHookError,
  9496. useTransition: throwInvalidHookError,
  9497. useEvent: throwInvalidHookError
  9498. };
  9499. var HooksDispatcherOnMountInDEV = null;
  9500. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  9501. var HooksDispatcherOnUpdateInDEV = null;
  9502. var HooksDispatcherOnRerenderInDEV = null;
  9503. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  9504. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  9505. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  9506. {
  9507. var warnInvalidContextAccess = function() {
  9508. error(
  9509. "Context can only be read while React is rendering. " +
  9510. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  9511. "In function components, you can read it directly in the function body, but not " +
  9512. "inside Hooks like useReducer() or useMemo()."
  9513. );
  9514. };
  9515. var warnInvalidHookAccess = function() {
  9516. error(
  9517. "Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. " +
  9518. "You can only call Hooks at the top level of your React function. " +
  9519. "For more information, see " +
  9520. "https://fb.me/rules-of-hooks"
  9521. );
  9522. };
  9523. HooksDispatcherOnMountInDEV = {
  9524. readContext: function(context, observedBits) {
  9525. return readContext(context, observedBits);
  9526. },
  9527. useCallback: function(callback, deps) {
  9528. currentHookNameInDev = "useCallback";
  9529. mountHookTypesDev();
  9530. checkDepsAreArrayDev(deps);
  9531. return mountCallback(callback, deps);
  9532. },
  9533. useContext: function(context, observedBits) {
  9534. currentHookNameInDev = "useContext";
  9535. mountHookTypesDev();
  9536. return readContext(context, observedBits);
  9537. },
  9538. useEffect: function(create, deps) {
  9539. currentHookNameInDev = "useEffect";
  9540. mountHookTypesDev();
  9541. checkDepsAreArrayDev(deps);
  9542. return mountEffect(create, deps);
  9543. },
  9544. useImperativeHandle: function(ref, create, deps) {
  9545. currentHookNameInDev = "useImperativeHandle";
  9546. mountHookTypesDev();
  9547. checkDepsAreArrayDev(deps);
  9548. return mountImperativeHandle(ref, create, deps);
  9549. },
  9550. useLayoutEffect: function(create, deps) {
  9551. currentHookNameInDev = "useLayoutEffect";
  9552. mountHookTypesDev();
  9553. checkDepsAreArrayDev(deps);
  9554. return mountLayoutEffect(create, deps);
  9555. },
  9556. useMemo: function(create, deps) {
  9557. currentHookNameInDev = "useMemo";
  9558. mountHookTypesDev();
  9559. checkDepsAreArrayDev(deps);
  9560. var prevDispatcher = ReactCurrentDispatcher.current;
  9561. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9562. try {
  9563. return mountMemo(create, deps);
  9564. } finally {
  9565. ReactCurrentDispatcher.current = prevDispatcher;
  9566. }
  9567. },
  9568. useReducer: function(reducer, initialArg, init) {
  9569. currentHookNameInDev = "useReducer";
  9570. mountHookTypesDev();
  9571. var prevDispatcher = ReactCurrentDispatcher.current;
  9572. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9573. try {
  9574. return mountReducer(reducer, initialArg, init);
  9575. } finally {
  9576. ReactCurrentDispatcher.current = prevDispatcher;
  9577. }
  9578. },
  9579. useRef: function(initialValue) {
  9580. currentHookNameInDev = "useRef";
  9581. mountHookTypesDev();
  9582. return mountRef(initialValue);
  9583. },
  9584. useState: function(initialState) {
  9585. currentHookNameInDev = "useState";
  9586. mountHookTypesDev();
  9587. var prevDispatcher = ReactCurrentDispatcher.current;
  9588. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9589. try {
  9590. return mountState(initialState);
  9591. } finally {
  9592. ReactCurrentDispatcher.current = prevDispatcher;
  9593. }
  9594. },
  9595. useDebugValue: function(value, formatterFn) {
  9596. currentHookNameInDev = "useDebugValue";
  9597. mountHookTypesDev();
  9598. return mountDebugValue();
  9599. },
  9600. useResponder: function(responder, props) {
  9601. currentHookNameInDev = "useResponder";
  9602. mountHookTypesDev();
  9603. return createDeprecatedResponderListener(responder, props);
  9604. },
  9605. useDeferredValue: function(value, config) {
  9606. currentHookNameInDev = "useDeferredValue";
  9607. mountHookTypesDev();
  9608. return mountDeferredValue(value, config);
  9609. },
  9610. useTransition: function(config) {
  9611. currentHookNameInDev = "useTransition";
  9612. mountHookTypesDev();
  9613. return mountTransition(config);
  9614. },
  9615. useEvent: function(event) {
  9616. currentHookNameInDev = "useEvent";
  9617. mountHookTypesDev();
  9618. return mountEventListener();
  9619. }
  9620. };
  9621. HooksDispatcherOnMountWithHookTypesInDEV = {
  9622. readContext: function(context, observedBits) {
  9623. return readContext(context, observedBits);
  9624. },
  9625. useCallback: function(callback, deps) {
  9626. currentHookNameInDev = "useCallback";
  9627. updateHookTypesDev();
  9628. return mountCallback(callback, deps);
  9629. },
  9630. useContext: function(context, observedBits) {
  9631. currentHookNameInDev = "useContext";
  9632. updateHookTypesDev();
  9633. return readContext(context, observedBits);
  9634. },
  9635. useEffect: function(create, deps) {
  9636. currentHookNameInDev = "useEffect";
  9637. updateHookTypesDev();
  9638. return mountEffect(create, deps);
  9639. },
  9640. useImperativeHandle: function(ref, create, deps) {
  9641. currentHookNameInDev = "useImperativeHandle";
  9642. updateHookTypesDev();
  9643. return mountImperativeHandle(ref, create, deps);
  9644. },
  9645. useLayoutEffect: function(create, deps) {
  9646. currentHookNameInDev = "useLayoutEffect";
  9647. updateHookTypesDev();
  9648. return mountLayoutEffect(create, deps);
  9649. },
  9650. useMemo: function(create, deps) {
  9651. currentHookNameInDev = "useMemo";
  9652. updateHookTypesDev();
  9653. var prevDispatcher = ReactCurrentDispatcher.current;
  9654. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9655. try {
  9656. return mountMemo(create, deps);
  9657. } finally {
  9658. ReactCurrentDispatcher.current = prevDispatcher;
  9659. }
  9660. },
  9661. useReducer: function(reducer, initialArg, init) {
  9662. currentHookNameInDev = "useReducer";
  9663. updateHookTypesDev();
  9664. var prevDispatcher = ReactCurrentDispatcher.current;
  9665. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9666. try {
  9667. return mountReducer(reducer, initialArg, init);
  9668. } finally {
  9669. ReactCurrentDispatcher.current = prevDispatcher;
  9670. }
  9671. },
  9672. useRef: function(initialValue) {
  9673. currentHookNameInDev = "useRef";
  9674. updateHookTypesDev();
  9675. return mountRef(initialValue);
  9676. },
  9677. useState: function(initialState) {
  9678. currentHookNameInDev = "useState";
  9679. updateHookTypesDev();
  9680. var prevDispatcher = ReactCurrentDispatcher.current;
  9681. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9682. try {
  9683. return mountState(initialState);
  9684. } finally {
  9685. ReactCurrentDispatcher.current = prevDispatcher;
  9686. }
  9687. },
  9688. useDebugValue: function(value, formatterFn) {
  9689. currentHookNameInDev = "useDebugValue";
  9690. updateHookTypesDev();
  9691. return mountDebugValue();
  9692. },
  9693. useResponder: function(responder, props) {
  9694. currentHookNameInDev = "useResponder";
  9695. updateHookTypesDev();
  9696. return createDeprecatedResponderListener(responder, props);
  9697. },
  9698. useDeferredValue: function(value, config) {
  9699. currentHookNameInDev = "useDeferredValue";
  9700. updateHookTypesDev();
  9701. return mountDeferredValue(value, config);
  9702. },
  9703. useTransition: function(config) {
  9704. currentHookNameInDev = "useTransition";
  9705. updateHookTypesDev();
  9706. return mountTransition(config);
  9707. },
  9708. useEvent: function(event) {
  9709. currentHookNameInDev = "useEvent";
  9710. updateHookTypesDev();
  9711. return mountEventListener();
  9712. }
  9713. };
  9714. HooksDispatcherOnUpdateInDEV = {
  9715. readContext: function(context, observedBits) {
  9716. return readContext(context, observedBits);
  9717. },
  9718. useCallback: function(callback, deps) {
  9719. currentHookNameInDev = "useCallback";
  9720. updateHookTypesDev();
  9721. return updateCallback(callback, deps);
  9722. },
  9723. useContext: function(context, observedBits) {
  9724. currentHookNameInDev = "useContext";
  9725. updateHookTypesDev();
  9726. return readContext(context, observedBits);
  9727. },
  9728. useEffect: function(create, deps) {
  9729. currentHookNameInDev = "useEffect";
  9730. updateHookTypesDev();
  9731. return updateEffect(create, deps);
  9732. },
  9733. useImperativeHandle: function(ref, create, deps) {
  9734. currentHookNameInDev = "useImperativeHandle";
  9735. updateHookTypesDev();
  9736. return updateImperativeHandle(ref, create, deps);
  9737. },
  9738. useLayoutEffect: function(create, deps) {
  9739. currentHookNameInDev = "useLayoutEffect";
  9740. updateHookTypesDev();
  9741. return updateLayoutEffect(create, deps);
  9742. },
  9743. useMemo: function(create, deps) {
  9744. currentHookNameInDev = "useMemo";
  9745. updateHookTypesDev();
  9746. var prevDispatcher = ReactCurrentDispatcher.current;
  9747. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9748. try {
  9749. return updateMemo(create, deps);
  9750. } finally {
  9751. ReactCurrentDispatcher.current = prevDispatcher;
  9752. }
  9753. },
  9754. useReducer: function(reducer, initialArg, init) {
  9755. currentHookNameInDev = "useReducer";
  9756. updateHookTypesDev();
  9757. var prevDispatcher = ReactCurrentDispatcher.current;
  9758. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9759. try {
  9760. return updateReducer(reducer, initialArg, init);
  9761. } finally {
  9762. ReactCurrentDispatcher.current = prevDispatcher;
  9763. }
  9764. },
  9765. useRef: function(initialValue) {
  9766. currentHookNameInDev = "useRef";
  9767. updateHookTypesDev();
  9768. return updateRef();
  9769. },
  9770. useState: function(initialState) {
  9771. currentHookNameInDev = "useState";
  9772. updateHookTypesDev();
  9773. var prevDispatcher = ReactCurrentDispatcher.current;
  9774. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9775. try {
  9776. return updateState(initialState);
  9777. } finally {
  9778. ReactCurrentDispatcher.current = prevDispatcher;
  9779. }
  9780. },
  9781. useDebugValue: function(value, formatterFn) {
  9782. currentHookNameInDev = "useDebugValue";
  9783. updateHookTypesDev();
  9784. return updateDebugValue();
  9785. },
  9786. useResponder: function(responder, props) {
  9787. currentHookNameInDev = "useResponder";
  9788. updateHookTypesDev();
  9789. return createDeprecatedResponderListener(responder, props);
  9790. },
  9791. useDeferredValue: function(value, config) {
  9792. currentHookNameInDev = "useDeferredValue";
  9793. updateHookTypesDev();
  9794. return updateDeferredValue(value, config);
  9795. },
  9796. useTransition: function(config) {
  9797. currentHookNameInDev = "useTransition";
  9798. updateHookTypesDev();
  9799. return updateTransition(config);
  9800. },
  9801. useEvent: function(event) {
  9802. currentHookNameInDev = "useEvent";
  9803. updateHookTypesDev();
  9804. return updateEventListener();
  9805. }
  9806. };
  9807. HooksDispatcherOnRerenderInDEV = {
  9808. readContext: function(context, observedBits) {
  9809. return readContext(context, observedBits);
  9810. },
  9811. useCallback: function(callback, deps) {
  9812. currentHookNameInDev = "useCallback";
  9813. updateHookTypesDev();
  9814. return updateCallback(callback, deps);
  9815. },
  9816. useContext: function(context, observedBits) {
  9817. currentHookNameInDev = "useContext";
  9818. updateHookTypesDev();
  9819. return readContext(context, observedBits);
  9820. },
  9821. useEffect: function(create, deps) {
  9822. currentHookNameInDev = "useEffect";
  9823. updateHookTypesDev();
  9824. return updateEffect(create, deps);
  9825. },
  9826. useImperativeHandle: function(ref, create, deps) {
  9827. currentHookNameInDev = "useImperativeHandle";
  9828. updateHookTypesDev();
  9829. return updateImperativeHandle(ref, create, deps);
  9830. },
  9831. useLayoutEffect: function(create, deps) {
  9832. currentHookNameInDev = "useLayoutEffect";
  9833. updateHookTypesDev();
  9834. return updateLayoutEffect(create, deps);
  9835. },
  9836. useMemo: function(create, deps) {
  9837. currentHookNameInDev = "useMemo";
  9838. updateHookTypesDev();
  9839. var prevDispatcher = ReactCurrentDispatcher.current;
  9840. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9841. try {
  9842. return updateMemo(create, deps);
  9843. } finally {
  9844. ReactCurrentDispatcher.current = prevDispatcher;
  9845. }
  9846. },
  9847. useReducer: function(reducer, initialArg, init) {
  9848. currentHookNameInDev = "useReducer";
  9849. updateHookTypesDev();
  9850. var prevDispatcher = ReactCurrentDispatcher.current;
  9851. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9852. try {
  9853. return rerenderReducer(reducer, initialArg, init);
  9854. } finally {
  9855. ReactCurrentDispatcher.current = prevDispatcher;
  9856. }
  9857. },
  9858. useRef: function(initialValue) {
  9859. currentHookNameInDev = "useRef";
  9860. updateHookTypesDev();
  9861. return updateRef();
  9862. },
  9863. useState: function(initialState) {
  9864. currentHookNameInDev = "useState";
  9865. updateHookTypesDev();
  9866. var prevDispatcher = ReactCurrentDispatcher.current;
  9867. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9868. try {
  9869. return rerenderState(initialState);
  9870. } finally {
  9871. ReactCurrentDispatcher.current = prevDispatcher;
  9872. }
  9873. },
  9874. useDebugValue: function(value, formatterFn) {
  9875. currentHookNameInDev = "useDebugValue";
  9876. updateHookTypesDev();
  9877. return updateDebugValue();
  9878. },
  9879. useResponder: function(responder, props) {
  9880. currentHookNameInDev = "useResponder";
  9881. updateHookTypesDev();
  9882. return createDeprecatedResponderListener(responder, props);
  9883. },
  9884. useDeferredValue: function(value, config) {
  9885. currentHookNameInDev = "useDeferredValue";
  9886. updateHookTypesDev();
  9887. return rerenderDeferredValue(value, config);
  9888. },
  9889. useTransition: function(config) {
  9890. currentHookNameInDev = "useTransition";
  9891. updateHookTypesDev();
  9892. return rerenderTransition(config);
  9893. },
  9894. useEvent: function(event) {
  9895. currentHookNameInDev = "useEvent";
  9896. updateHookTypesDev();
  9897. return updateEventListener();
  9898. }
  9899. };
  9900. InvalidNestedHooksDispatcherOnMountInDEV = {
  9901. readContext: function(context, observedBits) {
  9902. warnInvalidContextAccess();
  9903. return readContext(context, observedBits);
  9904. },
  9905. useCallback: function(callback, deps) {
  9906. currentHookNameInDev = "useCallback";
  9907. warnInvalidHookAccess();
  9908. mountHookTypesDev();
  9909. return mountCallback(callback, deps);
  9910. },
  9911. useContext: function(context, observedBits) {
  9912. currentHookNameInDev = "useContext";
  9913. warnInvalidHookAccess();
  9914. mountHookTypesDev();
  9915. return readContext(context, observedBits);
  9916. },
  9917. useEffect: function(create, deps) {
  9918. currentHookNameInDev = "useEffect";
  9919. warnInvalidHookAccess();
  9920. mountHookTypesDev();
  9921. return mountEffect(create, deps);
  9922. },
  9923. useImperativeHandle: function(ref, create, deps) {
  9924. currentHookNameInDev = "useImperativeHandle";
  9925. warnInvalidHookAccess();
  9926. mountHookTypesDev();
  9927. return mountImperativeHandle(ref, create, deps);
  9928. },
  9929. useLayoutEffect: function(create, deps) {
  9930. currentHookNameInDev = "useLayoutEffect";
  9931. warnInvalidHookAccess();
  9932. mountHookTypesDev();
  9933. return mountLayoutEffect(create, deps);
  9934. },
  9935. useMemo: function(create, deps) {
  9936. currentHookNameInDev = "useMemo";
  9937. warnInvalidHookAccess();
  9938. mountHookTypesDev();
  9939. var prevDispatcher = ReactCurrentDispatcher.current;
  9940. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9941. try {
  9942. return mountMemo(create, deps);
  9943. } finally {
  9944. ReactCurrentDispatcher.current = prevDispatcher;
  9945. }
  9946. },
  9947. useReducer: function(reducer, initialArg, init) {
  9948. currentHookNameInDev = "useReducer";
  9949. warnInvalidHookAccess();
  9950. mountHookTypesDev();
  9951. var prevDispatcher = ReactCurrentDispatcher.current;
  9952. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9953. try {
  9954. return mountReducer(reducer, initialArg, init);
  9955. } finally {
  9956. ReactCurrentDispatcher.current = prevDispatcher;
  9957. }
  9958. },
  9959. useRef: function(initialValue) {
  9960. currentHookNameInDev = "useRef";
  9961. warnInvalidHookAccess();
  9962. mountHookTypesDev();
  9963. return mountRef(initialValue);
  9964. },
  9965. useState: function(initialState) {
  9966. currentHookNameInDev = "useState";
  9967. warnInvalidHookAccess();
  9968. mountHookTypesDev();
  9969. var prevDispatcher = ReactCurrentDispatcher.current;
  9970. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9971. try {
  9972. return mountState(initialState);
  9973. } finally {
  9974. ReactCurrentDispatcher.current = prevDispatcher;
  9975. }
  9976. },
  9977. useDebugValue: function(value, formatterFn) {
  9978. currentHookNameInDev = "useDebugValue";
  9979. warnInvalidHookAccess();
  9980. mountHookTypesDev();
  9981. return mountDebugValue();
  9982. },
  9983. useResponder: function(responder, props) {
  9984. currentHookNameInDev = "useResponder";
  9985. warnInvalidHookAccess();
  9986. mountHookTypesDev();
  9987. return createDeprecatedResponderListener(responder, props);
  9988. },
  9989. useDeferredValue: function(value, config) {
  9990. currentHookNameInDev = "useDeferredValue";
  9991. warnInvalidHookAccess();
  9992. mountHookTypesDev();
  9993. return mountDeferredValue(value, config);
  9994. },
  9995. useTransition: function(config) {
  9996. currentHookNameInDev = "useTransition";
  9997. warnInvalidHookAccess();
  9998. mountHookTypesDev();
  9999. return mountTransition(config);
  10000. },
  10001. useEvent: function(event) {
  10002. currentHookNameInDev = "useEvent";
  10003. warnInvalidHookAccess();
  10004. mountHookTypesDev();
  10005. return mountEventListener();
  10006. }
  10007. };
  10008. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  10009. readContext: function(context, observedBits) {
  10010. warnInvalidContextAccess();
  10011. return readContext(context, observedBits);
  10012. },
  10013. useCallback: function(callback, deps) {
  10014. currentHookNameInDev = "useCallback";
  10015. warnInvalidHookAccess();
  10016. updateHookTypesDev();
  10017. return updateCallback(callback, deps);
  10018. },
  10019. useContext: function(context, observedBits) {
  10020. currentHookNameInDev = "useContext";
  10021. warnInvalidHookAccess();
  10022. updateHookTypesDev();
  10023. return readContext(context, observedBits);
  10024. },
  10025. useEffect: function(create, deps) {
  10026. currentHookNameInDev = "useEffect";
  10027. warnInvalidHookAccess();
  10028. updateHookTypesDev();
  10029. return updateEffect(create, deps);
  10030. },
  10031. useImperativeHandle: function(ref, create, deps) {
  10032. currentHookNameInDev = "useImperativeHandle";
  10033. warnInvalidHookAccess();
  10034. updateHookTypesDev();
  10035. return updateImperativeHandle(ref, create, deps);
  10036. },
  10037. useLayoutEffect: function(create, deps) {
  10038. currentHookNameInDev = "useLayoutEffect";
  10039. warnInvalidHookAccess();
  10040. updateHookTypesDev();
  10041. return updateLayoutEffect(create, deps);
  10042. },
  10043. useMemo: function(create, deps) {
  10044. currentHookNameInDev = "useMemo";
  10045. warnInvalidHookAccess();
  10046. updateHookTypesDev();
  10047. var prevDispatcher = ReactCurrentDispatcher.current;
  10048. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10049. try {
  10050. return updateMemo(create, deps);
  10051. } finally {
  10052. ReactCurrentDispatcher.current = prevDispatcher;
  10053. }
  10054. },
  10055. useReducer: function(reducer, initialArg, init) {
  10056. currentHookNameInDev = "useReducer";
  10057. warnInvalidHookAccess();
  10058. updateHookTypesDev();
  10059. var prevDispatcher = ReactCurrentDispatcher.current;
  10060. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10061. try {
  10062. return updateReducer(reducer, initialArg, init);
  10063. } finally {
  10064. ReactCurrentDispatcher.current = prevDispatcher;
  10065. }
  10066. },
  10067. useRef: function(initialValue) {
  10068. currentHookNameInDev = "useRef";
  10069. warnInvalidHookAccess();
  10070. updateHookTypesDev();
  10071. return updateRef();
  10072. },
  10073. useState: function(initialState) {
  10074. currentHookNameInDev = "useState";
  10075. warnInvalidHookAccess();
  10076. updateHookTypesDev();
  10077. var prevDispatcher = ReactCurrentDispatcher.current;
  10078. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10079. try {
  10080. return updateState(initialState);
  10081. } finally {
  10082. ReactCurrentDispatcher.current = prevDispatcher;
  10083. }
  10084. },
  10085. useDebugValue: function(value, formatterFn) {
  10086. currentHookNameInDev = "useDebugValue";
  10087. warnInvalidHookAccess();
  10088. updateHookTypesDev();
  10089. return updateDebugValue();
  10090. },
  10091. useResponder: function(responder, props) {
  10092. currentHookNameInDev = "useResponder";
  10093. warnInvalidHookAccess();
  10094. updateHookTypesDev();
  10095. return createDeprecatedResponderListener(responder, props);
  10096. },
  10097. useDeferredValue: function(value, config) {
  10098. currentHookNameInDev = "useDeferredValue";
  10099. warnInvalidHookAccess();
  10100. updateHookTypesDev();
  10101. return updateDeferredValue(value, config);
  10102. },
  10103. useTransition: function(config) {
  10104. currentHookNameInDev = "useTransition";
  10105. warnInvalidHookAccess();
  10106. updateHookTypesDev();
  10107. return updateTransition(config);
  10108. },
  10109. useEvent: function(event) {
  10110. currentHookNameInDev = "useEvent";
  10111. warnInvalidHookAccess();
  10112. updateHookTypesDev();
  10113. return updateEventListener();
  10114. }
  10115. };
  10116. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  10117. readContext: function(context, observedBits) {
  10118. warnInvalidContextAccess();
  10119. return readContext(context, observedBits);
  10120. },
  10121. useCallback: function(callback, deps) {
  10122. currentHookNameInDev = "useCallback";
  10123. warnInvalidHookAccess();
  10124. updateHookTypesDev();
  10125. return updateCallback(callback, deps);
  10126. },
  10127. useContext: function(context, observedBits) {
  10128. currentHookNameInDev = "useContext";
  10129. warnInvalidHookAccess();
  10130. updateHookTypesDev();
  10131. return readContext(context, observedBits);
  10132. },
  10133. useEffect: function(create, deps) {
  10134. currentHookNameInDev = "useEffect";
  10135. warnInvalidHookAccess();
  10136. updateHookTypesDev();
  10137. return updateEffect(create, deps);
  10138. },
  10139. useImperativeHandle: function(ref, create, deps) {
  10140. currentHookNameInDev = "useImperativeHandle";
  10141. warnInvalidHookAccess();
  10142. updateHookTypesDev();
  10143. return updateImperativeHandle(ref, create, deps);
  10144. },
  10145. useLayoutEffect: function(create, deps) {
  10146. currentHookNameInDev = "useLayoutEffect";
  10147. warnInvalidHookAccess();
  10148. updateHookTypesDev();
  10149. return updateLayoutEffect(create, deps);
  10150. },
  10151. useMemo: function(create, deps) {
  10152. currentHookNameInDev = "useMemo";
  10153. warnInvalidHookAccess();
  10154. updateHookTypesDev();
  10155. var prevDispatcher = ReactCurrentDispatcher.current;
  10156. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10157. try {
  10158. return updateMemo(create, deps);
  10159. } finally {
  10160. ReactCurrentDispatcher.current = prevDispatcher;
  10161. }
  10162. },
  10163. useReducer: function(reducer, initialArg, init) {
  10164. currentHookNameInDev = "useReducer";
  10165. warnInvalidHookAccess();
  10166. updateHookTypesDev();
  10167. var prevDispatcher = ReactCurrentDispatcher.current;
  10168. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10169. try {
  10170. return rerenderReducer(reducer, initialArg, init);
  10171. } finally {
  10172. ReactCurrentDispatcher.current = prevDispatcher;
  10173. }
  10174. },
  10175. useRef: function(initialValue) {
  10176. currentHookNameInDev = "useRef";
  10177. warnInvalidHookAccess();
  10178. updateHookTypesDev();
  10179. return updateRef();
  10180. },
  10181. useState: function(initialState) {
  10182. currentHookNameInDev = "useState";
  10183. warnInvalidHookAccess();
  10184. updateHookTypesDev();
  10185. var prevDispatcher = ReactCurrentDispatcher.current;
  10186. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10187. try {
  10188. return rerenderState(initialState);
  10189. } finally {
  10190. ReactCurrentDispatcher.current = prevDispatcher;
  10191. }
  10192. },
  10193. useDebugValue: function(value, formatterFn) {
  10194. currentHookNameInDev = "useDebugValue";
  10195. warnInvalidHookAccess();
  10196. updateHookTypesDev();
  10197. return updateDebugValue();
  10198. },
  10199. useResponder: function(responder, props) {
  10200. currentHookNameInDev = "useResponder";
  10201. warnInvalidHookAccess();
  10202. updateHookTypesDev();
  10203. return createDeprecatedResponderListener(responder, props);
  10204. },
  10205. useDeferredValue: function(value, config) {
  10206. currentHookNameInDev = "useDeferredValue";
  10207. warnInvalidHookAccess();
  10208. updateHookTypesDev();
  10209. return rerenderDeferredValue(value, config);
  10210. },
  10211. useTransition: function(config) {
  10212. currentHookNameInDev = "useTransition";
  10213. warnInvalidHookAccess();
  10214. updateHookTypesDev();
  10215. return rerenderTransition(config);
  10216. },
  10217. useEvent: function(event) {
  10218. currentHookNameInDev = "useEvent";
  10219. warnInvalidHookAccess();
  10220. updateHookTypesDev();
  10221. return updateEventListener();
  10222. }
  10223. };
  10224. }
  10225. var now$1 = Scheduler.unstable_now;
  10226. var commitTime = 0;
  10227. var profilerStartTime = -1;
  10228. function getCommitTime() {
  10229. return commitTime;
  10230. }
  10231. function recordCommitTime() {
  10232. commitTime = now$1();
  10233. }
  10234. function startProfilerTimer(fiber) {
  10235. profilerStartTime = now$1();
  10236. if (fiber.actualStartTime < 0) {
  10237. fiber.actualStartTime = now$1();
  10238. }
  10239. }
  10240. function stopProfilerTimerIfRunning(fiber) {
  10241. profilerStartTime = -1;
  10242. }
  10243. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  10244. if (profilerStartTime >= 0) {
  10245. var elapsedTime = now$1() - profilerStartTime;
  10246. fiber.actualDuration += elapsedTime;
  10247. if (overrideBaseTime) {
  10248. fiber.selfBaseDuration = elapsedTime;
  10249. }
  10250. profilerStartTime = -1;
  10251. }
  10252. }
  10253. function enterHydrationState(fiber) {
  10254. {
  10255. return false;
  10256. }
  10257. }
  10258. function prepareToHydrateHostInstance(
  10259. fiber,
  10260. rootContainerInstance,
  10261. hostContext
  10262. ) {
  10263. {
  10264. {
  10265. throw Error(
  10266. "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  10267. );
  10268. }
  10269. }
  10270. }
  10271. function prepareToHydrateHostTextInstance(fiber) {
  10272. {
  10273. {
  10274. throw Error(
  10275. "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  10276. );
  10277. }
  10278. }
  10279. var shouldUpdate = hydrateTextInstance();
  10280. }
  10281. function popHydrationState(fiber) {
  10282. {
  10283. return false;
  10284. }
  10285. }
  10286. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  10287. var didReceiveUpdate = false;
  10288. var didWarnAboutBadClass;
  10289. var didWarnAboutModulePatternComponent;
  10290. var didWarnAboutContextTypeOnFunctionComponent;
  10291. var didWarnAboutGetDerivedStateOnFunctionComponent;
  10292. var didWarnAboutFunctionRefs;
  10293. var didWarnAboutReassigningProps;
  10294. var didWarnAboutRevealOrder;
  10295. var didWarnAboutTailOptions;
  10296. {
  10297. didWarnAboutBadClass = {};
  10298. didWarnAboutModulePatternComponent = {};
  10299. didWarnAboutContextTypeOnFunctionComponent = {};
  10300. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  10301. didWarnAboutFunctionRefs = {};
  10302. didWarnAboutReassigningProps = false;
  10303. didWarnAboutRevealOrder = {};
  10304. didWarnAboutTailOptions = {};
  10305. }
  10306. function reconcileChildren(
  10307. current,
  10308. workInProgress,
  10309. nextChildren,
  10310. renderExpirationTime
  10311. ) {
  10312. if (current === null) {
  10313. // If this is a fresh new component that hasn't been rendered yet, we
  10314. // won't update its child set by applying minimal side-effects. Instead,
  10315. // we will add them all to the child before it gets rendered. That means
  10316. // we can optimize this reconciliation pass by not tracking side-effects.
  10317. workInProgress.child = mountChildFibers(
  10318. workInProgress,
  10319. null,
  10320. nextChildren,
  10321. renderExpirationTime
  10322. );
  10323. } else {
  10324. // If the current child is the same as the work in progress, it means that
  10325. // we haven't yet started any work on these children. Therefore, we use
  10326. // the clone algorithm to create a copy of all the current children.
  10327. // If we had any progressed work already, that is invalid at this point so
  10328. // let's throw it out.
  10329. workInProgress.child = reconcileChildFibers(
  10330. workInProgress,
  10331. current.child,
  10332. nextChildren,
  10333. renderExpirationTime
  10334. );
  10335. }
  10336. }
  10337. function forceUnmountCurrentAndReconcile(
  10338. current,
  10339. workInProgress,
  10340. nextChildren,
  10341. renderExpirationTime
  10342. ) {
  10343. // This function is fork of reconcileChildren. It's used in cases where we
  10344. // want to reconcile without matching against the existing set. This has the
  10345. // effect of all current children being unmounted; even if the type and key
  10346. // are the same, the old child is unmounted and a new child is created.
  10347. //
  10348. // To do this, we're going to go through the reconcile algorithm twice. In
  10349. // the first pass, we schedule a deletion for all the current children by
  10350. // passing null.
  10351. workInProgress.child = reconcileChildFibers(
  10352. workInProgress,
  10353. current.child,
  10354. null,
  10355. renderExpirationTime
  10356. ); // In the second pass, we mount the new children. The trick here is that we
  10357. // pass null in place of where we usually pass the current child set. This has
  10358. // the effect of remounting all children regardless of whether their
  10359. // identities match.
  10360. workInProgress.child = reconcileChildFibers(
  10361. workInProgress,
  10362. null,
  10363. nextChildren,
  10364. renderExpirationTime
  10365. );
  10366. }
  10367. function updateForwardRef(
  10368. current,
  10369. workInProgress,
  10370. Component,
  10371. nextProps,
  10372. renderExpirationTime
  10373. ) {
  10374. // TODO: current can be non-null here even if the component
  10375. // hasn't yet mounted. This happens after the first render suspends.
  10376. // We'll need to figure out if this is fine or can cause issues.
  10377. {
  10378. if (workInProgress.type !== workInProgress.elementType) {
  10379. // Lazy component props can't be validated in createElement
  10380. // because they're only guaranteed to be resolved here.
  10381. var innerPropTypes = Component.propTypes;
  10382. if (innerPropTypes) {
  10383. checkPropTypes(
  10384. innerPropTypes,
  10385. nextProps, // Resolved props
  10386. "prop",
  10387. getComponentName(Component)
  10388. );
  10389. }
  10390. }
  10391. }
  10392. var render = Component.render;
  10393. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  10394. var nextChildren;
  10395. prepareToReadContext(workInProgress, renderExpirationTime);
  10396. {
  10397. ReactCurrentOwner$1.current = workInProgress;
  10398. setIsRendering(true);
  10399. nextChildren = renderWithHooks(
  10400. current,
  10401. workInProgress,
  10402. render,
  10403. nextProps,
  10404. ref,
  10405. renderExpirationTime
  10406. );
  10407. if (workInProgress.mode & StrictMode) {
  10408. // Only double-render components with Hooks
  10409. if (workInProgress.memoizedState !== null) {
  10410. nextChildren = renderWithHooks(
  10411. current,
  10412. workInProgress,
  10413. render,
  10414. nextProps,
  10415. ref,
  10416. renderExpirationTime
  10417. );
  10418. }
  10419. }
  10420. setIsRendering(false);
  10421. }
  10422. if (current !== null && !didReceiveUpdate) {
  10423. bailoutHooks(current, workInProgress, renderExpirationTime);
  10424. return bailoutOnAlreadyFinishedWork(
  10425. current,
  10426. workInProgress,
  10427. renderExpirationTime
  10428. );
  10429. } // React DevTools reads this flag.
  10430. workInProgress.effectTag |= PerformedWork;
  10431. reconcileChildren(
  10432. current,
  10433. workInProgress,
  10434. nextChildren,
  10435. renderExpirationTime
  10436. );
  10437. return workInProgress.child;
  10438. }
  10439. function updateMemoComponent(
  10440. current,
  10441. workInProgress,
  10442. Component,
  10443. nextProps,
  10444. updateExpirationTime,
  10445. renderExpirationTime
  10446. ) {
  10447. if (current === null) {
  10448. var type = Component.type;
  10449. if (
  10450. isSimpleFunctionComponent(type) &&
  10451. Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  10452. Component.defaultProps === undefined
  10453. ) {
  10454. var resolvedType = type;
  10455. {
  10456. resolvedType = resolveFunctionForHotReloading(type);
  10457. } // If this is a plain function component without default props,
  10458. // and with only the default shallow comparison, we upgrade it
  10459. // to a SimpleMemoComponent to allow fast path updates.
  10460. workInProgress.tag = SimpleMemoComponent;
  10461. workInProgress.type = resolvedType;
  10462. {
  10463. validateFunctionComponentInDev(workInProgress, type);
  10464. }
  10465. return updateSimpleMemoComponent(
  10466. current,
  10467. workInProgress,
  10468. resolvedType,
  10469. nextProps,
  10470. updateExpirationTime,
  10471. renderExpirationTime
  10472. );
  10473. }
  10474. {
  10475. var innerPropTypes = type.propTypes;
  10476. if (innerPropTypes) {
  10477. // Inner memo component props aren't currently validated in createElement.
  10478. // We could move it there, but we'd still need this for lazy code path.
  10479. checkPropTypes(
  10480. innerPropTypes,
  10481. nextProps, // Resolved props
  10482. "prop",
  10483. getComponentName(type)
  10484. );
  10485. }
  10486. }
  10487. var child = createFiberFromTypeAndProps(
  10488. Component.type,
  10489. null,
  10490. nextProps,
  10491. null,
  10492. workInProgress.mode,
  10493. renderExpirationTime
  10494. );
  10495. child.ref = workInProgress.ref;
  10496. child.return = workInProgress;
  10497. workInProgress.child = child;
  10498. return child;
  10499. }
  10500. {
  10501. var _type = Component.type;
  10502. var _innerPropTypes = _type.propTypes;
  10503. if (_innerPropTypes) {
  10504. // Inner memo component props aren't currently validated in createElement.
  10505. // We could move it there, but we'd still need this for lazy code path.
  10506. checkPropTypes(
  10507. _innerPropTypes,
  10508. nextProps, // Resolved props
  10509. "prop",
  10510. getComponentName(_type)
  10511. );
  10512. }
  10513. }
  10514. var currentChild = current.child; // This is always exactly one child
  10515. if (updateExpirationTime < renderExpirationTime) {
  10516. // This will be the props with resolved defaultProps,
  10517. // unlike current.memoizedProps which will be the unresolved ones.
  10518. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  10519. var compare = Component.compare;
  10520. compare = compare !== null ? compare : shallowEqual;
  10521. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  10522. return bailoutOnAlreadyFinishedWork(
  10523. current,
  10524. workInProgress,
  10525. renderExpirationTime
  10526. );
  10527. }
  10528. } // React DevTools reads this flag.
  10529. workInProgress.effectTag |= PerformedWork;
  10530. var newChild = createWorkInProgress(currentChild, nextProps);
  10531. newChild.ref = workInProgress.ref;
  10532. newChild.return = workInProgress;
  10533. workInProgress.child = newChild;
  10534. return newChild;
  10535. }
  10536. function updateSimpleMemoComponent(
  10537. current,
  10538. workInProgress,
  10539. Component,
  10540. nextProps,
  10541. updateExpirationTime,
  10542. renderExpirationTime
  10543. ) {
  10544. // TODO: current can be non-null here even if the component
  10545. // hasn't yet mounted. This happens when the inner render suspends.
  10546. // We'll need to figure out if this is fine or can cause issues.
  10547. {
  10548. if (workInProgress.type !== workInProgress.elementType) {
  10549. // Lazy component props can't be validated in createElement
  10550. // because they're only guaranteed to be resolved here.
  10551. var outerMemoType = workInProgress.elementType;
  10552. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  10553. // We warn when you define propTypes on lazy()
  10554. // so let's just skip over it to find memo() outer wrapper.
  10555. // Inner props for memo are validated later.
  10556. outerMemoType = refineResolvedLazyComponent(outerMemoType);
  10557. }
  10558. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  10559. if (outerPropTypes) {
  10560. checkPropTypes(
  10561. outerPropTypes,
  10562. nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  10563. "prop",
  10564. getComponentName(outerMemoType)
  10565. );
  10566. } // Inner propTypes will be validated in the function component path.
  10567. }
  10568. }
  10569. if (current !== null) {
  10570. var prevProps = current.memoizedProps;
  10571. if (
  10572. shallowEqual(prevProps, nextProps) &&
  10573. current.ref === workInProgress.ref && // Prevent bailout if the implementation changed due to hot reload.
  10574. workInProgress.type === current.type
  10575. ) {
  10576. didReceiveUpdate = false;
  10577. if (updateExpirationTime < renderExpirationTime) {
  10578. // The pending update priority was cleared at the beginning of
  10579. // beginWork. We're about to bail out, but there might be additional
  10580. // updates at a lower priority. Usually, the priority level of the
  10581. // remaining updates is accumlated during the evaluation of the
  10582. // component (i.e. when processing the update queue). But since since
  10583. // we're bailing out early *without* evaluating the component, we need
  10584. // to account for it here, too. Reset to the value of the current fiber.
  10585. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  10586. // because a MemoComponent fiber does not have hooks or an update queue;
  10587. // rather, it wraps around an inner component, which may or may not
  10588. // contains hooks.
  10589. // TODO: Move the reset at in beginWork out of the common path so that
  10590. // this is no longer necessary.
  10591. workInProgress.expirationTime = current.expirationTime;
  10592. return bailoutOnAlreadyFinishedWork(
  10593. current,
  10594. workInProgress,
  10595. renderExpirationTime
  10596. );
  10597. }
  10598. }
  10599. }
  10600. return updateFunctionComponent(
  10601. current,
  10602. workInProgress,
  10603. Component,
  10604. nextProps,
  10605. renderExpirationTime
  10606. );
  10607. }
  10608. function updateFragment(current, workInProgress, renderExpirationTime) {
  10609. var nextChildren = workInProgress.pendingProps;
  10610. reconcileChildren(
  10611. current,
  10612. workInProgress,
  10613. nextChildren,
  10614. renderExpirationTime
  10615. );
  10616. return workInProgress.child;
  10617. }
  10618. function updateMode(current, workInProgress, renderExpirationTime) {
  10619. var nextChildren = workInProgress.pendingProps.children;
  10620. reconcileChildren(
  10621. current,
  10622. workInProgress,
  10623. nextChildren,
  10624. renderExpirationTime
  10625. );
  10626. return workInProgress.child;
  10627. }
  10628. function updateProfiler(current, workInProgress, renderExpirationTime) {
  10629. {
  10630. workInProgress.effectTag |= Update; // Reset effect durations for the next eventual effect phase.
  10631. // These are reset during render to allow the DevTools commit hook a chance to read them,
  10632. var stateNode = workInProgress.stateNode;
  10633. stateNode.effectDuration = 0;
  10634. stateNode.passiveEffectDuration = 0;
  10635. }
  10636. var nextProps = workInProgress.pendingProps;
  10637. var nextChildren = nextProps.children;
  10638. reconcileChildren(
  10639. current,
  10640. workInProgress,
  10641. nextChildren,
  10642. renderExpirationTime
  10643. );
  10644. return workInProgress.child;
  10645. }
  10646. function markRef(current, workInProgress) {
  10647. var ref = workInProgress.ref;
  10648. if (
  10649. (current === null && ref !== null) ||
  10650. (current !== null && current.ref !== ref)
  10651. ) {
  10652. // Schedule a Ref effect
  10653. workInProgress.effectTag |= Ref;
  10654. }
  10655. }
  10656. function updateFunctionComponent(
  10657. current,
  10658. workInProgress,
  10659. Component,
  10660. nextProps,
  10661. renderExpirationTime
  10662. ) {
  10663. {
  10664. if (workInProgress.type !== workInProgress.elementType) {
  10665. // Lazy component props can't be validated in createElement
  10666. // because they're only guaranteed to be resolved here.
  10667. var innerPropTypes = Component.propTypes;
  10668. if (innerPropTypes) {
  10669. checkPropTypes(
  10670. innerPropTypes,
  10671. nextProps, // Resolved props
  10672. "prop",
  10673. getComponentName(Component)
  10674. );
  10675. }
  10676. }
  10677. }
  10678. var context;
  10679. {
  10680. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  10681. context = getMaskedContext(workInProgress, unmaskedContext);
  10682. }
  10683. var nextChildren;
  10684. prepareToReadContext(workInProgress, renderExpirationTime);
  10685. {
  10686. ReactCurrentOwner$1.current = workInProgress;
  10687. setIsRendering(true);
  10688. nextChildren = renderWithHooks(
  10689. current,
  10690. workInProgress,
  10691. Component,
  10692. nextProps,
  10693. context,
  10694. renderExpirationTime
  10695. );
  10696. if (workInProgress.mode & StrictMode) {
  10697. // Only double-render components with Hooks
  10698. if (workInProgress.memoizedState !== null) {
  10699. nextChildren = renderWithHooks(
  10700. current,
  10701. workInProgress,
  10702. Component,
  10703. nextProps,
  10704. context,
  10705. renderExpirationTime
  10706. );
  10707. }
  10708. }
  10709. setIsRendering(false);
  10710. }
  10711. if (current !== null && !didReceiveUpdate) {
  10712. bailoutHooks(current, workInProgress, renderExpirationTime);
  10713. return bailoutOnAlreadyFinishedWork(
  10714. current,
  10715. workInProgress,
  10716. renderExpirationTime
  10717. );
  10718. } // React DevTools reads this flag.
  10719. workInProgress.effectTag |= PerformedWork;
  10720. reconcileChildren(
  10721. current,
  10722. workInProgress,
  10723. nextChildren,
  10724. renderExpirationTime
  10725. );
  10726. return workInProgress.child;
  10727. }
  10728. function updateClassComponent(
  10729. current,
  10730. workInProgress,
  10731. Component,
  10732. nextProps,
  10733. renderExpirationTime
  10734. ) {
  10735. {
  10736. if (workInProgress.type !== workInProgress.elementType) {
  10737. // Lazy component props can't be validated in createElement
  10738. // because they're only guaranteed to be resolved here.
  10739. var innerPropTypes = Component.propTypes;
  10740. if (innerPropTypes) {
  10741. checkPropTypes(
  10742. innerPropTypes,
  10743. nextProps, // Resolved props
  10744. "prop",
  10745. getComponentName(Component)
  10746. );
  10747. }
  10748. }
  10749. } // Push context providers early to prevent context stack mismatches.
  10750. // During mounting we don't know the child context yet as the instance doesn't exist.
  10751. // We will invalidate the child context in finishClassComponent() right after rendering.
  10752. var hasContext;
  10753. if (isContextProvider(Component)) {
  10754. hasContext = true;
  10755. pushContextProvider(workInProgress);
  10756. } else {
  10757. hasContext = false;
  10758. }
  10759. prepareToReadContext(workInProgress, renderExpirationTime);
  10760. var instance = workInProgress.stateNode;
  10761. var shouldUpdate;
  10762. if (instance === null) {
  10763. if (current !== null) {
  10764. // A class component without an instance only mounts if it suspended
  10765. // inside a non-concurrent tree, in an inconsistent state. We want to
  10766. // treat it like a new mount, even though an empty version of it already
  10767. // committed. Disconnect the alternate pointers.
  10768. current.alternate = null;
  10769. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10770. workInProgress.effectTag |= Placement;
  10771. } // In the initial pass we might need to construct the instance.
  10772. constructClassInstance(workInProgress, Component, nextProps);
  10773. mountClassInstance(
  10774. workInProgress,
  10775. Component,
  10776. nextProps,
  10777. renderExpirationTime
  10778. );
  10779. shouldUpdate = true;
  10780. } else if (current === null) {
  10781. // In a resume, we'll already have an instance we can reuse.
  10782. shouldUpdate = resumeMountClassInstance(
  10783. workInProgress,
  10784. Component,
  10785. nextProps,
  10786. renderExpirationTime
  10787. );
  10788. } else {
  10789. shouldUpdate = updateClassInstance(
  10790. current,
  10791. workInProgress,
  10792. Component,
  10793. nextProps,
  10794. renderExpirationTime
  10795. );
  10796. }
  10797. var nextUnitOfWork = finishClassComponent(
  10798. current,
  10799. workInProgress,
  10800. Component,
  10801. shouldUpdate,
  10802. hasContext,
  10803. renderExpirationTime
  10804. );
  10805. {
  10806. var inst = workInProgress.stateNode;
  10807. if (inst.props !== nextProps) {
  10808. if (!didWarnAboutReassigningProps) {
  10809. error(
  10810. "It looks like %s is reassigning its own `this.props` while rendering. " +
  10811. "This is not supported and can lead to confusing bugs.",
  10812. getComponentName(workInProgress.type) || "a component"
  10813. );
  10814. }
  10815. didWarnAboutReassigningProps = true;
  10816. }
  10817. }
  10818. return nextUnitOfWork;
  10819. }
  10820. function finishClassComponent(
  10821. current,
  10822. workInProgress,
  10823. Component,
  10824. shouldUpdate,
  10825. hasContext,
  10826. renderExpirationTime
  10827. ) {
  10828. // Refs should update even if shouldComponentUpdate returns false
  10829. markRef(current, workInProgress);
  10830. var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
  10831. if (!shouldUpdate && !didCaptureError) {
  10832. // Context providers should defer to sCU for rendering
  10833. if (hasContext) {
  10834. invalidateContextProvider(workInProgress, Component, false);
  10835. }
  10836. return bailoutOnAlreadyFinishedWork(
  10837. current,
  10838. workInProgress,
  10839. renderExpirationTime
  10840. );
  10841. }
  10842. var instance = workInProgress.stateNode; // Rerender
  10843. ReactCurrentOwner$1.current = workInProgress;
  10844. var nextChildren;
  10845. if (
  10846. didCaptureError &&
  10847. typeof Component.getDerivedStateFromError !== "function"
  10848. ) {
  10849. // If we captured an error, but getDerivedStateFromError is not defined,
  10850. // unmount all the children. componentDidCatch will schedule an update to
  10851. // re-render a fallback. This is temporary until we migrate everyone to
  10852. // the new API.
  10853. // TODO: Warn in a future release.
  10854. nextChildren = null;
  10855. {
  10856. stopProfilerTimerIfRunning();
  10857. }
  10858. } else {
  10859. {
  10860. setIsRendering(true);
  10861. nextChildren = instance.render();
  10862. if (workInProgress.mode & StrictMode) {
  10863. instance.render();
  10864. }
  10865. setIsRendering(false);
  10866. }
  10867. } // React DevTools reads this flag.
  10868. workInProgress.effectTag |= PerformedWork;
  10869. if (current !== null && didCaptureError) {
  10870. // If we're recovering from an error, reconcile without reusing any of
  10871. // the existing children. Conceptually, the normal children and the children
  10872. // that are shown on error are two different sets, so we shouldn't reuse
  10873. // normal children even if their identities match.
  10874. forceUnmountCurrentAndReconcile(
  10875. current,
  10876. workInProgress,
  10877. nextChildren,
  10878. renderExpirationTime
  10879. );
  10880. } else {
  10881. reconcileChildren(
  10882. current,
  10883. workInProgress,
  10884. nextChildren,
  10885. renderExpirationTime
  10886. );
  10887. } // Memoize state using the values we just used to render.
  10888. // TODO: Restructure so we never read values from the instance.
  10889. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  10890. if (hasContext) {
  10891. invalidateContextProvider(workInProgress, Component, true);
  10892. }
  10893. return workInProgress.child;
  10894. }
  10895. function pushHostRootContext(workInProgress) {
  10896. var root = workInProgress.stateNode;
  10897. if (root.pendingContext) {
  10898. pushTopLevelContextObject(
  10899. workInProgress,
  10900. root.pendingContext,
  10901. root.pendingContext !== root.context
  10902. );
  10903. } else if (root.context) {
  10904. // Should always be set
  10905. pushTopLevelContextObject(workInProgress, root.context, false);
  10906. }
  10907. pushHostContainer(workInProgress, root.containerInfo);
  10908. }
  10909. function updateHostRoot(current, workInProgress, renderExpirationTime) {
  10910. pushHostRootContext(workInProgress);
  10911. var updateQueue = workInProgress.updateQueue;
  10912. if (!(current !== null && updateQueue !== null)) {
  10913. throw Error(
  10914. "If the root does not have an updateQueue, we should have already bailed out. This error is likely caused by a bug in React. Please file an issue."
  10915. );
  10916. }
  10917. var nextProps = workInProgress.pendingProps;
  10918. var prevState = workInProgress.memoizedState;
  10919. var prevChildren = prevState !== null ? prevState.element : null;
  10920. cloneUpdateQueue(current, workInProgress);
  10921. processUpdateQueue(workInProgress, nextProps, null, renderExpirationTime);
  10922. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  10923. // being called "element".
  10924. var nextChildren = nextState.element;
  10925. if (nextChildren === prevChildren) {
  10926. return bailoutOnAlreadyFinishedWork(
  10927. current,
  10928. workInProgress,
  10929. renderExpirationTime
  10930. );
  10931. }
  10932. var root = workInProgress.stateNode;
  10933. if (root.hydrate && enterHydrationState()) {
  10934. // If we don't have any current children this might be the first pass.
  10935. // We always try to hydrate. If this isn't a hydration pass there won't
  10936. // be any children to hydrate which is effectively the same thing as
  10937. // not hydrating.
  10938. var child = mountChildFibers(
  10939. workInProgress,
  10940. null,
  10941. nextChildren,
  10942. renderExpirationTime
  10943. );
  10944. workInProgress.child = child;
  10945. var node = child;
  10946. while (node) {
  10947. // Mark each child as hydrating. This is a fast path to know whether this
  10948. // tree is part of a hydrating tree. This is used to determine if a child
  10949. // node has fully mounted yet, and for scheduling event replaying.
  10950. // Conceptually this is similar to Placement in that a new subtree is
  10951. // inserted into the React tree here. It just happens to not need DOM
  10952. // mutations because it already exists.
  10953. node.effectTag = (node.effectTag & ~Placement) | Hydrating;
  10954. node = node.sibling;
  10955. }
  10956. } else {
  10957. // Otherwise reset hydration state in case we aborted and resumed another
  10958. // root.
  10959. reconcileChildren(
  10960. current,
  10961. workInProgress,
  10962. nextChildren,
  10963. renderExpirationTime
  10964. );
  10965. }
  10966. return workInProgress.child;
  10967. }
  10968. function updateHostComponent(current, workInProgress, renderExpirationTime) {
  10969. pushHostContext(workInProgress);
  10970. var type = workInProgress.type;
  10971. var nextProps = workInProgress.pendingProps;
  10972. var prevProps = current !== null ? current.memoizedProps : null;
  10973. var nextChildren = nextProps.children;
  10974. if (prevProps !== null && shouldSetTextContent()) {
  10975. // If we're switching from a direct text child to a normal child, or to
  10976. // empty, we need to schedule the text content to be reset.
  10977. workInProgress.effectTag |= ContentReset;
  10978. }
  10979. markRef(current, workInProgress); // Check the host config to see if the children are offscreen/hidden.
  10980. if (
  10981. workInProgress.mode & ConcurrentMode &&
  10982. renderExpirationTime !== Never &&
  10983. shouldDeprioritizeSubtree()
  10984. ) {
  10985. {
  10986. markSpawnedWork(Never);
  10987. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  10988. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  10989. return null;
  10990. }
  10991. reconcileChildren(
  10992. current,
  10993. workInProgress,
  10994. nextChildren,
  10995. renderExpirationTime
  10996. );
  10997. return workInProgress.child;
  10998. }
  10999. function updateHostText(current, workInProgress) {
  11000. // immediately after.
  11001. return null;
  11002. }
  11003. function mountLazyComponent(
  11004. _current,
  11005. workInProgress,
  11006. elementType,
  11007. updateExpirationTime,
  11008. renderExpirationTime
  11009. ) {
  11010. if (_current !== null) {
  11011. // A lazy component only mounts if it suspended inside a non-
  11012. // concurrent tree, in an inconsistent state. We want to treat it like
  11013. // a new mount, even though an empty version of it already committed.
  11014. // Disconnect the alternate pointers.
  11015. _current.alternate = null;
  11016. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  11017. workInProgress.effectTag |= Placement;
  11018. }
  11019. var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
  11020. // Cancel and resume right after we know the tag.
  11021. cancelWorkTimer(workInProgress);
  11022. var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
  11023. workInProgress.type = Component;
  11024. var resolvedTag = (workInProgress.tag = resolveLazyComponentTag(Component));
  11025. startWorkTimer(workInProgress);
  11026. var resolvedProps = resolveDefaultProps(Component, props);
  11027. var child;
  11028. switch (resolvedTag) {
  11029. case FunctionComponent: {
  11030. {
  11031. validateFunctionComponentInDev(workInProgress, Component);
  11032. workInProgress.type = Component = resolveFunctionForHotReloading(
  11033. Component
  11034. );
  11035. }
  11036. child = updateFunctionComponent(
  11037. null,
  11038. workInProgress,
  11039. Component,
  11040. resolvedProps,
  11041. renderExpirationTime
  11042. );
  11043. return child;
  11044. }
  11045. case ClassComponent: {
  11046. {
  11047. workInProgress.type = Component = resolveClassForHotReloading(
  11048. Component
  11049. );
  11050. }
  11051. child = updateClassComponent(
  11052. null,
  11053. workInProgress,
  11054. Component,
  11055. resolvedProps,
  11056. renderExpirationTime
  11057. );
  11058. return child;
  11059. }
  11060. case ForwardRef: {
  11061. {
  11062. workInProgress.type = Component = resolveForwardRefForHotReloading(
  11063. Component
  11064. );
  11065. }
  11066. child = updateForwardRef(
  11067. null,
  11068. workInProgress,
  11069. Component,
  11070. resolvedProps,
  11071. renderExpirationTime
  11072. );
  11073. return child;
  11074. }
  11075. case MemoComponent: {
  11076. {
  11077. if (workInProgress.type !== workInProgress.elementType) {
  11078. var outerPropTypes = Component.propTypes;
  11079. if (outerPropTypes) {
  11080. checkPropTypes(
  11081. outerPropTypes,
  11082. resolvedProps, // Resolved for outer only
  11083. "prop",
  11084. getComponentName(Component)
  11085. );
  11086. }
  11087. }
  11088. }
  11089. child = updateMemoComponent(
  11090. null,
  11091. workInProgress,
  11092. Component,
  11093. resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  11094. updateExpirationTime,
  11095. renderExpirationTime
  11096. );
  11097. return child;
  11098. }
  11099. }
  11100. var hint = "";
  11101. {
  11102. if (
  11103. Component !== null &&
  11104. typeof Component === "object" &&
  11105. Component.$$typeof === REACT_LAZY_TYPE
  11106. ) {
  11107. hint = " Did you wrap a component in React.lazy() more than once?";
  11108. }
  11109. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  11110. // because the fact that it's a separate type of work is an
  11111. // implementation detail.
  11112. {
  11113. throw Error(
  11114. "Element type is invalid. Received a promise that resolves to: " +
  11115. Component +
  11116. ". Lazy element type must resolve to a class or function." +
  11117. hint
  11118. );
  11119. }
  11120. }
  11121. function mountIncompleteClassComponent(
  11122. _current,
  11123. workInProgress,
  11124. Component,
  11125. nextProps,
  11126. renderExpirationTime
  11127. ) {
  11128. if (_current !== null) {
  11129. // An incomplete component only mounts if it suspended inside a non-
  11130. // concurrent tree, in an inconsistent state. We want to treat it like
  11131. // a new mount, even though an empty version of it already committed.
  11132. // Disconnect the alternate pointers.
  11133. _current.alternate = null;
  11134. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  11135. workInProgress.effectTag |= Placement;
  11136. } // Promote the fiber to a class and try rendering again.
  11137. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  11138. // Push context providers early to prevent context stack mismatches.
  11139. // During mounting we don't know the child context yet as the instance doesn't exist.
  11140. // We will invalidate the child context in finishClassComponent() right after rendering.
  11141. var hasContext;
  11142. if (isContextProvider(Component)) {
  11143. hasContext = true;
  11144. pushContextProvider(workInProgress);
  11145. } else {
  11146. hasContext = false;
  11147. }
  11148. prepareToReadContext(workInProgress, renderExpirationTime);
  11149. constructClassInstance(workInProgress, Component, nextProps);
  11150. mountClassInstance(
  11151. workInProgress,
  11152. Component,
  11153. nextProps,
  11154. renderExpirationTime
  11155. );
  11156. return finishClassComponent(
  11157. null,
  11158. workInProgress,
  11159. Component,
  11160. true,
  11161. hasContext,
  11162. renderExpirationTime
  11163. );
  11164. }
  11165. function mountIndeterminateComponent(
  11166. _current,
  11167. workInProgress,
  11168. Component,
  11169. renderExpirationTime
  11170. ) {
  11171. if (_current !== null) {
  11172. // An indeterminate component only mounts if it suspended inside a non-
  11173. // concurrent tree, in an inconsistent state. We want to treat it like
  11174. // a new mount, even though an empty version of it already committed.
  11175. // Disconnect the alternate pointers.
  11176. _current.alternate = null;
  11177. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  11178. workInProgress.effectTag |= Placement;
  11179. }
  11180. var props = workInProgress.pendingProps;
  11181. var context;
  11182. {
  11183. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  11184. context = getMaskedContext(workInProgress, unmaskedContext);
  11185. }
  11186. prepareToReadContext(workInProgress, renderExpirationTime);
  11187. var value;
  11188. {
  11189. if (
  11190. Component.prototype &&
  11191. typeof Component.prototype.render === "function"
  11192. ) {
  11193. var componentName = getComponentName(Component) || "Unknown";
  11194. if (!didWarnAboutBadClass[componentName]) {
  11195. error(
  11196. "The <%s /> component appears to have a render method, but doesn't extend React.Component. " +
  11197. "This is likely to cause errors. Change %s to extend React.Component instead.",
  11198. componentName,
  11199. componentName
  11200. );
  11201. didWarnAboutBadClass[componentName] = true;
  11202. }
  11203. }
  11204. if (workInProgress.mode & StrictMode) {
  11205. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  11206. }
  11207. ReactCurrentOwner$1.current = workInProgress;
  11208. value = renderWithHooks(
  11209. null,
  11210. workInProgress,
  11211. Component,
  11212. props,
  11213. context,
  11214. renderExpirationTime
  11215. );
  11216. } // React DevTools reads this flag.
  11217. workInProgress.effectTag |= PerformedWork;
  11218. if (
  11219. typeof value === "object" &&
  11220. value !== null &&
  11221. typeof value.render === "function" &&
  11222. value.$$typeof === undefined
  11223. ) {
  11224. {
  11225. var _componentName = getComponentName(Component) || "Unknown";
  11226. if (!didWarnAboutModulePatternComponent[_componentName]) {
  11227. error(
  11228. "The <%s /> component appears to be a function component that returns a class instance. " +
  11229. "Change %s to a class that extends React.Component instead. " +
  11230. "If you can't use a class try assigning the prototype on the function as a workaround. " +
  11231. "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " +
  11232. "cannot be called with `new` by React.",
  11233. _componentName,
  11234. _componentName,
  11235. _componentName
  11236. );
  11237. didWarnAboutModulePatternComponent[_componentName] = true;
  11238. }
  11239. } // Proceed under the assumption that this is a class instance
  11240. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  11241. workInProgress.memoizedState = null;
  11242. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  11243. // During mounting we don't know the child context yet as the instance doesn't exist.
  11244. // We will invalidate the child context in finishClassComponent() right after rendering.
  11245. var hasContext = false;
  11246. if (isContextProvider(Component)) {
  11247. hasContext = true;
  11248. pushContextProvider(workInProgress);
  11249. } else {
  11250. hasContext = false;
  11251. }
  11252. workInProgress.memoizedState =
  11253. value.state !== null && value.state !== undefined ? value.state : null;
  11254. initializeUpdateQueue(workInProgress);
  11255. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  11256. if (typeof getDerivedStateFromProps === "function") {
  11257. applyDerivedStateFromProps(
  11258. workInProgress,
  11259. Component,
  11260. getDerivedStateFromProps,
  11261. props
  11262. );
  11263. }
  11264. adoptClassInstance(workInProgress, value);
  11265. mountClassInstance(workInProgress, Component, props, renderExpirationTime);
  11266. return finishClassComponent(
  11267. null,
  11268. workInProgress,
  11269. Component,
  11270. true,
  11271. hasContext,
  11272. renderExpirationTime
  11273. );
  11274. } else {
  11275. // Proceed under the assumption that this is a function component
  11276. workInProgress.tag = FunctionComponent;
  11277. {
  11278. if (workInProgress.mode & StrictMode) {
  11279. // Only double-render components with Hooks
  11280. if (workInProgress.memoizedState !== null) {
  11281. value = renderWithHooks(
  11282. null,
  11283. workInProgress,
  11284. Component,
  11285. props,
  11286. context,
  11287. renderExpirationTime
  11288. );
  11289. }
  11290. }
  11291. }
  11292. reconcileChildren(null, workInProgress, value, renderExpirationTime);
  11293. {
  11294. validateFunctionComponentInDev(workInProgress, Component);
  11295. }
  11296. return workInProgress.child;
  11297. }
  11298. }
  11299. function validateFunctionComponentInDev(workInProgress, Component) {
  11300. {
  11301. if (Component) {
  11302. if (Component.childContextTypes) {
  11303. error(
  11304. "%s(...): childContextTypes cannot be defined on a function component.",
  11305. Component.displayName || Component.name || "Component"
  11306. );
  11307. }
  11308. }
  11309. if (workInProgress.ref !== null) {
  11310. var info = "";
  11311. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  11312. if (ownerName) {
  11313. info += "\n\nCheck the render method of `" + ownerName + "`.";
  11314. }
  11315. var warningKey = ownerName || workInProgress._debugID || "";
  11316. var debugSource = workInProgress._debugSource;
  11317. if (debugSource) {
  11318. warningKey = debugSource.fileName + ":" + debugSource.lineNumber;
  11319. }
  11320. if (!didWarnAboutFunctionRefs[warningKey]) {
  11321. didWarnAboutFunctionRefs[warningKey] = true;
  11322. error(
  11323. "Function components cannot be given refs. " +
  11324. "Attempts to access this ref will fail. " +
  11325. "Did you mean to use React.forwardRef()?%s",
  11326. info
  11327. );
  11328. }
  11329. }
  11330. if (typeof Component.getDerivedStateFromProps === "function") {
  11331. var _componentName2 = getComponentName(Component) || "Unknown";
  11332. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
  11333. error(
  11334. "%s: Function components do not support getDerivedStateFromProps.",
  11335. _componentName2
  11336. );
  11337. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
  11338. }
  11339. }
  11340. if (
  11341. typeof Component.contextType === "object" &&
  11342. Component.contextType !== null
  11343. ) {
  11344. var _componentName3 = getComponentName(Component) || "Unknown";
  11345. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
  11346. error(
  11347. "%s: Function components do not support contextType.",
  11348. _componentName3
  11349. );
  11350. didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
  11351. }
  11352. }
  11353. }
  11354. }
  11355. var SUSPENDED_MARKER = {
  11356. dehydrated: null,
  11357. retryTime: NoWork
  11358. };
  11359. function shouldRemainOnFallback(suspenseContext, current, workInProgress) {
  11360. // If the context is telling us that we should show a fallback, and we're not
  11361. // already showing content, then we should show the fallback instead.
  11362. return (
  11363. hasSuspenseContext(suspenseContext, ForceSuspenseFallback) &&
  11364. (current === null || current.memoizedState !== null)
  11365. );
  11366. }
  11367. function updateSuspenseComponent(
  11368. current,
  11369. workInProgress,
  11370. renderExpirationTime
  11371. ) {
  11372. var mode = workInProgress.mode;
  11373. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  11374. {
  11375. if (shouldSuspend(workInProgress)) {
  11376. workInProgress.effectTag |= DidCapture;
  11377. }
  11378. }
  11379. var suspenseContext = suspenseStackCursor.current;
  11380. var nextDidTimeout = false;
  11381. var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
  11382. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  11383. // Something in this boundary's subtree already suspended. Switch to
  11384. // rendering the fallback children.
  11385. nextDidTimeout = true;
  11386. workInProgress.effectTag &= ~DidCapture;
  11387. } else {
  11388. // Attempting the main content
  11389. if (current === null || current.memoizedState !== null) {
  11390. // This is a new mount or this boundary is already showing a fallback state.
  11391. // Mark this subtree context as having at least one invisible parent that could
  11392. // handle the fallback state.
  11393. // Boundaries without fallbacks or should be avoided are not considered since
  11394. // they cannot handle preferred fallback states.
  11395. if (
  11396. nextProps.fallback !== undefined &&
  11397. nextProps.unstable_avoidThisFallback !== true
  11398. ) {
  11399. suspenseContext = addSubtreeSuspenseContext(
  11400. suspenseContext,
  11401. InvisibleParentSuspenseContext
  11402. );
  11403. }
  11404. }
  11405. }
  11406. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11407. pushSuspenseContext(workInProgress, suspenseContext); // This next part is a bit confusing. If the children timeout, we switch to
  11408. // showing the fallback children in place of the "primary" children.
  11409. // However, we don't want to delete the primary children because then their
  11410. // state will be lost (both the React state and the host state, e.g.
  11411. // uncontrolled form inputs). Instead we keep them mounted and hide them.
  11412. // Both the fallback children AND the primary children are rendered at the
  11413. // same time. Once the primary children are un-suspended, we can delete
  11414. // the fallback children — don't need to preserve their state.
  11415. //
  11416. // The two sets of children are siblings in the host environment, but
  11417. // semantically, for purposes of reconciliation, they are two separate sets.
  11418. // So we store them using two fragment fibers.
  11419. //
  11420. // However, we want to avoid allocating extra fibers for every placeholder.
  11421. // They're only necessary when the children time out, because that's the
  11422. // only time when both sets are mounted.
  11423. //
  11424. // So, the extra fragment fibers are only used if the children time out.
  11425. // Otherwise, we render the primary children directly. This requires some
  11426. // custom reconciliation logic to preserve the state of the primary
  11427. // children. It's essentially a very basic form of re-parenting.
  11428. if (current === null) {
  11429. // If we're currently hydrating, try to hydrate this boundary.
  11430. // But only if this has a fallback.
  11431. if (nextProps.fallback !== undefined); // This is the initial mount. This branch is pretty simple because there's
  11432. // no previous state that needs to be preserved.
  11433. if (nextDidTimeout) {
  11434. // Mount separate fragments for primary and fallback children.
  11435. var nextFallbackChildren = nextProps.fallback;
  11436. var primaryChildFragment = createFiberFromFragment(
  11437. null,
  11438. mode,
  11439. NoWork,
  11440. null
  11441. );
  11442. primaryChildFragment.return = workInProgress;
  11443. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11444. // Outside of blocking mode, we commit the effects from the
  11445. // partially completed, timed-out tree, too.
  11446. var progressedState = workInProgress.memoizedState;
  11447. var progressedPrimaryChild =
  11448. progressedState !== null
  11449. ? workInProgress.child.child
  11450. : workInProgress.child;
  11451. primaryChildFragment.child = progressedPrimaryChild;
  11452. var progressedChild = progressedPrimaryChild;
  11453. while (progressedChild !== null) {
  11454. progressedChild.return = primaryChildFragment;
  11455. progressedChild = progressedChild.sibling;
  11456. }
  11457. }
  11458. var fallbackChildFragment = createFiberFromFragment(
  11459. nextFallbackChildren,
  11460. mode,
  11461. renderExpirationTime,
  11462. null
  11463. );
  11464. fallbackChildFragment.return = workInProgress;
  11465. primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
  11466. // fallback children.
  11467. workInProgress.memoizedState = SUSPENDED_MARKER;
  11468. workInProgress.child = primaryChildFragment;
  11469. return fallbackChildFragment;
  11470. } else {
  11471. // Mount the primary children without an intermediate fragment fiber.
  11472. var nextPrimaryChildren = nextProps.children;
  11473. workInProgress.memoizedState = null;
  11474. return (workInProgress.child = mountChildFibers(
  11475. workInProgress,
  11476. null,
  11477. nextPrimaryChildren,
  11478. renderExpirationTime
  11479. ));
  11480. }
  11481. } else {
  11482. // This is an update. This branch is more complicated because we need to
  11483. // ensure the state of the primary children is preserved.
  11484. var prevState = current.memoizedState;
  11485. if (prevState !== null) {
  11486. // wrapped in a fragment fiber.
  11487. var currentPrimaryChildFragment = current.child;
  11488. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  11489. if (nextDidTimeout) {
  11490. // Still timed out. Reuse the current primary children by cloning
  11491. // its fragment. We're going to skip over these entirely.
  11492. var _nextFallbackChildren2 = nextProps.fallback;
  11493. var _primaryChildFragment2 = createWorkInProgress(
  11494. currentPrimaryChildFragment,
  11495. currentPrimaryChildFragment.pendingProps
  11496. );
  11497. _primaryChildFragment2.return = workInProgress;
  11498. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11499. // Outside of blocking mode, we commit the effects from the
  11500. // partially completed, timed-out tree, too.
  11501. var _progressedState = workInProgress.memoizedState;
  11502. var _progressedPrimaryChild =
  11503. _progressedState !== null
  11504. ? workInProgress.child.child
  11505. : workInProgress.child;
  11506. if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
  11507. _primaryChildFragment2.child = _progressedPrimaryChild;
  11508. var _progressedChild2 = _progressedPrimaryChild;
  11509. while (_progressedChild2 !== null) {
  11510. _progressedChild2.return = _primaryChildFragment2;
  11511. _progressedChild2 = _progressedChild2.sibling;
  11512. }
  11513. }
  11514. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11515. // parent of a new tree, we need to set its treeBaseDuration.
  11516. if (workInProgress.mode & ProfileMode) {
  11517. // treeBaseDuration is the sum of all the child tree base durations.
  11518. var _treeBaseDuration = 0;
  11519. var _hiddenChild = _primaryChildFragment2.child;
  11520. while (_hiddenChild !== null) {
  11521. _treeBaseDuration += _hiddenChild.treeBaseDuration;
  11522. _hiddenChild = _hiddenChild.sibling;
  11523. }
  11524. _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
  11525. } // Clone the fallback child fragment, too. These we'll continue
  11526. // working on.
  11527. var _fallbackChildFragment2 = createWorkInProgress(
  11528. currentFallbackChildFragment,
  11529. _nextFallbackChildren2
  11530. );
  11531. _fallbackChildFragment2.return = workInProgress;
  11532. _primaryChildFragment2.sibling = _fallbackChildFragment2;
  11533. _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11534. // fallback children.
  11535. workInProgress.memoizedState = SUSPENDED_MARKER;
  11536. workInProgress.child = _primaryChildFragment2;
  11537. return _fallbackChildFragment2;
  11538. } else {
  11539. // No longer suspended. Switch back to showing the primary children,
  11540. // and remove the intermediate fragment fiber.
  11541. var _nextPrimaryChildren = nextProps.children;
  11542. var currentPrimaryChild = currentPrimaryChildFragment.child;
  11543. var primaryChild = reconcileChildFibers(
  11544. workInProgress,
  11545. currentPrimaryChild,
  11546. _nextPrimaryChildren,
  11547. renderExpirationTime
  11548. ); // If this render doesn't suspend, we need to delete the fallback
  11549. // children. Wait until the complete phase, after we've confirmed the
  11550. // fallback is no longer needed.
  11551. // TODO: Would it be better to store the fallback fragment on
  11552. // the stateNode?
  11553. // Continue rendering the children, like we normally do.
  11554. workInProgress.memoizedState = null;
  11555. return (workInProgress.child = primaryChild);
  11556. }
  11557. } else {
  11558. // The current tree has not already timed out. That means the primary
  11559. // children are not wrapped in a fragment fiber.
  11560. var _currentPrimaryChild = current.child;
  11561. if (nextDidTimeout) {
  11562. // Timed out. Wrap the children in a fragment fiber to keep them
  11563. // separate from the fallback children.
  11564. var _nextFallbackChildren3 = nextProps.fallback;
  11565. var _primaryChildFragment3 = createFiberFromFragment(
  11566. // It shouldn't matter what the pending props are because we aren't
  11567. // going to render this fragment.
  11568. null,
  11569. mode,
  11570. NoWork,
  11571. null
  11572. );
  11573. _primaryChildFragment3.return = workInProgress;
  11574. _primaryChildFragment3.child = _currentPrimaryChild;
  11575. if (_currentPrimaryChild !== null) {
  11576. _currentPrimaryChild.return = _primaryChildFragment3;
  11577. } // Even though we're creating a new fiber, there are no new children,
  11578. // because we're reusing an already mounted tree. So we don't need to
  11579. // schedule a placement.
  11580. // primaryChildFragment.effectTag |= Placement;
  11581. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11582. // Outside of blocking mode, we commit the effects from the
  11583. // partially completed, timed-out tree, too.
  11584. var _progressedState2 = workInProgress.memoizedState;
  11585. var _progressedPrimaryChild2 =
  11586. _progressedState2 !== null
  11587. ? workInProgress.child.child
  11588. : workInProgress.child;
  11589. _primaryChildFragment3.child = _progressedPrimaryChild2;
  11590. var _progressedChild3 = _progressedPrimaryChild2;
  11591. while (_progressedChild3 !== null) {
  11592. _progressedChild3.return = _primaryChildFragment3;
  11593. _progressedChild3 = _progressedChild3.sibling;
  11594. }
  11595. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11596. // parent of a new tree, we need to set its treeBaseDuration.
  11597. if (workInProgress.mode & ProfileMode) {
  11598. // treeBaseDuration is the sum of all the child tree base durations.
  11599. var _treeBaseDuration2 = 0;
  11600. var _hiddenChild2 = _primaryChildFragment3.child;
  11601. while (_hiddenChild2 !== null) {
  11602. _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
  11603. _hiddenChild2 = _hiddenChild2.sibling;
  11604. }
  11605. _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
  11606. } // Create a fragment from the fallback children, too.
  11607. var _fallbackChildFragment3 = createFiberFromFragment(
  11608. _nextFallbackChildren3,
  11609. mode,
  11610. renderExpirationTime,
  11611. null
  11612. );
  11613. _fallbackChildFragment3.return = workInProgress;
  11614. _primaryChildFragment3.sibling = _fallbackChildFragment3;
  11615. _fallbackChildFragment3.effectTag |= Placement;
  11616. _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11617. // fallback children.
  11618. workInProgress.memoizedState = SUSPENDED_MARKER;
  11619. workInProgress.child = _primaryChildFragment3;
  11620. return _fallbackChildFragment3;
  11621. } else {
  11622. // Still haven't timed out. Continue rendering the children, like we
  11623. // normally do.
  11624. workInProgress.memoizedState = null;
  11625. var _nextPrimaryChildren2 = nextProps.children;
  11626. return (workInProgress.child = reconcileChildFibers(
  11627. workInProgress,
  11628. _currentPrimaryChild,
  11629. _nextPrimaryChildren2,
  11630. renderExpirationTime
  11631. ));
  11632. }
  11633. }
  11634. }
  11635. }
  11636. function scheduleWorkOnFiber(fiber, renderExpirationTime) {
  11637. if (fiber.expirationTime < renderExpirationTime) {
  11638. fiber.expirationTime = renderExpirationTime;
  11639. }
  11640. var alternate = fiber.alternate;
  11641. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  11642. alternate.expirationTime = renderExpirationTime;
  11643. }
  11644. scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
  11645. }
  11646. function propagateSuspenseContextChange(
  11647. workInProgress,
  11648. firstChild,
  11649. renderExpirationTime
  11650. ) {
  11651. // Mark any Suspense boundaries with fallbacks as having work to do.
  11652. // If they were previously forced into fallbacks, they may now be able
  11653. // to unblock.
  11654. var node = firstChild;
  11655. while (node !== null) {
  11656. if (node.tag === SuspenseComponent) {
  11657. var state = node.memoizedState;
  11658. if (state !== null) {
  11659. scheduleWorkOnFiber(node, renderExpirationTime);
  11660. }
  11661. } else if (node.tag === SuspenseListComponent) {
  11662. // If the tail is hidden there might not be an Suspense boundaries
  11663. // to schedule work on. In this case we have to schedule it on the
  11664. // list itself.
  11665. // We don't have to traverse to the children of the list since
  11666. // the list will propagate the change when it rerenders.
  11667. scheduleWorkOnFiber(node, renderExpirationTime);
  11668. } else if (node.child !== null) {
  11669. node.child.return = node;
  11670. node = node.child;
  11671. continue;
  11672. }
  11673. if (node === workInProgress) {
  11674. return;
  11675. }
  11676. while (node.sibling === null) {
  11677. if (node.return === null || node.return === workInProgress) {
  11678. return;
  11679. }
  11680. node = node.return;
  11681. }
  11682. node.sibling.return = node.return;
  11683. node = node.sibling;
  11684. }
  11685. }
  11686. function findLastContentRow(firstChild) {
  11687. // This is going to find the last row among these children that is already
  11688. // showing content on the screen, as opposed to being in fallback state or
  11689. // new. If a row has multiple Suspense boundaries, any of them being in the
  11690. // fallback state, counts as the whole row being in a fallback state.
  11691. // Note that the "rows" will be workInProgress, but any nested children
  11692. // will still be current since we haven't rendered them yet. The mounted
  11693. // order may not be the same as the new order. We use the new order.
  11694. var row = firstChild;
  11695. var lastContentRow = null;
  11696. while (row !== null) {
  11697. var currentRow = row.alternate; // New rows can't be content rows.
  11698. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11699. lastContentRow = row;
  11700. }
  11701. row = row.sibling;
  11702. }
  11703. return lastContentRow;
  11704. }
  11705. function validateRevealOrder(revealOrder) {
  11706. {
  11707. if (
  11708. revealOrder !== undefined &&
  11709. revealOrder !== "forwards" &&
  11710. revealOrder !== "backwards" &&
  11711. revealOrder !== "together" &&
  11712. !didWarnAboutRevealOrder[revealOrder]
  11713. ) {
  11714. didWarnAboutRevealOrder[revealOrder] = true;
  11715. if (typeof revealOrder === "string") {
  11716. switch (revealOrder.toLowerCase()) {
  11717. case "together":
  11718. case "forwards":
  11719. case "backwards": {
  11720. error(
  11721. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11722. 'Use lowercase "%s" instead.',
  11723. revealOrder,
  11724. revealOrder.toLowerCase()
  11725. );
  11726. break;
  11727. }
  11728. case "forward":
  11729. case "backward": {
  11730. error(
  11731. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11732. 'React uses the -s suffix in the spelling. Use "%ss" instead.',
  11733. revealOrder,
  11734. revealOrder.toLowerCase()
  11735. );
  11736. break;
  11737. }
  11738. default:
  11739. error(
  11740. '"%s" is not a supported revealOrder on <SuspenseList />. ' +
  11741. 'Did you mean "together", "forwards" or "backwards"?',
  11742. revealOrder
  11743. );
  11744. break;
  11745. }
  11746. } else {
  11747. error(
  11748. "%s is not a supported value for revealOrder on <SuspenseList />. " +
  11749. 'Did you mean "together", "forwards" or "backwards"?',
  11750. revealOrder
  11751. );
  11752. }
  11753. }
  11754. }
  11755. }
  11756. function validateTailOptions(tailMode, revealOrder) {
  11757. {
  11758. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  11759. if (tailMode !== "collapsed" && tailMode !== "hidden") {
  11760. didWarnAboutTailOptions[tailMode] = true;
  11761. error(
  11762. '"%s" is not a supported value for tail on <SuspenseList />. ' +
  11763. 'Did you mean "collapsed" or "hidden"?',
  11764. tailMode
  11765. );
  11766. } else if (revealOrder !== "forwards" && revealOrder !== "backwards") {
  11767. didWarnAboutTailOptions[tailMode] = true;
  11768. error(
  11769. '<SuspenseList tail="%s" /> is only valid if revealOrder is ' +
  11770. '"forwards" or "backwards". ' +
  11771. 'Did you mean to specify revealOrder="forwards"?',
  11772. tailMode
  11773. );
  11774. }
  11775. }
  11776. }
  11777. }
  11778. function validateSuspenseListNestedChild(childSlot, index) {
  11779. {
  11780. var isArray = Array.isArray(childSlot);
  11781. var isIterable = !isArray && typeof getIteratorFn(childSlot) === "function";
  11782. if (isArray || isIterable) {
  11783. var type = isArray ? "array" : "iterable";
  11784. error(
  11785. "A nested %s was passed to row #%s in <SuspenseList />. Wrap it in " +
  11786. "an additional SuspenseList to configure its revealOrder: " +
  11787. "<SuspenseList revealOrder=...> ... " +
  11788. "<SuspenseList revealOrder=...>{%s}</SuspenseList> ... " +
  11789. "</SuspenseList>",
  11790. type,
  11791. index,
  11792. type
  11793. );
  11794. return false;
  11795. }
  11796. }
  11797. return true;
  11798. }
  11799. function validateSuspenseListChildren(children, revealOrder) {
  11800. {
  11801. if (
  11802. (revealOrder === "forwards" || revealOrder === "backwards") &&
  11803. children !== undefined &&
  11804. children !== null &&
  11805. children !== false
  11806. ) {
  11807. if (Array.isArray(children)) {
  11808. for (var i = 0; i < children.length; i++) {
  11809. if (!validateSuspenseListNestedChild(children[i], i)) {
  11810. return;
  11811. }
  11812. }
  11813. } else {
  11814. var iteratorFn = getIteratorFn(children);
  11815. if (typeof iteratorFn === "function") {
  11816. var childrenIterator = iteratorFn.call(children);
  11817. if (childrenIterator) {
  11818. var step = childrenIterator.next();
  11819. var _i = 0;
  11820. for (; !step.done; step = childrenIterator.next()) {
  11821. if (!validateSuspenseListNestedChild(step.value, _i)) {
  11822. return;
  11823. }
  11824. _i++;
  11825. }
  11826. }
  11827. } else {
  11828. error(
  11829. 'A single row was passed to a <SuspenseList revealOrder="%s" />. ' +
  11830. "This is not useful since it needs multiple rows. " +
  11831. "Did you mean to pass multiple children or an array?",
  11832. revealOrder
  11833. );
  11834. }
  11835. }
  11836. }
  11837. }
  11838. }
  11839. function initSuspenseListRenderState(
  11840. workInProgress,
  11841. isBackwards,
  11842. tail,
  11843. lastContentRow,
  11844. tailMode,
  11845. lastEffectBeforeRendering
  11846. ) {
  11847. var renderState = workInProgress.memoizedState;
  11848. if (renderState === null) {
  11849. workInProgress.memoizedState = {
  11850. isBackwards: isBackwards,
  11851. rendering: null,
  11852. renderingStartTime: 0,
  11853. last: lastContentRow,
  11854. tail: tail,
  11855. tailExpiration: 0,
  11856. tailMode: tailMode,
  11857. lastEffect: lastEffectBeforeRendering
  11858. };
  11859. } else {
  11860. // We can reuse the existing object from previous renders.
  11861. renderState.isBackwards = isBackwards;
  11862. renderState.rendering = null;
  11863. renderState.renderingStartTime = 0;
  11864. renderState.last = lastContentRow;
  11865. renderState.tail = tail;
  11866. renderState.tailExpiration = 0;
  11867. renderState.tailMode = tailMode;
  11868. renderState.lastEffect = lastEffectBeforeRendering;
  11869. }
  11870. } // This can end up rendering this component multiple passes.
  11871. // The first pass splits the children fibers into two sets. A head and tail.
  11872. // We first render the head. If anything is in fallback state, we do another
  11873. // pass through beginWork to rerender all children (including the tail) with
  11874. // the force suspend context. If the first render didn't have anything in
  11875. // in fallback state. Then we render each row in the tail one-by-one.
  11876. // That happens in the completeWork phase without going back to beginWork.
  11877. function updateSuspenseListComponent(
  11878. current,
  11879. workInProgress,
  11880. renderExpirationTime
  11881. ) {
  11882. var nextProps = workInProgress.pendingProps;
  11883. var revealOrder = nextProps.revealOrder;
  11884. var tailMode = nextProps.tail;
  11885. var newChildren = nextProps.children;
  11886. validateRevealOrder(revealOrder);
  11887. validateTailOptions(tailMode, revealOrder);
  11888. validateSuspenseListChildren(newChildren, revealOrder);
  11889. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11890. var suspenseContext = suspenseStackCursor.current;
  11891. var shouldForceFallback = hasSuspenseContext(
  11892. suspenseContext,
  11893. ForceSuspenseFallback
  11894. );
  11895. if (shouldForceFallback) {
  11896. suspenseContext = setShallowSuspenseContext(
  11897. suspenseContext,
  11898. ForceSuspenseFallback
  11899. );
  11900. workInProgress.effectTag |= DidCapture;
  11901. } else {
  11902. var didSuspendBefore =
  11903. current !== null && (current.effectTag & DidCapture) !== NoEffect;
  11904. if (didSuspendBefore) {
  11905. // If we previously forced a fallback, we need to schedule work
  11906. // on any nested boundaries to let them know to try to render
  11907. // again. This is the same as context updating.
  11908. propagateSuspenseContextChange(
  11909. workInProgress,
  11910. workInProgress.child,
  11911. renderExpirationTime
  11912. );
  11913. }
  11914. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11915. }
  11916. pushSuspenseContext(workInProgress, suspenseContext);
  11917. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11918. // Outside of blocking mode, SuspenseList doesn't work so we just
  11919. // use make it a noop by treating it as the default revealOrder.
  11920. workInProgress.memoizedState = null;
  11921. } else {
  11922. switch (revealOrder) {
  11923. case "forwards": {
  11924. var lastContentRow = findLastContentRow(workInProgress.child);
  11925. var tail;
  11926. if (lastContentRow === null) {
  11927. // The whole list is part of the tail.
  11928. // TODO: We could fast path by just rendering the tail now.
  11929. tail = workInProgress.child;
  11930. workInProgress.child = null;
  11931. } else {
  11932. // Disconnect the tail rows after the content row.
  11933. // We're going to render them separately later.
  11934. tail = lastContentRow.sibling;
  11935. lastContentRow.sibling = null;
  11936. }
  11937. initSuspenseListRenderState(
  11938. workInProgress,
  11939. false, // isBackwards
  11940. tail,
  11941. lastContentRow,
  11942. tailMode,
  11943. workInProgress.lastEffect
  11944. );
  11945. break;
  11946. }
  11947. case "backwards": {
  11948. // We're going to find the first row that has existing content.
  11949. // At the same time we're going to reverse the list of everything
  11950. // we pass in the meantime. That's going to be our tail in reverse
  11951. // order.
  11952. var _tail = null;
  11953. var row = workInProgress.child;
  11954. workInProgress.child = null;
  11955. while (row !== null) {
  11956. var currentRow = row.alternate; // New rows can't be content rows.
  11957. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11958. // This is the beginning of the main content.
  11959. workInProgress.child = row;
  11960. break;
  11961. }
  11962. var nextRow = row.sibling;
  11963. row.sibling = _tail;
  11964. _tail = row;
  11965. row = nextRow;
  11966. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  11967. initSuspenseListRenderState(
  11968. workInProgress,
  11969. true, // isBackwards
  11970. _tail,
  11971. null, // last
  11972. tailMode,
  11973. workInProgress.lastEffect
  11974. );
  11975. break;
  11976. }
  11977. case "together": {
  11978. initSuspenseListRenderState(
  11979. workInProgress,
  11980. false, // isBackwards
  11981. null, // tail
  11982. null, // last
  11983. undefined,
  11984. workInProgress.lastEffect
  11985. );
  11986. break;
  11987. }
  11988. default: {
  11989. // The default reveal order is the same as not having
  11990. // a boundary.
  11991. workInProgress.memoizedState = null;
  11992. }
  11993. }
  11994. }
  11995. return workInProgress.child;
  11996. }
  11997. function updatePortalComponent(current, workInProgress, renderExpirationTime) {
  11998. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  11999. var nextChildren = workInProgress.pendingProps;
  12000. if (current === null) {
  12001. // Portals are special because we don't append the children during mount
  12002. // but at commit. Therefore we need to track insertions which the normal
  12003. // flow doesn't do during mount. This doesn't happen at the root because
  12004. // the root always starts with a "current" with a null child.
  12005. // TODO: Consider unifying this with how the root works.
  12006. workInProgress.child = reconcileChildFibers(
  12007. workInProgress,
  12008. null,
  12009. nextChildren,
  12010. renderExpirationTime
  12011. );
  12012. } else {
  12013. reconcileChildren(
  12014. current,
  12015. workInProgress,
  12016. nextChildren,
  12017. renderExpirationTime
  12018. );
  12019. }
  12020. return workInProgress.child;
  12021. }
  12022. function updateContextProvider(current, workInProgress, renderExpirationTime) {
  12023. var providerType = workInProgress.type;
  12024. var context = providerType._context;
  12025. var newProps = workInProgress.pendingProps;
  12026. var oldProps = workInProgress.memoizedProps;
  12027. var newValue = newProps.value;
  12028. {
  12029. var providerPropTypes = workInProgress.type.propTypes;
  12030. if (providerPropTypes) {
  12031. checkPropTypes(providerPropTypes, newProps, "prop", "Context.Provider");
  12032. }
  12033. }
  12034. pushProvider(workInProgress, newValue);
  12035. if (oldProps !== null) {
  12036. var oldValue = oldProps.value;
  12037. var changedBits = calculateChangedBits(context, newValue, oldValue);
  12038. if (changedBits === 0) {
  12039. // No change. Bailout early if children are the same.
  12040. if (oldProps.children === newProps.children && !hasContextChanged()) {
  12041. return bailoutOnAlreadyFinishedWork(
  12042. current,
  12043. workInProgress,
  12044. renderExpirationTime
  12045. );
  12046. }
  12047. } else {
  12048. // The context value changed. Search for matching consumers and schedule
  12049. // them to update.
  12050. propagateContextChange(
  12051. workInProgress,
  12052. context,
  12053. changedBits,
  12054. renderExpirationTime
  12055. );
  12056. }
  12057. }
  12058. var newChildren = newProps.children;
  12059. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  12060. return workInProgress.child;
  12061. }
  12062. var hasWarnedAboutUsingContextAsConsumer = false;
  12063. function updateContextConsumer(current, workInProgress, renderExpirationTime) {
  12064. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  12065. // DEV mode, we create a separate object for Context.Consumer that acts
  12066. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  12067. // so we use the old behaviour (Context.Consumer references Context) to
  12068. // reduce size and overhead. The separate object references context via
  12069. // a property called "_context", which also gives us the ability to check
  12070. // in DEV mode if this property exists or not and warn if it does not.
  12071. {
  12072. if (context._context === undefined) {
  12073. // This may be because it's a Context (rather than a Consumer).
  12074. // Or it may be because it's older React where they're the same thing.
  12075. // We only want to warn if we're sure it's a new React.
  12076. if (context !== context.Consumer) {
  12077. if (!hasWarnedAboutUsingContextAsConsumer) {
  12078. hasWarnedAboutUsingContextAsConsumer = true;
  12079. error(
  12080. "Rendering <Context> directly is not supported and will be removed in " +
  12081. "a future major release. Did you mean to render <Context.Consumer> instead?"
  12082. );
  12083. }
  12084. }
  12085. } else {
  12086. context = context._context;
  12087. }
  12088. }
  12089. var newProps = workInProgress.pendingProps;
  12090. var render = newProps.children;
  12091. {
  12092. if (typeof render !== "function") {
  12093. error(
  12094. "A context consumer was rendered with multiple children, or a child " +
  12095. "that isn't a function. A context consumer expects a single child " +
  12096. "that is a function. If you did pass a function, make sure there " +
  12097. "is no trailing or leading whitespace around it."
  12098. );
  12099. }
  12100. }
  12101. prepareToReadContext(workInProgress, renderExpirationTime);
  12102. var newValue = readContext(context, newProps.unstable_observedBits);
  12103. var newChildren;
  12104. {
  12105. ReactCurrentOwner$1.current = workInProgress;
  12106. setIsRendering(true);
  12107. newChildren = render(newValue);
  12108. setIsRendering(false);
  12109. } // React DevTools reads this flag.
  12110. workInProgress.effectTag |= PerformedWork;
  12111. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  12112. return workInProgress.child;
  12113. }
  12114. function markWorkInProgressReceivedUpdate() {
  12115. didReceiveUpdate = true;
  12116. }
  12117. function bailoutOnAlreadyFinishedWork(
  12118. current,
  12119. workInProgress,
  12120. renderExpirationTime
  12121. ) {
  12122. cancelWorkTimer(workInProgress);
  12123. if (current !== null) {
  12124. // Reuse previous dependencies
  12125. workInProgress.dependencies = current.dependencies;
  12126. }
  12127. {
  12128. // Don't update "base" render times for bailouts.
  12129. stopProfilerTimerIfRunning();
  12130. }
  12131. var updateExpirationTime = workInProgress.expirationTime;
  12132. if (updateExpirationTime !== NoWork) {
  12133. markUnprocessedUpdateTime(updateExpirationTime);
  12134. } // Check if the children have any pending work.
  12135. var childExpirationTime = workInProgress.childExpirationTime;
  12136. if (childExpirationTime < renderExpirationTime) {
  12137. // The children don't have any work either. We can skip them.
  12138. // TODO: Once we add back resuming, we should check if the children are
  12139. // a work-in-progress set. If so, we need to transfer their effects.
  12140. return null;
  12141. } else {
  12142. // This fiber doesn't have work, but its subtree does. Clone the child
  12143. // fibers and continue.
  12144. cloneChildFibers(current, workInProgress);
  12145. return workInProgress.child;
  12146. }
  12147. }
  12148. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  12149. {
  12150. var returnFiber = oldWorkInProgress.return;
  12151. if (returnFiber === null) {
  12152. throw new Error("Cannot swap the root fiber.");
  12153. } // Disconnect from the old current.
  12154. // It will get deleted.
  12155. current.alternate = null;
  12156. oldWorkInProgress.alternate = null; // Connect to the new tree.
  12157. newWorkInProgress.index = oldWorkInProgress.index;
  12158. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  12159. newWorkInProgress.return = oldWorkInProgress.return;
  12160. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  12161. if (oldWorkInProgress === returnFiber.child) {
  12162. returnFiber.child = newWorkInProgress;
  12163. } else {
  12164. var prevSibling = returnFiber.child;
  12165. if (prevSibling === null) {
  12166. throw new Error("Expected parent to have a child.");
  12167. }
  12168. while (prevSibling.sibling !== oldWorkInProgress) {
  12169. prevSibling = prevSibling.sibling;
  12170. if (prevSibling === null) {
  12171. throw new Error("Expected to find the previous sibling.");
  12172. }
  12173. }
  12174. prevSibling.sibling = newWorkInProgress;
  12175. } // Delete the old fiber and place the new one.
  12176. // Since the old fiber is disconnected, we have to schedule it manually.
  12177. var last = returnFiber.lastEffect;
  12178. if (last !== null) {
  12179. last.nextEffect = current;
  12180. returnFiber.lastEffect = current;
  12181. } else {
  12182. returnFiber.firstEffect = returnFiber.lastEffect = current;
  12183. }
  12184. current.nextEffect = null;
  12185. current.effectTag = Deletion;
  12186. newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
  12187. return newWorkInProgress;
  12188. }
  12189. }
  12190. function beginWork(current, workInProgress, renderExpirationTime) {
  12191. var updateExpirationTime = workInProgress.expirationTime;
  12192. {
  12193. if (workInProgress._debugNeedsRemount && current !== null) {
  12194. // This will restart the begin phase with a new fiber.
  12195. return remountFiber(
  12196. current,
  12197. workInProgress,
  12198. createFiberFromTypeAndProps(
  12199. workInProgress.type,
  12200. workInProgress.key,
  12201. workInProgress.pendingProps,
  12202. workInProgress._debugOwner || null,
  12203. workInProgress.mode,
  12204. workInProgress.expirationTime
  12205. )
  12206. );
  12207. }
  12208. }
  12209. if (current !== null) {
  12210. var oldProps = current.memoizedProps;
  12211. var newProps = workInProgress.pendingProps;
  12212. if (
  12213. oldProps !== newProps ||
  12214. hasContextChanged() || // Force a re-render if the implementation changed due to hot reload:
  12215. workInProgress.type !== current.type
  12216. ) {
  12217. // If props or context changed, mark the fiber as having performed work.
  12218. // This may be unset if the props are determined to be equal later (memo).
  12219. didReceiveUpdate = true;
  12220. } else if (updateExpirationTime < renderExpirationTime) {
  12221. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  12222. // the begin phase. There's still some bookkeeping we that needs to be done
  12223. // in this optimized path, mostly pushing stuff onto the stack.
  12224. switch (workInProgress.tag) {
  12225. case HostRoot:
  12226. pushHostRootContext(workInProgress);
  12227. break;
  12228. case HostComponent:
  12229. pushHostContext(workInProgress);
  12230. if (
  12231. workInProgress.mode & ConcurrentMode &&
  12232. renderExpirationTime !== Never &&
  12233. shouldDeprioritizeSubtree(workInProgress.type)
  12234. ) {
  12235. {
  12236. markSpawnedWork(Never);
  12237. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  12238. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  12239. return null;
  12240. }
  12241. break;
  12242. case ClassComponent: {
  12243. var Component = workInProgress.type;
  12244. if (isContextProvider(Component)) {
  12245. pushContextProvider(workInProgress);
  12246. }
  12247. break;
  12248. }
  12249. case HostPortal:
  12250. pushHostContainer(
  12251. workInProgress,
  12252. workInProgress.stateNode.containerInfo
  12253. );
  12254. break;
  12255. case ContextProvider: {
  12256. var newValue = workInProgress.memoizedProps.value;
  12257. pushProvider(workInProgress, newValue);
  12258. break;
  12259. }
  12260. case Profiler:
  12261. {
  12262. // Profiler should only call onRender when one of its descendants actually rendered.
  12263. var hasChildWork =
  12264. workInProgress.childExpirationTime >= renderExpirationTime;
  12265. if (hasChildWork) {
  12266. workInProgress.effectTag |= Update;
  12267. } // Reset effect durations for the next eventual effect phase.
  12268. // These are reset during render to allow the DevTools commit hook a chance to read them,
  12269. var stateNode = workInProgress.stateNode;
  12270. stateNode.effectDuration = 0;
  12271. stateNode.passiveEffectDuration = 0;
  12272. }
  12273. break;
  12274. case SuspenseComponent: {
  12275. var state = workInProgress.memoizedState;
  12276. if (state !== null) {
  12277. // whether to retry the primary children, or to skip over it and
  12278. // go straight to the fallback. Check the priority of the primary
  12279. // child fragment.
  12280. var primaryChildFragment = workInProgress.child;
  12281. var primaryChildExpirationTime =
  12282. primaryChildFragment.childExpirationTime;
  12283. if (
  12284. primaryChildExpirationTime !== NoWork &&
  12285. primaryChildExpirationTime >= renderExpirationTime
  12286. ) {
  12287. // The primary children have pending work. Use the normal path
  12288. // to attempt to render the primary children again.
  12289. return updateSuspenseComponent(
  12290. current,
  12291. workInProgress,
  12292. renderExpirationTime
  12293. );
  12294. } else {
  12295. pushSuspenseContext(
  12296. workInProgress,
  12297. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  12298. ); // The primary children do not have pending work with sufficient
  12299. // priority. Bailout.
  12300. var child = bailoutOnAlreadyFinishedWork(
  12301. current,
  12302. workInProgress,
  12303. renderExpirationTime
  12304. );
  12305. if (child !== null) {
  12306. // The fallback children have pending work. Skip over the
  12307. // primary children and work on the fallback.
  12308. return child.sibling;
  12309. } else {
  12310. return null;
  12311. }
  12312. }
  12313. } else {
  12314. pushSuspenseContext(
  12315. workInProgress,
  12316. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  12317. );
  12318. }
  12319. break;
  12320. }
  12321. case SuspenseListComponent: {
  12322. var didSuspendBefore = (current.effectTag & DidCapture) !== NoEffect;
  12323. var _hasChildWork =
  12324. workInProgress.childExpirationTime >= renderExpirationTime;
  12325. if (didSuspendBefore) {
  12326. if (_hasChildWork) {
  12327. // If something was in fallback state last time, and we have all the
  12328. // same children then we're still in progressive loading state.
  12329. // Something might get unblocked by state updates or retries in the
  12330. // tree which will affect the tail. So we need to use the normal
  12331. // path to compute the correct tail.
  12332. return updateSuspenseListComponent(
  12333. current,
  12334. workInProgress,
  12335. renderExpirationTime
  12336. );
  12337. } // If none of the children had any work, that means that none of
  12338. // them got retried so they'll still be blocked in the same way
  12339. // as before. We can fast bail out.
  12340. workInProgress.effectTag |= DidCapture;
  12341. } // If nothing suspended before and we're rendering the same children,
  12342. // then the tail doesn't matter. Anything new that suspends will work
  12343. // in the "together" mode, so we can continue from the state we had.
  12344. var renderState = workInProgress.memoizedState;
  12345. if (renderState !== null) {
  12346. // Reset to the "together" mode in case we've started a different
  12347. // update in the past but didn't complete it.
  12348. renderState.rendering = null;
  12349. renderState.tail = null;
  12350. }
  12351. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  12352. if (_hasChildWork) {
  12353. break;
  12354. } else {
  12355. // If none of the children had any work, that means that none of
  12356. // them got retried so they'll still be blocked in the same way
  12357. // as before. We can fast bail out.
  12358. return null;
  12359. }
  12360. }
  12361. }
  12362. return bailoutOnAlreadyFinishedWork(
  12363. current,
  12364. workInProgress,
  12365. renderExpirationTime
  12366. );
  12367. } else {
  12368. // An update was scheduled on this fiber, but there are no new props
  12369. // nor legacy context. Set this to false. If an update queue or context
  12370. // consumer produces a changed value, it will set this to true. Otherwise,
  12371. // the component will assume the children have not changed and bail out.
  12372. didReceiveUpdate = false;
  12373. }
  12374. } else {
  12375. didReceiveUpdate = false;
  12376. } // Before entering the begin phase, clear pending update priority.
  12377. // TODO: This assumes that we're about to evaluate the component and process
  12378. // the update queue. However, there's an exception: SimpleMemoComponent
  12379. // sometimes bails out later in the begin phase. This indicates that we should
  12380. // move this assignment out of the common path and into each branch.
  12381. workInProgress.expirationTime = NoWork;
  12382. switch (workInProgress.tag) {
  12383. case IndeterminateComponent: {
  12384. return mountIndeterminateComponent(
  12385. current,
  12386. workInProgress,
  12387. workInProgress.type,
  12388. renderExpirationTime
  12389. );
  12390. }
  12391. case LazyComponent: {
  12392. var elementType = workInProgress.elementType;
  12393. return mountLazyComponent(
  12394. current,
  12395. workInProgress,
  12396. elementType,
  12397. updateExpirationTime,
  12398. renderExpirationTime
  12399. );
  12400. }
  12401. case FunctionComponent: {
  12402. var _Component = workInProgress.type;
  12403. var unresolvedProps = workInProgress.pendingProps;
  12404. var resolvedProps =
  12405. workInProgress.elementType === _Component
  12406. ? unresolvedProps
  12407. : resolveDefaultProps(_Component, unresolvedProps);
  12408. return updateFunctionComponent(
  12409. current,
  12410. workInProgress,
  12411. _Component,
  12412. resolvedProps,
  12413. renderExpirationTime
  12414. );
  12415. }
  12416. case ClassComponent: {
  12417. var _Component2 = workInProgress.type;
  12418. var _unresolvedProps = workInProgress.pendingProps;
  12419. var _resolvedProps =
  12420. workInProgress.elementType === _Component2
  12421. ? _unresolvedProps
  12422. : resolveDefaultProps(_Component2, _unresolvedProps);
  12423. return updateClassComponent(
  12424. current,
  12425. workInProgress,
  12426. _Component2,
  12427. _resolvedProps,
  12428. renderExpirationTime
  12429. );
  12430. }
  12431. case HostRoot:
  12432. return updateHostRoot(current, workInProgress, renderExpirationTime);
  12433. case HostComponent:
  12434. return updateHostComponent(current, workInProgress, renderExpirationTime);
  12435. case HostText:
  12436. return updateHostText();
  12437. case SuspenseComponent:
  12438. return updateSuspenseComponent(
  12439. current,
  12440. workInProgress,
  12441. renderExpirationTime
  12442. );
  12443. case HostPortal:
  12444. return updatePortalComponent(
  12445. current,
  12446. workInProgress,
  12447. renderExpirationTime
  12448. );
  12449. case ForwardRef: {
  12450. var type = workInProgress.type;
  12451. var _unresolvedProps2 = workInProgress.pendingProps;
  12452. var _resolvedProps2 =
  12453. workInProgress.elementType === type
  12454. ? _unresolvedProps2
  12455. : resolveDefaultProps(type, _unresolvedProps2);
  12456. return updateForwardRef(
  12457. current,
  12458. workInProgress,
  12459. type,
  12460. _resolvedProps2,
  12461. renderExpirationTime
  12462. );
  12463. }
  12464. case Fragment:
  12465. return updateFragment(current, workInProgress, renderExpirationTime);
  12466. case Mode:
  12467. return updateMode(current, workInProgress, renderExpirationTime);
  12468. case Profiler:
  12469. return updateProfiler(current, workInProgress, renderExpirationTime);
  12470. case ContextProvider:
  12471. return updateContextProvider(
  12472. current,
  12473. workInProgress,
  12474. renderExpirationTime
  12475. );
  12476. case ContextConsumer:
  12477. return updateContextConsumer(
  12478. current,
  12479. workInProgress,
  12480. renderExpirationTime
  12481. );
  12482. case MemoComponent: {
  12483. var _type2 = workInProgress.type;
  12484. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  12485. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  12486. {
  12487. if (workInProgress.type !== workInProgress.elementType) {
  12488. var outerPropTypes = _type2.propTypes;
  12489. if (outerPropTypes) {
  12490. checkPropTypes(
  12491. outerPropTypes,
  12492. _resolvedProps3, // Resolved for outer only
  12493. "prop",
  12494. getComponentName(_type2)
  12495. );
  12496. }
  12497. }
  12498. }
  12499. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  12500. return updateMemoComponent(
  12501. current,
  12502. workInProgress,
  12503. _type2,
  12504. _resolvedProps3,
  12505. updateExpirationTime,
  12506. renderExpirationTime
  12507. );
  12508. }
  12509. case SimpleMemoComponent: {
  12510. return updateSimpleMemoComponent(
  12511. current,
  12512. workInProgress,
  12513. workInProgress.type,
  12514. workInProgress.pendingProps,
  12515. updateExpirationTime,
  12516. renderExpirationTime
  12517. );
  12518. }
  12519. case IncompleteClassComponent: {
  12520. var _Component3 = workInProgress.type;
  12521. var _unresolvedProps4 = workInProgress.pendingProps;
  12522. var _resolvedProps4 =
  12523. workInProgress.elementType === _Component3
  12524. ? _unresolvedProps4
  12525. : resolveDefaultProps(_Component3, _unresolvedProps4);
  12526. return mountIncompleteClassComponent(
  12527. current,
  12528. workInProgress,
  12529. _Component3,
  12530. _resolvedProps4,
  12531. renderExpirationTime
  12532. );
  12533. }
  12534. case SuspenseListComponent: {
  12535. return updateSuspenseListComponent(
  12536. current,
  12537. workInProgress,
  12538. renderExpirationTime
  12539. );
  12540. }
  12541. }
  12542. {
  12543. throw Error(
  12544. "Unknown unit of work tag (" +
  12545. workInProgress.tag +
  12546. "). This error is likely caused by a bug in React. Please file an issue."
  12547. );
  12548. }
  12549. }
  12550. function markUpdate(workInProgress) {
  12551. // Tag the fiber with an update effect. This turns a Placement into
  12552. // a PlacementAndUpdate.
  12553. workInProgress.effectTag |= Update;
  12554. }
  12555. function markRef$1(workInProgress) {
  12556. workInProgress.effectTag |= Ref;
  12557. }
  12558. var appendAllChildren;
  12559. var updateHostContainer;
  12560. var updateHostComponent$1;
  12561. var updateHostText$1;
  12562. {
  12563. // Mutation mode
  12564. appendAllChildren = function(
  12565. parent,
  12566. workInProgress,
  12567. needsVisibilityToggle,
  12568. isHidden
  12569. ) {
  12570. // We only have the top Fiber that was created but we need recurse down its
  12571. // children to find all the terminal nodes.
  12572. var node = workInProgress.child;
  12573. while (node !== null) {
  12574. if (node.tag === HostComponent || node.tag === HostText) {
  12575. appendInitialChild(parent, node.stateNode);
  12576. } else if (node.tag === HostPortal);
  12577. else if (node.child !== null) {
  12578. node.child.return = node;
  12579. node = node.child;
  12580. continue;
  12581. }
  12582. if (node === workInProgress) {
  12583. return;
  12584. }
  12585. while (node.sibling === null) {
  12586. if (node.return === null || node.return === workInProgress) {
  12587. return;
  12588. }
  12589. node = node.return;
  12590. }
  12591. node.sibling.return = node.return;
  12592. node = node.sibling;
  12593. }
  12594. };
  12595. updateHostContainer = function(workInProgress) {
  12596. // Noop
  12597. };
  12598. updateHostComponent$1 = function(
  12599. current,
  12600. workInProgress,
  12601. type,
  12602. newProps,
  12603. rootContainerInstance
  12604. ) {
  12605. // If we have an alternate, that means this is an update and we need to
  12606. // schedule a side-effect to do the updates.
  12607. var oldProps = current.memoizedProps;
  12608. if (oldProps === newProps) {
  12609. // In mutation mode, this is sufficient for a bailout because
  12610. // we won't touch this node even if children changed.
  12611. return;
  12612. } // If we get updated because one of our children updated, we don't
  12613. // have newProps so we'll have to reuse them.
  12614. // TODO: Split the update API as separate for the props vs. children.
  12615. // Even better would be if children weren't special cased at all tho.
  12616. var instance = workInProgress.stateNode;
  12617. var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
  12618. // component is hitting the resume path. Figure out why. Possibly
  12619. // related to `hidden`.
  12620. var updatePayload = prepareUpdate(); // TODO: Type this specific to this type of component.
  12621. workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  12622. // is a new ref we mark this as an update. All the work is done in commitWork.
  12623. if (updatePayload) {
  12624. markUpdate(workInProgress);
  12625. }
  12626. };
  12627. updateHostText$1 = function(current, workInProgress, oldText, newText) {
  12628. // If the text differs, mark it as an update. All the work in done in commitWork.
  12629. if (oldText !== newText) {
  12630. markUpdate(workInProgress);
  12631. }
  12632. };
  12633. }
  12634. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  12635. switch (renderState.tailMode) {
  12636. case "hidden": {
  12637. // Any insertions at the end of the tail list after this point
  12638. // should be invisible. If there are already mounted boundaries
  12639. // anything before them are not considered for collapsing.
  12640. // Therefore we need to go through the whole tail to find if
  12641. // there are any.
  12642. var tailNode = renderState.tail;
  12643. var lastTailNode = null;
  12644. while (tailNode !== null) {
  12645. if (tailNode.alternate !== null) {
  12646. lastTailNode = tailNode;
  12647. }
  12648. tailNode = tailNode.sibling;
  12649. } // Next we're simply going to delete all insertions after the
  12650. // last rendered item.
  12651. if (lastTailNode === null) {
  12652. // All remaining items in the tail are insertions.
  12653. renderState.tail = null;
  12654. } else {
  12655. // Detach the insertion after the last node that was already
  12656. // inserted.
  12657. lastTailNode.sibling = null;
  12658. }
  12659. break;
  12660. }
  12661. case "collapsed": {
  12662. // Any insertions at the end of the tail list after this point
  12663. // should be invisible. If there are already mounted boundaries
  12664. // anything before them are not considered for collapsing.
  12665. // Therefore we need to go through the whole tail to find if
  12666. // there are any.
  12667. var _tailNode = renderState.tail;
  12668. var _lastTailNode = null;
  12669. while (_tailNode !== null) {
  12670. if (_tailNode.alternate !== null) {
  12671. _lastTailNode = _tailNode;
  12672. }
  12673. _tailNode = _tailNode.sibling;
  12674. } // Next we're simply going to delete all insertions after the
  12675. // last rendered item.
  12676. if (_lastTailNode === null) {
  12677. // All remaining items in the tail are insertions.
  12678. if (!hasRenderedATailFallback && renderState.tail !== null) {
  12679. // We suspended during the head. We want to show at least one
  12680. // row at the tail. So we'll keep on and cut off the rest.
  12681. renderState.tail.sibling = null;
  12682. } else {
  12683. renderState.tail = null;
  12684. }
  12685. } else {
  12686. // Detach the insertion after the last node that was already
  12687. // inserted.
  12688. _lastTailNode.sibling = null;
  12689. }
  12690. break;
  12691. }
  12692. }
  12693. }
  12694. function completeWork(current, workInProgress, renderExpirationTime) {
  12695. var newProps = workInProgress.pendingProps;
  12696. switch (workInProgress.tag) {
  12697. case IndeterminateComponent:
  12698. case LazyComponent:
  12699. case SimpleMemoComponent:
  12700. case FunctionComponent:
  12701. case ForwardRef:
  12702. case Fragment:
  12703. case Mode:
  12704. case Profiler:
  12705. case ContextConsumer:
  12706. case MemoComponent:
  12707. return null;
  12708. case ClassComponent: {
  12709. var Component = workInProgress.type;
  12710. if (isContextProvider(Component)) {
  12711. popContext(workInProgress);
  12712. }
  12713. return null;
  12714. }
  12715. case HostRoot: {
  12716. popHostContainer(workInProgress);
  12717. popTopLevelContextObject(workInProgress);
  12718. var fiberRoot = workInProgress.stateNode;
  12719. if (fiberRoot.pendingContext) {
  12720. fiberRoot.context = fiberRoot.pendingContext;
  12721. fiberRoot.pendingContext = null;
  12722. }
  12723. if (current === null || current.child === null) {
  12724. // If we hydrated, pop so that we can delete any remaining children
  12725. // that weren't hydrated.
  12726. var wasHydrated = popHydrationState();
  12727. if (wasHydrated) {
  12728. // If we hydrated, then we'll need to schedule an update for
  12729. // the commit side-effects on the root.
  12730. markUpdate(workInProgress);
  12731. }
  12732. }
  12733. updateHostContainer(workInProgress);
  12734. return null;
  12735. }
  12736. case HostComponent: {
  12737. popHostContext(workInProgress);
  12738. var rootContainerInstance = getRootHostContainer();
  12739. var type = workInProgress.type;
  12740. if (current !== null && workInProgress.stateNode != null) {
  12741. updateHostComponent$1(
  12742. current,
  12743. workInProgress,
  12744. type,
  12745. newProps,
  12746. rootContainerInstance
  12747. );
  12748. if (current.ref !== workInProgress.ref) {
  12749. markRef$1(workInProgress);
  12750. }
  12751. } else {
  12752. if (!newProps) {
  12753. if (!(workInProgress.stateNode !== null)) {
  12754. throw Error(
  12755. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12756. );
  12757. } // This can happen when we abort work.
  12758. return null;
  12759. }
  12760. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  12761. // "stack" as the parent. Then append children as we go in beginWork
  12762. // or completeWork depending on whether we want to add them top->down or
  12763. // bottom->up. Top->down is faster in IE11.
  12764. var _wasHydrated = popHydrationState();
  12765. if (_wasHydrated) {
  12766. // TODO: Move this and createInstance step into the beginPhase
  12767. // to consolidate.
  12768. if (prepareToHydrateHostInstance()) {
  12769. // If changes to the hydrated node need to be applied at the
  12770. // commit-phase we mark this as such.
  12771. markUpdate(workInProgress);
  12772. }
  12773. } else {
  12774. var instance = createInstance(
  12775. type,
  12776. newProps,
  12777. rootContainerInstance,
  12778. currentHostContext,
  12779. workInProgress
  12780. );
  12781. appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
  12782. workInProgress.stateNode = instance;
  12783. // (eg DOM renderer supports auto-focus for certain elements).
  12784. // Make sure such renderers get scheduled for later work.
  12785. if (finalizeInitialChildren(instance)) {
  12786. markUpdate(workInProgress);
  12787. }
  12788. }
  12789. if (workInProgress.ref !== null) {
  12790. // If there is a ref on a host node we need to schedule a callback
  12791. markRef$1(workInProgress);
  12792. }
  12793. }
  12794. return null;
  12795. }
  12796. case HostText: {
  12797. var newText = newProps;
  12798. if (current && workInProgress.stateNode != null) {
  12799. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  12800. // to schedule a side-effect to do the updates.
  12801. updateHostText$1(current, workInProgress, oldText, newText);
  12802. } else {
  12803. if (typeof newText !== "string") {
  12804. if (!(workInProgress.stateNode !== null)) {
  12805. throw Error(
  12806. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12807. );
  12808. } // This can happen when we abort work.
  12809. }
  12810. var _rootContainerInstance = getRootHostContainer();
  12811. var _currentHostContext = getHostContext();
  12812. var _wasHydrated2 = popHydrationState();
  12813. if (_wasHydrated2) {
  12814. if (prepareToHydrateHostTextInstance()) {
  12815. markUpdate(workInProgress);
  12816. }
  12817. } else {
  12818. workInProgress.stateNode = createTextInstance(
  12819. newText,
  12820. _rootContainerInstance,
  12821. _currentHostContext,
  12822. workInProgress
  12823. );
  12824. }
  12825. }
  12826. return null;
  12827. }
  12828. case SuspenseComponent: {
  12829. popSuspenseContext(workInProgress);
  12830. var nextState = workInProgress.memoizedState;
  12831. if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
  12832. // Something suspended. Re-render with the fallback children.
  12833. workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
  12834. return workInProgress;
  12835. }
  12836. var nextDidTimeout = nextState !== null;
  12837. var prevDidTimeout = false;
  12838. if (current === null) {
  12839. if (workInProgress.memoizedProps.fallback !== undefined);
  12840. } else {
  12841. var prevState = current.memoizedState;
  12842. prevDidTimeout = prevState !== null;
  12843. if (!nextDidTimeout && prevState !== null) {
  12844. // We just switched from the fallback to the normal children.
  12845. // Delete the fallback.
  12846. // TODO: Would it be better to store the fallback fragment on
  12847. // the stateNode during the begin phase?
  12848. var currentFallbackChild = current.child.sibling;
  12849. if (currentFallbackChild !== null) {
  12850. // Deletions go at the beginning of the return fiber's effect list
  12851. var first = workInProgress.firstEffect;
  12852. if (first !== null) {
  12853. workInProgress.firstEffect = currentFallbackChild;
  12854. currentFallbackChild.nextEffect = first;
  12855. } else {
  12856. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
  12857. currentFallbackChild.nextEffect = null;
  12858. }
  12859. currentFallbackChild.effectTag = Deletion;
  12860. }
  12861. }
  12862. }
  12863. if (nextDidTimeout && !prevDidTimeout) {
  12864. // If this subtreee is running in blocking mode we can suspend,
  12865. // otherwise we won't suspend.
  12866. // TODO: This will still suspend a synchronous tree if anything
  12867. // in the concurrent tree already suspended during this render.
  12868. // This is a known bug.
  12869. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  12870. // TODO: Move this back to throwException because this is too late
  12871. // if this is a large tree which is common for initial loads. We
  12872. // don't know if we should restart a render or not until we get
  12873. // this marker, and this is too late.
  12874. // If this render already had a ping or lower pri updates,
  12875. // and this is the first time we know we're going to suspend we
  12876. // should be able to immediately restart from within throwException.
  12877. var hasInvisibleChildContext =
  12878. current === null &&
  12879. workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  12880. if (
  12881. hasInvisibleChildContext ||
  12882. hasSuspenseContext(
  12883. suspenseStackCursor.current,
  12884. InvisibleParentSuspenseContext
  12885. )
  12886. ) {
  12887. // If this was in an invisible tree or a new render, then showing
  12888. // this boundary is ok.
  12889. renderDidSuspend();
  12890. } else {
  12891. // Otherwise, we're going to have to hide content so we should
  12892. // suspend for longer if possible.
  12893. renderDidSuspendDelayIfPossible();
  12894. }
  12895. }
  12896. }
  12897. {
  12898. // TODO: Only schedule updates if these values are non equal, i.e. it changed.
  12899. if (nextDidTimeout || prevDidTimeout) {
  12900. // If this boundary just timed out, schedule an effect to attach a
  12901. // retry listener to the promise. This flag is also used to hide the
  12902. // primary children. In mutation mode, we also need the flag to
  12903. // *unhide* children that were previously hidden, so check if this
  12904. // is currently timed out, too.
  12905. workInProgress.effectTag |= Update;
  12906. }
  12907. }
  12908. return null;
  12909. }
  12910. case HostPortal:
  12911. popHostContainer(workInProgress);
  12912. updateHostContainer(workInProgress);
  12913. return null;
  12914. case ContextProvider:
  12915. // Pop provider fiber
  12916. popProvider(workInProgress);
  12917. return null;
  12918. case IncompleteClassComponent: {
  12919. // Same as class component case. I put it down here so that the tags are
  12920. // sequential to ensure this switch is compiled to a jump table.
  12921. var _Component = workInProgress.type;
  12922. if (isContextProvider(_Component)) {
  12923. popContext(workInProgress);
  12924. }
  12925. return null;
  12926. }
  12927. case SuspenseListComponent: {
  12928. popSuspenseContext(workInProgress);
  12929. var renderState = workInProgress.memoizedState;
  12930. if (renderState === null) {
  12931. // We're running in the default, "independent" mode.
  12932. // We don't do anything in this mode.
  12933. return null;
  12934. }
  12935. var didSuspendAlready =
  12936. (workInProgress.effectTag & DidCapture) !== NoEffect;
  12937. var renderedTail = renderState.rendering;
  12938. if (renderedTail === null) {
  12939. // We just rendered the head.
  12940. if (!didSuspendAlready) {
  12941. // This is the first pass. We need to figure out if anything is still
  12942. // suspended in the rendered set.
  12943. // If new content unsuspended, but there's still some content that
  12944. // didn't. Then we need to do a second pass that forces everything
  12945. // to keep showing their fallbacks.
  12946. // We might be suspended if something in this render pass suspended, or
  12947. // something in the previous committed pass suspended. Otherwise,
  12948. // there's no chance so we can skip the expensive call to
  12949. // findFirstSuspended.
  12950. var cannotBeSuspended =
  12951. renderHasNotSuspendedYet() &&
  12952. (current === null || (current.effectTag & DidCapture) === NoEffect);
  12953. if (!cannotBeSuspended) {
  12954. var row = workInProgress.child;
  12955. while (row !== null) {
  12956. var suspended = findFirstSuspended(row);
  12957. if (suspended !== null) {
  12958. didSuspendAlready = true;
  12959. workInProgress.effectTag |= DidCapture;
  12960. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  12961. // part of the second pass. In that case nothing will subscribe to
  12962. // its thennables. Instead, we'll transfer its thennables to the
  12963. // SuspenseList so that it can retry if they resolve.
  12964. // There might be multiple of these in the list but since we're
  12965. // going to wait for all of them anyway, it doesn't really matter
  12966. // which ones gets to ping. In theory we could get clever and keep
  12967. // track of how many dependencies remain but it gets tricky because
  12968. // in the meantime, we can add/remove/change items and dependencies.
  12969. // We might bail out of the loop before finding any but that
  12970. // doesn't matter since that means that the other boundaries that
  12971. // we did find already has their listeners attached.
  12972. var newThennables = suspended.updateQueue;
  12973. if (newThennables !== null) {
  12974. workInProgress.updateQueue = newThennables;
  12975. workInProgress.effectTag |= Update;
  12976. } // Rerender the whole list, but this time, we'll force fallbacks
  12977. // to stay in place.
  12978. // Reset the effect list before doing the second pass since that's now invalid.
  12979. if (renderState.lastEffect === null) {
  12980. workInProgress.firstEffect = null;
  12981. }
  12982. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  12983. resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
  12984. // rerender the children.
  12985. pushSuspenseContext(
  12986. workInProgress,
  12987. setShallowSuspenseContext(
  12988. suspenseStackCursor.current,
  12989. ForceSuspenseFallback
  12990. )
  12991. );
  12992. return workInProgress.child;
  12993. }
  12994. row = row.sibling;
  12995. }
  12996. }
  12997. } else {
  12998. cutOffTailIfNeeded(renderState, false);
  12999. } // Next we're going to render the tail.
  13000. } else {
  13001. // Append the rendered row to the child list.
  13002. if (!didSuspendAlready) {
  13003. var _suspended = findFirstSuspended(renderedTail);
  13004. if (_suspended !== null) {
  13005. workInProgress.effectTag |= DidCapture;
  13006. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  13007. // get lost if this row ends up dropped during a second pass.
  13008. var _newThennables = _suspended.updateQueue;
  13009. if (_newThennables !== null) {
  13010. workInProgress.updateQueue = _newThennables;
  13011. workInProgress.effectTag |= Update;
  13012. }
  13013. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  13014. if (
  13015. renderState.tail === null &&
  13016. renderState.tailMode === "hidden" &&
  13017. !renderedTail.alternate
  13018. ) {
  13019. // We need to delete the row we just rendered.
  13020. // Reset the effect list to what it was before we rendered this
  13021. // child. The nested children have already appended themselves.
  13022. var lastEffect = (workInProgress.lastEffect =
  13023. renderState.lastEffect); // Remove any effects that were appended after this point.
  13024. if (lastEffect !== null) {
  13025. lastEffect.nextEffect = null;
  13026. } // We're done.
  13027. return null;
  13028. }
  13029. } else if (
  13030. // The time it took to render last row is greater than time until
  13031. // the expiration.
  13032. now() * 2 - renderState.renderingStartTime >
  13033. renderState.tailExpiration &&
  13034. renderExpirationTime > Never
  13035. ) {
  13036. // We have now passed our CPU deadline and we'll just give up further
  13037. // attempts to render the main content and only render fallbacks.
  13038. // The assumption is that this is usually faster.
  13039. workInProgress.effectTag |= DidCapture;
  13040. didSuspendAlready = true;
  13041. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  13042. // to get it started back up to attempt the next item. If we can show
  13043. // them, then they really have the same priority as this render.
  13044. // So we'll pick it back up the very next render pass once we've had
  13045. // an opportunity to yield for paint.
  13046. var nextPriority = renderExpirationTime - 1;
  13047. workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
  13048. {
  13049. markSpawnedWork(nextPriority);
  13050. }
  13051. }
  13052. }
  13053. if (renderState.isBackwards) {
  13054. // The effect list of the backwards tail will have been added
  13055. // to the end. This breaks the guarantee that life-cycles fire in
  13056. // sibling order but that isn't a strong guarantee promised by React.
  13057. // Especially since these might also just pop in during future commits.
  13058. // Append to the beginning of the list.
  13059. renderedTail.sibling = workInProgress.child;
  13060. workInProgress.child = renderedTail;
  13061. } else {
  13062. var previousSibling = renderState.last;
  13063. if (previousSibling !== null) {
  13064. previousSibling.sibling = renderedTail;
  13065. } else {
  13066. workInProgress.child = renderedTail;
  13067. }
  13068. renderState.last = renderedTail;
  13069. }
  13070. }
  13071. if (renderState.tail !== null) {
  13072. // We still have tail rows to render.
  13073. if (renderState.tailExpiration === 0) {
  13074. // Heuristic for how long we're willing to spend rendering rows
  13075. // until we just give up and show what we have so far.
  13076. var TAIL_EXPIRATION_TIMEOUT_MS = 500;
  13077. renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS; // TODO: This is meant to mimic the train model or JND but this
  13078. // is a per component value. It should really be since the start
  13079. // of the total render or last commit. Consider using something like
  13080. // globalMostRecentFallbackTime. That doesn't account for being
  13081. // suspended for part of the time or when it's a new render.
  13082. // It should probably use a global start time value instead.
  13083. } // Pop a row.
  13084. var next = renderState.tail;
  13085. renderState.rendering = next;
  13086. renderState.tail = next.sibling;
  13087. renderState.lastEffect = workInProgress.lastEffect;
  13088. renderState.renderingStartTime = now();
  13089. next.sibling = null; // Restore the context.
  13090. // TODO: We can probably just avoid popping it instead and only
  13091. // setting it the first time we go from not suspended to suspended.
  13092. var suspenseContext = suspenseStackCursor.current;
  13093. if (didSuspendAlready) {
  13094. suspenseContext = setShallowSuspenseContext(
  13095. suspenseContext,
  13096. ForceSuspenseFallback
  13097. );
  13098. } else {
  13099. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  13100. }
  13101. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  13102. return next;
  13103. }
  13104. return null;
  13105. }
  13106. }
  13107. {
  13108. throw Error(
  13109. "Unknown unit of work tag (" +
  13110. workInProgress.tag +
  13111. "). This error is likely caused by a bug in React. Please file an issue."
  13112. );
  13113. }
  13114. }
  13115. function unwindWork(workInProgress, renderExpirationTime) {
  13116. switch (workInProgress.tag) {
  13117. case ClassComponent: {
  13118. var Component = workInProgress.type;
  13119. if (isContextProvider(Component)) {
  13120. popContext(workInProgress);
  13121. }
  13122. var effectTag = workInProgress.effectTag;
  13123. if (effectTag & ShouldCapture) {
  13124. workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;
  13125. return workInProgress;
  13126. }
  13127. return null;
  13128. }
  13129. case HostRoot: {
  13130. popHostContainer(workInProgress);
  13131. popTopLevelContextObject(workInProgress);
  13132. var _effectTag = workInProgress.effectTag;
  13133. if (!((_effectTag & DidCapture) === NoEffect)) {
  13134. throw Error(
  13135. "The root failed to unmount after an error. This is likely a bug in React. Please file an issue."
  13136. );
  13137. }
  13138. workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture;
  13139. return workInProgress;
  13140. }
  13141. case HostComponent: {
  13142. // TODO: popHydrationState
  13143. popHostContext(workInProgress);
  13144. return null;
  13145. }
  13146. case SuspenseComponent: {
  13147. popSuspenseContext(workInProgress);
  13148. var _effectTag2 = workInProgress.effectTag;
  13149. if (_effectTag2 & ShouldCapture) {
  13150. workInProgress.effectTag = (_effectTag2 & ~ShouldCapture) | DidCapture; // Captured a suspense effect. Re-render the boundary.
  13151. return workInProgress;
  13152. }
  13153. return null;
  13154. }
  13155. case SuspenseListComponent: {
  13156. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  13157. // caught by a nested boundary. If not, it should bubble through.
  13158. return null;
  13159. }
  13160. case HostPortal:
  13161. popHostContainer(workInProgress);
  13162. return null;
  13163. case ContextProvider:
  13164. popProvider(workInProgress);
  13165. return null;
  13166. default:
  13167. return null;
  13168. }
  13169. }
  13170. function unwindInterruptedWork(interruptedWork) {
  13171. switch (interruptedWork.tag) {
  13172. case ClassComponent: {
  13173. var childContextTypes = interruptedWork.type.childContextTypes;
  13174. if (childContextTypes !== null && childContextTypes !== undefined) {
  13175. popContext(interruptedWork);
  13176. }
  13177. break;
  13178. }
  13179. case HostRoot: {
  13180. popHostContainer(interruptedWork);
  13181. popTopLevelContextObject(interruptedWork);
  13182. break;
  13183. }
  13184. case HostComponent: {
  13185. popHostContext(interruptedWork);
  13186. break;
  13187. }
  13188. case HostPortal:
  13189. popHostContainer(interruptedWork);
  13190. break;
  13191. case SuspenseComponent:
  13192. popSuspenseContext(interruptedWork);
  13193. break;
  13194. case SuspenseListComponent:
  13195. popSuspenseContext(interruptedWork);
  13196. break;
  13197. case ContextProvider:
  13198. popProvider(interruptedWork);
  13199. break;
  13200. }
  13201. }
  13202. function createCapturedValue(value, source) {
  13203. // If the value is an error, call this function immediately after it is thrown
  13204. // so the stack is accurate.
  13205. return {
  13206. value: value,
  13207. source: source,
  13208. stack: getStackByFiberInDevAndProd(source)
  13209. };
  13210. }
  13211. // Module provided by RN:
  13212. if (
  13213. !(
  13214. typeof ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog ===
  13215. "function"
  13216. )
  13217. ) {
  13218. throw Error(
  13219. "Expected ReactFiberErrorDialog.showErrorDialog to be a function."
  13220. );
  13221. }
  13222. function showErrorDialog(capturedError) {
  13223. return ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog(
  13224. capturedError
  13225. );
  13226. }
  13227. function logCapturedError(capturedError) {
  13228. var logError = showErrorDialog(capturedError); // Allow injected showErrorDialog() to prevent default console.error logging.
  13229. // This enables renderers like ReactNative to better manage redbox behavior.
  13230. if (logError === false) {
  13231. return;
  13232. }
  13233. var error = capturedError.error;
  13234. {
  13235. var componentName = capturedError.componentName,
  13236. componentStack = capturedError.componentStack,
  13237. errorBoundaryName = capturedError.errorBoundaryName,
  13238. errorBoundaryFound = capturedError.errorBoundaryFound,
  13239. willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
  13240. // `preventDefault()` in window `error` handler.
  13241. // We record this information as an expando on the error.
  13242. if (error != null && error._suppressLogging) {
  13243. if (errorBoundaryFound && willRetry) {
  13244. // The error is recoverable and was silenced.
  13245. // Ignore it and don't print the stack addendum.
  13246. // This is handy for testing error boundaries without noise.
  13247. return;
  13248. } // The error is fatal. Since the silencing might have
  13249. // been accidental, we'll surface it anyway.
  13250. // However, the browser would have silenced the original error
  13251. // so we'll print it first, and then print the stack addendum.
  13252. console["error"](error); // Don't transform to our wrapper
  13253. // For a more detailed description of this block, see:
  13254. // https://github.com/facebook/react/pull/13384
  13255. }
  13256. var componentNameMessage = componentName
  13257. ? "The above error occurred in the <" + componentName + "> component:"
  13258. : "The above error occurred in one of your React components:";
  13259. var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
  13260. if (errorBoundaryFound && errorBoundaryName) {
  13261. if (willRetry) {
  13262. errorBoundaryMessage =
  13263. "React will try to recreate this component tree from scratch " +
  13264. ("using the error boundary you provided, " + errorBoundaryName + ".");
  13265. } else {
  13266. errorBoundaryMessage =
  13267. "This error was initially handled by the error boundary " +
  13268. errorBoundaryName +
  13269. ".\n" +
  13270. "Recreating the tree from scratch failed so React will unmount the tree.";
  13271. }
  13272. } else {
  13273. errorBoundaryMessage =
  13274. "Consider adding an error boundary to your tree to customize error handling behavior.\n" +
  13275. "Visit https://fb.me/react-error-boundaries to learn more about error boundaries.";
  13276. }
  13277. var combinedMessage =
  13278. "" +
  13279. componentNameMessage +
  13280. componentStack +
  13281. "\n\n" +
  13282. ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  13283. // We don't include the original error message and JS stack because the browser
  13284. // has already printed it. Even if the application swallows the error, it is still
  13285. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  13286. console["error"](combinedMessage); // Don't transform to our wrapper
  13287. }
  13288. }
  13289. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  13290. {
  13291. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  13292. }
  13293. var PossiblyWeakSet = typeof WeakSet === "function" ? WeakSet : Set;
  13294. function logError(boundary, errorInfo) {
  13295. var source = errorInfo.source;
  13296. var stack = errorInfo.stack;
  13297. if (stack === null && source !== null) {
  13298. stack = getStackByFiberInDevAndProd(source);
  13299. }
  13300. var capturedError = {
  13301. componentName: source !== null ? getComponentName(source.type) : null,
  13302. componentStack: stack !== null ? stack : "",
  13303. error: errorInfo.value,
  13304. errorBoundary: null,
  13305. errorBoundaryName: null,
  13306. errorBoundaryFound: false,
  13307. willRetry: false
  13308. };
  13309. if (boundary !== null && boundary.tag === ClassComponent) {
  13310. capturedError.errorBoundary = boundary.stateNode;
  13311. capturedError.errorBoundaryName = getComponentName(boundary.type);
  13312. capturedError.errorBoundaryFound = true;
  13313. capturedError.willRetry = true;
  13314. }
  13315. try {
  13316. logCapturedError(capturedError);
  13317. } catch (e) {
  13318. // This method must not throw, or React internal state will get messed up.
  13319. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  13320. // we want to report this error outside of the normal stack as a last resort.
  13321. // https://github.com/facebook/react/issues/13188
  13322. setTimeout(function() {
  13323. throw e;
  13324. });
  13325. }
  13326. }
  13327. var callComponentWillUnmountWithTimer = function(current, instance) {
  13328. startPhaseTimer(current, "componentWillUnmount");
  13329. instance.props = current.memoizedProps;
  13330. instance.state = current.memoizedState;
  13331. {
  13332. instance.componentWillUnmount();
  13333. }
  13334. stopPhaseTimer();
  13335. }; // Capture errors so they don't interrupt unmounting.
  13336. function safelyCallComponentWillUnmount(current, instance) {
  13337. {
  13338. invokeGuardedCallback(
  13339. null,
  13340. callComponentWillUnmountWithTimer,
  13341. null,
  13342. current,
  13343. instance
  13344. );
  13345. if (hasCaughtError()) {
  13346. var unmountError = clearCaughtError();
  13347. captureCommitPhaseError(current, unmountError);
  13348. }
  13349. }
  13350. }
  13351. function safelyDetachRef(current) {
  13352. var ref = current.ref;
  13353. if (ref !== null) {
  13354. if (typeof ref === "function") {
  13355. {
  13356. invokeGuardedCallback(null, ref, null, null);
  13357. if (hasCaughtError()) {
  13358. var refError = clearCaughtError();
  13359. captureCommitPhaseError(current, refError);
  13360. }
  13361. }
  13362. } else {
  13363. ref.current = null;
  13364. }
  13365. }
  13366. }
  13367. function safelyCallDestroy(current, destroy) {
  13368. {
  13369. invokeGuardedCallback(null, destroy, null);
  13370. if (hasCaughtError()) {
  13371. var error = clearCaughtError();
  13372. captureCommitPhaseError(current, error);
  13373. }
  13374. }
  13375. }
  13376. function commitBeforeMutationLifeCycles(current, finishedWork) {
  13377. switch (finishedWork.tag) {
  13378. case FunctionComponent:
  13379. case ForwardRef:
  13380. case SimpleMemoComponent:
  13381. case Block: {
  13382. return;
  13383. }
  13384. case ClassComponent: {
  13385. if (finishedWork.effectTag & Snapshot) {
  13386. if (current !== null) {
  13387. var prevProps = current.memoizedProps;
  13388. var prevState = current.memoizedState;
  13389. startPhaseTimer(finishedWork, "getSnapshotBeforeUpdate");
  13390. var instance = finishedWork.stateNode; // We could update instance props and state here,
  13391. // but instead we rely on them being set during last render.
  13392. // TODO: revisit this when we implement resuming.
  13393. {
  13394. if (
  13395. finishedWork.type === finishedWork.elementType &&
  13396. !didWarnAboutReassigningProps
  13397. ) {
  13398. if (instance.props !== finishedWork.memoizedProps) {
  13399. error(
  13400. "Expected %s props to match memoized props before " +
  13401. "getSnapshotBeforeUpdate. " +
  13402. "This might either be because of a bug in React, or because " +
  13403. "a component reassigns its own `this.props`. " +
  13404. "Please file an issue.",
  13405. getComponentName(finishedWork.type) || "instance"
  13406. );
  13407. }
  13408. if (instance.state !== finishedWork.memoizedState) {
  13409. error(
  13410. "Expected %s state to match memoized state before " +
  13411. "getSnapshotBeforeUpdate. " +
  13412. "This might either be because of a bug in React, or because " +
  13413. "a component reassigns its own `this.state`. " +
  13414. "Please file an issue.",
  13415. getComponentName(finishedWork.type) || "instance"
  13416. );
  13417. }
  13418. }
  13419. }
  13420. var snapshot = instance.getSnapshotBeforeUpdate(
  13421. finishedWork.elementType === finishedWork.type
  13422. ? prevProps
  13423. : resolveDefaultProps(finishedWork.type, prevProps),
  13424. prevState
  13425. );
  13426. {
  13427. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  13428. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  13429. didWarnSet.add(finishedWork.type);
  13430. error(
  13431. "%s.getSnapshotBeforeUpdate(): A snapshot value (or null) " +
  13432. "must be returned. You have returned undefined.",
  13433. getComponentName(finishedWork.type)
  13434. );
  13435. }
  13436. }
  13437. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  13438. stopPhaseTimer();
  13439. }
  13440. }
  13441. return;
  13442. }
  13443. case HostRoot:
  13444. case HostComponent:
  13445. case HostText:
  13446. case HostPortal:
  13447. case IncompleteClassComponent:
  13448. // Nothing to do for these component types
  13449. return;
  13450. }
  13451. {
  13452. throw Error(
  13453. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13454. );
  13455. }
  13456. }
  13457. function commitHookEffectListUnmount(tag, finishedWork) {
  13458. var updateQueue = finishedWork.updateQueue;
  13459. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13460. if (lastEffect !== null) {
  13461. var firstEffect = lastEffect.next;
  13462. var effect = firstEffect;
  13463. do {
  13464. if ((effect.tag & tag) === tag) {
  13465. // Unmount
  13466. var destroy = effect.destroy;
  13467. effect.destroy = undefined;
  13468. if (destroy !== undefined) {
  13469. destroy();
  13470. }
  13471. }
  13472. effect = effect.next;
  13473. } while (effect !== firstEffect);
  13474. }
  13475. }
  13476. function commitHookEffectListMount(tag, finishedWork) {
  13477. var updateQueue = finishedWork.updateQueue;
  13478. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13479. if (lastEffect !== null) {
  13480. var firstEffect = lastEffect.next;
  13481. var effect = firstEffect;
  13482. do {
  13483. if ((effect.tag & tag) === tag) {
  13484. // Mount
  13485. var create = effect.create;
  13486. effect.destroy = create();
  13487. {
  13488. var destroy = effect.destroy;
  13489. if (destroy !== undefined && typeof destroy !== "function") {
  13490. var addendum = void 0;
  13491. if (destroy === null) {
  13492. addendum =
  13493. " You returned null. If your effect does not require clean " +
  13494. "up, return undefined (or nothing).";
  13495. } else if (typeof destroy.then === "function") {
  13496. addendum =
  13497. "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " +
  13498. "Instead, write the async function inside your effect " +
  13499. "and call it immediately:\n\n" +
  13500. "useEffect(() => {\n" +
  13501. " async function fetchData() {\n" +
  13502. " // You can await here\n" +
  13503. " const response = await MyAPI.getData(someId);\n" +
  13504. " // ...\n" +
  13505. " }\n" +
  13506. " fetchData();\n" +
  13507. "}, [someId]); // Or [] if effect doesn't need props or state\n\n" +
  13508. "Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching";
  13509. } else {
  13510. addendum = " You returned: " + destroy;
  13511. }
  13512. error(
  13513. "An effect function must not return anything besides a function, " +
  13514. "which is used for clean-up.%s%s",
  13515. addendum,
  13516. getStackByFiberInDevAndProd(finishedWork)
  13517. );
  13518. }
  13519. }
  13520. }
  13521. effect = effect.next;
  13522. } while (effect !== firstEffect);
  13523. }
  13524. }
  13525. function commitPassiveHookEffects(finishedWork) {
  13526. if ((finishedWork.effectTag & Passive) !== NoEffect) {
  13527. switch (finishedWork.tag) {
  13528. case FunctionComponent:
  13529. case ForwardRef:
  13530. case SimpleMemoComponent:
  13531. case Block: {
  13532. // TODO (#17945) We should call all passive destroy functions (for all fibers)
  13533. // before calling any create functions. The current approach only serializes
  13534. // these for a single fiber.
  13535. {
  13536. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
  13537. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  13538. }
  13539. break;
  13540. }
  13541. }
  13542. }
  13543. }
  13544. function commitLifeCycles(
  13545. finishedRoot,
  13546. current,
  13547. finishedWork,
  13548. committedExpirationTime
  13549. ) {
  13550. switch (finishedWork.tag) {
  13551. case FunctionComponent:
  13552. case ForwardRef:
  13553. case SimpleMemoComponent:
  13554. case Block: {
  13555. // At this point layout effects have already been destroyed (during mutation phase).
  13556. // This is done to prevent sibling component effects from interfering with each other,
  13557. // e.g. a destroy function in one component should never override a ref set
  13558. // by a create function in another component during the same commit.
  13559. {
  13560. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  13561. }
  13562. return;
  13563. }
  13564. case ClassComponent: {
  13565. var instance = finishedWork.stateNode;
  13566. if (finishedWork.effectTag & Update) {
  13567. if (current === null) {
  13568. startPhaseTimer(finishedWork, "componentDidMount"); // We could update instance props and state here,
  13569. // but instead we rely on them being set during last render.
  13570. // TODO: revisit this when we implement resuming.
  13571. {
  13572. if (
  13573. finishedWork.type === finishedWork.elementType &&
  13574. !didWarnAboutReassigningProps
  13575. ) {
  13576. if (instance.props !== finishedWork.memoizedProps) {
  13577. error(
  13578. "Expected %s props to match memoized props before " +
  13579. "componentDidMount. " +
  13580. "This might either be because of a bug in React, or because " +
  13581. "a component reassigns its own `this.props`. " +
  13582. "Please file an issue.",
  13583. getComponentName(finishedWork.type) || "instance"
  13584. );
  13585. }
  13586. if (instance.state !== finishedWork.memoizedState) {
  13587. error(
  13588. "Expected %s state to match memoized state before " +
  13589. "componentDidMount. " +
  13590. "This might either be because of a bug in React, or because " +
  13591. "a component reassigns its own `this.state`. " +
  13592. "Please file an issue.",
  13593. getComponentName(finishedWork.type) || "instance"
  13594. );
  13595. }
  13596. }
  13597. }
  13598. {
  13599. instance.componentDidMount();
  13600. }
  13601. stopPhaseTimer();
  13602. } else {
  13603. var prevProps =
  13604. finishedWork.elementType === finishedWork.type
  13605. ? current.memoizedProps
  13606. : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  13607. var prevState = current.memoizedState;
  13608. startPhaseTimer(finishedWork, "componentDidUpdate"); // We could update instance props and state here,
  13609. // but instead we rely on them being set during last render.
  13610. // TODO: revisit this when we implement resuming.
  13611. {
  13612. if (
  13613. finishedWork.type === finishedWork.elementType &&
  13614. !didWarnAboutReassigningProps
  13615. ) {
  13616. if (instance.props !== finishedWork.memoizedProps) {
  13617. error(
  13618. "Expected %s props to match memoized props before " +
  13619. "componentDidUpdate. " +
  13620. "This might either be because of a bug in React, or because " +
  13621. "a component reassigns its own `this.props`. " +
  13622. "Please file an issue.",
  13623. getComponentName(finishedWork.type) || "instance"
  13624. );
  13625. }
  13626. if (instance.state !== finishedWork.memoizedState) {
  13627. error(
  13628. "Expected %s state to match memoized state before " +
  13629. "componentDidUpdate. " +
  13630. "This might either be because of a bug in React, or because " +
  13631. "a component reassigns its own `this.state`. " +
  13632. "Please file an issue.",
  13633. getComponentName(finishedWork.type) || "instance"
  13634. );
  13635. }
  13636. }
  13637. }
  13638. {
  13639. instance.componentDidUpdate(
  13640. prevProps,
  13641. prevState,
  13642. instance.__reactInternalSnapshotBeforeUpdate
  13643. );
  13644. }
  13645. stopPhaseTimer();
  13646. }
  13647. }
  13648. var updateQueue = finishedWork.updateQueue;
  13649. if (updateQueue !== null) {
  13650. {
  13651. if (
  13652. finishedWork.type === finishedWork.elementType &&
  13653. !didWarnAboutReassigningProps
  13654. ) {
  13655. if (instance.props !== finishedWork.memoizedProps) {
  13656. error(
  13657. "Expected %s props to match memoized props before " +
  13658. "processing the update queue. " +
  13659. "This might either be because of a bug in React, or because " +
  13660. "a component reassigns its own `this.props`. " +
  13661. "Please file an issue.",
  13662. getComponentName(finishedWork.type) || "instance"
  13663. );
  13664. }
  13665. if (instance.state !== finishedWork.memoizedState) {
  13666. error(
  13667. "Expected %s state to match memoized state before " +
  13668. "processing the update queue. " +
  13669. "This might either be because of a bug in React, or because " +
  13670. "a component reassigns its own `this.state`. " +
  13671. "Please file an issue.",
  13672. getComponentName(finishedWork.type) || "instance"
  13673. );
  13674. }
  13675. }
  13676. } // We could update instance props and state here,
  13677. // but instead we rely on them being set during last render.
  13678. // TODO: revisit this when we implement resuming.
  13679. commitUpdateQueue(finishedWork, updateQueue, instance);
  13680. }
  13681. return;
  13682. }
  13683. case HostRoot: {
  13684. var _updateQueue = finishedWork.updateQueue;
  13685. if (_updateQueue !== null) {
  13686. var _instance = null;
  13687. if (finishedWork.child !== null) {
  13688. switch (finishedWork.child.tag) {
  13689. case HostComponent:
  13690. _instance = getPublicInstance(finishedWork.child.stateNode);
  13691. break;
  13692. case ClassComponent:
  13693. _instance = finishedWork.child.stateNode;
  13694. break;
  13695. }
  13696. }
  13697. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  13698. }
  13699. return;
  13700. }
  13701. case HostComponent: {
  13702. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  13703. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  13704. // These effects should only be committed when components are first mounted,
  13705. // aka when there is no current/alternate.
  13706. if (current === null && finishedWork.effectTag & Update) {
  13707. var type = finishedWork.type;
  13708. var props = finishedWork.memoizedProps;
  13709. }
  13710. return;
  13711. }
  13712. case HostText: {
  13713. // We have no life-cycles associated with text.
  13714. return;
  13715. }
  13716. case HostPortal: {
  13717. // We have no life-cycles associated with portals.
  13718. return;
  13719. }
  13720. case Profiler: {
  13721. {
  13722. var _finishedWork$memoize2 = finishedWork.memoizedProps,
  13723. onCommit = _finishedWork$memoize2.onCommit,
  13724. onRender = _finishedWork$memoize2.onRender;
  13725. var effectDuration = finishedWork.stateNode.effectDuration;
  13726. var commitTime = getCommitTime();
  13727. if (typeof onRender === "function") {
  13728. {
  13729. onRender(
  13730. finishedWork.memoizedProps.id,
  13731. current === null ? "mount" : "update",
  13732. finishedWork.actualDuration,
  13733. finishedWork.treeBaseDuration,
  13734. finishedWork.actualStartTime,
  13735. commitTime,
  13736. finishedRoot.memoizedInteractions
  13737. );
  13738. }
  13739. }
  13740. }
  13741. return;
  13742. }
  13743. case SuspenseComponent: {
  13744. return;
  13745. }
  13746. case SuspenseListComponent:
  13747. case IncompleteClassComponent:
  13748. case FundamentalComponent:
  13749. case ScopeComponent:
  13750. return;
  13751. }
  13752. {
  13753. throw Error(
  13754. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13755. );
  13756. }
  13757. }
  13758. function hideOrUnhideAllChildren(finishedWork, isHidden) {
  13759. {
  13760. // We only have the top Fiber that was inserted but we need to recurse down its
  13761. // children to find all the terminal nodes.
  13762. var node = finishedWork;
  13763. while (true) {
  13764. if (node.tag === HostComponent) {
  13765. var instance = node.stateNode;
  13766. if (isHidden) {
  13767. hideInstance(instance);
  13768. } else {
  13769. unhideInstance(node.stateNode, node.memoizedProps);
  13770. }
  13771. } else if (node.tag === HostText) {
  13772. var _instance3 = node.stateNode;
  13773. if (isHidden) {
  13774. hideTextInstance();
  13775. } else {
  13776. unhideTextInstance(_instance3, node.memoizedProps);
  13777. }
  13778. } else if (
  13779. node.tag === SuspenseComponent &&
  13780. node.memoizedState !== null &&
  13781. node.memoizedState.dehydrated === null
  13782. ) {
  13783. // Found a nested Suspense component that timed out. Skip over the
  13784. // primary child fragment, which should remain hidden.
  13785. var fallbackChildFragment = node.child.sibling;
  13786. fallbackChildFragment.return = node;
  13787. node = fallbackChildFragment;
  13788. continue;
  13789. } else if (node.child !== null) {
  13790. node.child.return = node;
  13791. node = node.child;
  13792. continue;
  13793. }
  13794. if (node === finishedWork) {
  13795. return;
  13796. }
  13797. while (node.sibling === null) {
  13798. if (node.return === null || node.return === finishedWork) {
  13799. return;
  13800. }
  13801. node = node.return;
  13802. }
  13803. node.sibling.return = node.return;
  13804. node = node.sibling;
  13805. }
  13806. }
  13807. }
  13808. function commitAttachRef(finishedWork) {
  13809. var ref = finishedWork.ref;
  13810. if (ref !== null) {
  13811. var instance = finishedWork.stateNode;
  13812. var instanceToUse;
  13813. switch (finishedWork.tag) {
  13814. case HostComponent:
  13815. instanceToUse = getPublicInstance(instance);
  13816. break;
  13817. default:
  13818. instanceToUse = instance;
  13819. } // Moved outside to ensure DCE works with this flag
  13820. if (typeof ref === "function") {
  13821. ref(instanceToUse);
  13822. } else {
  13823. {
  13824. if (!ref.hasOwnProperty("current")) {
  13825. error(
  13826. "Unexpected ref object provided for %s. " +
  13827. "Use either a ref-setter function or React.createRef().%s",
  13828. getComponentName(finishedWork.type),
  13829. getStackByFiberInDevAndProd(finishedWork)
  13830. );
  13831. }
  13832. }
  13833. ref.current = instanceToUse;
  13834. }
  13835. }
  13836. }
  13837. function commitDetachRef(current) {
  13838. var currentRef = current.ref;
  13839. if (currentRef !== null) {
  13840. if (typeof currentRef === "function") {
  13841. currentRef(null);
  13842. } else {
  13843. currentRef.current = null;
  13844. }
  13845. }
  13846. } // User-originating errors (lifecycles and refs) should not interrupt
  13847. // deletion, so don't let them throw. Host-originating errors should
  13848. // interrupt deletion, so it's okay
  13849. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  13850. onCommitUnmount(current);
  13851. switch (current.tag) {
  13852. case FunctionComponent:
  13853. case ForwardRef:
  13854. case MemoComponent:
  13855. case SimpleMemoComponent:
  13856. case Block: {
  13857. var updateQueue = current.updateQueue;
  13858. if (updateQueue !== null) {
  13859. var lastEffect = updateQueue.lastEffect;
  13860. if (lastEffect !== null) {
  13861. var firstEffect = lastEffect.next;
  13862. {
  13863. // When the owner fiber is deleted, the destroy function of a passive
  13864. // effect hook is called during the synchronous commit phase. This is
  13865. // a concession to implementation complexity. Calling it in the
  13866. // passive effect phase (like they usually are, when dependencies
  13867. // change during an update) would require either traversing the
  13868. // children of the deleted fiber again, or including unmount effects
  13869. // as part of the fiber effect list.
  13870. //
  13871. // Because this is during the sync commit phase, we need to change
  13872. // the priority.
  13873. //
  13874. // TODO: Reconsider this implementation trade off.
  13875. var priorityLevel =
  13876. renderPriorityLevel > NormalPriority
  13877. ? NormalPriority
  13878. : renderPriorityLevel;
  13879. runWithPriority(priorityLevel, function() {
  13880. var effect = firstEffect;
  13881. do {
  13882. var _effect3 = effect,
  13883. _destroy = _effect3.destroy,
  13884. _tag = _effect3.tag;
  13885. if (_destroy !== undefined) {
  13886. {
  13887. safelyCallDestroy(current, _destroy);
  13888. }
  13889. }
  13890. effect = effect.next;
  13891. } while (effect !== firstEffect);
  13892. });
  13893. }
  13894. }
  13895. }
  13896. return;
  13897. }
  13898. case ClassComponent: {
  13899. safelyDetachRef(current);
  13900. var instance = current.stateNode;
  13901. if (typeof instance.componentWillUnmount === "function") {
  13902. safelyCallComponentWillUnmount(current, instance);
  13903. }
  13904. return;
  13905. }
  13906. case HostComponent: {
  13907. safelyDetachRef(current);
  13908. return;
  13909. }
  13910. case HostPortal: {
  13911. // TODO: this is recursive.
  13912. // We are also not using this parent because
  13913. // the portal will get pushed immediately.
  13914. {
  13915. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  13916. }
  13917. return;
  13918. }
  13919. case FundamentalComponent: {
  13920. return;
  13921. }
  13922. case DehydratedFragment: {
  13923. return;
  13924. }
  13925. case ScopeComponent: {
  13926. return;
  13927. }
  13928. }
  13929. }
  13930. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  13931. // While we're inside a removed host node we don't want to call
  13932. // removeChild on the inner nodes because they're removed by the top
  13933. // call anyway. We also want to call componentWillUnmount on all
  13934. // composites before this host node is removed from the tree. Therefore
  13935. // we do an inner loop while we're still inside the host node.
  13936. var node = root;
  13937. while (true) {
  13938. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
  13939. // Skip portals because commitUnmount() currently visits them recursively.
  13940. if (
  13941. node.child !== null && // If we use mutation we drill down into portals using commitUnmount above.
  13942. // If we don't use mutation we drill down into portals here instead.
  13943. node.tag !== HostPortal
  13944. ) {
  13945. node.child.return = node;
  13946. node = node.child;
  13947. continue;
  13948. }
  13949. if (node === root) {
  13950. return;
  13951. }
  13952. while (node.sibling === null) {
  13953. if (node.return === null || node.return === root) {
  13954. return;
  13955. }
  13956. node = node.return;
  13957. }
  13958. node.sibling.return = node.return;
  13959. node = node.sibling;
  13960. }
  13961. }
  13962. function detachFiber(current) {
  13963. var alternate = current.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
  13964. // should clear the child pointer of the parent alternate to let this
  13965. // get GC:ed but we don't know which for sure which parent is the current
  13966. // one so we'll settle for GC:ing the subtree of this child. This child
  13967. // itself will be GC:ed when the parent updates the next time.
  13968. current.return = null;
  13969. current.child = null;
  13970. current.memoizedState = null;
  13971. current.updateQueue = null;
  13972. current.dependencies = null;
  13973. current.alternate = null;
  13974. current.firstEffect = null;
  13975. current.lastEffect = null;
  13976. current.pendingProps = null;
  13977. current.memoizedProps = null;
  13978. current.stateNode = null;
  13979. if (alternate !== null) {
  13980. detachFiber(alternate);
  13981. }
  13982. }
  13983. function getHostParentFiber(fiber) {
  13984. var parent = fiber.return;
  13985. while (parent !== null) {
  13986. if (isHostParent(parent)) {
  13987. return parent;
  13988. }
  13989. parent = parent.return;
  13990. }
  13991. {
  13992. throw Error(
  13993. "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue."
  13994. );
  13995. }
  13996. }
  13997. function isHostParent(fiber) {
  13998. return (
  13999. fiber.tag === HostComponent ||
  14000. fiber.tag === HostRoot ||
  14001. fiber.tag === HostPortal
  14002. );
  14003. }
  14004. function getHostSibling(fiber) {
  14005. // We're going to search forward into the tree until we find a sibling host
  14006. // node. Unfortunately, if multiple insertions are done in a row we have to
  14007. // search past them. This leads to exponential search for the next sibling.
  14008. // TODO: Find a more efficient way to do this.
  14009. var node = fiber;
  14010. siblings: while (true) {
  14011. // If we didn't find anything, let's try the next sibling.
  14012. while (node.sibling === null) {
  14013. if (node.return === null || isHostParent(node.return)) {
  14014. // If we pop out of the root or hit the parent the fiber we are the
  14015. // last sibling.
  14016. return null;
  14017. }
  14018. node = node.return;
  14019. }
  14020. node.sibling.return = node.return;
  14021. node = node.sibling;
  14022. while (
  14023. node.tag !== HostComponent &&
  14024. node.tag !== HostText &&
  14025. node.tag !== DehydratedFragment
  14026. ) {
  14027. // If it is not host node and, we might have a host node inside it.
  14028. // Try to search down until we find one.
  14029. if (node.effectTag & Placement) {
  14030. // If we don't have a child, try the siblings instead.
  14031. continue siblings;
  14032. } // If we don't have a child, try the siblings instead.
  14033. // We also skip portals because they are not part of this host tree.
  14034. if (node.child === null || node.tag === HostPortal) {
  14035. continue siblings;
  14036. } else {
  14037. node.child.return = node;
  14038. node = node.child;
  14039. }
  14040. } // Check if this host node is stable or about to be placed.
  14041. if (!(node.effectTag & Placement)) {
  14042. // Found it!
  14043. return node.stateNode;
  14044. }
  14045. }
  14046. }
  14047. function commitPlacement(finishedWork) {
  14048. var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
  14049. var parent;
  14050. var isContainer;
  14051. var parentStateNode = parentFiber.stateNode;
  14052. switch (parentFiber.tag) {
  14053. case HostComponent:
  14054. parent = parentStateNode;
  14055. isContainer = false;
  14056. break;
  14057. case HostRoot:
  14058. parent = parentStateNode.containerInfo;
  14059. isContainer = true;
  14060. break;
  14061. case HostPortal:
  14062. parent = parentStateNode.containerInfo;
  14063. isContainer = true;
  14064. break;
  14065. case FundamentalComponent:
  14066. // eslint-disable-next-line-no-fallthrough
  14067. default: {
  14068. throw Error(
  14069. "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue."
  14070. );
  14071. }
  14072. }
  14073. if (parentFiber.effectTag & ContentReset) {
  14074. parentFiber.effectTag &= ~ContentReset;
  14075. }
  14076. var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
  14077. // children to find all the terminal nodes.
  14078. if (isContainer) {
  14079. insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
  14080. } else {
  14081. insertOrAppendPlacementNode(finishedWork, before, parent);
  14082. }
  14083. }
  14084. function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
  14085. var tag = node.tag;
  14086. var isHost = tag === HostComponent || tag === HostText;
  14087. if (isHost || enableFundamentalAPI) {
  14088. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  14089. if (before) {
  14090. insertInContainerBefore(parent);
  14091. } else {
  14092. appendChildToContainer(parent, stateNode);
  14093. }
  14094. } else if (tag === HostPortal);
  14095. else {
  14096. var child = node.child;
  14097. if (child !== null) {
  14098. insertOrAppendPlacementNodeIntoContainer(child, before, parent);
  14099. var sibling = child.sibling;
  14100. while (sibling !== null) {
  14101. insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
  14102. sibling = sibling.sibling;
  14103. }
  14104. }
  14105. }
  14106. }
  14107. function insertOrAppendPlacementNode(node, before, parent) {
  14108. var tag = node.tag;
  14109. var isHost = tag === HostComponent || tag === HostText;
  14110. if (isHost || enableFundamentalAPI) {
  14111. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  14112. if (before) {
  14113. insertBefore(parent, stateNode, before);
  14114. } else {
  14115. appendChild(parent, stateNode);
  14116. }
  14117. } else if (tag === HostPortal);
  14118. else {
  14119. var child = node.child;
  14120. if (child !== null) {
  14121. insertOrAppendPlacementNode(child, before, parent);
  14122. var sibling = child.sibling;
  14123. while (sibling !== null) {
  14124. insertOrAppendPlacementNode(sibling, before, parent);
  14125. sibling = sibling.sibling;
  14126. }
  14127. }
  14128. }
  14129. }
  14130. function unmountHostComponents(finishedRoot, current, renderPriorityLevel) {
  14131. // We only have the top Fiber that was deleted but we need to recurse down its
  14132. // children to find all the terminal nodes.
  14133. var node = current; // Each iteration, currentParent is populated with node's host parent if not
  14134. // currentParentIsValid.
  14135. var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
  14136. var currentParent;
  14137. var currentParentIsContainer;
  14138. while (true) {
  14139. if (!currentParentIsValid) {
  14140. var parent = node.return;
  14141. findParent: while (true) {
  14142. if (!(parent !== null)) {
  14143. throw Error(
  14144. "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue."
  14145. );
  14146. }
  14147. var parentStateNode = parent.stateNode;
  14148. switch (parent.tag) {
  14149. case HostComponent:
  14150. currentParent = parentStateNode;
  14151. currentParentIsContainer = false;
  14152. break findParent;
  14153. case HostRoot:
  14154. currentParent = parentStateNode.containerInfo;
  14155. currentParentIsContainer = true;
  14156. break findParent;
  14157. case HostPortal:
  14158. currentParent = parentStateNode.containerInfo;
  14159. currentParentIsContainer = true;
  14160. break findParent;
  14161. }
  14162. parent = parent.return;
  14163. }
  14164. currentParentIsValid = true;
  14165. }
  14166. if (node.tag === HostComponent || node.tag === HostText) {
  14167. commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
  14168. // node from the tree.
  14169. if (currentParentIsContainer) {
  14170. removeChildFromContainer(currentParent, node.stateNode);
  14171. } else {
  14172. removeChild(currentParent, node.stateNode);
  14173. } // Don't visit children because we already visited them.
  14174. } else if (node.tag === HostPortal) {
  14175. if (node.child !== null) {
  14176. // When we go into a portal, it becomes the parent to remove from.
  14177. // We will reassign it back when we pop the portal on the way up.
  14178. currentParent = node.stateNode.containerInfo;
  14179. currentParentIsContainer = true; // Visit children because portals might contain host components.
  14180. node.child.return = node;
  14181. node = node.child;
  14182. continue;
  14183. }
  14184. } else {
  14185. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
  14186. if (node.child !== null) {
  14187. node.child.return = node;
  14188. node = node.child;
  14189. continue;
  14190. }
  14191. }
  14192. if (node === current) {
  14193. return;
  14194. }
  14195. while (node.sibling === null) {
  14196. if (node.return === null || node.return === current) {
  14197. return;
  14198. }
  14199. node = node.return;
  14200. if (node.tag === HostPortal) {
  14201. // When we go out of the portal, we need to restore the parent.
  14202. // Since we don't keep a stack of them, we will search for it.
  14203. currentParentIsValid = false;
  14204. }
  14205. }
  14206. node.sibling.return = node.return;
  14207. node = node.sibling;
  14208. }
  14209. }
  14210. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  14211. {
  14212. // Recursively delete all host nodes from the parent.
  14213. // Detach refs and call componentWillUnmount() on the whole subtree.
  14214. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  14215. }
  14216. detachFiber(current);
  14217. }
  14218. function commitWork(current, finishedWork) {
  14219. switch (finishedWork.tag) {
  14220. case FunctionComponent:
  14221. case ForwardRef:
  14222. case MemoComponent:
  14223. case SimpleMemoComponent:
  14224. case Block: {
  14225. // Layout effects are destroyed during the mutation phase so that all
  14226. // destroy functions for all fibers are called before any create functions.
  14227. // This prevents sibling component effects from interfering with each other,
  14228. // e.g. a destroy function in one component should never override a ref set
  14229. // by a create function in another component during the same commit.
  14230. {
  14231. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  14232. }
  14233. return;
  14234. }
  14235. case ClassComponent: {
  14236. return;
  14237. }
  14238. case HostComponent: {
  14239. var instance = finishedWork.stateNode;
  14240. if (instance != null) {
  14241. // Commit the work prepared earlier.
  14242. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  14243. // as the newProps. The updatePayload will contain the real change in
  14244. // this case.
  14245. var oldProps = current !== null ? current.memoizedProps : newProps;
  14246. var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
  14247. var updatePayload = finishedWork.updateQueue;
  14248. finishedWork.updateQueue = null;
  14249. if (updatePayload !== null) {
  14250. commitUpdate(instance, updatePayload, type, oldProps, newProps);
  14251. }
  14252. }
  14253. return;
  14254. }
  14255. case HostText: {
  14256. if (!(finishedWork.stateNode !== null)) {
  14257. throw Error(
  14258. "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue."
  14259. );
  14260. }
  14261. var textInstance = finishedWork.stateNode;
  14262. var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  14263. // as the newProps. The updatePayload will contain the real change in
  14264. // this case.
  14265. var oldText = current !== null ? current.memoizedProps : newText;
  14266. commitTextUpdate(textInstance, oldText, newText);
  14267. return;
  14268. }
  14269. case HostRoot: {
  14270. return;
  14271. }
  14272. case Profiler: {
  14273. return;
  14274. }
  14275. case SuspenseComponent: {
  14276. commitSuspenseComponent(finishedWork);
  14277. attachSuspenseRetryListeners(finishedWork);
  14278. return;
  14279. }
  14280. case SuspenseListComponent: {
  14281. attachSuspenseRetryListeners(finishedWork);
  14282. return;
  14283. }
  14284. case IncompleteClassComponent: {
  14285. return;
  14286. }
  14287. }
  14288. {
  14289. throw Error(
  14290. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  14291. );
  14292. }
  14293. }
  14294. function commitSuspenseComponent(finishedWork) {
  14295. var newState = finishedWork.memoizedState;
  14296. var newDidTimeout;
  14297. var primaryChildParent = finishedWork;
  14298. if (newState === null) {
  14299. newDidTimeout = false;
  14300. } else {
  14301. newDidTimeout = true;
  14302. primaryChildParent = finishedWork.child;
  14303. markCommitTimeOfFallback();
  14304. }
  14305. if (primaryChildParent !== null) {
  14306. hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
  14307. }
  14308. }
  14309. function attachSuspenseRetryListeners(finishedWork) {
  14310. // If this boundary just timed out, then it will have a set of thenables.
  14311. // For each thenable, attach a listener so that when it resolves, React
  14312. // attempts to re-render the boundary in the primary (pre-timeout) state.
  14313. var thenables = finishedWork.updateQueue;
  14314. if (thenables !== null) {
  14315. finishedWork.updateQueue = null;
  14316. var retryCache = finishedWork.stateNode;
  14317. if (retryCache === null) {
  14318. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  14319. }
  14320. thenables.forEach(function(thenable) {
  14321. // Memoize using the boundary fiber to prevent redundant listeners.
  14322. var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
  14323. if (!retryCache.has(thenable)) {
  14324. {
  14325. if (thenable.__reactDoNotTraceInteractions !== true) {
  14326. retry = tracing.unstable_wrap(retry);
  14327. }
  14328. }
  14329. retryCache.add(thenable);
  14330. thenable.then(retry, retry);
  14331. }
  14332. });
  14333. }
  14334. }
  14335. function commitResetTextContent(current) {
  14336. resetTextContent(current.stateNode);
  14337. }
  14338. var PossiblyWeakMap = typeof WeakMap === "function" ? WeakMap : Map;
  14339. function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
  14340. var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
  14341. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  14342. // being called "element".
  14343. update.payload = {
  14344. element: null
  14345. };
  14346. var error = errorInfo.value;
  14347. update.callback = function() {
  14348. onUncaughtError(error);
  14349. logError(fiber, errorInfo);
  14350. };
  14351. return update;
  14352. }
  14353. function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
  14354. var update = createUpdate(expirationTime, null);
  14355. update.tag = CaptureUpdate;
  14356. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  14357. if (typeof getDerivedStateFromError === "function") {
  14358. var error$1 = errorInfo.value;
  14359. update.payload = function() {
  14360. logError(fiber, errorInfo);
  14361. return getDerivedStateFromError(error$1);
  14362. };
  14363. }
  14364. var inst = fiber.stateNode;
  14365. if (inst !== null && typeof inst.componentDidCatch === "function") {
  14366. update.callback = function callback() {
  14367. {
  14368. markFailedErrorBoundaryForHotReloading(fiber);
  14369. }
  14370. if (typeof getDerivedStateFromError !== "function") {
  14371. // To preserve the preexisting retry behavior of error boundaries,
  14372. // we keep track of which ones already failed during this batch.
  14373. // This gets reset before we yield back to the browser.
  14374. // TODO: Warn in strict mode if getDerivedStateFromError is
  14375. // not defined.
  14376. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  14377. logError(fiber, errorInfo);
  14378. }
  14379. var error$1 = errorInfo.value;
  14380. var stack = errorInfo.stack;
  14381. this.componentDidCatch(error$1, {
  14382. componentStack: stack !== null ? stack : ""
  14383. });
  14384. {
  14385. if (typeof getDerivedStateFromError !== "function") {
  14386. // If componentDidCatch is the only error boundary method defined,
  14387. // then it needs to call setState to recover from errors.
  14388. // If no state update is scheduled then the boundary will swallow the error.
  14389. if (fiber.expirationTime !== Sync) {
  14390. error(
  14391. "%s: Error boundaries should implement getDerivedStateFromError(). " +
  14392. "In that method, return a state update to display an error message or fallback UI.",
  14393. getComponentName(fiber.type) || "Unknown"
  14394. );
  14395. }
  14396. }
  14397. }
  14398. };
  14399. } else {
  14400. update.callback = function() {
  14401. markFailedErrorBoundaryForHotReloading(fiber);
  14402. };
  14403. }
  14404. return update;
  14405. }
  14406. function attachPingListener(root, renderExpirationTime, thenable) {
  14407. // Attach a listener to the promise to "ping" the root and retry. But
  14408. // only if one does not already exist for the current render expiration
  14409. // time (which acts like a "thread ID" here).
  14410. var pingCache = root.pingCache;
  14411. var threadIDs;
  14412. if (pingCache === null) {
  14413. pingCache = root.pingCache = new PossiblyWeakMap();
  14414. threadIDs = new Set();
  14415. pingCache.set(thenable, threadIDs);
  14416. } else {
  14417. threadIDs = pingCache.get(thenable);
  14418. if (threadIDs === undefined) {
  14419. threadIDs = new Set();
  14420. pingCache.set(thenable, threadIDs);
  14421. }
  14422. }
  14423. if (!threadIDs.has(renderExpirationTime)) {
  14424. // Memoize using the thread ID to prevent redundant listeners.
  14425. threadIDs.add(renderExpirationTime);
  14426. var ping = pingSuspendedRoot.bind(
  14427. null,
  14428. root,
  14429. thenable,
  14430. renderExpirationTime
  14431. );
  14432. thenable.then(ping, ping);
  14433. }
  14434. }
  14435. function throwException(
  14436. root,
  14437. returnFiber,
  14438. sourceFiber,
  14439. value,
  14440. renderExpirationTime
  14441. ) {
  14442. // The source fiber did not complete.
  14443. sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
  14444. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  14445. if (
  14446. value !== null &&
  14447. typeof value === "object" &&
  14448. typeof value.then === "function"
  14449. ) {
  14450. // This is a thenable.
  14451. var thenable = value;
  14452. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  14453. // Reset the memoizedState to what it was before we attempted
  14454. // to render it.
  14455. var currentSource = sourceFiber.alternate;
  14456. if (currentSource) {
  14457. sourceFiber.updateQueue = currentSource.updateQueue;
  14458. sourceFiber.memoizedState = currentSource.memoizedState;
  14459. sourceFiber.expirationTime = currentSource.expirationTime;
  14460. } else {
  14461. sourceFiber.updateQueue = null;
  14462. sourceFiber.memoizedState = null;
  14463. }
  14464. }
  14465. var hasInvisibleParentBoundary = hasSuspenseContext(
  14466. suspenseStackCursor.current,
  14467. InvisibleParentSuspenseContext
  14468. ); // Schedule the nearest Suspense to re-render the timed out view.
  14469. var _workInProgress = returnFiber;
  14470. do {
  14471. if (
  14472. _workInProgress.tag === SuspenseComponent &&
  14473. shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)
  14474. ) {
  14475. // Found the nearest boundary.
  14476. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  14477. // attach another listener to flip the boundary back to its normal state.
  14478. var thenables = _workInProgress.updateQueue;
  14479. if (thenables === null) {
  14480. var updateQueue = new Set();
  14481. updateQueue.add(thenable);
  14482. _workInProgress.updateQueue = updateQueue;
  14483. } else {
  14484. thenables.add(thenable);
  14485. } // If the boundary is outside of blocking mode, we should *not*
  14486. // suspend the commit. Pretend as if the suspended component rendered
  14487. // null and keep rendering. In the commit phase, we'll schedule a
  14488. // subsequent synchronous update to re-render the Suspense.
  14489. //
  14490. // Note: It doesn't matter whether the component that suspended was
  14491. // inside a blocking mode tree. If the Suspense is outside of it, we
  14492. // should *not* suspend the commit.
  14493. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  14494. _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
  14495. // But we shouldn't call any lifecycle methods or callbacks. Remove
  14496. // all lifecycle effect tags.
  14497. sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
  14498. if (sourceFiber.tag === ClassComponent) {
  14499. var currentSourceFiber = sourceFiber.alternate;
  14500. if (currentSourceFiber === null) {
  14501. // This is a new mount. Change the tag so it's not mistaken for a
  14502. // completed class component. For example, we should not call
  14503. // componentWillUnmount if it is deleted.
  14504. sourceFiber.tag = IncompleteClassComponent;
  14505. } else {
  14506. // When we try rendering again, we should not reuse the current fiber,
  14507. // since it's known to be in an inconsistent state. Use a force update to
  14508. // prevent a bail out.
  14509. var update = createUpdate(Sync, null);
  14510. update.tag = ForceUpdate;
  14511. enqueueUpdate(sourceFiber, update);
  14512. }
  14513. } // The source fiber did not complete. Mark it with Sync priority to
  14514. // indicate that it still has pending work.
  14515. sourceFiber.expirationTime = Sync; // Exit without suspending.
  14516. return;
  14517. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  14518. // with the normal suspend path.
  14519. //
  14520. // After this we'll use a set of heuristics to determine whether this
  14521. // render pass will run to completion or restart or "suspend" the commit.
  14522. // The actual logic for this is spread out in different places.
  14523. //
  14524. // This first principle is that if we're going to suspend when we complete
  14525. // a root, then we should also restart if we get an update or ping that
  14526. // might unsuspend it, and vice versa. The only reason to suspend is
  14527. // because you think you might want to restart before committing. However,
  14528. // it doesn't make sense to restart only while in the period we're suspended.
  14529. //
  14530. // Restarting too aggressively is also not good because it starves out any
  14531. // intermediate loading state. So we use heuristics to determine when.
  14532. // Suspense Heuristics
  14533. //
  14534. // If nothing threw a Promise or all the same fallbacks are already showing,
  14535. // then don't suspend/restart.
  14536. //
  14537. // If this is an initial render of a new tree of Suspense boundaries and
  14538. // those trigger a fallback, then don't suspend/restart. We want to ensure
  14539. // that we can show the initial loading state as quickly as possible.
  14540. //
  14541. // If we hit a "Delayed" case, such as when we'd switch from content back into
  14542. // a fallback, then we should always suspend/restart. SuspenseConfig applies to
  14543. // this case. If none is defined, JND is used instead.
  14544. //
  14545. // If we're already showing a fallback and it gets "retried", allowing us to show
  14546. // another level, but there's still an inner boundary that would show a fallback,
  14547. // then we suspend/restart for 500ms since the last time we showed a fallback
  14548. // anywhere in the tree. This effectively throttles progressive loading into a
  14549. // consistent train of commits. This also gives us an opportunity to restart to
  14550. // get to the completed state slightly earlier.
  14551. //
  14552. // If there's ambiguity due to batching it's resolved in preference of:
  14553. // 1) "delayed", 2) "initial render", 3) "retry".
  14554. //
  14555. // We want to ensure that a "busy" state doesn't get force committed. We want to
  14556. // ensure that new initial loading states can commit as soon as possible.
  14557. attachPingListener(root, renderExpirationTime, thenable);
  14558. _workInProgress.effectTag |= ShouldCapture;
  14559. _workInProgress.expirationTime = renderExpirationTime;
  14560. return;
  14561. } // This boundary already captured during this render. Continue to the next
  14562. // boundary.
  14563. _workInProgress = _workInProgress.return;
  14564. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  14565. // TODO: Use invariant so the message is stripped in prod?
  14566. value = new Error(
  14567. (getComponentName(sourceFiber.type) || "A React component") +
  14568. " suspended while rendering, but no fallback UI was specified.\n" +
  14569. "\n" +
  14570. "Add a <Suspense fallback=...> component higher in the tree to " +
  14571. "provide a loading indicator or placeholder to display." +
  14572. getStackByFiberInDevAndProd(sourceFiber)
  14573. );
  14574. } // We didn't find a boundary that could handle this type of exception. Start
  14575. // over and traverse parent path again, this time treating the exception
  14576. // as an error.
  14577. renderDidError();
  14578. value = createCapturedValue(value, sourceFiber);
  14579. var workInProgress = returnFiber;
  14580. do {
  14581. switch (workInProgress.tag) {
  14582. case HostRoot: {
  14583. var _errorInfo = value;
  14584. workInProgress.effectTag |= ShouldCapture;
  14585. workInProgress.expirationTime = renderExpirationTime;
  14586. var _update = createRootErrorUpdate(
  14587. workInProgress,
  14588. _errorInfo,
  14589. renderExpirationTime
  14590. );
  14591. enqueueCapturedUpdate(workInProgress, _update);
  14592. return;
  14593. }
  14594. case ClassComponent:
  14595. // Capture and retry
  14596. var errorInfo = value;
  14597. var ctor = workInProgress.type;
  14598. var instance = workInProgress.stateNode;
  14599. if (
  14600. (workInProgress.effectTag & DidCapture) === NoEffect &&
  14601. (typeof ctor.getDerivedStateFromError === "function" ||
  14602. (instance !== null &&
  14603. typeof instance.componentDidCatch === "function" &&
  14604. !isAlreadyFailedLegacyErrorBoundary(instance)))
  14605. ) {
  14606. workInProgress.effectTag |= ShouldCapture;
  14607. workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
  14608. var _update2 = createClassErrorUpdate(
  14609. workInProgress,
  14610. errorInfo,
  14611. renderExpirationTime
  14612. );
  14613. enqueueCapturedUpdate(workInProgress, _update2);
  14614. return;
  14615. }
  14616. break;
  14617. }
  14618. workInProgress = workInProgress.return;
  14619. } while (workInProgress !== null);
  14620. }
  14621. var ceil = Math.ceil;
  14622. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  14623. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  14624. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  14625. var NoContext =
  14626. /* */
  14627. 0;
  14628. var BatchedContext =
  14629. /* */
  14630. 1;
  14631. var DiscreteEventContext =
  14632. /* */
  14633. 4;
  14634. var LegacyUnbatchedContext =
  14635. /* */
  14636. 8;
  14637. var RenderContext =
  14638. /* */
  14639. 16;
  14640. var CommitContext =
  14641. /* */
  14642. 32;
  14643. var RootIncomplete = 0;
  14644. var RootFatalErrored = 1;
  14645. var RootErrored = 2;
  14646. var RootSuspended = 3;
  14647. var RootSuspendedWithDelay = 4;
  14648. var RootCompleted = 5;
  14649. // Describes where we are in the React execution stack
  14650. var executionContext = NoContext; // The root we're working on
  14651. var workInProgressRoot = null; // The fiber we're working on
  14652. var workInProgress = null; // The expiration time we're rendering
  14653. var renderExpirationTime$1 = NoWork; // Whether to root completed, errored, suspended, etc.
  14654. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  14655. var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
  14656. // This is conceptually a time stamp but expressed in terms of an ExpirationTime
  14657. // because we deal mostly with expiration times in the hot path, so this avoids
  14658. // the conversion happening in the hot path.
  14659. var workInProgressRootLatestProcessedExpirationTime = Sync;
  14660. var workInProgressRootLatestSuspenseTimeout = Sync;
  14661. var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
  14662. // includes unprocessed updates, not work in bailed out children.
  14663. var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
  14664. // This flag determines if it might be worthwhile to restart if an opportunity
  14665. // happens latere.
  14666. var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
  14667. // model where we don't commit new loading states in too quick succession.
  14668. var globalMostRecentFallbackTime = 0;
  14669. var FALLBACK_THROTTLE_MS = 500;
  14670. var nextEffect = null;
  14671. var hasUncaughtError = false;
  14672. var firstUncaughtError = null;
  14673. var legacyErrorBoundariesThatAlreadyFailed = null;
  14674. var rootDoesHavePassiveEffects = false;
  14675. var rootWithPendingPassiveEffects = null;
  14676. var pendingPassiveEffectsRenderPriority = NoPriority;
  14677. var pendingPassiveEffectsExpirationTime = NoWork;
  14678. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  14679. var NESTED_UPDATE_LIMIT = 50;
  14680. var nestedUpdateCount = 0;
  14681. var rootWithNestedUpdates = null;
  14682. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  14683. var nestedPassiveUpdateCount = 0;
  14684. var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
  14685. // during the commit phase. This enables them to be traced across components
  14686. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  14687. // hydration or SuspenseList.
  14688. var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
  14689. // time). However, if two updates are scheduled within the same event, we
  14690. // should treat their start times as simultaneous, even if the actual clock
  14691. // time has advanced between the first and second call.
  14692. // In other words, because expiration times determine how updates are batched,
  14693. // we want all updates of like priority that occur within the same event to
  14694. // receive the same expiration time. Otherwise we get tearing.
  14695. var currentEventTime = NoWork;
  14696. function requestCurrentTimeForUpdate() {
  14697. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  14698. // We're inside React, so it's fine to read the actual time.
  14699. return msToExpirationTime(now());
  14700. } // We're not inside React, so we may be in the middle of a browser event.
  14701. if (currentEventTime !== NoWork) {
  14702. // Use the same start time for all updates until we enter React again.
  14703. return currentEventTime;
  14704. } // This is the first update since React yielded. Compute a new start time.
  14705. currentEventTime = msToExpirationTime(now());
  14706. return currentEventTime;
  14707. }
  14708. function getCurrentTime() {
  14709. return msToExpirationTime(now());
  14710. }
  14711. function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
  14712. var mode = fiber.mode;
  14713. if ((mode & BlockingMode) === NoMode) {
  14714. return Sync;
  14715. }
  14716. var priorityLevel = getCurrentPriorityLevel();
  14717. if ((mode & ConcurrentMode) === NoMode) {
  14718. return priorityLevel === ImmediatePriority ? Sync : Batched;
  14719. }
  14720. if ((executionContext & RenderContext) !== NoContext) {
  14721. // Use whatever time we're already rendering
  14722. // TODO: Should there be a way to opt out, like with `runWithPriority`?
  14723. return renderExpirationTime$1;
  14724. }
  14725. var expirationTime;
  14726. if (suspenseConfig !== null) {
  14727. // Compute an expiration time based on the Suspense timeout.
  14728. expirationTime = computeSuspenseExpiration(
  14729. currentTime,
  14730. suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION
  14731. );
  14732. } else {
  14733. // Compute an expiration time based on the Scheduler priority.
  14734. switch (priorityLevel) {
  14735. case ImmediatePriority:
  14736. expirationTime = Sync;
  14737. break;
  14738. case UserBlockingPriority:
  14739. // TODO: Rename this to computeUserBlockingExpiration
  14740. expirationTime = computeInteractiveExpiration(currentTime);
  14741. break;
  14742. case NormalPriority:
  14743. case LowPriority:
  14744. // TODO: Handle LowPriority
  14745. // TODO: Rename this to... something better.
  14746. expirationTime = computeAsyncExpiration(currentTime);
  14747. break;
  14748. case IdlePriority:
  14749. expirationTime = Idle;
  14750. break;
  14751. default: {
  14752. throw Error("Expected a valid priority level");
  14753. }
  14754. }
  14755. } // If we're in the middle of rendering a tree, do not update at the same
  14756. // expiration time that is already rendering.
  14757. // TODO: We shouldn't have to do this if the update is on a different root.
  14758. // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
  14759. // the root when we check for this condition.
  14760. if (
  14761. workInProgressRoot !== null &&
  14762. expirationTime === renderExpirationTime$1
  14763. ) {
  14764. // This is a trick to move this update into a separate batch
  14765. expirationTime -= 1;
  14766. }
  14767. return expirationTime;
  14768. }
  14769. function scheduleUpdateOnFiber(fiber, expirationTime) {
  14770. checkForNestedUpdates();
  14771. warnAboutRenderPhaseUpdatesInDEV(fiber);
  14772. var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
  14773. if (root === null) {
  14774. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  14775. return;
  14776. }
  14777. checkForInterruption(fiber, expirationTime);
  14778. recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
  14779. // priority as an argument to that function and this one.
  14780. var priorityLevel = getCurrentPriorityLevel();
  14781. if (expirationTime === Sync) {
  14782. if (
  14783. // Check if we're inside unbatchedUpdates
  14784. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  14785. (executionContext & (RenderContext | CommitContext)) === NoContext
  14786. ) {
  14787. // Register pending interactions on the root to avoid losing traced interaction data.
  14788. schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  14789. // root inside of batchedUpdates should be synchronous, but layout updates
  14790. // should be deferred until the end of the batch.
  14791. performSyncWorkOnRoot(root);
  14792. } else {
  14793. ensureRootIsScheduled(root);
  14794. schedulePendingInteractions(root, expirationTime);
  14795. if (executionContext === NoContext) {
  14796. // Flush the synchronous work now, unless we're already working or inside
  14797. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  14798. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  14799. // without immediately flushing it. We only do this for user-initiated
  14800. // updates, to preserve historical behavior of legacy mode.
  14801. flushSyncCallbackQueue();
  14802. }
  14803. }
  14804. } else {
  14805. ensureRootIsScheduled(root);
  14806. schedulePendingInteractions(root, expirationTime);
  14807. }
  14808. if (
  14809. (executionContext & DiscreteEventContext) !== NoContext && // Only updates at user-blocking priority or greater are considered
  14810. // discrete, even inside a discrete event.
  14811. (priorityLevel === UserBlockingPriority ||
  14812. priorityLevel === ImmediatePriority)
  14813. ) {
  14814. // This is the result of a discrete event. Track the lowest priority
  14815. // discrete update per root so we can flush them early, if needed.
  14816. if (rootsWithPendingDiscreteUpdates === null) {
  14817. rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
  14818. } else {
  14819. var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
  14820. if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
  14821. rootsWithPendingDiscreteUpdates.set(root, expirationTime);
  14822. }
  14823. }
  14824. }
  14825. }
  14826. var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
  14827. // work without treating it as a typical update that originates from an event;
  14828. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  14829. // on a fiber.
  14830. function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
  14831. // Update the source fiber's expiration time
  14832. if (fiber.expirationTime < expirationTime) {
  14833. fiber.expirationTime = expirationTime;
  14834. }
  14835. var alternate = fiber.alternate;
  14836. if (alternate !== null && alternate.expirationTime < expirationTime) {
  14837. alternate.expirationTime = expirationTime;
  14838. } // Walk the parent path to the root and update the child expiration time.
  14839. var node = fiber.return;
  14840. var root = null;
  14841. if (node === null && fiber.tag === HostRoot) {
  14842. root = fiber.stateNode;
  14843. } else {
  14844. while (node !== null) {
  14845. alternate = node.alternate;
  14846. if (node.childExpirationTime < expirationTime) {
  14847. node.childExpirationTime = expirationTime;
  14848. if (
  14849. alternate !== null &&
  14850. alternate.childExpirationTime < expirationTime
  14851. ) {
  14852. alternate.childExpirationTime = expirationTime;
  14853. }
  14854. } else if (
  14855. alternate !== null &&
  14856. alternate.childExpirationTime < expirationTime
  14857. ) {
  14858. alternate.childExpirationTime = expirationTime;
  14859. }
  14860. if (node.return === null && node.tag === HostRoot) {
  14861. root = node.stateNode;
  14862. break;
  14863. }
  14864. node = node.return;
  14865. }
  14866. }
  14867. if (root !== null) {
  14868. if (workInProgressRoot === root) {
  14869. // Received an update to a tree that's in the middle of rendering. Mark
  14870. // that's unprocessed work on this root.
  14871. markUnprocessedUpdateTime(expirationTime);
  14872. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  14873. // The root already suspended with a delay, which means this render
  14874. // definitely won't finish. Since we have a new update, let's mark it as
  14875. // suspended now, right before marking the incoming update. This has the
  14876. // effect of interrupting the current render and switching to the update.
  14877. // TODO: This happens to work when receiving an update during the render
  14878. // phase, because of the trick inside computeExpirationForFiber to
  14879. // subtract 1 from `renderExpirationTime` to move it into a
  14880. // separate bucket. But we should probably model it with an exception,
  14881. // using the same mechanism we use to force hydration of a subtree.
  14882. // TODO: This does not account for low pri updates that were already
  14883. // scheduled before the root started rendering. Need to track the next
  14884. // pending expiration time (perhaps by backtracking the return path) and
  14885. // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
  14886. markRootSuspendedAtTime(root, renderExpirationTime$1);
  14887. }
  14888. } // Mark that the root has a pending update.
  14889. markRootUpdatedAtTime(root, expirationTime);
  14890. }
  14891. return root;
  14892. }
  14893. function getNextRootExpirationTimeToWorkOn(root) {
  14894. // Determines the next expiration time that the root should render, taking
  14895. // into account levels that may be suspended, or levels that may have
  14896. // received a ping.
  14897. var lastExpiredTime = root.lastExpiredTime;
  14898. if (lastExpiredTime !== NoWork) {
  14899. return lastExpiredTime;
  14900. } // "Pending" refers to any update that hasn't committed yet, including if it
  14901. // suspended. The "suspended" range is therefore a subset.
  14902. var firstPendingTime = root.firstPendingTime;
  14903. if (!isRootSuspendedAtTime(root, firstPendingTime)) {
  14904. // The highest priority pending time is not suspended. Let's work on that.
  14905. return firstPendingTime;
  14906. } // If the first pending time is suspended, check if there's a lower priority
  14907. // pending level that we know about. Or check if we received a ping. Work
  14908. // on whichever is higher priority.
  14909. var lastPingedTime = root.lastPingedTime;
  14910. var nextKnownPendingLevel = root.nextKnownPendingLevel;
  14911. var nextLevel =
  14912. lastPingedTime > nextKnownPendingLevel
  14913. ? lastPingedTime
  14914. : nextKnownPendingLevel;
  14915. if (nextLevel <= Idle && firstPendingTime !== nextLevel) {
  14916. // Don't work on Idle/Never priority unless everything else is committed.
  14917. return NoWork;
  14918. }
  14919. return nextLevel;
  14920. } // Use this function to schedule a task for a root. There's only one task per
  14921. // root; if a task was already scheduled, we'll check to make sure the
  14922. // expiration time of the existing task is the same as the expiration time of
  14923. // the next level that the root has work on. This function is called on every
  14924. // update, and right before exiting a task.
  14925. function ensureRootIsScheduled(root) {
  14926. var lastExpiredTime = root.lastExpiredTime;
  14927. if (lastExpiredTime !== NoWork) {
  14928. // Special case: Expired work should flush synchronously.
  14929. root.callbackExpirationTime = Sync;
  14930. root.callbackPriority = ImmediatePriority;
  14931. root.callbackNode = scheduleSyncCallback(
  14932. performSyncWorkOnRoot.bind(null, root)
  14933. );
  14934. return;
  14935. }
  14936. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  14937. var existingCallbackNode = root.callbackNode;
  14938. if (expirationTime === NoWork) {
  14939. // There's nothing to work on.
  14940. if (existingCallbackNode !== null) {
  14941. root.callbackNode = null;
  14942. root.callbackExpirationTime = NoWork;
  14943. root.callbackPriority = NoPriority;
  14944. }
  14945. return;
  14946. } // TODO: If this is an update, we already read the current time. Pass the
  14947. // time as an argument.
  14948. var currentTime = requestCurrentTimeForUpdate();
  14949. var priorityLevel = inferPriorityFromExpirationTime(
  14950. currentTime,
  14951. expirationTime
  14952. ); // If there's an existing render task, confirm it has the correct priority and
  14953. // expiration time. Otherwise, we'll cancel it and schedule a new one.
  14954. if (existingCallbackNode !== null) {
  14955. var existingCallbackPriority = root.callbackPriority;
  14956. var existingCallbackExpirationTime = root.callbackExpirationTime;
  14957. if (
  14958. // Callback must have the exact same expiration time.
  14959. existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
  14960. existingCallbackPriority >= priorityLevel
  14961. ) {
  14962. // Existing callback is sufficient.
  14963. return;
  14964. } // Need to schedule a new task.
  14965. // TODO: Instead of scheduling a new task, we should be able to change the
  14966. // priority of the existing one.
  14967. cancelCallback(existingCallbackNode);
  14968. }
  14969. root.callbackExpirationTime = expirationTime;
  14970. root.callbackPriority = priorityLevel;
  14971. var callbackNode;
  14972. if (expirationTime === Sync) {
  14973. // Sync React callbacks are scheduled on a special internal queue
  14974. callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  14975. } else {
  14976. callbackNode = scheduleCallback(
  14977. priorityLevel,
  14978. performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
  14979. // ordering because tasks are processed in timeout order.
  14980. {
  14981. timeout: expirationTimeToMs(expirationTime) - now()
  14982. }
  14983. );
  14984. }
  14985. root.callbackNode = callbackNode;
  14986. } // This is the entry point for every concurrent task, i.e. anything that
  14987. // goes through Scheduler.
  14988. function performConcurrentWorkOnRoot(root, didTimeout) {
  14989. // Since we know we're in a React event, we can clear the current
  14990. // event time. The next update will compute a new event time.
  14991. currentEventTime = NoWork; // Check if the render expired.
  14992. if (didTimeout) {
  14993. // The render task took too long to complete. Mark the current time as
  14994. // expired to synchronously render all expired work in a single batch.
  14995. var currentTime = requestCurrentTimeForUpdate();
  14996. markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
  14997. ensureRootIsScheduled(root);
  14998. return null;
  14999. } // Determine the next expiration time to work on, using the fields stored
  15000. // on the root.
  15001. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  15002. if (expirationTime === NoWork) {
  15003. return null;
  15004. }
  15005. var originalCallbackNode = root.callbackNode;
  15006. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15007. throw Error("Should not already be working.");
  15008. }
  15009. flushPassiveEffects();
  15010. var exitStatus = renderRootConcurrent(root, expirationTime);
  15011. if (exitStatus !== RootIncomplete) {
  15012. if (exitStatus === RootErrored) {
  15013. // If something threw an error, try rendering one more time. We'll
  15014. // render synchronously to block concurrent data mutations, and we'll
  15015. // render at Idle (or lower) so that all pending updates are included.
  15016. // If it still fails after the second attempt, we'll give up and commit
  15017. // the resulting tree.
  15018. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  15019. exitStatus = renderRootSync(root, expirationTime);
  15020. }
  15021. if (exitStatus === RootFatalErrored) {
  15022. var fatalError = workInProgressRootFatalError;
  15023. prepareFreshStack(root, expirationTime);
  15024. markRootSuspendedAtTime(root, expirationTime);
  15025. ensureRootIsScheduled(root);
  15026. throw fatalError;
  15027. } // We now have a consistent tree. The next step is either to commit it,
  15028. // or, if something suspended, wait to commit it after a timeout.
  15029. var finishedWork = (root.finishedWork = root.current.alternate);
  15030. root.finishedExpirationTime = expirationTime;
  15031. finishConcurrentRender(root, finishedWork, exitStatus, expirationTime);
  15032. }
  15033. ensureRootIsScheduled(root);
  15034. if (root.callbackNode === originalCallbackNode) {
  15035. // The task node scheduled for this root is the same one that's
  15036. // currently executed. Need to return a continuation.
  15037. return performConcurrentWorkOnRoot.bind(null, root);
  15038. }
  15039. return null;
  15040. }
  15041. function finishConcurrentRender(
  15042. root,
  15043. finishedWork,
  15044. exitStatus,
  15045. expirationTime
  15046. ) {
  15047. switch (exitStatus) {
  15048. case RootIncomplete:
  15049. case RootFatalErrored: {
  15050. {
  15051. throw Error("Root did not complete. This is a bug in React.");
  15052. }
  15053. }
  15054. // Flow knows about invariant, so it complains if I add a break
  15055. // statement, but eslint doesn't know about invariant, so it complains
  15056. // if I do. eslint-disable-next-line no-fallthrough
  15057. case RootErrored: {
  15058. // We should have already attempted to retry this tree. If we reached
  15059. // this point, it errored again. Commit it.
  15060. commitRoot(root);
  15061. break;
  15062. }
  15063. case RootSuspended: {
  15064. markRootSuspendedAtTime(root, expirationTime);
  15065. var lastSuspendedTime = root.lastSuspendedTime;
  15066. if (expirationTime === lastSuspendedTime) {
  15067. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  15068. } // We have an acceptable loading state. We need to figure out if we
  15069. // should immediately commit it or wait a bit.
  15070. // If we have processed new updates during this render, we may now
  15071. // have a new loading state ready. We want to ensure that we commit
  15072. // that as soon as possible.
  15073. var hasNotProcessedNewUpdates =
  15074. workInProgressRootLatestProcessedExpirationTime === Sync;
  15075. if (
  15076. hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
  15077. !IsThisRendererActing.current
  15078. ) {
  15079. // If we have not processed any new updates during this pass, then
  15080. // this is either a retry of an existing fallback state or a
  15081. // hidden tree. Hidden trees shouldn't be batched with other work
  15082. // and after that's fixed it can only be a retry. We're going to
  15083. // throttle committing retries so that we don't show too many
  15084. // loading states too quickly.
  15085. var msUntilTimeout =
  15086. globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  15087. if (msUntilTimeout > 10) {
  15088. if (workInProgressRootHasPendingPing) {
  15089. var lastPingedTime = root.lastPingedTime;
  15090. if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
  15091. // This render was pinged but we didn't get to restart
  15092. // earlier so try restarting now instead.
  15093. root.lastPingedTime = expirationTime;
  15094. prepareFreshStack(root, expirationTime);
  15095. break;
  15096. }
  15097. }
  15098. var nextTime = getNextRootExpirationTimeToWorkOn(root);
  15099. if (nextTime !== NoWork && nextTime !== expirationTime) {
  15100. // There's additional work on this root.
  15101. break;
  15102. }
  15103. if (
  15104. lastSuspendedTime !== NoWork &&
  15105. lastSuspendedTime !== expirationTime
  15106. ) {
  15107. // We should prefer to render the fallback of at the last
  15108. // suspended level. Ping the last suspended level to try
  15109. // rendering it again.
  15110. root.lastPingedTime = lastSuspendedTime;
  15111. break;
  15112. } // The render is suspended, it hasn't timed out, and there's no
  15113. // lower priority work to do. Instead of committing the fallback
  15114. // immediately, wait for more data to arrive.
  15115. root.timeoutHandle = scheduleTimeout(
  15116. commitRoot.bind(null, root),
  15117. msUntilTimeout
  15118. );
  15119. break;
  15120. }
  15121. } // The work expired. Commit immediately.
  15122. commitRoot(root);
  15123. break;
  15124. }
  15125. case RootSuspendedWithDelay: {
  15126. markRootSuspendedAtTime(root, expirationTime);
  15127. var _lastSuspendedTime = root.lastSuspendedTime;
  15128. if (expirationTime === _lastSuspendedTime) {
  15129. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  15130. }
  15131. {
  15132. // We're suspended in a state that should be avoided. We'll try to
  15133. // avoid committing it for as long as the timeouts let us.
  15134. if (workInProgressRootHasPendingPing) {
  15135. var _lastPingedTime = root.lastPingedTime;
  15136. if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
  15137. // This render was pinged but we didn't get to restart earlier
  15138. // so try restarting now instead.
  15139. root.lastPingedTime = expirationTime;
  15140. prepareFreshStack(root, expirationTime);
  15141. break;
  15142. }
  15143. }
  15144. var _nextTime = getNextRootExpirationTimeToWorkOn(root);
  15145. if (_nextTime !== NoWork && _nextTime !== expirationTime) {
  15146. // There's additional work on this root.
  15147. break;
  15148. }
  15149. if (
  15150. _lastSuspendedTime !== NoWork &&
  15151. _lastSuspendedTime !== expirationTime
  15152. ) {
  15153. // We should prefer to render the fallback of at the last
  15154. // suspended level. Ping the last suspended level to try
  15155. // rendering it again.
  15156. root.lastPingedTime = _lastSuspendedTime;
  15157. break;
  15158. }
  15159. var _msUntilTimeout;
  15160. if (workInProgressRootLatestSuspenseTimeout !== Sync) {
  15161. // We have processed a suspense config whose expiration time we
  15162. // can use as the timeout.
  15163. _msUntilTimeout =
  15164. expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
  15165. } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
  15166. // This should never normally happen because only new updates
  15167. // cause delayed states, so we should have processed something.
  15168. // However, this could also happen in an offscreen tree.
  15169. _msUntilTimeout = 0;
  15170. } else {
  15171. // If we don't have a suspense config, we're going to use a
  15172. // heuristic to determine how long we can suspend.
  15173. var eventTimeMs = inferTimeFromExpirationTime(
  15174. workInProgressRootLatestProcessedExpirationTime
  15175. );
  15176. var currentTimeMs = now();
  15177. var timeUntilExpirationMs =
  15178. expirationTimeToMs(expirationTime) - currentTimeMs;
  15179. var timeElapsed = currentTimeMs - eventTimeMs;
  15180. if (timeElapsed < 0) {
  15181. // We get this wrong some time since we estimate the time.
  15182. timeElapsed = 0;
  15183. }
  15184. _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
  15185. // event time is exact instead of inferred from expiration time
  15186. // we don't need this.
  15187. if (timeUntilExpirationMs < _msUntilTimeout) {
  15188. _msUntilTimeout = timeUntilExpirationMs;
  15189. }
  15190. } // Don't bother with a very short suspense time.
  15191. if (_msUntilTimeout > 10) {
  15192. // The render is suspended, it hasn't timed out, and there's no
  15193. // lower priority work to do. Instead of committing the fallback
  15194. // immediately, wait for more data to arrive.
  15195. root.timeoutHandle = scheduleTimeout(
  15196. commitRoot.bind(null, root),
  15197. _msUntilTimeout
  15198. );
  15199. break;
  15200. }
  15201. } // The work expired. Commit immediately.
  15202. commitRoot(root);
  15203. break;
  15204. }
  15205. case RootCompleted: {
  15206. // The work completed. Ready to commit.
  15207. if (
  15208. // do not delay if we're inside an act() scope
  15209. workInProgressRootLatestProcessedExpirationTime !== Sync &&
  15210. workInProgressRootCanSuspendUsingConfig !== null
  15211. ) {
  15212. // If we have exceeded the minimum loading delay, which probably
  15213. // means we have shown a spinner already, we might have to suspend
  15214. // a bit longer to ensure that the spinner is shown for
  15215. // enough time.
  15216. var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(
  15217. workInProgressRootLatestProcessedExpirationTime,
  15218. expirationTime,
  15219. workInProgressRootCanSuspendUsingConfig
  15220. );
  15221. if (_msUntilTimeout2 > 10) {
  15222. markRootSuspendedAtTime(root, expirationTime);
  15223. root.timeoutHandle = scheduleTimeout(
  15224. commitRoot.bind(null, root),
  15225. _msUntilTimeout2
  15226. );
  15227. break;
  15228. }
  15229. }
  15230. commitRoot(root);
  15231. break;
  15232. }
  15233. default: {
  15234. {
  15235. throw Error("Unknown root exit status.");
  15236. }
  15237. }
  15238. }
  15239. } // This is the entry point for synchronous tasks that don't go
  15240. // through Scheduler
  15241. function performSyncWorkOnRoot(root) {
  15242. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15243. throw Error("Should not already be working.");
  15244. }
  15245. flushPassiveEffects();
  15246. var lastExpiredTime = root.lastExpiredTime;
  15247. var expirationTime;
  15248. if (lastExpiredTime !== NoWork) {
  15249. // There's expired work on this root. Check if we have a partial tree
  15250. // that we can reuse.
  15251. if (
  15252. root === workInProgressRoot &&
  15253. renderExpirationTime$1 >= lastExpiredTime
  15254. ) {
  15255. // There's a partial tree with equal or greater than priority than the
  15256. // expired level. Finish rendering it before rendering the rest of the
  15257. // expired work.
  15258. expirationTime = renderExpirationTime$1;
  15259. } else {
  15260. // Start a fresh tree.
  15261. expirationTime = lastExpiredTime;
  15262. }
  15263. } else {
  15264. // There's no expired work. This must be a new, synchronous render.
  15265. expirationTime = Sync;
  15266. }
  15267. var exitStatus = renderRootSync(root, expirationTime);
  15268. if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
  15269. // If something threw an error, try rendering one more time. We'll
  15270. // render synchronously to block concurrent data mutations, and we'll
  15271. // render at Idle (or lower) so that all pending updates are included.
  15272. // If it still fails after the second attempt, we'll give up and commit
  15273. // the resulting tree.
  15274. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  15275. exitStatus = renderRootSync(root, expirationTime);
  15276. }
  15277. if (exitStatus === RootFatalErrored) {
  15278. var fatalError = workInProgressRootFatalError;
  15279. prepareFreshStack(root, expirationTime);
  15280. markRootSuspendedAtTime(root, expirationTime);
  15281. ensureRootIsScheduled(root);
  15282. throw fatalError;
  15283. } // We now have a consistent tree. Because this is a sync render, we
  15284. // will commit it even if something suspended.
  15285. root.finishedWork = root.current.alternate;
  15286. root.finishedExpirationTime = expirationTime;
  15287. commitRoot(root); // Before exiting, make sure there's a callback scheduled for the next
  15288. // pending level.
  15289. ensureRootIsScheduled(root);
  15290. return null;
  15291. }
  15292. function syncUpdates(fn, a, b, c) {
  15293. return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
  15294. }
  15295. function batchedUpdates$1(fn, a) {
  15296. var prevExecutionContext = executionContext;
  15297. executionContext |= BatchedContext;
  15298. try {
  15299. return fn(a);
  15300. } finally {
  15301. executionContext = prevExecutionContext;
  15302. if (executionContext === NoContext) {
  15303. // Flush the immediate callbacks that were scheduled during this batch
  15304. flushSyncCallbackQueue();
  15305. }
  15306. }
  15307. }
  15308. function flushSync(fn, a) {
  15309. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  15310. {
  15311. throw Error(
  15312. "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering."
  15313. );
  15314. }
  15315. }
  15316. var prevExecutionContext = executionContext;
  15317. executionContext |= BatchedContext;
  15318. try {
  15319. return runWithPriority(ImmediatePriority, fn.bind(null, a));
  15320. } finally {
  15321. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  15322. // Note that this will happen even if batchedUpdates is higher up
  15323. // the stack.
  15324. flushSyncCallbackQueue();
  15325. }
  15326. }
  15327. function prepareFreshStack(root, expirationTime) {
  15328. root.finishedWork = null;
  15329. root.finishedExpirationTime = NoWork;
  15330. var timeoutHandle = root.timeoutHandle;
  15331. if (timeoutHandle !== noTimeout) {
  15332. // The root previous suspended and scheduled a timeout to commit a fallback
  15333. // state. Now that we have additional work, cancel the timeout.
  15334. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  15335. cancelTimeout(timeoutHandle);
  15336. }
  15337. if (workInProgress !== null) {
  15338. var interruptedWork = workInProgress.return;
  15339. while (interruptedWork !== null) {
  15340. unwindInterruptedWork(interruptedWork);
  15341. interruptedWork = interruptedWork.return;
  15342. }
  15343. }
  15344. workInProgressRoot = root;
  15345. workInProgress = createWorkInProgress(root.current, null);
  15346. renderExpirationTime$1 = expirationTime;
  15347. workInProgressRootExitStatus = RootIncomplete;
  15348. workInProgressRootFatalError = null;
  15349. workInProgressRootLatestProcessedExpirationTime = Sync;
  15350. workInProgressRootLatestSuspenseTimeout = Sync;
  15351. workInProgressRootCanSuspendUsingConfig = null;
  15352. workInProgressRootNextUnprocessedUpdateTime = NoWork;
  15353. workInProgressRootHasPendingPing = false;
  15354. {
  15355. spawnedWorkDuringRender = null;
  15356. }
  15357. {
  15358. ReactStrictModeWarnings.discardPendingWarnings();
  15359. }
  15360. }
  15361. function handleError(root, thrownValue) {
  15362. do {
  15363. try {
  15364. // Reset module-level state that was set during the render phase.
  15365. resetContextDependencies();
  15366. resetHooksAfterThrow();
  15367. resetCurrentFiber();
  15368. if (workInProgress === null || workInProgress.return === null) {
  15369. // Expected to be working on a non-root fiber. This is a fatal error
  15370. // because there's no ancestor that can handle it; the root is
  15371. // supposed to capture all errors that weren't caught by an error
  15372. // boundary.
  15373. workInProgressRootExitStatus = RootFatalErrored;
  15374. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  15375. // sibling, or the parent if there are no siblings. But since the root
  15376. // has no siblings nor a parent, we set it to null. Usually this is
  15377. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  15378. // interntionally not calling those, we need set it here.
  15379. // TODO: Consider calling `unwindWork` to pop the contexts.
  15380. workInProgress = null;
  15381. return null;
  15382. }
  15383. if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
  15384. // Record the time spent rendering before an error was thrown. This
  15385. // avoids inaccurate Profiler durations in the case of a
  15386. // suspended render.
  15387. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
  15388. }
  15389. throwException(
  15390. root,
  15391. workInProgress.return,
  15392. workInProgress,
  15393. thrownValue,
  15394. renderExpirationTime$1
  15395. );
  15396. workInProgress = completeUnitOfWork(workInProgress);
  15397. } catch (yetAnotherThrownValue) {
  15398. // Something in the return path also threw.
  15399. thrownValue = yetAnotherThrownValue;
  15400. continue;
  15401. } // Return to the normal work loop.
  15402. return;
  15403. } while (true);
  15404. }
  15405. function pushDispatcher(root) {
  15406. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15407. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  15408. if (prevDispatcher === null) {
  15409. // The React isomorphic package does not include a default dispatcher.
  15410. // Instead the first renderer will lazily attach one, in order to give
  15411. // nicer error messages.
  15412. return ContextOnlyDispatcher;
  15413. } else {
  15414. return prevDispatcher;
  15415. }
  15416. }
  15417. function popDispatcher(prevDispatcher) {
  15418. ReactCurrentDispatcher$1.current = prevDispatcher;
  15419. }
  15420. function pushInteractions(root) {
  15421. {
  15422. var prevInteractions = tracing.__interactionsRef.current;
  15423. tracing.__interactionsRef.current = root.memoizedInteractions;
  15424. return prevInteractions;
  15425. }
  15426. }
  15427. function popInteractions(prevInteractions) {
  15428. {
  15429. tracing.__interactionsRef.current = prevInteractions;
  15430. }
  15431. }
  15432. function markCommitTimeOfFallback() {
  15433. globalMostRecentFallbackTime = now();
  15434. }
  15435. function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
  15436. if (
  15437. expirationTime < workInProgressRootLatestProcessedExpirationTime &&
  15438. expirationTime > Idle
  15439. ) {
  15440. workInProgressRootLatestProcessedExpirationTime = expirationTime;
  15441. }
  15442. if (suspenseConfig !== null) {
  15443. if (
  15444. expirationTime < workInProgressRootLatestSuspenseTimeout &&
  15445. expirationTime > Idle
  15446. ) {
  15447. workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
  15448. workInProgressRootCanSuspendUsingConfig = suspenseConfig;
  15449. }
  15450. }
  15451. }
  15452. function markUnprocessedUpdateTime(expirationTime) {
  15453. if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
  15454. workInProgressRootNextUnprocessedUpdateTime = expirationTime;
  15455. }
  15456. }
  15457. function renderDidSuspend() {
  15458. if (workInProgressRootExitStatus === RootIncomplete) {
  15459. workInProgressRootExitStatus = RootSuspended;
  15460. }
  15461. }
  15462. function renderDidSuspendDelayIfPossible() {
  15463. if (
  15464. workInProgressRootExitStatus === RootIncomplete ||
  15465. workInProgressRootExitStatus === RootSuspended
  15466. ) {
  15467. workInProgressRootExitStatus = RootSuspendedWithDelay;
  15468. } // Check if there's a lower priority update somewhere else in the tree.
  15469. if (
  15470. workInProgressRootNextUnprocessedUpdateTime !== NoWork &&
  15471. workInProgressRoot !== null
  15472. ) {
  15473. // Mark the current render as suspended, and then mark that there's a
  15474. // pending update.
  15475. // TODO: This should immediately interrupt the current render, instead
  15476. // of waiting until the next time we yield.
  15477. markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime$1);
  15478. markRootUpdatedAtTime(
  15479. workInProgressRoot,
  15480. workInProgressRootNextUnprocessedUpdateTime
  15481. );
  15482. }
  15483. }
  15484. function renderDidError() {
  15485. if (workInProgressRootExitStatus !== RootCompleted) {
  15486. workInProgressRootExitStatus = RootErrored;
  15487. }
  15488. } // Called during render to determine if anything has suspended.
  15489. // Returns false if we're not sure.
  15490. function renderHasNotSuspendedYet() {
  15491. // If something errored or completed, we can't really be sure,
  15492. // so those are false.
  15493. return workInProgressRootExitStatus === RootIncomplete;
  15494. }
  15495. function inferTimeFromExpirationTime(expirationTime) {
  15496. // We don't know exactly when the update was scheduled, but we can infer an
  15497. // approximate start time from the expiration time.
  15498. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  15499. return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
  15500. }
  15501. function inferTimeFromExpirationTimeWithSuspenseConfig(
  15502. expirationTime,
  15503. suspenseConfig
  15504. ) {
  15505. // We don't know exactly when the update was scheduled, but we can infer an
  15506. // approximate start time from the expiration time by subtracting the timeout
  15507. // that was added to the event time.
  15508. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  15509. return (
  15510. earliestExpirationTimeMs -
  15511. (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION)
  15512. );
  15513. }
  15514. function renderRootSync(root, expirationTime) {
  15515. var prevExecutionContext = executionContext;
  15516. executionContext |= RenderContext;
  15517. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15518. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15519. if (
  15520. root !== workInProgressRoot ||
  15521. expirationTime !== renderExpirationTime$1
  15522. ) {
  15523. prepareFreshStack(root, expirationTime);
  15524. startWorkOnPendingInteractions(root, expirationTime);
  15525. }
  15526. var prevInteractions = pushInteractions(root);
  15527. startWorkLoopTimer(workInProgress);
  15528. do {
  15529. try {
  15530. workLoopSync();
  15531. break;
  15532. } catch (thrownValue) {
  15533. handleError(root, thrownValue);
  15534. }
  15535. } while (true);
  15536. resetContextDependencies();
  15537. {
  15538. popInteractions(prevInteractions);
  15539. }
  15540. executionContext = prevExecutionContext;
  15541. popDispatcher(prevDispatcher);
  15542. if (workInProgress !== null) {
  15543. // This is a sync render, so we should have finished the whole tree.
  15544. {
  15545. throw Error(
  15546. "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue."
  15547. );
  15548. }
  15549. }
  15550. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15551. workInProgressRoot = null;
  15552. return workInProgressRootExitStatus;
  15553. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  15554. /** @noinline */
  15555. function workLoopSync() {
  15556. // Already timed out, so perform work without checking if we need to yield.
  15557. while (workInProgress !== null) {
  15558. workInProgress = performUnitOfWork(workInProgress);
  15559. }
  15560. }
  15561. function renderRootConcurrent(root, expirationTime) {
  15562. var prevExecutionContext = executionContext;
  15563. executionContext |= RenderContext;
  15564. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15565. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15566. if (
  15567. root !== workInProgressRoot ||
  15568. expirationTime !== renderExpirationTime$1
  15569. ) {
  15570. prepareFreshStack(root, expirationTime);
  15571. startWorkOnPendingInteractions(root, expirationTime);
  15572. }
  15573. var prevInteractions = pushInteractions(root);
  15574. startWorkLoopTimer(workInProgress);
  15575. do {
  15576. try {
  15577. workLoopConcurrent();
  15578. break;
  15579. } catch (thrownValue) {
  15580. handleError(root, thrownValue);
  15581. }
  15582. } while (true);
  15583. resetContextDependencies();
  15584. {
  15585. popInteractions(prevInteractions);
  15586. }
  15587. popDispatcher(prevDispatcher);
  15588. executionContext = prevExecutionContext; // Check if the tree has completed.
  15589. if (workInProgress !== null) {
  15590. // Still work remaining.
  15591. stopInterruptedWorkLoopTimer();
  15592. return RootIncomplete;
  15593. } else {
  15594. // Completed the tree.
  15595. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15596. workInProgressRoot = null; // Return the final exit status.
  15597. return workInProgressRootExitStatus;
  15598. }
  15599. }
  15600. /** @noinline */
  15601. function workLoopConcurrent() {
  15602. // Perform work until Scheduler asks us to yield
  15603. while (workInProgress !== null && !shouldYield()) {
  15604. workInProgress = performUnitOfWork(workInProgress);
  15605. }
  15606. }
  15607. function performUnitOfWork(unitOfWork) {
  15608. // The current, flushed, state of this fiber is the alternate. Ideally
  15609. // nothing should rely on this, but relying on it here means that we don't
  15610. // need an additional field on the work in progress.
  15611. var current = unitOfWork.alternate;
  15612. startWorkTimer(unitOfWork);
  15613. setCurrentFiber(unitOfWork);
  15614. var next;
  15615. if ((unitOfWork.mode & ProfileMode) !== NoMode) {
  15616. startProfilerTimer(unitOfWork);
  15617. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15618. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  15619. } else {
  15620. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15621. }
  15622. resetCurrentFiber();
  15623. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  15624. if (next === null) {
  15625. // If this doesn't spawn new work, complete the current work.
  15626. next = completeUnitOfWork(unitOfWork);
  15627. }
  15628. ReactCurrentOwner$2.current = null;
  15629. return next;
  15630. }
  15631. function completeUnitOfWork(unitOfWork) {
  15632. // Attempt to complete the current unit of work, then move to the next
  15633. // sibling. If there are no more siblings, return to the parent fiber.
  15634. workInProgress = unitOfWork;
  15635. do {
  15636. // The current, flushed, state of this fiber is the alternate. Ideally
  15637. // nothing should rely on this, but relying on it here means that we don't
  15638. // need an additional field on the work in progress.
  15639. var current = workInProgress.alternate;
  15640. var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
  15641. if ((workInProgress.effectTag & Incomplete) === NoEffect) {
  15642. setCurrentFiber(workInProgress);
  15643. var next = void 0;
  15644. if ((workInProgress.mode & ProfileMode) === NoMode) {
  15645. next = completeWork(current, workInProgress, renderExpirationTime$1);
  15646. } else {
  15647. startProfilerTimer(workInProgress);
  15648. next = completeWork(current, workInProgress, renderExpirationTime$1); // Update render duration assuming we didn't error.
  15649. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
  15650. }
  15651. stopWorkTimer(workInProgress);
  15652. resetCurrentFiber();
  15653. resetChildExpirationTime(workInProgress);
  15654. if (next !== null) {
  15655. // Completing this fiber spawned new work. Work on that next.
  15656. return next;
  15657. }
  15658. if (
  15659. returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  15660. (returnFiber.effectTag & Incomplete) === NoEffect
  15661. ) {
  15662. // Append all the effects of the subtree and this fiber onto the effect
  15663. // list of the parent. The completion order of the children affects the
  15664. // side-effect order.
  15665. if (returnFiber.firstEffect === null) {
  15666. returnFiber.firstEffect = workInProgress.firstEffect;
  15667. }
  15668. if (workInProgress.lastEffect !== null) {
  15669. if (returnFiber.lastEffect !== null) {
  15670. returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
  15671. }
  15672. returnFiber.lastEffect = workInProgress.lastEffect;
  15673. } // If this fiber had side-effects, we append it AFTER the children's
  15674. // side-effects. We can perform certain side-effects earlier if needed,
  15675. // by doing multiple passes over the effect list. We don't want to
  15676. // schedule our own side-effect on our own list because if end up
  15677. // reusing children we'll schedule this effect onto itself since we're
  15678. // at the end.
  15679. var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
  15680. // list. PerformedWork effect is read by React DevTools but shouldn't be
  15681. // committed.
  15682. if (effectTag > PerformedWork) {
  15683. if (returnFiber.lastEffect !== null) {
  15684. returnFiber.lastEffect.nextEffect = workInProgress;
  15685. } else {
  15686. returnFiber.firstEffect = workInProgress;
  15687. }
  15688. returnFiber.lastEffect = workInProgress;
  15689. }
  15690. }
  15691. } else {
  15692. // This fiber did not complete because something threw. Pop values off
  15693. // the stack without entering the complete phase. If this is a boundary,
  15694. // capture values if possible.
  15695. var _next = unwindWork(workInProgress); // Because this fiber did not complete, don't reset its expiration time.
  15696. if ((workInProgress.mode & ProfileMode) !== NoMode) {
  15697. // Record the render duration for the fiber that errored.
  15698. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
  15699. var actualDuration = workInProgress.actualDuration;
  15700. var child = workInProgress.child;
  15701. while (child !== null) {
  15702. actualDuration += child.actualDuration;
  15703. child = child.sibling;
  15704. }
  15705. workInProgress.actualDuration = actualDuration;
  15706. }
  15707. if (_next !== null) {
  15708. // If completing this work spawned new work, do that next. We'll come
  15709. // back here again.
  15710. // Since we're restarting, remove anything that is not a host effect
  15711. // from the effect tag.
  15712. // TODO: The name stopFailedWorkTimer is misleading because Suspense
  15713. // also captures and restarts.
  15714. stopFailedWorkTimer(workInProgress);
  15715. _next.effectTag &= HostEffectMask;
  15716. return _next;
  15717. }
  15718. stopWorkTimer(workInProgress);
  15719. if (returnFiber !== null) {
  15720. // Mark the parent fiber as incomplete and clear its effect list.
  15721. returnFiber.firstEffect = returnFiber.lastEffect = null;
  15722. returnFiber.effectTag |= Incomplete;
  15723. }
  15724. }
  15725. var siblingFiber = workInProgress.sibling;
  15726. if (siblingFiber !== null) {
  15727. // If there is more work to do in this returnFiber, do that next.
  15728. return siblingFiber;
  15729. } // Otherwise, return to the parent
  15730. workInProgress = returnFiber;
  15731. } while (workInProgress !== null); // We've reached the root.
  15732. if (workInProgressRootExitStatus === RootIncomplete) {
  15733. workInProgressRootExitStatus = RootCompleted;
  15734. }
  15735. return null;
  15736. }
  15737. function getRemainingExpirationTime(fiber) {
  15738. var updateExpirationTime = fiber.expirationTime;
  15739. var childExpirationTime = fiber.childExpirationTime;
  15740. return updateExpirationTime > childExpirationTime
  15741. ? updateExpirationTime
  15742. : childExpirationTime;
  15743. }
  15744. function resetChildExpirationTime(completedWork) {
  15745. if (
  15746. renderExpirationTime$1 !== Never &&
  15747. completedWork.childExpirationTime === Never
  15748. ) {
  15749. // The children of this component are hidden. Don't bubble their
  15750. // expiration times.
  15751. return;
  15752. }
  15753. var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
  15754. if ((completedWork.mode & ProfileMode) !== NoMode) {
  15755. // In profiling mode, resetChildExpirationTime is also used to reset
  15756. // profiler durations.
  15757. var actualDuration = completedWork.actualDuration;
  15758. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  15759. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  15760. // When work is done, it should bubble to the parent's actualDuration. If
  15761. // the fiber has not been cloned though, (meaning no work was done), then
  15762. // this value will reflect the amount of time spent working on a previous
  15763. // render. In that case it should not bubble. We determine whether it was
  15764. // cloned by comparing the child pointer.
  15765. var shouldBubbleActualDurations =
  15766. completedWork.alternate === null ||
  15767. completedWork.child !== completedWork.alternate.child;
  15768. var child = completedWork.child;
  15769. while (child !== null) {
  15770. var childUpdateExpirationTime = child.expirationTime;
  15771. var childChildExpirationTime = child.childExpirationTime;
  15772. if (childUpdateExpirationTime > newChildExpirationTime) {
  15773. newChildExpirationTime = childUpdateExpirationTime;
  15774. }
  15775. if (childChildExpirationTime > newChildExpirationTime) {
  15776. newChildExpirationTime = childChildExpirationTime;
  15777. }
  15778. if (shouldBubbleActualDurations) {
  15779. actualDuration += child.actualDuration;
  15780. }
  15781. treeBaseDuration += child.treeBaseDuration;
  15782. child = child.sibling;
  15783. }
  15784. completedWork.actualDuration = actualDuration;
  15785. completedWork.treeBaseDuration = treeBaseDuration;
  15786. } else {
  15787. var _child = completedWork.child;
  15788. while (_child !== null) {
  15789. var _childUpdateExpirationTime = _child.expirationTime;
  15790. var _childChildExpirationTime = _child.childExpirationTime;
  15791. if (_childUpdateExpirationTime > newChildExpirationTime) {
  15792. newChildExpirationTime = _childUpdateExpirationTime;
  15793. }
  15794. if (_childChildExpirationTime > newChildExpirationTime) {
  15795. newChildExpirationTime = _childChildExpirationTime;
  15796. }
  15797. _child = _child.sibling;
  15798. }
  15799. }
  15800. completedWork.childExpirationTime = newChildExpirationTime;
  15801. }
  15802. function commitRoot(root) {
  15803. var renderPriorityLevel = getCurrentPriorityLevel();
  15804. runWithPriority(
  15805. ImmediatePriority,
  15806. commitRootImpl.bind(null, root, renderPriorityLevel)
  15807. );
  15808. return null;
  15809. }
  15810. function commitRootImpl(root, renderPriorityLevel) {
  15811. do {
  15812. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  15813. // means `flushPassiveEffects` will sometimes result in additional
  15814. // passive effects. So we need to keep flushing in a loop until there are
  15815. // no more pending effects.
  15816. // TODO: Might be better if `flushPassiveEffects` did not automatically
  15817. // flush synchronous work at the end, to avoid factoring hazards like this.
  15818. flushPassiveEffects();
  15819. } while (rootWithPendingPassiveEffects !== null);
  15820. flushRenderPhaseStrictModeWarningsInDEV();
  15821. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15822. throw Error("Should not already be working.");
  15823. }
  15824. var finishedWork = root.finishedWork;
  15825. var expirationTime = root.finishedExpirationTime;
  15826. if (finishedWork === null) {
  15827. return null;
  15828. }
  15829. root.finishedWork = null;
  15830. root.finishedExpirationTime = NoWork;
  15831. if (!(finishedWork !== root.current)) {
  15832. throw Error(
  15833. "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue."
  15834. );
  15835. } // commitRoot never returns a continuation; it always finishes synchronously.
  15836. // So we can clear these now to allow a new callback to be scheduled.
  15837. root.callbackNode = null;
  15838. root.callbackExpirationTime = NoWork;
  15839. root.callbackPriority = NoPriority;
  15840. root.nextKnownPendingLevel = NoWork;
  15841. startCommitTimer(); // Update the first and last pending times on this root. The new first
  15842. // pending time is whatever is left on the root fiber.
  15843. var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(
  15844. finishedWork
  15845. );
  15846. markRootFinishedAtTime(
  15847. root,
  15848. expirationTime,
  15849. remainingExpirationTimeBeforeCommit
  15850. );
  15851. if (root === workInProgressRoot) {
  15852. // We can reset these now that they are finished.
  15853. workInProgressRoot = null;
  15854. workInProgress = null;
  15855. renderExpirationTime$1 = NoWork;
  15856. } // This indicates that the last root we worked on is not the same one that
  15857. // we're committing now. This most commonly happens when a suspended root
  15858. // times out.
  15859. // Get the list of effects.
  15860. var firstEffect;
  15861. if (finishedWork.effectTag > PerformedWork) {
  15862. // A fiber's effect list consists only of its children, not itself. So if
  15863. // the root has an effect, we need to add it to the end of the list. The
  15864. // resulting list is the set that would belong to the root's parent, if it
  15865. // had one; that is, all the effects in the tree including the root.
  15866. if (finishedWork.lastEffect !== null) {
  15867. finishedWork.lastEffect.nextEffect = finishedWork;
  15868. firstEffect = finishedWork.firstEffect;
  15869. } else {
  15870. firstEffect = finishedWork;
  15871. }
  15872. } else {
  15873. // There is no effect on the root.
  15874. firstEffect = finishedWork.firstEffect;
  15875. }
  15876. if (firstEffect !== null) {
  15877. var prevExecutionContext = executionContext;
  15878. executionContext |= CommitContext;
  15879. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  15880. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  15881. // of the effect list for each phase: all mutation effects come before all
  15882. // layout effects, and so on.
  15883. // The first phase a "before mutation" phase. We use this phase to read the
  15884. // state of the host tree right before we mutate it. This is where
  15885. // getSnapshotBeforeUpdate is called.
  15886. startCommitSnapshotEffectsTimer();
  15887. prepareForCommit(root.containerInfo);
  15888. nextEffect = firstEffect;
  15889. do {
  15890. {
  15891. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  15892. if (hasCaughtError()) {
  15893. if (!(nextEffect !== null)) {
  15894. throw Error("Should be working on an effect.");
  15895. }
  15896. var error = clearCaughtError();
  15897. captureCommitPhaseError(nextEffect, error);
  15898. nextEffect = nextEffect.nextEffect;
  15899. }
  15900. }
  15901. } while (nextEffect !== null);
  15902. stopCommitSnapshotEffectsTimer();
  15903. {
  15904. // Mark the current commit time to be shared by all Profilers in this
  15905. // batch. This enables them to be grouped later.
  15906. recordCommitTime();
  15907. } // The next phase is the mutation phase, where we mutate the host tree.
  15908. startCommitHostEffectsTimer();
  15909. nextEffect = firstEffect;
  15910. do {
  15911. {
  15912. invokeGuardedCallback(
  15913. null,
  15914. commitMutationEffects,
  15915. null,
  15916. root,
  15917. renderPriorityLevel
  15918. );
  15919. if (hasCaughtError()) {
  15920. if (!(nextEffect !== null)) {
  15921. throw Error("Should be working on an effect.");
  15922. }
  15923. var _error = clearCaughtError();
  15924. captureCommitPhaseError(nextEffect, _error);
  15925. nextEffect = nextEffect.nextEffect;
  15926. }
  15927. }
  15928. } while (nextEffect !== null);
  15929. stopCommitHostEffectsTimer();
  15930. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  15931. // the mutation phase, so that the previous tree is still current during
  15932. // componentWillUnmount, but before the layout phase, so that the finished
  15933. // work is current during componentDidMount/Update.
  15934. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  15935. // the host tree after it's been mutated. The idiomatic use case for this is
  15936. // layout, but class component lifecycles also fire here for legacy reasons.
  15937. startCommitLifeCyclesTimer();
  15938. nextEffect = firstEffect;
  15939. do {
  15940. {
  15941. invokeGuardedCallback(
  15942. null,
  15943. commitLayoutEffects,
  15944. null,
  15945. root,
  15946. expirationTime
  15947. );
  15948. if (hasCaughtError()) {
  15949. if (!(nextEffect !== null)) {
  15950. throw Error("Should be working on an effect.");
  15951. }
  15952. var _error2 = clearCaughtError();
  15953. captureCommitPhaseError(nextEffect, _error2);
  15954. nextEffect = nextEffect.nextEffect;
  15955. }
  15956. }
  15957. } while (nextEffect !== null);
  15958. stopCommitLifeCyclesTimer();
  15959. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  15960. // opportunity to paint.
  15961. requestPaint();
  15962. {
  15963. popInteractions(prevInteractions);
  15964. }
  15965. executionContext = prevExecutionContext;
  15966. } else {
  15967. // No effects.
  15968. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  15969. // no effects.
  15970. // TODO: Maybe there's a better way to report this.
  15971. startCommitSnapshotEffectsTimer();
  15972. stopCommitSnapshotEffectsTimer();
  15973. {
  15974. recordCommitTime();
  15975. }
  15976. startCommitHostEffectsTimer();
  15977. stopCommitHostEffectsTimer();
  15978. startCommitLifeCyclesTimer();
  15979. stopCommitLifeCyclesTimer();
  15980. }
  15981. stopCommitTimer();
  15982. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  15983. if (rootDoesHavePassiveEffects) {
  15984. // This commit has passive effects. Stash a reference to them. But don't
  15985. // schedule a callback until after flushing layout work.
  15986. rootDoesHavePassiveEffects = false;
  15987. rootWithPendingPassiveEffects = root;
  15988. pendingPassiveEffectsExpirationTime = expirationTime;
  15989. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  15990. } else {
  15991. // We are done with the effect chain at this point so let's clear the
  15992. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  15993. // clear this in flushPassiveEffects.
  15994. nextEffect = firstEffect;
  15995. while (nextEffect !== null) {
  15996. var nextNextEffect = nextEffect.nextEffect;
  15997. nextEffect.nextEffect = null;
  15998. nextEffect = nextNextEffect;
  15999. }
  16000. } // Check if there's remaining work on this root
  16001. var remainingExpirationTime = root.firstPendingTime;
  16002. if (remainingExpirationTime !== NoWork) {
  16003. {
  16004. if (spawnedWorkDuringRender !== null) {
  16005. var expirationTimes = spawnedWorkDuringRender;
  16006. spawnedWorkDuringRender = null;
  16007. for (var i = 0; i < expirationTimes.length; i++) {
  16008. scheduleInteractions(
  16009. root,
  16010. expirationTimes[i],
  16011. root.memoizedInteractions
  16012. );
  16013. }
  16014. }
  16015. schedulePendingInteractions(root, remainingExpirationTime);
  16016. }
  16017. } else {
  16018. // If there's no remaining work, we can clear the set of already failed
  16019. // error boundaries.
  16020. legacyErrorBoundariesThatAlreadyFailed = null;
  16021. }
  16022. {
  16023. if (!rootDidHavePassiveEffects) {
  16024. // If there are no passive effects, then we can complete the pending interactions.
  16025. // Otherwise, we'll wait until after the passive effects are flushed.
  16026. // Wait to do this until after remaining work has been scheduled,
  16027. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  16028. finishPendingInteractions(root, expirationTime);
  16029. }
  16030. }
  16031. if (remainingExpirationTime === Sync) {
  16032. // Count the number of times the root synchronously re-renders without
  16033. // finishing. If there are too many, it indicates an infinite update loop.
  16034. if (root === rootWithNestedUpdates) {
  16035. nestedUpdateCount++;
  16036. } else {
  16037. nestedUpdateCount = 0;
  16038. rootWithNestedUpdates = root;
  16039. }
  16040. } else {
  16041. nestedUpdateCount = 0;
  16042. }
  16043. onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
  16044. // additional work on this root is scheduled.
  16045. ensureRootIsScheduled(root);
  16046. if (hasUncaughtError) {
  16047. hasUncaughtError = false;
  16048. var _error3 = firstUncaughtError;
  16049. firstUncaughtError = null;
  16050. throw _error3;
  16051. }
  16052. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  16053. // This is a legacy edge case. We just committed the initial mount of
  16054. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  16055. // synchronously, but layout updates should be deferred until the end
  16056. // of the batch.
  16057. return null;
  16058. } // If layout work was scheduled, flush it now.
  16059. flushSyncCallbackQueue();
  16060. return null;
  16061. }
  16062. function commitBeforeMutationEffects() {
  16063. while (nextEffect !== null) {
  16064. var effectTag = nextEffect.effectTag;
  16065. if ((effectTag & Snapshot) !== NoEffect) {
  16066. setCurrentFiber(nextEffect);
  16067. recordEffect();
  16068. var current = nextEffect.alternate;
  16069. commitBeforeMutationLifeCycles(current, nextEffect);
  16070. resetCurrentFiber();
  16071. }
  16072. if ((effectTag & Passive) !== NoEffect) {
  16073. // If there are passive effects, schedule a callback to flush at
  16074. // the earliest opportunity.
  16075. if (!rootDoesHavePassiveEffects) {
  16076. rootDoesHavePassiveEffects = true;
  16077. scheduleCallback(NormalPriority, function() {
  16078. flushPassiveEffects();
  16079. return null;
  16080. });
  16081. }
  16082. }
  16083. nextEffect = nextEffect.nextEffect;
  16084. }
  16085. }
  16086. function commitMutationEffects(root, renderPriorityLevel) {
  16087. // TODO: Should probably move the bulk of this function to commitWork.
  16088. while (nextEffect !== null) {
  16089. setCurrentFiber(nextEffect);
  16090. var effectTag = nextEffect.effectTag;
  16091. if (effectTag & ContentReset) {
  16092. commitResetTextContent(nextEffect);
  16093. }
  16094. if (effectTag & Ref) {
  16095. var current = nextEffect.alternate;
  16096. if (current !== null) {
  16097. commitDetachRef(current);
  16098. }
  16099. } // The following switch statement is only concerned about placement,
  16100. // updates, and deletions. To avoid needing to add a case for every possible
  16101. // bitmap value, we remove the secondary effects from the effect tag and
  16102. // switch on that value.
  16103. var primaryEffectTag =
  16104. effectTag & (Placement | Update | Deletion | Hydrating);
  16105. switch (primaryEffectTag) {
  16106. case Placement: {
  16107. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  16108. // inserted, before any life-cycles like componentDidMount gets called.
  16109. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  16110. // and isMounted is deprecated anyway so we should be able to kill this.
  16111. nextEffect.effectTag &= ~Placement;
  16112. break;
  16113. }
  16114. case PlacementAndUpdate: {
  16115. // Placement
  16116. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  16117. // inserted, before any life-cycles like componentDidMount gets called.
  16118. nextEffect.effectTag &= ~Placement; // Update
  16119. var _current = nextEffect.alternate;
  16120. commitWork(_current, nextEffect);
  16121. break;
  16122. }
  16123. case Hydrating: {
  16124. nextEffect.effectTag &= ~Hydrating;
  16125. break;
  16126. }
  16127. case HydratingAndUpdate: {
  16128. nextEffect.effectTag &= ~Hydrating; // Update
  16129. var _current2 = nextEffect.alternate;
  16130. commitWork(_current2, nextEffect);
  16131. break;
  16132. }
  16133. case Update: {
  16134. var _current3 = nextEffect.alternate;
  16135. commitWork(_current3, nextEffect);
  16136. break;
  16137. }
  16138. case Deletion: {
  16139. commitDeletion(root, nextEffect, renderPriorityLevel);
  16140. break;
  16141. }
  16142. } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
  16143. recordEffect();
  16144. resetCurrentFiber();
  16145. nextEffect = nextEffect.nextEffect;
  16146. }
  16147. }
  16148. function commitLayoutEffects(root, committedExpirationTime) {
  16149. // TODO: Should probably move the bulk of this function to commitWork.
  16150. while (nextEffect !== null) {
  16151. setCurrentFiber(nextEffect);
  16152. var effectTag = nextEffect.effectTag;
  16153. if (effectTag & (Update | Callback)) {
  16154. recordEffect();
  16155. var current = nextEffect.alternate;
  16156. commitLifeCycles(root, current, nextEffect);
  16157. }
  16158. if (effectTag & Ref) {
  16159. recordEffect();
  16160. commitAttachRef(nextEffect);
  16161. }
  16162. resetCurrentFiber();
  16163. nextEffect = nextEffect.nextEffect;
  16164. }
  16165. }
  16166. function flushPassiveEffects() {
  16167. if (pendingPassiveEffectsRenderPriority !== NoPriority) {
  16168. var priorityLevel =
  16169. pendingPassiveEffectsRenderPriority > NormalPriority
  16170. ? NormalPriority
  16171. : pendingPassiveEffectsRenderPriority;
  16172. pendingPassiveEffectsRenderPriority = NoPriority;
  16173. return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
  16174. }
  16175. }
  16176. function flushPassiveEffectsImpl() {
  16177. if (rootWithPendingPassiveEffects === null) {
  16178. return false;
  16179. }
  16180. var root = rootWithPendingPassiveEffects;
  16181. var expirationTime = pendingPassiveEffectsExpirationTime;
  16182. rootWithPendingPassiveEffects = null;
  16183. pendingPassiveEffectsExpirationTime = NoWork;
  16184. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  16185. throw Error("Cannot flush passive effects while already rendering.");
  16186. }
  16187. var prevExecutionContext = executionContext;
  16188. executionContext |= CommitContext;
  16189. var prevInteractions = pushInteractions(root);
  16190. {
  16191. // Note: This currently assumes there are no passive effects on the root fiber
  16192. // because the root is not part of its own effect list.
  16193. // This could change in the future.
  16194. var _effect2 = root.current.firstEffect;
  16195. while (_effect2 !== null) {
  16196. {
  16197. setCurrentFiber(_effect2);
  16198. invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
  16199. if (hasCaughtError()) {
  16200. if (!(_effect2 !== null)) {
  16201. throw Error("Should be working on an effect.");
  16202. }
  16203. var _error5 = clearCaughtError();
  16204. captureCommitPhaseError(_effect2, _error5);
  16205. }
  16206. resetCurrentFiber();
  16207. }
  16208. var nextNextEffect = _effect2.nextEffect; // Remove nextEffect pointer to assist GC
  16209. _effect2.nextEffect = null;
  16210. _effect2 = nextNextEffect;
  16211. }
  16212. }
  16213. {
  16214. popInteractions(prevInteractions);
  16215. finishPendingInteractions(root, expirationTime);
  16216. }
  16217. executionContext = prevExecutionContext;
  16218. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  16219. // exceeds the limit, we'll fire a warning.
  16220. nestedPassiveUpdateCount =
  16221. rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  16222. return true;
  16223. }
  16224. function isAlreadyFailedLegacyErrorBoundary(instance) {
  16225. return (
  16226. legacyErrorBoundariesThatAlreadyFailed !== null &&
  16227. legacyErrorBoundariesThatAlreadyFailed.has(instance)
  16228. );
  16229. }
  16230. function markLegacyErrorBoundaryAsFailed(instance) {
  16231. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  16232. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  16233. } else {
  16234. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  16235. }
  16236. }
  16237. function prepareToThrowUncaughtError(error) {
  16238. if (!hasUncaughtError) {
  16239. hasUncaughtError = true;
  16240. firstUncaughtError = error;
  16241. }
  16242. }
  16243. var onUncaughtError = prepareToThrowUncaughtError;
  16244. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  16245. var errorInfo = createCapturedValue(error, sourceFiber);
  16246. var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
  16247. enqueueUpdate(rootFiber, update);
  16248. var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
  16249. if (root !== null) {
  16250. ensureRootIsScheduled(root);
  16251. schedulePendingInteractions(root, Sync);
  16252. }
  16253. }
  16254. function captureCommitPhaseError(sourceFiber, error) {
  16255. if (sourceFiber.tag === HostRoot) {
  16256. // Error was thrown at the root. There is no parent, so the root
  16257. // itself should capture it.
  16258. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  16259. return;
  16260. }
  16261. var fiber = sourceFiber.return;
  16262. while (fiber !== null) {
  16263. if (fiber.tag === HostRoot) {
  16264. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  16265. return;
  16266. } else if (fiber.tag === ClassComponent) {
  16267. var ctor = fiber.type;
  16268. var instance = fiber.stateNode;
  16269. if (
  16270. typeof ctor.getDerivedStateFromError === "function" ||
  16271. (typeof instance.componentDidCatch === "function" &&
  16272. !isAlreadyFailedLegacyErrorBoundary(instance))
  16273. ) {
  16274. var errorInfo = createCapturedValue(error, sourceFiber);
  16275. var update = createClassErrorUpdate(
  16276. fiber,
  16277. errorInfo, // TODO: This is always sync
  16278. Sync
  16279. );
  16280. enqueueUpdate(fiber, update);
  16281. var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
  16282. if (root !== null) {
  16283. ensureRootIsScheduled(root);
  16284. schedulePendingInteractions(root, Sync);
  16285. }
  16286. return;
  16287. }
  16288. }
  16289. fiber = fiber.return;
  16290. }
  16291. }
  16292. function pingSuspendedRoot(root, thenable, suspendedTime) {
  16293. var pingCache = root.pingCache;
  16294. if (pingCache !== null) {
  16295. // The thenable resolved, so we no longer need to memoize, because it will
  16296. // never be thrown again.
  16297. pingCache.delete(thenable);
  16298. }
  16299. if (workInProgressRoot === root && renderExpirationTime$1 === suspendedTime) {
  16300. // Received a ping at the same priority level at which we're currently
  16301. // rendering. We might want to restart this render. This should mirror
  16302. // the logic of whether or not a root suspends once it completes.
  16303. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  16304. // we should probably never restart.
  16305. // If we're suspended with delay, we'll always suspend so we can always
  16306. // restart. If we're suspended without any updates, it might be a retry.
  16307. // If it's early in the retry we can restart. We can't know for sure
  16308. // whether we'll eventually process an update during this render pass,
  16309. // but it's somewhat unlikely that we get to a ping before that, since
  16310. // getting to the root most update is usually very fast.
  16311. if (
  16312. workInProgressRootExitStatus === RootSuspendedWithDelay ||
  16313. (workInProgressRootExitStatus === RootSuspended &&
  16314. workInProgressRootLatestProcessedExpirationTime === Sync &&
  16315. now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS)
  16316. ) {
  16317. // Restart from the root. Don't need to schedule a ping because
  16318. // we're already working on this tree.
  16319. prepareFreshStack(root, renderExpirationTime$1);
  16320. } else {
  16321. // Even though we can't restart right now, we might get an
  16322. // opportunity later. So we mark this render as having a ping.
  16323. workInProgressRootHasPendingPing = true;
  16324. }
  16325. return;
  16326. }
  16327. if (!isRootSuspendedAtTime(root, suspendedTime)) {
  16328. // The root is no longer suspended at this time.
  16329. return;
  16330. }
  16331. var lastPingedTime = root.lastPingedTime;
  16332. if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
  16333. // There's already a lower priority ping scheduled.
  16334. return;
  16335. } // Mark the time at which this ping was scheduled.
  16336. root.lastPingedTime = suspendedTime;
  16337. ensureRootIsScheduled(root);
  16338. schedulePendingInteractions(root, suspendedTime);
  16339. }
  16340. function retryTimedOutBoundary(boundaryFiber, retryTime) {
  16341. // The boundary fiber (a Suspense component or SuspenseList component)
  16342. // previously was rendered in its fallback state. One of the promises that
  16343. // suspended it has resolved, which means at least part of the tree was
  16344. // likely unblocked. Try rendering again, at a new expiration time.
  16345. if (retryTime === NoWork) {
  16346. var suspenseConfig = null; // Retries don't carry over the already committed update.
  16347. var currentTime = requestCurrentTimeForUpdate();
  16348. retryTime = computeExpirationForFiber(
  16349. currentTime,
  16350. boundaryFiber,
  16351. suspenseConfig
  16352. );
  16353. } // TODO: Special case idle priority?
  16354. var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
  16355. if (root !== null) {
  16356. ensureRootIsScheduled(root);
  16357. schedulePendingInteractions(root, retryTime);
  16358. }
  16359. }
  16360. function resolveRetryThenable(boundaryFiber, thenable) {
  16361. var retryTime = NoWork; // Default
  16362. var retryCache;
  16363. {
  16364. retryCache = boundaryFiber.stateNode;
  16365. }
  16366. if (retryCache !== null) {
  16367. // The thenable resolved, so we no longer need to memoize, because it will
  16368. // never be thrown again.
  16369. retryCache.delete(thenable);
  16370. }
  16371. retryTimedOutBoundary(boundaryFiber, retryTime);
  16372. } // Computes the next Just Noticeable Difference (JND) boundary.
  16373. // The theory is that a person can't tell the difference between small differences in time.
  16374. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  16375. // difference in the experience. However, waiting for longer might mean that we can avoid
  16376. // showing an intermediate loading state. The longer we have already waited, the harder it
  16377. // is to tell small differences in time. Therefore, the longer we've already waited,
  16378. // the longer we can wait additionally. At some point we have to give up though.
  16379. // We pick a train model where the next boundary commits at a consistent schedule.
  16380. // These particular numbers are vague estimates. We expect to adjust them based on research.
  16381. function jnd(timeElapsed) {
  16382. return timeElapsed < 120
  16383. ? 120
  16384. : timeElapsed < 480
  16385. ? 480
  16386. : timeElapsed < 1080
  16387. ? 1080
  16388. : timeElapsed < 1920
  16389. ? 1920
  16390. : timeElapsed < 3000
  16391. ? 3000
  16392. : timeElapsed < 4320
  16393. ? 4320
  16394. : ceil(timeElapsed / 1960) * 1960;
  16395. }
  16396. function computeMsUntilSuspenseLoadingDelay(
  16397. mostRecentEventTime,
  16398. committedExpirationTime,
  16399. suspenseConfig
  16400. ) {
  16401. var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
  16402. if (busyMinDurationMs <= 0) {
  16403. return 0;
  16404. }
  16405. var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
  16406. var currentTimeMs = now();
  16407. var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(
  16408. mostRecentEventTime,
  16409. suspenseConfig
  16410. );
  16411. var timeElapsed = currentTimeMs - eventTimeMs;
  16412. if (timeElapsed <= busyDelayMs) {
  16413. // If we haven't yet waited longer than the initial delay, we don't
  16414. // have to wait any additional time.
  16415. return 0;
  16416. }
  16417. var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
  16418. return msUntilTimeout;
  16419. }
  16420. function checkForNestedUpdates() {
  16421. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  16422. nestedUpdateCount = 0;
  16423. rootWithNestedUpdates = null;
  16424. {
  16425. throw Error(
  16426. "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."
  16427. );
  16428. }
  16429. }
  16430. {
  16431. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  16432. nestedPassiveUpdateCount = 0;
  16433. error(
  16434. "Maximum update depth exceeded. This can happen when a component " +
  16435. "calls setState inside useEffect, but useEffect either doesn't " +
  16436. "have a dependency array, or one of the dependencies changes on " +
  16437. "every render."
  16438. );
  16439. }
  16440. }
  16441. }
  16442. function flushRenderPhaseStrictModeWarningsInDEV() {
  16443. {
  16444. ReactStrictModeWarnings.flushLegacyContextWarning();
  16445. {
  16446. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  16447. }
  16448. }
  16449. }
  16450. function stopFinishedWorkLoopTimer() {
  16451. var didCompleteRoot = true;
  16452. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  16453. interruptedBy = null;
  16454. }
  16455. function stopInterruptedWorkLoopTimer() {
  16456. // TODO: Track which fiber caused the interruption.
  16457. var didCompleteRoot = false;
  16458. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  16459. interruptedBy = null;
  16460. }
  16461. function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
  16462. if (
  16463. workInProgressRoot !== null &&
  16464. updateExpirationTime > renderExpirationTime$1
  16465. ) {
  16466. interruptedBy = fiberThatReceivedUpdate;
  16467. }
  16468. }
  16469. var didWarnStateUpdateForUnmountedComponent = null;
  16470. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  16471. {
  16472. var tag = fiber.tag;
  16473. if (
  16474. tag !== HostRoot &&
  16475. tag !== ClassComponent &&
  16476. tag !== FunctionComponent &&
  16477. tag !== ForwardRef &&
  16478. tag !== MemoComponent &&
  16479. tag !== SimpleMemoComponent &&
  16480. tag !== Block
  16481. ) {
  16482. // Only warn for user-defined components, not internal ones like Suspense.
  16483. return;
  16484. }
  16485. // the problematic code almost always lies inside that component.
  16486. var componentName = getComponentName(fiber.type) || "ReactComponent";
  16487. if (didWarnStateUpdateForUnmountedComponent !== null) {
  16488. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  16489. return;
  16490. }
  16491. didWarnStateUpdateForUnmountedComponent.add(componentName);
  16492. } else {
  16493. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  16494. }
  16495. error(
  16496. "Can't perform a React state update on an unmounted component. This " +
  16497. "is a no-op, but it indicates a memory leak in your application. To " +
  16498. "fix, cancel all subscriptions and asynchronous tasks in %s.%s",
  16499. tag === ClassComponent
  16500. ? "the componentWillUnmount method"
  16501. : "a useEffect cleanup function",
  16502. getStackByFiberInDevAndProd(fiber)
  16503. );
  16504. }
  16505. }
  16506. var beginWork$1;
  16507. {
  16508. var dummyFiber = null;
  16509. beginWork$1 = function(current, unitOfWork, expirationTime) {
  16510. // If a component throws an error, we replay it again in a synchronously
  16511. // dispatched event, so that the debugger will treat it as an uncaught
  16512. // error See ReactErrorUtils for more information.
  16513. // Before entering the begin phase, copy the work-in-progress onto a dummy
  16514. // fiber. If beginWork throws, we'll use this to reset the state.
  16515. var originalWorkInProgressCopy = assignFiberPropertiesInDEV(
  16516. dummyFiber,
  16517. unitOfWork
  16518. );
  16519. try {
  16520. return beginWork(current, unitOfWork, expirationTime);
  16521. } catch (originalError) {
  16522. if (
  16523. originalError !== null &&
  16524. typeof originalError === "object" &&
  16525. typeof originalError.then === "function"
  16526. ) {
  16527. // Don't replay promises. Treat everything else like an error.
  16528. throw originalError;
  16529. } // Keep this code in sync with handleError; any changes here must have
  16530. // corresponding changes there.
  16531. resetContextDependencies();
  16532. resetHooksAfterThrow(); // Don't reset current debug fiber, since we're about to work on the
  16533. // same fiber again.
  16534. // Unwind the failed stack frame
  16535. unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
  16536. assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
  16537. if (unitOfWork.mode & ProfileMode) {
  16538. // Reset the profiler timer.
  16539. startProfilerTimer(unitOfWork);
  16540. } // Run beginWork again.
  16541. invokeGuardedCallback(
  16542. null,
  16543. beginWork,
  16544. null,
  16545. current,
  16546. unitOfWork,
  16547. expirationTime
  16548. );
  16549. if (hasCaughtError()) {
  16550. var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
  16551. // Rethrow this error instead of the original one.
  16552. throw replayError;
  16553. } else {
  16554. // This branch is reachable if the render phase is impure.
  16555. throw originalError;
  16556. }
  16557. }
  16558. };
  16559. }
  16560. var didWarnAboutUpdateInRender = false;
  16561. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  16562. {
  16563. if ((executionContext & RenderContext) !== NoContext) {
  16564. switch (fiber.tag) {
  16565. case FunctionComponent:
  16566. case ForwardRef:
  16567. case SimpleMemoComponent: {
  16568. error(
  16569. "Cannot update a component from inside the function body of a " +
  16570. "different component."
  16571. );
  16572. break;
  16573. }
  16574. case ClassComponent: {
  16575. if (isRendering && !didWarnAboutUpdateInRender) {
  16576. error(
  16577. "Cannot update during an existing state transition (such as " +
  16578. "within `render`). Render methods should be a pure " +
  16579. "function of props and state."
  16580. );
  16581. didWarnAboutUpdateInRender = true;
  16582. break;
  16583. }
  16584. }
  16585. }
  16586. }
  16587. }
  16588. } // a 'shared' variable that changes when act() opens/closes in tests.
  16589. var IsThisRendererActing = {
  16590. current: false
  16591. };
  16592. function warnIfNotScopedWithMatchingAct(fiber) {
  16593. {
  16594. if (
  16595. IsSomeRendererActing.current === true &&
  16596. IsThisRendererActing.current !== true
  16597. ) {
  16598. error(
  16599. "It looks like you're using the wrong act() around your test interactions.\n" +
  16600. "Be sure to use the matching version of act() corresponding to your renderer:\n\n" +
  16601. "// for react-dom:\n" + // Break up imports to avoid accidentally parsing them as dependencies.
  16602. "import {act} fr" +
  16603. "om 'react-dom/test-utils';\n" +
  16604. "// ...\n" +
  16605. "act(() => ...);\n\n" +
  16606. "// for react-test-renderer:\n" + // Break up imports to avoid accidentally parsing them as dependencies.
  16607. "import TestRenderer fr" +
  16608. "om react-test-renderer';\n" +
  16609. "const {act} = TestRenderer;\n" +
  16610. "// ...\n" +
  16611. "act(() => ...);" +
  16612. "%s",
  16613. getStackByFiberInDevAndProd(fiber)
  16614. );
  16615. }
  16616. }
  16617. }
  16618. function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
  16619. {
  16620. if (
  16621. (fiber.mode & StrictMode) !== NoMode &&
  16622. IsSomeRendererActing.current === false &&
  16623. IsThisRendererActing.current === false
  16624. ) {
  16625. error(
  16626. "An update to %s ran an effect, but was not wrapped in act(...).\n\n" +
  16627. "When testing, code that causes React state updates should be " +
  16628. "wrapped into act(...):\n\n" +
  16629. "act(() => {\n" +
  16630. " /* fire events that update state */\n" +
  16631. "});\n" +
  16632. "/* assert on the output */\n\n" +
  16633. "This ensures that you're testing the behavior the user would see " +
  16634. "in the browser." +
  16635. " Learn more at https://fb.me/react-wrap-tests-with-act" +
  16636. "%s",
  16637. getComponentName(fiber.type),
  16638. getStackByFiberInDevAndProd(fiber)
  16639. );
  16640. }
  16641. }
  16642. }
  16643. function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
  16644. {
  16645. if (
  16646. executionContext === NoContext &&
  16647. IsSomeRendererActing.current === false &&
  16648. IsThisRendererActing.current === false
  16649. ) {
  16650. error(
  16651. "An update to %s inside a test was not wrapped in act(...).\n\n" +
  16652. "When testing, code that causes React state updates should be " +
  16653. "wrapped into act(...):\n\n" +
  16654. "act(() => {\n" +
  16655. " /* fire events that update state */\n" +
  16656. "});\n" +
  16657. "/* assert on the output */\n\n" +
  16658. "This ensures that you're testing the behavior the user would see " +
  16659. "in the browser." +
  16660. " Learn more at https://fb.me/react-wrap-tests-with-act" +
  16661. "%s",
  16662. getComponentName(fiber.type),
  16663. getStackByFiberInDevAndProd(fiber)
  16664. );
  16665. }
  16666. }
  16667. }
  16668. var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
  16669. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  16670. // scheduler is the actual recommendation. The alternative could be a testing build,
  16671. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  16672. // to get their tests right.
  16673. function warnIfUnmockedScheduler(fiber) {
  16674. {
  16675. if (
  16676. didWarnAboutUnmockedScheduler === false &&
  16677. Scheduler.unstable_flushAllWithoutAsserting === undefined
  16678. ) {
  16679. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  16680. didWarnAboutUnmockedScheduler = true;
  16681. error(
  16682. 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
  16683. "to guarantee consistent behaviour across tests and browsers. " +
  16684. "For example, with jest: \n" + // Break up requires to avoid accidentally parsing them as dependencies.
  16685. "jest.mock('scheduler', () => require" +
  16686. "('scheduler/unstable_mock'));\n\n" +
  16687. "For more info, visit https://fb.me/react-mock-scheduler"
  16688. );
  16689. } else {
  16690. didWarnAboutUnmockedScheduler = true;
  16691. error(
  16692. 'Starting from React v17, the "scheduler" module will need to be mocked ' +
  16693. "to guarantee consistent behaviour across tests and browsers. " +
  16694. "For example, with jest: \n" + // Break up requires to avoid accidentally parsing them as dependencies.
  16695. "jest.mock('scheduler', () => require" +
  16696. "('scheduler/unstable_mock'));\n\n" +
  16697. "For more info, visit https://fb.me/react-mock-scheduler"
  16698. );
  16699. }
  16700. }
  16701. }
  16702. }
  16703. function computeThreadID(root, expirationTime) {
  16704. // Interaction threads are unique per root and expiration time.
  16705. return expirationTime * 1000 + root.interactionThreadID;
  16706. }
  16707. function markSpawnedWork(expirationTime) {
  16708. if (spawnedWorkDuringRender === null) {
  16709. spawnedWorkDuringRender = [expirationTime];
  16710. } else {
  16711. spawnedWorkDuringRender.push(expirationTime);
  16712. }
  16713. }
  16714. function scheduleInteractions(root, expirationTime, interactions) {
  16715. if (interactions.size > 0) {
  16716. var pendingInteractionMap = root.pendingInteractionMap;
  16717. var pendingInteractions = pendingInteractionMap.get(expirationTime);
  16718. if (pendingInteractions != null) {
  16719. interactions.forEach(function(interaction) {
  16720. if (!pendingInteractions.has(interaction)) {
  16721. // Update the pending async work count for previously unscheduled interaction.
  16722. interaction.__count++;
  16723. }
  16724. pendingInteractions.add(interaction);
  16725. });
  16726. } else {
  16727. pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
  16728. interactions.forEach(function(interaction) {
  16729. interaction.__count++;
  16730. });
  16731. }
  16732. var subscriber = tracing.__subscriberRef.current;
  16733. if (subscriber !== null) {
  16734. var threadID = computeThreadID(root, expirationTime);
  16735. subscriber.onWorkScheduled(interactions, threadID);
  16736. }
  16737. }
  16738. }
  16739. function schedulePendingInteractions(root, expirationTime) {
  16740. scheduleInteractions(root, expirationTime, tracing.__interactionsRef.current);
  16741. }
  16742. function startWorkOnPendingInteractions(root, expirationTime) {
  16743. // we can accurately attribute time spent working on it, And so that cascading
  16744. // work triggered during the render phase will be associated with it.
  16745. var interactions = new Set();
  16746. root.pendingInteractionMap.forEach(function(
  16747. scheduledInteractions,
  16748. scheduledExpirationTime
  16749. ) {
  16750. if (scheduledExpirationTime >= expirationTime) {
  16751. scheduledInteractions.forEach(function(interaction) {
  16752. return interactions.add(interaction);
  16753. });
  16754. }
  16755. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  16756. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  16757. // without having to recalculate it. We will also use it in commitWork() to
  16758. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  16759. // way to access it when the onCommitRoot() hook is called.
  16760. root.memoizedInteractions = interactions;
  16761. if (interactions.size > 0) {
  16762. var subscriber = tracing.__subscriberRef.current;
  16763. if (subscriber !== null) {
  16764. var threadID = computeThreadID(root, expirationTime);
  16765. try {
  16766. subscriber.onWorkStarted(interactions, threadID);
  16767. } catch (error) {
  16768. // If the subscriber throws, rethrow it in a separate task
  16769. scheduleCallback(ImmediatePriority, function() {
  16770. throw error;
  16771. });
  16772. }
  16773. }
  16774. }
  16775. }
  16776. function finishPendingInteractions(root, committedExpirationTime) {
  16777. var earliestRemainingTimeAfterCommit = root.firstPendingTime;
  16778. var subscriber;
  16779. try {
  16780. subscriber = tracing.__subscriberRef.current;
  16781. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  16782. var threadID = computeThreadID(root, committedExpirationTime);
  16783. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  16784. }
  16785. } catch (error) {
  16786. // If the subscriber throws, rethrow it in a separate task
  16787. scheduleCallback(ImmediatePriority, function() {
  16788. throw error;
  16789. });
  16790. } finally {
  16791. // Clear completed interactions from the pending Map.
  16792. // Unless the render was suspended or cascading work was scheduled,
  16793. // In which case– leave pending interactions until the subsequent render.
  16794. var pendingInteractionMap = root.pendingInteractionMap;
  16795. pendingInteractionMap.forEach(function(
  16796. scheduledInteractions,
  16797. scheduledExpirationTime
  16798. ) {
  16799. // Only decrement the pending interaction count if we're done.
  16800. // If there's still work at the current priority,
  16801. // That indicates that we are waiting for suspense data.
  16802. if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
  16803. pendingInteractionMap.delete(scheduledExpirationTime);
  16804. scheduledInteractions.forEach(function(interaction) {
  16805. interaction.__count--;
  16806. if (subscriber !== null && interaction.__count === 0) {
  16807. try {
  16808. subscriber.onInteractionScheduledWorkCompleted(interaction);
  16809. } catch (error) {
  16810. // If the subscriber throws, rethrow it in a separate task
  16811. scheduleCallback(ImmediatePriority, function() {
  16812. throw error;
  16813. });
  16814. }
  16815. }
  16816. });
  16817. }
  16818. });
  16819. }
  16820. }
  16821. var onScheduleFiberRoot = null;
  16822. var onCommitFiberRoot = null;
  16823. var onCommitFiberUnmount = null;
  16824. var hasLoggedError = false;
  16825. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined";
  16826. function injectInternals(internals) {
  16827. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") {
  16828. // No DevTools
  16829. return false;
  16830. }
  16831. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  16832. if (hook.isDisabled) {
  16833. // This isn't a real property on the hook, but it can be set to opt out
  16834. // of DevTools integration and associated warnings and logs.
  16835. // https://github.com/facebook/react/issues/3877
  16836. return true;
  16837. }
  16838. if (!hook.supportsFiber) {
  16839. {
  16840. error(
  16841. "The installed version of React DevTools is too old and will not work " +
  16842. "with the current version of React. Please update React DevTools. " +
  16843. "https://fb.me/react-devtools"
  16844. );
  16845. } // DevTools exists, even though it doesn't support Fiber.
  16846. return true;
  16847. }
  16848. try {
  16849. var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  16850. if (true) {
  16851. // Only used by Fast Refresh
  16852. if (typeof hook.onScheduleFiberRoot === "function") {
  16853. onScheduleFiberRoot = function(root, children) {
  16854. try {
  16855. hook.onScheduleFiberRoot(rendererID, root, children);
  16856. } catch (err) {
  16857. if (true && !hasLoggedError) {
  16858. hasLoggedError = true;
  16859. error("React instrumentation encountered an error: %s", err);
  16860. }
  16861. }
  16862. };
  16863. }
  16864. }
  16865. onCommitFiberRoot = function(root, expirationTime) {
  16866. try {
  16867. var didError = (root.current.effectTag & DidCapture) === DidCapture;
  16868. if (enableProfilerTimer) {
  16869. var currentTime = getCurrentTime();
  16870. var priorityLevel = inferPriorityFromExpirationTime(
  16871. currentTime,
  16872. expirationTime
  16873. );
  16874. hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  16875. } else {
  16876. hook.onCommitFiberRoot(rendererID, root, undefined, didError);
  16877. }
  16878. } catch (err) {
  16879. if (true) {
  16880. if (!hasLoggedError) {
  16881. hasLoggedError = true;
  16882. error("React instrumentation encountered an error: %s", err);
  16883. }
  16884. }
  16885. }
  16886. };
  16887. onCommitFiberUnmount = function(fiber) {
  16888. try {
  16889. hook.onCommitFiberUnmount(rendererID, fiber);
  16890. } catch (err) {
  16891. if (true) {
  16892. if (!hasLoggedError) {
  16893. hasLoggedError = true;
  16894. error("React instrumentation encountered an error: %s", err);
  16895. }
  16896. }
  16897. }
  16898. };
  16899. } catch (err) {
  16900. // Catch all errors because it is unsafe to throw during initialization.
  16901. {
  16902. error("React instrumentation encountered an error: %s.", err);
  16903. }
  16904. } // DevTools exists
  16905. return true;
  16906. }
  16907. function onScheduleRoot(root, children) {
  16908. if (typeof onScheduleFiberRoot === "function") {
  16909. onScheduleFiberRoot(root, children);
  16910. }
  16911. }
  16912. function onCommitRoot(root, expirationTime) {
  16913. if (typeof onCommitFiberRoot === "function") {
  16914. onCommitFiberRoot(root, expirationTime);
  16915. }
  16916. }
  16917. function onCommitUnmount(fiber) {
  16918. if (typeof onCommitFiberUnmount === "function") {
  16919. onCommitFiberUnmount(fiber);
  16920. }
  16921. }
  16922. var hasBadMapPolyfill;
  16923. {
  16924. hasBadMapPolyfill = false;
  16925. try {
  16926. var nonExtensibleObject = Object.preventExtensions({});
  16927. var testMap = new Map([[nonExtensibleObject, null]]);
  16928. var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
  16929. // https://github.com/rollup/rollup/issues/1771
  16930. // TODO: we can remove these if Rollup fixes the bug.
  16931. testMap.set(0, 0);
  16932. testSet.add(0);
  16933. } catch (e) {
  16934. // TODO: Consider warning about bad polyfills
  16935. hasBadMapPolyfill = true;
  16936. }
  16937. }
  16938. var debugCounter = 1;
  16939. function FiberNode(tag, pendingProps, key, mode) {
  16940. // Instance
  16941. this.tag = tag;
  16942. this.key = key;
  16943. this.elementType = null;
  16944. this.type = null;
  16945. this.stateNode = null; // Fiber
  16946. this.return = null;
  16947. this.child = null;
  16948. this.sibling = null;
  16949. this.index = 0;
  16950. this.ref = null;
  16951. this.pendingProps = pendingProps;
  16952. this.memoizedProps = null;
  16953. this.updateQueue = null;
  16954. this.memoizedState = null;
  16955. this.dependencies = null;
  16956. this.mode = mode; // Effects
  16957. this.effectTag = NoEffect;
  16958. this.nextEffect = null;
  16959. this.firstEffect = null;
  16960. this.lastEffect = null;
  16961. this.expirationTime = NoWork;
  16962. this.childExpirationTime = NoWork;
  16963. this.alternate = null;
  16964. {
  16965. // Note: The following is done to avoid a v8 performance cliff.
  16966. //
  16967. // Initializing the fields below to smis and later updating them with
  16968. // double values will cause Fibers to end up having separate shapes.
  16969. // This behavior/bug has something to do with Object.preventExtension().
  16970. // Fortunately this only impacts DEV builds.
  16971. // Unfortunately it makes React unusably slow for some applications.
  16972. // To work around this, initialize the fields below with doubles.
  16973. //
  16974. // Learn more about this here:
  16975. // https://github.com/facebook/react/issues/14365
  16976. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  16977. this.actualDuration = Number.NaN;
  16978. this.actualStartTime = Number.NaN;
  16979. this.selfBaseDuration = Number.NaN;
  16980. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  16981. // This won't trigger the performance cliff mentioned above,
  16982. // and it simplifies other profiler code (including DevTools).
  16983. this.actualDuration = 0;
  16984. this.actualStartTime = -1;
  16985. this.selfBaseDuration = 0;
  16986. this.treeBaseDuration = 0;
  16987. } // This is normally DEV-only except www when it adds listeners.
  16988. // TODO: remove the User Timing integration in favor of Root Events.
  16989. {
  16990. this._debugID = debugCounter++;
  16991. this._debugIsCurrentlyTiming = false;
  16992. }
  16993. {
  16994. this._debugSource = null;
  16995. this._debugOwner = null;
  16996. this._debugNeedsRemount = false;
  16997. this._debugHookTypes = null;
  16998. if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") {
  16999. Object.preventExtensions(this);
  17000. }
  17001. }
  17002. } // This is a constructor function, rather than a POJO constructor, still
  17003. // please ensure we do the following:
  17004. // 1) Nobody should add any instance methods on this. Instance methods can be
  17005. // more difficult to predict when they get optimized and they are almost
  17006. // never inlined properly in static compilers.
  17007. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  17008. // always know when it is a fiber.
  17009. // 3) We might want to experiment with using numeric keys since they are easier
  17010. // to optimize in a non-JIT environment.
  17011. // 4) We can easily go from a constructor to a createFiber object literal if that
  17012. // is faster.
  17013. // 5) It should be easy to port this to a C struct and keep a C implementation
  17014. // compatible.
  17015. var createFiber = function(tag, pendingProps, key, mode) {
  17016. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  17017. return new FiberNode(tag, pendingProps, key, mode);
  17018. };
  17019. function shouldConstruct(Component) {
  17020. var prototype = Component.prototype;
  17021. return !!(prototype && prototype.isReactComponent);
  17022. }
  17023. function isSimpleFunctionComponent(type) {
  17024. return (
  17025. typeof type === "function" &&
  17026. !shouldConstruct(type) &&
  17027. type.defaultProps === undefined
  17028. );
  17029. }
  17030. function resolveLazyComponentTag(Component) {
  17031. if (typeof Component === "function") {
  17032. return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
  17033. } else if (Component !== undefined && Component !== null) {
  17034. var $$typeof = Component.$$typeof;
  17035. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  17036. return ForwardRef;
  17037. }
  17038. if ($$typeof === REACT_MEMO_TYPE) {
  17039. return MemoComponent;
  17040. }
  17041. }
  17042. return IndeterminateComponent;
  17043. } // This is used to create an alternate fiber to do work on.
  17044. function createWorkInProgress(current, pendingProps) {
  17045. var workInProgress = current.alternate;
  17046. if (workInProgress === null) {
  17047. // We use a double buffering pooling technique because we know that we'll
  17048. // only ever need at most two versions of a tree. We pool the "other" unused
  17049. // node that we're free to reuse. This is lazily created to avoid allocating
  17050. // extra objects for things that are never updated. It also allow us to
  17051. // reclaim the extra memory if needed.
  17052. workInProgress = createFiber(
  17053. current.tag,
  17054. pendingProps,
  17055. current.key,
  17056. current.mode
  17057. );
  17058. workInProgress.elementType = current.elementType;
  17059. workInProgress.type = current.type;
  17060. workInProgress.stateNode = current.stateNode;
  17061. {
  17062. // DEV-only fields
  17063. {
  17064. workInProgress._debugID = current._debugID;
  17065. }
  17066. workInProgress._debugSource = current._debugSource;
  17067. workInProgress._debugOwner = current._debugOwner;
  17068. workInProgress._debugHookTypes = current._debugHookTypes;
  17069. }
  17070. workInProgress.alternate = current;
  17071. current.alternate = workInProgress;
  17072. } else {
  17073. workInProgress.pendingProps = pendingProps; // We already have an alternate.
  17074. // Reset the effect tag.
  17075. workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
  17076. workInProgress.nextEffect = null;
  17077. workInProgress.firstEffect = null;
  17078. workInProgress.lastEffect = null;
  17079. {
  17080. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  17081. // This prevents time from endlessly accumulating in new commits.
  17082. // This has the downside of resetting values for different priority renders,
  17083. // But works for yielding (the common case) and should support resuming.
  17084. workInProgress.actualDuration = 0;
  17085. workInProgress.actualStartTime = -1;
  17086. }
  17087. }
  17088. {
  17089. // Trying to debug a mysterious internal-only production failure.
  17090. // See D20130868 and t62461245.
  17091. // This is only on for RN FB builds.
  17092. if (current == null) {
  17093. throw Error("current is " + current + " but it can't be");
  17094. }
  17095. if (workInProgress == null) {
  17096. throw Error("workInProgress is " + workInProgress + " but it can't be");
  17097. }
  17098. }
  17099. workInProgress.childExpirationTime = current.childExpirationTime;
  17100. workInProgress.expirationTime = current.expirationTime;
  17101. workInProgress.child = current.child;
  17102. workInProgress.memoizedProps = current.memoizedProps;
  17103. workInProgress.memoizedState = current.memoizedState;
  17104. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  17105. // it cannot be shared with the current fiber.
  17106. var currentDependencies = current.dependencies;
  17107. workInProgress.dependencies =
  17108. currentDependencies === null
  17109. ? null
  17110. : {
  17111. expirationTime: currentDependencies.expirationTime,
  17112. firstContext: currentDependencies.firstContext,
  17113. responders: currentDependencies.responders
  17114. }; // These will be overridden during the parent's reconciliation
  17115. workInProgress.sibling = current.sibling;
  17116. workInProgress.index = current.index;
  17117. workInProgress.ref = current.ref;
  17118. {
  17119. workInProgress.selfBaseDuration = current.selfBaseDuration;
  17120. workInProgress.treeBaseDuration = current.treeBaseDuration;
  17121. }
  17122. {
  17123. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  17124. switch (workInProgress.tag) {
  17125. case IndeterminateComponent:
  17126. case FunctionComponent:
  17127. case SimpleMemoComponent:
  17128. workInProgress.type = resolveFunctionForHotReloading(current.type);
  17129. break;
  17130. case ClassComponent:
  17131. workInProgress.type = resolveClassForHotReloading(current.type);
  17132. break;
  17133. case ForwardRef:
  17134. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  17135. break;
  17136. }
  17137. }
  17138. return workInProgress;
  17139. } // Used to reuse a Fiber for a second pass.
  17140. function resetWorkInProgress(workInProgress, renderExpirationTime) {
  17141. // This resets the Fiber to what createFiber or createWorkInProgress would
  17142. // have set the values to before during the first pass. Ideally this wouldn't
  17143. // be necessary but unfortunately many code paths reads from the workInProgress
  17144. // when they should be reading from current and writing to workInProgress.
  17145. // We assume pendingProps, index, key, ref, return are still untouched to
  17146. // avoid doing another reconciliation.
  17147. // Reset the effect tag but keep any Placement tags, since that's something
  17148. // that child fiber is setting, not the reconciliation.
  17149. workInProgress.effectTag &= Placement; // The effect list is no longer valid.
  17150. workInProgress.nextEffect = null;
  17151. workInProgress.firstEffect = null;
  17152. workInProgress.lastEffect = null;
  17153. var current = workInProgress.alternate;
  17154. if (current === null) {
  17155. // Reset to createFiber's initial values.
  17156. workInProgress.childExpirationTime = NoWork;
  17157. workInProgress.expirationTime = renderExpirationTime;
  17158. workInProgress.child = null;
  17159. workInProgress.memoizedProps = null;
  17160. workInProgress.memoizedState = null;
  17161. workInProgress.updateQueue = null;
  17162. workInProgress.dependencies = null;
  17163. {
  17164. // Note: We don't reset the actualTime counts. It's useful to accumulate
  17165. // actual time across multiple render passes.
  17166. workInProgress.selfBaseDuration = 0;
  17167. workInProgress.treeBaseDuration = 0;
  17168. }
  17169. } else {
  17170. // Reset to the cloned values that createWorkInProgress would've.
  17171. workInProgress.childExpirationTime = current.childExpirationTime;
  17172. workInProgress.expirationTime = current.expirationTime;
  17173. workInProgress.child = current.child;
  17174. workInProgress.memoizedProps = current.memoizedProps;
  17175. workInProgress.memoizedState = current.memoizedState;
  17176. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  17177. // it cannot be shared with the current fiber.
  17178. var currentDependencies = current.dependencies;
  17179. workInProgress.dependencies =
  17180. currentDependencies === null
  17181. ? null
  17182. : {
  17183. expirationTime: currentDependencies.expirationTime,
  17184. firstContext: currentDependencies.firstContext,
  17185. responders: currentDependencies.responders
  17186. };
  17187. {
  17188. // Note: We don't reset the actualTime counts. It's useful to accumulate
  17189. // actual time across multiple render passes.
  17190. workInProgress.selfBaseDuration = current.selfBaseDuration;
  17191. workInProgress.treeBaseDuration = current.treeBaseDuration;
  17192. }
  17193. }
  17194. return workInProgress;
  17195. }
  17196. function createHostRootFiber(tag) {
  17197. var mode;
  17198. if (tag === ConcurrentRoot) {
  17199. mode = ConcurrentMode | BlockingMode | StrictMode;
  17200. } else if (tag === BlockingRoot) {
  17201. mode = BlockingMode | StrictMode;
  17202. } else {
  17203. mode = NoMode;
  17204. }
  17205. if (isDevToolsPresent) {
  17206. // Always collect profile timings when DevTools are present.
  17207. // This enables DevTools to start capturing timing at any point–
  17208. // Without some nodes in the tree having empty base times.
  17209. mode |= ProfileMode;
  17210. }
  17211. return createFiber(HostRoot, null, null, mode);
  17212. }
  17213. function createFiberFromTypeAndProps(
  17214. type, // React$ElementType
  17215. key,
  17216. pendingProps,
  17217. owner,
  17218. mode,
  17219. expirationTime
  17220. ) {
  17221. var fiber;
  17222. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  17223. var resolvedType = type;
  17224. if (typeof type === "function") {
  17225. if (shouldConstruct(type)) {
  17226. fiberTag = ClassComponent;
  17227. {
  17228. resolvedType = resolveClassForHotReloading(resolvedType);
  17229. }
  17230. } else {
  17231. {
  17232. resolvedType = resolveFunctionForHotReloading(resolvedType);
  17233. }
  17234. }
  17235. } else if (typeof type === "string") {
  17236. fiberTag = HostComponent;
  17237. } else {
  17238. getTag: switch (type) {
  17239. case REACT_FRAGMENT_TYPE:
  17240. return createFiberFromFragment(
  17241. pendingProps.children,
  17242. mode,
  17243. expirationTime,
  17244. key
  17245. );
  17246. case REACT_CONCURRENT_MODE_TYPE:
  17247. fiberTag = Mode;
  17248. mode |= ConcurrentMode | BlockingMode | StrictMode;
  17249. break;
  17250. case REACT_STRICT_MODE_TYPE:
  17251. fiberTag = Mode;
  17252. mode |= StrictMode;
  17253. break;
  17254. case REACT_PROFILER_TYPE:
  17255. return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
  17256. case REACT_SUSPENSE_TYPE:
  17257. return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
  17258. case REACT_SUSPENSE_LIST_TYPE:
  17259. return createFiberFromSuspenseList(
  17260. pendingProps,
  17261. mode,
  17262. expirationTime,
  17263. key
  17264. );
  17265. default: {
  17266. if (typeof type === "object" && type !== null) {
  17267. switch (type.$$typeof) {
  17268. case REACT_PROVIDER_TYPE:
  17269. fiberTag = ContextProvider;
  17270. break getTag;
  17271. case REACT_CONTEXT_TYPE:
  17272. // This is a consumer
  17273. fiberTag = ContextConsumer;
  17274. break getTag;
  17275. case REACT_FORWARD_REF_TYPE:
  17276. fiberTag = ForwardRef;
  17277. {
  17278. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  17279. }
  17280. break getTag;
  17281. case REACT_MEMO_TYPE:
  17282. fiberTag = MemoComponent;
  17283. break getTag;
  17284. case REACT_LAZY_TYPE:
  17285. fiberTag = LazyComponent;
  17286. resolvedType = null;
  17287. break getTag;
  17288. case REACT_BLOCK_TYPE:
  17289. fiberTag = Block;
  17290. break getTag;
  17291. }
  17292. }
  17293. var info = "";
  17294. {
  17295. if (
  17296. type === undefined ||
  17297. (typeof type === "object" &&
  17298. type !== null &&
  17299. Object.keys(type).length === 0)
  17300. ) {
  17301. info +=
  17302. " You likely forgot to export your component from the file " +
  17303. "it's defined in, or you might have mixed up default and " +
  17304. "named imports.";
  17305. }
  17306. var ownerName = owner ? getComponentName(owner.type) : null;
  17307. if (ownerName) {
  17308. info += "\n\nCheck the render method of `" + ownerName + "`.";
  17309. }
  17310. }
  17311. {
  17312. throw Error(
  17313. "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: " +
  17314. (type == null ? type : typeof type) +
  17315. "." +
  17316. info
  17317. );
  17318. }
  17319. }
  17320. }
  17321. }
  17322. fiber = createFiber(fiberTag, pendingProps, key, mode);
  17323. fiber.elementType = type;
  17324. fiber.type = resolvedType;
  17325. fiber.expirationTime = expirationTime;
  17326. return fiber;
  17327. }
  17328. function createFiberFromElement(element, mode, expirationTime) {
  17329. var owner = null;
  17330. {
  17331. owner = element._owner;
  17332. }
  17333. var type = element.type;
  17334. var key = element.key;
  17335. var pendingProps = element.props;
  17336. var fiber = createFiberFromTypeAndProps(
  17337. type,
  17338. key,
  17339. pendingProps,
  17340. owner,
  17341. mode,
  17342. expirationTime
  17343. );
  17344. {
  17345. fiber._debugSource = element._source;
  17346. fiber._debugOwner = element._owner;
  17347. }
  17348. return fiber;
  17349. }
  17350. function createFiberFromFragment(elements, mode, expirationTime, key) {
  17351. var fiber = createFiber(Fragment, elements, key, mode);
  17352. fiber.expirationTime = expirationTime;
  17353. return fiber;
  17354. }
  17355. function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
  17356. {
  17357. if (typeof pendingProps.id !== "string") {
  17358. error('Profiler must specify an "id" as a prop');
  17359. }
  17360. }
  17361. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  17362. fiber.elementType = REACT_PROFILER_TYPE;
  17363. fiber.type = REACT_PROFILER_TYPE;
  17364. fiber.expirationTime = expirationTime;
  17365. {
  17366. fiber.stateNode = {
  17367. effectDuration: 0,
  17368. passiveEffectDuration: 0
  17369. };
  17370. }
  17371. return fiber;
  17372. }
  17373. function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
  17374. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  17375. // This needs to be fixed in getComponentName so that it relies on the tag
  17376. // instead.
  17377. fiber.type = REACT_SUSPENSE_TYPE;
  17378. fiber.elementType = REACT_SUSPENSE_TYPE;
  17379. fiber.expirationTime = expirationTime;
  17380. return fiber;
  17381. }
  17382. function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
  17383. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  17384. {
  17385. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  17386. // This needs to be fixed in getComponentName so that it relies on the tag
  17387. // instead.
  17388. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  17389. }
  17390. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  17391. fiber.expirationTime = expirationTime;
  17392. return fiber;
  17393. }
  17394. function createFiberFromText(content, mode, expirationTime) {
  17395. var fiber = createFiber(HostText, content, null, mode);
  17396. fiber.expirationTime = expirationTime;
  17397. return fiber;
  17398. }
  17399. function createFiberFromPortal(portal, mode, expirationTime) {
  17400. var pendingProps = portal.children !== null ? portal.children : [];
  17401. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  17402. fiber.expirationTime = expirationTime;
  17403. fiber.stateNode = {
  17404. containerInfo: portal.containerInfo,
  17405. pendingChildren: null,
  17406. // Used by persistent updates
  17407. implementation: portal.implementation
  17408. };
  17409. return fiber;
  17410. } // Used for stashing WIP properties to replay failed work in DEV.
  17411. function assignFiberPropertiesInDEV(target, source) {
  17412. if (target === null) {
  17413. // This Fiber's initial properties will always be overwritten.
  17414. // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
  17415. target = createFiber(IndeterminateComponent, null, null, NoMode);
  17416. } // This is intentionally written as a list of all properties.
  17417. // We tried to use Object.assign() instead but this is called in
  17418. // the hottest path, and Object.assign() was too slow:
  17419. // https://github.com/facebook/react/issues/12502
  17420. // This code is DEV-only so size is not a concern.
  17421. target.tag = source.tag;
  17422. target.key = source.key;
  17423. target.elementType = source.elementType;
  17424. target.type = source.type;
  17425. target.stateNode = source.stateNode;
  17426. target.return = source.return;
  17427. target.child = source.child;
  17428. target.sibling = source.sibling;
  17429. target.index = source.index;
  17430. target.ref = source.ref;
  17431. target.pendingProps = source.pendingProps;
  17432. target.memoizedProps = source.memoizedProps;
  17433. target.updateQueue = source.updateQueue;
  17434. target.memoizedState = source.memoizedState;
  17435. target.dependencies = source.dependencies;
  17436. target.mode = source.mode;
  17437. target.effectTag = source.effectTag;
  17438. target.nextEffect = source.nextEffect;
  17439. target.firstEffect = source.firstEffect;
  17440. target.lastEffect = source.lastEffect;
  17441. target.expirationTime = source.expirationTime;
  17442. target.childExpirationTime = source.childExpirationTime;
  17443. target.alternate = source.alternate;
  17444. {
  17445. target.actualDuration = source.actualDuration;
  17446. target.actualStartTime = source.actualStartTime;
  17447. target.selfBaseDuration = source.selfBaseDuration;
  17448. target.treeBaseDuration = source.treeBaseDuration;
  17449. }
  17450. {
  17451. target._debugID = source._debugID;
  17452. target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
  17453. }
  17454. target._debugSource = source._debugSource;
  17455. target._debugOwner = source._debugOwner;
  17456. target._debugNeedsRemount = source._debugNeedsRemount;
  17457. target._debugHookTypes = source._debugHookTypes;
  17458. return target;
  17459. }
  17460. function FiberRootNode(containerInfo, tag, hydrate) {
  17461. this.tag = tag;
  17462. this.current = null;
  17463. this.containerInfo = containerInfo;
  17464. this.pendingChildren = null;
  17465. this.pingCache = null;
  17466. this.finishedExpirationTime = NoWork;
  17467. this.finishedWork = null;
  17468. this.timeoutHandle = noTimeout;
  17469. this.context = null;
  17470. this.pendingContext = null;
  17471. this.hydrate = hydrate;
  17472. this.callbackNode = null;
  17473. this.callbackPriority = NoPriority;
  17474. this.firstPendingTime = NoWork;
  17475. this.firstSuspendedTime = NoWork;
  17476. this.lastSuspendedTime = NoWork;
  17477. this.nextKnownPendingLevel = NoWork;
  17478. this.lastPingedTime = NoWork;
  17479. this.lastExpiredTime = NoWork;
  17480. {
  17481. this.interactionThreadID = tracing.unstable_getThreadID();
  17482. this.memoizedInteractions = new Set();
  17483. this.pendingInteractionMap = new Map();
  17484. }
  17485. }
  17486. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  17487. var root = new FiberRootNode(containerInfo, tag, hydrate);
  17488. // stateNode is any.
  17489. var uninitializedFiber = createHostRootFiber(tag);
  17490. root.current = uninitializedFiber;
  17491. uninitializedFiber.stateNode = root;
  17492. initializeUpdateQueue(uninitializedFiber);
  17493. return root;
  17494. }
  17495. function isRootSuspendedAtTime(root, expirationTime) {
  17496. var firstSuspendedTime = root.firstSuspendedTime;
  17497. var lastSuspendedTime = root.lastSuspendedTime;
  17498. return (
  17499. firstSuspendedTime !== NoWork &&
  17500. firstSuspendedTime >= expirationTime &&
  17501. lastSuspendedTime <= expirationTime
  17502. );
  17503. }
  17504. function markRootSuspendedAtTime(root, expirationTime) {
  17505. var firstSuspendedTime = root.firstSuspendedTime;
  17506. var lastSuspendedTime = root.lastSuspendedTime;
  17507. if (firstSuspendedTime < expirationTime) {
  17508. root.firstSuspendedTime = expirationTime;
  17509. }
  17510. if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
  17511. root.lastSuspendedTime = expirationTime;
  17512. }
  17513. if (expirationTime <= root.lastPingedTime) {
  17514. root.lastPingedTime = NoWork;
  17515. }
  17516. if (expirationTime <= root.lastExpiredTime) {
  17517. root.lastExpiredTime = NoWork;
  17518. }
  17519. }
  17520. function markRootUpdatedAtTime(root, expirationTime) {
  17521. // Update the range of pending times
  17522. var firstPendingTime = root.firstPendingTime;
  17523. if (expirationTime > firstPendingTime) {
  17524. root.firstPendingTime = expirationTime;
  17525. } // Update the range of suspended times. Treat everything lower priority or
  17526. // equal to this update as unsuspended.
  17527. var firstSuspendedTime = root.firstSuspendedTime;
  17528. if (firstSuspendedTime !== NoWork) {
  17529. if (expirationTime >= firstSuspendedTime) {
  17530. // The entire suspended range is now unsuspended.
  17531. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  17532. } else if (expirationTime >= root.lastSuspendedTime) {
  17533. root.lastSuspendedTime = expirationTime + 1;
  17534. } // This is a pending level. Check if it's higher priority than the next
  17535. // known pending level.
  17536. if (expirationTime > root.nextKnownPendingLevel) {
  17537. root.nextKnownPendingLevel = expirationTime;
  17538. }
  17539. }
  17540. }
  17541. function markRootFinishedAtTime(
  17542. root,
  17543. finishedExpirationTime,
  17544. remainingExpirationTime
  17545. ) {
  17546. // Update the range of pending times
  17547. root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
  17548. // equal to this update as unsuspended.
  17549. if (finishedExpirationTime <= root.lastSuspendedTime) {
  17550. // The entire suspended range is now unsuspended.
  17551. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  17552. } else if (finishedExpirationTime <= root.firstSuspendedTime) {
  17553. // Part of the suspended range is now unsuspended. Narrow the range to
  17554. // include everything between the unsuspended time (non-inclusive) and the
  17555. // last suspended time.
  17556. root.firstSuspendedTime = finishedExpirationTime - 1;
  17557. }
  17558. if (finishedExpirationTime <= root.lastPingedTime) {
  17559. // Clear the pinged time
  17560. root.lastPingedTime = NoWork;
  17561. }
  17562. if (finishedExpirationTime <= root.lastExpiredTime) {
  17563. // Clear the expired time
  17564. root.lastExpiredTime = NoWork;
  17565. }
  17566. }
  17567. function markRootExpiredAtTime(root, expirationTime) {
  17568. var lastExpiredTime = root.lastExpiredTime;
  17569. if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
  17570. root.lastExpiredTime = expirationTime;
  17571. }
  17572. }
  17573. var didWarnAboutNestedUpdates;
  17574. var didWarnAboutFindNodeInStrictMode;
  17575. {
  17576. didWarnAboutNestedUpdates = false;
  17577. didWarnAboutFindNodeInStrictMode = {};
  17578. }
  17579. function getContextForSubtree(parentComponent) {
  17580. if (!parentComponent) {
  17581. return emptyContextObject;
  17582. }
  17583. var fiber = get(parentComponent);
  17584. var parentContext = findCurrentUnmaskedContext(fiber);
  17585. if (fiber.tag === ClassComponent) {
  17586. var Component = fiber.type;
  17587. if (isContextProvider(Component)) {
  17588. return processChildContext(fiber, Component, parentContext);
  17589. }
  17590. }
  17591. return parentContext;
  17592. }
  17593. function findHostInstanceWithWarning(component, methodName) {
  17594. {
  17595. var fiber = get(component);
  17596. if (fiber === undefined) {
  17597. if (typeof component.render === "function") {
  17598. {
  17599. throw Error("Unable to find node on an unmounted component.");
  17600. }
  17601. } else {
  17602. {
  17603. throw Error(
  17604. "Argument appears to not be a ReactComponent. Keys: " +
  17605. Object.keys(component)
  17606. );
  17607. }
  17608. }
  17609. }
  17610. var hostFiber = findCurrentHostFiber(fiber);
  17611. if (hostFiber === null) {
  17612. return null;
  17613. }
  17614. if (hostFiber.mode & StrictMode) {
  17615. var componentName = getComponentName(fiber.type) || "Component";
  17616. if (!didWarnAboutFindNodeInStrictMode[componentName]) {
  17617. didWarnAboutFindNodeInStrictMode[componentName] = true;
  17618. if (fiber.mode & StrictMode) {
  17619. error(
  17620. "%s is deprecated in StrictMode. " +
  17621. "%s was passed an instance of %s which is inside StrictMode. " +
  17622. "Instead, add a ref directly to the element you want to reference. " +
  17623. "Learn more about using refs safely here: " +
  17624. "https://fb.me/react-strict-mode-find-node%s",
  17625. methodName,
  17626. methodName,
  17627. componentName,
  17628. getStackByFiberInDevAndProd(hostFiber)
  17629. );
  17630. } else {
  17631. error(
  17632. "%s is deprecated in StrictMode. " +
  17633. "%s was passed an instance of %s which renders StrictMode children. " +
  17634. "Instead, add a ref directly to the element you want to reference. " +
  17635. "Learn more about using refs safely here: " +
  17636. "https://fb.me/react-strict-mode-find-node%s",
  17637. methodName,
  17638. methodName,
  17639. componentName,
  17640. getStackByFiberInDevAndProd(hostFiber)
  17641. );
  17642. }
  17643. }
  17644. }
  17645. return hostFiber.stateNode;
  17646. }
  17647. }
  17648. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  17649. return createFiberRoot(containerInfo, tag, hydrate);
  17650. }
  17651. function updateContainer(element, container, parentComponent, callback) {
  17652. {
  17653. onScheduleRoot(container, element);
  17654. }
  17655. var current$1 = container.current;
  17656. var currentTime = requestCurrentTimeForUpdate();
  17657. {
  17658. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  17659. if ("undefined" !== typeof jest) {
  17660. warnIfUnmockedScheduler(current$1);
  17661. warnIfNotScopedWithMatchingAct(current$1);
  17662. }
  17663. }
  17664. var suspenseConfig = requestCurrentSuspenseConfig();
  17665. var expirationTime = computeExpirationForFiber(
  17666. currentTime,
  17667. current$1,
  17668. suspenseConfig
  17669. );
  17670. var context = getContextForSubtree(parentComponent);
  17671. if (container.context === null) {
  17672. container.context = context;
  17673. } else {
  17674. container.pendingContext = context;
  17675. }
  17676. {
  17677. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  17678. didWarnAboutNestedUpdates = true;
  17679. error(
  17680. "Render methods should be a pure function of props and state; " +
  17681. "triggering nested component updates from render is not allowed. " +
  17682. "If necessary, trigger nested updates in componentDidUpdate.\n\n" +
  17683. "Check the render method of %s.",
  17684. getComponentName(current.type) || "Unknown"
  17685. );
  17686. }
  17687. }
  17688. var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
  17689. // being called "element".
  17690. update.payload = {
  17691. element: element
  17692. };
  17693. callback = callback === undefined ? null : callback;
  17694. if (callback !== null) {
  17695. {
  17696. if (typeof callback !== "function") {
  17697. error(
  17698. "render(...): Expected the last optional `callback` argument to be a " +
  17699. "function. Instead received: %s.",
  17700. callback
  17701. );
  17702. }
  17703. }
  17704. update.callback = callback;
  17705. }
  17706. enqueueUpdate(current$1, update);
  17707. scheduleWork(current$1, expirationTime);
  17708. return expirationTime;
  17709. }
  17710. function getPublicRootInstance(container) {
  17711. var containerFiber = container.current;
  17712. if (!containerFiber.child) {
  17713. return null;
  17714. }
  17715. switch (containerFiber.child.tag) {
  17716. case HostComponent:
  17717. return getPublicInstance(containerFiber.child.stateNode);
  17718. default:
  17719. return containerFiber.child.stateNode;
  17720. }
  17721. }
  17722. var shouldSuspendImpl = function(fiber) {
  17723. return false;
  17724. };
  17725. function shouldSuspend(fiber) {
  17726. return shouldSuspendImpl(fiber);
  17727. }
  17728. var overrideHookState = null;
  17729. var overrideProps = null;
  17730. var scheduleUpdate = null;
  17731. var setSuspenseHandler = null;
  17732. {
  17733. var copyWithSetImpl = function(obj, path, idx, value) {
  17734. if (idx >= path.length) {
  17735. return value;
  17736. }
  17737. var key = path[idx];
  17738. var updated = Array.isArray(obj) ? obj.slice() : Object.assign({}, obj); // $FlowFixMe number or string is fine here
  17739. updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
  17740. return updated;
  17741. };
  17742. var copyWithSet = function(obj, path, value) {
  17743. return copyWithSetImpl(obj, path, 0, value);
  17744. }; // Support DevTools editable values for useState and useReducer.
  17745. overrideHookState = function(fiber, id, path, value) {
  17746. // For now, the "id" of stateful hooks is just the stateful hook index.
  17747. // This may change in the future with e.g. nested hooks.
  17748. var currentHook = fiber.memoizedState;
  17749. while (currentHook !== null && id > 0) {
  17750. currentHook = currentHook.next;
  17751. id--;
  17752. }
  17753. if (currentHook !== null) {
  17754. var newState = copyWithSet(currentHook.memoizedState, path, value);
  17755. currentHook.memoizedState = newState;
  17756. currentHook.baseState = newState; // We aren't actually adding an update to the queue,
  17757. // because there is no update we can add for useReducer hooks that won't trigger an error.
  17758. // (There's no appropriate action type for DevTools overrides.)
  17759. // As a result though, React will see the scheduled update as a noop and bailout.
  17760. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  17761. fiber.memoizedProps = Object.assign({}, fiber.memoizedProps);
  17762. scheduleWork(fiber, Sync);
  17763. }
  17764. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  17765. overrideProps = function(fiber, path, value) {
  17766. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  17767. if (fiber.alternate) {
  17768. fiber.alternate.pendingProps = fiber.pendingProps;
  17769. }
  17770. scheduleWork(fiber, Sync);
  17771. };
  17772. scheduleUpdate = function(fiber) {
  17773. scheduleWork(fiber, Sync);
  17774. };
  17775. setSuspenseHandler = function(newShouldSuspendImpl) {
  17776. shouldSuspendImpl = newShouldSuspendImpl;
  17777. };
  17778. }
  17779. function injectIntoDevTools(devToolsConfig) {
  17780. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  17781. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  17782. return injectInternals({
  17783. bundleType: devToolsConfig.bundleType,
  17784. version: devToolsConfig.version,
  17785. rendererPackageName: devToolsConfig.rendererPackageName,
  17786. rendererConfig: devToolsConfig.rendererConfig,
  17787. overrideHookState: overrideHookState,
  17788. overrideProps: overrideProps,
  17789. setSuspenseHandler: setSuspenseHandler,
  17790. scheduleUpdate: scheduleUpdate,
  17791. currentDispatcherRef: ReactCurrentDispatcher,
  17792. findHostInstanceByFiber: function(fiber) {
  17793. var hostFiber = findCurrentHostFiber(fiber);
  17794. if (hostFiber === null) {
  17795. return null;
  17796. }
  17797. return hostFiber.stateNode;
  17798. },
  17799. findFiberByHostInstance: function(instance) {
  17800. if (!findFiberByHostInstance) {
  17801. // Might not be implemented by the renderer.
  17802. return null;
  17803. }
  17804. return findFiberByHostInstance(instance);
  17805. },
  17806. // React Refresh
  17807. findHostInstancesForRefresh: findHostInstancesForRefresh,
  17808. scheduleRefresh: scheduleRefresh,
  17809. scheduleRoot: scheduleRoot,
  17810. setRefreshHandler: setRefreshHandler,
  17811. // Enables DevTools to append owner stacks to error messages in DEV mode.
  17812. getCurrentFiber: function() {
  17813. return current;
  17814. }
  17815. });
  17816. }
  17817. var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing;
  17818. function createPortal(
  17819. children,
  17820. containerInfo, // TODO: figure out the API for cross-renderer implementation.
  17821. implementation
  17822. ) {
  17823. var key =
  17824. arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  17825. return {
  17826. // This tag allow us to uniquely identify this as a React Portal
  17827. $$typeof: REACT_PORTAL_TYPE,
  17828. key: key == null ? null : "" + key,
  17829. children: children,
  17830. containerInfo: containerInfo,
  17831. implementation: implementation
  17832. };
  17833. }
  17834. // TODO: this is special because it gets imported during build.
  17835. var ReactVersion = "16.13.0";
  17836. var emptyObject$1 = {};
  17837. {
  17838. Object.freeze(emptyObject$1);
  17839. }
  17840. var getInspectorDataForViewTag;
  17841. var getInspectorDataForViewAtPoint;
  17842. {
  17843. var traverseOwnerTreeUp = function(hierarchy, instance) {
  17844. if (instance) {
  17845. hierarchy.unshift(instance);
  17846. traverseOwnerTreeUp(hierarchy, instance._debugOwner);
  17847. }
  17848. };
  17849. var getOwnerHierarchy = function(instance) {
  17850. var hierarchy = [];
  17851. traverseOwnerTreeUp(hierarchy, instance);
  17852. return hierarchy;
  17853. };
  17854. var lastNonHostInstance = function(hierarchy) {
  17855. for (var i = hierarchy.length - 1; i > 1; i--) {
  17856. var instance = hierarchy[i];
  17857. if (instance.tag !== HostComponent) {
  17858. return instance;
  17859. }
  17860. }
  17861. return hierarchy[0];
  17862. };
  17863. var getHostProps = function(fiber) {
  17864. var host = findCurrentHostFiber(fiber);
  17865. if (host) {
  17866. return host.memoizedProps || emptyObject$1;
  17867. }
  17868. return emptyObject$1;
  17869. };
  17870. var getHostNode = function(fiber, findNodeHandle) {
  17871. var hostNode; // look for children first for the hostNode
  17872. // as composite fibers do not have a hostNode
  17873. while (fiber) {
  17874. if (fiber.stateNode !== null && fiber.tag === HostComponent) {
  17875. hostNode = findNodeHandle(fiber.stateNode);
  17876. }
  17877. if (hostNode) {
  17878. return hostNode;
  17879. }
  17880. fiber = fiber.child;
  17881. }
  17882. return null;
  17883. };
  17884. var createHierarchy = function(fiberHierarchy) {
  17885. return fiberHierarchy.map(function(fiber) {
  17886. return {
  17887. name: getComponentName(fiber.type),
  17888. getInspectorData: function(findNodeHandle) {
  17889. return {
  17890. props: getHostProps(fiber),
  17891. source: fiber._debugSource,
  17892. measure: function(callback) {
  17893. // If this is Fabric, we'll find a ShadowNode and use that to measure.
  17894. var hostFiber = findCurrentHostFiber(fiber);
  17895. var shadowNode =
  17896. hostFiber != null &&
  17897. hostFiber.stateNode !== null &&
  17898. hostFiber.stateNode.node;
  17899. if (shadowNode) {
  17900. nativeFabricUIManager.measure(shadowNode, callback);
  17901. } else {
  17902. return ReactNativePrivateInterface.UIManager.measure(
  17903. getHostNode(fiber, findNodeHandle),
  17904. callback
  17905. );
  17906. }
  17907. }
  17908. };
  17909. }
  17910. };
  17911. });
  17912. };
  17913. var getInspectorDataForInstance = function(closestInstance) {
  17914. // Handle case where user clicks outside of ReactNative
  17915. if (!closestInstance) {
  17916. return {
  17917. hierarchy: [],
  17918. props: emptyObject$1,
  17919. selectedIndex: null,
  17920. source: null
  17921. };
  17922. }
  17923. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17924. var fiberHierarchy = getOwnerHierarchy(fiber);
  17925. var instance = lastNonHostInstance(fiberHierarchy);
  17926. var hierarchy = createHierarchy(fiberHierarchy);
  17927. var props = getHostProps(instance);
  17928. var source = instance._debugSource;
  17929. var selectedIndex = fiberHierarchy.indexOf(instance);
  17930. return {
  17931. hierarchy: hierarchy,
  17932. props: props,
  17933. selectedIndex: selectedIndex,
  17934. source: source
  17935. };
  17936. };
  17937. getInspectorDataForViewTag = function(viewTag) {
  17938. var closestInstance = getInstanceFromTag(viewTag); // Handle case where user clicks outside of ReactNative
  17939. if (!closestInstance) {
  17940. return {
  17941. hierarchy: [],
  17942. props: emptyObject$1,
  17943. selectedIndex: null,
  17944. source: null
  17945. };
  17946. }
  17947. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17948. var fiberHierarchy = getOwnerHierarchy(fiber);
  17949. var instance = lastNonHostInstance(fiberHierarchy);
  17950. var hierarchy = createHierarchy(fiberHierarchy);
  17951. var props = getHostProps(instance);
  17952. var source = instance._debugSource;
  17953. var selectedIndex = fiberHierarchy.indexOf(instance);
  17954. return {
  17955. hierarchy: hierarchy,
  17956. props: props,
  17957. selectedIndex: selectedIndex,
  17958. source: source
  17959. };
  17960. };
  17961. getInspectorDataForViewAtPoint = function(
  17962. findNodeHandle,
  17963. inspectedView,
  17964. locationX,
  17965. locationY,
  17966. callback
  17967. ) {
  17968. var closestInstance = null;
  17969. if (inspectedView._internalInstanceHandle != null) {
  17970. // For Fabric we can look up the instance handle directly and measure it.
  17971. nativeFabricUIManager.findNodeAtPoint(
  17972. inspectedView._internalInstanceHandle.stateNode.node,
  17973. locationX,
  17974. locationY,
  17975. function(internalInstanceHandle) {
  17976. if (internalInstanceHandle == null) {
  17977. callback(
  17978. Object.assign(
  17979. {
  17980. pointerY: locationY,
  17981. frame: {
  17982. left: 0,
  17983. top: 0,
  17984. width: 0,
  17985. height: 0
  17986. }
  17987. },
  17988. getInspectorDataForInstance(closestInstance)
  17989. )
  17990. );
  17991. }
  17992. closestInstance =
  17993. internalInstanceHandle.stateNode.canonical._internalInstanceHandle;
  17994. nativeFabricUIManager.measure(
  17995. internalInstanceHandle.stateNode.node,
  17996. function(x, y, width, height, pageX, pageY) {
  17997. callback(
  17998. Object.assign(
  17999. {
  18000. pointerY: locationY,
  18001. frame: {
  18002. left: pageX,
  18003. top: pageY,
  18004. width: width,
  18005. height: height
  18006. }
  18007. },
  18008. getInspectorDataForInstance(closestInstance)
  18009. )
  18010. );
  18011. }
  18012. );
  18013. }
  18014. );
  18015. } else if (inspectedView._internalFiberInstanceHandleDEV != null) {
  18016. // For Paper we fall back to the old strategy using the React tag.
  18017. ReactNativePrivateInterface.UIManager.findSubviewIn(
  18018. findNodeHandle(inspectedView),
  18019. [locationX, locationY],
  18020. function(nativeViewTag, left, top, width, height) {
  18021. var inspectorData = getInspectorDataForInstance(
  18022. getInstanceFromTag(nativeViewTag)
  18023. );
  18024. callback(
  18025. Object.assign({}, inspectorData, {
  18026. pointerY: locationY,
  18027. frame: {
  18028. left: left,
  18029. top: top,
  18030. width: width,
  18031. height: height
  18032. },
  18033. touchedViewTag: nativeViewTag
  18034. })
  18035. );
  18036. }
  18037. );
  18038. } else {
  18039. error(
  18040. "getInspectorDataForViewAtPoint expects to receieve a host component"
  18041. );
  18042. return;
  18043. }
  18044. };
  18045. }
  18046. var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
  18047. function findHostInstance_DEPRECATED(componentOrHandle) {
  18048. {
  18049. var owner = ReactCurrentOwner$3.current;
  18050. if (owner !== null && owner.stateNode !== null) {
  18051. if (!owner.stateNode._warnedAboutRefsInRender) {
  18052. error(
  18053. "%s is accessing findNodeHandle inside its render(). " +
  18054. "render() should be a pure function of props and state. It should " +
  18055. "never access something that requires stale data from the previous " +
  18056. "render, such as refs. Move this logic to componentDidMount and " +
  18057. "componentDidUpdate instead.",
  18058. getComponentName(owner.type) || "A component"
  18059. );
  18060. }
  18061. owner.stateNode._warnedAboutRefsInRender = true;
  18062. }
  18063. }
  18064. if (componentOrHandle == null) {
  18065. return null;
  18066. }
  18067. if (componentOrHandle._nativeTag) {
  18068. return componentOrHandle;
  18069. }
  18070. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  18071. return componentOrHandle.canonical;
  18072. }
  18073. var hostInstance;
  18074. {
  18075. hostInstance = findHostInstanceWithWarning(
  18076. componentOrHandle,
  18077. "findHostInstance_DEPRECATED"
  18078. );
  18079. }
  18080. if (hostInstance == null) {
  18081. return hostInstance;
  18082. }
  18083. if (hostInstance.canonical) {
  18084. // Fabric
  18085. return hostInstance.canonical;
  18086. }
  18087. return hostInstance;
  18088. }
  18089. function findNodeHandle(componentOrHandle) {
  18090. {
  18091. var owner = ReactCurrentOwner$3.current;
  18092. if (owner !== null && owner.stateNode !== null) {
  18093. if (!owner.stateNode._warnedAboutRefsInRender) {
  18094. error(
  18095. "%s is accessing findNodeHandle inside its render(). " +
  18096. "render() should be a pure function of props and state. It should " +
  18097. "never access something that requires stale data from the previous " +
  18098. "render, such as refs. Move this logic to componentDidMount and " +
  18099. "componentDidUpdate instead.",
  18100. getComponentName(owner.type) || "A component"
  18101. );
  18102. }
  18103. owner.stateNode._warnedAboutRefsInRender = true;
  18104. }
  18105. }
  18106. if (componentOrHandle == null) {
  18107. return null;
  18108. }
  18109. if (typeof componentOrHandle === "number") {
  18110. // Already a node handle
  18111. return componentOrHandle;
  18112. }
  18113. if (componentOrHandle._nativeTag) {
  18114. return componentOrHandle._nativeTag;
  18115. }
  18116. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  18117. return componentOrHandle.canonical._nativeTag;
  18118. }
  18119. var hostInstance;
  18120. {
  18121. hostInstance = findHostInstanceWithWarning(
  18122. componentOrHandle,
  18123. "findNodeHandle"
  18124. );
  18125. }
  18126. if (hostInstance == null) {
  18127. return hostInstance;
  18128. }
  18129. if (hostInstance.canonical) {
  18130. // Fabric
  18131. return hostInstance.canonical._nativeTag;
  18132. }
  18133. return hostInstance._nativeTag;
  18134. }
  18135. function dispatchCommand(handle, command, args) {
  18136. if (handle._nativeTag == null) {
  18137. {
  18138. error(
  18139. "dispatchCommand was called with a ref that isn't a " +
  18140. "native component. Use React.forwardRef to get access to the underlying native component"
  18141. );
  18142. }
  18143. return;
  18144. }
  18145. if (handle._internalInstanceHandle) {
  18146. nativeFabricUIManager.dispatchCommand(
  18147. handle._internalInstanceHandle.stateNode.node,
  18148. command,
  18149. args
  18150. );
  18151. } else {
  18152. ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
  18153. handle._nativeTag,
  18154. command,
  18155. args
  18156. );
  18157. }
  18158. }
  18159. function render(element, containerTag, callback) {
  18160. var root = roots.get(containerTag);
  18161. if (!root) {
  18162. // TODO (bvaughn): If we decide to keep the wrapper component,
  18163. // We could create a wrapper for containerTag as well to reduce special casing.
  18164. root = createContainer(containerTag, LegacyRoot, false);
  18165. roots.set(containerTag, root);
  18166. }
  18167. updateContainer(element, root, null, callback);
  18168. return getPublicRootInstance(root);
  18169. }
  18170. function unmountComponentAtNode(containerTag) {
  18171. var root = roots.get(containerTag);
  18172. if (root) {
  18173. // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
  18174. updateContainer(null, root, null, function() {
  18175. roots.delete(containerTag);
  18176. });
  18177. }
  18178. }
  18179. function unmountComponentAtNodeAndRemoveContainer(containerTag) {
  18180. unmountComponentAtNode(containerTag); // Call back into native to remove all of the subviews from this container
  18181. ReactNativePrivateInterface.UIManager.removeRootView(containerTag);
  18182. }
  18183. function createPortal$1(children, containerTag) {
  18184. var key =
  18185. arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  18186. return createPortal(children, containerTag, null, key);
  18187. }
  18188. setBatchingImplementation(batchedUpdates$1);
  18189. function computeComponentStackForErrorReporting(reactTag) {
  18190. var fiber = getInstanceFromTag(reactTag);
  18191. if (!fiber) {
  18192. return "";
  18193. }
  18194. return getStackByFiberInDevAndProd(fiber);
  18195. }
  18196. var roots = new Map();
  18197. var Internals = {
  18198. computeComponentStackForErrorReporting: computeComponentStackForErrorReporting
  18199. };
  18200. injectIntoDevTools({
  18201. findFiberByHostInstance: getInstanceFromTag,
  18202. bundleType: 1,
  18203. version: ReactVersion,
  18204. rendererPackageName: "react-native-renderer",
  18205. rendererConfig: {
  18206. getInspectorDataForViewTag: getInspectorDataForViewTag,
  18207. getInspectorDataForViewAtPoint: getInspectorDataForViewAtPoint.bind(
  18208. null,
  18209. findNodeHandle
  18210. )
  18211. }
  18212. });
  18213. exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = Internals;
  18214. exports.createPortal = createPortal$1;
  18215. exports.dispatchCommand = dispatchCommand;
  18216. exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
  18217. exports.findNodeHandle = findNodeHandle;
  18218. exports.render = render;
  18219. exports.unmountComponentAtNode = unmountComponentAtNode;
  18220. exports.unmountComponentAtNodeAndRemoveContainer = unmountComponentAtNodeAndRemoveContainer;
  18221. exports.unstable_batchedUpdates = batchedUpdates;
  18222. })();
  18223. }