ReactNativeRenderer-dev.js 639 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136
  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. * @providesModule ReactNativeRenderer-dev
  10. * @preventMunge
  11. * @generated
  12. */
  13. 'use strict';
  14. if (__DEV__) {
  15. (function() {
  16. "use strict";
  17. var React = require("react");
  18. require("react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore");
  19. var ReactNativePrivateInterface = require("react-native/Libraries/ReactPrivate/ReactNativePrivateInterface");
  20. var Scheduler = require("scheduler");
  21. var tracing = require("scheduler/tracing");
  22. var ReactSharedInternals =
  23. React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
  24. // Current owner and dispatcher used to share the same ref,
  25. // but PR #14548 split them out to better support the react-debug-tools package.
  26. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher")) {
  27. ReactSharedInternals.ReactCurrentDispatcher = {
  28. current: null
  29. };
  30. }
  31. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentBatchConfig")) {
  32. ReactSharedInternals.ReactCurrentBatchConfig = {
  33. suspense: null
  34. };
  35. }
  36. // by calls to these methods by a Babel plugin.
  37. //
  38. // In PROD (or in packages without access to React internals),
  39. // they are left as they are instead.
  40. function warn(format) {
  41. {
  42. for (
  43. var _len = arguments.length,
  44. args = new Array(_len > 1 ? _len - 1 : 0),
  45. _key = 1;
  46. _key < _len;
  47. _key++
  48. ) {
  49. args[_key - 1] = arguments[_key];
  50. }
  51. printWarning("warn", format, args);
  52. }
  53. }
  54. function error(format) {
  55. {
  56. for (
  57. var _len2 = arguments.length,
  58. args = new Array(_len2 > 1 ? _len2 - 1 : 0),
  59. _key2 = 1;
  60. _key2 < _len2;
  61. _key2++
  62. ) {
  63. args[_key2 - 1] = arguments[_key2];
  64. }
  65. printWarning("error", format, args);
  66. }
  67. }
  68. function printWarning(level, format, args) {
  69. // When changing this logic, you might want to also
  70. // update consoleWithStackDev.www.js as well.
  71. {
  72. var hasExistingStack =
  73. args.length > 0 &&
  74. typeof args[args.length - 1] === "string" &&
  75. args[args.length - 1].indexOf("\n in") === 0;
  76. if (!hasExistingStack) {
  77. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  78. var stack = ReactDebugCurrentFrame.getStackAddendum();
  79. if (stack !== "") {
  80. format += "%s";
  81. args = args.concat([stack]);
  82. }
  83. }
  84. var argsWithFormat = args.map(function(item) {
  85. return "" + item;
  86. }); // Careful: RN currently depends on this prefix
  87. argsWithFormat.unshift("Warning: " + format); // We intentionally don't use spread (or .apply) directly because it
  88. // breaks IE9: https://github.com/facebook/react/issues/13610
  89. // eslint-disable-next-line react-internal/no-production-logging
  90. Function.prototype.apply.call(console[level], console, argsWithFormat);
  91. try {
  92. // --- Welcome to debugging React ---
  93. // This error was thrown as a convenience so that you can use this stack
  94. // to find the callsite that caused this warning to fire.
  95. var argIndex = 0;
  96. var message =
  97. "Warning: " +
  98. format.replace(/%s/g, function() {
  99. return args[argIndex++];
  100. });
  101. throw new Error(message);
  102. } catch (x) {}
  103. }
  104. }
  105. var FunctionComponent = 0;
  106. var ClassComponent = 1;
  107. var IndeterminateComponent = 2; // Before we know whether it is function or class
  108. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  109. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  110. var HostComponent = 5;
  111. var HostText = 6;
  112. var Fragment = 7;
  113. var Mode = 8;
  114. var ContextConsumer = 9;
  115. var ContextProvider = 10;
  116. var ForwardRef = 11;
  117. var Profiler = 12;
  118. var SuspenseComponent = 13;
  119. var MemoComponent = 14;
  120. var SimpleMemoComponent = 15;
  121. var LazyComponent = 16;
  122. var IncompleteClassComponent = 17;
  123. var DehydratedFragment = 18;
  124. var SuspenseListComponent = 19;
  125. var FundamentalComponent = 20;
  126. var ScopeComponent = 21;
  127. var Block = 22;
  128. function getParent(inst) {
  129. do {
  130. inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
  131. // That is depending on if we want nested subtrees (layers) to bubble
  132. // events to their parent. We could also go through parentNode on the
  133. // host node but that wouldn't work for React Native and doesn't let us
  134. // do the portal feature.
  135. } while (inst && inst.tag !== HostComponent);
  136. if (inst) {
  137. return inst;
  138. }
  139. return null;
  140. }
  141. /**
  142. * Return the lowest common ancestor of A and B, or null if they are in
  143. * different trees.
  144. */
  145. function getLowestCommonAncestor(instA, instB) {
  146. var depthA = 0;
  147. for (var tempA = instA; tempA; tempA = getParent(tempA)) {
  148. depthA++;
  149. }
  150. var depthB = 0;
  151. for (var tempB = instB; tempB; tempB = getParent(tempB)) {
  152. depthB++;
  153. } // If A is deeper, crawl up.
  154. while (depthA - depthB > 0) {
  155. instA = getParent(instA);
  156. depthA--;
  157. } // If B is deeper, crawl up.
  158. while (depthB - depthA > 0) {
  159. instB = getParent(instB);
  160. depthB--;
  161. } // Walk in lockstep until we find a match.
  162. var depth = depthA;
  163. while (depth--) {
  164. if (instA === instB || instA === instB.alternate) {
  165. return instA;
  166. }
  167. instA = getParent(instA);
  168. instB = getParent(instB);
  169. }
  170. return null;
  171. }
  172. /**
  173. * Return if A is an ancestor of B.
  174. */
  175. function isAncestor(instA, instB) {
  176. while (instB) {
  177. if (instA === instB || instA === instB.alternate) {
  178. return true;
  179. }
  180. instB = getParent(instB);
  181. }
  182. return false;
  183. }
  184. /**
  185. * Return the parent instance of the passed-in instance.
  186. */
  187. function getParentInstance(inst) {
  188. return getParent(inst);
  189. }
  190. /**
  191. * Simulates the traversal of a two-phase, capture/bubble event dispatch.
  192. */
  193. function traverseTwoPhase(inst, fn, arg) {
  194. var path = [];
  195. while (inst) {
  196. path.push(inst);
  197. inst = getParent(inst);
  198. }
  199. var i;
  200. for (i = path.length; i-- > 0; ) {
  201. fn(path[i], "captured", arg);
  202. }
  203. for (i = 0; i < path.length; i++) {
  204. fn(path[i], "bubbled", arg);
  205. }
  206. }
  207. var invokeGuardedCallbackImpl = function(
  208. name,
  209. func,
  210. context,
  211. a,
  212. b,
  213. c,
  214. d,
  215. e,
  216. f
  217. ) {
  218. var funcArgs = Array.prototype.slice.call(arguments, 3);
  219. try {
  220. func.apply(context, funcArgs);
  221. } catch (error) {
  222. this.onError(error);
  223. }
  224. };
  225. {
  226. // In DEV mode, we swap out invokeGuardedCallback for a special version
  227. // that plays more nicely with the browser's DevTools. The idea is to preserve
  228. // "Pause on exceptions" behavior. Because React wraps all user-provided
  229. // functions in invokeGuardedCallback, and the production version of
  230. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  231. // like caught exceptions, and the DevTools won't pause unless the developer
  232. // takes the extra step of enabling pause on caught exceptions. This is
  233. // unintuitive, though, because even though React has caught the error, from
  234. // the developer's perspective, the error is uncaught.
  235. //
  236. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  237. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  238. // DOM node, and call the user-provided callback from inside an event handler
  239. // for that fake event. If the callback throws, the error is "captured" using
  240. // a global event handler. But because the error happens in a different
  241. // event loop context, it does not interrupt the normal program flow.
  242. // Effectively, this gives us try-catch behavior without actually using
  243. // try-catch. Neat!
  244. // Check that the browser supports the APIs we need to implement our special
  245. // DEV version of invokeGuardedCallback
  246. if (
  247. typeof window !== "undefined" &&
  248. typeof window.dispatchEvent === "function" &&
  249. typeof document !== "undefined" &&
  250. typeof document.createEvent === "function"
  251. ) {
  252. var fakeNode = document.createElement("react");
  253. var invokeGuardedCallbackDev = function(
  254. name,
  255. func,
  256. context,
  257. a,
  258. b,
  259. c,
  260. d,
  261. e,
  262. f
  263. ) {
  264. // If document doesn't exist we know for sure we will crash in this method
  265. // when we call document.createEvent(). However this can cause confusing
  266. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  267. // So we preemptively throw with a better message instead.
  268. if (!(typeof document !== "undefined")) {
  269. throw Error(
  270. "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."
  271. );
  272. }
  273. var evt = document.createEvent("Event"); // Keeps track of whether the user-provided callback threw an error. We
  274. // set this to true at the beginning, then set it to false right after
  275. // calling the function. If the function errors, `didError` will never be
  276. // set to false. This strategy works even if the browser is flaky and
  277. // fails to call our global error handler, because it doesn't rely on
  278. // the error event at all.
  279. var didError = true; // Keeps track of the value of window.event so that we can reset it
  280. // during the callback to let user code access window.event in the
  281. // browsers that support it.
  282. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  283. // dispatching: https://github.com/facebook/react/issues/13688
  284. var windowEventDescriptor = Object.getOwnPropertyDescriptor(
  285. window,
  286. "event"
  287. ); // Create an event handler for our fake event. We will synchronously
  288. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  289. // call the user-provided callback.
  290. var funcArgs = Array.prototype.slice.call(arguments, 3);
  291. function callCallback() {
  292. // We immediately remove the callback from event listeners so that
  293. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  294. // nested call would trigger the fake event handlers of any call higher
  295. // in the stack.
  296. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  297. // window.event assignment in both IE <= 10 as they throw an error
  298. // "Member not found" in strict mode, and in Firefox which does not
  299. // support window.event.
  300. if (
  301. typeof window.event !== "undefined" &&
  302. window.hasOwnProperty("event")
  303. ) {
  304. window.event = windowEvent;
  305. }
  306. func.apply(context, funcArgs);
  307. didError = false;
  308. } // Create a global error event handler. We use this to capture the value
  309. // that was thrown. It's possible that this error handler will fire more
  310. // than once; for example, if non-React code also calls `dispatchEvent`
  311. // and a handler for that event throws. We should be resilient to most of
  312. // those cases. Even if our error event handler fires more than once, the
  313. // last error event is always used. If the callback actually does error,
  314. // we know that the last error event is the correct one, because it's not
  315. // possible for anything else to have happened in between our callback
  316. // erroring and the code that follows the `dispatchEvent` call below. If
  317. // the callback doesn't error, but the error event was fired, we know to
  318. // ignore it because `didError` will be false, as described above.
  319. var error; // Use this to track whether the error event is ever called.
  320. var didSetError = false;
  321. var isCrossOriginError = false;
  322. function handleWindowError(event) {
  323. error = event.error;
  324. didSetError = true;
  325. if (error === null && event.colno === 0 && event.lineno === 0) {
  326. isCrossOriginError = true;
  327. }
  328. if (event.defaultPrevented) {
  329. // Some other error handler has prevented default.
  330. // Browsers silence the error report if this happens.
  331. // We'll remember this to later decide whether to log it or not.
  332. if (error != null && typeof error === "object") {
  333. try {
  334. error._suppressLogging = true;
  335. } catch (inner) {
  336. // Ignore.
  337. }
  338. }
  339. }
  340. } // Create a fake event type.
  341. var evtType = "react-" + (name ? name : "invokeguardedcallback"); // Attach our event handlers
  342. window.addEventListener("error", handleWindowError);
  343. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  344. // errors, it will trigger our global error handler.
  345. evt.initEvent(evtType, false, false);
  346. fakeNode.dispatchEvent(evt);
  347. if (windowEventDescriptor) {
  348. Object.defineProperty(window, "event", windowEventDescriptor);
  349. }
  350. if (didError) {
  351. if (!didSetError) {
  352. // The callback errored, but the error event never fired.
  353. error = new Error(
  354. "An error was thrown inside one of your components, but React " +
  355. "doesn't know what it was. This is likely due to browser " +
  356. 'flakiness. React does its best to preserve the "Pause on ' +
  357. 'exceptions" behavior of the DevTools, which requires some ' +
  358. "DEV-mode only tricks. It's possible that these don't work in " +
  359. "your browser. Try triggering the error in production mode, " +
  360. "or switching to a modern browser. If you suspect that this is " +
  361. "actually an issue with React, please file an issue."
  362. );
  363. } else if (isCrossOriginError) {
  364. error = new Error(
  365. "A cross-origin error was thrown. React doesn't have access to " +
  366. "the actual error object in development. " +
  367. "See https://fb.me/react-crossorigin-error for more information."
  368. );
  369. }
  370. this.onError(error);
  371. } // Remove our event listeners
  372. window.removeEventListener("error", handleWindowError);
  373. };
  374. invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
  375. }
  376. }
  377. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  378. var hasError = false;
  379. var caughtError = null; // Used by event system to capture/rethrow the first error.
  380. var hasRethrowError = false;
  381. var rethrowError = null;
  382. var reporter = {
  383. onError: function(error) {
  384. hasError = true;
  385. caughtError = error;
  386. }
  387. };
  388. /**
  389. * Call a function while guarding against errors that happens within it.
  390. * Returns an error if it throws, otherwise null.
  391. *
  392. * In production, this is implemented using a try-catch. The reason we don't
  393. * use a try-catch directly is so that we can swap out a different
  394. * implementation in DEV mode.
  395. *
  396. * @param {String} name of the guard to use for logging or debugging
  397. * @param {Function} func The function to invoke
  398. * @param {*} context The context to use when calling the function
  399. * @param {...*} args Arguments for function
  400. */
  401. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  402. hasError = false;
  403. caughtError = null;
  404. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  405. }
  406. /**
  407. * Same as invokeGuardedCallback, but instead of returning an error, it stores
  408. * it in a global so it can be rethrown by `rethrowCaughtError` later.
  409. * TODO: See if caughtError and rethrowError can be unified.
  410. *
  411. * @param {String} name of the guard to use for logging or debugging
  412. * @param {Function} func The function to invoke
  413. * @param {*} context The context to use when calling the function
  414. * @param {...*} args Arguments for function
  415. */
  416. function invokeGuardedCallbackAndCatchFirstError(
  417. name,
  418. func,
  419. context,
  420. a,
  421. b,
  422. c,
  423. d,
  424. e,
  425. f
  426. ) {
  427. invokeGuardedCallback.apply(this, arguments);
  428. if (hasError) {
  429. var error = clearCaughtError();
  430. if (!hasRethrowError) {
  431. hasRethrowError = true;
  432. rethrowError = error;
  433. }
  434. }
  435. }
  436. /**
  437. * During execution of guarded functions we will capture the first error which
  438. * we will rethrow to be handled by the top level error handler.
  439. */
  440. function rethrowCaughtError() {
  441. if (hasRethrowError) {
  442. var error = rethrowError;
  443. hasRethrowError = false;
  444. rethrowError = null;
  445. throw error;
  446. }
  447. }
  448. function hasCaughtError() {
  449. return hasError;
  450. }
  451. function clearCaughtError() {
  452. if (hasError) {
  453. var error = caughtError;
  454. hasError = false;
  455. caughtError = null;
  456. return error;
  457. } else {
  458. {
  459. throw Error(
  460. "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue."
  461. );
  462. }
  463. }
  464. }
  465. var getFiberCurrentPropsFromNode = null;
  466. var getInstanceFromNode = null;
  467. var getNodeFromInstance = null;
  468. function setComponentTree(
  469. getFiberCurrentPropsFromNodeImpl,
  470. getInstanceFromNodeImpl,
  471. getNodeFromInstanceImpl
  472. ) {
  473. getFiberCurrentPropsFromNode = getFiberCurrentPropsFromNodeImpl;
  474. getInstanceFromNode = getInstanceFromNodeImpl;
  475. getNodeFromInstance = getNodeFromInstanceImpl;
  476. {
  477. if (!getNodeFromInstance || !getInstanceFromNode) {
  478. error(
  479. "EventPluginUtils.setComponentTree(...): Injected " +
  480. "module is missing getNodeFromInstance or getInstanceFromNode."
  481. );
  482. }
  483. }
  484. }
  485. var validateEventDispatches;
  486. {
  487. validateEventDispatches = function(event) {
  488. var dispatchListeners = event._dispatchListeners;
  489. var dispatchInstances = event._dispatchInstances;
  490. var listenersIsArr = Array.isArray(dispatchListeners);
  491. var listenersLen = listenersIsArr
  492. ? dispatchListeners.length
  493. : dispatchListeners
  494. ? 1
  495. : 0;
  496. var instancesIsArr = Array.isArray(dispatchInstances);
  497. var instancesLen = instancesIsArr
  498. ? dispatchInstances.length
  499. : dispatchInstances
  500. ? 1
  501. : 0;
  502. if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
  503. error("EventPluginUtils: Invalid `event`.");
  504. }
  505. };
  506. }
  507. /**
  508. * Dispatch the event to the listener.
  509. * @param {SyntheticEvent} event SyntheticEvent to handle
  510. * @param {function} listener Application-level callback
  511. * @param {*} inst Internal component instance
  512. */
  513. function executeDispatch(event, listener, inst) {
  514. var type = event.type || "unknown-event";
  515. event.currentTarget = getNodeFromInstance(inst);
  516. invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
  517. event.currentTarget = null;
  518. }
  519. /**
  520. * Standard/simple iteration through an event's collected dispatches.
  521. */
  522. function executeDispatchesInOrder(event) {
  523. var dispatchListeners = event._dispatchListeners;
  524. var dispatchInstances = event._dispatchInstances;
  525. {
  526. validateEventDispatches(event);
  527. }
  528. if (Array.isArray(dispatchListeners)) {
  529. for (var i = 0; i < dispatchListeners.length; i++) {
  530. if (event.isPropagationStopped()) {
  531. break;
  532. } // Listeners and Instances are two parallel arrays that are always in sync.
  533. executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
  534. }
  535. } else if (dispatchListeners) {
  536. executeDispatch(event, dispatchListeners, dispatchInstances);
  537. }
  538. event._dispatchListeners = null;
  539. event._dispatchInstances = null;
  540. }
  541. /**
  542. * Standard/simple iteration through an event's collected dispatches, but stops
  543. * at the first dispatch execution returning true, and returns that id.
  544. *
  545. * @return {?string} id of the first dispatch execution who's listener returns
  546. * true, or null if no listener returned true.
  547. */
  548. function executeDispatchesInOrderStopAtTrueImpl(event) {
  549. var dispatchListeners = event._dispatchListeners;
  550. var dispatchInstances = event._dispatchInstances;
  551. {
  552. validateEventDispatches(event);
  553. }
  554. if (Array.isArray(dispatchListeners)) {
  555. for (var i = 0; i < dispatchListeners.length; i++) {
  556. if (event.isPropagationStopped()) {
  557. break;
  558. } // Listeners and Instances are two parallel arrays that are always in sync.
  559. if (dispatchListeners[i](event, dispatchInstances[i])) {
  560. return dispatchInstances[i];
  561. }
  562. }
  563. } else if (dispatchListeners) {
  564. if (dispatchListeners(event, dispatchInstances)) {
  565. return dispatchInstances;
  566. }
  567. }
  568. return null;
  569. }
  570. /**
  571. * @see executeDispatchesInOrderStopAtTrueImpl
  572. */
  573. function executeDispatchesInOrderStopAtTrue(event) {
  574. var ret = executeDispatchesInOrderStopAtTrueImpl(event);
  575. event._dispatchInstances = null;
  576. event._dispatchListeners = null;
  577. return ret;
  578. }
  579. /**
  580. * Execution of a "direct" dispatch - there must be at most one dispatch
  581. * accumulated on the event or it is considered an error. It doesn't really make
  582. * sense for an event with multiple dispatches (bubbled) to keep track of the
  583. * return values at each dispatch execution, but it does tend to make sense when
  584. * dealing with "direct" dispatches.
  585. *
  586. * @return {*} The return value of executing the single dispatch.
  587. */
  588. function executeDirectDispatch(event) {
  589. {
  590. validateEventDispatches(event);
  591. }
  592. var dispatchListener = event._dispatchListeners;
  593. var dispatchInstance = event._dispatchInstances;
  594. if (!!Array.isArray(dispatchListener)) {
  595. throw Error("executeDirectDispatch(...): Invalid `event`.");
  596. }
  597. event.currentTarget = dispatchListener
  598. ? getNodeFromInstance(dispatchInstance)
  599. : null;
  600. var res = dispatchListener ? dispatchListener(event) : null;
  601. event.currentTarget = null;
  602. event._dispatchListeners = null;
  603. event._dispatchInstances = null;
  604. return res;
  605. }
  606. /**
  607. * @param {SyntheticEvent} event
  608. * @return {boolean} True iff number of dispatches accumulated is greater than 0.
  609. */
  610. function hasDispatches(event) {
  611. return !!event._dispatchListeners;
  612. }
  613. function isInteractive(tag) {
  614. return (
  615. tag === "button" ||
  616. tag === "input" ||
  617. tag === "select" ||
  618. tag === "textarea"
  619. );
  620. }
  621. function shouldPreventMouseEvent(name, type, props) {
  622. switch (name) {
  623. case "onClick":
  624. case "onClickCapture":
  625. case "onDoubleClick":
  626. case "onDoubleClickCapture":
  627. case "onMouseDown":
  628. case "onMouseDownCapture":
  629. case "onMouseMove":
  630. case "onMouseMoveCapture":
  631. case "onMouseUp":
  632. case "onMouseUpCapture":
  633. case "onMouseEnter":
  634. return !!(props.disabled && isInteractive(type));
  635. default:
  636. return false;
  637. }
  638. }
  639. /**
  640. * @param {object} inst The instance, which is the source of events.
  641. * @param {string} registrationName Name of listener (e.g. `onClick`).
  642. * @return {?function} The stored callback.
  643. */
  644. function getListener(inst, registrationName) {
  645. var listener; // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
  646. // live here; needs to be moved to a better place soon
  647. var stateNode = inst.stateNode;
  648. if (!stateNode) {
  649. // Work in progress (ex: onload events in incremental mode).
  650. return null;
  651. }
  652. var props = getFiberCurrentPropsFromNode(stateNode);
  653. if (!props) {
  654. // Work in progress.
  655. return null;
  656. }
  657. listener = props[registrationName];
  658. if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
  659. return null;
  660. }
  661. if (!(!listener || typeof listener === "function")) {
  662. throw Error(
  663. "Expected `" +
  664. registrationName +
  665. "` listener to be a function, instead got a value of `" +
  666. typeof listener +
  667. "` type."
  668. );
  669. }
  670. return listener;
  671. }
  672. /**
  673. * Accumulates items that must not be null or undefined into the first one. This
  674. * is used to conserve memory by avoiding array allocations, and thus sacrifices
  675. * API cleanness. Since `current` can be null before being passed in and not
  676. * null after this function, make sure to assign it back to `current`:
  677. *
  678. * `a = accumulateInto(a, b);`
  679. *
  680. * This API should be sparingly used. Try `accumulate` for something cleaner.
  681. *
  682. * @return {*|array<*>} An accumulation of items.
  683. */
  684. function accumulateInto(current, next) {
  685. if (!(next != null)) {
  686. throw Error(
  687. "accumulateInto(...): Accumulated items must not be null or undefined."
  688. );
  689. }
  690. if (current == null) {
  691. return next;
  692. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  693. // certain that x is an Array (x could be a string with concat method).
  694. if (Array.isArray(current)) {
  695. if (Array.isArray(next)) {
  696. current.push.apply(current, next);
  697. return current;
  698. }
  699. current.push(next);
  700. return current;
  701. }
  702. if (Array.isArray(next)) {
  703. // A bit too dangerous to mutate `next`.
  704. return [current].concat(next);
  705. }
  706. return [current, next];
  707. }
  708. /**
  709. * @param {array} arr an "accumulation" of items which is either an Array or
  710. * a single item. Useful when paired with the `accumulate` module. This is a
  711. * simple utility that allows us to reason about a collection of items, but
  712. * handling the case when there is exactly one item (and we do not need to
  713. * allocate an array).
  714. * @param {function} cb Callback invoked with each element or a collection.
  715. * @param {?} [scope] Scope used as `this` in a callback.
  716. */
  717. function forEachAccumulated(arr, cb, scope) {
  718. if (Array.isArray(arr)) {
  719. arr.forEach(cb, scope);
  720. } else if (arr) {
  721. cb.call(scope, arr);
  722. }
  723. }
  724. /**
  725. * Some event types have a notion of different registration names for different
  726. * "phases" of propagation. This finds listeners by a given phase.
  727. */
  728. function listenerAtPhase(inst, event, propagationPhase) {
  729. var registrationName =
  730. event.dispatchConfig.phasedRegistrationNames[propagationPhase];
  731. return getListener(inst, registrationName);
  732. }
  733. /**
  734. * A small set of propagation patterns, each of which will accept a small amount
  735. * of information, and generate a set of "dispatch ready event objects" - which
  736. * are sets of events that have already been annotated with a set of dispatched
  737. * listener functions/ids. The API is designed this way to discourage these
  738. * propagation strategies from actually executing the dispatches, since we
  739. * always want to collect the entire set of dispatches before executing even a
  740. * single one.
  741. */
  742. /**
  743. * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
  744. * here, allows us to not have to bind or create functions for each event.
  745. * Mutating the event's members allows us to not have to create a wrapping
  746. * "dispatch" object that pairs the event with the listener.
  747. */
  748. function accumulateDirectionalDispatches(inst, phase, event) {
  749. {
  750. if (!inst) {
  751. error("Dispatching inst must not be null");
  752. }
  753. }
  754. var listener = listenerAtPhase(inst, event, phase);
  755. if (listener) {
  756. event._dispatchListeners = accumulateInto(
  757. event._dispatchListeners,
  758. listener
  759. );
  760. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  761. }
  762. }
  763. /**
  764. * Collect dispatches (must be entirely collected before dispatching - see unit
  765. * tests). Lazily allocate the array to conserve memory. We must loop through
  766. * each event and perform the traversal for each one. We cannot perform a
  767. * single traversal for the entire collection of events because each event may
  768. * have a different target.
  769. */
  770. function accumulateTwoPhaseDispatchesSingle(event) {
  771. if (event && event.dispatchConfig.phasedRegistrationNames) {
  772. traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
  773. }
  774. }
  775. /**
  776. * Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
  777. */
  778. function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
  779. if (event && event.dispatchConfig.phasedRegistrationNames) {
  780. var targetInst = event._targetInst;
  781. var parentInst = targetInst ? getParentInstance(targetInst) : null;
  782. traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
  783. }
  784. }
  785. /**
  786. * Accumulates without regard to direction, does not look for phased
  787. * registration names. Same as `accumulateDirectDispatchesSingle` but without
  788. * requiring that the `dispatchMarker` be the same as the dispatched ID.
  789. */
  790. function accumulateDispatches(inst, ignoredDirection, event) {
  791. if (inst && event && event.dispatchConfig.registrationName) {
  792. var registrationName = event.dispatchConfig.registrationName;
  793. var listener = getListener(inst, registrationName);
  794. if (listener) {
  795. event._dispatchListeners = accumulateInto(
  796. event._dispatchListeners,
  797. listener
  798. );
  799. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  800. }
  801. }
  802. }
  803. /**
  804. * Accumulates dispatches on an `SyntheticEvent`, but only for the
  805. * `dispatchMarker`.
  806. * @param {SyntheticEvent} event
  807. */
  808. function accumulateDirectDispatchesSingle(event) {
  809. if (event && event.dispatchConfig.registrationName) {
  810. accumulateDispatches(event._targetInst, null, event);
  811. }
  812. }
  813. function accumulateTwoPhaseDispatches(events) {
  814. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
  815. }
  816. function accumulateTwoPhaseDispatchesSkipTarget(events) {
  817. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
  818. }
  819. function accumulateDirectDispatches(events) {
  820. forEachAccumulated(events, accumulateDirectDispatchesSingle);
  821. }
  822. var EVENT_POOL_SIZE = 10;
  823. /**
  824. * @interface Event
  825. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  826. */
  827. var EventInterface = {
  828. type: null,
  829. target: null,
  830. // currentTarget is set when dispatching; no use in copying it here
  831. currentTarget: function() {
  832. return null;
  833. },
  834. eventPhase: null,
  835. bubbles: null,
  836. cancelable: null,
  837. timeStamp: function(event) {
  838. return event.timeStamp || Date.now();
  839. },
  840. defaultPrevented: null,
  841. isTrusted: null
  842. };
  843. function functionThatReturnsTrue() {
  844. return true;
  845. }
  846. function functionThatReturnsFalse() {
  847. return false;
  848. }
  849. /**
  850. * Synthetic events are dispatched by event plugins, typically in response to a
  851. * top-level event delegation handler.
  852. *
  853. * These systems should generally use pooling to reduce the frequency of garbage
  854. * collection. The system should check `isPersistent` to determine whether the
  855. * event should be released into the pool after being dispatched. Users that
  856. * need a persisted event should invoke `persist`.
  857. *
  858. * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
  859. * normalizing browser quirks. Subclasses do not necessarily have to implement a
  860. * DOM interface; custom application-specific events can also subclass this.
  861. *
  862. * @param {object} dispatchConfig Configuration used to dispatch this event.
  863. * @param {*} targetInst Marker identifying the event target.
  864. * @param {object} nativeEvent Native browser event.
  865. * @param {DOMEventTarget} nativeEventTarget Target node.
  866. */
  867. function SyntheticEvent(
  868. dispatchConfig,
  869. targetInst,
  870. nativeEvent,
  871. nativeEventTarget
  872. ) {
  873. {
  874. // these have a getter/setter for warnings
  875. delete this.nativeEvent;
  876. delete this.preventDefault;
  877. delete this.stopPropagation;
  878. delete this.isDefaultPrevented;
  879. delete this.isPropagationStopped;
  880. }
  881. this.dispatchConfig = dispatchConfig;
  882. this._targetInst = targetInst;
  883. this.nativeEvent = nativeEvent;
  884. var Interface = this.constructor.Interface;
  885. for (var propName in Interface) {
  886. if (!Interface.hasOwnProperty(propName)) {
  887. continue;
  888. }
  889. {
  890. delete this[propName]; // this has a getter/setter for warnings
  891. }
  892. var normalize = Interface[propName];
  893. if (normalize) {
  894. this[propName] = normalize(nativeEvent);
  895. } else {
  896. if (propName === "target") {
  897. this.target = nativeEventTarget;
  898. } else {
  899. this[propName] = nativeEvent[propName];
  900. }
  901. }
  902. }
  903. var defaultPrevented =
  904. nativeEvent.defaultPrevented != null
  905. ? nativeEvent.defaultPrevented
  906. : nativeEvent.returnValue === false;
  907. if (defaultPrevented) {
  908. this.isDefaultPrevented = functionThatReturnsTrue;
  909. } else {
  910. this.isDefaultPrevented = functionThatReturnsFalse;
  911. }
  912. this.isPropagationStopped = functionThatReturnsFalse;
  913. return this;
  914. }
  915. Object.assign(SyntheticEvent.prototype, {
  916. preventDefault: function() {
  917. this.defaultPrevented = true;
  918. var event = this.nativeEvent;
  919. if (!event) {
  920. return;
  921. }
  922. if (event.preventDefault) {
  923. event.preventDefault();
  924. } else if (typeof event.returnValue !== "unknown") {
  925. event.returnValue = false;
  926. }
  927. this.isDefaultPrevented = functionThatReturnsTrue;
  928. },
  929. stopPropagation: function() {
  930. var event = this.nativeEvent;
  931. if (!event) {
  932. return;
  933. }
  934. if (event.stopPropagation) {
  935. event.stopPropagation();
  936. } else if (typeof event.cancelBubble !== "unknown") {
  937. // The ChangeEventPlugin registers a "propertychange" event for
  938. // IE. This event does not support bubbling or cancelling, and
  939. // any references to cancelBubble throw "Member not found". A
  940. // typeof check of "unknown" circumvents this issue (and is also
  941. // IE specific).
  942. event.cancelBubble = true;
  943. }
  944. this.isPropagationStopped = functionThatReturnsTrue;
  945. },
  946. /**
  947. * We release all dispatched `SyntheticEvent`s after each event loop, adding
  948. * them back into the pool. This allows a way to hold onto a reference that
  949. * won't be added back into the pool.
  950. */
  951. persist: function() {
  952. this.isPersistent = functionThatReturnsTrue;
  953. },
  954. /**
  955. * Checks if this event should be released back into the pool.
  956. *
  957. * @return {boolean} True if this should not be released, false otherwise.
  958. */
  959. isPersistent: functionThatReturnsFalse,
  960. /**
  961. * `PooledClass` looks for `destructor` on each instance it releases.
  962. */
  963. destructor: function() {
  964. var Interface = this.constructor.Interface;
  965. for (var propName in Interface) {
  966. {
  967. Object.defineProperty(
  968. this,
  969. propName,
  970. getPooledWarningPropertyDefinition(propName, Interface[propName])
  971. );
  972. }
  973. }
  974. this.dispatchConfig = null;
  975. this._targetInst = null;
  976. this.nativeEvent = null;
  977. this.isDefaultPrevented = functionThatReturnsFalse;
  978. this.isPropagationStopped = functionThatReturnsFalse;
  979. this._dispatchListeners = null;
  980. this._dispatchInstances = null;
  981. {
  982. Object.defineProperty(
  983. this,
  984. "nativeEvent",
  985. getPooledWarningPropertyDefinition("nativeEvent", null)
  986. );
  987. Object.defineProperty(
  988. this,
  989. "isDefaultPrevented",
  990. getPooledWarningPropertyDefinition(
  991. "isDefaultPrevented",
  992. functionThatReturnsFalse
  993. )
  994. );
  995. Object.defineProperty(
  996. this,
  997. "isPropagationStopped",
  998. getPooledWarningPropertyDefinition(
  999. "isPropagationStopped",
  1000. functionThatReturnsFalse
  1001. )
  1002. );
  1003. Object.defineProperty(
  1004. this,
  1005. "preventDefault",
  1006. getPooledWarningPropertyDefinition("preventDefault", function() {})
  1007. );
  1008. Object.defineProperty(
  1009. this,
  1010. "stopPropagation",
  1011. getPooledWarningPropertyDefinition("stopPropagation", function() {})
  1012. );
  1013. }
  1014. }
  1015. });
  1016. SyntheticEvent.Interface = EventInterface;
  1017. /**
  1018. * Helper to reduce boilerplate when creating subclasses.
  1019. */
  1020. SyntheticEvent.extend = function(Interface) {
  1021. var Super = this;
  1022. var E = function() {};
  1023. E.prototype = Super.prototype;
  1024. var prototype = new E();
  1025. function Class() {
  1026. return Super.apply(this, arguments);
  1027. }
  1028. Object.assign(prototype, Class.prototype);
  1029. Class.prototype = prototype;
  1030. Class.prototype.constructor = Class;
  1031. Class.Interface = Object.assign({}, Super.Interface, Interface);
  1032. Class.extend = Super.extend;
  1033. addEventPoolingTo(Class);
  1034. return Class;
  1035. };
  1036. addEventPoolingTo(SyntheticEvent);
  1037. /**
  1038. * Helper to nullify syntheticEvent instance properties when destructing
  1039. *
  1040. * @param {String} propName
  1041. * @param {?object} getVal
  1042. * @return {object} defineProperty object
  1043. */
  1044. function getPooledWarningPropertyDefinition(propName, getVal) {
  1045. var isFunction = typeof getVal === "function";
  1046. return {
  1047. configurable: true,
  1048. set: set,
  1049. get: get
  1050. };
  1051. function set(val) {
  1052. var action = isFunction ? "setting the method" : "setting the property";
  1053. warn(action, "This is effectively a no-op");
  1054. return val;
  1055. }
  1056. function get() {
  1057. var action = isFunction ? "accessing the method" : "accessing the property";
  1058. var result = isFunction
  1059. ? "This is a no-op function"
  1060. : "This is set to null";
  1061. warn(action, result);
  1062. return getVal;
  1063. }
  1064. function warn(action, result) {
  1065. {
  1066. error(
  1067. "This synthetic event is reused for performance reasons. If you're seeing this, " +
  1068. "you're %s `%s` on a released/nullified synthetic event. %s. " +
  1069. "If you must keep the original synthetic event around, use event.persist(). " +
  1070. "See https://fb.me/react-event-pooling for more information.",
  1071. action,
  1072. propName,
  1073. result
  1074. );
  1075. }
  1076. }
  1077. }
  1078. function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
  1079. var EventConstructor = this;
  1080. if (EventConstructor.eventPool.length) {
  1081. var instance = EventConstructor.eventPool.pop();
  1082. EventConstructor.call(
  1083. instance,
  1084. dispatchConfig,
  1085. targetInst,
  1086. nativeEvent,
  1087. nativeInst
  1088. );
  1089. return instance;
  1090. }
  1091. return new EventConstructor(
  1092. dispatchConfig,
  1093. targetInst,
  1094. nativeEvent,
  1095. nativeInst
  1096. );
  1097. }
  1098. function releasePooledEvent(event) {
  1099. var EventConstructor = this;
  1100. if (!(event instanceof EventConstructor)) {
  1101. throw Error(
  1102. "Trying to release an event instance into a pool of a different type."
  1103. );
  1104. }
  1105. event.destructor();
  1106. if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
  1107. EventConstructor.eventPool.push(event);
  1108. }
  1109. }
  1110. function addEventPoolingTo(EventConstructor) {
  1111. EventConstructor.eventPool = [];
  1112. EventConstructor.getPooled = getPooledEvent;
  1113. EventConstructor.release = releasePooledEvent;
  1114. }
  1115. /**
  1116. * `touchHistory` isn't actually on the native event, but putting it in the
  1117. * interface will ensure that it is cleaned up when pooled/destroyed. The
  1118. * `ResponderEventPlugin` will populate it appropriately.
  1119. */
  1120. var ResponderSyntheticEvent = SyntheticEvent.extend({
  1121. touchHistory: function(nativeEvent) {
  1122. return null; // Actually doesn't even look at the native event.
  1123. }
  1124. });
  1125. var TOP_TOUCH_START = "topTouchStart";
  1126. var TOP_TOUCH_MOVE = "topTouchMove";
  1127. var TOP_TOUCH_END = "topTouchEnd";
  1128. var TOP_TOUCH_CANCEL = "topTouchCancel";
  1129. var TOP_SCROLL = "topScroll";
  1130. var TOP_SELECTION_CHANGE = "topSelectionChange";
  1131. function isStartish(topLevelType) {
  1132. return topLevelType === TOP_TOUCH_START;
  1133. }
  1134. function isMoveish(topLevelType) {
  1135. return topLevelType === TOP_TOUCH_MOVE;
  1136. }
  1137. function isEndish(topLevelType) {
  1138. return topLevelType === TOP_TOUCH_END || topLevelType === TOP_TOUCH_CANCEL;
  1139. }
  1140. var startDependencies = [TOP_TOUCH_START];
  1141. var moveDependencies = [TOP_TOUCH_MOVE];
  1142. var endDependencies = [TOP_TOUCH_CANCEL, TOP_TOUCH_END];
  1143. /**
  1144. * Tracks the position and time of each active touch by `touch.identifier`. We
  1145. * should typically only see IDs in the range of 1-20 because IDs get recycled
  1146. * when touches end and start again.
  1147. */
  1148. var MAX_TOUCH_BANK = 20;
  1149. var touchBank = [];
  1150. var touchHistory = {
  1151. touchBank: touchBank,
  1152. numberActiveTouches: 0,
  1153. // If there is only one active touch, we remember its location. This prevents
  1154. // us having to loop through all of the touches all the time in the most
  1155. // common case.
  1156. indexOfSingleActiveTouch: -1,
  1157. mostRecentTimeStamp: 0
  1158. };
  1159. function timestampForTouch(touch) {
  1160. // The legacy internal implementation provides "timeStamp", which has been
  1161. // renamed to "timestamp". Let both work for now while we iron it out
  1162. // TODO (evv): rename timeStamp to timestamp in internal code
  1163. return touch.timeStamp || touch.timestamp;
  1164. }
  1165. /**
  1166. * TODO: Instead of making gestures recompute filtered velocity, we could
  1167. * include a built in velocity computation that can be reused globally.
  1168. */
  1169. function createTouchRecord(touch) {
  1170. return {
  1171. touchActive: true,
  1172. startPageX: touch.pageX,
  1173. startPageY: touch.pageY,
  1174. startTimeStamp: timestampForTouch(touch),
  1175. currentPageX: touch.pageX,
  1176. currentPageY: touch.pageY,
  1177. currentTimeStamp: timestampForTouch(touch),
  1178. previousPageX: touch.pageX,
  1179. previousPageY: touch.pageY,
  1180. previousTimeStamp: timestampForTouch(touch)
  1181. };
  1182. }
  1183. function resetTouchRecord(touchRecord, touch) {
  1184. touchRecord.touchActive = true;
  1185. touchRecord.startPageX = touch.pageX;
  1186. touchRecord.startPageY = touch.pageY;
  1187. touchRecord.startTimeStamp = timestampForTouch(touch);
  1188. touchRecord.currentPageX = touch.pageX;
  1189. touchRecord.currentPageY = touch.pageY;
  1190. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1191. touchRecord.previousPageX = touch.pageX;
  1192. touchRecord.previousPageY = touch.pageY;
  1193. touchRecord.previousTimeStamp = timestampForTouch(touch);
  1194. }
  1195. function getTouchIdentifier(_ref) {
  1196. var identifier = _ref.identifier;
  1197. if (!(identifier != null)) {
  1198. throw Error("Touch object is missing identifier.");
  1199. }
  1200. {
  1201. if (identifier > MAX_TOUCH_BANK) {
  1202. error(
  1203. "Touch identifier %s is greater than maximum supported %s which causes " +
  1204. "performance issues backfilling array locations for all of the indices.",
  1205. identifier,
  1206. MAX_TOUCH_BANK
  1207. );
  1208. }
  1209. }
  1210. return identifier;
  1211. }
  1212. function recordTouchStart(touch) {
  1213. var identifier = getTouchIdentifier(touch);
  1214. var touchRecord = touchBank[identifier];
  1215. if (touchRecord) {
  1216. resetTouchRecord(touchRecord, touch);
  1217. } else {
  1218. touchBank[identifier] = createTouchRecord(touch);
  1219. }
  1220. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1221. }
  1222. function recordTouchMove(touch) {
  1223. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1224. if (touchRecord) {
  1225. touchRecord.touchActive = true;
  1226. touchRecord.previousPageX = touchRecord.currentPageX;
  1227. touchRecord.previousPageY = touchRecord.currentPageY;
  1228. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1229. touchRecord.currentPageX = touch.pageX;
  1230. touchRecord.currentPageY = touch.pageY;
  1231. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1232. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1233. } else {
  1234. {
  1235. warn(
  1236. "Cannot record touch move without a touch start.\n" +
  1237. "Touch Move: %s\n" +
  1238. "Touch Bank: %s",
  1239. printTouch(touch),
  1240. printTouchBank()
  1241. );
  1242. }
  1243. }
  1244. }
  1245. function recordTouchEnd(touch) {
  1246. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1247. if (touchRecord) {
  1248. touchRecord.touchActive = false;
  1249. touchRecord.previousPageX = touchRecord.currentPageX;
  1250. touchRecord.previousPageY = touchRecord.currentPageY;
  1251. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1252. touchRecord.currentPageX = touch.pageX;
  1253. touchRecord.currentPageY = touch.pageY;
  1254. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1255. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1256. } else {
  1257. {
  1258. warn(
  1259. "Cannot record touch end without a touch start.\n" +
  1260. "Touch End: %s\n" +
  1261. "Touch Bank: %s",
  1262. printTouch(touch),
  1263. printTouchBank()
  1264. );
  1265. }
  1266. }
  1267. }
  1268. function printTouch(touch) {
  1269. return JSON.stringify({
  1270. identifier: touch.identifier,
  1271. pageX: touch.pageX,
  1272. pageY: touch.pageY,
  1273. timestamp: timestampForTouch(touch)
  1274. });
  1275. }
  1276. function printTouchBank() {
  1277. var printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK));
  1278. if (touchBank.length > MAX_TOUCH_BANK) {
  1279. printed += " (original size: " + touchBank.length + ")";
  1280. }
  1281. return printed;
  1282. }
  1283. var ResponderTouchHistoryStore = {
  1284. recordTouchTrack: function(topLevelType, nativeEvent) {
  1285. if (isMoveish(topLevelType)) {
  1286. nativeEvent.changedTouches.forEach(recordTouchMove);
  1287. } else if (isStartish(topLevelType)) {
  1288. nativeEvent.changedTouches.forEach(recordTouchStart);
  1289. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1290. if (touchHistory.numberActiveTouches === 1) {
  1291. touchHistory.indexOfSingleActiveTouch =
  1292. nativeEvent.touches[0].identifier;
  1293. }
  1294. } else if (isEndish(topLevelType)) {
  1295. nativeEvent.changedTouches.forEach(recordTouchEnd);
  1296. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1297. if (touchHistory.numberActiveTouches === 1) {
  1298. for (var i = 0; i < touchBank.length; i++) {
  1299. var touchTrackToCheck = touchBank[i];
  1300. if (touchTrackToCheck != null && touchTrackToCheck.touchActive) {
  1301. touchHistory.indexOfSingleActiveTouch = i;
  1302. break;
  1303. }
  1304. }
  1305. {
  1306. var activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
  1307. if (activeRecord == null || !activeRecord.touchActive) {
  1308. error("Cannot find single active touch.");
  1309. }
  1310. }
  1311. }
  1312. }
  1313. },
  1314. touchHistory: touchHistory
  1315. };
  1316. /**
  1317. * Accumulates items that must not be null or undefined.
  1318. *
  1319. * This is used to conserve memory by avoiding array allocations.
  1320. *
  1321. * @return {*|array<*>} An accumulation of items.
  1322. */
  1323. function accumulate(current, next) {
  1324. if (!(next != null)) {
  1325. throw Error(
  1326. "accumulate(...): Accumulated items must not be null or undefined."
  1327. );
  1328. }
  1329. if (current == null) {
  1330. return next;
  1331. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  1332. // certain that x is an Array (x could be a string with concat method).
  1333. if (Array.isArray(current)) {
  1334. return current.concat(next);
  1335. }
  1336. if (Array.isArray(next)) {
  1337. return [current].concat(next);
  1338. }
  1339. return [current, next];
  1340. }
  1341. /**
  1342. * Instance of element that should respond to touch/move types of interactions,
  1343. * as indicated explicitly by relevant callbacks.
  1344. */
  1345. var responderInst = null;
  1346. /**
  1347. * Count of current touches. A textInput should become responder iff the
  1348. * selection changes while there is a touch on the screen.
  1349. */
  1350. var trackedTouchCount = 0;
  1351. var changeResponder = function(nextResponderInst, blockHostResponder) {
  1352. var oldResponderInst = responderInst;
  1353. responderInst = nextResponderInst;
  1354. if (ResponderEventPlugin.GlobalResponderHandler !== null) {
  1355. ResponderEventPlugin.GlobalResponderHandler.onChange(
  1356. oldResponderInst,
  1357. nextResponderInst,
  1358. blockHostResponder
  1359. );
  1360. }
  1361. };
  1362. var eventTypes = {
  1363. /**
  1364. * On a `touchStart`/`mouseDown`, is it desired that this element become the
  1365. * responder?
  1366. */
  1367. startShouldSetResponder: {
  1368. phasedRegistrationNames: {
  1369. bubbled: "onStartShouldSetResponder",
  1370. captured: "onStartShouldSetResponderCapture"
  1371. },
  1372. dependencies: startDependencies
  1373. },
  1374. /**
  1375. * On a `scroll`, is it desired that this element become the responder? This
  1376. * is usually not needed, but should be used to retroactively infer that a
  1377. * `touchStart` had occurred during momentum scroll. During a momentum scroll,
  1378. * a touch start will be immediately followed by a scroll event if the view is
  1379. * currently scrolling.
  1380. *
  1381. * TODO: This shouldn't bubble.
  1382. */
  1383. scrollShouldSetResponder: {
  1384. phasedRegistrationNames: {
  1385. bubbled: "onScrollShouldSetResponder",
  1386. captured: "onScrollShouldSetResponderCapture"
  1387. },
  1388. dependencies: [TOP_SCROLL]
  1389. },
  1390. /**
  1391. * On text selection change, should this element become the responder? This
  1392. * is needed for text inputs or other views with native selection, so the
  1393. * JS view can claim the responder.
  1394. *
  1395. * TODO: This shouldn't bubble.
  1396. */
  1397. selectionChangeShouldSetResponder: {
  1398. phasedRegistrationNames: {
  1399. bubbled: "onSelectionChangeShouldSetResponder",
  1400. captured: "onSelectionChangeShouldSetResponderCapture"
  1401. },
  1402. dependencies: [TOP_SELECTION_CHANGE]
  1403. },
  1404. /**
  1405. * On a `touchMove`/`mouseMove`, is it desired that this element become the
  1406. * responder?
  1407. */
  1408. moveShouldSetResponder: {
  1409. phasedRegistrationNames: {
  1410. bubbled: "onMoveShouldSetResponder",
  1411. captured: "onMoveShouldSetResponderCapture"
  1412. },
  1413. dependencies: moveDependencies
  1414. },
  1415. /**
  1416. * Direct responder events dispatched directly to responder. Do not bubble.
  1417. */
  1418. responderStart: {
  1419. registrationName: "onResponderStart",
  1420. dependencies: startDependencies
  1421. },
  1422. responderMove: {
  1423. registrationName: "onResponderMove",
  1424. dependencies: moveDependencies
  1425. },
  1426. responderEnd: {
  1427. registrationName: "onResponderEnd",
  1428. dependencies: endDependencies
  1429. },
  1430. responderRelease: {
  1431. registrationName: "onResponderRelease",
  1432. dependencies: endDependencies
  1433. },
  1434. responderTerminationRequest: {
  1435. registrationName: "onResponderTerminationRequest",
  1436. dependencies: []
  1437. },
  1438. responderGrant: {
  1439. registrationName: "onResponderGrant",
  1440. dependencies: []
  1441. },
  1442. responderReject: {
  1443. registrationName: "onResponderReject",
  1444. dependencies: []
  1445. },
  1446. responderTerminate: {
  1447. registrationName: "onResponderTerminate",
  1448. dependencies: []
  1449. }
  1450. };
  1451. /**
  1452. *
  1453. * Responder System:
  1454. * ----------------
  1455. *
  1456. * - A global, solitary "interaction lock" on a view.
  1457. * - If a node becomes the responder, it should convey visual feedback
  1458. * immediately to indicate so, either by highlighting or moving accordingly.
  1459. * - To be the responder means, that touches are exclusively important to that
  1460. * responder view, and no other view.
  1461. * - While touches are still occurring, the responder lock can be transferred to
  1462. * a new view, but only to increasingly "higher" views (meaning ancestors of
  1463. * the current responder).
  1464. *
  1465. * Responder being granted:
  1466. * ------------------------
  1467. *
  1468. * - Touch starts, moves, and scrolls can cause an ID to become the responder.
  1469. * - We capture/bubble `startShouldSetResponder`/`moveShouldSetResponder` to
  1470. * the "appropriate place".
  1471. * - If nothing is currently the responder, the "appropriate place" is the
  1472. * initiating event's `targetID`.
  1473. * - If something *is* already the responder, the "appropriate place" is the
  1474. * first common ancestor of the event target and the current `responderInst`.
  1475. * - Some negotiation happens: See the timing diagram below.
  1476. * - Scrolled views automatically become responder. The reasoning is that a
  1477. * platform scroll view that isn't built on top of the responder system has
  1478. * began scrolling, and the active responder must now be notified that the
  1479. * interaction is no longer locked to it - the system has taken over.
  1480. *
  1481. * - Responder being released:
  1482. * As soon as no more touches that *started* inside of descendants of the
  1483. * *current* responderInst, an `onResponderRelease` event is dispatched to the
  1484. * current responder, and the responder lock is released.
  1485. *
  1486. * TODO:
  1487. * - on "end", a callback hook for `onResponderEndShouldRemainResponder` that
  1488. * determines if the responder lock should remain.
  1489. * - If a view shouldn't "remain" the responder, any active touches should by
  1490. * default be considered "dead" and do not influence future negotiations or
  1491. * bubble paths. It should be as if those touches do not exist.
  1492. * -- For multitouch: Usually a translate-z will choose to "remain" responder
  1493. * after one out of many touches ended. For translate-y, usually the view
  1494. * doesn't wish to "remain" responder after one of many touches end.
  1495. * - Consider building this on top of a `stopPropagation` model similar to
  1496. * `W3C` events.
  1497. * - Ensure that `onResponderTerminate` is called on touch cancels, whether or
  1498. * not `onResponderTerminationRequest` returns `true` or `false`.
  1499. *
  1500. */
  1501. /* Negotiation Performed
  1502. +-----------------------+
  1503. / \
  1504. Process low level events to + Current Responder + wantsResponderID
  1505. determine who to perform negot-| (if any exists at all) |
  1506. iation/transition | Otherwise just pass through|
  1507. -------------------------------+----------------------------+------------------+
  1508. Bubble to find first ID | |
  1509. to return true:wantsResponderID| |
  1510. | |
  1511. +-------------+ | |
  1512. | onTouchStart| | |
  1513. +------+------+ none | |
  1514. | return| |
  1515. +-----------v-------------+true| +------------------------+ |
  1516. |onStartShouldSetResponder|----->|onResponderStart (cur) |<-----------+
  1517. +-----------+-------------+ | +------------------------+ | |
  1518. | | | +--------+-------+
  1519. | returned true for| false:REJECT +-------->|onResponderReject
  1520. | wantsResponderID | | | +----------------+
  1521. | (now attempt | +------------------+-----+ |
  1522. | handoff) | | onResponder | |
  1523. +------------------->| TerminationRequest| |
  1524. | +------------------+-----+ |
  1525. | | | +----------------+
  1526. | true:GRANT +-------->|onResponderGrant|
  1527. | | +--------+-------+
  1528. | +------------------------+ | |
  1529. | | onResponderTerminate |<-----------+
  1530. | +------------------+-----+ |
  1531. | | | +----------------+
  1532. | +-------->|onResponderStart|
  1533. | | +----------------+
  1534. Bubble to find first ID | |
  1535. to return true:wantsResponderID| |
  1536. | |
  1537. +-------------+ | |
  1538. | onTouchMove | | |
  1539. +------+------+ none | |
  1540. | return| |
  1541. +-----------v-------------+true| +------------------------+ |
  1542. |onMoveShouldSetResponder |----->|onResponderMove (cur) |<-----------+
  1543. +-----------+-------------+ | +------------------------+ | |
  1544. | | | +--------+-------+
  1545. | returned true for| false:REJECT +-------->|onResponderRejec|
  1546. | wantsResponderID | | | +----------------+
  1547. | (now attempt | +------------------+-----+ |
  1548. | handoff) | | onResponder | |
  1549. +------------------->| TerminationRequest| |
  1550. | +------------------+-----+ |
  1551. | | | +----------------+
  1552. | true:GRANT +-------->|onResponderGrant|
  1553. | | +--------+-------+
  1554. | +------------------------+ | |
  1555. | | onResponderTerminate |<-----------+
  1556. | +------------------+-----+ |
  1557. | | | +----------------+
  1558. | +-------->|onResponderMove |
  1559. | | +----------------+
  1560. | |
  1561. | |
  1562. Some active touch started| |
  1563. inside current responder | +------------------------+ |
  1564. +------------------------->| onResponderEnd | |
  1565. | | +------------------------+ |
  1566. +---+---------+ | |
  1567. | onTouchEnd | | |
  1568. +---+---------+ | |
  1569. | | +------------------------+ |
  1570. +------------------------->| onResponderEnd | |
  1571. No active touches started| +-----------+------------+ |
  1572. inside current responder | | |
  1573. | v |
  1574. | +------------------------+ |
  1575. | | onResponderRelease | |
  1576. | +------------------------+ |
  1577. | |
  1578. + + */
  1579. /**
  1580. * A note about event ordering in the `EventPluginRegistry`.
  1581. *
  1582. * Suppose plugins are injected in the following order:
  1583. *
  1584. * `[R, S, C]`
  1585. *
  1586. * To help illustrate the example, assume `S` is `SimpleEventPlugin` (for
  1587. * `onClick` etc) and `R` is `ResponderEventPlugin`.
  1588. *
  1589. * "Deferred-Dispatched Events":
  1590. *
  1591. * - The current event plugin system will traverse the list of injected plugins,
  1592. * in order, and extract events by collecting the plugin's return value of
  1593. * `extractEvents()`.
  1594. * - These events that are returned from `extractEvents` are "deferred
  1595. * dispatched events".
  1596. * - When returned from `extractEvents`, deferred-dispatched events contain an
  1597. * "accumulation" of deferred dispatches.
  1598. * - These deferred dispatches are accumulated/collected before they are
  1599. * returned, but processed at a later time by the `EventPluginRegistry` (hence the
  1600. * name deferred).
  1601. *
  1602. * In the process of returning their deferred-dispatched events, event plugins
  1603. * themselves can dispatch events on-demand without returning them from
  1604. * `extractEvents`. Plugins might want to do this, so that they can use event
  1605. * dispatching as a tool that helps them decide which events should be extracted
  1606. * in the first place.
  1607. *
  1608. * "On-Demand-Dispatched Events":
  1609. *
  1610. * - On-demand-dispatched events are not returned from `extractEvents`.
  1611. * - On-demand-dispatched events are dispatched during the process of returning
  1612. * the deferred-dispatched events.
  1613. * - They should not have side effects.
  1614. * - They should be avoided, and/or eventually be replaced with another
  1615. * abstraction that allows event plugins to perform multiple "rounds" of event
  1616. * extraction.
  1617. *
  1618. * Therefore, the sequence of event dispatches becomes:
  1619. *
  1620. * - `R`s on-demand events (if any) (dispatched by `R` on-demand)
  1621. * - `S`s on-demand events (if any) (dispatched by `S` on-demand)
  1622. * - `C`s on-demand events (if any) (dispatched by `C` on-demand)
  1623. * - `R`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1624. * - `S`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1625. * - `C`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1626. *
  1627. * In the case of `ResponderEventPlugin`: If the `startShouldSetResponder`
  1628. * on-demand dispatch returns `true` (and some other details are satisfied) the
  1629. * `onResponderGrant` deferred dispatched event is returned from
  1630. * `extractEvents`. The sequence of dispatch executions in this case
  1631. * will appear as follows:
  1632. *
  1633. * - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand)
  1634. * - `touchStartCapture` (`EventPluginRegistry` dispatches as usual)
  1635. * - `touchStart` (`EventPluginRegistry` dispatches as usual)
  1636. * - `responderGrant/Reject` (`EventPluginRegistry` dispatches as usual)
  1637. */
  1638. function setResponderAndExtractTransfer(
  1639. topLevelType,
  1640. targetInst,
  1641. nativeEvent,
  1642. nativeEventTarget
  1643. ) {
  1644. var shouldSetEventType = isStartish(topLevelType)
  1645. ? eventTypes.startShouldSetResponder
  1646. : isMoveish(topLevelType)
  1647. ? eventTypes.moveShouldSetResponder
  1648. : topLevelType === TOP_SELECTION_CHANGE
  1649. ? eventTypes.selectionChangeShouldSetResponder
  1650. : eventTypes.scrollShouldSetResponder; // TODO: stop one short of the current responder.
  1651. var bubbleShouldSetFrom = !responderInst
  1652. ? targetInst
  1653. : getLowestCommonAncestor(responderInst, targetInst); // When capturing/bubbling the "shouldSet" event, we want to skip the target
  1654. // (deepest ID) if it happens to be the current responder. The reasoning:
  1655. // It's strange to get an `onMoveShouldSetResponder` when you're *already*
  1656. // the responder.
  1657. var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
  1658. var shouldSetEvent = ResponderSyntheticEvent.getPooled(
  1659. shouldSetEventType,
  1660. bubbleShouldSetFrom,
  1661. nativeEvent,
  1662. nativeEventTarget
  1663. );
  1664. shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1665. if (skipOverBubbleShouldSetFrom) {
  1666. accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);
  1667. } else {
  1668. accumulateTwoPhaseDispatches(shouldSetEvent);
  1669. }
  1670. var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
  1671. if (!shouldSetEvent.isPersistent()) {
  1672. shouldSetEvent.constructor.release(shouldSetEvent);
  1673. }
  1674. if (!wantsResponderInst || wantsResponderInst === responderInst) {
  1675. return null;
  1676. }
  1677. var extracted;
  1678. var grantEvent = ResponderSyntheticEvent.getPooled(
  1679. eventTypes.responderGrant,
  1680. wantsResponderInst,
  1681. nativeEvent,
  1682. nativeEventTarget
  1683. );
  1684. grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1685. accumulateDirectDispatches(grantEvent);
  1686. var blockHostResponder = executeDirectDispatch(grantEvent) === true;
  1687. if (responderInst) {
  1688. var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
  1689. eventTypes.responderTerminationRequest,
  1690. responderInst,
  1691. nativeEvent,
  1692. nativeEventTarget
  1693. );
  1694. terminationRequestEvent.touchHistory =
  1695. ResponderTouchHistoryStore.touchHistory;
  1696. accumulateDirectDispatches(terminationRequestEvent);
  1697. var shouldSwitch =
  1698. !hasDispatches(terminationRequestEvent) ||
  1699. executeDirectDispatch(terminationRequestEvent);
  1700. if (!terminationRequestEvent.isPersistent()) {
  1701. terminationRequestEvent.constructor.release(terminationRequestEvent);
  1702. }
  1703. if (shouldSwitch) {
  1704. var terminateEvent = ResponderSyntheticEvent.getPooled(
  1705. eventTypes.responderTerminate,
  1706. responderInst,
  1707. nativeEvent,
  1708. nativeEventTarget
  1709. );
  1710. terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1711. accumulateDirectDispatches(terminateEvent);
  1712. extracted = accumulate(extracted, [grantEvent, terminateEvent]);
  1713. changeResponder(wantsResponderInst, blockHostResponder);
  1714. } else {
  1715. var rejectEvent = ResponderSyntheticEvent.getPooled(
  1716. eventTypes.responderReject,
  1717. wantsResponderInst,
  1718. nativeEvent,
  1719. nativeEventTarget
  1720. );
  1721. rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1722. accumulateDirectDispatches(rejectEvent);
  1723. extracted = accumulate(extracted, rejectEvent);
  1724. }
  1725. } else {
  1726. extracted = accumulate(extracted, grantEvent);
  1727. changeResponder(wantsResponderInst, blockHostResponder);
  1728. }
  1729. return extracted;
  1730. }
  1731. /**
  1732. * A transfer is a negotiation between a currently set responder and the next
  1733. * element to claim responder status. Any start event could trigger a transfer
  1734. * of responderInst. Any move event could trigger a transfer.
  1735. *
  1736. * @param {string} topLevelType Record from `BrowserEventConstants`.
  1737. * @return {boolean} True if a transfer of responder could possibly occur.
  1738. */
  1739. function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
  1740. return (
  1741. topLevelInst && // responderIgnoreScroll: We are trying to migrate away from specifically
  1742. // tracking native scroll events here and responderIgnoreScroll indicates we
  1743. // will send topTouchCancel to handle canceling touch events instead
  1744. ((topLevelType === TOP_SCROLL && !nativeEvent.responderIgnoreScroll) ||
  1745. (trackedTouchCount > 0 && topLevelType === TOP_SELECTION_CHANGE) ||
  1746. isStartish(topLevelType) ||
  1747. isMoveish(topLevelType))
  1748. );
  1749. }
  1750. /**
  1751. * Returns whether or not this touch end event makes it such that there are no
  1752. * longer any touches that started inside of the current `responderInst`.
  1753. *
  1754. * @param {NativeEvent} nativeEvent Native touch end event.
  1755. * @return {boolean} Whether or not this touch end event ends the responder.
  1756. */
  1757. function noResponderTouches(nativeEvent) {
  1758. var touches = nativeEvent.touches;
  1759. if (!touches || touches.length === 0) {
  1760. return true;
  1761. }
  1762. for (var i = 0; i < touches.length; i++) {
  1763. var activeTouch = touches[i];
  1764. var target = activeTouch.target;
  1765. if (target !== null && target !== undefined && target !== 0) {
  1766. // Is the original touch location inside of the current responder?
  1767. var targetInst = getInstanceFromNode(target);
  1768. if (isAncestor(responderInst, targetInst)) {
  1769. return false;
  1770. }
  1771. }
  1772. }
  1773. return true;
  1774. }
  1775. var ResponderEventPlugin = {
  1776. /* For unit testing only */
  1777. _getResponder: function() {
  1778. return responderInst;
  1779. },
  1780. eventTypes: eventTypes,
  1781. /**
  1782. * We must be resilient to `targetInst` being `null` on `touchMove` or
  1783. * `touchEnd`. On certain platforms, this means that a native scroll has
  1784. * assumed control and the original touch targets are destroyed.
  1785. */
  1786. extractEvents: function(
  1787. topLevelType,
  1788. targetInst,
  1789. nativeEvent,
  1790. nativeEventTarget,
  1791. eventSystemFlags
  1792. ) {
  1793. if (isStartish(topLevelType)) {
  1794. trackedTouchCount += 1;
  1795. } else if (isEndish(topLevelType)) {
  1796. if (trackedTouchCount >= 0) {
  1797. trackedTouchCount -= 1;
  1798. } else {
  1799. {
  1800. warn(
  1801. "Ended a touch event which was not counted in `trackedTouchCount`."
  1802. );
  1803. }
  1804. return null;
  1805. }
  1806. }
  1807. ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
  1808. var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
  1809. ? setResponderAndExtractTransfer(
  1810. topLevelType,
  1811. targetInst,
  1812. nativeEvent,
  1813. nativeEventTarget
  1814. )
  1815. : null; // Responder may or may not have transferred on a new touch start/move.
  1816. // Regardless, whoever is the responder after any potential transfer, we
  1817. // direct all touch start/move/ends to them in the form of
  1818. // `onResponderMove/Start/End`. These will be called for *every* additional
  1819. // finger that move/start/end, dispatched directly to whoever is the
  1820. // current responder at that moment, until the responder is "released".
  1821. //
  1822. // These multiple individual change touch events are are always bookended
  1823. // by `onResponderGrant`, and one of
  1824. // (`onResponderRelease/onResponderTerminate`).
  1825. var isResponderTouchStart = responderInst && isStartish(topLevelType);
  1826. var isResponderTouchMove = responderInst && isMoveish(topLevelType);
  1827. var isResponderTouchEnd = responderInst && isEndish(topLevelType);
  1828. var incrementalTouch = isResponderTouchStart
  1829. ? eventTypes.responderStart
  1830. : isResponderTouchMove
  1831. ? eventTypes.responderMove
  1832. : isResponderTouchEnd
  1833. ? eventTypes.responderEnd
  1834. : null;
  1835. if (incrementalTouch) {
  1836. var gesture = ResponderSyntheticEvent.getPooled(
  1837. incrementalTouch,
  1838. responderInst,
  1839. nativeEvent,
  1840. nativeEventTarget
  1841. );
  1842. gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1843. accumulateDirectDispatches(gesture);
  1844. extracted = accumulate(extracted, gesture);
  1845. }
  1846. var isResponderTerminate =
  1847. responderInst && topLevelType === TOP_TOUCH_CANCEL;
  1848. var isResponderRelease =
  1849. responderInst &&
  1850. !isResponderTerminate &&
  1851. isEndish(topLevelType) &&
  1852. noResponderTouches(nativeEvent);
  1853. var finalTouch = isResponderTerminate
  1854. ? eventTypes.responderTerminate
  1855. : isResponderRelease
  1856. ? eventTypes.responderRelease
  1857. : null;
  1858. if (finalTouch) {
  1859. var finalEvent = ResponderSyntheticEvent.getPooled(
  1860. finalTouch,
  1861. responderInst,
  1862. nativeEvent,
  1863. nativeEventTarget
  1864. );
  1865. finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1866. accumulateDirectDispatches(finalEvent);
  1867. extracted = accumulate(extracted, finalEvent);
  1868. changeResponder(null);
  1869. }
  1870. return extracted;
  1871. },
  1872. GlobalResponderHandler: null,
  1873. injection: {
  1874. /**
  1875. * @param {{onChange: (ReactID, ReactID) => void} GlobalResponderHandler
  1876. * Object that handles any change in responder. Use this to inject
  1877. * integration with an existing touch handling system etc.
  1878. */
  1879. injectGlobalResponderHandler: function(GlobalResponderHandler) {
  1880. ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler;
  1881. }
  1882. }
  1883. };
  1884. /**
  1885. * Injectable ordering of event plugins.
  1886. */
  1887. var eventPluginOrder = null;
  1888. /**
  1889. * Injectable mapping from names to event plugin modules.
  1890. */
  1891. var namesToPlugins = {};
  1892. /**
  1893. * Recomputes the plugin list using the injected plugins and plugin ordering.
  1894. *
  1895. * @private
  1896. */
  1897. function recomputePluginOrdering() {
  1898. if (!eventPluginOrder) {
  1899. // Wait until an `eventPluginOrder` is injected.
  1900. return;
  1901. }
  1902. for (var pluginName in namesToPlugins) {
  1903. var pluginModule = namesToPlugins[pluginName];
  1904. var pluginIndex = eventPluginOrder.indexOf(pluginName);
  1905. if (!(pluginIndex > -1)) {
  1906. throw Error(
  1907. "EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `" +
  1908. pluginName +
  1909. "`."
  1910. );
  1911. }
  1912. if (plugins[pluginIndex]) {
  1913. continue;
  1914. }
  1915. if (!pluginModule.extractEvents) {
  1916. throw Error(
  1917. "EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `" +
  1918. pluginName +
  1919. "` does not."
  1920. );
  1921. }
  1922. plugins[pluginIndex] = pluginModule;
  1923. var publishedEvents = pluginModule.eventTypes;
  1924. for (var eventName in publishedEvents) {
  1925. if (
  1926. !publishEventForPlugin(
  1927. publishedEvents[eventName],
  1928. pluginModule,
  1929. eventName
  1930. )
  1931. ) {
  1932. throw Error(
  1933. "EventPluginRegistry: Failed to publish event `" +
  1934. eventName +
  1935. "` for plugin `" +
  1936. pluginName +
  1937. "`."
  1938. );
  1939. }
  1940. }
  1941. }
  1942. }
  1943. /**
  1944. * Publishes an event so that it can be dispatched by the supplied plugin.
  1945. *
  1946. * @param {object} dispatchConfig Dispatch configuration for the event.
  1947. * @param {object} PluginModule Plugin publishing the event.
  1948. * @return {boolean} True if the event was successfully published.
  1949. * @private
  1950. */
  1951. function publishEventForPlugin(dispatchConfig, pluginModule, eventName) {
  1952. if (!!eventNameDispatchConfigs.hasOwnProperty(eventName)) {
  1953. throw Error(
  1954. "EventPluginRegistry: More than one plugin attempted to publish the same event name, `" +
  1955. eventName +
  1956. "`."
  1957. );
  1958. }
  1959. eventNameDispatchConfigs[eventName] = dispatchConfig;
  1960. var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
  1961. if (phasedRegistrationNames) {
  1962. for (var phaseName in phasedRegistrationNames) {
  1963. if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
  1964. var phasedRegistrationName = phasedRegistrationNames[phaseName];
  1965. publishRegistrationName(
  1966. phasedRegistrationName,
  1967. pluginModule,
  1968. eventName
  1969. );
  1970. }
  1971. }
  1972. return true;
  1973. } else if (dispatchConfig.registrationName) {
  1974. publishRegistrationName(
  1975. dispatchConfig.registrationName,
  1976. pluginModule,
  1977. eventName
  1978. );
  1979. return true;
  1980. }
  1981. return false;
  1982. }
  1983. /**
  1984. * Publishes a registration name that is used to identify dispatched events.
  1985. *
  1986. * @param {string} registrationName Registration name to add.
  1987. * @param {object} PluginModule Plugin publishing the event.
  1988. * @private
  1989. */
  1990. function publishRegistrationName(registrationName, pluginModule, eventName) {
  1991. if (!!registrationNameModules[registrationName]) {
  1992. throw Error(
  1993. "EventPluginRegistry: More than one plugin attempted to publish the same registration name, `" +
  1994. registrationName +
  1995. "`."
  1996. );
  1997. }
  1998. registrationNameModules[registrationName] = pluginModule;
  1999. registrationNameDependencies[registrationName] =
  2000. pluginModule.eventTypes[eventName].dependencies;
  2001. {
  2002. var lowerCasedName = registrationName.toLowerCase();
  2003. }
  2004. }
  2005. /**
  2006. * Registers plugins so that they can extract and dispatch events.
  2007. */
  2008. /**
  2009. * Ordered list of injected plugins.
  2010. */
  2011. var plugins = [];
  2012. /**
  2013. * Mapping from event name to dispatch config
  2014. */
  2015. var eventNameDispatchConfigs = {};
  2016. /**
  2017. * Mapping from registration name to plugin module
  2018. */
  2019. var registrationNameModules = {};
  2020. /**
  2021. * Mapping from registration name to event name
  2022. */
  2023. var registrationNameDependencies = {};
  2024. /**
  2025. * Injects an ordering of plugins (by plugin name). This allows the ordering
  2026. * to be decoupled from injection of the actual plugins so that ordering is
  2027. * always deterministic regardless of packaging, on-the-fly injection, etc.
  2028. *
  2029. * @param {array} InjectedEventPluginOrder
  2030. * @internal
  2031. */
  2032. function injectEventPluginOrder(injectedEventPluginOrder) {
  2033. if (!!eventPluginOrder) {
  2034. throw Error(
  2035. "EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React."
  2036. );
  2037. } // Clone the ordering so it cannot be dynamically mutated.
  2038. eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
  2039. recomputePluginOrdering();
  2040. }
  2041. /**
  2042. * Injects plugins to be used by plugin event system. The plugin names must be
  2043. * in the ordering injected by `injectEventPluginOrder`.
  2044. *
  2045. * Plugins can be injected as part of page initialization or on-the-fly.
  2046. *
  2047. * @param {object} injectedNamesToPlugins Map from names to plugin modules.
  2048. * @internal
  2049. */
  2050. function injectEventPluginsByName(injectedNamesToPlugins) {
  2051. var isOrderingDirty = false;
  2052. for (var pluginName in injectedNamesToPlugins) {
  2053. if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
  2054. continue;
  2055. }
  2056. var pluginModule = injectedNamesToPlugins[pluginName];
  2057. if (
  2058. !namesToPlugins.hasOwnProperty(pluginName) ||
  2059. namesToPlugins[pluginName] !== pluginModule
  2060. ) {
  2061. if (!!namesToPlugins[pluginName]) {
  2062. throw Error(
  2063. "EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
  2064. pluginName +
  2065. "`."
  2066. );
  2067. }
  2068. namesToPlugins[pluginName] = pluginModule;
  2069. isOrderingDirty = true;
  2070. }
  2071. }
  2072. if (isOrderingDirty) {
  2073. recomputePluginOrdering();
  2074. }
  2075. }
  2076. var customBubblingEventTypes =
  2077. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2078. .customBubblingEventTypes,
  2079. customDirectEventTypes =
  2080. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2081. .customDirectEventTypes;
  2082. var ReactNativeBridgeEventPlugin = {
  2083. eventTypes: {},
  2084. extractEvents: function(
  2085. topLevelType,
  2086. targetInst,
  2087. nativeEvent,
  2088. nativeEventTarget,
  2089. eventSystemFlags
  2090. ) {
  2091. if (targetInst == null) {
  2092. // Probably a node belonging to another renderer's tree.
  2093. return null;
  2094. }
  2095. var bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
  2096. var directDispatchConfig = customDirectEventTypes[topLevelType];
  2097. if (!(bubbleDispatchConfig || directDispatchConfig)) {
  2098. throw Error(
  2099. 'Unsupported top level event type "' + topLevelType + '" dispatched'
  2100. );
  2101. }
  2102. var event = SyntheticEvent.getPooled(
  2103. bubbleDispatchConfig || directDispatchConfig,
  2104. targetInst,
  2105. nativeEvent,
  2106. nativeEventTarget
  2107. );
  2108. if (bubbleDispatchConfig) {
  2109. accumulateTwoPhaseDispatches(event);
  2110. } else if (directDispatchConfig) {
  2111. accumulateDirectDispatches(event);
  2112. } else {
  2113. return null;
  2114. }
  2115. return event;
  2116. }
  2117. };
  2118. var ReactNativeEventPluginOrder = [
  2119. "ResponderEventPlugin",
  2120. "ReactNativeBridgeEventPlugin"
  2121. ];
  2122. /**
  2123. * Make sure essential globals are available and are patched correctly. Please don't remove this
  2124. * line. Bundles created by react-packager `require` it before executing any application code. This
  2125. * ensures it exists in the dependency graph and can be `require`d.
  2126. * TODO: require this in packager, not in React #10932517
  2127. */
  2128. /**
  2129. * Inject module for resolving DOM hierarchy and plugin ordering.
  2130. */
  2131. injectEventPluginOrder(ReactNativeEventPluginOrder);
  2132. /**
  2133. * Some important event plugins included by default (without having to require
  2134. * them).
  2135. */
  2136. injectEventPluginsByName({
  2137. ResponderEventPlugin: ResponderEventPlugin,
  2138. ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin
  2139. });
  2140. var instanceCache = new Map();
  2141. var instanceProps = new Map();
  2142. function precacheFiberNode(hostInst, tag) {
  2143. instanceCache.set(tag, hostInst);
  2144. }
  2145. function uncacheFiberNode(tag) {
  2146. instanceCache.delete(tag);
  2147. instanceProps.delete(tag);
  2148. }
  2149. function getInstanceFromTag(tag) {
  2150. return instanceCache.get(tag) || null;
  2151. }
  2152. function getTagFromInstance(inst) {
  2153. var nativeInstance = inst.stateNode;
  2154. var tag = nativeInstance._nativeTag;
  2155. if (tag === undefined) {
  2156. nativeInstance = nativeInstance.canonical;
  2157. tag = nativeInstance._nativeTag;
  2158. }
  2159. if (!tag) {
  2160. throw Error("All native instances should have a tag.");
  2161. }
  2162. return nativeInstance;
  2163. }
  2164. function getFiberCurrentPropsFromNode$1(stateNode) {
  2165. return instanceProps.get(stateNode._nativeTag) || null;
  2166. }
  2167. function updateFiberProps(tag, props) {
  2168. instanceProps.set(tag, props);
  2169. }
  2170. var PLUGIN_EVENT_SYSTEM = 1;
  2171. var enableProfilerTimer = true;
  2172. var enableFundamentalAPI = false;
  2173. var warnAboutStringRefs = false;
  2174. // the renderer. Such as when we're dispatching events or if third party
  2175. // libraries need to call batchedUpdates. Eventually, this API will go away when
  2176. // everything is batched by default. We'll then have a similar API to opt-out of
  2177. // scheduled work and instead do synchronous work.
  2178. // Defaults
  2179. var batchedUpdatesImpl = function(fn, bookkeeping) {
  2180. return fn(bookkeeping);
  2181. };
  2182. var isInsideEventHandler = false;
  2183. function batchedUpdates(fn, bookkeeping) {
  2184. if (isInsideEventHandler) {
  2185. // If we are currently inside another batch, we need to wait until it
  2186. // fully completes before restoring state.
  2187. return fn(bookkeeping);
  2188. }
  2189. isInsideEventHandler = true;
  2190. try {
  2191. return batchedUpdatesImpl(fn, bookkeeping);
  2192. } finally {
  2193. isInsideEventHandler = false;
  2194. }
  2195. }
  2196. function setBatchingImplementation(
  2197. _batchedUpdatesImpl,
  2198. _discreteUpdatesImpl,
  2199. _flushDiscreteUpdatesImpl,
  2200. _batchedEventUpdatesImpl
  2201. ) {
  2202. batchedUpdatesImpl = _batchedUpdatesImpl;
  2203. }
  2204. /**
  2205. * Internal queue of events that have accumulated their dispatches and are
  2206. * waiting to have their dispatches executed.
  2207. */
  2208. var eventQueue = null;
  2209. /**
  2210. * Dispatches an event and releases it back into the pool, unless persistent.
  2211. *
  2212. * @param {?object} event Synthetic event to be dispatched.
  2213. * @private
  2214. */
  2215. var executeDispatchesAndRelease = function(event) {
  2216. if (event) {
  2217. executeDispatchesInOrder(event);
  2218. if (!event.isPersistent()) {
  2219. event.constructor.release(event);
  2220. }
  2221. }
  2222. };
  2223. var executeDispatchesAndReleaseTopLevel = function(e) {
  2224. return executeDispatchesAndRelease(e);
  2225. };
  2226. function runEventsInBatch(events) {
  2227. if (events !== null) {
  2228. eventQueue = accumulateInto(eventQueue, events);
  2229. } // Set `eventQueue` to null before processing it so that we can tell if more
  2230. // events get enqueued while processing.
  2231. var processingEventQueue = eventQueue;
  2232. eventQueue = null;
  2233. if (!processingEventQueue) {
  2234. return;
  2235. }
  2236. forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
  2237. if (!!eventQueue) {
  2238. throw Error(
  2239. "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented."
  2240. );
  2241. } // This would be a good time to rethrow if any of the event handlers threw.
  2242. rethrowCaughtError();
  2243. }
  2244. /**
  2245. * Version of `ReactBrowserEventEmitter` that works on the receiving side of a
  2246. * serialized worker boundary.
  2247. */
  2248. // Shared default empty native event - conserve memory.
  2249. var EMPTY_NATIVE_EVENT = {};
  2250. /**
  2251. * Selects a subsequence of `Touch`es, without destroying `touches`.
  2252. *
  2253. * @param {Array<Touch>} touches Deserialized touch objects.
  2254. * @param {Array<number>} indices Indices by which to pull subsequence.
  2255. * @return {Array<Touch>} Subsequence of touch objects.
  2256. */
  2257. var touchSubsequence = function(touches, indices) {
  2258. var ret = [];
  2259. for (var i = 0; i < indices.length; i++) {
  2260. ret.push(touches[indices[i]]);
  2261. }
  2262. return ret;
  2263. };
  2264. /**
  2265. * TODO: Pool all of this.
  2266. *
  2267. * Destroys `touches` by removing touch objects at indices `indices`. This is
  2268. * to maintain compatibility with W3C touch "end" events, where the active
  2269. * touches don't include the set that has just been "ended".
  2270. *
  2271. * @param {Array<Touch>} touches Deserialized touch objects.
  2272. * @param {Array<number>} indices Indices to remove from `touches`.
  2273. * @return {Array<Touch>} Subsequence of removed touch objects.
  2274. */
  2275. var removeTouchesAtIndices = function(touches, indices) {
  2276. var rippedOut = []; // use an unsafe downcast to alias to nullable elements,
  2277. // so we can delete and then compact.
  2278. var temp = touches;
  2279. for (var i = 0; i < indices.length; i++) {
  2280. var index = indices[i];
  2281. rippedOut.push(touches[index]);
  2282. temp[index] = null;
  2283. }
  2284. var fillAt = 0;
  2285. for (var j = 0; j < temp.length; j++) {
  2286. var cur = temp[j];
  2287. if (cur !== null) {
  2288. temp[fillAt++] = cur;
  2289. }
  2290. }
  2291. temp.length = fillAt;
  2292. return rippedOut;
  2293. };
  2294. /**
  2295. * Internal version of `receiveEvent` in terms of normalized (non-tag)
  2296. * `rootNodeID`.
  2297. *
  2298. * @see receiveEvent.
  2299. *
  2300. * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
  2301. * @param {TopLevelType} topLevelType Top level type of event.
  2302. * @param {?object} nativeEventParam Object passed from native.
  2303. */
  2304. function _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam) {
  2305. var nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT;
  2306. var inst = getInstanceFromTag(rootNodeID);
  2307. var target = null;
  2308. if (inst != null) {
  2309. target = inst.stateNode;
  2310. }
  2311. batchedUpdates(function() {
  2312. runExtractedPluginEventsInBatch(
  2313. topLevelType,
  2314. inst,
  2315. nativeEvent,
  2316. target,
  2317. PLUGIN_EVENT_SYSTEM
  2318. );
  2319. }); // React Native doesn't use ReactControlledComponent but if it did, here's
  2320. // where it would do it.
  2321. }
  2322. /**
  2323. * Allows registered plugins an opportunity to extract events from top-level
  2324. * native browser events.
  2325. *
  2326. * @return {*} An accumulation of synthetic events.
  2327. * @internal
  2328. */
  2329. function extractPluginEvents(
  2330. topLevelType,
  2331. targetInst,
  2332. nativeEvent,
  2333. nativeEventTarget,
  2334. eventSystemFlags
  2335. ) {
  2336. var events = null;
  2337. for (var i = 0; i < plugins.length; i++) {
  2338. // Not every plugin in the ordering may be loaded at runtime.
  2339. var possiblePlugin = plugins[i];
  2340. if (possiblePlugin) {
  2341. var extractedEvents = possiblePlugin.extractEvents(
  2342. topLevelType,
  2343. targetInst,
  2344. nativeEvent,
  2345. nativeEventTarget,
  2346. eventSystemFlags
  2347. );
  2348. if (extractedEvents) {
  2349. events = accumulateInto(events, extractedEvents);
  2350. }
  2351. }
  2352. }
  2353. return events;
  2354. }
  2355. function runExtractedPluginEventsInBatch(
  2356. topLevelType,
  2357. targetInst,
  2358. nativeEvent,
  2359. nativeEventTarget,
  2360. eventSystemFlags
  2361. ) {
  2362. var events = extractPluginEvents(
  2363. topLevelType,
  2364. targetInst,
  2365. nativeEvent,
  2366. nativeEventTarget,
  2367. eventSystemFlags
  2368. );
  2369. runEventsInBatch(events);
  2370. }
  2371. /**
  2372. * Publicly exposed method on module for native objc to invoke when a top
  2373. * level event is extracted.
  2374. * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
  2375. * @param {TopLevelType} topLevelType Top level type of event.
  2376. * @param {object} nativeEventParam Object passed from native.
  2377. */
  2378. function receiveEvent(rootNodeID, topLevelType, nativeEventParam) {
  2379. _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam);
  2380. }
  2381. /**
  2382. * Simple multi-wrapper around `receiveEvent` that is intended to receive an
  2383. * efficient representation of `Touch` objects, and other information that
  2384. * can be used to construct W3C compliant `Event` and `Touch` lists.
  2385. *
  2386. * This may create dispatch behavior that differs than web touch handling. We
  2387. * loop through each of the changed touches and receive it as a single event.
  2388. * So two `touchStart`/`touchMove`s that occur simultaneously are received as
  2389. * two separate touch event dispatches - when they arguably should be one.
  2390. *
  2391. * This implementation reuses the `Touch` objects themselves as the `Event`s
  2392. * since we dispatch an event for each touch (though that might not be spec
  2393. * compliant). The main purpose of reusing them is to save allocations.
  2394. *
  2395. * TODO: Dispatch multiple changed touches in one event. The bubble path
  2396. * could be the first common ancestor of all the `changedTouches`.
  2397. *
  2398. * One difference between this behavior and W3C spec: cancelled touches will
  2399. * not appear in `.touches`, or in any future `.touches`, though they may
  2400. * still be "actively touching the surface".
  2401. *
  2402. * Web desktop polyfills only need to construct a fake touch event with
  2403. * identifier 0, also abandoning traditional click handlers.
  2404. */
  2405. function receiveTouches(eventTopLevelType, touches, changedIndices) {
  2406. var changedTouches =
  2407. eventTopLevelType === "topTouchEnd" ||
  2408. eventTopLevelType === "topTouchCancel"
  2409. ? removeTouchesAtIndices(touches, changedIndices)
  2410. : touchSubsequence(touches, changedIndices);
  2411. for (var jj = 0; jj < changedTouches.length; jj++) {
  2412. var touch = changedTouches[jj]; // Touch objects can fulfill the role of `DOM` `Event` objects if we set
  2413. // the `changedTouches`/`touches`. This saves allocations.
  2414. touch.changedTouches = changedTouches;
  2415. touch.touches = touches;
  2416. var nativeEvent = touch;
  2417. var rootNodeID = null;
  2418. var target = nativeEvent.target;
  2419. if (target !== null && target !== undefined) {
  2420. if (target < 1) {
  2421. {
  2422. error("A view is reporting that a touch occurred on tag zero.");
  2423. }
  2424. } else {
  2425. rootNodeID = target;
  2426. }
  2427. } // $FlowFixMe Shouldn't we *not* call it if rootNodeID is null?
  2428. _receiveRootNodeIDEvent(rootNodeID, eventTopLevelType, nativeEvent);
  2429. }
  2430. }
  2431. // Module provided by RN:
  2432. var ReactNativeGlobalResponderHandler = {
  2433. onChange: function(from, to, blockNativeResponder) {
  2434. if (to !== null) {
  2435. var tag = to.stateNode._nativeTag;
  2436. ReactNativePrivateInterface.UIManager.setJSResponder(
  2437. tag,
  2438. blockNativeResponder
  2439. );
  2440. } else {
  2441. ReactNativePrivateInterface.UIManager.clearJSResponder();
  2442. }
  2443. }
  2444. };
  2445. /**
  2446. * Register the event emitter with the native bridge
  2447. */
  2448. ReactNativePrivateInterface.RCTEventEmitter.register({
  2449. receiveEvent: receiveEvent,
  2450. receiveTouches: receiveTouches
  2451. });
  2452. setComponentTree(
  2453. getFiberCurrentPropsFromNode$1,
  2454. getInstanceFromTag,
  2455. getTagFromInstance
  2456. );
  2457. ResponderEventPlugin.injection.injectGlobalResponderHandler(
  2458. ReactNativeGlobalResponderHandler
  2459. );
  2460. /**
  2461. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  2462. * instance (key) and the internal representation (value). This allows public
  2463. * methods to accept the user facing instance as an argument and map them back
  2464. * to internal methods.
  2465. *
  2466. * Note that this module is currently shared and assumed to be stateless.
  2467. * If this becomes an actual Map, that will break.
  2468. */
  2469. function get(key) {
  2470. return key._reactInternalFiber;
  2471. }
  2472. function set(key, value) {
  2473. key._reactInternalFiber = value;
  2474. }
  2475. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  2476. // nor polyfill, then a plain number is used for performance.
  2477. var hasSymbol = typeof Symbol === "function" && Symbol.for;
  2478. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 0xeac7;
  2479. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 0xeaca;
  2480. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 0xeacb;
  2481. var REACT_STRICT_MODE_TYPE = hasSymbol
  2482. ? Symbol.for("react.strict_mode")
  2483. : 0xeacc;
  2484. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 0xead2;
  2485. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for("react.provider") : 0xeacd;
  2486. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for("react.context") : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  2487. var REACT_CONCURRENT_MODE_TYPE = hasSymbol
  2488. ? Symbol.for("react.concurrent_mode")
  2489. : 0xeacf;
  2490. var REACT_FORWARD_REF_TYPE = hasSymbol
  2491. ? Symbol.for("react.forward_ref")
  2492. : 0xead0;
  2493. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for("react.suspense") : 0xead1;
  2494. var REACT_SUSPENSE_LIST_TYPE = hasSymbol
  2495. ? Symbol.for("react.suspense_list")
  2496. : 0xead8;
  2497. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for("react.memo") : 0xead3;
  2498. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for("react.lazy") : 0xead4;
  2499. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for("react.block") : 0xead9;
  2500. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === "function" && Symbol.iterator;
  2501. var FAUX_ITERATOR_SYMBOL = "@@iterator";
  2502. function getIteratorFn(maybeIterable) {
  2503. if (maybeIterable === null || typeof maybeIterable !== "object") {
  2504. return null;
  2505. }
  2506. var maybeIterator =
  2507. (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
  2508. maybeIterable[FAUX_ITERATOR_SYMBOL];
  2509. if (typeof maybeIterator === "function") {
  2510. return maybeIterator;
  2511. }
  2512. return null;
  2513. }
  2514. // TODO: Move this to "react" once we can import from externals.
  2515. var Uninitialized = -1;
  2516. var Pending = 0;
  2517. var Resolved = 1;
  2518. var Rejected = 2;
  2519. function refineResolvedLazyComponent(lazyComponent) {
  2520. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  2521. }
  2522. function initializeLazyComponentType(lazyComponent) {
  2523. if (lazyComponent._status === Uninitialized) {
  2524. var ctor = lazyComponent._result;
  2525. if (!ctor) {
  2526. // TODO: Remove this later. THis only exists in case you use an older "react" package.
  2527. ctor = lazyComponent._ctor;
  2528. }
  2529. var thenable = ctor(); // Transition to the next state.
  2530. var pending = lazyComponent;
  2531. pending._status = Pending;
  2532. pending._result = thenable;
  2533. thenable.then(
  2534. function(moduleObject) {
  2535. if (lazyComponent._status === Pending) {
  2536. var defaultExport = moduleObject.default;
  2537. {
  2538. if (defaultExport === undefined) {
  2539. error(
  2540. "lazy: Expected the result of a dynamic import() call. " +
  2541. "Instead received: %s\n\nYour code should look like: \n " + // Break up imports to avoid accidentally parsing them as dependencies.
  2542. "const MyComponent = lazy(() => imp" +
  2543. "ort('./MyComponent'))",
  2544. moduleObject
  2545. );
  2546. }
  2547. } // Transition to the next state.
  2548. var resolved = lazyComponent;
  2549. resolved._status = Resolved;
  2550. resolved._result = defaultExport;
  2551. }
  2552. },
  2553. function(error) {
  2554. if (lazyComponent._status === Pending) {
  2555. // Transition to the next state.
  2556. var rejected = lazyComponent;
  2557. rejected._status = Rejected;
  2558. rejected._result = error;
  2559. }
  2560. }
  2561. );
  2562. }
  2563. }
  2564. function getWrappedName(outerType, innerType, wrapperName) {
  2565. var functionName = innerType.displayName || innerType.name || "";
  2566. return (
  2567. outerType.displayName ||
  2568. (functionName !== "" ? wrapperName + "(" + functionName + ")" : wrapperName)
  2569. );
  2570. }
  2571. function getContextName(type) {
  2572. return type.displayName || "Context";
  2573. }
  2574. function getComponentName(type) {
  2575. if (type == null) {
  2576. // Host root, text node or just invalid type.
  2577. return null;
  2578. }
  2579. {
  2580. if (typeof type.tag === "number") {
  2581. error(
  2582. "Received an unexpected object in getComponentName(). " +
  2583. "This is likely a bug in React. Please file an issue."
  2584. );
  2585. }
  2586. }
  2587. if (typeof type === "function") {
  2588. return type.displayName || type.name || null;
  2589. }
  2590. if (typeof type === "string") {
  2591. return type;
  2592. }
  2593. switch (type) {
  2594. case REACT_FRAGMENT_TYPE:
  2595. return "Fragment";
  2596. case REACT_PORTAL_TYPE:
  2597. return "Portal";
  2598. case REACT_PROFILER_TYPE:
  2599. return "Profiler";
  2600. case REACT_STRICT_MODE_TYPE:
  2601. return "StrictMode";
  2602. case REACT_SUSPENSE_TYPE:
  2603. return "Suspense";
  2604. case REACT_SUSPENSE_LIST_TYPE:
  2605. return "SuspenseList";
  2606. }
  2607. if (typeof type === "object") {
  2608. switch (type.$$typeof) {
  2609. case REACT_CONTEXT_TYPE:
  2610. var context = type;
  2611. return getContextName(context) + ".Consumer";
  2612. case REACT_PROVIDER_TYPE:
  2613. var provider = type;
  2614. return getContextName(provider._context) + ".Provider";
  2615. case REACT_FORWARD_REF_TYPE:
  2616. return getWrappedName(type, type.render, "ForwardRef");
  2617. case REACT_MEMO_TYPE:
  2618. return getComponentName(type.type);
  2619. case REACT_BLOCK_TYPE:
  2620. return getComponentName(type.render);
  2621. case REACT_LAZY_TYPE: {
  2622. var thenable = type;
  2623. var resolvedThenable = refineResolvedLazyComponent(thenable);
  2624. if (resolvedThenable) {
  2625. return getComponentName(resolvedThenable);
  2626. }
  2627. break;
  2628. }
  2629. }
  2630. }
  2631. return null;
  2632. }
  2633. // Don't change these two values. They're used by React Dev Tools.
  2634. var NoEffect =
  2635. /* */
  2636. 0;
  2637. var PerformedWork =
  2638. /* */
  2639. 1; // You can change the rest (and add more).
  2640. var Placement =
  2641. /* */
  2642. 2;
  2643. var Update =
  2644. /* */
  2645. 4;
  2646. var PlacementAndUpdate =
  2647. /* */
  2648. 6;
  2649. var Deletion =
  2650. /* */
  2651. 8;
  2652. var ContentReset =
  2653. /* */
  2654. 16;
  2655. var Callback =
  2656. /* */
  2657. 32;
  2658. var DidCapture =
  2659. /* */
  2660. 64;
  2661. var Ref =
  2662. /* */
  2663. 128;
  2664. var Snapshot =
  2665. /* */
  2666. 256;
  2667. var Passive =
  2668. /* */
  2669. 512;
  2670. var Hydrating =
  2671. /* */
  2672. 1024;
  2673. var HydratingAndUpdate =
  2674. /* */
  2675. 1028; // Passive & Update & Callback & Ref & Snapshot
  2676. var LifecycleEffectMask =
  2677. /* */
  2678. 932; // Union of all host effects
  2679. var HostEffectMask =
  2680. /* */
  2681. 2047;
  2682. var Incomplete =
  2683. /* */
  2684. 2048;
  2685. var ShouldCapture =
  2686. /* */
  2687. 4096;
  2688. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  2689. function getNearestMountedFiber(fiber) {
  2690. var node = fiber;
  2691. var nearestMounted = fiber;
  2692. if (!fiber.alternate) {
  2693. // If there is no alternate, this might be a new tree that isn't inserted
  2694. // yet. If it is, then it will have a pending insertion effect on it.
  2695. var nextNode = node;
  2696. do {
  2697. node = nextNode;
  2698. if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
  2699. // This is an insertion or in-progress hydration. The nearest possible
  2700. // mounted fiber is the parent but we need to continue to figure out
  2701. // if that one is still mounted.
  2702. nearestMounted = node.return;
  2703. }
  2704. nextNode = node.return;
  2705. } while (nextNode);
  2706. } else {
  2707. while (node.return) {
  2708. node = node.return;
  2709. }
  2710. }
  2711. if (node.tag === HostRoot) {
  2712. // TODO: Check if this was a nested HostRoot when used with
  2713. // renderContainerIntoSubtree.
  2714. return nearestMounted;
  2715. } // If we didn't hit the root, that means that we're in an disconnected tree
  2716. // that has been unmounted.
  2717. return null;
  2718. }
  2719. function isFiberMounted(fiber) {
  2720. return getNearestMountedFiber(fiber) === fiber;
  2721. }
  2722. function isMounted(component) {
  2723. {
  2724. var owner = ReactCurrentOwner.current;
  2725. if (owner !== null && owner.tag === ClassComponent) {
  2726. var ownerFiber = owner;
  2727. var instance = ownerFiber.stateNode;
  2728. if (!instance._warnedAboutRefsInRender) {
  2729. error(
  2730. "%s is accessing isMounted inside its render() function. " +
  2731. "render() should be a pure function of props and state. It should " +
  2732. "never access something that requires stale data from the previous " +
  2733. "render, such as refs. Move this logic to componentDidMount and " +
  2734. "componentDidUpdate instead.",
  2735. getComponentName(ownerFiber.type) || "A component"
  2736. );
  2737. }
  2738. instance._warnedAboutRefsInRender = true;
  2739. }
  2740. }
  2741. var fiber = get(component);
  2742. if (!fiber) {
  2743. return false;
  2744. }
  2745. return getNearestMountedFiber(fiber) === fiber;
  2746. }
  2747. function assertIsMounted(fiber) {
  2748. if (!(getNearestMountedFiber(fiber) === fiber)) {
  2749. throw Error("Unable to find node on an unmounted component.");
  2750. }
  2751. }
  2752. function findCurrentFiberUsingSlowPath(fiber) {
  2753. var alternate = fiber.alternate;
  2754. if (!alternate) {
  2755. // If there is no alternate, then we only need to check if it is mounted.
  2756. var nearestMounted = getNearestMountedFiber(fiber);
  2757. if (!(nearestMounted !== null)) {
  2758. throw Error("Unable to find node on an unmounted component.");
  2759. }
  2760. if (nearestMounted !== fiber) {
  2761. return null;
  2762. }
  2763. return fiber;
  2764. } // If we have two possible branches, we'll walk backwards up to the root
  2765. // to see what path the root points to. On the way we may hit one of the
  2766. // special cases and we'll deal with them.
  2767. var a = fiber;
  2768. var b = alternate;
  2769. while (true) {
  2770. var parentA = a.return;
  2771. if (parentA === null) {
  2772. // We're at the root.
  2773. break;
  2774. }
  2775. var parentB = parentA.alternate;
  2776. if (parentB === null) {
  2777. // There is no alternate. This is an unusual case. Currently, it only
  2778. // happens when a Suspense component is hidden. An extra fragment fiber
  2779. // is inserted in between the Suspense fiber and its children. Skip
  2780. // over this extra fragment fiber and proceed to the next parent.
  2781. var nextParent = parentA.return;
  2782. if (nextParent !== null) {
  2783. a = b = nextParent;
  2784. continue;
  2785. } // If there's no parent, we're at the root.
  2786. break;
  2787. } // If both copies of the parent fiber point to the same child, we can
  2788. // assume that the child is current. This happens when we bailout on low
  2789. // priority: the bailed out fiber's child reuses the current child.
  2790. if (parentA.child === parentB.child) {
  2791. var child = parentA.child;
  2792. while (child) {
  2793. if (child === a) {
  2794. // We've determined that A is the current branch.
  2795. assertIsMounted(parentA);
  2796. return fiber;
  2797. }
  2798. if (child === b) {
  2799. // We've determined that B is the current branch.
  2800. assertIsMounted(parentA);
  2801. return alternate;
  2802. }
  2803. child = child.sibling;
  2804. } // We should never have an alternate for any mounting node. So the only
  2805. // way this could possibly happen is if this was unmounted, if at all.
  2806. {
  2807. throw Error("Unable to find node on an unmounted component.");
  2808. }
  2809. }
  2810. if (a.return !== b.return) {
  2811. // The return pointer of A and the return pointer of B point to different
  2812. // fibers. We assume that return pointers never criss-cross, so A must
  2813. // belong to the child set of A.return, and B must belong to the child
  2814. // set of B.return.
  2815. a = parentA;
  2816. b = parentB;
  2817. } else {
  2818. // The return pointers point to the same fiber. We'll have to use the
  2819. // default, slow path: scan the child sets of each parent alternate to see
  2820. // which child belongs to which set.
  2821. //
  2822. // Search parent A's child set
  2823. var didFindChild = false;
  2824. var _child = parentA.child;
  2825. while (_child) {
  2826. if (_child === a) {
  2827. didFindChild = true;
  2828. a = parentA;
  2829. b = parentB;
  2830. break;
  2831. }
  2832. if (_child === b) {
  2833. didFindChild = true;
  2834. b = parentA;
  2835. a = parentB;
  2836. break;
  2837. }
  2838. _child = _child.sibling;
  2839. }
  2840. if (!didFindChild) {
  2841. // Search parent B's child set
  2842. _child = parentB.child;
  2843. while (_child) {
  2844. if (_child === a) {
  2845. didFindChild = true;
  2846. a = parentB;
  2847. b = parentA;
  2848. break;
  2849. }
  2850. if (_child === b) {
  2851. didFindChild = true;
  2852. b = parentB;
  2853. a = parentA;
  2854. break;
  2855. }
  2856. _child = _child.sibling;
  2857. }
  2858. if (!didFindChild) {
  2859. throw Error(
  2860. "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue."
  2861. );
  2862. }
  2863. }
  2864. }
  2865. if (!(a.alternate === b)) {
  2866. throw Error(
  2867. "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue."
  2868. );
  2869. }
  2870. } // If the root is not a host container, we're in a disconnected tree. I.e.
  2871. // unmounted.
  2872. if (!(a.tag === HostRoot)) {
  2873. throw Error("Unable to find node on an unmounted component.");
  2874. }
  2875. if (a.stateNode.current === a) {
  2876. // We've determined that A is the current branch.
  2877. return fiber;
  2878. } // Otherwise B has to be current branch.
  2879. return alternate;
  2880. }
  2881. function findCurrentHostFiber(parent) {
  2882. var currentParent = findCurrentFiberUsingSlowPath(parent);
  2883. if (!currentParent) {
  2884. return null;
  2885. } // Next we'll drill down this component to find the first HostComponent/Text.
  2886. var node = currentParent;
  2887. while (true) {
  2888. if (node.tag === HostComponent || node.tag === HostText) {
  2889. return node;
  2890. } else if (node.child) {
  2891. node.child.return = node;
  2892. node = node.child;
  2893. continue;
  2894. }
  2895. if (node === currentParent) {
  2896. return null;
  2897. }
  2898. while (!node.sibling) {
  2899. if (!node.return || node.return === currentParent) {
  2900. return null;
  2901. }
  2902. node = node.return;
  2903. }
  2904. node.sibling.return = node.return;
  2905. node = node.sibling;
  2906. } // Flow needs the return null here, but ESLint complains about it.
  2907. // eslint-disable-next-line no-unreachable
  2908. return null;
  2909. }
  2910. // Modules provided by RN:
  2911. var emptyObject = {};
  2912. /**
  2913. * Create a payload that contains all the updates between two sets of props.
  2914. *
  2915. * These helpers are all encapsulated into a single module, because they use
  2916. * mutation as a performance optimization which leads to subtle shared
  2917. * dependencies between the code paths. To avoid this mutable state leaking
  2918. * across modules, I've kept them isolated to this module.
  2919. */
  2920. // Tracks removed keys
  2921. var removedKeys = null;
  2922. var removedKeyCount = 0;
  2923. var deepDifferOptions = {
  2924. unsafelyIgnoreFunctions: true
  2925. };
  2926. function defaultDiffer(prevProp, nextProp) {
  2927. if (typeof nextProp !== "object" || nextProp === null) {
  2928. // Scalars have already been checked for equality
  2929. return true;
  2930. } else {
  2931. // For objects and arrays, the default diffing algorithm is a deep compare
  2932. return ReactNativePrivateInterface.deepDiffer(
  2933. prevProp,
  2934. nextProp,
  2935. deepDifferOptions
  2936. );
  2937. }
  2938. }
  2939. function restoreDeletedValuesInNestedArray(
  2940. updatePayload,
  2941. node,
  2942. validAttributes
  2943. ) {
  2944. if (Array.isArray(node)) {
  2945. var i = node.length;
  2946. while (i-- && removedKeyCount > 0) {
  2947. restoreDeletedValuesInNestedArray(
  2948. updatePayload,
  2949. node[i],
  2950. validAttributes
  2951. );
  2952. }
  2953. } else if (node && removedKeyCount > 0) {
  2954. var obj = node;
  2955. for (var propKey in removedKeys) {
  2956. if (!removedKeys[propKey]) {
  2957. continue;
  2958. }
  2959. var nextProp = obj[propKey];
  2960. if (nextProp === undefined) {
  2961. continue;
  2962. }
  2963. var attributeConfig = validAttributes[propKey];
  2964. if (!attributeConfig) {
  2965. continue; // not a valid native prop
  2966. }
  2967. if (typeof nextProp === "function") {
  2968. nextProp = true;
  2969. }
  2970. if (typeof nextProp === "undefined") {
  2971. nextProp = null;
  2972. }
  2973. if (typeof attributeConfig !== "object") {
  2974. // case: !Object is the default case
  2975. updatePayload[propKey] = nextProp;
  2976. } else if (
  2977. typeof attributeConfig.diff === "function" ||
  2978. typeof attributeConfig.process === "function"
  2979. ) {
  2980. // case: CustomAttributeConfiguration
  2981. var nextValue =
  2982. typeof attributeConfig.process === "function"
  2983. ? attributeConfig.process(nextProp)
  2984. : nextProp;
  2985. updatePayload[propKey] = nextValue;
  2986. }
  2987. removedKeys[propKey] = false;
  2988. removedKeyCount--;
  2989. }
  2990. }
  2991. }
  2992. function diffNestedArrayProperty(
  2993. updatePayload,
  2994. prevArray,
  2995. nextArray,
  2996. validAttributes
  2997. ) {
  2998. var minLength =
  2999. prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
  3000. var i;
  3001. for (i = 0; i < minLength; i++) {
  3002. // Diff any items in the array in the forward direction. Repeated keys
  3003. // will be overwritten by later values.
  3004. updatePayload = diffNestedProperty(
  3005. updatePayload,
  3006. prevArray[i],
  3007. nextArray[i],
  3008. validAttributes
  3009. );
  3010. }
  3011. for (; i < prevArray.length; i++) {
  3012. // Clear out all remaining properties.
  3013. updatePayload = clearNestedProperty(
  3014. updatePayload,
  3015. prevArray[i],
  3016. validAttributes
  3017. );
  3018. }
  3019. for (; i < nextArray.length; i++) {
  3020. // Add all remaining properties.
  3021. updatePayload = addNestedProperty(
  3022. updatePayload,
  3023. nextArray[i],
  3024. validAttributes
  3025. );
  3026. }
  3027. return updatePayload;
  3028. }
  3029. function diffNestedProperty(
  3030. updatePayload,
  3031. prevProp,
  3032. nextProp,
  3033. validAttributes
  3034. ) {
  3035. if (!updatePayload && prevProp === nextProp) {
  3036. // If no properties have been added, then we can bail out quickly on object
  3037. // equality.
  3038. return updatePayload;
  3039. }
  3040. if (!prevProp || !nextProp) {
  3041. if (nextProp) {
  3042. return addNestedProperty(updatePayload, nextProp, validAttributes);
  3043. }
  3044. if (prevProp) {
  3045. return clearNestedProperty(updatePayload, prevProp, validAttributes);
  3046. }
  3047. return updatePayload;
  3048. }
  3049. if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
  3050. // Both are leaves, we can diff the leaves.
  3051. return diffProperties(updatePayload, prevProp, nextProp, validAttributes);
  3052. }
  3053. if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
  3054. // Both are arrays, we can diff the arrays.
  3055. return diffNestedArrayProperty(
  3056. updatePayload,
  3057. prevProp,
  3058. nextProp,
  3059. validAttributes
  3060. );
  3061. }
  3062. if (Array.isArray(prevProp)) {
  3063. return diffProperties(
  3064. updatePayload, // $FlowFixMe - We know that this is always an object when the input is.
  3065. ReactNativePrivateInterface.flattenStyle(prevProp), // $FlowFixMe - We know that this isn't an array because of above flow.
  3066. nextProp,
  3067. validAttributes
  3068. );
  3069. }
  3070. return diffProperties(
  3071. updatePayload,
  3072. prevProp, // $FlowFixMe - We know that this is always an object when the input is.
  3073. ReactNativePrivateInterface.flattenStyle(nextProp),
  3074. validAttributes
  3075. );
  3076. }
  3077. /**
  3078. * addNestedProperty takes a single set of props and valid attribute
  3079. * attribute configurations. It processes each prop and adds it to the
  3080. * updatePayload.
  3081. */
  3082. function addNestedProperty(updatePayload, nextProp, validAttributes) {
  3083. if (!nextProp) {
  3084. return updatePayload;
  3085. }
  3086. if (!Array.isArray(nextProp)) {
  3087. // Add each property of the leaf.
  3088. return addProperties(updatePayload, nextProp, validAttributes);
  3089. }
  3090. for (var i = 0; i < nextProp.length; i++) {
  3091. // Add all the properties of the array.
  3092. updatePayload = addNestedProperty(
  3093. updatePayload,
  3094. nextProp[i],
  3095. validAttributes
  3096. );
  3097. }
  3098. return updatePayload;
  3099. }
  3100. /**
  3101. * clearNestedProperty takes a single set of props and valid attributes. It
  3102. * adds a null sentinel to the updatePayload, for each prop key.
  3103. */
  3104. function clearNestedProperty(updatePayload, prevProp, validAttributes) {
  3105. if (!prevProp) {
  3106. return updatePayload;
  3107. }
  3108. if (!Array.isArray(prevProp)) {
  3109. // Add each property of the leaf.
  3110. return clearProperties(updatePayload, prevProp, validAttributes);
  3111. }
  3112. for (var i = 0; i < prevProp.length; i++) {
  3113. // Add all the properties of the array.
  3114. updatePayload = clearNestedProperty(
  3115. updatePayload,
  3116. prevProp[i],
  3117. validAttributes
  3118. );
  3119. }
  3120. return updatePayload;
  3121. }
  3122. /**
  3123. * diffProperties takes two sets of props and a set of valid attributes
  3124. * and write to updatePayload the values that changed or were deleted.
  3125. * If no updatePayload is provided, a new one is created and returned if
  3126. * anything changed.
  3127. */
  3128. function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
  3129. var attributeConfig;
  3130. var nextProp;
  3131. var prevProp;
  3132. for (var propKey in nextProps) {
  3133. attributeConfig = validAttributes[propKey];
  3134. if (!attributeConfig) {
  3135. continue; // not a valid native prop
  3136. }
  3137. prevProp = prevProps[propKey];
  3138. nextProp = nextProps[propKey]; // functions are converted to booleans as markers that the associated
  3139. // events should be sent from native.
  3140. if (typeof nextProp === "function") {
  3141. nextProp = true; // If nextProp is not a function, then don't bother changing prevProp
  3142. // since nextProp will win and go into the updatePayload regardless.
  3143. if (typeof prevProp === "function") {
  3144. prevProp = true;
  3145. }
  3146. } // An explicit value of undefined is treated as a null because it overrides
  3147. // any other preceding value.
  3148. if (typeof nextProp === "undefined") {
  3149. nextProp = null;
  3150. if (typeof prevProp === "undefined") {
  3151. prevProp = null;
  3152. }
  3153. }
  3154. if (removedKeys) {
  3155. removedKeys[propKey] = false;
  3156. }
  3157. if (updatePayload && updatePayload[propKey] !== undefined) {
  3158. // Something else already triggered an update to this key because another
  3159. // value diffed. Since we're now later in the nested arrays our value is
  3160. // more important so we need to calculate it and override the existing
  3161. // value. It doesn't matter if nothing changed, we'll set it anyway.
  3162. // Pattern match on: attributeConfig
  3163. if (typeof attributeConfig !== "object") {
  3164. // case: !Object is the default case
  3165. updatePayload[propKey] = nextProp;
  3166. } else if (
  3167. typeof attributeConfig.diff === "function" ||
  3168. typeof attributeConfig.process === "function"
  3169. ) {
  3170. // case: CustomAttributeConfiguration
  3171. var nextValue =
  3172. typeof attributeConfig.process === "function"
  3173. ? attributeConfig.process(nextProp)
  3174. : nextProp;
  3175. updatePayload[propKey] = nextValue;
  3176. }
  3177. continue;
  3178. }
  3179. if (prevProp === nextProp) {
  3180. continue; // nothing changed
  3181. } // Pattern match on: attributeConfig
  3182. if (typeof attributeConfig !== "object") {
  3183. // case: !Object is the default case
  3184. if (defaultDiffer(prevProp, nextProp)) {
  3185. // a normal leaf has changed
  3186. (updatePayload || (updatePayload = {}))[propKey] = nextProp;
  3187. }
  3188. } else if (
  3189. typeof attributeConfig.diff === "function" ||
  3190. typeof attributeConfig.process === "function"
  3191. ) {
  3192. // case: CustomAttributeConfiguration
  3193. var shouldUpdate =
  3194. prevProp === undefined ||
  3195. (typeof attributeConfig.diff === "function"
  3196. ? attributeConfig.diff(prevProp, nextProp)
  3197. : defaultDiffer(prevProp, nextProp));
  3198. if (shouldUpdate) {
  3199. var _nextValue =
  3200. typeof attributeConfig.process === "function"
  3201. ? attributeConfig.process(nextProp)
  3202. : nextProp;
  3203. (updatePayload || (updatePayload = {}))[propKey] = _nextValue;
  3204. }
  3205. } else {
  3206. // default: fallthrough case when nested properties are defined
  3207. removedKeys = null;
  3208. removedKeyCount = 0; // We think that attributeConfig is not CustomAttributeConfiguration at
  3209. // this point so we assume it must be AttributeConfiguration.
  3210. updatePayload = diffNestedProperty(
  3211. updatePayload,
  3212. prevProp,
  3213. nextProp,
  3214. attributeConfig
  3215. );
  3216. if (removedKeyCount > 0 && updatePayload) {
  3217. restoreDeletedValuesInNestedArray(
  3218. updatePayload,
  3219. nextProp,
  3220. attributeConfig
  3221. );
  3222. removedKeys = null;
  3223. }
  3224. }
  3225. } // Also iterate through all the previous props to catch any that have been
  3226. // removed and make sure native gets the signal so it can reset them to the
  3227. // default.
  3228. for (var _propKey in prevProps) {
  3229. if (nextProps[_propKey] !== undefined) {
  3230. continue; // we've already covered this key in the previous pass
  3231. }
  3232. attributeConfig = validAttributes[_propKey];
  3233. if (!attributeConfig) {
  3234. continue; // not a valid native prop
  3235. }
  3236. if (updatePayload && updatePayload[_propKey] !== undefined) {
  3237. // This was already updated to a diff result earlier.
  3238. continue;
  3239. }
  3240. prevProp = prevProps[_propKey];
  3241. if (prevProp === undefined) {
  3242. continue; // was already empty anyway
  3243. } // Pattern match on: attributeConfig
  3244. if (
  3245. typeof attributeConfig !== "object" ||
  3246. typeof attributeConfig.diff === "function" ||
  3247. typeof attributeConfig.process === "function"
  3248. ) {
  3249. // case: CustomAttributeConfiguration | !Object
  3250. // Flag the leaf property for removal by sending a sentinel.
  3251. (updatePayload || (updatePayload = {}))[_propKey] = null;
  3252. if (!removedKeys) {
  3253. removedKeys = {};
  3254. }
  3255. if (!removedKeys[_propKey]) {
  3256. removedKeys[_propKey] = true;
  3257. removedKeyCount++;
  3258. }
  3259. } else {
  3260. // default:
  3261. // This is a nested attribute configuration where all the properties
  3262. // were removed so we need to go through and clear out all of them.
  3263. updatePayload = clearNestedProperty(
  3264. updatePayload,
  3265. prevProp,
  3266. attributeConfig
  3267. );
  3268. }
  3269. }
  3270. return updatePayload;
  3271. }
  3272. /**
  3273. * addProperties adds all the valid props to the payload after being processed.
  3274. */
  3275. function addProperties(updatePayload, props, validAttributes) {
  3276. // TODO: Fast path
  3277. return diffProperties(updatePayload, emptyObject, props, validAttributes);
  3278. }
  3279. /**
  3280. * clearProperties clears all the previous props by adding a null sentinel
  3281. * to the payload for each valid key.
  3282. */
  3283. function clearProperties(updatePayload, prevProps, validAttributes) {
  3284. // TODO: Fast path
  3285. return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
  3286. }
  3287. function create(props, validAttributes) {
  3288. return addProperties(
  3289. null, // updatePayload
  3290. props,
  3291. validAttributes
  3292. );
  3293. }
  3294. function diff(prevProps, nextProps, validAttributes) {
  3295. return diffProperties(
  3296. null, // updatePayload
  3297. prevProps,
  3298. nextProps,
  3299. validAttributes
  3300. );
  3301. }
  3302. /**
  3303. * In the future, we should cleanup callbacks by cancelling them instead of
  3304. * using this.
  3305. */
  3306. function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
  3307. return function() {
  3308. if (!callback) {
  3309. return undefined;
  3310. } // This protects against createClass() components.
  3311. // We don't know if there is code depending on it.
  3312. // We intentionally don't use isMounted() because even accessing
  3313. // isMounted property on a React ES6 class will trigger a warning.
  3314. if (typeof context.__isMounted === "boolean") {
  3315. if (!context.__isMounted) {
  3316. return undefined;
  3317. }
  3318. } // FIXME: there used to be other branches that protected
  3319. // against unmounted host components. But RN host components don't
  3320. // define isMounted() anymore, so those checks didn't do anything.
  3321. // They caused false positive warning noise so we removed them:
  3322. // https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
  3323. // However, this means that the callback is NOT guaranteed to be safe
  3324. // for host components. The solution we should implement is to make
  3325. // UIManager.measure() and similar calls truly cancelable. Then we
  3326. // can change our own code calling them to cancel when something unmounts.
  3327. return callback.apply(context, arguments);
  3328. };
  3329. }
  3330. function warnForStyleProps(props, validAttributes) {
  3331. {
  3332. for (var key in validAttributes.style) {
  3333. if (!(validAttributes[key] || props[key] === undefined)) {
  3334. error(
  3335. "You are setting the style `{ %s" +
  3336. ": ... }` as a prop. You " +
  3337. "should nest it in a style object. " +
  3338. "E.g. `{ style: { %s" +
  3339. ": ... } }`",
  3340. key,
  3341. key
  3342. );
  3343. }
  3344. }
  3345. }
  3346. }
  3347. var ReactNativeFiberHostComponent =
  3348. /*#__PURE__*/
  3349. (function() {
  3350. function ReactNativeFiberHostComponent(
  3351. tag,
  3352. viewConfig,
  3353. internalInstanceHandleDEV
  3354. ) {
  3355. this._nativeTag = tag;
  3356. this._children = [];
  3357. this.viewConfig = viewConfig;
  3358. {
  3359. this._internalFiberInstanceHandleDEV = internalInstanceHandleDEV;
  3360. }
  3361. }
  3362. var _proto = ReactNativeFiberHostComponent.prototype;
  3363. _proto.blur = function blur() {
  3364. ReactNativePrivateInterface.TextInputState.blurTextInput(this);
  3365. };
  3366. _proto.focus = function focus() {
  3367. ReactNativePrivateInterface.TextInputState.focusTextInput(this);
  3368. };
  3369. _proto.measure = function measure(callback) {
  3370. ReactNativePrivateInterface.UIManager.measure(
  3371. this._nativeTag,
  3372. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3373. );
  3374. };
  3375. _proto.measureInWindow = function measureInWindow(callback) {
  3376. ReactNativePrivateInterface.UIManager.measureInWindow(
  3377. this._nativeTag,
  3378. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3379. );
  3380. };
  3381. _proto.measureLayout = function measureLayout(
  3382. relativeToNativeNode,
  3383. onSuccess,
  3384. onFail
  3385. ) /* currently unused */
  3386. {
  3387. var relativeNode;
  3388. if (typeof relativeToNativeNode === "number") {
  3389. // Already a node handle
  3390. relativeNode = relativeToNativeNode;
  3391. } else {
  3392. var nativeNode = relativeToNativeNode;
  3393. if (nativeNode._nativeTag) {
  3394. relativeNode = nativeNode._nativeTag;
  3395. }
  3396. }
  3397. if (relativeNode == null) {
  3398. {
  3399. error(
  3400. "Warning: ref.measureLayout must be called with a node handle or a ref to a native component."
  3401. );
  3402. }
  3403. return;
  3404. }
  3405. ReactNativePrivateInterface.UIManager.measureLayout(
  3406. this._nativeTag,
  3407. relativeNode,
  3408. mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
  3409. mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess)
  3410. );
  3411. };
  3412. _proto.setNativeProps = function setNativeProps(nativeProps) {
  3413. {
  3414. warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
  3415. }
  3416. var updatePayload = create(nativeProps, this.viewConfig.validAttributes); // Avoid the overhead of bridge calls if there's no update.
  3417. // This is an expensive no-op for Android, and causes an unnecessary
  3418. // view invalidation for certain components (eg RCTTextInput) on iOS.
  3419. if (updatePayload != null) {
  3420. ReactNativePrivateInterface.UIManager.updateView(
  3421. this._nativeTag,
  3422. this.viewConfig.uiViewClassName,
  3423. updatePayload
  3424. );
  3425. }
  3426. };
  3427. return ReactNativeFiberHostComponent;
  3428. })(); // eslint-disable-next-line no-unused-expressions
  3429. // can re-export everything from this module.
  3430. function shim() {
  3431. {
  3432. throw Error(
  3433. "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue."
  3434. );
  3435. }
  3436. } // Hydration (when unsupported)
  3437. var isSuspenseInstancePending = shim;
  3438. var isSuspenseInstanceFallback = shim;
  3439. var hydrateTextInstance = shim;
  3440. var getViewConfigForType =
  3441. ReactNativePrivateInterface.ReactNativeViewConfigRegistry.get;
  3442. var UPDATE_SIGNAL = {};
  3443. {
  3444. Object.freeze(UPDATE_SIGNAL);
  3445. } // Counter for uniquely identifying views.
  3446. // % 10 === 1 means it is a rootTag.
  3447. // % 2 === 0 means it is a Fabric tag.
  3448. var nextReactTag = 3;
  3449. function allocateTag() {
  3450. var tag = nextReactTag;
  3451. if (tag % 10 === 1) {
  3452. tag += 2;
  3453. }
  3454. nextReactTag = tag + 2;
  3455. return tag;
  3456. }
  3457. function recursivelyUncacheFiberNode(node) {
  3458. if (typeof node === "number") {
  3459. // Leaf node (eg text)
  3460. uncacheFiberNode(node);
  3461. } else {
  3462. uncacheFiberNode(node._nativeTag);
  3463. node._children.forEach(recursivelyUncacheFiberNode);
  3464. }
  3465. }
  3466. function appendInitialChild(parentInstance, child) {
  3467. parentInstance._children.push(child);
  3468. }
  3469. function createInstance(
  3470. type,
  3471. props,
  3472. rootContainerInstance,
  3473. hostContext,
  3474. internalInstanceHandle
  3475. ) {
  3476. var tag = allocateTag();
  3477. var viewConfig = getViewConfigForType(type);
  3478. {
  3479. for (var key in viewConfig.validAttributes) {
  3480. if (props.hasOwnProperty(key)) {
  3481. ReactNativePrivateInterface.deepFreezeAndThrowOnMutationInDev(
  3482. props[key]
  3483. );
  3484. }
  3485. }
  3486. }
  3487. var updatePayload = create(props, viewConfig.validAttributes);
  3488. ReactNativePrivateInterface.UIManager.createView(
  3489. tag, // reactTag
  3490. viewConfig.uiViewClassName, // viewName
  3491. rootContainerInstance, // rootTag
  3492. updatePayload // props
  3493. );
  3494. var component = new ReactNativeFiberHostComponent(
  3495. tag,
  3496. viewConfig,
  3497. internalInstanceHandle
  3498. );
  3499. precacheFiberNode(internalInstanceHandle, tag);
  3500. updateFiberProps(tag, props); // Not sure how to avoid this cast. Flow is okay if the component is defined
  3501. // in the same file but if it's external it can't see the types.
  3502. return component;
  3503. }
  3504. function createTextInstance(
  3505. text,
  3506. rootContainerInstance,
  3507. hostContext,
  3508. internalInstanceHandle
  3509. ) {
  3510. if (!hostContext.isInAParentText) {
  3511. throw Error("Text strings must be rendered within a <Text> component.");
  3512. }
  3513. var tag = allocateTag();
  3514. ReactNativePrivateInterface.UIManager.createView(
  3515. tag, // reactTag
  3516. "RCTRawText", // viewName
  3517. rootContainerInstance, // rootTag
  3518. {
  3519. text: text
  3520. } // props
  3521. );
  3522. precacheFiberNode(internalInstanceHandle, tag);
  3523. return tag;
  3524. }
  3525. function finalizeInitialChildren(
  3526. parentInstance,
  3527. type,
  3528. props,
  3529. rootContainerInstance,
  3530. hostContext
  3531. ) {
  3532. // Don't send a no-op message over the bridge.
  3533. if (parentInstance._children.length === 0) {
  3534. return false;
  3535. } // Map from child objects to native tags.
  3536. // Either way we need to pass a copy of the Array to prevent it from being frozen.
  3537. var nativeTags = parentInstance._children.map(function(child) {
  3538. return typeof child === "number"
  3539. ? child // Leaf node (eg text)
  3540. : child._nativeTag;
  3541. });
  3542. ReactNativePrivateInterface.UIManager.setChildren(
  3543. parentInstance._nativeTag, // containerTag
  3544. nativeTags // reactTags
  3545. );
  3546. return false;
  3547. }
  3548. function getRootHostContext(rootContainerInstance) {
  3549. return {
  3550. isInAParentText: false
  3551. };
  3552. }
  3553. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  3554. var prevIsInAParentText = parentHostContext.isInAParentText;
  3555. var isInAParentText =
  3556. type === "AndroidTextInput" || // Android
  3557. type === "RCTMultilineTextInputView" || // iOS
  3558. type === "RCTSinglelineTextInputView" || // iOS
  3559. type === "RCTText" ||
  3560. type === "RCTVirtualText";
  3561. if (prevIsInAParentText !== isInAParentText) {
  3562. return {
  3563. isInAParentText: isInAParentText
  3564. };
  3565. } else {
  3566. return parentHostContext;
  3567. }
  3568. }
  3569. function getPublicInstance(instance) {
  3570. return instance;
  3571. }
  3572. function prepareForCommit(containerInfo) {
  3573. // Noop
  3574. }
  3575. function prepareUpdate(
  3576. instance,
  3577. type,
  3578. oldProps,
  3579. newProps,
  3580. rootContainerInstance,
  3581. hostContext
  3582. ) {
  3583. return UPDATE_SIGNAL;
  3584. }
  3585. function resetAfterCommit(containerInfo) {
  3586. // Noop
  3587. }
  3588. var scheduleTimeout = setTimeout;
  3589. var cancelTimeout = clearTimeout;
  3590. var noTimeout = -1;
  3591. function shouldDeprioritizeSubtree(type, props) {
  3592. return false;
  3593. }
  3594. function shouldSetTextContent(type, props) {
  3595. // TODO (bvaughn) Revisit this decision.
  3596. // Always returning false simplifies the createInstance() implementation,
  3597. // But creates an additional child Fiber for raw text children.
  3598. // No additional native views are created though.
  3599. // It's not clear to me which is better so I'm deferring for now.
  3600. // More context @ github.com/facebook/react/pull/8560#discussion_r92111303
  3601. return false;
  3602. } // -------------------
  3603. function appendChild(parentInstance, child) {
  3604. var childTag = typeof child === "number" ? child : child._nativeTag;
  3605. var children = parentInstance._children;
  3606. var index = children.indexOf(child);
  3607. if (index >= 0) {
  3608. children.splice(index, 1);
  3609. children.push(child);
  3610. ReactNativePrivateInterface.UIManager.manageChildren(
  3611. parentInstance._nativeTag, // containerTag
  3612. [index], // moveFromIndices
  3613. [children.length - 1], // moveToIndices
  3614. [], // addChildReactTags
  3615. [], // addAtIndices
  3616. [] // removeAtIndices
  3617. );
  3618. } else {
  3619. children.push(child);
  3620. ReactNativePrivateInterface.UIManager.manageChildren(
  3621. parentInstance._nativeTag, // containerTag
  3622. [], // moveFromIndices
  3623. [], // moveToIndices
  3624. [childTag], // addChildReactTags
  3625. [children.length - 1], // addAtIndices
  3626. [] // removeAtIndices
  3627. );
  3628. }
  3629. }
  3630. function appendChildToContainer(parentInstance, child) {
  3631. var childTag = typeof child === "number" ? child : child._nativeTag;
  3632. ReactNativePrivateInterface.UIManager.setChildren(
  3633. parentInstance, // containerTag
  3634. [childTag] // reactTags
  3635. );
  3636. }
  3637. function commitTextUpdate(textInstance, oldText, newText) {
  3638. ReactNativePrivateInterface.UIManager.updateView(
  3639. textInstance, // reactTag
  3640. "RCTRawText", // viewName
  3641. {
  3642. text: newText
  3643. } // props
  3644. );
  3645. }
  3646. function commitUpdate(
  3647. instance,
  3648. updatePayloadTODO,
  3649. type,
  3650. oldProps,
  3651. newProps,
  3652. internalInstanceHandle
  3653. ) {
  3654. var viewConfig = instance.viewConfig;
  3655. updateFiberProps(instance._nativeTag, newProps);
  3656. var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); // Avoid the overhead of bridge calls if there's no update.
  3657. // This is an expensive no-op for Android, and causes an unnecessary
  3658. // view invalidation for certain components (eg RCTTextInput) on iOS.
  3659. if (updatePayload != null) {
  3660. ReactNativePrivateInterface.UIManager.updateView(
  3661. instance._nativeTag, // reactTag
  3662. viewConfig.uiViewClassName, // viewName
  3663. updatePayload // props
  3664. );
  3665. }
  3666. }
  3667. function insertBefore(parentInstance, child, beforeChild) {
  3668. var children = parentInstance._children;
  3669. var index = children.indexOf(child); // Move existing child or add new child?
  3670. if (index >= 0) {
  3671. children.splice(index, 1);
  3672. var beforeChildIndex = children.indexOf(beforeChild);
  3673. children.splice(beforeChildIndex, 0, child);
  3674. ReactNativePrivateInterface.UIManager.manageChildren(
  3675. parentInstance._nativeTag, // containerID
  3676. [index], // moveFromIndices
  3677. [beforeChildIndex], // moveToIndices
  3678. [], // addChildReactTags
  3679. [], // addAtIndices
  3680. [] // removeAtIndices
  3681. );
  3682. } else {
  3683. var _beforeChildIndex = children.indexOf(beforeChild);
  3684. children.splice(_beforeChildIndex, 0, child);
  3685. var childTag = typeof child === "number" ? child : child._nativeTag;
  3686. ReactNativePrivateInterface.UIManager.manageChildren(
  3687. parentInstance._nativeTag, // containerID
  3688. [], // moveFromIndices
  3689. [], // moveToIndices
  3690. [childTag], // addChildReactTags
  3691. [_beforeChildIndex], // addAtIndices
  3692. [] // removeAtIndices
  3693. );
  3694. }
  3695. }
  3696. function insertInContainerBefore(parentInstance, child, beforeChild) {
  3697. // TODO (bvaughn): Remove this check when...
  3698. // We create a wrapper object for the container in ReactNative render()
  3699. // Or we refactor to remove wrapper objects entirely.
  3700. // For more info on pros/cons see PR #8560 description.
  3701. if (!(typeof parentInstance !== "number")) {
  3702. throw Error("Container does not support insertBefore operation");
  3703. }
  3704. }
  3705. function removeChild(parentInstance, child) {
  3706. recursivelyUncacheFiberNode(child);
  3707. var children = parentInstance._children;
  3708. var index = children.indexOf(child);
  3709. children.splice(index, 1);
  3710. ReactNativePrivateInterface.UIManager.manageChildren(
  3711. parentInstance._nativeTag, // containerID
  3712. [], // moveFromIndices
  3713. [], // moveToIndices
  3714. [], // addChildReactTags
  3715. [], // addAtIndices
  3716. [index] // removeAtIndices
  3717. );
  3718. }
  3719. function removeChildFromContainer(parentInstance, child) {
  3720. recursivelyUncacheFiberNode(child);
  3721. ReactNativePrivateInterface.UIManager.manageChildren(
  3722. parentInstance, // containerID
  3723. [], // moveFromIndices
  3724. [], // moveToIndices
  3725. [], // addChildReactTags
  3726. [], // addAtIndices
  3727. [0] // removeAtIndices
  3728. );
  3729. }
  3730. function resetTextContent(instance) {
  3731. // Noop
  3732. }
  3733. function hideInstance(instance) {
  3734. var viewConfig = instance.viewConfig;
  3735. var updatePayload = create(
  3736. {
  3737. style: {
  3738. display: "none"
  3739. }
  3740. },
  3741. viewConfig.validAttributes
  3742. );
  3743. ReactNativePrivateInterface.UIManager.updateView(
  3744. instance._nativeTag,
  3745. viewConfig.uiViewClassName,
  3746. updatePayload
  3747. );
  3748. }
  3749. function hideTextInstance(textInstance) {
  3750. throw new Error("Not yet implemented.");
  3751. }
  3752. function unhideInstance(instance, props) {
  3753. var viewConfig = instance.viewConfig;
  3754. var updatePayload = diff(
  3755. Object.assign({}, props, {
  3756. style: [
  3757. props.style,
  3758. {
  3759. display: "none"
  3760. }
  3761. ]
  3762. }),
  3763. props,
  3764. viewConfig.validAttributes
  3765. );
  3766. ReactNativePrivateInterface.UIManager.updateView(
  3767. instance._nativeTag,
  3768. viewConfig.uiViewClassName,
  3769. updatePayload
  3770. );
  3771. }
  3772. function unhideTextInstance(textInstance, text) {
  3773. throw new Error("Not yet implemented.");
  3774. }
  3775. var loggedTypeFailures = {};
  3776. function checkPropTypes(typeSpecs, values, location, componentName) {
  3777. {
  3778. // $FlowFixMe This is okay but Flow doesn't know it.
  3779. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  3780. for (var typeSpecName in typeSpecs) {
  3781. if (has(typeSpecs, typeSpecName)) {
  3782. var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
  3783. // fail the render phase where it didn't fail before. So we log it.
  3784. // After these have been cleaned up, we'll let them throw.
  3785. try {
  3786. // This is intentionally an invariant that gets caught. It's the same
  3787. // behavior as without this statement except with a better message.
  3788. if (typeof typeSpecs[typeSpecName] !== "function") {
  3789. var err = Error(
  3790. (componentName || "React class") +
  3791. ": " +
  3792. location +
  3793. " type `" +
  3794. typeSpecName +
  3795. "` is invalid; " +
  3796. "it must be a function, usually from the `prop-types` package, but received `" +
  3797. typeof typeSpecs[typeSpecName] +
  3798. "`." +
  3799. "This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."
  3800. );
  3801. err.name = "Invariant Violation";
  3802. throw err;
  3803. }
  3804. error$1 = typeSpecs[typeSpecName](
  3805. values,
  3806. typeSpecName,
  3807. componentName,
  3808. location,
  3809. null,
  3810. "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"
  3811. );
  3812. } catch (ex) {
  3813. error$1 = ex;
  3814. }
  3815. if (error$1 && !(error$1 instanceof Error)) {
  3816. error(
  3817. "%s: type specification of %s" +
  3818. " `%s` is invalid; the type checker " +
  3819. "function must return `null` or an `Error` but returned a %s. " +
  3820. "You may have forgotten to pass an argument to the type checker " +
  3821. "creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and " +
  3822. "shape all require an argument).",
  3823. componentName || "React class",
  3824. location,
  3825. typeSpecName,
  3826. typeof error$1
  3827. );
  3828. }
  3829. if (
  3830. error$1 instanceof Error &&
  3831. !(error$1.message in loggedTypeFailures)
  3832. ) {
  3833. // Only monitor this failure once because there tends to be a lot of the
  3834. // same error.
  3835. loggedTypeFailures[error$1.message] = true;
  3836. error("Failed %s type: %s", location, error$1.message);
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. // Prefix measurements so that it's possible to filter them.
  3843. // Longer prefixes are hard to read in DevTools.
  3844. var reactEmoji = "\u269B";
  3845. var warningEmoji = "\u26D4";
  3846. var supportsUserTiming =
  3847. typeof performance !== "undefined" &&
  3848. typeof performance.mark === "function" &&
  3849. typeof performance.clearMarks === "function" &&
  3850. typeof performance.measure === "function" &&
  3851. typeof performance.clearMeasures === "function"; // Keep track of current fiber so that we know the path to unwind on pause.
  3852. // TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
  3853. var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
  3854. // Reusing `currentFiber` would be confusing for this because user code fiber
  3855. // can change during commit phase too, but we don't need to unwind it (since
  3856. // lifecycles in the commit phase don't resemble a tree).
  3857. var currentPhase = null;
  3858. var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
  3859. // so we will keep track of it, and include it in the report.
  3860. // Track commits caused by cascading updates.
  3861. var isCommitting = false;
  3862. var hasScheduledUpdateInCurrentCommit = false;
  3863. var hasScheduledUpdateInCurrentPhase = false;
  3864. var commitCountInCurrentWorkLoop = 0;
  3865. var effectCountInCurrentCommit = 0;
  3866. // to avoid stretch the commit phase with measurement overhead.
  3867. var labelsInCurrentCommit = new Set();
  3868. var formatMarkName = function(markName) {
  3869. return reactEmoji + " " + markName;
  3870. };
  3871. var formatLabel = function(label, warning) {
  3872. var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
  3873. var suffix = warning ? " Warning: " + warning : "";
  3874. return "" + prefix + label + suffix;
  3875. };
  3876. var beginMark = function(markName) {
  3877. performance.mark(formatMarkName(markName));
  3878. };
  3879. var clearMark = function(markName) {
  3880. performance.clearMarks(formatMarkName(markName));
  3881. };
  3882. var endMark = function(label, markName, warning) {
  3883. var formattedMarkName = formatMarkName(markName);
  3884. var formattedLabel = formatLabel(label, warning);
  3885. try {
  3886. performance.measure(formattedLabel, formattedMarkName);
  3887. } catch (err) {} // If previous mark was missing for some reason, this will throw.
  3888. // This could only happen if React crashed in an unexpected place earlier.
  3889. // Don't pile on with more errors.
  3890. // Clear marks immediately to avoid growing buffer.
  3891. performance.clearMarks(formattedMarkName);
  3892. performance.clearMeasures(formattedLabel);
  3893. };
  3894. var getFiberMarkName = function(label, debugID) {
  3895. return label + " (#" + debugID + ")";
  3896. };
  3897. var getFiberLabel = function(componentName, isMounted, phase) {
  3898. if (phase === null) {
  3899. // These are composite component total time measurements.
  3900. return componentName + " [" + (isMounted ? "update" : "mount") + "]";
  3901. } else {
  3902. // Composite component methods.
  3903. return componentName + "." + phase;
  3904. }
  3905. };
  3906. var beginFiberMark = function(fiber, phase) {
  3907. var componentName = getComponentName(fiber.type) || "Unknown";
  3908. var debugID = fiber._debugID;
  3909. var isMounted = fiber.alternate !== null;
  3910. var label = getFiberLabel(componentName, isMounted, phase);
  3911. if (isCommitting && labelsInCurrentCommit.has(label)) {
  3912. // During the commit phase, we don't show duplicate labels because
  3913. // there is a fixed overhead for every measurement, and we don't
  3914. // want to stretch the commit phase beyond necessary.
  3915. return false;
  3916. }
  3917. labelsInCurrentCommit.add(label);
  3918. var markName = getFiberMarkName(label, debugID);
  3919. beginMark(markName);
  3920. return true;
  3921. };
  3922. var clearFiberMark = function(fiber, phase) {
  3923. var componentName = getComponentName(fiber.type) || "Unknown";
  3924. var debugID = fiber._debugID;
  3925. var isMounted = fiber.alternate !== null;
  3926. var label = getFiberLabel(componentName, isMounted, phase);
  3927. var markName = getFiberMarkName(label, debugID);
  3928. clearMark(markName);
  3929. };
  3930. var endFiberMark = function(fiber, phase, warning) {
  3931. var componentName = getComponentName(fiber.type) || "Unknown";
  3932. var debugID = fiber._debugID;
  3933. var isMounted = fiber.alternate !== null;
  3934. var label = getFiberLabel(componentName, isMounted, phase);
  3935. var markName = getFiberMarkName(label, debugID);
  3936. endMark(label, markName, warning);
  3937. };
  3938. var shouldIgnoreFiber = function(fiber) {
  3939. // Host components should be skipped in the timeline.
  3940. // We could check typeof fiber.type, but does this work with RN?
  3941. switch (fiber.tag) {
  3942. case HostRoot:
  3943. case HostComponent:
  3944. case HostText:
  3945. case HostPortal:
  3946. case Fragment:
  3947. case ContextProvider:
  3948. case ContextConsumer:
  3949. case Mode:
  3950. return true;
  3951. default:
  3952. return false;
  3953. }
  3954. };
  3955. var clearPendingPhaseMeasurement = function() {
  3956. if (currentPhase !== null && currentPhaseFiber !== null) {
  3957. clearFiberMark(currentPhaseFiber, currentPhase);
  3958. }
  3959. currentPhaseFiber = null;
  3960. currentPhase = null;
  3961. hasScheduledUpdateInCurrentPhase = false;
  3962. };
  3963. var pauseTimers = function() {
  3964. // Stops all currently active measurements so that they can be resumed
  3965. // if we continue in a later deferred loop from the same unit of work.
  3966. var fiber = currentFiber;
  3967. while (fiber) {
  3968. if (fiber._debugIsCurrentlyTiming) {
  3969. endFiberMark(fiber, null, null);
  3970. }
  3971. fiber = fiber.return;
  3972. }
  3973. };
  3974. var resumeTimersRecursively = function(fiber) {
  3975. if (fiber.return !== null) {
  3976. resumeTimersRecursively(fiber.return);
  3977. }
  3978. if (fiber._debugIsCurrentlyTiming) {
  3979. beginFiberMark(fiber, null);
  3980. }
  3981. };
  3982. var resumeTimers = function() {
  3983. // Resumes all measurements that were active during the last deferred loop.
  3984. if (currentFiber !== null) {
  3985. resumeTimersRecursively(currentFiber);
  3986. }
  3987. };
  3988. function recordEffect() {
  3989. {
  3990. effectCountInCurrentCommit++;
  3991. }
  3992. }
  3993. function recordScheduleUpdate() {
  3994. {
  3995. if (isCommitting) {
  3996. hasScheduledUpdateInCurrentCommit = true;
  3997. }
  3998. if (
  3999. currentPhase !== null &&
  4000. currentPhase !== "componentWillMount" &&
  4001. currentPhase !== "componentWillReceiveProps"
  4002. ) {
  4003. hasScheduledUpdateInCurrentPhase = true;
  4004. }
  4005. }
  4006. }
  4007. function startWorkTimer(fiber) {
  4008. {
  4009. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4010. return;
  4011. } // If we pause, this is the fiber to unwind from.
  4012. currentFiber = fiber;
  4013. if (!beginFiberMark(fiber, null)) {
  4014. return;
  4015. }
  4016. fiber._debugIsCurrentlyTiming = true;
  4017. }
  4018. }
  4019. function cancelWorkTimer(fiber) {
  4020. {
  4021. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4022. return;
  4023. } // Remember we shouldn't complete measurement for this fiber.
  4024. // Otherwise flamechart will be deep even for small updates.
  4025. fiber._debugIsCurrentlyTiming = false;
  4026. clearFiberMark(fiber, null);
  4027. }
  4028. }
  4029. function stopWorkTimer(fiber) {
  4030. {
  4031. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4032. return;
  4033. } // If we pause, its parent is the fiber to unwind from.
  4034. currentFiber = fiber.return;
  4035. if (!fiber._debugIsCurrentlyTiming) {
  4036. return;
  4037. }
  4038. fiber._debugIsCurrentlyTiming = false;
  4039. endFiberMark(fiber, null, null);
  4040. }
  4041. }
  4042. function stopFailedWorkTimer(fiber) {
  4043. {
  4044. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  4045. return;
  4046. } // If we pause, its parent is the fiber to unwind from.
  4047. currentFiber = fiber.return;
  4048. if (!fiber._debugIsCurrentlyTiming) {
  4049. return;
  4050. }
  4051. fiber._debugIsCurrentlyTiming = false;
  4052. var warning =
  4053. fiber.tag === SuspenseComponent
  4054. ? "Rendering was suspended"
  4055. : "An error was thrown inside this error boundary";
  4056. endFiberMark(fiber, null, warning);
  4057. }
  4058. }
  4059. function startPhaseTimer(fiber, phase) {
  4060. {
  4061. if (!supportsUserTiming) {
  4062. return;
  4063. }
  4064. clearPendingPhaseMeasurement();
  4065. if (!beginFiberMark(fiber, phase)) {
  4066. return;
  4067. }
  4068. currentPhaseFiber = fiber;
  4069. currentPhase = phase;
  4070. }
  4071. }
  4072. function stopPhaseTimer() {
  4073. {
  4074. if (!supportsUserTiming) {
  4075. return;
  4076. }
  4077. if (currentPhase !== null && currentPhaseFiber !== null) {
  4078. var warning = hasScheduledUpdateInCurrentPhase
  4079. ? "Scheduled a cascading update"
  4080. : null;
  4081. endFiberMark(currentPhaseFiber, currentPhase, warning);
  4082. }
  4083. currentPhase = null;
  4084. currentPhaseFiber = null;
  4085. }
  4086. }
  4087. function startWorkLoopTimer(nextUnitOfWork) {
  4088. {
  4089. currentFiber = nextUnitOfWork;
  4090. if (!supportsUserTiming) {
  4091. return;
  4092. }
  4093. commitCountInCurrentWorkLoop = 0; // This is top level call.
  4094. // Any other measurements are performed within.
  4095. beginMark("(React Tree Reconciliation)"); // Resume any measurements that were in progress during the last loop.
  4096. resumeTimers();
  4097. }
  4098. }
  4099. function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
  4100. {
  4101. if (!supportsUserTiming) {
  4102. return;
  4103. }
  4104. var warning = null;
  4105. if (interruptedBy !== null) {
  4106. if (interruptedBy.tag === HostRoot) {
  4107. warning = "A top-level update interrupted the previous render";
  4108. } else {
  4109. var componentName = getComponentName(interruptedBy.type) || "Unknown";
  4110. warning =
  4111. "An update to " + componentName + " interrupted the previous render";
  4112. }
  4113. } else if (commitCountInCurrentWorkLoop > 1) {
  4114. warning = "There were cascading updates";
  4115. }
  4116. commitCountInCurrentWorkLoop = 0;
  4117. var label = didCompleteRoot
  4118. ? "(React Tree Reconciliation: Completed Root)"
  4119. : "(React Tree Reconciliation: Yielded)"; // Pause any measurements until the next loop.
  4120. pauseTimers();
  4121. endMark(label, "(React Tree Reconciliation)", warning);
  4122. }
  4123. }
  4124. function startCommitTimer() {
  4125. {
  4126. if (!supportsUserTiming) {
  4127. return;
  4128. }
  4129. isCommitting = true;
  4130. hasScheduledUpdateInCurrentCommit = false;
  4131. labelsInCurrentCommit.clear();
  4132. beginMark("(Committing Changes)");
  4133. }
  4134. }
  4135. function stopCommitTimer() {
  4136. {
  4137. if (!supportsUserTiming) {
  4138. return;
  4139. }
  4140. var warning = null;
  4141. if (hasScheduledUpdateInCurrentCommit) {
  4142. warning = "Lifecycle hook scheduled a cascading update";
  4143. } else if (commitCountInCurrentWorkLoop > 0) {
  4144. warning = "Caused by a cascading update in earlier commit";
  4145. }
  4146. hasScheduledUpdateInCurrentCommit = false;
  4147. commitCountInCurrentWorkLoop++;
  4148. isCommitting = false;
  4149. labelsInCurrentCommit.clear();
  4150. endMark("(Committing Changes)", "(Committing Changes)", warning);
  4151. }
  4152. }
  4153. function startCommitSnapshotEffectsTimer() {
  4154. {
  4155. if (!supportsUserTiming) {
  4156. return;
  4157. }
  4158. effectCountInCurrentCommit = 0;
  4159. beginMark("(Committing Snapshot Effects)");
  4160. }
  4161. }
  4162. function stopCommitSnapshotEffectsTimer() {
  4163. {
  4164. if (!supportsUserTiming) {
  4165. return;
  4166. }
  4167. var count = effectCountInCurrentCommit;
  4168. effectCountInCurrentCommit = 0;
  4169. endMark(
  4170. "(Committing Snapshot Effects: " + count + " Total)",
  4171. "(Committing Snapshot Effects)",
  4172. null
  4173. );
  4174. }
  4175. }
  4176. function startCommitHostEffectsTimer() {
  4177. {
  4178. if (!supportsUserTiming) {
  4179. return;
  4180. }
  4181. effectCountInCurrentCommit = 0;
  4182. beginMark("(Committing Host Effects)");
  4183. }
  4184. }
  4185. function stopCommitHostEffectsTimer() {
  4186. {
  4187. if (!supportsUserTiming) {
  4188. return;
  4189. }
  4190. var count = effectCountInCurrentCommit;
  4191. effectCountInCurrentCommit = 0;
  4192. endMark(
  4193. "(Committing Host Effects: " + count + " Total)",
  4194. "(Committing Host Effects)",
  4195. null
  4196. );
  4197. }
  4198. }
  4199. function startCommitLifeCyclesTimer() {
  4200. {
  4201. if (!supportsUserTiming) {
  4202. return;
  4203. }
  4204. effectCountInCurrentCommit = 0;
  4205. beginMark("(Calling Lifecycle Methods)");
  4206. }
  4207. }
  4208. function stopCommitLifeCyclesTimer() {
  4209. {
  4210. if (!supportsUserTiming) {
  4211. return;
  4212. }
  4213. var count = effectCountInCurrentCommit;
  4214. effectCountInCurrentCommit = 0;
  4215. endMark(
  4216. "(Calling Lifecycle Methods: " + count + " Total)",
  4217. "(Calling Lifecycle Methods)",
  4218. null
  4219. );
  4220. }
  4221. }
  4222. var valueStack = [];
  4223. var fiberStack;
  4224. {
  4225. fiberStack = [];
  4226. }
  4227. var index = -1;
  4228. function createCursor(defaultValue) {
  4229. return {
  4230. current: defaultValue
  4231. };
  4232. }
  4233. function pop(cursor, fiber) {
  4234. if (index < 0) {
  4235. {
  4236. error("Unexpected pop.");
  4237. }
  4238. return;
  4239. }
  4240. {
  4241. if (fiber !== fiberStack[index]) {
  4242. error("Unexpected Fiber popped.");
  4243. }
  4244. }
  4245. cursor.current = valueStack[index];
  4246. valueStack[index] = null;
  4247. {
  4248. fiberStack[index] = null;
  4249. }
  4250. index--;
  4251. }
  4252. function push(cursor, value, fiber) {
  4253. index++;
  4254. valueStack[index] = cursor.current;
  4255. {
  4256. fiberStack[index] = fiber;
  4257. }
  4258. cursor.current = value;
  4259. }
  4260. var warnedAboutMissingGetChildContext;
  4261. {
  4262. warnedAboutMissingGetChildContext = {};
  4263. }
  4264. var emptyContextObject = {};
  4265. {
  4266. Object.freeze(emptyContextObject);
  4267. } // A cursor to the current merged context object on the stack.
  4268. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  4269. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  4270. // We use this to get access to the parent context after we have already
  4271. // pushed the next context provider, and now need to merge their contexts.
  4272. var previousContext = emptyContextObject;
  4273. function getUnmaskedContext(
  4274. workInProgress,
  4275. Component,
  4276. didPushOwnContextIfProvider
  4277. ) {
  4278. {
  4279. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  4280. // If the fiber is a context provider itself, when we read its context
  4281. // we may have already pushed its own child context on the stack. A context
  4282. // provider should not "see" its own child context. Therefore we read the
  4283. // previous (parent) context instead for a context provider.
  4284. return previousContext;
  4285. }
  4286. return contextStackCursor.current;
  4287. }
  4288. }
  4289. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  4290. {
  4291. var instance = workInProgress.stateNode;
  4292. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  4293. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  4294. }
  4295. }
  4296. function getMaskedContext(workInProgress, unmaskedContext) {
  4297. {
  4298. var type = workInProgress.type;
  4299. var contextTypes = type.contextTypes;
  4300. if (!contextTypes) {
  4301. return emptyContextObject;
  4302. } // Avoid recreating masked context unless unmasked context has changed.
  4303. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  4304. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  4305. var instance = workInProgress.stateNode;
  4306. if (
  4307. instance &&
  4308. instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
  4309. ) {
  4310. return instance.__reactInternalMemoizedMaskedChildContext;
  4311. }
  4312. var context = {};
  4313. for (var key in contextTypes) {
  4314. context[key] = unmaskedContext[key];
  4315. }
  4316. {
  4317. var name = getComponentName(type) || "Unknown";
  4318. checkPropTypes(contextTypes, context, "context", name);
  4319. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  4320. // Context is created before the class component is instantiated so check for instance.
  4321. if (instance) {
  4322. cacheContext(workInProgress, unmaskedContext, context);
  4323. }
  4324. return context;
  4325. }
  4326. }
  4327. function hasContextChanged() {
  4328. {
  4329. return didPerformWorkStackCursor.current;
  4330. }
  4331. }
  4332. function isContextProvider(type) {
  4333. {
  4334. var childContextTypes = type.childContextTypes;
  4335. return childContextTypes !== null && childContextTypes !== undefined;
  4336. }
  4337. }
  4338. function popContext(fiber) {
  4339. {
  4340. pop(didPerformWorkStackCursor, fiber);
  4341. pop(contextStackCursor, fiber);
  4342. }
  4343. }
  4344. function popTopLevelContextObject(fiber) {
  4345. {
  4346. pop(didPerformWorkStackCursor, fiber);
  4347. pop(contextStackCursor, fiber);
  4348. }
  4349. }
  4350. function pushTopLevelContextObject(fiber, context, didChange) {
  4351. {
  4352. if (!(contextStackCursor.current === emptyContextObject)) {
  4353. throw Error(
  4354. "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
  4355. );
  4356. }
  4357. push(contextStackCursor, context, fiber);
  4358. push(didPerformWorkStackCursor, didChange, fiber);
  4359. }
  4360. }
  4361. function processChildContext(fiber, type, parentContext) {
  4362. {
  4363. var instance = fiber.stateNode;
  4364. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  4365. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  4366. if (typeof instance.getChildContext !== "function") {
  4367. {
  4368. var componentName = getComponentName(type) || "Unknown";
  4369. if (!warnedAboutMissingGetChildContext[componentName]) {
  4370. warnedAboutMissingGetChildContext[componentName] = true;
  4371. error(
  4372. "%s.childContextTypes is specified but there is no getChildContext() method " +
  4373. "on the instance. You can either define getChildContext() on %s or remove " +
  4374. "childContextTypes from it.",
  4375. componentName,
  4376. componentName
  4377. );
  4378. }
  4379. }
  4380. return parentContext;
  4381. }
  4382. var childContext;
  4383. startPhaseTimer(fiber, "getChildContext");
  4384. childContext = instance.getChildContext();
  4385. stopPhaseTimer();
  4386. for (var contextKey in childContext) {
  4387. if (!(contextKey in childContextTypes)) {
  4388. throw Error(
  4389. (getComponentName(type) || "Unknown") +
  4390. '.getChildContext(): key "' +
  4391. contextKey +
  4392. '" is not defined in childContextTypes.'
  4393. );
  4394. }
  4395. }
  4396. {
  4397. var name = getComponentName(type) || "Unknown";
  4398. checkPropTypes(childContextTypes, childContext, "child context", name);
  4399. }
  4400. return Object.assign({}, parentContext, {}, childContext);
  4401. }
  4402. }
  4403. function pushContextProvider(workInProgress) {
  4404. {
  4405. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  4406. // If the instance does not exist yet, we will push null at first,
  4407. // and replace it on the stack later when invalidating the context.
  4408. var memoizedMergedChildContext =
  4409. (instance && instance.__reactInternalMemoizedMergedChildContext) ||
  4410. emptyContextObject; // Remember the parent context so we can merge with it later.
  4411. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  4412. previousContext = contextStackCursor.current;
  4413. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  4414. push(
  4415. didPerformWorkStackCursor,
  4416. didPerformWorkStackCursor.current,
  4417. workInProgress
  4418. );
  4419. return true;
  4420. }
  4421. }
  4422. function invalidateContextProvider(workInProgress, type, didChange) {
  4423. {
  4424. var instance = workInProgress.stateNode;
  4425. if (!instance) {
  4426. throw Error(
  4427. "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
  4428. );
  4429. }
  4430. if (didChange) {
  4431. // Merge parent and own context.
  4432. // Skip this if we're not updating due to sCU.
  4433. // This avoids unnecessarily recomputing memoized values.
  4434. var mergedContext = processChildContext(
  4435. workInProgress,
  4436. type,
  4437. previousContext
  4438. );
  4439. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  4440. // It is important to unwind the context in the reverse order.
  4441. pop(didPerformWorkStackCursor, workInProgress);
  4442. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  4443. push(contextStackCursor, mergedContext, workInProgress);
  4444. push(didPerformWorkStackCursor, didChange, workInProgress);
  4445. } else {
  4446. pop(didPerformWorkStackCursor, workInProgress);
  4447. push(didPerformWorkStackCursor, didChange, workInProgress);
  4448. }
  4449. }
  4450. }
  4451. function findCurrentUnmaskedContext(fiber) {
  4452. {
  4453. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  4454. // makes sense elsewhere
  4455. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  4456. throw Error(
  4457. "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
  4458. );
  4459. }
  4460. var node = fiber;
  4461. do {
  4462. switch (node.tag) {
  4463. case HostRoot:
  4464. return node.stateNode.context;
  4465. case ClassComponent: {
  4466. var Component = node.type;
  4467. if (isContextProvider(Component)) {
  4468. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  4469. }
  4470. break;
  4471. }
  4472. }
  4473. node = node.return;
  4474. } while (node !== null);
  4475. {
  4476. throw Error(
  4477. "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
  4478. );
  4479. }
  4480. }
  4481. }
  4482. var LegacyRoot = 0;
  4483. var BlockingRoot = 1;
  4484. var ConcurrentRoot = 2;
  4485. // Intentionally not named imports because Rollup would use dynamic dispatch for
  4486. var Scheduler_runWithPriority = Scheduler.unstable_runWithPriority,
  4487. Scheduler_scheduleCallback = Scheduler.unstable_scheduleCallback,
  4488. Scheduler_cancelCallback = Scheduler.unstable_cancelCallback,
  4489. Scheduler_shouldYield = Scheduler.unstable_shouldYield,
  4490. Scheduler_requestPaint = Scheduler.unstable_requestPaint,
  4491. Scheduler_now = Scheduler.unstable_now,
  4492. Scheduler_getCurrentPriorityLevel =
  4493. Scheduler.unstable_getCurrentPriorityLevel,
  4494. Scheduler_ImmediatePriority = Scheduler.unstable_ImmediatePriority,
  4495. Scheduler_UserBlockingPriority = Scheduler.unstable_UserBlockingPriority,
  4496. Scheduler_NormalPriority = Scheduler.unstable_NormalPriority,
  4497. Scheduler_LowPriority = Scheduler.unstable_LowPriority,
  4498. Scheduler_IdlePriority = Scheduler.unstable_IdlePriority;
  4499. {
  4500. // Provide explicit error message when production+profiling bundle of e.g.
  4501. // react-dom is used with production (non-profiling) bundle of
  4502. // scheduler/tracing
  4503. if (
  4504. !(
  4505. tracing.__interactionsRef != null &&
  4506. tracing.__interactionsRef.current != null
  4507. )
  4508. ) {
  4509. throw Error(
  4510. "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"
  4511. );
  4512. }
  4513. }
  4514. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  4515. // ascending numbers so we can compare them like numbers. They start at 90 to
  4516. // avoid clashing with Scheduler's priorities.
  4517. var ImmediatePriority = 99;
  4518. var UserBlockingPriority = 98;
  4519. var NormalPriority = 97;
  4520. var LowPriority = 96;
  4521. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  4522. var NoPriority = 90;
  4523. var shouldYield = Scheduler_shouldYield;
  4524. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  4525. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function() {};
  4526. var syncQueue = null;
  4527. var immediateQueueCallbackNode = null;
  4528. var isFlushingSyncQueue = false;
  4529. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  4530. // This will be the case for modern browsers that support `performance.now`. In
  4531. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  4532. // timestamp. In that case, subtract the module initialization time to simulate
  4533. // the behavior of performance.now and keep our times small enough to fit
  4534. // within 32 bits.
  4535. // TODO: Consider lifting this into Scheduler.
  4536. var now =
  4537. initialTimeMs < 10000
  4538. ? Scheduler_now
  4539. : function() {
  4540. return Scheduler_now() - initialTimeMs;
  4541. };
  4542. function getCurrentPriorityLevel() {
  4543. switch (Scheduler_getCurrentPriorityLevel()) {
  4544. case Scheduler_ImmediatePriority:
  4545. return ImmediatePriority;
  4546. case Scheduler_UserBlockingPriority:
  4547. return UserBlockingPriority;
  4548. case Scheduler_NormalPriority:
  4549. return NormalPriority;
  4550. case Scheduler_LowPriority:
  4551. return LowPriority;
  4552. case Scheduler_IdlePriority:
  4553. return IdlePriority;
  4554. default: {
  4555. throw Error("Unknown priority level.");
  4556. }
  4557. }
  4558. }
  4559. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  4560. switch (reactPriorityLevel) {
  4561. case ImmediatePriority:
  4562. return Scheduler_ImmediatePriority;
  4563. case UserBlockingPriority:
  4564. return Scheduler_UserBlockingPriority;
  4565. case NormalPriority:
  4566. return Scheduler_NormalPriority;
  4567. case LowPriority:
  4568. return Scheduler_LowPriority;
  4569. case IdlePriority:
  4570. return Scheduler_IdlePriority;
  4571. default: {
  4572. throw Error("Unknown priority level.");
  4573. }
  4574. }
  4575. }
  4576. function runWithPriority(reactPriorityLevel, fn) {
  4577. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4578. return Scheduler_runWithPriority(priorityLevel, fn);
  4579. }
  4580. function scheduleCallback(reactPriorityLevel, callback, options) {
  4581. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4582. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  4583. }
  4584. function scheduleSyncCallback(callback) {
  4585. // Push this callback into an internal queue. We'll flush these either in
  4586. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  4587. if (syncQueue === null) {
  4588. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  4589. immediateQueueCallbackNode = Scheduler_scheduleCallback(
  4590. Scheduler_ImmediatePriority,
  4591. flushSyncCallbackQueueImpl
  4592. );
  4593. } else {
  4594. // Push onto existing queue. Don't need to schedule a callback because
  4595. // we already scheduled one when we created the queue.
  4596. syncQueue.push(callback);
  4597. }
  4598. return fakeCallbackNode;
  4599. }
  4600. function cancelCallback(callbackNode) {
  4601. if (callbackNode !== fakeCallbackNode) {
  4602. Scheduler_cancelCallback(callbackNode);
  4603. }
  4604. }
  4605. function flushSyncCallbackQueue() {
  4606. if (immediateQueueCallbackNode !== null) {
  4607. var node = immediateQueueCallbackNode;
  4608. immediateQueueCallbackNode = null;
  4609. Scheduler_cancelCallback(node);
  4610. }
  4611. flushSyncCallbackQueueImpl();
  4612. }
  4613. function flushSyncCallbackQueueImpl() {
  4614. if (!isFlushingSyncQueue && syncQueue !== null) {
  4615. // Prevent re-entrancy.
  4616. isFlushingSyncQueue = true;
  4617. var i = 0;
  4618. try {
  4619. var _isSync = true;
  4620. var queue = syncQueue;
  4621. runWithPriority(ImmediatePriority, function() {
  4622. for (; i < queue.length; i++) {
  4623. var callback = queue[i];
  4624. do {
  4625. callback = callback(_isSync);
  4626. } while (callback !== null);
  4627. }
  4628. });
  4629. syncQueue = null;
  4630. } catch (error) {
  4631. // If something throws, leave the remaining callbacks on the queue.
  4632. if (syncQueue !== null) {
  4633. syncQueue = syncQueue.slice(i + 1);
  4634. } // Resume flushing in the next tick
  4635. Scheduler_scheduleCallback(
  4636. Scheduler_ImmediatePriority,
  4637. flushSyncCallbackQueue
  4638. );
  4639. throw error;
  4640. } finally {
  4641. isFlushingSyncQueue = false;
  4642. }
  4643. }
  4644. }
  4645. var NoMode = 0;
  4646. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  4647. // tag instead
  4648. var BlockingMode = 2;
  4649. var ConcurrentMode = 4;
  4650. var ProfileMode = 8;
  4651. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  4652. // Math.pow(2, 30) - 1
  4653. // 0b111111111111111111111111111111
  4654. var MAX_SIGNED_31_BIT_INT = 1073741823;
  4655. var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
  4656. // Never work can be committed in an inconsistent state without tearing the UI.
  4657. // The main example is offscreen content, like a hidden subtree. So one possible
  4658. // name is Offscreen. However, it also includes dehydrated Suspense boundaries,
  4659. // which are inconsistent in the sense that they haven't finished yet, but
  4660. // aren't visibly inconsistent because the server rendered HTML matches what the
  4661. // hydrated tree would look like.
  4662. var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
  4663. // order to be consistent.
  4664. var Idle = 2; // Continuous Hydration is slightly higher than Idle and is used to increase
  4665. var Sync = MAX_SIGNED_31_BIT_INT;
  4666. var Batched = Sync - 1;
  4667. var UNIT_SIZE = 10;
  4668. var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
  4669. function msToExpirationTime(ms) {
  4670. // Always subtract from the offset so that we don't clash with the magic number for NoWork.
  4671. return MAGIC_NUMBER_OFFSET - ((ms / UNIT_SIZE) | 0);
  4672. }
  4673. function expirationTimeToMs(expirationTime) {
  4674. return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
  4675. }
  4676. function ceiling(num, precision) {
  4677. return (((num / precision) | 0) + 1) * precision;
  4678. }
  4679. function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
  4680. return (
  4681. MAGIC_NUMBER_OFFSET -
  4682. ceiling(
  4683. MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE,
  4684. bucketSizeMs / UNIT_SIZE
  4685. )
  4686. );
  4687. } // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
  4688. // the names to reflect.
  4689. var LOW_PRIORITY_EXPIRATION = 5000;
  4690. var LOW_PRIORITY_BATCH_SIZE = 250;
  4691. function computeAsyncExpiration(currentTime) {
  4692. return computeExpirationBucket(
  4693. currentTime,
  4694. LOW_PRIORITY_EXPIRATION,
  4695. LOW_PRIORITY_BATCH_SIZE
  4696. );
  4697. }
  4698. function computeSuspenseExpiration(currentTime, timeoutMs) {
  4699. // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
  4700. return computeExpirationBucket(
  4701. currentTime,
  4702. timeoutMs,
  4703. LOW_PRIORITY_BATCH_SIZE
  4704. );
  4705. } // We intentionally set a higher expiration time for interactive updates in
  4706. // dev than in production.
  4707. //
  4708. // If the main thread is being blocked so long that you hit the expiration,
  4709. // it's a problem that could be solved with better scheduling.
  4710. //
  4711. // People will be more likely to notice this and fix it with the long
  4712. // expiration time in development.
  4713. //
  4714. // In production we opt for better UX at the risk of masking scheduling
  4715. // problems, by expiring fast.
  4716. var HIGH_PRIORITY_EXPIRATION = 500;
  4717. var HIGH_PRIORITY_BATCH_SIZE = 100;
  4718. function computeInteractiveExpiration(currentTime) {
  4719. return computeExpirationBucket(
  4720. currentTime,
  4721. HIGH_PRIORITY_EXPIRATION,
  4722. HIGH_PRIORITY_BATCH_SIZE
  4723. );
  4724. }
  4725. function inferPriorityFromExpirationTime(currentTime, expirationTime) {
  4726. if (expirationTime === Sync) {
  4727. return ImmediatePriority;
  4728. }
  4729. if (expirationTime === Never || expirationTime === Idle) {
  4730. return IdlePriority;
  4731. }
  4732. var msUntil =
  4733. expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
  4734. if (msUntil <= 0) {
  4735. return ImmediatePriority;
  4736. }
  4737. if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
  4738. return UserBlockingPriority;
  4739. }
  4740. if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
  4741. return NormalPriority;
  4742. } // TODO: Handle LowPriority
  4743. // Assume anything lower has idle priority
  4744. return IdlePriority;
  4745. }
  4746. /**
  4747. * inlined Object.is polyfill to avoid requiring consumers ship their own
  4748. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  4749. */
  4750. function is(x, y) {
  4751. return (
  4752. (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare
  4753. );
  4754. }
  4755. var objectIs = typeof Object.is === "function" ? Object.is : is;
  4756. var hasOwnProperty = Object.prototype.hasOwnProperty;
  4757. /**
  4758. * Performs equality by iterating through keys on an object and returning false
  4759. * when any key has values which are not strictly equal between the arguments.
  4760. * Returns true when the values of all keys are strictly equal.
  4761. */
  4762. function shallowEqual(objA, objB) {
  4763. if (objectIs(objA, objB)) {
  4764. return true;
  4765. }
  4766. if (
  4767. typeof objA !== "object" ||
  4768. objA === null ||
  4769. typeof objB !== "object" ||
  4770. objB === null
  4771. ) {
  4772. return false;
  4773. }
  4774. var keysA = Object.keys(objA);
  4775. var keysB = Object.keys(objB);
  4776. if (keysA.length !== keysB.length) {
  4777. return false;
  4778. } // Test for A's keys different from B.
  4779. for (var i = 0; i < keysA.length; i++) {
  4780. if (
  4781. !hasOwnProperty.call(objB, keysA[i]) ||
  4782. !objectIs(objA[keysA[i]], objB[keysA[i]])
  4783. ) {
  4784. return false;
  4785. }
  4786. }
  4787. return true;
  4788. }
  4789. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  4790. function describeComponentFrame(name, source, ownerName) {
  4791. var sourceInfo = "";
  4792. if (source) {
  4793. var path = source.fileName;
  4794. var fileName = path.replace(BEFORE_SLASH_RE, "");
  4795. {
  4796. // In DEV, include code for a common special case:
  4797. // prefer "folder/index.js" instead of just "index.js".
  4798. if (/^index\./.test(fileName)) {
  4799. var match = path.match(BEFORE_SLASH_RE);
  4800. if (match) {
  4801. var pathBeforeSlash = match[1];
  4802. if (pathBeforeSlash) {
  4803. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, "");
  4804. fileName = folderName + "/" + fileName;
  4805. }
  4806. }
  4807. }
  4808. }
  4809. sourceInfo = " (at " + fileName + ":" + source.lineNumber + ")";
  4810. } else if (ownerName) {
  4811. sourceInfo = " (created by " + ownerName + ")";
  4812. }
  4813. return "\n in " + (name || "Unknown") + sourceInfo;
  4814. }
  4815. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  4816. function describeFiber(fiber) {
  4817. switch (fiber.tag) {
  4818. case HostRoot:
  4819. case HostPortal:
  4820. case HostText:
  4821. case Fragment:
  4822. case ContextProvider:
  4823. case ContextConsumer:
  4824. return "";
  4825. default:
  4826. var owner = fiber._debugOwner;
  4827. var source = fiber._debugSource;
  4828. var name = getComponentName(fiber.type);
  4829. var ownerName = null;
  4830. if (owner) {
  4831. ownerName = getComponentName(owner.type);
  4832. }
  4833. return describeComponentFrame(name, source, ownerName);
  4834. }
  4835. }
  4836. function getStackByFiberInDevAndProd(workInProgress) {
  4837. var info = "";
  4838. var node = workInProgress;
  4839. do {
  4840. info += describeFiber(node);
  4841. node = node.return;
  4842. } while (node);
  4843. return info;
  4844. }
  4845. var current = null;
  4846. var isRendering = false;
  4847. function getCurrentFiberOwnerNameInDevOrNull() {
  4848. {
  4849. if (current === null) {
  4850. return null;
  4851. }
  4852. var owner = current._debugOwner;
  4853. if (owner !== null && typeof owner !== "undefined") {
  4854. return getComponentName(owner.type);
  4855. }
  4856. }
  4857. return null;
  4858. }
  4859. function getCurrentFiberStackInDev() {
  4860. {
  4861. if (current === null) {
  4862. return "";
  4863. } // Safe because if current fiber exists, we are reconciling,
  4864. // and it is guaranteed to be the work-in-progress version.
  4865. return getStackByFiberInDevAndProd(current);
  4866. }
  4867. }
  4868. function resetCurrentFiber() {
  4869. {
  4870. ReactDebugCurrentFrame.getCurrentStack = null;
  4871. current = null;
  4872. isRendering = false;
  4873. }
  4874. }
  4875. function setCurrentFiber(fiber) {
  4876. {
  4877. ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
  4878. current = fiber;
  4879. isRendering = false;
  4880. }
  4881. }
  4882. function setIsRendering(rendering) {
  4883. {
  4884. isRendering = rendering;
  4885. }
  4886. }
  4887. var ReactStrictModeWarnings = {
  4888. recordUnsafeLifecycleWarnings: function(fiber, instance) {},
  4889. flushPendingUnsafeLifecycleWarnings: function() {},
  4890. recordLegacyContextWarning: function(fiber, instance) {},
  4891. flushLegacyContextWarning: function() {},
  4892. discardPendingWarnings: function() {}
  4893. };
  4894. {
  4895. var findStrictRoot = function(fiber) {
  4896. var maybeStrictRoot = null;
  4897. var node = fiber;
  4898. while (node !== null) {
  4899. if (node.mode & StrictMode) {
  4900. maybeStrictRoot = node;
  4901. }
  4902. node = node.return;
  4903. }
  4904. return maybeStrictRoot;
  4905. };
  4906. var setToSortedString = function(set) {
  4907. var array = [];
  4908. set.forEach(function(value) {
  4909. array.push(value);
  4910. });
  4911. return array.sort().join(", ");
  4912. };
  4913. var pendingComponentWillMountWarnings = [];
  4914. var pendingUNSAFE_ComponentWillMountWarnings = [];
  4915. var pendingComponentWillReceivePropsWarnings = [];
  4916. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4917. var pendingComponentWillUpdateWarnings = [];
  4918. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  4919. var didWarnAboutUnsafeLifecycles = new Set();
  4920. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function(
  4921. fiber,
  4922. instance
  4923. ) {
  4924. // Dedup strategy: Warn once per component.
  4925. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  4926. return;
  4927. }
  4928. if (
  4929. typeof instance.componentWillMount === "function" && // Don't warn about react-lifecycles-compat polyfilled components.
  4930. instance.componentWillMount.__suppressDeprecationWarning !== true
  4931. ) {
  4932. pendingComponentWillMountWarnings.push(fiber);
  4933. }
  4934. if (
  4935. fiber.mode & StrictMode &&
  4936. typeof instance.UNSAFE_componentWillMount === "function"
  4937. ) {
  4938. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  4939. }
  4940. if (
  4941. typeof instance.componentWillReceiveProps === "function" &&
  4942. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  4943. ) {
  4944. pendingComponentWillReceivePropsWarnings.push(fiber);
  4945. }
  4946. if (
  4947. fiber.mode & StrictMode &&
  4948. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  4949. ) {
  4950. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  4951. }
  4952. if (
  4953. typeof instance.componentWillUpdate === "function" &&
  4954. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  4955. ) {
  4956. pendingComponentWillUpdateWarnings.push(fiber);
  4957. }
  4958. if (
  4959. fiber.mode & StrictMode &&
  4960. typeof instance.UNSAFE_componentWillUpdate === "function"
  4961. ) {
  4962. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  4963. }
  4964. };
  4965. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() {
  4966. // We do an initial pass to gather component names
  4967. var componentWillMountUniqueNames = new Set();
  4968. if (pendingComponentWillMountWarnings.length > 0) {
  4969. pendingComponentWillMountWarnings.forEach(function(fiber) {
  4970. componentWillMountUniqueNames.add(
  4971. getComponentName(fiber.type) || "Component"
  4972. );
  4973. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4974. });
  4975. pendingComponentWillMountWarnings = [];
  4976. }
  4977. var UNSAFE_componentWillMountUniqueNames = new Set();
  4978. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  4979. pendingUNSAFE_ComponentWillMountWarnings.forEach(function(fiber) {
  4980. UNSAFE_componentWillMountUniqueNames.add(
  4981. getComponentName(fiber.type) || "Component"
  4982. );
  4983. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4984. });
  4985. pendingUNSAFE_ComponentWillMountWarnings = [];
  4986. }
  4987. var componentWillReceivePropsUniqueNames = new Set();
  4988. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  4989. pendingComponentWillReceivePropsWarnings.forEach(function(fiber) {
  4990. componentWillReceivePropsUniqueNames.add(
  4991. getComponentName(fiber.type) || "Component"
  4992. );
  4993. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4994. });
  4995. pendingComponentWillReceivePropsWarnings = [];
  4996. }
  4997. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  4998. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  4999. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function(fiber) {
  5000. UNSAFE_componentWillReceivePropsUniqueNames.add(
  5001. getComponentName(fiber.type) || "Component"
  5002. );
  5003. didWarnAboutUnsafeLifecycles.add(fiber.type);
  5004. });
  5005. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  5006. }
  5007. var componentWillUpdateUniqueNames = new Set();
  5008. if (pendingComponentWillUpdateWarnings.length > 0) {
  5009. pendingComponentWillUpdateWarnings.forEach(function(fiber) {
  5010. componentWillUpdateUniqueNames.add(
  5011. getComponentName(fiber.type) || "Component"
  5012. );
  5013. didWarnAboutUnsafeLifecycles.add(fiber.type);
  5014. });
  5015. pendingComponentWillUpdateWarnings = [];
  5016. }
  5017. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  5018. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  5019. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function(fiber) {
  5020. UNSAFE_componentWillUpdateUniqueNames.add(
  5021. getComponentName(fiber.type) || "Component"
  5022. );
  5023. didWarnAboutUnsafeLifecycles.add(fiber.type);
  5024. });
  5025. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  5026. } // Finally, we flush all the warnings
  5027. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  5028. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  5029. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  5030. error(
  5031. "Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. " +
  5032. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5033. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  5034. "\nPlease update the following components: %s",
  5035. sortedNames
  5036. );
  5037. }
  5038. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  5039. var _sortedNames = setToSortedString(
  5040. UNSAFE_componentWillReceivePropsUniqueNames
  5041. );
  5042. error(
  5043. "Using UNSAFE_componentWillReceiveProps in strict mode is not recommended " +
  5044. "and may indicate bugs in your code. " +
  5045. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5046. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5047. "* If you're updating state whenever props change, " +
  5048. "refactor your code to use memoization techniques or move it to " +
  5049. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  5050. "\nPlease update the following components: %s",
  5051. _sortedNames
  5052. );
  5053. }
  5054. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  5055. var _sortedNames2 = setToSortedString(
  5056. UNSAFE_componentWillUpdateUniqueNames
  5057. );
  5058. error(
  5059. "Using UNSAFE_componentWillUpdate in strict mode is not recommended " +
  5060. "and may indicate bugs in your code. " +
  5061. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5062. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5063. "\nPlease update the following components: %s",
  5064. _sortedNames2
  5065. );
  5066. }
  5067. if (componentWillMountUniqueNames.size > 0) {
  5068. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  5069. warn(
  5070. "componentWillMount has been renamed, and is not recommended for use. " +
  5071. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5072. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  5073. "* Rename componentWillMount to UNSAFE_componentWillMount to suppress " +
  5074. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  5075. "To rename all deprecated lifecycles to their new names, you can run " +
  5076. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  5077. "\nPlease update the following components: %s",
  5078. _sortedNames3
  5079. );
  5080. }
  5081. if (componentWillReceivePropsUniqueNames.size > 0) {
  5082. var _sortedNames4 = setToSortedString(
  5083. componentWillReceivePropsUniqueNames
  5084. );
  5085. warn(
  5086. "componentWillReceiveProps has been renamed, and is not recommended for use. " +
  5087. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5088. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5089. "* If you're updating state whenever props change, refactor your " +
  5090. "code to use memoization techniques or move it to " +
  5091. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  5092. "* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress " +
  5093. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  5094. "To rename all deprecated lifecycles to their new names, you can run " +
  5095. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  5096. "\nPlease update the following components: %s",
  5097. _sortedNames4
  5098. );
  5099. }
  5100. if (componentWillUpdateUniqueNames.size > 0) {
  5101. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  5102. warn(
  5103. "componentWillUpdate has been renamed, and is not recommended for use. " +
  5104. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  5105. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  5106. "* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress " +
  5107. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  5108. "To rename all deprecated lifecycles to their new names, you can run " +
  5109. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  5110. "\nPlease update the following components: %s",
  5111. _sortedNames5
  5112. );
  5113. }
  5114. };
  5115. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  5116. var didWarnAboutLegacyContext = new Set();
  5117. ReactStrictModeWarnings.recordLegacyContextWarning = function(
  5118. fiber,
  5119. instance
  5120. ) {
  5121. var strictRoot = findStrictRoot(fiber);
  5122. if (strictRoot === null) {
  5123. error(
  5124. "Expected to find a StrictMode component in a strict mode tree. " +
  5125. "This error is likely caused by a bug in React. Please file an issue."
  5126. );
  5127. return;
  5128. } // Dedup strategy: Warn once per component.
  5129. if (didWarnAboutLegacyContext.has(fiber.type)) {
  5130. return;
  5131. }
  5132. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  5133. if (
  5134. fiber.type.contextTypes != null ||
  5135. fiber.type.childContextTypes != null ||
  5136. (instance !== null && typeof instance.getChildContext === "function")
  5137. ) {
  5138. if (warningsForRoot === undefined) {
  5139. warningsForRoot = [];
  5140. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  5141. }
  5142. warningsForRoot.push(fiber);
  5143. }
  5144. };
  5145. ReactStrictModeWarnings.flushLegacyContextWarning = function() {
  5146. pendingLegacyContextWarning.forEach(function(fiberArray, strictRoot) {
  5147. if (fiberArray.length === 0) {
  5148. return;
  5149. }
  5150. var firstFiber = fiberArray[0];
  5151. var uniqueNames = new Set();
  5152. fiberArray.forEach(function(fiber) {
  5153. uniqueNames.add(getComponentName(fiber.type) || "Component");
  5154. didWarnAboutLegacyContext.add(fiber.type);
  5155. });
  5156. var sortedNames = setToSortedString(uniqueNames);
  5157. var firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
  5158. error(
  5159. "Legacy context API has been detected within a strict-mode tree." +
  5160. "\n\nThe old API will be supported in all 16.x releases, but applications " +
  5161. "using it should migrate to the new version." +
  5162. "\n\nPlease update the following components: %s" +
  5163. "\n\nLearn more about this warning here: https://fb.me/react-legacy-context" +
  5164. "%s",
  5165. sortedNames,
  5166. firstComponentStack
  5167. );
  5168. });
  5169. };
  5170. ReactStrictModeWarnings.discardPendingWarnings = function() {
  5171. pendingComponentWillMountWarnings = [];
  5172. pendingUNSAFE_ComponentWillMountWarnings = [];
  5173. pendingComponentWillReceivePropsWarnings = [];
  5174. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  5175. pendingComponentWillUpdateWarnings = [];
  5176. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  5177. pendingLegacyContextWarning = new Map();
  5178. };
  5179. }
  5180. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  5181. var failedBoundaries = null;
  5182. var setRefreshHandler = function(handler) {
  5183. {
  5184. resolveFamily = handler;
  5185. }
  5186. };
  5187. function resolveFunctionForHotReloading(type) {
  5188. {
  5189. if (resolveFamily === null) {
  5190. // Hot reloading is disabled.
  5191. return type;
  5192. }
  5193. var family = resolveFamily(type);
  5194. if (family === undefined) {
  5195. return type;
  5196. } // Use the latest known implementation.
  5197. return family.current;
  5198. }
  5199. }
  5200. function resolveClassForHotReloading(type) {
  5201. // No implementation differences.
  5202. return resolveFunctionForHotReloading(type);
  5203. }
  5204. function resolveForwardRefForHotReloading(type) {
  5205. {
  5206. if (resolveFamily === null) {
  5207. // Hot reloading is disabled.
  5208. return type;
  5209. }
  5210. var family = resolveFamily(type);
  5211. if (family === undefined) {
  5212. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  5213. if (
  5214. type !== null &&
  5215. type !== undefined &&
  5216. typeof type.render === "function"
  5217. ) {
  5218. // ForwardRef is special because its resolved .type is an object,
  5219. // but it's possible that we only have its inner render function in the map.
  5220. // If that inner render function is different, we'll build a new forwardRef type.
  5221. var currentRender = resolveFunctionForHotReloading(type.render);
  5222. if (type.render !== currentRender) {
  5223. var syntheticType = {
  5224. $$typeof: REACT_FORWARD_REF_TYPE,
  5225. render: currentRender
  5226. };
  5227. if (type.displayName !== undefined) {
  5228. syntheticType.displayName = type.displayName;
  5229. }
  5230. return syntheticType;
  5231. }
  5232. }
  5233. return type;
  5234. } // Use the latest known implementation.
  5235. return family.current;
  5236. }
  5237. }
  5238. function isCompatibleFamilyForHotReloading(fiber, element) {
  5239. {
  5240. if (resolveFamily === null) {
  5241. // Hot reloading is disabled.
  5242. return false;
  5243. }
  5244. var prevType = fiber.elementType;
  5245. var nextType = element.type; // If we got here, we know types aren't === equal.
  5246. var needsCompareFamilies = false;
  5247. var $$typeofNextType =
  5248. typeof nextType === "object" && nextType !== null
  5249. ? nextType.$$typeof
  5250. : null;
  5251. switch (fiber.tag) {
  5252. case ClassComponent: {
  5253. if (typeof nextType === "function") {
  5254. needsCompareFamilies = true;
  5255. }
  5256. break;
  5257. }
  5258. case FunctionComponent: {
  5259. if (typeof nextType === "function") {
  5260. needsCompareFamilies = true;
  5261. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  5262. // We don't know the inner type yet.
  5263. // We're going to assume that the lazy inner type is stable,
  5264. // and so it is sufficient to avoid reconciling it away.
  5265. // We're not going to unwrap or actually use the new lazy type.
  5266. needsCompareFamilies = true;
  5267. }
  5268. break;
  5269. }
  5270. case ForwardRef: {
  5271. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  5272. needsCompareFamilies = true;
  5273. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  5274. needsCompareFamilies = true;
  5275. }
  5276. break;
  5277. }
  5278. case MemoComponent:
  5279. case SimpleMemoComponent: {
  5280. if ($$typeofNextType === REACT_MEMO_TYPE) {
  5281. // TODO: if it was but can no longer be simple,
  5282. // we shouldn't set this.
  5283. needsCompareFamilies = true;
  5284. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  5285. needsCompareFamilies = true;
  5286. }
  5287. break;
  5288. }
  5289. default:
  5290. return false;
  5291. } // Check if both types have a family and it's the same one.
  5292. if (needsCompareFamilies) {
  5293. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  5294. // This means both of them need to be registered to preserve state.
  5295. // If we unwrapped and compared the inner types for wrappers instead,
  5296. // then we would risk falsely saying two separate memo(Foo)
  5297. // calls are equivalent because they wrap the same Foo function.
  5298. var prevFamily = resolveFamily(prevType);
  5299. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  5300. return true;
  5301. }
  5302. }
  5303. return false;
  5304. }
  5305. }
  5306. function markFailedErrorBoundaryForHotReloading(fiber) {
  5307. {
  5308. if (resolveFamily === null) {
  5309. // Hot reloading is disabled.
  5310. return;
  5311. }
  5312. if (typeof WeakSet !== "function") {
  5313. return;
  5314. }
  5315. if (failedBoundaries === null) {
  5316. failedBoundaries = new WeakSet();
  5317. }
  5318. failedBoundaries.add(fiber);
  5319. }
  5320. }
  5321. var scheduleRefresh = function(root, update) {
  5322. {
  5323. if (resolveFamily === null) {
  5324. // Hot reloading is disabled.
  5325. return;
  5326. }
  5327. var staleFamilies = update.staleFamilies,
  5328. updatedFamilies = update.updatedFamilies;
  5329. flushPassiveEffects();
  5330. flushSync(function() {
  5331. scheduleFibersWithFamiliesRecursively(
  5332. root.current,
  5333. updatedFamilies,
  5334. staleFamilies
  5335. );
  5336. });
  5337. }
  5338. };
  5339. var scheduleRoot = function(root, element) {
  5340. {
  5341. if (root.context !== emptyContextObject) {
  5342. // Super edge case: root has a legacy _renderSubtree context
  5343. // but we don't know the parentComponent so we can't pass it.
  5344. // Just ignore. We'll delete this with _renderSubtree code path later.
  5345. return;
  5346. }
  5347. flushPassiveEffects();
  5348. syncUpdates(function() {
  5349. updateContainer(element, root, null, null);
  5350. });
  5351. }
  5352. };
  5353. function scheduleFibersWithFamiliesRecursively(
  5354. fiber,
  5355. updatedFamilies,
  5356. staleFamilies
  5357. ) {
  5358. {
  5359. var alternate = fiber.alternate,
  5360. child = fiber.child,
  5361. sibling = fiber.sibling,
  5362. tag = fiber.tag,
  5363. type = fiber.type;
  5364. var candidateType = null;
  5365. switch (tag) {
  5366. case FunctionComponent:
  5367. case SimpleMemoComponent:
  5368. case ClassComponent:
  5369. candidateType = type;
  5370. break;
  5371. case ForwardRef:
  5372. candidateType = type.render;
  5373. break;
  5374. }
  5375. if (resolveFamily === null) {
  5376. throw new Error("Expected resolveFamily to be set during hot reload.");
  5377. }
  5378. var needsRender = false;
  5379. var needsRemount = false;
  5380. if (candidateType !== null) {
  5381. var family = resolveFamily(candidateType);
  5382. if (family !== undefined) {
  5383. if (staleFamilies.has(family)) {
  5384. needsRemount = true;
  5385. } else if (updatedFamilies.has(family)) {
  5386. if (tag === ClassComponent) {
  5387. needsRemount = true;
  5388. } else {
  5389. needsRender = true;
  5390. }
  5391. }
  5392. }
  5393. }
  5394. if (failedBoundaries !== null) {
  5395. if (
  5396. failedBoundaries.has(fiber) ||
  5397. (alternate !== null && failedBoundaries.has(alternate))
  5398. ) {
  5399. needsRemount = true;
  5400. }
  5401. }
  5402. if (needsRemount) {
  5403. fiber._debugNeedsRemount = true;
  5404. }
  5405. if (needsRemount || needsRender) {
  5406. scheduleWork(fiber, Sync);
  5407. }
  5408. if (child !== null && !needsRemount) {
  5409. scheduleFibersWithFamiliesRecursively(
  5410. child,
  5411. updatedFamilies,
  5412. staleFamilies
  5413. );
  5414. }
  5415. if (sibling !== null) {
  5416. scheduleFibersWithFamiliesRecursively(
  5417. sibling,
  5418. updatedFamilies,
  5419. staleFamilies
  5420. );
  5421. }
  5422. }
  5423. }
  5424. var findHostInstancesForRefresh = function(root, families) {
  5425. {
  5426. var hostInstances = new Set();
  5427. var types = new Set(
  5428. families.map(function(family) {
  5429. return family.current;
  5430. })
  5431. );
  5432. findHostInstancesForMatchingFibersRecursively(
  5433. root.current,
  5434. types,
  5435. hostInstances
  5436. );
  5437. return hostInstances;
  5438. }
  5439. };
  5440. function findHostInstancesForMatchingFibersRecursively(
  5441. fiber,
  5442. types,
  5443. hostInstances
  5444. ) {
  5445. {
  5446. var child = fiber.child,
  5447. sibling = fiber.sibling,
  5448. tag = fiber.tag,
  5449. type = fiber.type;
  5450. var candidateType = null;
  5451. switch (tag) {
  5452. case FunctionComponent:
  5453. case SimpleMemoComponent:
  5454. case ClassComponent:
  5455. candidateType = type;
  5456. break;
  5457. case ForwardRef:
  5458. candidateType = type.render;
  5459. break;
  5460. }
  5461. var didMatch = false;
  5462. if (candidateType !== null) {
  5463. if (types.has(candidateType)) {
  5464. didMatch = true;
  5465. }
  5466. }
  5467. if (didMatch) {
  5468. // We have a match. This only drills down to the closest host components.
  5469. // There's no need to search deeper because for the purpose of giving
  5470. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  5471. findHostInstancesForFiberShallowly(fiber, hostInstances);
  5472. } else {
  5473. // If there's no match, maybe there will be one further down in the child tree.
  5474. if (child !== null) {
  5475. findHostInstancesForMatchingFibersRecursively(
  5476. child,
  5477. types,
  5478. hostInstances
  5479. );
  5480. }
  5481. }
  5482. if (sibling !== null) {
  5483. findHostInstancesForMatchingFibersRecursively(
  5484. sibling,
  5485. types,
  5486. hostInstances
  5487. );
  5488. }
  5489. }
  5490. }
  5491. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  5492. {
  5493. var foundHostInstances = findChildHostInstancesForFiberShallowly(
  5494. fiber,
  5495. hostInstances
  5496. );
  5497. if (foundHostInstances) {
  5498. return;
  5499. } // If we didn't find any host children, fallback to closest host parent.
  5500. var node = fiber;
  5501. while (true) {
  5502. switch (node.tag) {
  5503. case HostComponent:
  5504. hostInstances.add(node.stateNode);
  5505. return;
  5506. case HostPortal:
  5507. hostInstances.add(node.stateNode.containerInfo);
  5508. return;
  5509. case HostRoot:
  5510. hostInstances.add(node.stateNode.containerInfo);
  5511. return;
  5512. }
  5513. if (node.return === null) {
  5514. throw new Error("Expected to reach root first.");
  5515. }
  5516. node = node.return;
  5517. }
  5518. }
  5519. }
  5520. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  5521. {
  5522. var node = fiber;
  5523. var foundHostInstances = false;
  5524. while (true) {
  5525. if (node.tag === HostComponent) {
  5526. // We got a match.
  5527. foundHostInstances = true;
  5528. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  5529. } else if (node.child !== null) {
  5530. node.child.return = node;
  5531. node = node.child;
  5532. continue;
  5533. }
  5534. if (node === fiber) {
  5535. return foundHostInstances;
  5536. }
  5537. while (node.sibling === null) {
  5538. if (node.return === null || node.return === fiber) {
  5539. return foundHostInstances;
  5540. }
  5541. node = node.return;
  5542. }
  5543. node.sibling.return = node.return;
  5544. node = node.sibling;
  5545. }
  5546. }
  5547. return false;
  5548. }
  5549. function resolveDefaultProps(Component, baseProps) {
  5550. if (Component && Component.defaultProps) {
  5551. // Resolve default props. Taken from ReactElement
  5552. var props = Object.assign({}, baseProps);
  5553. var defaultProps = Component.defaultProps;
  5554. for (var propName in defaultProps) {
  5555. if (props[propName] === undefined) {
  5556. props[propName] = defaultProps[propName];
  5557. }
  5558. }
  5559. return props;
  5560. }
  5561. return baseProps;
  5562. }
  5563. function readLazyComponentType(lazyComponent) {
  5564. initializeLazyComponentType(lazyComponent);
  5565. if (lazyComponent._status !== Resolved) {
  5566. throw lazyComponent._result;
  5567. }
  5568. return lazyComponent._result;
  5569. }
  5570. var valueCursor = createCursor(null);
  5571. var rendererSigil;
  5572. {
  5573. // Use this to detect multiple renderers using the same context
  5574. rendererSigil = {};
  5575. }
  5576. var currentlyRenderingFiber = null;
  5577. var lastContextDependency = null;
  5578. var lastContextWithAllBitsObserved = null;
  5579. var isDisallowedContextReadInDEV = false;
  5580. function resetContextDependencies() {
  5581. // This is called right before React yields execution, to ensure `readContext`
  5582. // cannot be called outside the render phase.
  5583. currentlyRenderingFiber = null;
  5584. lastContextDependency = null;
  5585. lastContextWithAllBitsObserved = null;
  5586. {
  5587. isDisallowedContextReadInDEV = false;
  5588. }
  5589. }
  5590. function enterDisallowedContextReadInDEV() {
  5591. {
  5592. isDisallowedContextReadInDEV = true;
  5593. }
  5594. }
  5595. function exitDisallowedContextReadInDEV() {
  5596. {
  5597. isDisallowedContextReadInDEV = false;
  5598. }
  5599. }
  5600. function pushProvider(providerFiber, nextValue) {
  5601. var context = providerFiber.type._context;
  5602. {
  5603. push(valueCursor, context._currentValue, providerFiber);
  5604. context._currentValue = nextValue;
  5605. {
  5606. if (
  5607. context._currentRenderer !== undefined &&
  5608. context._currentRenderer !== null &&
  5609. context._currentRenderer !== rendererSigil
  5610. ) {
  5611. error(
  5612. "Detected multiple renderers concurrently rendering the " +
  5613. "same context provider. This is currently unsupported."
  5614. );
  5615. }
  5616. context._currentRenderer = rendererSigil;
  5617. }
  5618. }
  5619. }
  5620. function popProvider(providerFiber) {
  5621. var currentValue = valueCursor.current;
  5622. pop(valueCursor, providerFiber);
  5623. var context = providerFiber.type._context;
  5624. {
  5625. context._currentValue = currentValue;
  5626. }
  5627. }
  5628. function calculateChangedBits(context, newValue, oldValue) {
  5629. if (objectIs(oldValue, newValue)) {
  5630. // No change
  5631. return 0;
  5632. } else {
  5633. var changedBits =
  5634. typeof context._calculateChangedBits === "function"
  5635. ? context._calculateChangedBits(oldValue, newValue)
  5636. : MAX_SIGNED_31_BIT_INT;
  5637. {
  5638. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  5639. error(
  5640. "calculateChangedBits: Expected the return value to be a " +
  5641. "31-bit integer. Instead received: %s",
  5642. changedBits
  5643. );
  5644. }
  5645. }
  5646. return changedBits | 0;
  5647. }
  5648. }
  5649. function scheduleWorkOnParentPath(parent, renderExpirationTime) {
  5650. // Update the child expiration time of all the ancestors, including
  5651. // the alternates.
  5652. var node = parent;
  5653. while (node !== null) {
  5654. var alternate = node.alternate;
  5655. if (node.childExpirationTime < renderExpirationTime) {
  5656. node.childExpirationTime = renderExpirationTime;
  5657. if (
  5658. alternate !== null &&
  5659. alternate.childExpirationTime < renderExpirationTime
  5660. ) {
  5661. alternate.childExpirationTime = renderExpirationTime;
  5662. }
  5663. } else if (
  5664. alternate !== null &&
  5665. alternate.childExpirationTime < renderExpirationTime
  5666. ) {
  5667. alternate.childExpirationTime = renderExpirationTime;
  5668. } else {
  5669. // Neither alternate was updated, which means the rest of the
  5670. // ancestor path already has sufficient priority.
  5671. break;
  5672. }
  5673. node = node.return;
  5674. }
  5675. }
  5676. function propagateContextChange(
  5677. workInProgress,
  5678. context,
  5679. changedBits,
  5680. renderExpirationTime
  5681. ) {
  5682. var fiber = workInProgress.child;
  5683. if (fiber !== null) {
  5684. // Set the return pointer of the child to the work-in-progress fiber.
  5685. fiber.return = workInProgress;
  5686. }
  5687. while (fiber !== null) {
  5688. var nextFiber = void 0; // Visit this fiber.
  5689. var list = fiber.dependencies;
  5690. if (list !== null) {
  5691. nextFiber = fiber.child;
  5692. var dependency = list.firstContext;
  5693. while (dependency !== null) {
  5694. // Check if the context matches.
  5695. if (
  5696. dependency.context === context &&
  5697. (dependency.observedBits & changedBits) !== 0
  5698. ) {
  5699. // Match! Schedule an update on this fiber.
  5700. if (fiber.tag === ClassComponent) {
  5701. // Schedule a force update on the work-in-progress.
  5702. var update = createUpdate(renderExpirationTime, null);
  5703. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  5704. // update to the current fiber, too, which means it will persist even if
  5705. // this render is thrown away. Since it's a race condition, not sure it's
  5706. // worth fixing.
  5707. enqueueUpdate(fiber, update);
  5708. }
  5709. if (fiber.expirationTime < renderExpirationTime) {
  5710. fiber.expirationTime = renderExpirationTime;
  5711. }
  5712. var alternate = fiber.alternate;
  5713. if (
  5714. alternate !== null &&
  5715. alternate.expirationTime < renderExpirationTime
  5716. ) {
  5717. alternate.expirationTime = renderExpirationTime;
  5718. }
  5719. scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
  5720. if (list.expirationTime < renderExpirationTime) {
  5721. list.expirationTime = renderExpirationTime;
  5722. } // Since we already found a match, we can stop traversing the
  5723. // dependency list.
  5724. break;
  5725. }
  5726. dependency = dependency.next;
  5727. }
  5728. } else if (fiber.tag === ContextProvider) {
  5729. // Don't scan deeper if this is a matching provider
  5730. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  5731. } else {
  5732. // Traverse down.
  5733. nextFiber = fiber.child;
  5734. }
  5735. if (nextFiber !== null) {
  5736. // Set the return pointer of the child to the work-in-progress fiber.
  5737. nextFiber.return = fiber;
  5738. } else {
  5739. // No child. Traverse to next sibling.
  5740. nextFiber = fiber;
  5741. while (nextFiber !== null) {
  5742. if (nextFiber === workInProgress) {
  5743. // We're back to the root of this subtree. Exit.
  5744. nextFiber = null;
  5745. break;
  5746. }
  5747. var sibling = nextFiber.sibling;
  5748. if (sibling !== null) {
  5749. // Set the return pointer of the sibling to the work-in-progress fiber.
  5750. sibling.return = nextFiber.return;
  5751. nextFiber = sibling;
  5752. break;
  5753. } // No more siblings. Traverse up.
  5754. nextFiber = nextFiber.return;
  5755. }
  5756. }
  5757. fiber = nextFiber;
  5758. }
  5759. }
  5760. function prepareToReadContext(workInProgress, renderExpirationTime) {
  5761. currentlyRenderingFiber = workInProgress;
  5762. lastContextDependency = null;
  5763. lastContextWithAllBitsObserved = null;
  5764. var dependencies = workInProgress.dependencies;
  5765. if (dependencies !== null) {
  5766. var firstContext = dependencies.firstContext;
  5767. if (firstContext !== null) {
  5768. if (dependencies.expirationTime >= renderExpirationTime) {
  5769. // Context list has a pending update. Mark that this fiber performed work.
  5770. markWorkInProgressReceivedUpdate();
  5771. } // Reset the work-in-progress list
  5772. dependencies.firstContext = null;
  5773. }
  5774. }
  5775. }
  5776. function readContext(context, observedBits) {
  5777. {
  5778. // This warning would fire if you read context inside a Hook like useMemo.
  5779. // Unlike the class check below, it's not enforced in production for perf.
  5780. if (isDisallowedContextReadInDEV) {
  5781. error(
  5782. "Context can only be read while React is rendering. " +
  5783. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  5784. "In function components, you can read it directly in the function body, but not " +
  5785. "inside Hooks like useReducer() or useMemo()."
  5786. );
  5787. }
  5788. }
  5789. if (lastContextWithAllBitsObserved === context);
  5790. else if (observedBits === false || observedBits === 0);
  5791. else {
  5792. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  5793. if (
  5794. typeof observedBits !== "number" ||
  5795. observedBits === MAX_SIGNED_31_BIT_INT
  5796. ) {
  5797. // Observe all updates.
  5798. lastContextWithAllBitsObserved = context;
  5799. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  5800. } else {
  5801. resolvedObservedBits = observedBits;
  5802. }
  5803. var contextItem = {
  5804. context: context,
  5805. observedBits: resolvedObservedBits,
  5806. next: null
  5807. };
  5808. if (lastContextDependency === null) {
  5809. if (!(currentlyRenderingFiber !== null)) {
  5810. throw Error(
  5811. "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()."
  5812. );
  5813. } // This is the first dependency for this component. Create a new list.
  5814. lastContextDependency = contextItem;
  5815. currentlyRenderingFiber.dependencies = {
  5816. expirationTime: NoWork,
  5817. firstContext: contextItem,
  5818. responders: null
  5819. };
  5820. } else {
  5821. // Append a new context item.
  5822. lastContextDependency = lastContextDependency.next = contextItem;
  5823. }
  5824. }
  5825. return context._currentValue;
  5826. }
  5827. var UpdateState = 0;
  5828. var ReplaceState = 1;
  5829. var ForceUpdate = 2;
  5830. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  5831. // It should only be read right after calling `processUpdateQueue`, via
  5832. // `checkHasForceUpdateAfterProcessing`.
  5833. var hasForceUpdate = false;
  5834. var didWarnUpdateInsideUpdate;
  5835. var currentlyProcessingQueue;
  5836. {
  5837. didWarnUpdateInsideUpdate = false;
  5838. currentlyProcessingQueue = null;
  5839. }
  5840. function initializeUpdateQueue(fiber) {
  5841. var queue = {
  5842. baseState: fiber.memoizedState,
  5843. baseQueue: null,
  5844. shared: {
  5845. pending: null
  5846. },
  5847. effects: null
  5848. };
  5849. fiber.updateQueue = queue;
  5850. }
  5851. function cloneUpdateQueue(current, workInProgress) {
  5852. // Clone the update queue from current. Unless it's already a clone.
  5853. var queue = workInProgress.updateQueue;
  5854. var currentQueue = current.updateQueue;
  5855. if (queue === currentQueue) {
  5856. var clone = {
  5857. baseState: currentQueue.baseState,
  5858. baseQueue: currentQueue.baseQueue,
  5859. shared: currentQueue.shared,
  5860. effects: currentQueue.effects
  5861. };
  5862. workInProgress.updateQueue = clone;
  5863. }
  5864. }
  5865. function createUpdate(expirationTime, suspenseConfig) {
  5866. var update = {
  5867. expirationTime: expirationTime,
  5868. suspenseConfig: suspenseConfig,
  5869. tag: UpdateState,
  5870. payload: null,
  5871. callback: null,
  5872. next: null
  5873. };
  5874. update.next = update;
  5875. {
  5876. update.priority = getCurrentPriorityLevel();
  5877. }
  5878. return update;
  5879. }
  5880. function enqueueUpdate(fiber, update) {
  5881. var updateQueue = fiber.updateQueue;
  5882. if (updateQueue === null) {
  5883. // Only occurs if the fiber has been unmounted.
  5884. return;
  5885. }
  5886. var sharedQueue = updateQueue.shared;
  5887. var pending = sharedQueue.pending;
  5888. if (pending === null) {
  5889. // This is the first update. Create a circular list.
  5890. update.next = update;
  5891. } else {
  5892. update.next = pending.next;
  5893. pending.next = update;
  5894. }
  5895. sharedQueue.pending = update;
  5896. {
  5897. if (
  5898. currentlyProcessingQueue === sharedQueue &&
  5899. !didWarnUpdateInsideUpdate
  5900. ) {
  5901. error(
  5902. "An update (setState, replaceState, or forceUpdate) was scheduled " +
  5903. "from inside an update function. Update functions should be pure, " +
  5904. "with zero side-effects. Consider using componentDidUpdate or a " +
  5905. "callback."
  5906. );
  5907. didWarnUpdateInsideUpdate = true;
  5908. }
  5909. }
  5910. }
  5911. function enqueueCapturedUpdate(workInProgress, update) {
  5912. var current = workInProgress.alternate;
  5913. if (current !== null) {
  5914. // Ensure the work-in-progress queue is a clone
  5915. cloneUpdateQueue(current, workInProgress);
  5916. } // Captured updates go only on the work-in-progress queue.
  5917. var queue = workInProgress.updateQueue; // Append the update to the end of the list.
  5918. var last = queue.baseQueue;
  5919. if (last === null) {
  5920. queue.baseQueue = update.next = update;
  5921. update.next = update;
  5922. } else {
  5923. update.next = last.next;
  5924. last.next = update;
  5925. }
  5926. }
  5927. function getStateFromUpdate(
  5928. workInProgress,
  5929. queue,
  5930. update,
  5931. prevState,
  5932. nextProps,
  5933. instance
  5934. ) {
  5935. switch (update.tag) {
  5936. case ReplaceState: {
  5937. var payload = update.payload;
  5938. if (typeof payload === "function") {
  5939. // Updater function
  5940. {
  5941. enterDisallowedContextReadInDEV();
  5942. }
  5943. var nextState = payload.call(instance, prevState, nextProps);
  5944. {
  5945. exitDisallowedContextReadInDEV();
  5946. }
  5947. return nextState;
  5948. } // State object
  5949. return payload;
  5950. }
  5951. case CaptureUpdate: {
  5952. workInProgress.effectTag =
  5953. (workInProgress.effectTag & ~ShouldCapture) | DidCapture;
  5954. }
  5955. // Intentional fallthrough
  5956. case UpdateState: {
  5957. var _payload = update.payload;
  5958. var partialState;
  5959. if (typeof _payload === "function") {
  5960. // Updater function
  5961. {
  5962. enterDisallowedContextReadInDEV();
  5963. }
  5964. partialState = _payload.call(instance, prevState, nextProps);
  5965. {
  5966. exitDisallowedContextReadInDEV();
  5967. }
  5968. } else {
  5969. // Partial state object
  5970. partialState = _payload;
  5971. }
  5972. if (partialState === null || partialState === undefined) {
  5973. // Null and undefined are treated as no-ops.
  5974. return prevState;
  5975. } // Merge the partial state and the previous state.
  5976. return Object.assign({}, prevState, partialState);
  5977. }
  5978. case ForceUpdate: {
  5979. hasForceUpdate = true;
  5980. return prevState;
  5981. }
  5982. }
  5983. return prevState;
  5984. }
  5985. function processUpdateQueue(
  5986. workInProgress,
  5987. props,
  5988. instance,
  5989. renderExpirationTime
  5990. ) {
  5991. // This is always non-null on a ClassComponent or HostRoot
  5992. var queue = workInProgress.updateQueue;
  5993. hasForceUpdate = false;
  5994. {
  5995. currentlyProcessingQueue = queue.shared;
  5996. } // The last rebase update that is NOT part of the base state.
  5997. var baseQueue = queue.baseQueue; // The last pending update that hasn't been processed yet.
  5998. var pendingQueue = queue.shared.pending;
  5999. if (pendingQueue !== null) {
  6000. // We have new updates that haven't been processed yet.
  6001. // We'll add them to the base queue.
  6002. if (baseQueue !== null) {
  6003. // Merge the pending queue and the base queue.
  6004. var baseFirst = baseQueue.next;
  6005. var pendingFirst = pendingQueue.next;
  6006. baseQueue.next = pendingFirst;
  6007. pendingQueue.next = baseFirst;
  6008. }
  6009. baseQueue = pendingQueue;
  6010. queue.shared.pending = null; // TODO: Pass `current` as argument
  6011. var current = workInProgress.alternate;
  6012. if (current !== null) {
  6013. var currentQueue = current.updateQueue;
  6014. if (currentQueue !== null) {
  6015. currentQueue.baseQueue = pendingQueue;
  6016. }
  6017. }
  6018. } // These values may change as we process the queue.
  6019. if (baseQueue !== null) {
  6020. var first = baseQueue.next; // Iterate through the list of updates to compute the result.
  6021. var newState = queue.baseState;
  6022. var newExpirationTime = NoWork;
  6023. var newBaseState = null;
  6024. var newBaseQueueFirst = null;
  6025. var newBaseQueueLast = null;
  6026. if (first !== null) {
  6027. var update = first;
  6028. do {
  6029. var updateExpirationTime = update.expirationTime;
  6030. if (updateExpirationTime < renderExpirationTime) {
  6031. // Priority is insufficient. Skip this update. If this is the first
  6032. // skipped update, the previous update/state is the new base
  6033. // update/state.
  6034. var clone = {
  6035. expirationTime: update.expirationTime,
  6036. suspenseConfig: update.suspenseConfig,
  6037. tag: update.tag,
  6038. payload: update.payload,
  6039. callback: update.callback,
  6040. next: null
  6041. };
  6042. if (newBaseQueueLast === null) {
  6043. newBaseQueueFirst = newBaseQueueLast = clone;
  6044. newBaseState = newState;
  6045. } else {
  6046. newBaseQueueLast = newBaseQueueLast.next = clone;
  6047. } // Update the remaining priority in the queue.
  6048. if (updateExpirationTime > newExpirationTime) {
  6049. newExpirationTime = updateExpirationTime;
  6050. }
  6051. } else {
  6052. // This update does have sufficient priority.
  6053. if (newBaseQueueLast !== null) {
  6054. var _clone = {
  6055. expirationTime: Sync,
  6056. // This update is going to be committed so we never want uncommit it.
  6057. suspenseConfig: update.suspenseConfig,
  6058. tag: update.tag,
  6059. payload: update.payload,
  6060. callback: update.callback,
  6061. next: null
  6062. };
  6063. newBaseQueueLast = newBaseQueueLast.next = _clone;
  6064. } // Mark the event time of this update as relevant to this render pass.
  6065. // TODO: This should ideally use the true event time of this update rather than
  6066. // its priority which is a derived and not reverseable value.
  6067. // TODO: We should skip this update if it was already committed but currently
  6068. // we have no way of detecting the difference between a committed and suspended
  6069. // update here.
  6070. markRenderEventTimeAndConfig(
  6071. updateExpirationTime,
  6072. update.suspenseConfig
  6073. ); // Process this update.
  6074. newState = getStateFromUpdate(
  6075. workInProgress,
  6076. queue,
  6077. update,
  6078. newState,
  6079. props,
  6080. instance
  6081. );
  6082. var callback = update.callback;
  6083. if (callback !== null) {
  6084. workInProgress.effectTag |= Callback;
  6085. var effects = queue.effects;
  6086. if (effects === null) {
  6087. queue.effects = [update];
  6088. } else {
  6089. effects.push(update);
  6090. }
  6091. }
  6092. }
  6093. update = update.next;
  6094. if (update === null || update === first) {
  6095. pendingQueue = queue.shared.pending;
  6096. if (pendingQueue === null) {
  6097. break;
  6098. } else {
  6099. // An update was scheduled from inside a reducer. Add the new
  6100. // pending updates to the end of the list and keep processing.
  6101. update = baseQueue.next = pendingQueue.next;
  6102. pendingQueue.next = first;
  6103. queue.baseQueue = baseQueue = pendingQueue;
  6104. queue.shared.pending = null;
  6105. }
  6106. }
  6107. } while (true);
  6108. }
  6109. if (newBaseQueueLast === null) {
  6110. newBaseState = newState;
  6111. } else {
  6112. newBaseQueueLast.next = newBaseQueueFirst;
  6113. }
  6114. queue.baseState = newBaseState;
  6115. queue.baseQueue = newBaseQueueLast; // Set the remaining expiration time to be whatever is remaining in the queue.
  6116. // This should be fine because the only two other things that contribute to
  6117. // expiration time are props and context. We're already in the middle of the
  6118. // begin phase by the time we start processing the queue, so we've already
  6119. // dealt with the props. Context in components that specify
  6120. // shouldComponentUpdate is tricky; but we'll have to account for
  6121. // that regardless.
  6122. markUnprocessedUpdateTime(newExpirationTime);
  6123. workInProgress.expirationTime = newExpirationTime;
  6124. workInProgress.memoizedState = newState;
  6125. }
  6126. {
  6127. currentlyProcessingQueue = null;
  6128. }
  6129. }
  6130. function callCallback(callback, context) {
  6131. if (!(typeof callback === "function")) {
  6132. throw Error(
  6133. "Invalid argument passed as callback. Expected a function. Instead received: " +
  6134. callback
  6135. );
  6136. }
  6137. callback.call(context);
  6138. }
  6139. function resetHasForceUpdateBeforeProcessing() {
  6140. hasForceUpdate = false;
  6141. }
  6142. function checkHasForceUpdateAfterProcessing() {
  6143. return hasForceUpdate;
  6144. }
  6145. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  6146. // Commit the effects
  6147. var effects = finishedQueue.effects;
  6148. finishedQueue.effects = null;
  6149. if (effects !== null) {
  6150. for (var i = 0; i < effects.length; i++) {
  6151. var effect = effects[i];
  6152. var callback = effect.callback;
  6153. if (callback !== null) {
  6154. effect.callback = null;
  6155. callCallback(callback, instance);
  6156. }
  6157. }
  6158. }
  6159. }
  6160. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  6161. function requestCurrentSuspenseConfig() {
  6162. return ReactCurrentBatchConfig.suspense;
  6163. }
  6164. var fakeInternalInstance = {};
  6165. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  6166. // We'll use it to determine whether we need to initialize legacy refs.
  6167. var emptyRefsObject = new React.Component().refs;
  6168. var didWarnAboutStateAssignmentForComponent;
  6169. var didWarnAboutUninitializedState;
  6170. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  6171. var didWarnAboutLegacyLifecyclesAndDerivedState;
  6172. var didWarnAboutUndefinedDerivedState;
  6173. var warnOnUndefinedDerivedState;
  6174. var warnOnInvalidCallback;
  6175. var didWarnAboutDirectlyAssigningPropsToState;
  6176. var didWarnAboutContextTypeAndContextTypes;
  6177. var didWarnAboutInvalidateContextType;
  6178. {
  6179. didWarnAboutStateAssignmentForComponent = new Set();
  6180. didWarnAboutUninitializedState = new Set();
  6181. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  6182. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  6183. didWarnAboutDirectlyAssigningPropsToState = new Set();
  6184. didWarnAboutUndefinedDerivedState = new Set();
  6185. didWarnAboutContextTypeAndContextTypes = new Set();
  6186. didWarnAboutInvalidateContextType = new Set();
  6187. var didWarnOnInvalidCallback = new Set();
  6188. warnOnInvalidCallback = function(callback, callerName) {
  6189. if (callback === null || typeof callback === "function") {
  6190. return;
  6191. }
  6192. var key = callerName + "_" + callback;
  6193. if (!didWarnOnInvalidCallback.has(key)) {
  6194. didWarnOnInvalidCallback.add(key);
  6195. error(
  6196. "%s(...): Expected the last optional `callback` argument to be a " +
  6197. "function. Instead received: %s.",
  6198. callerName,
  6199. callback
  6200. );
  6201. }
  6202. };
  6203. warnOnUndefinedDerivedState = function(type, partialState) {
  6204. if (partialState === undefined) {
  6205. var componentName = getComponentName(type) || "Component";
  6206. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  6207. didWarnAboutUndefinedDerivedState.add(componentName);
  6208. error(
  6209. "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " +
  6210. "You have returned undefined.",
  6211. componentName
  6212. );
  6213. }
  6214. }
  6215. }; // This is so gross but it's at least non-critical and can be removed if
  6216. // it causes problems. This is meant to give a nicer error message for
  6217. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  6218. // ...)) which otherwise throws a "_processChildContext is not a function"
  6219. // exception.
  6220. Object.defineProperty(fakeInternalInstance, "_processChildContext", {
  6221. enumerable: false,
  6222. value: function() {
  6223. {
  6224. throw Error(
  6225. "_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)."
  6226. );
  6227. }
  6228. }
  6229. });
  6230. Object.freeze(fakeInternalInstance);
  6231. }
  6232. function applyDerivedStateFromProps(
  6233. workInProgress,
  6234. ctor,
  6235. getDerivedStateFromProps,
  6236. nextProps
  6237. ) {
  6238. var prevState = workInProgress.memoizedState;
  6239. var partialState = getDerivedStateFromProps(nextProps, prevState);
  6240. {
  6241. warnOnUndefinedDerivedState(ctor, partialState);
  6242. } // Merge the partial state and the previous state.
  6243. var memoizedState =
  6244. partialState === null || partialState === undefined
  6245. ? prevState
  6246. : Object.assign({}, prevState, partialState);
  6247. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  6248. // base state.
  6249. if (workInProgress.expirationTime === NoWork) {
  6250. // Queue is always non-null for classes
  6251. var updateQueue = workInProgress.updateQueue;
  6252. updateQueue.baseState = memoizedState;
  6253. }
  6254. }
  6255. var classComponentUpdater = {
  6256. isMounted: isMounted,
  6257. enqueueSetState: function(inst, payload, callback) {
  6258. var fiber = get(inst);
  6259. var currentTime = requestCurrentTimeForUpdate();
  6260. var suspenseConfig = requestCurrentSuspenseConfig();
  6261. var expirationTime = computeExpirationForFiber(
  6262. currentTime,
  6263. fiber,
  6264. suspenseConfig
  6265. );
  6266. var update = createUpdate(expirationTime, suspenseConfig);
  6267. update.payload = payload;
  6268. if (callback !== undefined && callback !== null) {
  6269. {
  6270. warnOnInvalidCallback(callback, "setState");
  6271. }
  6272. update.callback = callback;
  6273. }
  6274. enqueueUpdate(fiber, update);
  6275. scheduleWork(fiber, expirationTime);
  6276. },
  6277. enqueueReplaceState: function(inst, payload, callback) {
  6278. var fiber = get(inst);
  6279. var currentTime = requestCurrentTimeForUpdate();
  6280. var suspenseConfig = requestCurrentSuspenseConfig();
  6281. var expirationTime = computeExpirationForFiber(
  6282. currentTime,
  6283. fiber,
  6284. suspenseConfig
  6285. );
  6286. var update = createUpdate(expirationTime, suspenseConfig);
  6287. update.tag = ReplaceState;
  6288. update.payload = payload;
  6289. if (callback !== undefined && callback !== null) {
  6290. {
  6291. warnOnInvalidCallback(callback, "replaceState");
  6292. }
  6293. update.callback = callback;
  6294. }
  6295. enqueueUpdate(fiber, update);
  6296. scheduleWork(fiber, expirationTime);
  6297. },
  6298. enqueueForceUpdate: function(inst, callback) {
  6299. var fiber = get(inst);
  6300. var currentTime = requestCurrentTimeForUpdate();
  6301. var suspenseConfig = requestCurrentSuspenseConfig();
  6302. var expirationTime = computeExpirationForFiber(
  6303. currentTime,
  6304. fiber,
  6305. suspenseConfig
  6306. );
  6307. var update = createUpdate(expirationTime, suspenseConfig);
  6308. update.tag = ForceUpdate;
  6309. if (callback !== undefined && callback !== null) {
  6310. {
  6311. warnOnInvalidCallback(callback, "forceUpdate");
  6312. }
  6313. update.callback = callback;
  6314. }
  6315. enqueueUpdate(fiber, update);
  6316. scheduleWork(fiber, expirationTime);
  6317. }
  6318. };
  6319. function checkShouldComponentUpdate(
  6320. workInProgress,
  6321. ctor,
  6322. oldProps,
  6323. newProps,
  6324. oldState,
  6325. newState,
  6326. nextContext
  6327. ) {
  6328. var instance = workInProgress.stateNode;
  6329. if (typeof instance.shouldComponentUpdate === "function") {
  6330. startPhaseTimer(workInProgress, "shouldComponentUpdate");
  6331. var shouldUpdate = instance.shouldComponentUpdate(
  6332. newProps,
  6333. newState,
  6334. nextContext
  6335. );
  6336. stopPhaseTimer();
  6337. {
  6338. if (shouldUpdate === undefined) {
  6339. error(
  6340. "%s.shouldComponentUpdate(): Returned undefined instead of a " +
  6341. "boolean value. Make sure to return true or false.",
  6342. getComponentName(ctor) || "Component"
  6343. );
  6344. }
  6345. }
  6346. return shouldUpdate;
  6347. }
  6348. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  6349. return (
  6350. !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState)
  6351. );
  6352. }
  6353. return true;
  6354. }
  6355. function checkClassInstance(workInProgress, ctor, newProps) {
  6356. var instance = workInProgress.stateNode;
  6357. {
  6358. var name = getComponentName(ctor) || "Component";
  6359. var renderPresent = instance.render;
  6360. if (!renderPresent) {
  6361. if (ctor.prototype && typeof ctor.prototype.render === "function") {
  6362. error(
  6363. "%s(...): No `render` method found on the returned component " +
  6364. "instance: did you accidentally return an object from the constructor?",
  6365. name
  6366. );
  6367. } else {
  6368. error(
  6369. "%s(...): No `render` method found on the returned component " +
  6370. "instance: you may have forgotten to define `render`.",
  6371. name
  6372. );
  6373. }
  6374. }
  6375. if (
  6376. instance.getInitialState &&
  6377. !instance.getInitialState.isReactClassApproved &&
  6378. !instance.state
  6379. ) {
  6380. error(
  6381. "getInitialState was defined on %s, a plain JavaScript class. " +
  6382. "This is only supported for classes created using React.createClass. " +
  6383. "Did you mean to define a state property instead?",
  6384. name
  6385. );
  6386. }
  6387. if (
  6388. instance.getDefaultProps &&
  6389. !instance.getDefaultProps.isReactClassApproved
  6390. ) {
  6391. error(
  6392. "getDefaultProps was defined on %s, a plain JavaScript class. " +
  6393. "This is only supported for classes created using React.createClass. " +
  6394. "Use a static property to define defaultProps instead.",
  6395. name
  6396. );
  6397. }
  6398. if (instance.propTypes) {
  6399. error(
  6400. "propTypes was defined as an instance property on %s. Use a static " +
  6401. "property to define propTypes instead.",
  6402. name
  6403. );
  6404. }
  6405. if (instance.contextType) {
  6406. error(
  6407. "contextType was defined as an instance property on %s. Use a static " +
  6408. "property to define contextType instead.",
  6409. name
  6410. );
  6411. }
  6412. {
  6413. if (instance.contextTypes) {
  6414. error(
  6415. "contextTypes was defined as an instance property on %s. Use a static " +
  6416. "property to define contextTypes instead.",
  6417. name
  6418. );
  6419. }
  6420. if (
  6421. ctor.contextType &&
  6422. ctor.contextTypes &&
  6423. !didWarnAboutContextTypeAndContextTypes.has(ctor)
  6424. ) {
  6425. didWarnAboutContextTypeAndContextTypes.add(ctor);
  6426. error(
  6427. "%s declares both contextTypes and contextType static properties. " +
  6428. "The legacy contextTypes property will be ignored.",
  6429. name
  6430. );
  6431. }
  6432. }
  6433. if (typeof instance.componentShouldUpdate === "function") {
  6434. error(
  6435. "%s has a method called " +
  6436. "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " +
  6437. "The name is phrased as a question because the function is " +
  6438. "expected to return a value.",
  6439. name
  6440. );
  6441. }
  6442. if (
  6443. ctor.prototype &&
  6444. ctor.prototype.isPureReactComponent &&
  6445. typeof instance.shouldComponentUpdate !== "undefined"
  6446. ) {
  6447. error(
  6448. "%s has a method called shouldComponentUpdate(). " +
  6449. "shouldComponentUpdate should not be used when extending React.PureComponent. " +
  6450. "Please extend React.Component if shouldComponentUpdate is used.",
  6451. getComponentName(ctor) || "A pure component"
  6452. );
  6453. }
  6454. if (typeof instance.componentDidUnmount === "function") {
  6455. error(
  6456. "%s has a method called " +
  6457. "componentDidUnmount(). But there is no such lifecycle method. " +
  6458. "Did you mean componentWillUnmount()?",
  6459. name
  6460. );
  6461. }
  6462. if (typeof instance.componentDidReceiveProps === "function") {
  6463. error(
  6464. "%s has a method called " +
  6465. "componentDidReceiveProps(). But there is no such lifecycle method. " +
  6466. "If you meant to update the state in response to changing props, " +
  6467. "use componentWillReceiveProps(). If you meant to fetch data or " +
  6468. "run side-effects or mutations after React has updated the UI, use componentDidUpdate().",
  6469. name
  6470. );
  6471. }
  6472. if (typeof instance.componentWillRecieveProps === "function") {
  6473. error(
  6474. "%s has a method called " +
  6475. "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?",
  6476. name
  6477. );
  6478. }
  6479. if (typeof instance.UNSAFE_componentWillRecieveProps === "function") {
  6480. error(
  6481. "%s has a method called " +
  6482. "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?",
  6483. name
  6484. );
  6485. }
  6486. var hasMutatedProps = instance.props !== newProps;
  6487. if (instance.props !== undefined && hasMutatedProps) {
  6488. error(
  6489. "%s(...): When calling super() in `%s`, make sure to pass " +
  6490. "up the same props that your component's constructor was passed.",
  6491. name,
  6492. name
  6493. );
  6494. }
  6495. if (instance.defaultProps) {
  6496. error(
  6497. "Setting defaultProps as an instance property on %s is not supported and will be ignored." +
  6498. " Instead, define defaultProps as a static property on %s.",
  6499. name,
  6500. name
  6501. );
  6502. }
  6503. if (
  6504. typeof instance.getSnapshotBeforeUpdate === "function" &&
  6505. typeof instance.componentDidUpdate !== "function" &&
  6506. !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)
  6507. ) {
  6508. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  6509. error(
  6510. "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " +
  6511. "This component defines getSnapshotBeforeUpdate() only.",
  6512. getComponentName(ctor)
  6513. );
  6514. }
  6515. if (typeof instance.getDerivedStateFromProps === "function") {
  6516. error(
  6517. "%s: getDerivedStateFromProps() is defined as an instance method " +
  6518. "and will be ignored. Instead, declare it as a static method.",
  6519. name
  6520. );
  6521. }
  6522. if (typeof instance.getDerivedStateFromError === "function") {
  6523. error(
  6524. "%s: getDerivedStateFromError() is defined as an instance method " +
  6525. "and will be ignored. Instead, declare it as a static method.",
  6526. name
  6527. );
  6528. }
  6529. if (typeof ctor.getSnapshotBeforeUpdate === "function") {
  6530. error(
  6531. "%s: getSnapshotBeforeUpdate() is defined as a static method " +
  6532. "and will be ignored. Instead, declare it as an instance method.",
  6533. name
  6534. );
  6535. }
  6536. var _state = instance.state;
  6537. if (_state && (typeof _state !== "object" || isArray(_state))) {
  6538. error("%s.state: must be set to an object or null", name);
  6539. }
  6540. if (
  6541. typeof instance.getChildContext === "function" &&
  6542. typeof ctor.childContextTypes !== "object"
  6543. ) {
  6544. error(
  6545. "%s.getChildContext(): childContextTypes must be defined in order to " +
  6546. "use getChildContext().",
  6547. name
  6548. );
  6549. }
  6550. }
  6551. }
  6552. function adoptClassInstance(workInProgress, instance) {
  6553. instance.updater = classComponentUpdater;
  6554. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  6555. set(instance, workInProgress);
  6556. {
  6557. instance._reactInternalInstance = fakeInternalInstance;
  6558. }
  6559. }
  6560. function constructClassInstance(workInProgress, ctor, props) {
  6561. var isLegacyContextConsumer = false;
  6562. var unmaskedContext = emptyContextObject;
  6563. var context = emptyContextObject;
  6564. var contextType = ctor.contextType;
  6565. {
  6566. if ("contextType" in ctor) {
  6567. var isValid = // Allow null for conditional declaration
  6568. contextType === null ||
  6569. (contextType !== undefined &&
  6570. contextType.$$typeof === REACT_CONTEXT_TYPE &&
  6571. contextType._context === undefined); // Not a <Context.Consumer>
  6572. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  6573. didWarnAboutInvalidateContextType.add(ctor);
  6574. var addendum = "";
  6575. if (contextType === undefined) {
  6576. addendum =
  6577. " However, it is set to undefined. " +
  6578. "This can be caused by a typo or by mixing up named and default imports. " +
  6579. "This can also happen due to a circular dependency, so " +
  6580. "try moving the createContext() call to a separate file.";
  6581. } else if (typeof contextType !== "object") {
  6582. addendum = " However, it is set to a " + typeof contextType + ".";
  6583. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  6584. addendum = " Did you accidentally pass the Context.Provider instead?";
  6585. } else if (contextType._context !== undefined) {
  6586. // <Context.Consumer>
  6587. addendum = " Did you accidentally pass the Context.Consumer instead?";
  6588. } else {
  6589. addendum =
  6590. " However, it is set to an object with keys {" +
  6591. Object.keys(contextType).join(", ") +
  6592. "}.";
  6593. }
  6594. error(
  6595. "%s defines an invalid contextType. " +
  6596. "contextType should point to the Context object returned by React.createContext().%s",
  6597. getComponentName(ctor) || "Component",
  6598. addendum
  6599. );
  6600. }
  6601. }
  6602. }
  6603. if (typeof contextType === "object" && contextType !== null) {
  6604. context = readContext(contextType);
  6605. } else {
  6606. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6607. var contextTypes = ctor.contextTypes;
  6608. isLegacyContextConsumer =
  6609. contextTypes !== null && contextTypes !== undefined;
  6610. context = isLegacyContextConsumer
  6611. ? getMaskedContext(workInProgress, unmaskedContext)
  6612. : emptyContextObject;
  6613. } // Instantiate twice to help detect side-effects.
  6614. var instance = new ctor(props, context);
  6615. var state = (workInProgress.memoizedState =
  6616. instance.state !== null && instance.state !== undefined
  6617. ? instance.state
  6618. : null);
  6619. adoptClassInstance(workInProgress, instance);
  6620. {
  6621. if (typeof ctor.getDerivedStateFromProps === "function" && state === null) {
  6622. var componentName = getComponentName(ctor) || "Component";
  6623. if (!didWarnAboutUninitializedState.has(componentName)) {
  6624. didWarnAboutUninitializedState.add(componentName);
  6625. error(
  6626. "`%s` uses `getDerivedStateFromProps` but its initial state is " +
  6627. "%s. This is not recommended. Instead, define the initial state by " +
  6628. "assigning an object to `this.state` in the constructor of `%s`. " +
  6629. "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.",
  6630. componentName,
  6631. instance.state === null ? "null" : "undefined",
  6632. componentName
  6633. );
  6634. }
  6635. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  6636. // Warn about these lifecycles if they are present.
  6637. // Don't warn about react-lifecycles-compat polyfilled methods though.
  6638. if (
  6639. typeof ctor.getDerivedStateFromProps === "function" ||
  6640. typeof instance.getSnapshotBeforeUpdate === "function"
  6641. ) {
  6642. var foundWillMountName = null;
  6643. var foundWillReceivePropsName = null;
  6644. var foundWillUpdateName = null;
  6645. if (
  6646. typeof instance.componentWillMount === "function" &&
  6647. instance.componentWillMount.__suppressDeprecationWarning !== true
  6648. ) {
  6649. foundWillMountName = "componentWillMount";
  6650. } else if (typeof instance.UNSAFE_componentWillMount === "function") {
  6651. foundWillMountName = "UNSAFE_componentWillMount";
  6652. }
  6653. if (
  6654. typeof instance.componentWillReceiveProps === "function" &&
  6655. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  6656. ) {
  6657. foundWillReceivePropsName = "componentWillReceiveProps";
  6658. } else if (
  6659. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  6660. ) {
  6661. foundWillReceivePropsName = "UNSAFE_componentWillReceiveProps";
  6662. }
  6663. if (
  6664. typeof instance.componentWillUpdate === "function" &&
  6665. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  6666. ) {
  6667. foundWillUpdateName = "componentWillUpdate";
  6668. } else if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  6669. foundWillUpdateName = "UNSAFE_componentWillUpdate";
  6670. }
  6671. if (
  6672. foundWillMountName !== null ||
  6673. foundWillReceivePropsName !== null ||
  6674. foundWillUpdateName !== null
  6675. ) {
  6676. var _componentName = getComponentName(ctor) || "Component";
  6677. var newApiName =
  6678. typeof ctor.getDerivedStateFromProps === "function"
  6679. ? "getDerivedStateFromProps()"
  6680. : "getSnapshotBeforeUpdate()";
  6681. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  6682. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  6683. error(
  6684. "Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n" +
  6685. "%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n" +
  6686. "The above lifecycles should be removed. Learn more about this warning here:\n" +
  6687. "https://fb.me/react-unsafe-component-lifecycles",
  6688. _componentName,
  6689. newApiName,
  6690. foundWillMountName !== null ? "\n " + foundWillMountName : "",
  6691. foundWillReceivePropsName !== null
  6692. ? "\n " + foundWillReceivePropsName
  6693. : "",
  6694. foundWillUpdateName !== null ? "\n " + foundWillUpdateName : ""
  6695. );
  6696. }
  6697. }
  6698. }
  6699. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  6700. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  6701. if (isLegacyContextConsumer) {
  6702. cacheContext(workInProgress, unmaskedContext, context);
  6703. }
  6704. return instance;
  6705. }
  6706. function callComponentWillMount(workInProgress, instance) {
  6707. startPhaseTimer(workInProgress, "componentWillMount");
  6708. var oldState = instance.state;
  6709. if (typeof instance.componentWillMount === "function") {
  6710. instance.componentWillMount();
  6711. }
  6712. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6713. instance.UNSAFE_componentWillMount();
  6714. }
  6715. stopPhaseTimer();
  6716. if (oldState !== instance.state) {
  6717. {
  6718. error(
  6719. "%s.componentWillMount(): Assigning directly to this.state is " +
  6720. "deprecated (except inside a component's " +
  6721. "constructor). Use setState instead.",
  6722. getComponentName(workInProgress.type) || "Component"
  6723. );
  6724. }
  6725. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6726. }
  6727. }
  6728. function callComponentWillReceiveProps(
  6729. workInProgress,
  6730. instance,
  6731. newProps,
  6732. nextContext
  6733. ) {
  6734. var oldState = instance.state;
  6735. startPhaseTimer(workInProgress, "componentWillReceiveProps");
  6736. if (typeof instance.componentWillReceiveProps === "function") {
  6737. instance.componentWillReceiveProps(newProps, nextContext);
  6738. }
  6739. if (typeof instance.UNSAFE_componentWillReceiveProps === "function") {
  6740. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  6741. }
  6742. stopPhaseTimer();
  6743. if (instance.state !== oldState) {
  6744. {
  6745. var componentName = getComponentName(workInProgress.type) || "Component";
  6746. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  6747. didWarnAboutStateAssignmentForComponent.add(componentName);
  6748. error(
  6749. "%s.componentWillReceiveProps(): Assigning directly to " +
  6750. "this.state is deprecated (except inside a component's " +
  6751. "constructor). Use setState instead.",
  6752. componentName
  6753. );
  6754. }
  6755. }
  6756. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6757. }
  6758. } // Invokes the mount life-cycles on a previously never rendered instance.
  6759. function mountClassInstance(
  6760. workInProgress,
  6761. ctor,
  6762. newProps,
  6763. renderExpirationTime
  6764. ) {
  6765. {
  6766. checkClassInstance(workInProgress, ctor, newProps);
  6767. }
  6768. var instance = workInProgress.stateNode;
  6769. instance.props = newProps;
  6770. instance.state = workInProgress.memoizedState;
  6771. instance.refs = emptyRefsObject;
  6772. initializeUpdateQueue(workInProgress);
  6773. var contextType = ctor.contextType;
  6774. if (typeof contextType === "object" && contextType !== null) {
  6775. instance.context = readContext(contextType);
  6776. } else {
  6777. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6778. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  6779. }
  6780. {
  6781. if (instance.state === newProps) {
  6782. var componentName = getComponentName(ctor) || "Component";
  6783. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  6784. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  6785. error(
  6786. "%s: It is not recommended to assign props directly to state " +
  6787. "because updates to props won't be reflected in state. " +
  6788. "In most cases, it is better to use props directly.",
  6789. componentName
  6790. );
  6791. }
  6792. }
  6793. if (workInProgress.mode & StrictMode) {
  6794. ReactStrictModeWarnings.recordLegacyContextWarning(
  6795. workInProgress,
  6796. instance
  6797. );
  6798. }
  6799. {
  6800. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(
  6801. workInProgress,
  6802. instance
  6803. );
  6804. }
  6805. }
  6806. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6807. instance.state = workInProgress.memoizedState;
  6808. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6809. if (typeof getDerivedStateFromProps === "function") {
  6810. applyDerivedStateFromProps(
  6811. workInProgress,
  6812. ctor,
  6813. getDerivedStateFromProps,
  6814. newProps
  6815. );
  6816. instance.state = workInProgress.memoizedState;
  6817. } // In order to support react-lifecycles-compat polyfilled components,
  6818. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6819. if (
  6820. typeof ctor.getDerivedStateFromProps !== "function" &&
  6821. typeof instance.getSnapshotBeforeUpdate !== "function" &&
  6822. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6823. typeof instance.componentWillMount === "function")
  6824. ) {
  6825. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  6826. // process them now.
  6827. processUpdateQueue(
  6828. workInProgress,
  6829. newProps,
  6830. instance,
  6831. renderExpirationTime
  6832. );
  6833. instance.state = workInProgress.memoizedState;
  6834. }
  6835. if (typeof instance.componentDidMount === "function") {
  6836. workInProgress.effectTag |= Update;
  6837. }
  6838. }
  6839. function resumeMountClassInstance(
  6840. workInProgress,
  6841. ctor,
  6842. newProps,
  6843. renderExpirationTime
  6844. ) {
  6845. var instance = workInProgress.stateNode;
  6846. var oldProps = workInProgress.memoizedProps;
  6847. instance.props = oldProps;
  6848. var oldContext = instance.context;
  6849. var contextType = ctor.contextType;
  6850. var nextContext = emptyContextObject;
  6851. if (typeof contextType === "object" && contextType !== null) {
  6852. nextContext = readContext(contextType);
  6853. } else {
  6854. var nextLegacyUnmaskedContext = getUnmaskedContext(
  6855. workInProgress,
  6856. ctor,
  6857. true
  6858. );
  6859. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  6860. }
  6861. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6862. var hasNewLifecycles =
  6863. typeof getDerivedStateFromProps === "function" ||
  6864. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  6865. // ever the previously attempted to render - not the "current". However,
  6866. // during componentDidUpdate we pass the "current" props.
  6867. // In order to support react-lifecycles-compat polyfilled components,
  6868. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6869. if (
  6870. !hasNewLifecycles &&
  6871. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  6872. typeof instance.componentWillReceiveProps === "function")
  6873. ) {
  6874. if (oldProps !== newProps || oldContext !== nextContext) {
  6875. callComponentWillReceiveProps(
  6876. workInProgress,
  6877. instance,
  6878. newProps,
  6879. nextContext
  6880. );
  6881. }
  6882. }
  6883. resetHasForceUpdateBeforeProcessing();
  6884. var oldState = workInProgress.memoizedState;
  6885. var newState = (instance.state = oldState);
  6886. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6887. newState = workInProgress.memoizedState;
  6888. if (
  6889. oldProps === newProps &&
  6890. oldState === newState &&
  6891. !hasContextChanged() &&
  6892. !checkHasForceUpdateAfterProcessing()
  6893. ) {
  6894. // If an update was already in progress, we should schedule an Update
  6895. // effect even though we're bailing out, so that cWU/cDU are called.
  6896. if (typeof instance.componentDidMount === "function") {
  6897. workInProgress.effectTag |= Update;
  6898. }
  6899. return false;
  6900. }
  6901. if (typeof getDerivedStateFromProps === "function") {
  6902. applyDerivedStateFromProps(
  6903. workInProgress,
  6904. ctor,
  6905. getDerivedStateFromProps,
  6906. newProps
  6907. );
  6908. newState = workInProgress.memoizedState;
  6909. }
  6910. var shouldUpdate =
  6911. checkHasForceUpdateAfterProcessing() ||
  6912. checkShouldComponentUpdate(
  6913. workInProgress,
  6914. ctor,
  6915. oldProps,
  6916. newProps,
  6917. oldState,
  6918. newState,
  6919. nextContext
  6920. );
  6921. if (shouldUpdate) {
  6922. // In order to support react-lifecycles-compat polyfilled components,
  6923. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6924. if (
  6925. !hasNewLifecycles &&
  6926. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6927. typeof instance.componentWillMount === "function")
  6928. ) {
  6929. startPhaseTimer(workInProgress, "componentWillMount");
  6930. if (typeof instance.componentWillMount === "function") {
  6931. instance.componentWillMount();
  6932. }
  6933. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6934. instance.UNSAFE_componentWillMount();
  6935. }
  6936. stopPhaseTimer();
  6937. }
  6938. if (typeof instance.componentDidMount === "function") {
  6939. workInProgress.effectTag |= Update;
  6940. }
  6941. } else {
  6942. // If an update was already in progress, we should schedule an Update
  6943. // effect even though we're bailing out, so that cWU/cDU are called.
  6944. if (typeof instance.componentDidMount === "function") {
  6945. workInProgress.effectTag |= Update;
  6946. } // If shouldComponentUpdate returned false, we should still update the
  6947. // memoized state to indicate that this work can be reused.
  6948. workInProgress.memoizedProps = newProps;
  6949. workInProgress.memoizedState = newState;
  6950. } // Update the existing instance's state, props, and context pointers even
  6951. // if shouldComponentUpdate returns false.
  6952. instance.props = newProps;
  6953. instance.state = newState;
  6954. instance.context = nextContext;
  6955. return shouldUpdate;
  6956. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  6957. function updateClassInstance(
  6958. current,
  6959. workInProgress,
  6960. ctor,
  6961. newProps,
  6962. renderExpirationTime
  6963. ) {
  6964. var instance = workInProgress.stateNode;
  6965. cloneUpdateQueue(current, workInProgress);
  6966. var oldProps = workInProgress.memoizedProps;
  6967. instance.props =
  6968. workInProgress.type === workInProgress.elementType
  6969. ? oldProps
  6970. : resolveDefaultProps(workInProgress.type, oldProps);
  6971. var oldContext = instance.context;
  6972. var contextType = ctor.contextType;
  6973. var nextContext = emptyContextObject;
  6974. if (typeof contextType === "object" && contextType !== null) {
  6975. nextContext = readContext(contextType);
  6976. } else {
  6977. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6978. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  6979. }
  6980. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6981. var hasNewLifecycles =
  6982. typeof getDerivedStateFromProps === "function" ||
  6983. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  6984. // ever the previously attempted to render - not the "current". However,
  6985. // during componentDidUpdate we pass the "current" props.
  6986. // In order to support react-lifecycles-compat polyfilled components,
  6987. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6988. if (
  6989. !hasNewLifecycles &&
  6990. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  6991. typeof instance.componentWillReceiveProps === "function")
  6992. ) {
  6993. if (oldProps !== newProps || oldContext !== nextContext) {
  6994. callComponentWillReceiveProps(
  6995. workInProgress,
  6996. instance,
  6997. newProps,
  6998. nextContext
  6999. );
  7000. }
  7001. }
  7002. resetHasForceUpdateBeforeProcessing();
  7003. var oldState = workInProgress.memoizedState;
  7004. var newState = (instance.state = oldState);
  7005. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  7006. newState = workInProgress.memoizedState;
  7007. if (
  7008. oldProps === newProps &&
  7009. oldState === newState &&
  7010. !hasContextChanged() &&
  7011. !checkHasForceUpdateAfterProcessing()
  7012. ) {
  7013. // If an update was already in progress, we should schedule an Update
  7014. // effect even though we're bailing out, so that cWU/cDU are called.
  7015. if (typeof instance.componentDidUpdate === "function") {
  7016. if (
  7017. oldProps !== current.memoizedProps ||
  7018. oldState !== current.memoizedState
  7019. ) {
  7020. workInProgress.effectTag |= Update;
  7021. }
  7022. }
  7023. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  7024. if (
  7025. oldProps !== current.memoizedProps ||
  7026. oldState !== current.memoizedState
  7027. ) {
  7028. workInProgress.effectTag |= Snapshot;
  7029. }
  7030. }
  7031. return false;
  7032. }
  7033. if (typeof getDerivedStateFromProps === "function") {
  7034. applyDerivedStateFromProps(
  7035. workInProgress,
  7036. ctor,
  7037. getDerivedStateFromProps,
  7038. newProps
  7039. );
  7040. newState = workInProgress.memoizedState;
  7041. }
  7042. var shouldUpdate =
  7043. checkHasForceUpdateAfterProcessing() ||
  7044. checkShouldComponentUpdate(
  7045. workInProgress,
  7046. ctor,
  7047. oldProps,
  7048. newProps,
  7049. oldState,
  7050. newState,
  7051. nextContext
  7052. );
  7053. if (shouldUpdate) {
  7054. // In order to support react-lifecycles-compat polyfilled components,
  7055. // Unsafe lifecycles should not be invoked for components using the new APIs.
  7056. if (
  7057. !hasNewLifecycles &&
  7058. (typeof instance.UNSAFE_componentWillUpdate === "function" ||
  7059. typeof instance.componentWillUpdate === "function")
  7060. ) {
  7061. startPhaseTimer(workInProgress, "componentWillUpdate");
  7062. if (typeof instance.componentWillUpdate === "function") {
  7063. instance.componentWillUpdate(newProps, newState, nextContext);
  7064. }
  7065. if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  7066. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  7067. }
  7068. stopPhaseTimer();
  7069. }
  7070. if (typeof instance.componentDidUpdate === "function") {
  7071. workInProgress.effectTag |= Update;
  7072. }
  7073. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  7074. workInProgress.effectTag |= Snapshot;
  7075. }
  7076. } else {
  7077. // If an update was already in progress, we should schedule an Update
  7078. // effect even though we're bailing out, so that cWU/cDU are called.
  7079. if (typeof instance.componentDidUpdate === "function") {
  7080. if (
  7081. oldProps !== current.memoizedProps ||
  7082. oldState !== current.memoizedState
  7083. ) {
  7084. workInProgress.effectTag |= Update;
  7085. }
  7086. }
  7087. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  7088. if (
  7089. oldProps !== current.memoizedProps ||
  7090. oldState !== current.memoizedState
  7091. ) {
  7092. workInProgress.effectTag |= Snapshot;
  7093. }
  7094. } // If shouldComponentUpdate returned false, we should still update the
  7095. // memoized props/state to indicate that this work can be reused.
  7096. workInProgress.memoizedProps = newProps;
  7097. workInProgress.memoizedState = newState;
  7098. } // Update the existing instance's state, props, and context pointers even
  7099. // if shouldComponentUpdate returns false.
  7100. instance.props = newProps;
  7101. instance.state = newState;
  7102. instance.context = nextContext;
  7103. return shouldUpdate;
  7104. }
  7105. var didWarnAboutMaps;
  7106. var didWarnAboutGenerators;
  7107. var didWarnAboutStringRefs;
  7108. var ownerHasKeyUseWarning;
  7109. var ownerHasFunctionTypeWarning;
  7110. var warnForMissingKey = function(child) {};
  7111. {
  7112. didWarnAboutMaps = false;
  7113. didWarnAboutGenerators = false;
  7114. didWarnAboutStringRefs = {};
  7115. /**
  7116. * Warn if there's no key explicitly set on dynamic arrays of children or
  7117. * object keys are not valid. This allows us to keep track of children between
  7118. * updates.
  7119. */
  7120. ownerHasKeyUseWarning = {};
  7121. ownerHasFunctionTypeWarning = {};
  7122. warnForMissingKey = function(child) {
  7123. if (child === null || typeof child !== "object") {
  7124. return;
  7125. }
  7126. if (!child._store || child._store.validated || child.key != null) {
  7127. return;
  7128. }
  7129. if (!(typeof child._store === "object")) {
  7130. throw Error(
  7131. "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue."
  7132. );
  7133. }
  7134. child._store.validated = true;
  7135. var currentComponentErrorInfo =
  7136. "Each child in a list should have a unique " +
  7137. '"key" prop. See https://fb.me/react-warning-keys for ' +
  7138. "more information." +
  7139. getCurrentFiberStackInDev();
  7140. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  7141. return;
  7142. }
  7143. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  7144. error(
  7145. "Each child in a list should have a unique " +
  7146. '"key" prop. See https://fb.me/react-warning-keys for ' +
  7147. "more information."
  7148. );
  7149. };
  7150. }
  7151. var isArray$1 = Array.isArray;
  7152. function coerceRef(returnFiber, current, element) {
  7153. var mixedRef = element.ref;
  7154. if (
  7155. mixedRef !== null &&
  7156. typeof mixedRef !== "function" &&
  7157. typeof mixedRef !== "object"
  7158. ) {
  7159. {
  7160. // TODO: Clean this up once we turn on the string ref warning for
  7161. // everyone, because the strict mode case will no longer be relevant
  7162. if (
  7163. (returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  7164. // because these cannot be automatically converted to an arrow function
  7165. // using a codemod. Therefore, we don't have to warn about string refs again.
  7166. !(
  7167. element._owner &&
  7168. element._self &&
  7169. element._owner.stateNode !== element._self
  7170. )
  7171. ) {
  7172. var componentName = getComponentName(returnFiber.type) || "Component";
  7173. if (!didWarnAboutStringRefs[componentName]) {
  7174. {
  7175. error(
  7176. 'A string ref, "%s", has been found within a strict mode tree. ' +
  7177. "String refs are a source of potential bugs and should be avoided. " +
  7178. "We recommend using useRef() or createRef() instead. " +
  7179. "Learn more about using refs safely here: " +
  7180. "https://fb.me/react-strict-mode-string-ref%s",
  7181. mixedRef,
  7182. getStackByFiberInDevAndProd(returnFiber)
  7183. );
  7184. }
  7185. didWarnAboutStringRefs[componentName] = true;
  7186. }
  7187. }
  7188. }
  7189. if (element._owner) {
  7190. var owner = element._owner;
  7191. var inst;
  7192. if (owner) {
  7193. var ownerFiber = owner;
  7194. if (!(ownerFiber.tag === ClassComponent)) {
  7195. throw Error(
  7196. "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"
  7197. );
  7198. }
  7199. inst = ownerFiber.stateNode;
  7200. }
  7201. if (!inst) {
  7202. throw Error(
  7203. "Missing owner for string ref " +
  7204. mixedRef +
  7205. ". This error is likely caused by a bug in React. Please file an issue."
  7206. );
  7207. }
  7208. var stringRef = "" + mixedRef; // Check if previous string ref matches new string ref
  7209. if (
  7210. current !== null &&
  7211. current.ref !== null &&
  7212. typeof current.ref === "function" &&
  7213. current.ref._stringRef === stringRef
  7214. ) {
  7215. return current.ref;
  7216. }
  7217. var ref = function(value) {
  7218. var refs = inst.refs;
  7219. if (refs === emptyRefsObject) {
  7220. // This is a lazy pooled frozen object, so we need to initialize.
  7221. refs = inst.refs = {};
  7222. }
  7223. if (value === null) {
  7224. delete refs[stringRef];
  7225. } else {
  7226. refs[stringRef] = value;
  7227. }
  7228. };
  7229. ref._stringRef = stringRef;
  7230. return ref;
  7231. } else {
  7232. if (!(typeof mixedRef === "string")) {
  7233. throw Error(
  7234. "Expected ref to be a function, a string, an object returned by React.createRef(), or null."
  7235. );
  7236. }
  7237. if (!element._owner) {
  7238. throw Error(
  7239. "Element ref was specified as a string (" +
  7240. mixedRef +
  7241. ") 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."
  7242. );
  7243. }
  7244. }
  7245. }
  7246. return mixedRef;
  7247. }
  7248. function throwOnInvalidObjectType(returnFiber, newChild) {
  7249. if (returnFiber.type !== "textarea") {
  7250. var addendum = "";
  7251. {
  7252. addendum =
  7253. " If you meant to render a collection of children, use an array " +
  7254. "instead." +
  7255. getCurrentFiberStackInDev();
  7256. }
  7257. {
  7258. throw Error(
  7259. "Objects are not valid as a React child (found: " +
  7260. (Object.prototype.toString.call(newChild) === "[object Object]"
  7261. ? "object with keys {" + Object.keys(newChild).join(", ") + "}"
  7262. : newChild) +
  7263. ")." +
  7264. addendum
  7265. );
  7266. }
  7267. }
  7268. }
  7269. function warnOnFunctionType() {
  7270. {
  7271. var currentComponentErrorInfo =
  7272. "Functions are not valid as a React child. This may happen if " +
  7273. "you return a Component instead of <Component /> from render. " +
  7274. "Or maybe you meant to call this function rather than return it." +
  7275. getCurrentFiberStackInDev();
  7276. if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
  7277. return;
  7278. }
  7279. ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
  7280. error(
  7281. "Functions are not valid as a React child. This may happen if " +
  7282. "you return a Component instead of <Component /> from render. " +
  7283. "Or maybe you meant to call this function rather than return it."
  7284. );
  7285. }
  7286. } // This wrapper function exists because I expect to clone the code in each path
  7287. // to be able to optimize each path individually by branching early. This needs
  7288. // a compiler or we can do it manually. Helpers that don't need this branching
  7289. // live outside of this function.
  7290. function ChildReconciler(shouldTrackSideEffects) {
  7291. function deleteChild(returnFiber, childToDelete) {
  7292. if (!shouldTrackSideEffects) {
  7293. // Noop.
  7294. return;
  7295. } // Deletions are added in reversed order so we add it to the front.
  7296. // At this point, the return fiber's effect list is empty except for
  7297. // deletions, so we can just append the deletion to the list. The remaining
  7298. // effects aren't added until the complete phase. Once we implement
  7299. // resuming, this may not be true.
  7300. var last = returnFiber.lastEffect;
  7301. if (last !== null) {
  7302. last.nextEffect = childToDelete;
  7303. returnFiber.lastEffect = childToDelete;
  7304. } else {
  7305. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  7306. }
  7307. childToDelete.nextEffect = null;
  7308. childToDelete.effectTag = Deletion;
  7309. }
  7310. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  7311. if (!shouldTrackSideEffects) {
  7312. // Noop.
  7313. return null;
  7314. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  7315. // assuming that after the first child we've already added everything.
  7316. var childToDelete = currentFirstChild;
  7317. while (childToDelete !== null) {
  7318. deleteChild(returnFiber, childToDelete);
  7319. childToDelete = childToDelete.sibling;
  7320. }
  7321. return null;
  7322. }
  7323. function mapRemainingChildren(returnFiber, currentFirstChild) {
  7324. // Add the remaining children to a temporary map so that we can find them by
  7325. // keys quickly. Implicit (null) keys get added to this set with their index
  7326. // instead.
  7327. var existingChildren = new Map();
  7328. var existingChild = currentFirstChild;
  7329. while (existingChild !== null) {
  7330. if (existingChild.key !== null) {
  7331. existingChildren.set(existingChild.key, existingChild);
  7332. } else {
  7333. existingChildren.set(existingChild.index, existingChild);
  7334. }
  7335. existingChild = existingChild.sibling;
  7336. }
  7337. return existingChildren;
  7338. }
  7339. function useFiber(fiber, pendingProps) {
  7340. // We currently set sibling to null and index to 0 here because it is easy
  7341. // to forget to do before returning it. E.g. for the single child case.
  7342. var clone = createWorkInProgress(fiber, pendingProps);
  7343. clone.index = 0;
  7344. clone.sibling = null;
  7345. return clone;
  7346. }
  7347. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  7348. newFiber.index = newIndex;
  7349. if (!shouldTrackSideEffects) {
  7350. // Noop.
  7351. return lastPlacedIndex;
  7352. }
  7353. var current = newFiber.alternate;
  7354. if (current !== null) {
  7355. var oldIndex = current.index;
  7356. if (oldIndex < lastPlacedIndex) {
  7357. // This is a move.
  7358. newFiber.effectTag = Placement;
  7359. return lastPlacedIndex;
  7360. } else {
  7361. // This item can stay in place.
  7362. return oldIndex;
  7363. }
  7364. } else {
  7365. // This is an insertion.
  7366. newFiber.effectTag = Placement;
  7367. return lastPlacedIndex;
  7368. }
  7369. }
  7370. function placeSingleChild(newFiber) {
  7371. // This is simpler for the single child case. We only need to do a
  7372. // placement for inserting new children.
  7373. if (shouldTrackSideEffects && newFiber.alternate === null) {
  7374. newFiber.effectTag = Placement;
  7375. }
  7376. return newFiber;
  7377. }
  7378. function updateTextNode(returnFiber, current, textContent, expirationTime) {
  7379. if (current === null || current.tag !== HostText) {
  7380. // Insert
  7381. var created = createFiberFromText(
  7382. textContent,
  7383. returnFiber.mode,
  7384. expirationTime
  7385. );
  7386. created.return = returnFiber;
  7387. return created;
  7388. } else {
  7389. // Update
  7390. var existing = useFiber(current, textContent);
  7391. existing.return = returnFiber;
  7392. return existing;
  7393. }
  7394. }
  7395. function updateElement(returnFiber, current, element, expirationTime) {
  7396. if (current !== null) {
  7397. if (
  7398. current.elementType === element.type || // Keep this check inline so it only runs on the false path:
  7399. isCompatibleFamilyForHotReloading(current, element)
  7400. ) {
  7401. // Move based on index
  7402. var existing = useFiber(current, element.props);
  7403. existing.ref = coerceRef(returnFiber, current, element);
  7404. existing.return = returnFiber;
  7405. {
  7406. existing._debugSource = element._source;
  7407. existing._debugOwner = element._owner;
  7408. }
  7409. return existing;
  7410. }
  7411. } // Insert
  7412. var created = createFiberFromElement(
  7413. element,
  7414. returnFiber.mode,
  7415. expirationTime
  7416. );
  7417. created.ref = coerceRef(returnFiber, current, element);
  7418. created.return = returnFiber;
  7419. return created;
  7420. }
  7421. function updatePortal(returnFiber, current, portal, expirationTime) {
  7422. if (
  7423. current === null ||
  7424. current.tag !== HostPortal ||
  7425. current.stateNode.containerInfo !== portal.containerInfo ||
  7426. current.stateNode.implementation !== portal.implementation
  7427. ) {
  7428. // Insert
  7429. var created = createFiberFromPortal(
  7430. portal,
  7431. returnFiber.mode,
  7432. expirationTime
  7433. );
  7434. created.return = returnFiber;
  7435. return created;
  7436. } else {
  7437. // Update
  7438. var existing = useFiber(current, portal.children || []);
  7439. existing.return = returnFiber;
  7440. return existing;
  7441. }
  7442. }
  7443. function updateFragment(returnFiber, current, fragment, expirationTime, key) {
  7444. if (current === null || current.tag !== Fragment) {
  7445. // Insert
  7446. var created = createFiberFromFragment(
  7447. fragment,
  7448. returnFiber.mode,
  7449. expirationTime,
  7450. key
  7451. );
  7452. created.return = returnFiber;
  7453. return created;
  7454. } else {
  7455. // Update
  7456. var existing = useFiber(current, fragment);
  7457. existing.return = returnFiber;
  7458. return existing;
  7459. }
  7460. }
  7461. function createChild(returnFiber, newChild, expirationTime) {
  7462. if (typeof newChild === "string" || typeof newChild === "number") {
  7463. // Text nodes don't have keys. If the previous node is implicitly keyed
  7464. // we can continue to replace it without aborting even if it is not a text
  7465. // node.
  7466. var created = createFiberFromText(
  7467. "" + newChild,
  7468. returnFiber.mode,
  7469. expirationTime
  7470. );
  7471. created.return = returnFiber;
  7472. return created;
  7473. }
  7474. if (typeof newChild === "object" && newChild !== null) {
  7475. switch (newChild.$$typeof) {
  7476. case REACT_ELEMENT_TYPE: {
  7477. var _created = createFiberFromElement(
  7478. newChild,
  7479. returnFiber.mode,
  7480. expirationTime
  7481. );
  7482. _created.ref = coerceRef(returnFiber, null, newChild);
  7483. _created.return = returnFiber;
  7484. return _created;
  7485. }
  7486. case REACT_PORTAL_TYPE: {
  7487. var _created2 = createFiberFromPortal(
  7488. newChild,
  7489. returnFiber.mode,
  7490. expirationTime
  7491. );
  7492. _created2.return = returnFiber;
  7493. return _created2;
  7494. }
  7495. }
  7496. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7497. var _created3 = createFiberFromFragment(
  7498. newChild,
  7499. returnFiber.mode,
  7500. expirationTime,
  7501. null
  7502. );
  7503. _created3.return = returnFiber;
  7504. return _created3;
  7505. }
  7506. throwOnInvalidObjectType(returnFiber, newChild);
  7507. }
  7508. {
  7509. if (typeof newChild === "function") {
  7510. warnOnFunctionType();
  7511. }
  7512. }
  7513. return null;
  7514. }
  7515. function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
  7516. // Update the fiber if the keys match, otherwise return null.
  7517. var key = oldFiber !== null ? oldFiber.key : null;
  7518. if (typeof newChild === "string" || typeof newChild === "number") {
  7519. // Text nodes don't have keys. If the previous node is implicitly keyed
  7520. // we can continue to replace it without aborting even if it is not a text
  7521. // node.
  7522. if (key !== null) {
  7523. return null;
  7524. }
  7525. return updateTextNode(
  7526. returnFiber,
  7527. oldFiber,
  7528. "" + newChild,
  7529. expirationTime
  7530. );
  7531. }
  7532. if (typeof newChild === "object" && newChild !== null) {
  7533. switch (newChild.$$typeof) {
  7534. case REACT_ELEMENT_TYPE: {
  7535. if (newChild.key === key) {
  7536. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7537. return updateFragment(
  7538. returnFiber,
  7539. oldFiber,
  7540. newChild.props.children,
  7541. expirationTime,
  7542. key
  7543. );
  7544. }
  7545. return updateElement(
  7546. returnFiber,
  7547. oldFiber,
  7548. newChild,
  7549. expirationTime
  7550. );
  7551. } else {
  7552. return null;
  7553. }
  7554. }
  7555. case REACT_PORTAL_TYPE: {
  7556. if (newChild.key === key) {
  7557. return updatePortal(
  7558. returnFiber,
  7559. oldFiber,
  7560. newChild,
  7561. expirationTime
  7562. );
  7563. } else {
  7564. return null;
  7565. }
  7566. }
  7567. }
  7568. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7569. if (key !== null) {
  7570. return null;
  7571. }
  7572. return updateFragment(
  7573. returnFiber,
  7574. oldFiber,
  7575. newChild,
  7576. expirationTime,
  7577. null
  7578. );
  7579. }
  7580. throwOnInvalidObjectType(returnFiber, newChild);
  7581. }
  7582. {
  7583. if (typeof newChild === "function") {
  7584. warnOnFunctionType();
  7585. }
  7586. }
  7587. return null;
  7588. }
  7589. function updateFromMap(
  7590. existingChildren,
  7591. returnFiber,
  7592. newIdx,
  7593. newChild,
  7594. expirationTime
  7595. ) {
  7596. if (typeof newChild === "string" || typeof newChild === "number") {
  7597. // Text nodes don't have keys, so we neither have to check the old nor
  7598. // new node for the key. If both are text nodes, they match.
  7599. var matchedFiber = existingChildren.get(newIdx) || null;
  7600. return updateTextNode(
  7601. returnFiber,
  7602. matchedFiber,
  7603. "" + newChild,
  7604. expirationTime
  7605. );
  7606. }
  7607. if (typeof newChild === "object" && newChild !== null) {
  7608. switch (newChild.$$typeof) {
  7609. case REACT_ELEMENT_TYPE: {
  7610. var _matchedFiber =
  7611. existingChildren.get(
  7612. newChild.key === null ? newIdx : newChild.key
  7613. ) || null;
  7614. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7615. return updateFragment(
  7616. returnFiber,
  7617. _matchedFiber,
  7618. newChild.props.children,
  7619. expirationTime,
  7620. newChild.key
  7621. );
  7622. }
  7623. return updateElement(
  7624. returnFiber,
  7625. _matchedFiber,
  7626. newChild,
  7627. expirationTime
  7628. );
  7629. }
  7630. case REACT_PORTAL_TYPE: {
  7631. var _matchedFiber2 =
  7632. existingChildren.get(
  7633. newChild.key === null ? newIdx : newChild.key
  7634. ) || null;
  7635. return updatePortal(
  7636. returnFiber,
  7637. _matchedFiber2,
  7638. newChild,
  7639. expirationTime
  7640. );
  7641. }
  7642. }
  7643. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7644. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  7645. return updateFragment(
  7646. returnFiber,
  7647. _matchedFiber3,
  7648. newChild,
  7649. expirationTime,
  7650. null
  7651. );
  7652. }
  7653. throwOnInvalidObjectType(returnFiber, newChild);
  7654. }
  7655. {
  7656. if (typeof newChild === "function") {
  7657. warnOnFunctionType();
  7658. }
  7659. }
  7660. return null;
  7661. }
  7662. /**
  7663. * Warns if there is a duplicate or missing key
  7664. */
  7665. function warnOnInvalidKey(child, knownKeys) {
  7666. {
  7667. if (typeof child !== "object" || child === null) {
  7668. return knownKeys;
  7669. }
  7670. switch (child.$$typeof) {
  7671. case REACT_ELEMENT_TYPE:
  7672. case REACT_PORTAL_TYPE:
  7673. warnForMissingKey(child);
  7674. var key = child.key;
  7675. if (typeof key !== "string") {
  7676. break;
  7677. }
  7678. if (knownKeys === null) {
  7679. knownKeys = new Set();
  7680. knownKeys.add(key);
  7681. break;
  7682. }
  7683. if (!knownKeys.has(key)) {
  7684. knownKeys.add(key);
  7685. break;
  7686. }
  7687. error(
  7688. "Encountered two children with the same key, `%s`. " +
  7689. "Keys should be unique so that components maintain their identity " +
  7690. "across updates. Non-unique keys may cause children to be " +
  7691. "duplicated and/or omitted — the behavior is unsupported and " +
  7692. "could change in a future version.",
  7693. key
  7694. );
  7695. break;
  7696. }
  7697. }
  7698. return knownKeys;
  7699. }
  7700. function reconcileChildrenArray(
  7701. returnFiber,
  7702. currentFirstChild,
  7703. newChildren,
  7704. expirationTime
  7705. ) {
  7706. // This algorithm can't optimize by searching from both ends since we
  7707. // don't have backpointers on fibers. I'm trying to see how far we can get
  7708. // with that model. If it ends up not being worth the tradeoffs, we can
  7709. // add it later.
  7710. // Even with a two ended optimization, we'd want to optimize for the case
  7711. // where there are few changes and brute force the comparison instead of
  7712. // going for the Map. It'd like to explore hitting that path first in
  7713. // forward-only mode and only go for the Map once we notice that we need
  7714. // lots of look ahead. This doesn't handle reversal as well as two ended
  7715. // search but that's unusual. Besides, for the two ended optimization to
  7716. // work on Iterables, we'd need to copy the whole set.
  7717. // In this first iteration, we'll just live with hitting the bad case
  7718. // (adding everything to a Map) in for every insert/move.
  7719. // If you change this code, also update reconcileChildrenIterator() which
  7720. // uses the same algorithm.
  7721. {
  7722. // First, validate keys.
  7723. var knownKeys = null;
  7724. for (var i = 0; i < newChildren.length; i++) {
  7725. var child = newChildren[i];
  7726. knownKeys = warnOnInvalidKey(child, knownKeys);
  7727. }
  7728. }
  7729. var resultingFirstChild = null;
  7730. var previousNewFiber = null;
  7731. var oldFiber = currentFirstChild;
  7732. var lastPlacedIndex = 0;
  7733. var newIdx = 0;
  7734. var nextOldFiber = null;
  7735. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  7736. if (oldFiber.index > newIdx) {
  7737. nextOldFiber = oldFiber;
  7738. oldFiber = null;
  7739. } else {
  7740. nextOldFiber = oldFiber.sibling;
  7741. }
  7742. var newFiber = updateSlot(
  7743. returnFiber,
  7744. oldFiber,
  7745. newChildren[newIdx],
  7746. expirationTime
  7747. );
  7748. if (newFiber === null) {
  7749. // TODO: This breaks on empty slots like null children. That's
  7750. // unfortunate because it triggers the slow path all the time. We need
  7751. // a better way to communicate whether this was a miss or null,
  7752. // boolean, undefined, etc.
  7753. if (oldFiber === null) {
  7754. oldFiber = nextOldFiber;
  7755. }
  7756. break;
  7757. }
  7758. if (shouldTrackSideEffects) {
  7759. if (oldFiber && newFiber.alternate === null) {
  7760. // We matched the slot, but we didn't reuse the existing fiber, so we
  7761. // need to delete the existing child.
  7762. deleteChild(returnFiber, oldFiber);
  7763. }
  7764. }
  7765. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7766. if (previousNewFiber === null) {
  7767. // TODO: Move out of the loop. This only happens for the first run.
  7768. resultingFirstChild = newFiber;
  7769. } else {
  7770. // TODO: Defer siblings if we're not at the right index for this slot.
  7771. // I.e. if we had null values before, then we want to defer this
  7772. // for each null value. However, we also don't want to call updateSlot
  7773. // with the previous one.
  7774. previousNewFiber.sibling = newFiber;
  7775. }
  7776. previousNewFiber = newFiber;
  7777. oldFiber = nextOldFiber;
  7778. }
  7779. if (newIdx === newChildren.length) {
  7780. // We've reached the end of the new children. We can delete the rest.
  7781. deleteRemainingChildren(returnFiber, oldFiber);
  7782. return resultingFirstChild;
  7783. }
  7784. if (oldFiber === null) {
  7785. // If we don't have any more existing children we can choose a fast path
  7786. // since the rest will all be insertions.
  7787. for (; newIdx < newChildren.length; newIdx++) {
  7788. var _newFiber = createChild(
  7789. returnFiber,
  7790. newChildren[newIdx],
  7791. expirationTime
  7792. );
  7793. if (_newFiber === null) {
  7794. continue;
  7795. }
  7796. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  7797. if (previousNewFiber === null) {
  7798. // TODO: Move out of the loop. This only happens for the first run.
  7799. resultingFirstChild = _newFiber;
  7800. } else {
  7801. previousNewFiber.sibling = _newFiber;
  7802. }
  7803. previousNewFiber = _newFiber;
  7804. }
  7805. return resultingFirstChild;
  7806. } // Add all children to a key map for quick lookups.
  7807. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  7808. for (; newIdx < newChildren.length; newIdx++) {
  7809. var _newFiber2 = updateFromMap(
  7810. existingChildren,
  7811. returnFiber,
  7812. newIdx,
  7813. newChildren[newIdx],
  7814. expirationTime
  7815. );
  7816. if (_newFiber2 !== null) {
  7817. if (shouldTrackSideEffects) {
  7818. if (_newFiber2.alternate !== null) {
  7819. // The new fiber is a work in progress, but if there exists a
  7820. // current, that means that we reused the fiber. We need to delete
  7821. // it from the child list so that we don't add it to the deletion
  7822. // list.
  7823. existingChildren.delete(
  7824. _newFiber2.key === null ? newIdx : _newFiber2.key
  7825. );
  7826. }
  7827. }
  7828. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  7829. if (previousNewFiber === null) {
  7830. resultingFirstChild = _newFiber2;
  7831. } else {
  7832. previousNewFiber.sibling = _newFiber2;
  7833. }
  7834. previousNewFiber = _newFiber2;
  7835. }
  7836. }
  7837. if (shouldTrackSideEffects) {
  7838. // Any existing children that weren't consumed above were deleted. We need
  7839. // to add them to the deletion list.
  7840. existingChildren.forEach(function(child) {
  7841. return deleteChild(returnFiber, child);
  7842. });
  7843. }
  7844. return resultingFirstChild;
  7845. }
  7846. function reconcileChildrenIterator(
  7847. returnFiber,
  7848. currentFirstChild,
  7849. newChildrenIterable,
  7850. expirationTime
  7851. ) {
  7852. // This is the same implementation as reconcileChildrenArray(),
  7853. // but using the iterator instead.
  7854. var iteratorFn = getIteratorFn(newChildrenIterable);
  7855. if (!(typeof iteratorFn === "function")) {
  7856. throw Error(
  7857. "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue."
  7858. );
  7859. }
  7860. {
  7861. // We don't support rendering Generators because it's a mutation.
  7862. // See https://github.com/facebook/react/issues/12995
  7863. if (
  7864. typeof Symbol === "function" && // $FlowFixMe Flow doesn't know about toStringTag
  7865. newChildrenIterable[Symbol.toStringTag] === "Generator"
  7866. ) {
  7867. if (!didWarnAboutGenerators) {
  7868. error(
  7869. "Using Generators as children is unsupported and will likely yield " +
  7870. "unexpected results because enumerating a generator mutates it. " +
  7871. "You may convert it to an array with `Array.from()` or the " +
  7872. "`[...spread]` operator before rendering. Keep in mind " +
  7873. "you might need to polyfill these features for older browsers."
  7874. );
  7875. }
  7876. didWarnAboutGenerators = true;
  7877. } // Warn about using Maps as children
  7878. if (newChildrenIterable.entries === iteratorFn) {
  7879. if (!didWarnAboutMaps) {
  7880. error(
  7881. "Using Maps as children is unsupported and will likely yield " +
  7882. "unexpected results. Convert it to a sequence/iterable of keyed " +
  7883. "ReactElements instead."
  7884. );
  7885. }
  7886. didWarnAboutMaps = true;
  7887. } // First, validate keys.
  7888. // We'll get a different iterator later for the main pass.
  7889. var _newChildren = iteratorFn.call(newChildrenIterable);
  7890. if (_newChildren) {
  7891. var knownKeys = null;
  7892. var _step = _newChildren.next();
  7893. for (; !_step.done; _step = _newChildren.next()) {
  7894. var child = _step.value;
  7895. knownKeys = warnOnInvalidKey(child, knownKeys);
  7896. }
  7897. }
  7898. }
  7899. var newChildren = iteratorFn.call(newChildrenIterable);
  7900. if (!(newChildren != null)) {
  7901. throw Error("An iterable object provided no iterator.");
  7902. }
  7903. var resultingFirstChild = null;
  7904. var previousNewFiber = null;
  7905. var oldFiber = currentFirstChild;
  7906. var lastPlacedIndex = 0;
  7907. var newIdx = 0;
  7908. var nextOldFiber = null;
  7909. var step = newChildren.next();
  7910. for (
  7911. ;
  7912. oldFiber !== null && !step.done;
  7913. newIdx++, step = newChildren.next()
  7914. ) {
  7915. if (oldFiber.index > newIdx) {
  7916. nextOldFiber = oldFiber;
  7917. oldFiber = null;
  7918. } else {
  7919. nextOldFiber = oldFiber.sibling;
  7920. }
  7921. var newFiber = updateSlot(
  7922. returnFiber,
  7923. oldFiber,
  7924. step.value,
  7925. expirationTime
  7926. );
  7927. if (newFiber === null) {
  7928. // TODO: This breaks on empty slots like null children. That's
  7929. // unfortunate because it triggers the slow path all the time. We need
  7930. // a better way to communicate whether this was a miss or null,
  7931. // boolean, undefined, etc.
  7932. if (oldFiber === null) {
  7933. oldFiber = nextOldFiber;
  7934. }
  7935. break;
  7936. }
  7937. if (shouldTrackSideEffects) {
  7938. if (oldFiber && newFiber.alternate === null) {
  7939. // We matched the slot, but we didn't reuse the existing fiber, so we
  7940. // need to delete the existing child.
  7941. deleteChild(returnFiber, oldFiber);
  7942. }
  7943. }
  7944. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7945. if (previousNewFiber === null) {
  7946. // TODO: Move out of the loop. This only happens for the first run.
  7947. resultingFirstChild = newFiber;
  7948. } else {
  7949. // TODO: Defer siblings if we're not at the right index for this slot.
  7950. // I.e. if we had null values before, then we want to defer this
  7951. // for each null value. However, we also don't want to call updateSlot
  7952. // with the previous one.
  7953. previousNewFiber.sibling = newFiber;
  7954. }
  7955. previousNewFiber = newFiber;
  7956. oldFiber = nextOldFiber;
  7957. }
  7958. if (step.done) {
  7959. // We've reached the end of the new children. We can delete the rest.
  7960. deleteRemainingChildren(returnFiber, oldFiber);
  7961. return resultingFirstChild;
  7962. }
  7963. if (oldFiber === null) {
  7964. // If we don't have any more existing children we can choose a fast path
  7965. // since the rest will all be insertions.
  7966. for (; !step.done; newIdx++, step = newChildren.next()) {
  7967. var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
  7968. if (_newFiber3 === null) {
  7969. continue;
  7970. }
  7971. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  7972. if (previousNewFiber === null) {
  7973. // TODO: Move out of the loop. This only happens for the first run.
  7974. resultingFirstChild = _newFiber3;
  7975. } else {
  7976. previousNewFiber.sibling = _newFiber3;
  7977. }
  7978. previousNewFiber = _newFiber3;
  7979. }
  7980. return resultingFirstChild;
  7981. } // Add all children to a key map for quick lookups.
  7982. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  7983. for (; !step.done; newIdx++, step = newChildren.next()) {
  7984. var _newFiber4 = updateFromMap(
  7985. existingChildren,
  7986. returnFiber,
  7987. newIdx,
  7988. step.value,
  7989. expirationTime
  7990. );
  7991. if (_newFiber4 !== null) {
  7992. if (shouldTrackSideEffects) {
  7993. if (_newFiber4.alternate !== null) {
  7994. // The new fiber is a work in progress, but if there exists a
  7995. // current, that means that we reused the fiber. We need to delete
  7996. // it from the child list so that we don't add it to the deletion
  7997. // list.
  7998. existingChildren.delete(
  7999. _newFiber4.key === null ? newIdx : _newFiber4.key
  8000. );
  8001. }
  8002. }
  8003. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  8004. if (previousNewFiber === null) {
  8005. resultingFirstChild = _newFiber4;
  8006. } else {
  8007. previousNewFiber.sibling = _newFiber4;
  8008. }
  8009. previousNewFiber = _newFiber4;
  8010. }
  8011. }
  8012. if (shouldTrackSideEffects) {
  8013. // Any existing children that weren't consumed above were deleted. We need
  8014. // to add them to the deletion list.
  8015. existingChildren.forEach(function(child) {
  8016. return deleteChild(returnFiber, child);
  8017. });
  8018. }
  8019. return resultingFirstChild;
  8020. }
  8021. function reconcileSingleTextNode(
  8022. returnFiber,
  8023. currentFirstChild,
  8024. textContent,
  8025. expirationTime
  8026. ) {
  8027. // There's no need to check for keys on text nodes since we don't have a
  8028. // way to define them.
  8029. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  8030. // We already have an existing node so let's just update it and delete
  8031. // the rest.
  8032. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  8033. var existing = useFiber(currentFirstChild, textContent);
  8034. existing.return = returnFiber;
  8035. return existing;
  8036. } // The existing first child is not a text node so we need to create one
  8037. // and delete the existing ones.
  8038. deleteRemainingChildren(returnFiber, currentFirstChild);
  8039. var created = createFiberFromText(
  8040. textContent,
  8041. returnFiber.mode,
  8042. expirationTime
  8043. );
  8044. created.return = returnFiber;
  8045. return created;
  8046. }
  8047. function reconcileSingleElement(
  8048. returnFiber,
  8049. currentFirstChild,
  8050. element,
  8051. expirationTime
  8052. ) {
  8053. var key = element.key;
  8054. var child = currentFirstChild;
  8055. while (child !== null) {
  8056. // TODO: If key === null and child.key === null, then this only applies to
  8057. // the first item in the list.
  8058. if (child.key === key) {
  8059. switch (child.tag) {
  8060. case Fragment: {
  8061. if (element.type === REACT_FRAGMENT_TYPE) {
  8062. deleteRemainingChildren(returnFiber, child.sibling);
  8063. var existing = useFiber(child, element.props.children);
  8064. existing.return = returnFiber;
  8065. {
  8066. existing._debugSource = element._source;
  8067. existing._debugOwner = element._owner;
  8068. }
  8069. return existing;
  8070. }
  8071. break;
  8072. }
  8073. case Block:
  8074. // We intentionally fallthrough here if enableBlocksAPI is not on.
  8075. // eslint-disable-next-lined no-fallthrough
  8076. default: {
  8077. if (
  8078. child.elementType === element.type || // Keep this check inline so it only runs on the false path:
  8079. isCompatibleFamilyForHotReloading(child, element)
  8080. ) {
  8081. deleteRemainingChildren(returnFiber, child.sibling);
  8082. var _existing3 = useFiber(child, element.props);
  8083. _existing3.ref = coerceRef(returnFiber, child, element);
  8084. _existing3.return = returnFiber;
  8085. {
  8086. _existing3._debugSource = element._source;
  8087. _existing3._debugOwner = element._owner;
  8088. }
  8089. return _existing3;
  8090. }
  8091. break;
  8092. }
  8093. } // Didn't match.
  8094. deleteRemainingChildren(returnFiber, child);
  8095. break;
  8096. } else {
  8097. deleteChild(returnFiber, child);
  8098. }
  8099. child = child.sibling;
  8100. }
  8101. if (element.type === REACT_FRAGMENT_TYPE) {
  8102. var created = createFiberFromFragment(
  8103. element.props.children,
  8104. returnFiber.mode,
  8105. expirationTime,
  8106. element.key
  8107. );
  8108. created.return = returnFiber;
  8109. return created;
  8110. } else {
  8111. var _created4 = createFiberFromElement(
  8112. element,
  8113. returnFiber.mode,
  8114. expirationTime
  8115. );
  8116. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  8117. _created4.return = returnFiber;
  8118. return _created4;
  8119. }
  8120. }
  8121. function reconcileSinglePortal(
  8122. returnFiber,
  8123. currentFirstChild,
  8124. portal,
  8125. expirationTime
  8126. ) {
  8127. var key = portal.key;
  8128. var child = currentFirstChild;
  8129. while (child !== null) {
  8130. // TODO: If key === null and child.key === null, then this only applies to
  8131. // the first item in the list.
  8132. if (child.key === key) {
  8133. if (
  8134. child.tag === HostPortal &&
  8135. child.stateNode.containerInfo === portal.containerInfo &&
  8136. child.stateNode.implementation === portal.implementation
  8137. ) {
  8138. deleteRemainingChildren(returnFiber, child.sibling);
  8139. var existing = useFiber(child, portal.children || []);
  8140. existing.return = returnFiber;
  8141. return existing;
  8142. } else {
  8143. deleteRemainingChildren(returnFiber, child);
  8144. break;
  8145. }
  8146. } else {
  8147. deleteChild(returnFiber, child);
  8148. }
  8149. child = child.sibling;
  8150. }
  8151. var created = createFiberFromPortal(
  8152. portal,
  8153. returnFiber.mode,
  8154. expirationTime
  8155. );
  8156. created.return = returnFiber;
  8157. return created;
  8158. } // This API will tag the children with the side-effect of the reconciliation
  8159. // itself. They will be added to the side-effect list as we pass through the
  8160. // children and the parent.
  8161. function reconcileChildFibers(
  8162. returnFiber,
  8163. currentFirstChild,
  8164. newChild,
  8165. expirationTime
  8166. ) {
  8167. // This function is not recursive.
  8168. // If the top level item is an array, we treat it as a set of children,
  8169. // not as a fragment. Nested arrays on the other hand will be treated as
  8170. // fragment nodes. Recursion happens at the normal flow.
  8171. // Handle top level unkeyed fragments as if they were arrays.
  8172. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  8173. // We treat the ambiguous cases above the same.
  8174. var isUnkeyedTopLevelFragment =
  8175. typeof newChild === "object" &&
  8176. newChild !== null &&
  8177. newChild.type === REACT_FRAGMENT_TYPE &&
  8178. newChild.key === null;
  8179. if (isUnkeyedTopLevelFragment) {
  8180. newChild = newChild.props.children;
  8181. } // Handle object types
  8182. var isObject = typeof newChild === "object" && newChild !== null;
  8183. if (isObject) {
  8184. switch (newChild.$$typeof) {
  8185. case REACT_ELEMENT_TYPE:
  8186. return placeSingleChild(
  8187. reconcileSingleElement(
  8188. returnFiber,
  8189. currentFirstChild,
  8190. newChild,
  8191. expirationTime
  8192. )
  8193. );
  8194. case REACT_PORTAL_TYPE:
  8195. return placeSingleChild(
  8196. reconcileSinglePortal(
  8197. returnFiber,
  8198. currentFirstChild,
  8199. newChild,
  8200. expirationTime
  8201. )
  8202. );
  8203. }
  8204. }
  8205. if (typeof newChild === "string" || typeof newChild === "number") {
  8206. return placeSingleChild(
  8207. reconcileSingleTextNode(
  8208. returnFiber,
  8209. currentFirstChild,
  8210. "" + newChild,
  8211. expirationTime
  8212. )
  8213. );
  8214. }
  8215. if (isArray$1(newChild)) {
  8216. return reconcileChildrenArray(
  8217. returnFiber,
  8218. currentFirstChild,
  8219. newChild,
  8220. expirationTime
  8221. );
  8222. }
  8223. if (getIteratorFn(newChild)) {
  8224. return reconcileChildrenIterator(
  8225. returnFiber,
  8226. currentFirstChild,
  8227. newChild,
  8228. expirationTime
  8229. );
  8230. }
  8231. if (isObject) {
  8232. throwOnInvalidObjectType(returnFiber, newChild);
  8233. }
  8234. {
  8235. if (typeof newChild === "function") {
  8236. warnOnFunctionType();
  8237. }
  8238. }
  8239. if (typeof newChild === "undefined" && !isUnkeyedTopLevelFragment) {
  8240. // If the new child is undefined, and the return fiber is a composite
  8241. // component, throw an error. If Fiber return types are disabled,
  8242. // we already threw above.
  8243. switch (returnFiber.tag) {
  8244. case ClassComponent: {
  8245. {
  8246. var instance = returnFiber.stateNode;
  8247. if (instance.render._isMockFunction) {
  8248. // We allow auto-mocks to proceed as if they're returning null.
  8249. break;
  8250. }
  8251. }
  8252. }
  8253. // Intentionally fall through to the next case, which handles both
  8254. // functions and classes
  8255. // eslint-disable-next-lined no-fallthrough
  8256. case FunctionComponent: {
  8257. var Component = returnFiber.type;
  8258. {
  8259. throw Error(
  8260. (Component.displayName || Component.name || "Component") +
  8261. "(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null."
  8262. );
  8263. }
  8264. }
  8265. }
  8266. } // Remaining cases are all treated as empty.
  8267. return deleteRemainingChildren(returnFiber, currentFirstChild);
  8268. }
  8269. return reconcileChildFibers;
  8270. }
  8271. var reconcileChildFibers = ChildReconciler(true);
  8272. var mountChildFibers = ChildReconciler(false);
  8273. function cloneChildFibers(current, workInProgress) {
  8274. if (!(current === null || workInProgress.child === current.child)) {
  8275. throw Error("Resuming work not yet implemented.");
  8276. }
  8277. if (workInProgress.child === null) {
  8278. return;
  8279. }
  8280. var currentChild = workInProgress.child;
  8281. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  8282. workInProgress.child = newChild;
  8283. newChild.return = workInProgress;
  8284. while (currentChild.sibling !== null) {
  8285. currentChild = currentChild.sibling;
  8286. newChild = newChild.sibling = createWorkInProgress(
  8287. currentChild,
  8288. currentChild.pendingProps
  8289. );
  8290. newChild.return = workInProgress;
  8291. }
  8292. newChild.sibling = null;
  8293. } // Reset a workInProgress child set to prepare it for a second pass.
  8294. function resetChildFibers(workInProgress, renderExpirationTime) {
  8295. var child = workInProgress.child;
  8296. while (child !== null) {
  8297. resetWorkInProgress(child, renderExpirationTime);
  8298. child = child.sibling;
  8299. }
  8300. }
  8301. var NO_CONTEXT = {};
  8302. var contextStackCursor$1 = createCursor(NO_CONTEXT);
  8303. var contextFiberStackCursor = createCursor(NO_CONTEXT);
  8304. var rootInstanceStackCursor = createCursor(NO_CONTEXT);
  8305. function requiredContext(c) {
  8306. if (!(c !== NO_CONTEXT)) {
  8307. throw Error(
  8308. "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue."
  8309. );
  8310. }
  8311. return c;
  8312. }
  8313. function getRootHostContainer() {
  8314. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8315. return rootInstance;
  8316. }
  8317. function pushHostContainer(fiber, nextRootInstance) {
  8318. // Push current root instance onto the stack;
  8319. // This allows us to reset root when portals are popped.
  8320. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  8321. // This enables us to pop only Fibers that provide unique contexts.
  8322. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  8323. // However, we can't just call getRootHostContext() and push it because
  8324. // we'd have a different number of entries on the stack depending on
  8325. // whether getRootHostContext() throws somewhere in renderer code or not.
  8326. // So we push an empty value first. This lets us safely unwind on errors.
  8327. push(contextStackCursor$1, NO_CONTEXT, fiber);
  8328. var nextRootContext = getRootHostContext(); // Now that we know this function doesn't throw, replace it.
  8329. pop(contextStackCursor$1, fiber);
  8330. push(contextStackCursor$1, nextRootContext, fiber);
  8331. }
  8332. function popHostContainer(fiber) {
  8333. pop(contextStackCursor$1, fiber);
  8334. pop(contextFiberStackCursor, fiber);
  8335. pop(rootInstanceStackCursor, fiber);
  8336. }
  8337. function getHostContext() {
  8338. var context = requiredContext(contextStackCursor$1.current);
  8339. return context;
  8340. }
  8341. function pushHostContext(fiber) {
  8342. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8343. var context = requiredContext(contextStackCursor$1.current);
  8344. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  8345. if (context === nextContext) {
  8346. return;
  8347. } // Track the context and the Fiber that provided it.
  8348. // This enables us to pop only Fibers that provide unique contexts.
  8349. push(contextFiberStackCursor, fiber, fiber);
  8350. push(contextStackCursor$1, nextContext, fiber);
  8351. }
  8352. function popHostContext(fiber) {
  8353. // Do not pop unless this Fiber provided the current context.
  8354. // pushHostContext() only pushes Fibers that provide unique contexts.
  8355. if (contextFiberStackCursor.current !== fiber) {
  8356. return;
  8357. }
  8358. pop(contextStackCursor$1, fiber);
  8359. pop(contextFiberStackCursor, fiber);
  8360. }
  8361. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  8362. // inherited deeply down the subtree. The upper bits only affect
  8363. // this immediate suspense boundary and gets reset each new
  8364. // boundary or suspense list.
  8365. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  8366. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  8367. // boundaries is not currently showing visible main content.
  8368. // Either because it is already showing a fallback or is not mounted at all.
  8369. // We can use this to determine if it is desirable to trigger a fallback at
  8370. // the parent. If not, then we might need to trigger undesirable boundaries
  8371. // and/or suspend the commit to avoid hiding the parent content.
  8372. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  8373. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  8374. // items into their fallback state during one of the render passes.
  8375. var ForceSuspenseFallback = 2;
  8376. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  8377. function hasSuspenseContext(parentContext, flag) {
  8378. return (parentContext & flag) !== 0;
  8379. }
  8380. function setDefaultShallowSuspenseContext(parentContext) {
  8381. return parentContext & SubtreeSuspenseContextMask;
  8382. }
  8383. function setShallowSuspenseContext(parentContext, shallowContext) {
  8384. return (parentContext & SubtreeSuspenseContextMask) | shallowContext;
  8385. }
  8386. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  8387. return parentContext | subtreeContext;
  8388. }
  8389. function pushSuspenseContext(fiber, newContext) {
  8390. push(suspenseStackCursor, newContext, fiber);
  8391. }
  8392. function popSuspenseContext(fiber) {
  8393. pop(suspenseStackCursor, fiber);
  8394. }
  8395. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  8396. // If it was the primary children that just suspended, capture and render the
  8397. // fallback. Otherwise, don't capture and bubble to the next boundary.
  8398. var nextState = workInProgress.memoizedState;
  8399. if (nextState !== null) {
  8400. if (nextState.dehydrated !== null) {
  8401. // A dehydrated boundary always captures.
  8402. return true;
  8403. }
  8404. return false;
  8405. }
  8406. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  8407. if (props.fallback === undefined) {
  8408. return false;
  8409. } // Regular boundaries always capture.
  8410. if (props.unstable_avoidThisFallback !== true) {
  8411. return true;
  8412. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  8413. // parent boundary if it is currently invisible.
  8414. if (hasInvisibleParent) {
  8415. return false;
  8416. } // If the parent is not able to handle it, we must handle it.
  8417. return true;
  8418. }
  8419. function findFirstSuspended(row) {
  8420. var node = row;
  8421. while (node !== null) {
  8422. if (node.tag === SuspenseComponent) {
  8423. var state = node.memoizedState;
  8424. if (state !== null) {
  8425. var dehydrated = state.dehydrated;
  8426. if (
  8427. dehydrated === null ||
  8428. isSuspenseInstancePending() ||
  8429. isSuspenseInstanceFallback()
  8430. ) {
  8431. return node;
  8432. }
  8433. }
  8434. } else if (
  8435. node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  8436. // keep track of whether it suspended or not.
  8437. node.memoizedProps.revealOrder !== undefined
  8438. ) {
  8439. var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
  8440. if (didSuspend) {
  8441. return node;
  8442. }
  8443. } else if (node.child !== null) {
  8444. node.child.return = node;
  8445. node = node.child;
  8446. continue;
  8447. }
  8448. if (node === row) {
  8449. return null;
  8450. }
  8451. while (node.sibling === null) {
  8452. if (node.return === null || node.return === row) {
  8453. return null;
  8454. }
  8455. node = node.return;
  8456. }
  8457. node.sibling.return = node.return;
  8458. node = node.sibling;
  8459. }
  8460. return null;
  8461. }
  8462. function createDeprecatedResponderListener(responder, props) {
  8463. var eventResponderListener = {
  8464. responder: responder,
  8465. props: props
  8466. };
  8467. {
  8468. Object.freeze(eventResponderListener);
  8469. }
  8470. return eventResponderListener;
  8471. }
  8472. var HasEffect =
  8473. /* */
  8474. 1; // Represents the phase in which the effect (not the clean-up) fires.
  8475. var Layout =
  8476. /* */
  8477. 2;
  8478. var Passive$1 =
  8479. /* */
  8480. 4;
  8481. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
  8482. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  8483. var didWarnAboutMismatchedHooksForComponent;
  8484. {
  8485. didWarnAboutMismatchedHooksForComponent = new Set();
  8486. }
  8487. // These are set right before calling the component.
  8488. var renderExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
  8489. // the work-in-progress hook.
  8490. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  8491. // current hook list is the list that belongs to the current fiber. The
  8492. // work-in-progress hook list is a new list that will be added to the
  8493. // work-in-progress fiber.
  8494. var currentHook = null;
  8495. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  8496. // does not get reset if we do another render pass; only when we're completely
  8497. // finished evaluating this component. This is an optimization so we know
  8498. // whether we need to clear render phase updates after a throw.
  8499. var didScheduleRenderPhaseUpdate = false;
  8500. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  8501. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  8502. // The list stores the order of hooks used during the initial render (mount).
  8503. // Subsequent renders (updates) reference this list.
  8504. var hookTypesDev = null;
  8505. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  8506. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  8507. // When true, such Hooks will always be "remounted". Only used during hot reload.
  8508. var ignorePreviousDependencies = false;
  8509. function mountHookTypesDev() {
  8510. {
  8511. var hookName = currentHookNameInDev;
  8512. if (hookTypesDev === null) {
  8513. hookTypesDev = [hookName];
  8514. } else {
  8515. hookTypesDev.push(hookName);
  8516. }
  8517. }
  8518. }
  8519. function updateHookTypesDev() {
  8520. {
  8521. var hookName = currentHookNameInDev;
  8522. if (hookTypesDev !== null) {
  8523. hookTypesUpdateIndexDev++;
  8524. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  8525. warnOnHookMismatchInDev(hookName);
  8526. }
  8527. }
  8528. }
  8529. }
  8530. function checkDepsAreArrayDev(deps) {
  8531. {
  8532. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  8533. // Verify deps, but only on mount to avoid extra checks.
  8534. // It's unlikely their type would change as usually you define them inline.
  8535. error(
  8536. "%s received a final argument that is not an array (instead, received `%s`). When " +
  8537. "specified, the final argument must be an array.",
  8538. currentHookNameInDev,
  8539. typeof deps
  8540. );
  8541. }
  8542. }
  8543. }
  8544. function warnOnHookMismatchInDev(currentHookName) {
  8545. {
  8546. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  8547. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  8548. didWarnAboutMismatchedHooksForComponent.add(componentName);
  8549. if (hookTypesDev !== null) {
  8550. var table = "";
  8551. var secondColumnStart = 30;
  8552. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  8553. var oldHookName = hookTypesDev[i];
  8554. var newHookName =
  8555. i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  8556. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  8557. // lol @ IE not supporting String#repeat
  8558. while (row.length < secondColumnStart) {
  8559. row += " ";
  8560. }
  8561. row += newHookName + "\n";
  8562. table += row;
  8563. }
  8564. error(
  8565. "React has detected a change in the order of Hooks called by %s. " +
  8566. "This will lead to bugs and errors if not fixed. " +
  8567. "For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n" +
  8568. " Previous render Next render\n" +
  8569. " ------------------------------------------------------\n" +
  8570. "%s" +
  8571. " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
  8572. componentName,
  8573. table
  8574. );
  8575. }
  8576. }
  8577. }
  8578. }
  8579. function throwInvalidHookError() {
  8580. {
  8581. throw Error(
  8582. "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."
  8583. );
  8584. }
  8585. }
  8586. function areHookInputsEqual(nextDeps, prevDeps) {
  8587. {
  8588. if (ignorePreviousDependencies) {
  8589. // Only true when this component is being hot reloaded.
  8590. return false;
  8591. }
  8592. }
  8593. if (prevDeps === null) {
  8594. {
  8595. error(
  8596. "%s received a final argument during this render, but not during " +
  8597. "the previous render. Even though the final argument is optional, " +
  8598. "its type cannot change between renders.",
  8599. currentHookNameInDev
  8600. );
  8601. }
  8602. return false;
  8603. }
  8604. {
  8605. // Don't bother comparing lengths in prod because these arrays should be
  8606. // passed inline.
  8607. if (nextDeps.length !== prevDeps.length) {
  8608. error(
  8609. "The final argument passed to %s changed size between renders. The " +
  8610. "order and size of this array must remain constant.\n\n" +
  8611. "Previous: %s\n" +
  8612. "Incoming: %s",
  8613. currentHookNameInDev,
  8614. "[" + prevDeps.join(", ") + "]",
  8615. "[" + nextDeps.join(", ") + "]"
  8616. );
  8617. }
  8618. }
  8619. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  8620. if (objectIs(nextDeps[i], prevDeps[i])) {
  8621. continue;
  8622. }
  8623. return false;
  8624. }
  8625. return true;
  8626. }
  8627. function renderWithHooks(
  8628. current,
  8629. workInProgress,
  8630. Component,
  8631. props,
  8632. secondArg,
  8633. nextRenderExpirationTime
  8634. ) {
  8635. renderExpirationTime = nextRenderExpirationTime;
  8636. currentlyRenderingFiber$1 = workInProgress;
  8637. {
  8638. hookTypesDev = current !== null ? current._debugHookTypes : null;
  8639. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  8640. ignorePreviousDependencies =
  8641. current !== null && current.type !== workInProgress.type;
  8642. }
  8643. workInProgress.memoizedState = null;
  8644. workInProgress.updateQueue = null;
  8645. workInProgress.expirationTime = NoWork; // The following should have already been reset
  8646. // currentHook = null;
  8647. // workInProgressHook = null;
  8648. // didScheduleRenderPhaseUpdate = false;
  8649. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  8650. // Currently we will identify the update render as a mount because memoizedState === null.
  8651. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  8652. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  8653. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  8654. // so memoizedState would be null during updates and mounts.
  8655. {
  8656. if (current !== null && current.memoizedState !== null) {
  8657. ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
  8658. } else if (hookTypesDev !== null) {
  8659. // This dispatcher handles an edge case where a component is updating,
  8660. // but no stateful hooks have been used.
  8661. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  8662. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  8663. // This dispatcher does that.
  8664. ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
  8665. } else {
  8666. ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
  8667. }
  8668. }
  8669. var children = Component(props, secondArg); // Check if there was a render phase update
  8670. if (workInProgress.expirationTime === renderExpirationTime) {
  8671. // Keep rendering in a loop for as long as render phase updates continue to
  8672. // be scheduled. Use a counter to prevent infinite loops.
  8673. var numberOfReRenders = 0;
  8674. do {
  8675. workInProgress.expirationTime = NoWork;
  8676. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  8677. throw Error(
  8678. "Too many re-renders. React limits the number of renders to prevent an infinite loop."
  8679. );
  8680. }
  8681. numberOfReRenders += 1;
  8682. {
  8683. // Even when hot reloading, allow dependencies to stabilize
  8684. // after first render to prevent infinite render phase updates.
  8685. ignorePreviousDependencies = false;
  8686. } // Start over from the beginning of the list
  8687. currentHook = null;
  8688. workInProgressHook = null;
  8689. workInProgress.updateQueue = null;
  8690. {
  8691. // Also validate hook order for cascading updates.
  8692. hookTypesUpdateIndexDev = -1;
  8693. }
  8694. ReactCurrentDispatcher.current = HooksDispatcherOnRerenderInDEV;
  8695. children = Component(props, secondArg);
  8696. } while (workInProgress.expirationTime === renderExpirationTime);
  8697. } // We can assume the previous dispatcher is always this one, since we set it
  8698. // at the beginning of the render phase and there's no re-entrancy.
  8699. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8700. {
  8701. workInProgress._debugHookTypes = hookTypesDev;
  8702. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  8703. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  8704. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  8705. renderExpirationTime = NoWork;
  8706. currentlyRenderingFiber$1 = null;
  8707. currentHook = null;
  8708. workInProgressHook = null;
  8709. {
  8710. currentHookNameInDev = null;
  8711. hookTypesDev = null;
  8712. hookTypesUpdateIndexDev = -1;
  8713. }
  8714. didScheduleRenderPhaseUpdate = false;
  8715. if (!!didRenderTooFewHooks) {
  8716. throw Error(
  8717. "Rendered fewer hooks than expected. This may be caused by an accidental early return statement."
  8718. );
  8719. }
  8720. return children;
  8721. }
  8722. function bailoutHooks(current, workInProgress, expirationTime) {
  8723. workInProgress.updateQueue = current.updateQueue;
  8724. workInProgress.effectTag &= ~(Passive | Update);
  8725. if (current.expirationTime <= expirationTime) {
  8726. current.expirationTime = NoWork;
  8727. }
  8728. }
  8729. function resetHooksAfterThrow() {
  8730. // We can assume the previous dispatcher is always this one, since we set it
  8731. // at the beginning of the render phase and there's no re-entrancy.
  8732. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8733. if (didScheduleRenderPhaseUpdate) {
  8734. // There were render phase updates. These are only valid for this render
  8735. // phase, which we are now aborting. Remove the updates from the queues so
  8736. // they do not persist to the next render. Do not remove updates from hooks
  8737. // that weren't processed.
  8738. //
  8739. // Only reset the updates from the queue if it has a clone. If it does
  8740. // not have a clone, that means it wasn't processed, and the updates were
  8741. // scheduled before we entered the render phase.
  8742. var hook = currentlyRenderingFiber$1.memoizedState;
  8743. while (hook !== null) {
  8744. var queue = hook.queue;
  8745. if (queue !== null) {
  8746. queue.pending = null;
  8747. }
  8748. hook = hook.next;
  8749. }
  8750. }
  8751. renderExpirationTime = NoWork;
  8752. currentlyRenderingFiber$1 = null;
  8753. currentHook = null;
  8754. workInProgressHook = null;
  8755. {
  8756. hookTypesDev = null;
  8757. hookTypesUpdateIndexDev = -1;
  8758. currentHookNameInDev = null;
  8759. }
  8760. didScheduleRenderPhaseUpdate = false;
  8761. }
  8762. function mountWorkInProgressHook() {
  8763. var hook = {
  8764. memoizedState: null,
  8765. baseState: null,
  8766. baseQueue: null,
  8767. queue: null,
  8768. next: null
  8769. };
  8770. if (workInProgressHook === null) {
  8771. // This is the first hook in the list
  8772. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  8773. } else {
  8774. // Append to the end of the list
  8775. workInProgressHook = workInProgressHook.next = hook;
  8776. }
  8777. return workInProgressHook;
  8778. }
  8779. function updateWorkInProgressHook() {
  8780. // This function is used both for updates and for re-renders triggered by a
  8781. // render phase update. It assumes there is either a current hook we can
  8782. // clone, or a work-in-progress hook from a previous render pass that we can
  8783. // use as a base. When we reach the end of the base list, we must switch to
  8784. // the dispatcher used for mounts.
  8785. var nextCurrentHook;
  8786. if (currentHook === null) {
  8787. var current = currentlyRenderingFiber$1.alternate;
  8788. if (current !== null) {
  8789. nextCurrentHook = current.memoizedState;
  8790. } else {
  8791. nextCurrentHook = null;
  8792. }
  8793. } else {
  8794. nextCurrentHook = currentHook.next;
  8795. }
  8796. var nextWorkInProgressHook;
  8797. if (workInProgressHook === null) {
  8798. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  8799. } else {
  8800. nextWorkInProgressHook = workInProgressHook.next;
  8801. }
  8802. if (nextWorkInProgressHook !== null) {
  8803. // There's already a work-in-progress. Reuse it.
  8804. workInProgressHook = nextWorkInProgressHook;
  8805. nextWorkInProgressHook = workInProgressHook.next;
  8806. currentHook = nextCurrentHook;
  8807. } else {
  8808. // Clone from the current hook.
  8809. if (!(nextCurrentHook !== null)) {
  8810. throw Error("Rendered more hooks than during the previous render.");
  8811. }
  8812. currentHook = nextCurrentHook;
  8813. var newHook = {
  8814. memoizedState: currentHook.memoizedState,
  8815. baseState: currentHook.baseState,
  8816. baseQueue: currentHook.baseQueue,
  8817. queue: currentHook.queue,
  8818. next: null
  8819. };
  8820. if (workInProgressHook === null) {
  8821. // This is the first hook in the list.
  8822. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  8823. } else {
  8824. // Append to the end of the list.
  8825. workInProgressHook = workInProgressHook.next = newHook;
  8826. }
  8827. }
  8828. return workInProgressHook;
  8829. }
  8830. function createFunctionComponentUpdateQueue() {
  8831. return {
  8832. lastEffect: null
  8833. };
  8834. }
  8835. function basicStateReducer(state, action) {
  8836. // $FlowFixMe: Flow doesn't like mixed types
  8837. return typeof action === "function" ? action(state) : action;
  8838. }
  8839. function mountReducer(reducer, initialArg, init) {
  8840. var hook = mountWorkInProgressHook();
  8841. var initialState;
  8842. if (init !== undefined) {
  8843. initialState = init(initialArg);
  8844. } else {
  8845. initialState = initialArg;
  8846. }
  8847. hook.memoizedState = hook.baseState = initialState;
  8848. var queue = (hook.queue = {
  8849. pending: null,
  8850. dispatch: null,
  8851. lastRenderedReducer: reducer,
  8852. lastRenderedState: initialState
  8853. });
  8854. var dispatch = (queue.dispatch = dispatchAction.bind(
  8855. null,
  8856. currentlyRenderingFiber$1,
  8857. queue
  8858. ));
  8859. return [hook.memoizedState, dispatch];
  8860. }
  8861. function updateReducer(reducer, initialArg, init) {
  8862. var hook = updateWorkInProgressHook();
  8863. var queue = hook.queue;
  8864. if (!(queue !== null)) {
  8865. throw Error(
  8866. "Should have a queue. This is likely a bug in React. Please file an issue."
  8867. );
  8868. }
  8869. queue.lastRenderedReducer = reducer;
  8870. var current = currentHook; // The last rebase update that is NOT part of the base state.
  8871. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  8872. var pendingQueue = queue.pending;
  8873. if (pendingQueue !== null) {
  8874. // We have new updates that haven't been processed yet.
  8875. // We'll add them to the base queue.
  8876. if (baseQueue !== null) {
  8877. // Merge the pending queue and the base queue.
  8878. var baseFirst = baseQueue.next;
  8879. var pendingFirst = pendingQueue.next;
  8880. baseQueue.next = pendingFirst;
  8881. pendingQueue.next = baseFirst;
  8882. }
  8883. current.baseQueue = baseQueue = pendingQueue;
  8884. queue.pending = null;
  8885. }
  8886. if (baseQueue !== null) {
  8887. // We have a queue to process.
  8888. var first = baseQueue.next;
  8889. var newState = current.baseState;
  8890. var newBaseState = null;
  8891. var newBaseQueueFirst = null;
  8892. var newBaseQueueLast = null;
  8893. var update = first;
  8894. do {
  8895. var updateExpirationTime = update.expirationTime;
  8896. if (updateExpirationTime < renderExpirationTime) {
  8897. // Priority is insufficient. Skip this update. If this is the first
  8898. // skipped update, the previous update/state is the new base
  8899. // update/state.
  8900. var clone = {
  8901. expirationTime: update.expirationTime,
  8902. suspenseConfig: update.suspenseConfig,
  8903. action: update.action,
  8904. eagerReducer: update.eagerReducer,
  8905. eagerState: update.eagerState,
  8906. next: null
  8907. };
  8908. if (newBaseQueueLast === null) {
  8909. newBaseQueueFirst = newBaseQueueLast = clone;
  8910. newBaseState = newState;
  8911. } else {
  8912. newBaseQueueLast = newBaseQueueLast.next = clone;
  8913. } // Update the remaining priority in the queue.
  8914. if (updateExpirationTime > currentlyRenderingFiber$1.expirationTime) {
  8915. currentlyRenderingFiber$1.expirationTime = updateExpirationTime;
  8916. markUnprocessedUpdateTime(updateExpirationTime);
  8917. }
  8918. } else {
  8919. // This update does have sufficient priority.
  8920. if (newBaseQueueLast !== null) {
  8921. var _clone = {
  8922. expirationTime: Sync,
  8923. // This update is going to be committed so we never want uncommit it.
  8924. suspenseConfig: update.suspenseConfig,
  8925. action: update.action,
  8926. eagerReducer: update.eagerReducer,
  8927. eagerState: update.eagerState,
  8928. next: null
  8929. };
  8930. newBaseQueueLast = newBaseQueueLast.next = _clone;
  8931. } // Mark the event time of this update as relevant to this render pass.
  8932. // TODO: This should ideally use the true event time of this update rather than
  8933. // its priority which is a derived and not reverseable value.
  8934. // TODO: We should skip this update if it was already committed but currently
  8935. // we have no way of detecting the difference between a committed and suspended
  8936. // update here.
  8937. markRenderEventTimeAndConfig(
  8938. updateExpirationTime,
  8939. update.suspenseConfig
  8940. ); // Process this update.
  8941. if (update.eagerReducer === reducer) {
  8942. // If this update was processed eagerly, and its reducer matches the
  8943. // current reducer, we can use the eagerly computed state.
  8944. newState = update.eagerState;
  8945. } else {
  8946. var action = update.action;
  8947. newState = reducer(newState, action);
  8948. }
  8949. }
  8950. update = update.next;
  8951. } while (update !== null && update !== first);
  8952. if (newBaseQueueLast === null) {
  8953. newBaseState = newState;
  8954. } else {
  8955. newBaseQueueLast.next = newBaseQueueFirst;
  8956. } // Mark that the fiber performed work, but only if the new state is
  8957. // different from the current state.
  8958. if (!objectIs(newState, hook.memoizedState)) {
  8959. markWorkInProgressReceivedUpdate();
  8960. }
  8961. hook.memoizedState = newState;
  8962. hook.baseState = newBaseState;
  8963. hook.baseQueue = newBaseQueueLast;
  8964. queue.lastRenderedState = newState;
  8965. }
  8966. var dispatch = queue.dispatch;
  8967. return [hook.memoizedState, dispatch];
  8968. }
  8969. function rerenderReducer(reducer, initialArg, init) {
  8970. var hook = updateWorkInProgressHook();
  8971. var queue = hook.queue;
  8972. if (!(queue !== null)) {
  8973. throw Error(
  8974. "Should have a queue. This is likely a bug in React. Please file an issue."
  8975. );
  8976. }
  8977. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  8978. // work-in-progress hook.
  8979. var dispatch = queue.dispatch;
  8980. var lastRenderPhaseUpdate = queue.pending;
  8981. var newState = hook.memoizedState;
  8982. if (lastRenderPhaseUpdate !== null) {
  8983. // The queue doesn't persist past this render pass.
  8984. queue.pending = null;
  8985. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  8986. var update = firstRenderPhaseUpdate;
  8987. do {
  8988. // Process this render phase update. We don't have to check the
  8989. // priority because it will always be the same as the current
  8990. // render's.
  8991. var action = update.action;
  8992. newState = reducer(newState, action);
  8993. update = update.next;
  8994. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  8995. // different from the current state.
  8996. if (!objectIs(newState, hook.memoizedState)) {
  8997. markWorkInProgressReceivedUpdate();
  8998. }
  8999. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  9000. // the base state unless the queue is empty.
  9001. // TODO: Not sure if this is the desired semantics, but it's what we
  9002. // do for gDSFP. I can't remember why.
  9003. if (hook.baseQueue === null) {
  9004. hook.baseState = newState;
  9005. }
  9006. queue.lastRenderedState = newState;
  9007. }
  9008. return [newState, dispatch];
  9009. }
  9010. function mountState(initialState) {
  9011. var hook = mountWorkInProgressHook();
  9012. if (typeof initialState === "function") {
  9013. // $FlowFixMe: Flow doesn't like mixed types
  9014. initialState = initialState();
  9015. }
  9016. hook.memoizedState = hook.baseState = initialState;
  9017. var queue = (hook.queue = {
  9018. pending: null,
  9019. dispatch: null,
  9020. lastRenderedReducer: basicStateReducer,
  9021. lastRenderedState: initialState
  9022. });
  9023. var dispatch = (queue.dispatch = dispatchAction.bind(
  9024. null,
  9025. currentlyRenderingFiber$1,
  9026. queue
  9027. ));
  9028. return [hook.memoizedState, dispatch];
  9029. }
  9030. function updateState(initialState) {
  9031. return updateReducer(basicStateReducer);
  9032. }
  9033. function rerenderState(initialState) {
  9034. return rerenderReducer(basicStateReducer);
  9035. }
  9036. function pushEffect(tag, create, destroy, deps) {
  9037. var effect = {
  9038. tag: tag,
  9039. create: create,
  9040. destroy: destroy,
  9041. deps: deps,
  9042. // Circular
  9043. next: null
  9044. };
  9045. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  9046. if (componentUpdateQueue === null) {
  9047. componentUpdateQueue = createFunctionComponentUpdateQueue();
  9048. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  9049. componentUpdateQueue.lastEffect = effect.next = effect;
  9050. } else {
  9051. var lastEffect = componentUpdateQueue.lastEffect;
  9052. if (lastEffect === null) {
  9053. componentUpdateQueue.lastEffect = effect.next = effect;
  9054. } else {
  9055. var firstEffect = lastEffect.next;
  9056. lastEffect.next = effect;
  9057. effect.next = firstEffect;
  9058. componentUpdateQueue.lastEffect = effect;
  9059. }
  9060. }
  9061. return effect;
  9062. }
  9063. function mountRef(initialValue) {
  9064. var hook = mountWorkInProgressHook();
  9065. var ref = {
  9066. current: initialValue
  9067. };
  9068. {
  9069. Object.seal(ref);
  9070. }
  9071. hook.memoizedState = ref;
  9072. return ref;
  9073. }
  9074. function updateRef(initialValue) {
  9075. var hook = updateWorkInProgressHook();
  9076. return hook.memoizedState;
  9077. }
  9078. function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  9079. var hook = mountWorkInProgressHook();
  9080. var nextDeps = deps === undefined ? null : deps;
  9081. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  9082. hook.memoizedState = pushEffect(
  9083. HasEffect | hookEffectTag,
  9084. create,
  9085. undefined,
  9086. nextDeps
  9087. );
  9088. }
  9089. function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  9090. var hook = updateWorkInProgressHook();
  9091. var nextDeps = deps === undefined ? null : deps;
  9092. var destroy = undefined;
  9093. if (currentHook !== null) {
  9094. var prevEffect = currentHook.memoizedState;
  9095. destroy = prevEffect.destroy;
  9096. if (nextDeps !== null) {
  9097. var prevDeps = prevEffect.deps;
  9098. if (areHookInputsEqual(nextDeps, prevDeps)) {
  9099. pushEffect(hookEffectTag, create, destroy, nextDeps);
  9100. return;
  9101. }
  9102. }
  9103. }
  9104. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  9105. hook.memoizedState = pushEffect(
  9106. HasEffect | hookEffectTag,
  9107. create,
  9108. destroy,
  9109. nextDeps
  9110. );
  9111. }
  9112. function mountEffect(create, deps) {
  9113. {
  9114. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  9115. if ("undefined" !== typeof jest) {
  9116. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  9117. }
  9118. }
  9119. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  9120. }
  9121. function updateEffect(create, deps) {
  9122. {
  9123. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  9124. if ("undefined" !== typeof jest) {
  9125. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  9126. }
  9127. }
  9128. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  9129. }
  9130. function mountLayoutEffect(create, deps) {
  9131. return mountEffectImpl(Update, Layout, create, deps);
  9132. }
  9133. function updateLayoutEffect(create, deps) {
  9134. return updateEffectImpl(Update, Layout, create, deps);
  9135. }
  9136. function imperativeHandleEffect(create, ref) {
  9137. if (typeof ref === "function") {
  9138. var refCallback = ref;
  9139. var _inst = create();
  9140. refCallback(_inst);
  9141. return function() {
  9142. refCallback(null);
  9143. };
  9144. } else if (ref !== null && ref !== undefined) {
  9145. var refObject = ref;
  9146. {
  9147. if (!refObject.hasOwnProperty("current")) {
  9148. error(
  9149. "Expected useImperativeHandle() first argument to either be a " +
  9150. "ref callback or React.createRef() object. Instead received: %s.",
  9151. "an object with keys {" + Object.keys(refObject).join(", ") + "}"
  9152. );
  9153. }
  9154. }
  9155. var _inst2 = create();
  9156. refObject.current = _inst2;
  9157. return function() {
  9158. refObject.current = null;
  9159. };
  9160. }
  9161. }
  9162. function mountImperativeHandle(ref, create, deps) {
  9163. {
  9164. if (typeof create !== "function") {
  9165. error(
  9166. "Expected useImperativeHandle() second argument to be a function " +
  9167. "that creates a handle. Instead received: %s.",
  9168. create !== null ? typeof create : "null"
  9169. );
  9170. }
  9171. } // TODO: If deps are provided, should we skip comparing the ref itself?
  9172. var effectDeps =
  9173. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  9174. return mountEffectImpl(
  9175. Update,
  9176. Layout,
  9177. imperativeHandleEffect.bind(null, create, ref),
  9178. effectDeps
  9179. );
  9180. }
  9181. function updateImperativeHandle(ref, create, deps) {
  9182. {
  9183. if (typeof create !== "function") {
  9184. error(
  9185. "Expected useImperativeHandle() second argument to be a function " +
  9186. "that creates a handle. Instead received: %s.",
  9187. create !== null ? typeof create : "null"
  9188. );
  9189. }
  9190. } // TODO: If deps are provided, should we skip comparing the ref itself?
  9191. var effectDeps =
  9192. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  9193. return updateEffectImpl(
  9194. Update,
  9195. Layout,
  9196. imperativeHandleEffect.bind(null, create, ref),
  9197. effectDeps
  9198. );
  9199. }
  9200. function mountDebugValue(value, formatterFn) {
  9201. // This hook is normally a no-op.
  9202. // The react-debug-hooks package injects its own implementation
  9203. // so that e.g. DevTools can display custom hook values.
  9204. }
  9205. var updateDebugValue = mountDebugValue;
  9206. function mountCallback(callback, deps) {
  9207. var hook = mountWorkInProgressHook();
  9208. var nextDeps = deps === undefined ? null : deps;
  9209. hook.memoizedState = [callback, nextDeps];
  9210. return callback;
  9211. }
  9212. function updateCallback(callback, deps) {
  9213. var hook = updateWorkInProgressHook();
  9214. var nextDeps = deps === undefined ? null : deps;
  9215. var prevState = hook.memoizedState;
  9216. if (prevState !== null) {
  9217. if (nextDeps !== null) {
  9218. var prevDeps = prevState[1];
  9219. if (areHookInputsEqual(nextDeps, prevDeps)) {
  9220. return prevState[0];
  9221. }
  9222. }
  9223. }
  9224. hook.memoizedState = [callback, nextDeps];
  9225. return callback;
  9226. }
  9227. function mountMemo(nextCreate, deps) {
  9228. var hook = mountWorkInProgressHook();
  9229. var nextDeps = deps === undefined ? null : deps;
  9230. var nextValue = nextCreate();
  9231. hook.memoizedState = [nextValue, nextDeps];
  9232. return nextValue;
  9233. }
  9234. function updateMemo(nextCreate, deps) {
  9235. var hook = updateWorkInProgressHook();
  9236. var nextDeps = deps === undefined ? null : deps;
  9237. var prevState = hook.memoizedState;
  9238. if (prevState !== null) {
  9239. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  9240. if (nextDeps !== null) {
  9241. var prevDeps = prevState[1];
  9242. if (areHookInputsEqual(nextDeps, prevDeps)) {
  9243. return prevState[0];
  9244. }
  9245. }
  9246. }
  9247. var nextValue = nextCreate();
  9248. hook.memoizedState = [nextValue, nextDeps];
  9249. return nextValue;
  9250. }
  9251. function mountDeferredValue(value, config) {
  9252. var _mountState = mountState(value),
  9253. prevValue = _mountState[0],
  9254. setValue = _mountState[1];
  9255. mountEffect(
  9256. function() {
  9257. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9258. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9259. try {
  9260. setValue(value);
  9261. } finally {
  9262. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9263. }
  9264. },
  9265. [value, config]
  9266. );
  9267. return prevValue;
  9268. }
  9269. function updateDeferredValue(value, config) {
  9270. var _updateState = updateState(),
  9271. prevValue = _updateState[0],
  9272. setValue = _updateState[1];
  9273. updateEffect(
  9274. function() {
  9275. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9276. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9277. try {
  9278. setValue(value);
  9279. } finally {
  9280. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9281. }
  9282. },
  9283. [value, config]
  9284. );
  9285. return prevValue;
  9286. }
  9287. function rerenderDeferredValue(value, config) {
  9288. var _rerenderState = rerenderState(),
  9289. prevValue = _rerenderState[0],
  9290. setValue = _rerenderState[1];
  9291. updateEffect(
  9292. function() {
  9293. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9294. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9295. try {
  9296. setValue(value);
  9297. } finally {
  9298. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9299. }
  9300. },
  9301. [value, config]
  9302. );
  9303. return prevValue;
  9304. }
  9305. function startTransition(setPending, config, callback) {
  9306. var priorityLevel = getCurrentPriorityLevel();
  9307. runWithPriority(
  9308. priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
  9309. function() {
  9310. setPending(true);
  9311. }
  9312. );
  9313. runWithPriority(
  9314. priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
  9315. function() {
  9316. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9317. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9318. try {
  9319. setPending(false);
  9320. callback();
  9321. } finally {
  9322. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9323. }
  9324. }
  9325. );
  9326. }
  9327. function mountTransition(config) {
  9328. var _mountState2 = mountState(false),
  9329. isPending = _mountState2[0],
  9330. setPending = _mountState2[1];
  9331. var start = mountCallback(startTransition.bind(null, setPending, config), [
  9332. setPending,
  9333. config
  9334. ]);
  9335. return [start, isPending];
  9336. }
  9337. function updateTransition(config) {
  9338. var _updateState2 = updateState(),
  9339. isPending = _updateState2[0],
  9340. setPending = _updateState2[1];
  9341. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9342. setPending,
  9343. config
  9344. ]);
  9345. return [start, isPending];
  9346. }
  9347. function rerenderTransition(config) {
  9348. var _rerenderState2 = rerenderState(),
  9349. isPending = _rerenderState2[0],
  9350. setPending = _rerenderState2[1];
  9351. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9352. setPending,
  9353. config
  9354. ]);
  9355. return [start, isPending];
  9356. }
  9357. function dispatchAction(fiber, queue, action) {
  9358. {
  9359. if (typeof arguments[3] === "function") {
  9360. error(
  9361. "State updates from the useState() and useReducer() Hooks don't support the " +
  9362. "second callback argument. To execute a side effect after " +
  9363. "rendering, declare it in the component body with useEffect()."
  9364. );
  9365. }
  9366. }
  9367. var currentTime = requestCurrentTimeForUpdate();
  9368. var suspenseConfig = requestCurrentSuspenseConfig();
  9369. var expirationTime = computeExpirationForFiber(
  9370. currentTime,
  9371. fiber,
  9372. suspenseConfig
  9373. );
  9374. var update = {
  9375. expirationTime: expirationTime,
  9376. suspenseConfig: suspenseConfig,
  9377. action: action,
  9378. eagerReducer: null,
  9379. eagerState: null,
  9380. next: null
  9381. };
  9382. {
  9383. update.priority = getCurrentPriorityLevel();
  9384. } // Append the update to the end of the list.
  9385. var pending = queue.pending;
  9386. if (pending === null) {
  9387. // This is the first update. Create a circular list.
  9388. update.next = update;
  9389. } else {
  9390. update.next = pending.next;
  9391. pending.next = update;
  9392. }
  9393. queue.pending = update;
  9394. var alternate = fiber.alternate;
  9395. if (
  9396. fiber === currentlyRenderingFiber$1 ||
  9397. (alternate !== null && alternate === currentlyRenderingFiber$1)
  9398. ) {
  9399. // This is a render phase update. Stash it in a lazily-created map of
  9400. // queue -> linked list of updates. After this render pass, we'll restart
  9401. // and apply the stashed updates on top of the work-in-progress hook.
  9402. didScheduleRenderPhaseUpdate = true;
  9403. update.expirationTime = renderExpirationTime;
  9404. currentlyRenderingFiber$1.expirationTime = renderExpirationTime;
  9405. } else {
  9406. if (
  9407. fiber.expirationTime === NoWork &&
  9408. (alternate === null || alternate.expirationTime === NoWork)
  9409. ) {
  9410. // The queue is currently empty, which means we can eagerly compute the
  9411. // next state before entering the render phase. If the new state is the
  9412. // same as the current state, we may be able to bail out entirely.
  9413. var lastRenderedReducer = queue.lastRenderedReducer;
  9414. if (lastRenderedReducer !== null) {
  9415. var prevDispatcher;
  9416. {
  9417. prevDispatcher = ReactCurrentDispatcher.current;
  9418. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9419. }
  9420. try {
  9421. var currentState = queue.lastRenderedState;
  9422. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  9423. // it, on the update object. If the reducer hasn't changed by the
  9424. // time we enter the render phase, then the eager state can be used
  9425. // without calling the reducer again.
  9426. update.eagerReducer = lastRenderedReducer;
  9427. update.eagerState = eagerState;
  9428. if (objectIs(eagerState, currentState)) {
  9429. // Fast path. We can bail out without scheduling React to re-render.
  9430. // It's still possible that we'll need to rebase this update later,
  9431. // if the component re-renders for a different reason and by that
  9432. // time the reducer has changed.
  9433. return;
  9434. }
  9435. } catch (error) {
  9436. // Suppress the error. It will throw again in the render phase.
  9437. } finally {
  9438. {
  9439. ReactCurrentDispatcher.current = prevDispatcher;
  9440. }
  9441. }
  9442. }
  9443. }
  9444. {
  9445. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  9446. if ("undefined" !== typeof jest) {
  9447. warnIfNotScopedWithMatchingAct(fiber);
  9448. warnIfNotCurrentlyActingUpdatesInDev(fiber);
  9449. }
  9450. }
  9451. scheduleWork(fiber, expirationTime);
  9452. }
  9453. }
  9454. function mountEventListener(event) {
  9455. return undefined;
  9456. }
  9457. function updateEventListener(event) {
  9458. return undefined;
  9459. }
  9460. var ContextOnlyDispatcher = {
  9461. readContext: readContext,
  9462. useCallback: throwInvalidHookError,
  9463. useContext: throwInvalidHookError,
  9464. useEffect: throwInvalidHookError,
  9465. useImperativeHandle: throwInvalidHookError,
  9466. useLayoutEffect: throwInvalidHookError,
  9467. useMemo: throwInvalidHookError,
  9468. useReducer: throwInvalidHookError,
  9469. useRef: throwInvalidHookError,
  9470. useState: throwInvalidHookError,
  9471. useDebugValue: throwInvalidHookError,
  9472. useResponder: throwInvalidHookError,
  9473. useDeferredValue: throwInvalidHookError,
  9474. useTransition: throwInvalidHookError,
  9475. useEvent: throwInvalidHookError
  9476. };
  9477. var HooksDispatcherOnMountInDEV = null;
  9478. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  9479. var HooksDispatcherOnUpdateInDEV = null;
  9480. var HooksDispatcherOnRerenderInDEV = null;
  9481. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  9482. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  9483. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  9484. {
  9485. var warnInvalidContextAccess = function() {
  9486. error(
  9487. "Context can only be read while React is rendering. " +
  9488. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  9489. "In function components, you can read it directly in the function body, but not " +
  9490. "inside Hooks like useReducer() or useMemo()."
  9491. );
  9492. };
  9493. var warnInvalidHookAccess = function() {
  9494. error(
  9495. "Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. " +
  9496. "You can only call Hooks at the top level of your React function. " +
  9497. "For more information, see " +
  9498. "https://fb.me/rules-of-hooks"
  9499. );
  9500. };
  9501. HooksDispatcherOnMountInDEV = {
  9502. readContext: function(context, observedBits) {
  9503. return readContext(context, observedBits);
  9504. },
  9505. useCallback: function(callback, deps) {
  9506. currentHookNameInDev = "useCallback";
  9507. mountHookTypesDev();
  9508. checkDepsAreArrayDev(deps);
  9509. return mountCallback(callback, deps);
  9510. },
  9511. useContext: function(context, observedBits) {
  9512. currentHookNameInDev = "useContext";
  9513. mountHookTypesDev();
  9514. return readContext(context, observedBits);
  9515. },
  9516. useEffect: function(create, deps) {
  9517. currentHookNameInDev = "useEffect";
  9518. mountHookTypesDev();
  9519. checkDepsAreArrayDev(deps);
  9520. return mountEffect(create, deps);
  9521. },
  9522. useImperativeHandle: function(ref, create, deps) {
  9523. currentHookNameInDev = "useImperativeHandle";
  9524. mountHookTypesDev();
  9525. checkDepsAreArrayDev(deps);
  9526. return mountImperativeHandle(ref, create, deps);
  9527. },
  9528. useLayoutEffect: function(create, deps) {
  9529. currentHookNameInDev = "useLayoutEffect";
  9530. mountHookTypesDev();
  9531. checkDepsAreArrayDev(deps);
  9532. return mountLayoutEffect(create, deps);
  9533. },
  9534. useMemo: function(create, deps) {
  9535. currentHookNameInDev = "useMemo";
  9536. mountHookTypesDev();
  9537. checkDepsAreArrayDev(deps);
  9538. var prevDispatcher = ReactCurrentDispatcher.current;
  9539. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9540. try {
  9541. return mountMemo(create, deps);
  9542. } finally {
  9543. ReactCurrentDispatcher.current = prevDispatcher;
  9544. }
  9545. },
  9546. useReducer: function(reducer, initialArg, init) {
  9547. currentHookNameInDev = "useReducer";
  9548. mountHookTypesDev();
  9549. var prevDispatcher = ReactCurrentDispatcher.current;
  9550. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9551. try {
  9552. return mountReducer(reducer, initialArg, init);
  9553. } finally {
  9554. ReactCurrentDispatcher.current = prevDispatcher;
  9555. }
  9556. },
  9557. useRef: function(initialValue) {
  9558. currentHookNameInDev = "useRef";
  9559. mountHookTypesDev();
  9560. return mountRef(initialValue);
  9561. },
  9562. useState: function(initialState) {
  9563. currentHookNameInDev = "useState";
  9564. mountHookTypesDev();
  9565. var prevDispatcher = ReactCurrentDispatcher.current;
  9566. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9567. try {
  9568. return mountState(initialState);
  9569. } finally {
  9570. ReactCurrentDispatcher.current = prevDispatcher;
  9571. }
  9572. },
  9573. useDebugValue: function(value, formatterFn) {
  9574. currentHookNameInDev = "useDebugValue";
  9575. mountHookTypesDev();
  9576. return mountDebugValue();
  9577. },
  9578. useResponder: function(responder, props) {
  9579. currentHookNameInDev = "useResponder";
  9580. mountHookTypesDev();
  9581. return createDeprecatedResponderListener(responder, props);
  9582. },
  9583. useDeferredValue: function(value, config) {
  9584. currentHookNameInDev = "useDeferredValue";
  9585. mountHookTypesDev();
  9586. return mountDeferredValue(value, config);
  9587. },
  9588. useTransition: function(config) {
  9589. currentHookNameInDev = "useTransition";
  9590. mountHookTypesDev();
  9591. return mountTransition(config);
  9592. },
  9593. useEvent: function(event) {
  9594. currentHookNameInDev = "useEvent";
  9595. mountHookTypesDev();
  9596. return mountEventListener();
  9597. }
  9598. };
  9599. HooksDispatcherOnMountWithHookTypesInDEV = {
  9600. readContext: function(context, observedBits) {
  9601. return readContext(context, observedBits);
  9602. },
  9603. useCallback: function(callback, deps) {
  9604. currentHookNameInDev = "useCallback";
  9605. updateHookTypesDev();
  9606. return mountCallback(callback, deps);
  9607. },
  9608. useContext: function(context, observedBits) {
  9609. currentHookNameInDev = "useContext";
  9610. updateHookTypesDev();
  9611. return readContext(context, observedBits);
  9612. },
  9613. useEffect: function(create, deps) {
  9614. currentHookNameInDev = "useEffect";
  9615. updateHookTypesDev();
  9616. return mountEffect(create, deps);
  9617. },
  9618. useImperativeHandle: function(ref, create, deps) {
  9619. currentHookNameInDev = "useImperativeHandle";
  9620. updateHookTypesDev();
  9621. return mountImperativeHandle(ref, create, deps);
  9622. },
  9623. useLayoutEffect: function(create, deps) {
  9624. currentHookNameInDev = "useLayoutEffect";
  9625. updateHookTypesDev();
  9626. return mountLayoutEffect(create, deps);
  9627. },
  9628. useMemo: function(create, deps) {
  9629. currentHookNameInDev = "useMemo";
  9630. updateHookTypesDev();
  9631. var prevDispatcher = ReactCurrentDispatcher.current;
  9632. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9633. try {
  9634. return mountMemo(create, deps);
  9635. } finally {
  9636. ReactCurrentDispatcher.current = prevDispatcher;
  9637. }
  9638. },
  9639. useReducer: function(reducer, initialArg, init) {
  9640. currentHookNameInDev = "useReducer";
  9641. updateHookTypesDev();
  9642. var prevDispatcher = ReactCurrentDispatcher.current;
  9643. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9644. try {
  9645. return mountReducer(reducer, initialArg, init);
  9646. } finally {
  9647. ReactCurrentDispatcher.current = prevDispatcher;
  9648. }
  9649. },
  9650. useRef: function(initialValue) {
  9651. currentHookNameInDev = "useRef";
  9652. updateHookTypesDev();
  9653. return mountRef(initialValue);
  9654. },
  9655. useState: function(initialState) {
  9656. currentHookNameInDev = "useState";
  9657. updateHookTypesDev();
  9658. var prevDispatcher = ReactCurrentDispatcher.current;
  9659. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9660. try {
  9661. return mountState(initialState);
  9662. } finally {
  9663. ReactCurrentDispatcher.current = prevDispatcher;
  9664. }
  9665. },
  9666. useDebugValue: function(value, formatterFn) {
  9667. currentHookNameInDev = "useDebugValue";
  9668. updateHookTypesDev();
  9669. return mountDebugValue();
  9670. },
  9671. useResponder: function(responder, props) {
  9672. currentHookNameInDev = "useResponder";
  9673. updateHookTypesDev();
  9674. return createDeprecatedResponderListener(responder, props);
  9675. },
  9676. useDeferredValue: function(value, config) {
  9677. currentHookNameInDev = "useDeferredValue";
  9678. updateHookTypesDev();
  9679. return mountDeferredValue(value, config);
  9680. },
  9681. useTransition: function(config) {
  9682. currentHookNameInDev = "useTransition";
  9683. updateHookTypesDev();
  9684. return mountTransition(config);
  9685. },
  9686. useEvent: function(event) {
  9687. currentHookNameInDev = "useEvent";
  9688. updateHookTypesDev();
  9689. return mountEventListener();
  9690. }
  9691. };
  9692. HooksDispatcherOnUpdateInDEV = {
  9693. readContext: function(context, observedBits) {
  9694. return readContext(context, observedBits);
  9695. },
  9696. useCallback: function(callback, deps) {
  9697. currentHookNameInDev = "useCallback";
  9698. updateHookTypesDev();
  9699. return updateCallback(callback, deps);
  9700. },
  9701. useContext: function(context, observedBits) {
  9702. currentHookNameInDev = "useContext";
  9703. updateHookTypesDev();
  9704. return readContext(context, observedBits);
  9705. },
  9706. useEffect: function(create, deps) {
  9707. currentHookNameInDev = "useEffect";
  9708. updateHookTypesDev();
  9709. return updateEffect(create, deps);
  9710. },
  9711. useImperativeHandle: function(ref, create, deps) {
  9712. currentHookNameInDev = "useImperativeHandle";
  9713. updateHookTypesDev();
  9714. return updateImperativeHandle(ref, create, deps);
  9715. },
  9716. useLayoutEffect: function(create, deps) {
  9717. currentHookNameInDev = "useLayoutEffect";
  9718. updateHookTypesDev();
  9719. return updateLayoutEffect(create, deps);
  9720. },
  9721. useMemo: function(create, deps) {
  9722. currentHookNameInDev = "useMemo";
  9723. updateHookTypesDev();
  9724. var prevDispatcher = ReactCurrentDispatcher.current;
  9725. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9726. try {
  9727. return updateMemo(create, deps);
  9728. } finally {
  9729. ReactCurrentDispatcher.current = prevDispatcher;
  9730. }
  9731. },
  9732. useReducer: function(reducer, initialArg, init) {
  9733. currentHookNameInDev = "useReducer";
  9734. updateHookTypesDev();
  9735. var prevDispatcher = ReactCurrentDispatcher.current;
  9736. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9737. try {
  9738. return updateReducer(reducer, initialArg, init);
  9739. } finally {
  9740. ReactCurrentDispatcher.current = prevDispatcher;
  9741. }
  9742. },
  9743. useRef: function(initialValue) {
  9744. currentHookNameInDev = "useRef";
  9745. updateHookTypesDev();
  9746. return updateRef();
  9747. },
  9748. useState: function(initialState) {
  9749. currentHookNameInDev = "useState";
  9750. updateHookTypesDev();
  9751. var prevDispatcher = ReactCurrentDispatcher.current;
  9752. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9753. try {
  9754. return updateState(initialState);
  9755. } finally {
  9756. ReactCurrentDispatcher.current = prevDispatcher;
  9757. }
  9758. },
  9759. useDebugValue: function(value, formatterFn) {
  9760. currentHookNameInDev = "useDebugValue";
  9761. updateHookTypesDev();
  9762. return updateDebugValue();
  9763. },
  9764. useResponder: function(responder, props) {
  9765. currentHookNameInDev = "useResponder";
  9766. updateHookTypesDev();
  9767. return createDeprecatedResponderListener(responder, props);
  9768. },
  9769. useDeferredValue: function(value, config) {
  9770. currentHookNameInDev = "useDeferredValue";
  9771. updateHookTypesDev();
  9772. return updateDeferredValue(value, config);
  9773. },
  9774. useTransition: function(config) {
  9775. currentHookNameInDev = "useTransition";
  9776. updateHookTypesDev();
  9777. return updateTransition(config);
  9778. },
  9779. useEvent: function(event) {
  9780. currentHookNameInDev = "useEvent";
  9781. updateHookTypesDev();
  9782. return updateEventListener();
  9783. }
  9784. };
  9785. HooksDispatcherOnRerenderInDEV = {
  9786. readContext: function(context, observedBits) {
  9787. return readContext(context, observedBits);
  9788. },
  9789. useCallback: function(callback, deps) {
  9790. currentHookNameInDev = "useCallback";
  9791. updateHookTypesDev();
  9792. return updateCallback(callback, deps);
  9793. },
  9794. useContext: function(context, observedBits) {
  9795. currentHookNameInDev = "useContext";
  9796. updateHookTypesDev();
  9797. return readContext(context, observedBits);
  9798. },
  9799. useEffect: function(create, deps) {
  9800. currentHookNameInDev = "useEffect";
  9801. updateHookTypesDev();
  9802. return updateEffect(create, deps);
  9803. },
  9804. useImperativeHandle: function(ref, create, deps) {
  9805. currentHookNameInDev = "useImperativeHandle";
  9806. updateHookTypesDev();
  9807. return updateImperativeHandle(ref, create, deps);
  9808. },
  9809. useLayoutEffect: function(create, deps) {
  9810. currentHookNameInDev = "useLayoutEffect";
  9811. updateHookTypesDev();
  9812. return updateLayoutEffect(create, deps);
  9813. },
  9814. useMemo: function(create, deps) {
  9815. currentHookNameInDev = "useMemo";
  9816. updateHookTypesDev();
  9817. var prevDispatcher = ReactCurrentDispatcher.current;
  9818. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9819. try {
  9820. return updateMemo(create, deps);
  9821. } finally {
  9822. ReactCurrentDispatcher.current = prevDispatcher;
  9823. }
  9824. },
  9825. useReducer: function(reducer, initialArg, init) {
  9826. currentHookNameInDev = "useReducer";
  9827. updateHookTypesDev();
  9828. var prevDispatcher = ReactCurrentDispatcher.current;
  9829. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9830. try {
  9831. return rerenderReducer(reducer, initialArg, init);
  9832. } finally {
  9833. ReactCurrentDispatcher.current = prevDispatcher;
  9834. }
  9835. },
  9836. useRef: function(initialValue) {
  9837. currentHookNameInDev = "useRef";
  9838. updateHookTypesDev();
  9839. return updateRef();
  9840. },
  9841. useState: function(initialState) {
  9842. currentHookNameInDev = "useState";
  9843. updateHookTypesDev();
  9844. var prevDispatcher = ReactCurrentDispatcher.current;
  9845. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9846. try {
  9847. return rerenderState(initialState);
  9848. } finally {
  9849. ReactCurrentDispatcher.current = prevDispatcher;
  9850. }
  9851. },
  9852. useDebugValue: function(value, formatterFn) {
  9853. currentHookNameInDev = "useDebugValue";
  9854. updateHookTypesDev();
  9855. return updateDebugValue();
  9856. },
  9857. useResponder: function(responder, props) {
  9858. currentHookNameInDev = "useResponder";
  9859. updateHookTypesDev();
  9860. return createDeprecatedResponderListener(responder, props);
  9861. },
  9862. useDeferredValue: function(value, config) {
  9863. currentHookNameInDev = "useDeferredValue";
  9864. updateHookTypesDev();
  9865. return rerenderDeferredValue(value, config);
  9866. },
  9867. useTransition: function(config) {
  9868. currentHookNameInDev = "useTransition";
  9869. updateHookTypesDev();
  9870. return rerenderTransition(config);
  9871. },
  9872. useEvent: function(event) {
  9873. currentHookNameInDev = "useEvent";
  9874. updateHookTypesDev();
  9875. return updateEventListener();
  9876. }
  9877. };
  9878. InvalidNestedHooksDispatcherOnMountInDEV = {
  9879. readContext: function(context, observedBits) {
  9880. warnInvalidContextAccess();
  9881. return readContext(context, observedBits);
  9882. },
  9883. useCallback: function(callback, deps) {
  9884. currentHookNameInDev = "useCallback";
  9885. warnInvalidHookAccess();
  9886. mountHookTypesDev();
  9887. return mountCallback(callback, deps);
  9888. },
  9889. useContext: function(context, observedBits) {
  9890. currentHookNameInDev = "useContext";
  9891. warnInvalidHookAccess();
  9892. mountHookTypesDev();
  9893. return readContext(context, observedBits);
  9894. },
  9895. useEffect: function(create, deps) {
  9896. currentHookNameInDev = "useEffect";
  9897. warnInvalidHookAccess();
  9898. mountHookTypesDev();
  9899. return mountEffect(create, deps);
  9900. },
  9901. useImperativeHandle: function(ref, create, deps) {
  9902. currentHookNameInDev = "useImperativeHandle";
  9903. warnInvalidHookAccess();
  9904. mountHookTypesDev();
  9905. return mountImperativeHandle(ref, create, deps);
  9906. },
  9907. useLayoutEffect: function(create, deps) {
  9908. currentHookNameInDev = "useLayoutEffect";
  9909. warnInvalidHookAccess();
  9910. mountHookTypesDev();
  9911. return mountLayoutEffect(create, deps);
  9912. },
  9913. useMemo: function(create, deps) {
  9914. currentHookNameInDev = "useMemo";
  9915. warnInvalidHookAccess();
  9916. mountHookTypesDev();
  9917. var prevDispatcher = ReactCurrentDispatcher.current;
  9918. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9919. try {
  9920. return mountMemo(create, deps);
  9921. } finally {
  9922. ReactCurrentDispatcher.current = prevDispatcher;
  9923. }
  9924. },
  9925. useReducer: function(reducer, initialArg, init) {
  9926. currentHookNameInDev = "useReducer";
  9927. warnInvalidHookAccess();
  9928. mountHookTypesDev();
  9929. var prevDispatcher = ReactCurrentDispatcher.current;
  9930. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9931. try {
  9932. return mountReducer(reducer, initialArg, init);
  9933. } finally {
  9934. ReactCurrentDispatcher.current = prevDispatcher;
  9935. }
  9936. },
  9937. useRef: function(initialValue) {
  9938. currentHookNameInDev = "useRef";
  9939. warnInvalidHookAccess();
  9940. mountHookTypesDev();
  9941. return mountRef(initialValue);
  9942. },
  9943. useState: function(initialState) {
  9944. currentHookNameInDev = "useState";
  9945. warnInvalidHookAccess();
  9946. mountHookTypesDev();
  9947. var prevDispatcher = ReactCurrentDispatcher.current;
  9948. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9949. try {
  9950. return mountState(initialState);
  9951. } finally {
  9952. ReactCurrentDispatcher.current = prevDispatcher;
  9953. }
  9954. },
  9955. useDebugValue: function(value, formatterFn) {
  9956. currentHookNameInDev = "useDebugValue";
  9957. warnInvalidHookAccess();
  9958. mountHookTypesDev();
  9959. return mountDebugValue();
  9960. },
  9961. useResponder: function(responder, props) {
  9962. currentHookNameInDev = "useResponder";
  9963. warnInvalidHookAccess();
  9964. mountHookTypesDev();
  9965. return createDeprecatedResponderListener(responder, props);
  9966. },
  9967. useDeferredValue: function(value, config) {
  9968. currentHookNameInDev = "useDeferredValue";
  9969. warnInvalidHookAccess();
  9970. mountHookTypesDev();
  9971. return mountDeferredValue(value, config);
  9972. },
  9973. useTransition: function(config) {
  9974. currentHookNameInDev = "useTransition";
  9975. warnInvalidHookAccess();
  9976. mountHookTypesDev();
  9977. return mountTransition(config);
  9978. },
  9979. useEvent: function(event) {
  9980. currentHookNameInDev = "useEvent";
  9981. warnInvalidHookAccess();
  9982. mountHookTypesDev();
  9983. return mountEventListener();
  9984. }
  9985. };
  9986. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  9987. readContext: function(context, observedBits) {
  9988. warnInvalidContextAccess();
  9989. return readContext(context, observedBits);
  9990. },
  9991. useCallback: function(callback, deps) {
  9992. currentHookNameInDev = "useCallback";
  9993. warnInvalidHookAccess();
  9994. updateHookTypesDev();
  9995. return updateCallback(callback, deps);
  9996. },
  9997. useContext: function(context, observedBits) {
  9998. currentHookNameInDev = "useContext";
  9999. warnInvalidHookAccess();
  10000. updateHookTypesDev();
  10001. return readContext(context, observedBits);
  10002. },
  10003. useEffect: function(create, deps) {
  10004. currentHookNameInDev = "useEffect";
  10005. warnInvalidHookAccess();
  10006. updateHookTypesDev();
  10007. return updateEffect(create, deps);
  10008. },
  10009. useImperativeHandle: function(ref, create, deps) {
  10010. currentHookNameInDev = "useImperativeHandle";
  10011. warnInvalidHookAccess();
  10012. updateHookTypesDev();
  10013. return updateImperativeHandle(ref, create, deps);
  10014. },
  10015. useLayoutEffect: function(create, deps) {
  10016. currentHookNameInDev = "useLayoutEffect";
  10017. warnInvalidHookAccess();
  10018. updateHookTypesDev();
  10019. return updateLayoutEffect(create, deps);
  10020. },
  10021. useMemo: function(create, deps) {
  10022. currentHookNameInDev = "useMemo";
  10023. warnInvalidHookAccess();
  10024. updateHookTypesDev();
  10025. var prevDispatcher = ReactCurrentDispatcher.current;
  10026. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10027. try {
  10028. return updateMemo(create, deps);
  10029. } finally {
  10030. ReactCurrentDispatcher.current = prevDispatcher;
  10031. }
  10032. },
  10033. useReducer: function(reducer, initialArg, init) {
  10034. currentHookNameInDev = "useReducer";
  10035. warnInvalidHookAccess();
  10036. updateHookTypesDev();
  10037. var prevDispatcher = ReactCurrentDispatcher.current;
  10038. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10039. try {
  10040. return updateReducer(reducer, initialArg, init);
  10041. } finally {
  10042. ReactCurrentDispatcher.current = prevDispatcher;
  10043. }
  10044. },
  10045. useRef: function(initialValue) {
  10046. currentHookNameInDev = "useRef";
  10047. warnInvalidHookAccess();
  10048. updateHookTypesDev();
  10049. return updateRef();
  10050. },
  10051. useState: function(initialState) {
  10052. currentHookNameInDev = "useState";
  10053. warnInvalidHookAccess();
  10054. updateHookTypesDev();
  10055. var prevDispatcher = ReactCurrentDispatcher.current;
  10056. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10057. try {
  10058. return updateState(initialState);
  10059. } finally {
  10060. ReactCurrentDispatcher.current = prevDispatcher;
  10061. }
  10062. },
  10063. useDebugValue: function(value, formatterFn) {
  10064. currentHookNameInDev = "useDebugValue";
  10065. warnInvalidHookAccess();
  10066. updateHookTypesDev();
  10067. return updateDebugValue();
  10068. },
  10069. useResponder: function(responder, props) {
  10070. currentHookNameInDev = "useResponder";
  10071. warnInvalidHookAccess();
  10072. updateHookTypesDev();
  10073. return createDeprecatedResponderListener(responder, props);
  10074. },
  10075. useDeferredValue: function(value, config) {
  10076. currentHookNameInDev = "useDeferredValue";
  10077. warnInvalidHookAccess();
  10078. updateHookTypesDev();
  10079. return updateDeferredValue(value, config);
  10080. },
  10081. useTransition: function(config) {
  10082. currentHookNameInDev = "useTransition";
  10083. warnInvalidHookAccess();
  10084. updateHookTypesDev();
  10085. return updateTransition(config);
  10086. },
  10087. useEvent: function(event) {
  10088. currentHookNameInDev = "useEvent";
  10089. warnInvalidHookAccess();
  10090. updateHookTypesDev();
  10091. return updateEventListener();
  10092. }
  10093. };
  10094. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  10095. readContext: function(context, observedBits) {
  10096. warnInvalidContextAccess();
  10097. return readContext(context, observedBits);
  10098. },
  10099. useCallback: function(callback, deps) {
  10100. currentHookNameInDev = "useCallback";
  10101. warnInvalidHookAccess();
  10102. updateHookTypesDev();
  10103. return updateCallback(callback, deps);
  10104. },
  10105. useContext: function(context, observedBits) {
  10106. currentHookNameInDev = "useContext";
  10107. warnInvalidHookAccess();
  10108. updateHookTypesDev();
  10109. return readContext(context, observedBits);
  10110. },
  10111. useEffect: function(create, deps) {
  10112. currentHookNameInDev = "useEffect";
  10113. warnInvalidHookAccess();
  10114. updateHookTypesDev();
  10115. return updateEffect(create, deps);
  10116. },
  10117. useImperativeHandle: function(ref, create, deps) {
  10118. currentHookNameInDev = "useImperativeHandle";
  10119. warnInvalidHookAccess();
  10120. updateHookTypesDev();
  10121. return updateImperativeHandle(ref, create, deps);
  10122. },
  10123. useLayoutEffect: function(create, deps) {
  10124. currentHookNameInDev = "useLayoutEffect";
  10125. warnInvalidHookAccess();
  10126. updateHookTypesDev();
  10127. return updateLayoutEffect(create, deps);
  10128. },
  10129. useMemo: function(create, deps) {
  10130. currentHookNameInDev = "useMemo";
  10131. warnInvalidHookAccess();
  10132. updateHookTypesDev();
  10133. var prevDispatcher = ReactCurrentDispatcher.current;
  10134. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10135. try {
  10136. return updateMemo(create, deps);
  10137. } finally {
  10138. ReactCurrentDispatcher.current = prevDispatcher;
  10139. }
  10140. },
  10141. useReducer: function(reducer, initialArg, init) {
  10142. currentHookNameInDev = "useReducer";
  10143. warnInvalidHookAccess();
  10144. updateHookTypesDev();
  10145. var prevDispatcher = ReactCurrentDispatcher.current;
  10146. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10147. try {
  10148. return rerenderReducer(reducer, initialArg, init);
  10149. } finally {
  10150. ReactCurrentDispatcher.current = prevDispatcher;
  10151. }
  10152. },
  10153. useRef: function(initialValue) {
  10154. currentHookNameInDev = "useRef";
  10155. warnInvalidHookAccess();
  10156. updateHookTypesDev();
  10157. return updateRef();
  10158. },
  10159. useState: function(initialState) {
  10160. currentHookNameInDev = "useState";
  10161. warnInvalidHookAccess();
  10162. updateHookTypesDev();
  10163. var prevDispatcher = ReactCurrentDispatcher.current;
  10164. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  10165. try {
  10166. return rerenderState(initialState);
  10167. } finally {
  10168. ReactCurrentDispatcher.current = prevDispatcher;
  10169. }
  10170. },
  10171. useDebugValue: function(value, formatterFn) {
  10172. currentHookNameInDev = "useDebugValue";
  10173. warnInvalidHookAccess();
  10174. updateHookTypesDev();
  10175. return updateDebugValue();
  10176. },
  10177. useResponder: function(responder, props) {
  10178. currentHookNameInDev = "useResponder";
  10179. warnInvalidHookAccess();
  10180. updateHookTypesDev();
  10181. return createDeprecatedResponderListener(responder, props);
  10182. },
  10183. useDeferredValue: function(value, config) {
  10184. currentHookNameInDev = "useDeferredValue";
  10185. warnInvalidHookAccess();
  10186. updateHookTypesDev();
  10187. return rerenderDeferredValue(value, config);
  10188. },
  10189. useTransition: function(config) {
  10190. currentHookNameInDev = "useTransition";
  10191. warnInvalidHookAccess();
  10192. updateHookTypesDev();
  10193. return rerenderTransition(config);
  10194. },
  10195. useEvent: function(event) {
  10196. currentHookNameInDev = "useEvent";
  10197. warnInvalidHookAccess();
  10198. updateHookTypesDev();
  10199. return updateEventListener();
  10200. }
  10201. };
  10202. }
  10203. var now$1 = Scheduler.unstable_now;
  10204. var commitTime = 0;
  10205. var profilerStartTime = -1;
  10206. function getCommitTime() {
  10207. return commitTime;
  10208. }
  10209. function recordCommitTime() {
  10210. commitTime = now$1();
  10211. }
  10212. function startProfilerTimer(fiber) {
  10213. profilerStartTime = now$1();
  10214. if (fiber.actualStartTime < 0) {
  10215. fiber.actualStartTime = now$1();
  10216. }
  10217. }
  10218. function stopProfilerTimerIfRunning(fiber) {
  10219. profilerStartTime = -1;
  10220. }
  10221. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  10222. if (profilerStartTime >= 0) {
  10223. var elapsedTime = now$1() - profilerStartTime;
  10224. fiber.actualDuration += elapsedTime;
  10225. if (overrideBaseTime) {
  10226. fiber.selfBaseDuration = elapsedTime;
  10227. }
  10228. profilerStartTime = -1;
  10229. }
  10230. }
  10231. function enterHydrationState(fiber) {
  10232. {
  10233. return false;
  10234. }
  10235. }
  10236. function prepareToHydrateHostInstance(
  10237. fiber,
  10238. rootContainerInstance,
  10239. hostContext
  10240. ) {
  10241. {
  10242. {
  10243. throw Error(
  10244. "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  10245. );
  10246. }
  10247. }
  10248. }
  10249. function prepareToHydrateHostTextInstance(fiber) {
  10250. {
  10251. {
  10252. throw Error(
  10253. "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  10254. );
  10255. }
  10256. }
  10257. var shouldUpdate = hydrateTextInstance();
  10258. }
  10259. function popHydrationState(fiber) {
  10260. {
  10261. return false;
  10262. }
  10263. }
  10264. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  10265. var didReceiveUpdate = false;
  10266. var didWarnAboutBadClass;
  10267. var didWarnAboutModulePatternComponent;
  10268. var didWarnAboutContextTypeOnFunctionComponent;
  10269. var didWarnAboutGetDerivedStateOnFunctionComponent;
  10270. var didWarnAboutFunctionRefs;
  10271. var didWarnAboutReassigningProps;
  10272. var didWarnAboutRevealOrder;
  10273. var didWarnAboutTailOptions;
  10274. {
  10275. didWarnAboutBadClass = {};
  10276. didWarnAboutModulePatternComponent = {};
  10277. didWarnAboutContextTypeOnFunctionComponent = {};
  10278. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  10279. didWarnAboutFunctionRefs = {};
  10280. didWarnAboutReassigningProps = false;
  10281. didWarnAboutRevealOrder = {};
  10282. didWarnAboutTailOptions = {};
  10283. }
  10284. function reconcileChildren(
  10285. current,
  10286. workInProgress,
  10287. nextChildren,
  10288. renderExpirationTime
  10289. ) {
  10290. if (current === null) {
  10291. // If this is a fresh new component that hasn't been rendered yet, we
  10292. // won't update its child set by applying minimal side-effects. Instead,
  10293. // we will add them all to the child before it gets rendered. That means
  10294. // we can optimize this reconciliation pass by not tracking side-effects.
  10295. workInProgress.child = mountChildFibers(
  10296. workInProgress,
  10297. null,
  10298. nextChildren,
  10299. renderExpirationTime
  10300. );
  10301. } else {
  10302. // If the current child is the same as the work in progress, it means that
  10303. // we haven't yet started any work on these children. Therefore, we use
  10304. // the clone algorithm to create a copy of all the current children.
  10305. // If we had any progressed work already, that is invalid at this point so
  10306. // let's throw it out.
  10307. workInProgress.child = reconcileChildFibers(
  10308. workInProgress,
  10309. current.child,
  10310. nextChildren,
  10311. renderExpirationTime
  10312. );
  10313. }
  10314. }
  10315. function forceUnmountCurrentAndReconcile(
  10316. current,
  10317. workInProgress,
  10318. nextChildren,
  10319. renderExpirationTime
  10320. ) {
  10321. // This function is fork of reconcileChildren. It's used in cases where we
  10322. // want to reconcile without matching against the existing set. This has the
  10323. // effect of all current children being unmounted; even if the type and key
  10324. // are the same, the old child is unmounted and a new child is created.
  10325. //
  10326. // To do this, we're going to go through the reconcile algorithm twice. In
  10327. // the first pass, we schedule a deletion for all the current children by
  10328. // passing null.
  10329. workInProgress.child = reconcileChildFibers(
  10330. workInProgress,
  10331. current.child,
  10332. null,
  10333. renderExpirationTime
  10334. ); // In the second pass, we mount the new children. The trick here is that we
  10335. // pass null in place of where we usually pass the current child set. This has
  10336. // the effect of remounting all children regardless of whether their
  10337. // identities match.
  10338. workInProgress.child = reconcileChildFibers(
  10339. workInProgress,
  10340. null,
  10341. nextChildren,
  10342. renderExpirationTime
  10343. );
  10344. }
  10345. function updateForwardRef(
  10346. current,
  10347. workInProgress,
  10348. Component,
  10349. nextProps,
  10350. renderExpirationTime
  10351. ) {
  10352. // TODO: current can be non-null here even if the component
  10353. // hasn't yet mounted. This happens after the first render suspends.
  10354. // We'll need to figure out if this is fine or can cause issues.
  10355. {
  10356. if (workInProgress.type !== workInProgress.elementType) {
  10357. // Lazy component props can't be validated in createElement
  10358. // because they're only guaranteed to be resolved here.
  10359. var innerPropTypes = Component.propTypes;
  10360. if (innerPropTypes) {
  10361. checkPropTypes(
  10362. innerPropTypes,
  10363. nextProps, // Resolved props
  10364. "prop",
  10365. getComponentName(Component)
  10366. );
  10367. }
  10368. }
  10369. }
  10370. var render = Component.render;
  10371. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  10372. var nextChildren;
  10373. prepareToReadContext(workInProgress, renderExpirationTime);
  10374. {
  10375. ReactCurrentOwner$1.current = workInProgress;
  10376. setIsRendering(true);
  10377. nextChildren = renderWithHooks(
  10378. current,
  10379. workInProgress,
  10380. render,
  10381. nextProps,
  10382. ref,
  10383. renderExpirationTime
  10384. );
  10385. setIsRendering(false);
  10386. }
  10387. if (current !== null && !didReceiveUpdate) {
  10388. bailoutHooks(current, workInProgress, renderExpirationTime);
  10389. return bailoutOnAlreadyFinishedWork(
  10390. current,
  10391. workInProgress,
  10392. renderExpirationTime
  10393. );
  10394. } // React DevTools reads this flag.
  10395. workInProgress.effectTag |= PerformedWork;
  10396. reconcileChildren(
  10397. current,
  10398. workInProgress,
  10399. nextChildren,
  10400. renderExpirationTime
  10401. );
  10402. return workInProgress.child;
  10403. }
  10404. function updateMemoComponent(
  10405. current,
  10406. workInProgress,
  10407. Component,
  10408. nextProps,
  10409. updateExpirationTime,
  10410. renderExpirationTime
  10411. ) {
  10412. if (current === null) {
  10413. var type = Component.type;
  10414. if (
  10415. isSimpleFunctionComponent(type) &&
  10416. Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  10417. Component.defaultProps === undefined
  10418. ) {
  10419. var resolvedType = type;
  10420. {
  10421. resolvedType = resolveFunctionForHotReloading(type);
  10422. } // If this is a plain function component without default props,
  10423. // and with only the default shallow comparison, we upgrade it
  10424. // to a SimpleMemoComponent to allow fast path updates.
  10425. workInProgress.tag = SimpleMemoComponent;
  10426. workInProgress.type = resolvedType;
  10427. {
  10428. validateFunctionComponentInDev(workInProgress, type);
  10429. }
  10430. return updateSimpleMemoComponent(
  10431. current,
  10432. workInProgress,
  10433. resolvedType,
  10434. nextProps,
  10435. updateExpirationTime,
  10436. renderExpirationTime
  10437. );
  10438. }
  10439. {
  10440. var innerPropTypes = type.propTypes;
  10441. if (innerPropTypes) {
  10442. // Inner memo component props aren't currently validated in createElement.
  10443. // We could move it there, but we'd still need this for lazy code path.
  10444. checkPropTypes(
  10445. innerPropTypes,
  10446. nextProps, // Resolved props
  10447. "prop",
  10448. getComponentName(type)
  10449. );
  10450. }
  10451. }
  10452. var child = createFiberFromTypeAndProps(
  10453. Component.type,
  10454. null,
  10455. nextProps,
  10456. null,
  10457. workInProgress.mode,
  10458. renderExpirationTime
  10459. );
  10460. child.ref = workInProgress.ref;
  10461. child.return = workInProgress;
  10462. workInProgress.child = child;
  10463. return child;
  10464. }
  10465. {
  10466. var _type = Component.type;
  10467. var _innerPropTypes = _type.propTypes;
  10468. if (_innerPropTypes) {
  10469. // Inner memo component props aren't currently validated in createElement.
  10470. // We could move it there, but we'd still need this for lazy code path.
  10471. checkPropTypes(
  10472. _innerPropTypes,
  10473. nextProps, // Resolved props
  10474. "prop",
  10475. getComponentName(_type)
  10476. );
  10477. }
  10478. }
  10479. var currentChild = current.child; // This is always exactly one child
  10480. if (updateExpirationTime < renderExpirationTime) {
  10481. // This will be the props with resolved defaultProps,
  10482. // unlike current.memoizedProps which will be the unresolved ones.
  10483. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  10484. var compare = Component.compare;
  10485. compare = compare !== null ? compare : shallowEqual;
  10486. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  10487. return bailoutOnAlreadyFinishedWork(
  10488. current,
  10489. workInProgress,
  10490. renderExpirationTime
  10491. );
  10492. }
  10493. } // React DevTools reads this flag.
  10494. workInProgress.effectTag |= PerformedWork;
  10495. var newChild = createWorkInProgress(currentChild, nextProps);
  10496. newChild.ref = workInProgress.ref;
  10497. newChild.return = workInProgress;
  10498. workInProgress.child = newChild;
  10499. return newChild;
  10500. }
  10501. function updateSimpleMemoComponent(
  10502. current,
  10503. workInProgress,
  10504. Component,
  10505. nextProps,
  10506. updateExpirationTime,
  10507. renderExpirationTime
  10508. ) {
  10509. // TODO: current can be non-null here even if the component
  10510. // hasn't yet mounted. This happens when the inner render suspends.
  10511. // We'll need to figure out if this is fine or can cause issues.
  10512. {
  10513. if (workInProgress.type !== workInProgress.elementType) {
  10514. // Lazy component props can't be validated in createElement
  10515. // because they're only guaranteed to be resolved here.
  10516. var outerMemoType = workInProgress.elementType;
  10517. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  10518. // We warn when you define propTypes on lazy()
  10519. // so let's just skip over it to find memo() outer wrapper.
  10520. // Inner props for memo are validated later.
  10521. outerMemoType = refineResolvedLazyComponent(outerMemoType);
  10522. }
  10523. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  10524. if (outerPropTypes) {
  10525. checkPropTypes(
  10526. outerPropTypes,
  10527. nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  10528. "prop",
  10529. getComponentName(outerMemoType)
  10530. );
  10531. } // Inner propTypes will be validated in the function component path.
  10532. }
  10533. }
  10534. if (current !== null) {
  10535. var prevProps = current.memoizedProps;
  10536. if (
  10537. shallowEqual(prevProps, nextProps) &&
  10538. current.ref === workInProgress.ref && // Prevent bailout if the implementation changed due to hot reload.
  10539. workInProgress.type === current.type
  10540. ) {
  10541. didReceiveUpdate = false;
  10542. if (updateExpirationTime < renderExpirationTime) {
  10543. // The pending update priority was cleared at the beginning of
  10544. // beginWork. We're about to bail out, but there might be additional
  10545. // updates at a lower priority. Usually, the priority level of the
  10546. // remaining updates is accumlated during the evaluation of the
  10547. // component (i.e. when processing the update queue). But since since
  10548. // we're bailing out early *without* evaluating the component, we need
  10549. // to account for it here, too. Reset to the value of the current fiber.
  10550. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  10551. // because a MemoComponent fiber does not have hooks or an update queue;
  10552. // rather, it wraps around an inner component, which may or may not
  10553. // contains hooks.
  10554. // TODO: Move the reset at in beginWork out of the common path so that
  10555. // this is no longer necessary.
  10556. workInProgress.expirationTime = current.expirationTime;
  10557. return bailoutOnAlreadyFinishedWork(
  10558. current,
  10559. workInProgress,
  10560. renderExpirationTime
  10561. );
  10562. }
  10563. }
  10564. }
  10565. return updateFunctionComponent(
  10566. current,
  10567. workInProgress,
  10568. Component,
  10569. nextProps,
  10570. renderExpirationTime
  10571. );
  10572. }
  10573. function updateFragment(current, workInProgress, renderExpirationTime) {
  10574. var nextChildren = workInProgress.pendingProps;
  10575. reconcileChildren(
  10576. current,
  10577. workInProgress,
  10578. nextChildren,
  10579. renderExpirationTime
  10580. );
  10581. return workInProgress.child;
  10582. }
  10583. function updateMode(current, workInProgress, renderExpirationTime) {
  10584. var nextChildren = workInProgress.pendingProps.children;
  10585. reconcileChildren(
  10586. current,
  10587. workInProgress,
  10588. nextChildren,
  10589. renderExpirationTime
  10590. );
  10591. return workInProgress.child;
  10592. }
  10593. function updateProfiler(current, workInProgress, renderExpirationTime) {
  10594. {
  10595. workInProgress.effectTag |= Update; // Reset effect durations for the next eventual effect phase.
  10596. // These are reset during render to allow the DevTools commit hook a chance to read them,
  10597. var stateNode = workInProgress.stateNode;
  10598. stateNode.effectDuration = 0;
  10599. stateNode.passiveEffectDuration = 0;
  10600. }
  10601. var nextProps = workInProgress.pendingProps;
  10602. var nextChildren = nextProps.children;
  10603. reconcileChildren(
  10604. current,
  10605. workInProgress,
  10606. nextChildren,
  10607. renderExpirationTime
  10608. );
  10609. return workInProgress.child;
  10610. }
  10611. function markRef(current, workInProgress) {
  10612. var ref = workInProgress.ref;
  10613. if (
  10614. (current === null && ref !== null) ||
  10615. (current !== null && current.ref !== ref)
  10616. ) {
  10617. // Schedule a Ref effect
  10618. workInProgress.effectTag |= Ref;
  10619. }
  10620. }
  10621. function updateFunctionComponent(
  10622. current,
  10623. workInProgress,
  10624. Component,
  10625. nextProps,
  10626. renderExpirationTime
  10627. ) {
  10628. {
  10629. if (workInProgress.type !== workInProgress.elementType) {
  10630. // Lazy component props can't be validated in createElement
  10631. // because they're only guaranteed to be resolved here.
  10632. var innerPropTypes = Component.propTypes;
  10633. if (innerPropTypes) {
  10634. checkPropTypes(
  10635. innerPropTypes,
  10636. nextProps, // Resolved props
  10637. "prop",
  10638. getComponentName(Component)
  10639. );
  10640. }
  10641. }
  10642. }
  10643. var context;
  10644. {
  10645. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  10646. context = getMaskedContext(workInProgress, unmaskedContext);
  10647. }
  10648. var nextChildren;
  10649. prepareToReadContext(workInProgress, renderExpirationTime);
  10650. {
  10651. ReactCurrentOwner$1.current = workInProgress;
  10652. setIsRendering(true);
  10653. nextChildren = renderWithHooks(
  10654. current,
  10655. workInProgress,
  10656. Component,
  10657. nextProps,
  10658. context,
  10659. renderExpirationTime
  10660. );
  10661. setIsRendering(false);
  10662. }
  10663. if (current !== null && !didReceiveUpdate) {
  10664. bailoutHooks(current, workInProgress, renderExpirationTime);
  10665. return bailoutOnAlreadyFinishedWork(
  10666. current,
  10667. workInProgress,
  10668. renderExpirationTime
  10669. );
  10670. } // React DevTools reads this flag.
  10671. workInProgress.effectTag |= PerformedWork;
  10672. reconcileChildren(
  10673. current,
  10674. workInProgress,
  10675. nextChildren,
  10676. renderExpirationTime
  10677. );
  10678. return workInProgress.child;
  10679. }
  10680. function updateClassComponent(
  10681. current,
  10682. workInProgress,
  10683. Component,
  10684. nextProps,
  10685. renderExpirationTime
  10686. ) {
  10687. {
  10688. if (workInProgress.type !== workInProgress.elementType) {
  10689. // Lazy component props can't be validated in createElement
  10690. // because they're only guaranteed to be resolved here.
  10691. var innerPropTypes = Component.propTypes;
  10692. if (innerPropTypes) {
  10693. checkPropTypes(
  10694. innerPropTypes,
  10695. nextProps, // Resolved props
  10696. "prop",
  10697. getComponentName(Component)
  10698. );
  10699. }
  10700. }
  10701. } // Push context providers early to prevent context stack mismatches.
  10702. // During mounting we don't know the child context yet as the instance doesn't exist.
  10703. // We will invalidate the child context in finishClassComponent() right after rendering.
  10704. var hasContext;
  10705. if (isContextProvider(Component)) {
  10706. hasContext = true;
  10707. pushContextProvider(workInProgress);
  10708. } else {
  10709. hasContext = false;
  10710. }
  10711. prepareToReadContext(workInProgress, renderExpirationTime);
  10712. var instance = workInProgress.stateNode;
  10713. var shouldUpdate;
  10714. if (instance === null) {
  10715. if (current !== null) {
  10716. // A class component without an instance only mounts if it suspended
  10717. // inside a non-concurrent tree, in an inconsistent state. We want to
  10718. // treat it like a new mount, even though an empty version of it already
  10719. // committed. Disconnect the alternate pointers.
  10720. current.alternate = null;
  10721. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10722. workInProgress.effectTag |= Placement;
  10723. } // In the initial pass we might need to construct the instance.
  10724. constructClassInstance(workInProgress, Component, nextProps);
  10725. mountClassInstance(
  10726. workInProgress,
  10727. Component,
  10728. nextProps,
  10729. renderExpirationTime
  10730. );
  10731. shouldUpdate = true;
  10732. } else if (current === null) {
  10733. // In a resume, we'll already have an instance we can reuse.
  10734. shouldUpdate = resumeMountClassInstance(
  10735. workInProgress,
  10736. Component,
  10737. nextProps,
  10738. renderExpirationTime
  10739. );
  10740. } else {
  10741. shouldUpdate = updateClassInstance(
  10742. current,
  10743. workInProgress,
  10744. Component,
  10745. nextProps,
  10746. renderExpirationTime
  10747. );
  10748. }
  10749. var nextUnitOfWork = finishClassComponent(
  10750. current,
  10751. workInProgress,
  10752. Component,
  10753. shouldUpdate,
  10754. hasContext,
  10755. renderExpirationTime
  10756. );
  10757. {
  10758. var inst = workInProgress.stateNode;
  10759. if (inst.props !== nextProps) {
  10760. if (!didWarnAboutReassigningProps) {
  10761. error(
  10762. "It looks like %s is reassigning its own `this.props` while rendering. " +
  10763. "This is not supported and can lead to confusing bugs.",
  10764. getComponentName(workInProgress.type) || "a component"
  10765. );
  10766. }
  10767. didWarnAboutReassigningProps = true;
  10768. }
  10769. }
  10770. return nextUnitOfWork;
  10771. }
  10772. function finishClassComponent(
  10773. current,
  10774. workInProgress,
  10775. Component,
  10776. shouldUpdate,
  10777. hasContext,
  10778. renderExpirationTime
  10779. ) {
  10780. // Refs should update even if shouldComponentUpdate returns false
  10781. markRef(current, workInProgress);
  10782. var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
  10783. if (!shouldUpdate && !didCaptureError) {
  10784. // Context providers should defer to sCU for rendering
  10785. if (hasContext) {
  10786. invalidateContextProvider(workInProgress, Component, false);
  10787. }
  10788. return bailoutOnAlreadyFinishedWork(
  10789. current,
  10790. workInProgress,
  10791. renderExpirationTime
  10792. );
  10793. }
  10794. var instance = workInProgress.stateNode; // Rerender
  10795. ReactCurrentOwner$1.current = workInProgress;
  10796. var nextChildren;
  10797. if (
  10798. didCaptureError &&
  10799. typeof Component.getDerivedStateFromError !== "function"
  10800. ) {
  10801. // If we captured an error, but getDerivedStateFromError is not defined,
  10802. // unmount all the children. componentDidCatch will schedule an update to
  10803. // re-render a fallback. This is temporary until we migrate everyone to
  10804. // the new API.
  10805. // TODO: Warn in a future release.
  10806. nextChildren = null;
  10807. {
  10808. stopProfilerTimerIfRunning();
  10809. }
  10810. } else {
  10811. {
  10812. setIsRendering(true);
  10813. nextChildren = instance.render();
  10814. setIsRendering(false);
  10815. }
  10816. } // React DevTools reads this flag.
  10817. workInProgress.effectTag |= PerformedWork;
  10818. if (current !== null && didCaptureError) {
  10819. // If we're recovering from an error, reconcile without reusing any of
  10820. // the existing children. Conceptually, the normal children and the children
  10821. // that are shown on error are two different sets, so we shouldn't reuse
  10822. // normal children even if their identities match.
  10823. forceUnmountCurrentAndReconcile(
  10824. current,
  10825. workInProgress,
  10826. nextChildren,
  10827. renderExpirationTime
  10828. );
  10829. } else {
  10830. reconcileChildren(
  10831. current,
  10832. workInProgress,
  10833. nextChildren,
  10834. renderExpirationTime
  10835. );
  10836. } // Memoize state using the values we just used to render.
  10837. // TODO: Restructure so we never read values from the instance.
  10838. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  10839. if (hasContext) {
  10840. invalidateContextProvider(workInProgress, Component, true);
  10841. }
  10842. return workInProgress.child;
  10843. }
  10844. function pushHostRootContext(workInProgress) {
  10845. var root = workInProgress.stateNode;
  10846. if (root.pendingContext) {
  10847. pushTopLevelContextObject(
  10848. workInProgress,
  10849. root.pendingContext,
  10850. root.pendingContext !== root.context
  10851. );
  10852. } else if (root.context) {
  10853. // Should always be set
  10854. pushTopLevelContextObject(workInProgress, root.context, false);
  10855. }
  10856. pushHostContainer(workInProgress, root.containerInfo);
  10857. }
  10858. function updateHostRoot(current, workInProgress, renderExpirationTime) {
  10859. pushHostRootContext(workInProgress);
  10860. var updateQueue = workInProgress.updateQueue;
  10861. if (!(current !== null && updateQueue !== null)) {
  10862. throw Error(
  10863. "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."
  10864. );
  10865. }
  10866. var nextProps = workInProgress.pendingProps;
  10867. var prevState = workInProgress.memoizedState;
  10868. var prevChildren = prevState !== null ? prevState.element : null;
  10869. cloneUpdateQueue(current, workInProgress);
  10870. processUpdateQueue(workInProgress, nextProps, null, renderExpirationTime);
  10871. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  10872. // being called "element".
  10873. var nextChildren = nextState.element;
  10874. if (nextChildren === prevChildren) {
  10875. return bailoutOnAlreadyFinishedWork(
  10876. current,
  10877. workInProgress,
  10878. renderExpirationTime
  10879. );
  10880. }
  10881. var root = workInProgress.stateNode;
  10882. if (root.hydrate && enterHydrationState()) {
  10883. // If we don't have any current children this might be the first pass.
  10884. // We always try to hydrate. If this isn't a hydration pass there won't
  10885. // be any children to hydrate which is effectively the same thing as
  10886. // not hydrating.
  10887. var child = mountChildFibers(
  10888. workInProgress,
  10889. null,
  10890. nextChildren,
  10891. renderExpirationTime
  10892. );
  10893. workInProgress.child = child;
  10894. var node = child;
  10895. while (node) {
  10896. // Mark each child as hydrating. This is a fast path to know whether this
  10897. // tree is part of a hydrating tree. This is used to determine if a child
  10898. // node has fully mounted yet, and for scheduling event replaying.
  10899. // Conceptually this is similar to Placement in that a new subtree is
  10900. // inserted into the React tree here. It just happens to not need DOM
  10901. // mutations because it already exists.
  10902. node.effectTag = (node.effectTag & ~Placement) | Hydrating;
  10903. node = node.sibling;
  10904. }
  10905. } else {
  10906. // Otherwise reset hydration state in case we aborted and resumed another
  10907. // root.
  10908. reconcileChildren(
  10909. current,
  10910. workInProgress,
  10911. nextChildren,
  10912. renderExpirationTime
  10913. );
  10914. }
  10915. return workInProgress.child;
  10916. }
  10917. function updateHostComponent(current, workInProgress, renderExpirationTime) {
  10918. pushHostContext(workInProgress);
  10919. var type = workInProgress.type;
  10920. var nextProps = workInProgress.pendingProps;
  10921. var prevProps = current !== null ? current.memoizedProps : null;
  10922. var nextChildren = nextProps.children;
  10923. if (prevProps !== null && shouldSetTextContent()) {
  10924. // If we're switching from a direct text child to a normal child, or to
  10925. // empty, we need to schedule the text content to be reset.
  10926. workInProgress.effectTag |= ContentReset;
  10927. }
  10928. markRef(current, workInProgress); // Check the host config to see if the children are offscreen/hidden.
  10929. if (
  10930. workInProgress.mode & ConcurrentMode &&
  10931. renderExpirationTime !== Never &&
  10932. shouldDeprioritizeSubtree()
  10933. ) {
  10934. {
  10935. markSpawnedWork(Never);
  10936. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  10937. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  10938. return null;
  10939. }
  10940. reconcileChildren(
  10941. current,
  10942. workInProgress,
  10943. nextChildren,
  10944. renderExpirationTime
  10945. );
  10946. return workInProgress.child;
  10947. }
  10948. function updateHostText(current, workInProgress) {
  10949. // immediately after.
  10950. return null;
  10951. }
  10952. function mountLazyComponent(
  10953. _current,
  10954. workInProgress,
  10955. elementType,
  10956. updateExpirationTime,
  10957. renderExpirationTime
  10958. ) {
  10959. if (_current !== null) {
  10960. // A lazy component only mounts if it suspended inside a non-
  10961. // concurrent tree, in an inconsistent state. We want to treat it like
  10962. // a new mount, even though an empty version of it already committed.
  10963. // Disconnect the alternate pointers.
  10964. _current.alternate = null;
  10965. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10966. workInProgress.effectTag |= Placement;
  10967. }
  10968. var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
  10969. // Cancel and resume right after we know the tag.
  10970. cancelWorkTimer(workInProgress);
  10971. var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
  10972. workInProgress.type = Component;
  10973. var resolvedTag = (workInProgress.tag = resolveLazyComponentTag(Component));
  10974. startWorkTimer(workInProgress);
  10975. var resolvedProps = resolveDefaultProps(Component, props);
  10976. var child;
  10977. switch (resolvedTag) {
  10978. case FunctionComponent: {
  10979. {
  10980. validateFunctionComponentInDev(workInProgress, Component);
  10981. workInProgress.type = Component = resolveFunctionForHotReloading(
  10982. Component
  10983. );
  10984. }
  10985. child = updateFunctionComponent(
  10986. null,
  10987. workInProgress,
  10988. Component,
  10989. resolvedProps,
  10990. renderExpirationTime
  10991. );
  10992. return child;
  10993. }
  10994. case ClassComponent: {
  10995. {
  10996. workInProgress.type = Component = resolveClassForHotReloading(
  10997. Component
  10998. );
  10999. }
  11000. child = updateClassComponent(
  11001. null,
  11002. workInProgress,
  11003. Component,
  11004. resolvedProps,
  11005. renderExpirationTime
  11006. );
  11007. return child;
  11008. }
  11009. case ForwardRef: {
  11010. {
  11011. workInProgress.type = Component = resolveForwardRefForHotReloading(
  11012. Component
  11013. );
  11014. }
  11015. child = updateForwardRef(
  11016. null,
  11017. workInProgress,
  11018. Component,
  11019. resolvedProps,
  11020. renderExpirationTime
  11021. );
  11022. return child;
  11023. }
  11024. case MemoComponent: {
  11025. {
  11026. if (workInProgress.type !== workInProgress.elementType) {
  11027. var outerPropTypes = Component.propTypes;
  11028. if (outerPropTypes) {
  11029. checkPropTypes(
  11030. outerPropTypes,
  11031. resolvedProps, // Resolved for outer only
  11032. "prop",
  11033. getComponentName(Component)
  11034. );
  11035. }
  11036. }
  11037. }
  11038. child = updateMemoComponent(
  11039. null,
  11040. workInProgress,
  11041. Component,
  11042. resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  11043. updateExpirationTime,
  11044. renderExpirationTime
  11045. );
  11046. return child;
  11047. }
  11048. }
  11049. var hint = "";
  11050. {
  11051. if (
  11052. Component !== null &&
  11053. typeof Component === "object" &&
  11054. Component.$$typeof === REACT_LAZY_TYPE
  11055. ) {
  11056. hint = " Did you wrap a component in React.lazy() more than once?";
  11057. }
  11058. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  11059. // because the fact that it's a separate type of work is an
  11060. // implementation detail.
  11061. {
  11062. throw Error(
  11063. "Element type is invalid. Received a promise that resolves to: " +
  11064. Component +
  11065. ". Lazy element type must resolve to a class or function." +
  11066. hint
  11067. );
  11068. }
  11069. }
  11070. function mountIncompleteClassComponent(
  11071. _current,
  11072. workInProgress,
  11073. Component,
  11074. nextProps,
  11075. renderExpirationTime
  11076. ) {
  11077. if (_current !== null) {
  11078. // An incomplete component only mounts if it suspended inside a non-
  11079. // concurrent tree, in an inconsistent state. We want to treat it like
  11080. // a new mount, even though an empty version of it already committed.
  11081. // Disconnect the alternate pointers.
  11082. _current.alternate = null;
  11083. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  11084. workInProgress.effectTag |= Placement;
  11085. } // Promote the fiber to a class and try rendering again.
  11086. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  11087. // Push context providers early to prevent context stack mismatches.
  11088. // During mounting we don't know the child context yet as the instance doesn't exist.
  11089. // We will invalidate the child context in finishClassComponent() right after rendering.
  11090. var hasContext;
  11091. if (isContextProvider(Component)) {
  11092. hasContext = true;
  11093. pushContextProvider(workInProgress);
  11094. } else {
  11095. hasContext = false;
  11096. }
  11097. prepareToReadContext(workInProgress, renderExpirationTime);
  11098. constructClassInstance(workInProgress, Component, nextProps);
  11099. mountClassInstance(
  11100. workInProgress,
  11101. Component,
  11102. nextProps,
  11103. renderExpirationTime
  11104. );
  11105. return finishClassComponent(
  11106. null,
  11107. workInProgress,
  11108. Component,
  11109. true,
  11110. hasContext,
  11111. renderExpirationTime
  11112. );
  11113. }
  11114. function mountIndeterminateComponent(
  11115. _current,
  11116. workInProgress,
  11117. Component,
  11118. renderExpirationTime
  11119. ) {
  11120. if (_current !== null) {
  11121. // An indeterminate component only mounts if it suspended inside a non-
  11122. // concurrent tree, in an inconsistent state. We want to treat it like
  11123. // a new mount, even though an empty version of it already committed.
  11124. // Disconnect the alternate pointers.
  11125. _current.alternate = null;
  11126. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  11127. workInProgress.effectTag |= Placement;
  11128. }
  11129. var props = workInProgress.pendingProps;
  11130. var context;
  11131. {
  11132. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  11133. context = getMaskedContext(workInProgress, unmaskedContext);
  11134. }
  11135. prepareToReadContext(workInProgress, renderExpirationTime);
  11136. var value;
  11137. {
  11138. if (
  11139. Component.prototype &&
  11140. typeof Component.prototype.render === "function"
  11141. ) {
  11142. var componentName = getComponentName(Component) || "Unknown";
  11143. if (!didWarnAboutBadClass[componentName]) {
  11144. error(
  11145. "The <%s /> component appears to have a render method, but doesn't extend React.Component. " +
  11146. "This is likely to cause errors. Change %s to extend React.Component instead.",
  11147. componentName,
  11148. componentName
  11149. );
  11150. didWarnAboutBadClass[componentName] = true;
  11151. }
  11152. }
  11153. if (workInProgress.mode & StrictMode) {
  11154. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  11155. }
  11156. ReactCurrentOwner$1.current = workInProgress;
  11157. value = renderWithHooks(
  11158. null,
  11159. workInProgress,
  11160. Component,
  11161. props,
  11162. context,
  11163. renderExpirationTime
  11164. );
  11165. } // React DevTools reads this flag.
  11166. workInProgress.effectTag |= PerformedWork;
  11167. if (
  11168. typeof value === "object" &&
  11169. value !== null &&
  11170. typeof value.render === "function" &&
  11171. value.$$typeof === undefined
  11172. ) {
  11173. {
  11174. var _componentName = getComponentName(Component) || "Unknown";
  11175. if (!didWarnAboutModulePatternComponent[_componentName]) {
  11176. error(
  11177. "The <%s /> component appears to be a function component that returns a class instance. " +
  11178. "Change %s to a class that extends React.Component instead. " +
  11179. "If you can't use a class try assigning the prototype on the function as a workaround. " +
  11180. "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " +
  11181. "cannot be called with `new` by React.",
  11182. _componentName,
  11183. _componentName,
  11184. _componentName
  11185. );
  11186. didWarnAboutModulePatternComponent[_componentName] = true;
  11187. }
  11188. } // Proceed under the assumption that this is a class instance
  11189. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  11190. workInProgress.memoizedState = null;
  11191. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  11192. // During mounting we don't know the child context yet as the instance doesn't exist.
  11193. // We will invalidate the child context in finishClassComponent() right after rendering.
  11194. var hasContext = false;
  11195. if (isContextProvider(Component)) {
  11196. hasContext = true;
  11197. pushContextProvider(workInProgress);
  11198. } else {
  11199. hasContext = false;
  11200. }
  11201. workInProgress.memoizedState =
  11202. value.state !== null && value.state !== undefined ? value.state : null;
  11203. initializeUpdateQueue(workInProgress);
  11204. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  11205. if (typeof getDerivedStateFromProps === "function") {
  11206. applyDerivedStateFromProps(
  11207. workInProgress,
  11208. Component,
  11209. getDerivedStateFromProps,
  11210. props
  11211. );
  11212. }
  11213. adoptClassInstance(workInProgress, value);
  11214. mountClassInstance(workInProgress, Component, props, renderExpirationTime);
  11215. return finishClassComponent(
  11216. null,
  11217. workInProgress,
  11218. Component,
  11219. true,
  11220. hasContext,
  11221. renderExpirationTime
  11222. );
  11223. } else {
  11224. // Proceed under the assumption that this is a function component
  11225. workInProgress.tag = FunctionComponent;
  11226. reconcileChildren(null, workInProgress, value, renderExpirationTime);
  11227. {
  11228. validateFunctionComponentInDev(workInProgress, Component);
  11229. }
  11230. return workInProgress.child;
  11231. }
  11232. }
  11233. function validateFunctionComponentInDev(workInProgress, Component) {
  11234. {
  11235. if (Component) {
  11236. if (Component.childContextTypes) {
  11237. error(
  11238. "%s(...): childContextTypes cannot be defined on a function component.",
  11239. Component.displayName || Component.name || "Component"
  11240. );
  11241. }
  11242. }
  11243. if (workInProgress.ref !== null) {
  11244. var info = "";
  11245. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  11246. if (ownerName) {
  11247. info += "\n\nCheck the render method of `" + ownerName + "`.";
  11248. }
  11249. var warningKey = ownerName || workInProgress._debugID || "";
  11250. var debugSource = workInProgress._debugSource;
  11251. if (debugSource) {
  11252. warningKey = debugSource.fileName + ":" + debugSource.lineNumber;
  11253. }
  11254. if (!didWarnAboutFunctionRefs[warningKey]) {
  11255. didWarnAboutFunctionRefs[warningKey] = true;
  11256. error(
  11257. "Function components cannot be given refs. " +
  11258. "Attempts to access this ref will fail. " +
  11259. "Did you mean to use React.forwardRef()?%s",
  11260. info
  11261. );
  11262. }
  11263. }
  11264. if (typeof Component.getDerivedStateFromProps === "function") {
  11265. var _componentName2 = getComponentName(Component) || "Unknown";
  11266. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
  11267. error(
  11268. "%s: Function components do not support getDerivedStateFromProps.",
  11269. _componentName2
  11270. );
  11271. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
  11272. }
  11273. }
  11274. if (
  11275. typeof Component.contextType === "object" &&
  11276. Component.contextType !== null
  11277. ) {
  11278. var _componentName3 = getComponentName(Component) || "Unknown";
  11279. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
  11280. error(
  11281. "%s: Function components do not support contextType.",
  11282. _componentName3
  11283. );
  11284. didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
  11285. }
  11286. }
  11287. }
  11288. }
  11289. var SUSPENDED_MARKER = {
  11290. dehydrated: null,
  11291. retryTime: NoWork
  11292. };
  11293. function shouldRemainOnFallback(suspenseContext, current, workInProgress) {
  11294. // If the context is telling us that we should show a fallback, and we're not
  11295. // already showing content, then we should show the fallback instead.
  11296. return (
  11297. hasSuspenseContext(suspenseContext, ForceSuspenseFallback) &&
  11298. (current === null || current.memoizedState !== null)
  11299. );
  11300. }
  11301. function updateSuspenseComponent(
  11302. current,
  11303. workInProgress,
  11304. renderExpirationTime
  11305. ) {
  11306. var mode = workInProgress.mode;
  11307. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  11308. {
  11309. if (shouldSuspend(workInProgress)) {
  11310. workInProgress.effectTag |= DidCapture;
  11311. }
  11312. }
  11313. var suspenseContext = suspenseStackCursor.current;
  11314. var nextDidTimeout = false;
  11315. var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
  11316. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  11317. // Something in this boundary's subtree already suspended. Switch to
  11318. // rendering the fallback children.
  11319. nextDidTimeout = true;
  11320. workInProgress.effectTag &= ~DidCapture;
  11321. } else {
  11322. // Attempting the main content
  11323. if (current === null || current.memoizedState !== null) {
  11324. // This is a new mount or this boundary is already showing a fallback state.
  11325. // Mark this subtree context as having at least one invisible parent that could
  11326. // handle the fallback state.
  11327. // Boundaries without fallbacks or should be avoided are not considered since
  11328. // they cannot handle preferred fallback states.
  11329. if (
  11330. nextProps.fallback !== undefined &&
  11331. nextProps.unstable_avoidThisFallback !== true
  11332. ) {
  11333. suspenseContext = addSubtreeSuspenseContext(
  11334. suspenseContext,
  11335. InvisibleParentSuspenseContext
  11336. );
  11337. }
  11338. }
  11339. }
  11340. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11341. pushSuspenseContext(workInProgress, suspenseContext); // This next part is a bit confusing. If the children timeout, we switch to
  11342. // showing the fallback children in place of the "primary" children.
  11343. // However, we don't want to delete the primary children because then their
  11344. // state will be lost (both the React state and the host state, e.g.
  11345. // uncontrolled form inputs). Instead we keep them mounted and hide them.
  11346. // Both the fallback children AND the primary children are rendered at the
  11347. // same time. Once the primary children are un-suspended, we can delete
  11348. // the fallback children — don't need to preserve their state.
  11349. //
  11350. // The two sets of children are siblings in the host environment, but
  11351. // semantically, for purposes of reconciliation, they are two separate sets.
  11352. // So we store them using two fragment fibers.
  11353. //
  11354. // However, we want to avoid allocating extra fibers for every placeholder.
  11355. // They're only necessary when the children time out, because that's the
  11356. // only time when both sets are mounted.
  11357. //
  11358. // So, the extra fragment fibers are only used if the children time out.
  11359. // Otherwise, we render the primary children directly. This requires some
  11360. // custom reconciliation logic to preserve the state of the primary
  11361. // children. It's essentially a very basic form of re-parenting.
  11362. if (current === null) {
  11363. // If we're currently hydrating, try to hydrate this boundary.
  11364. // But only if this has a fallback.
  11365. if (nextProps.fallback !== undefined); // This is the initial mount. This branch is pretty simple because there's
  11366. // no previous state that needs to be preserved.
  11367. if (nextDidTimeout) {
  11368. // Mount separate fragments for primary and fallback children.
  11369. var nextFallbackChildren = nextProps.fallback;
  11370. var primaryChildFragment = createFiberFromFragment(
  11371. null,
  11372. mode,
  11373. NoWork,
  11374. null
  11375. );
  11376. primaryChildFragment.return = workInProgress;
  11377. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11378. // Outside of blocking mode, we commit the effects from the
  11379. // partially completed, timed-out tree, too.
  11380. var progressedState = workInProgress.memoizedState;
  11381. var progressedPrimaryChild =
  11382. progressedState !== null
  11383. ? workInProgress.child.child
  11384. : workInProgress.child;
  11385. primaryChildFragment.child = progressedPrimaryChild;
  11386. var progressedChild = progressedPrimaryChild;
  11387. while (progressedChild !== null) {
  11388. progressedChild.return = primaryChildFragment;
  11389. progressedChild = progressedChild.sibling;
  11390. }
  11391. }
  11392. var fallbackChildFragment = createFiberFromFragment(
  11393. nextFallbackChildren,
  11394. mode,
  11395. renderExpirationTime,
  11396. null
  11397. );
  11398. fallbackChildFragment.return = workInProgress;
  11399. primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
  11400. // fallback children.
  11401. workInProgress.memoizedState = SUSPENDED_MARKER;
  11402. workInProgress.child = primaryChildFragment;
  11403. return fallbackChildFragment;
  11404. } else {
  11405. // Mount the primary children without an intermediate fragment fiber.
  11406. var nextPrimaryChildren = nextProps.children;
  11407. workInProgress.memoizedState = null;
  11408. return (workInProgress.child = mountChildFibers(
  11409. workInProgress,
  11410. null,
  11411. nextPrimaryChildren,
  11412. renderExpirationTime
  11413. ));
  11414. }
  11415. } else {
  11416. // This is an update. This branch is more complicated because we need to
  11417. // ensure the state of the primary children is preserved.
  11418. var prevState = current.memoizedState;
  11419. if (prevState !== null) {
  11420. // wrapped in a fragment fiber.
  11421. var currentPrimaryChildFragment = current.child;
  11422. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  11423. if (nextDidTimeout) {
  11424. // Still timed out. Reuse the current primary children by cloning
  11425. // its fragment. We're going to skip over these entirely.
  11426. var _nextFallbackChildren2 = nextProps.fallback;
  11427. var _primaryChildFragment2 = createWorkInProgress(
  11428. currentPrimaryChildFragment,
  11429. currentPrimaryChildFragment.pendingProps
  11430. );
  11431. _primaryChildFragment2.return = workInProgress;
  11432. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11433. // Outside of blocking mode, we commit the effects from the
  11434. // partially completed, timed-out tree, too.
  11435. var _progressedState = workInProgress.memoizedState;
  11436. var _progressedPrimaryChild =
  11437. _progressedState !== null
  11438. ? workInProgress.child.child
  11439. : workInProgress.child;
  11440. if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
  11441. _primaryChildFragment2.child = _progressedPrimaryChild;
  11442. var _progressedChild2 = _progressedPrimaryChild;
  11443. while (_progressedChild2 !== null) {
  11444. _progressedChild2.return = _primaryChildFragment2;
  11445. _progressedChild2 = _progressedChild2.sibling;
  11446. }
  11447. }
  11448. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11449. // parent of a new tree, we need to set its treeBaseDuration.
  11450. if (workInProgress.mode & ProfileMode) {
  11451. // treeBaseDuration is the sum of all the child tree base durations.
  11452. var _treeBaseDuration = 0;
  11453. var _hiddenChild = _primaryChildFragment2.child;
  11454. while (_hiddenChild !== null) {
  11455. _treeBaseDuration += _hiddenChild.treeBaseDuration;
  11456. _hiddenChild = _hiddenChild.sibling;
  11457. }
  11458. _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
  11459. } // Clone the fallback child fragment, too. These we'll continue
  11460. // working on.
  11461. var _fallbackChildFragment2 = createWorkInProgress(
  11462. currentFallbackChildFragment,
  11463. _nextFallbackChildren2
  11464. );
  11465. _fallbackChildFragment2.return = workInProgress;
  11466. _primaryChildFragment2.sibling = _fallbackChildFragment2;
  11467. _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11468. // fallback children.
  11469. workInProgress.memoizedState = SUSPENDED_MARKER;
  11470. workInProgress.child = _primaryChildFragment2;
  11471. return _fallbackChildFragment2;
  11472. } else {
  11473. // No longer suspended. Switch back to showing the primary children,
  11474. // and remove the intermediate fragment fiber.
  11475. var _nextPrimaryChildren = nextProps.children;
  11476. var currentPrimaryChild = currentPrimaryChildFragment.child;
  11477. var primaryChild = reconcileChildFibers(
  11478. workInProgress,
  11479. currentPrimaryChild,
  11480. _nextPrimaryChildren,
  11481. renderExpirationTime
  11482. ); // If this render doesn't suspend, we need to delete the fallback
  11483. // children. Wait until the complete phase, after we've confirmed the
  11484. // fallback is no longer needed.
  11485. // TODO: Would it be better to store the fallback fragment on
  11486. // the stateNode?
  11487. // Continue rendering the children, like we normally do.
  11488. workInProgress.memoizedState = null;
  11489. return (workInProgress.child = primaryChild);
  11490. }
  11491. } else {
  11492. // The current tree has not already timed out. That means the primary
  11493. // children are not wrapped in a fragment fiber.
  11494. var _currentPrimaryChild = current.child;
  11495. if (nextDidTimeout) {
  11496. // Timed out. Wrap the children in a fragment fiber to keep them
  11497. // separate from the fallback children.
  11498. var _nextFallbackChildren3 = nextProps.fallback;
  11499. var _primaryChildFragment3 = createFiberFromFragment(
  11500. // It shouldn't matter what the pending props are because we aren't
  11501. // going to render this fragment.
  11502. null,
  11503. mode,
  11504. NoWork,
  11505. null
  11506. );
  11507. _primaryChildFragment3.return = workInProgress;
  11508. _primaryChildFragment3.child = _currentPrimaryChild;
  11509. if (_currentPrimaryChild !== null) {
  11510. _currentPrimaryChild.return = _primaryChildFragment3;
  11511. } // Even though we're creating a new fiber, there are no new children,
  11512. // because we're reusing an already mounted tree. So we don't need to
  11513. // schedule a placement.
  11514. // primaryChildFragment.effectTag |= Placement;
  11515. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11516. // Outside of blocking mode, we commit the effects from the
  11517. // partially completed, timed-out tree, too.
  11518. var _progressedState2 = workInProgress.memoizedState;
  11519. var _progressedPrimaryChild2 =
  11520. _progressedState2 !== null
  11521. ? workInProgress.child.child
  11522. : workInProgress.child;
  11523. _primaryChildFragment3.child = _progressedPrimaryChild2;
  11524. var _progressedChild3 = _progressedPrimaryChild2;
  11525. while (_progressedChild3 !== null) {
  11526. _progressedChild3.return = _primaryChildFragment3;
  11527. _progressedChild3 = _progressedChild3.sibling;
  11528. }
  11529. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11530. // parent of a new tree, we need to set its treeBaseDuration.
  11531. if (workInProgress.mode & ProfileMode) {
  11532. // treeBaseDuration is the sum of all the child tree base durations.
  11533. var _treeBaseDuration2 = 0;
  11534. var _hiddenChild2 = _primaryChildFragment3.child;
  11535. while (_hiddenChild2 !== null) {
  11536. _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
  11537. _hiddenChild2 = _hiddenChild2.sibling;
  11538. }
  11539. _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
  11540. } // Create a fragment from the fallback children, too.
  11541. var _fallbackChildFragment3 = createFiberFromFragment(
  11542. _nextFallbackChildren3,
  11543. mode,
  11544. renderExpirationTime,
  11545. null
  11546. );
  11547. _fallbackChildFragment3.return = workInProgress;
  11548. _primaryChildFragment3.sibling = _fallbackChildFragment3;
  11549. _fallbackChildFragment3.effectTag |= Placement;
  11550. _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11551. // fallback children.
  11552. workInProgress.memoizedState = SUSPENDED_MARKER;
  11553. workInProgress.child = _primaryChildFragment3;
  11554. return _fallbackChildFragment3;
  11555. } else {
  11556. // Still haven't timed out. Continue rendering the children, like we
  11557. // normally do.
  11558. workInProgress.memoizedState = null;
  11559. var _nextPrimaryChildren2 = nextProps.children;
  11560. return (workInProgress.child = reconcileChildFibers(
  11561. workInProgress,
  11562. _currentPrimaryChild,
  11563. _nextPrimaryChildren2,
  11564. renderExpirationTime
  11565. ));
  11566. }
  11567. }
  11568. }
  11569. }
  11570. function scheduleWorkOnFiber(fiber, renderExpirationTime) {
  11571. if (fiber.expirationTime < renderExpirationTime) {
  11572. fiber.expirationTime = renderExpirationTime;
  11573. }
  11574. var alternate = fiber.alternate;
  11575. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  11576. alternate.expirationTime = renderExpirationTime;
  11577. }
  11578. scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
  11579. }
  11580. function propagateSuspenseContextChange(
  11581. workInProgress,
  11582. firstChild,
  11583. renderExpirationTime
  11584. ) {
  11585. // Mark any Suspense boundaries with fallbacks as having work to do.
  11586. // If they were previously forced into fallbacks, they may now be able
  11587. // to unblock.
  11588. var node = firstChild;
  11589. while (node !== null) {
  11590. if (node.tag === SuspenseComponent) {
  11591. var state = node.memoizedState;
  11592. if (state !== null) {
  11593. scheduleWorkOnFiber(node, renderExpirationTime);
  11594. }
  11595. } else if (node.tag === SuspenseListComponent) {
  11596. // If the tail is hidden there might not be an Suspense boundaries
  11597. // to schedule work on. In this case we have to schedule it on the
  11598. // list itself.
  11599. // We don't have to traverse to the children of the list since
  11600. // the list will propagate the change when it rerenders.
  11601. scheduleWorkOnFiber(node, renderExpirationTime);
  11602. } else if (node.child !== null) {
  11603. node.child.return = node;
  11604. node = node.child;
  11605. continue;
  11606. }
  11607. if (node === workInProgress) {
  11608. return;
  11609. }
  11610. while (node.sibling === null) {
  11611. if (node.return === null || node.return === workInProgress) {
  11612. return;
  11613. }
  11614. node = node.return;
  11615. }
  11616. node.sibling.return = node.return;
  11617. node = node.sibling;
  11618. }
  11619. }
  11620. function findLastContentRow(firstChild) {
  11621. // This is going to find the last row among these children that is already
  11622. // showing content on the screen, as opposed to being in fallback state or
  11623. // new. If a row has multiple Suspense boundaries, any of them being in the
  11624. // fallback state, counts as the whole row being in a fallback state.
  11625. // Note that the "rows" will be workInProgress, but any nested children
  11626. // will still be current since we haven't rendered them yet. The mounted
  11627. // order may not be the same as the new order. We use the new order.
  11628. var row = firstChild;
  11629. var lastContentRow = null;
  11630. while (row !== null) {
  11631. var currentRow = row.alternate; // New rows can't be content rows.
  11632. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11633. lastContentRow = row;
  11634. }
  11635. row = row.sibling;
  11636. }
  11637. return lastContentRow;
  11638. }
  11639. function validateRevealOrder(revealOrder) {
  11640. {
  11641. if (
  11642. revealOrder !== undefined &&
  11643. revealOrder !== "forwards" &&
  11644. revealOrder !== "backwards" &&
  11645. revealOrder !== "together" &&
  11646. !didWarnAboutRevealOrder[revealOrder]
  11647. ) {
  11648. didWarnAboutRevealOrder[revealOrder] = true;
  11649. if (typeof revealOrder === "string") {
  11650. switch (revealOrder.toLowerCase()) {
  11651. case "together":
  11652. case "forwards":
  11653. case "backwards": {
  11654. error(
  11655. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11656. 'Use lowercase "%s" instead.',
  11657. revealOrder,
  11658. revealOrder.toLowerCase()
  11659. );
  11660. break;
  11661. }
  11662. case "forward":
  11663. case "backward": {
  11664. error(
  11665. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11666. 'React uses the -s suffix in the spelling. Use "%ss" instead.',
  11667. revealOrder,
  11668. revealOrder.toLowerCase()
  11669. );
  11670. break;
  11671. }
  11672. default:
  11673. error(
  11674. '"%s" is not a supported revealOrder on <SuspenseList />. ' +
  11675. 'Did you mean "together", "forwards" or "backwards"?',
  11676. revealOrder
  11677. );
  11678. break;
  11679. }
  11680. } else {
  11681. error(
  11682. "%s is not a supported value for revealOrder on <SuspenseList />. " +
  11683. 'Did you mean "together", "forwards" or "backwards"?',
  11684. revealOrder
  11685. );
  11686. }
  11687. }
  11688. }
  11689. }
  11690. function validateTailOptions(tailMode, revealOrder) {
  11691. {
  11692. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  11693. if (tailMode !== "collapsed" && tailMode !== "hidden") {
  11694. didWarnAboutTailOptions[tailMode] = true;
  11695. error(
  11696. '"%s" is not a supported value for tail on <SuspenseList />. ' +
  11697. 'Did you mean "collapsed" or "hidden"?',
  11698. tailMode
  11699. );
  11700. } else if (revealOrder !== "forwards" && revealOrder !== "backwards") {
  11701. didWarnAboutTailOptions[tailMode] = true;
  11702. error(
  11703. '<SuspenseList tail="%s" /> is only valid if revealOrder is ' +
  11704. '"forwards" or "backwards". ' +
  11705. 'Did you mean to specify revealOrder="forwards"?',
  11706. tailMode
  11707. );
  11708. }
  11709. }
  11710. }
  11711. }
  11712. function validateSuspenseListNestedChild(childSlot, index) {
  11713. {
  11714. var isArray = Array.isArray(childSlot);
  11715. var isIterable = !isArray && typeof getIteratorFn(childSlot) === "function";
  11716. if (isArray || isIterable) {
  11717. var type = isArray ? "array" : "iterable";
  11718. error(
  11719. "A nested %s was passed to row #%s in <SuspenseList />. Wrap it in " +
  11720. "an additional SuspenseList to configure its revealOrder: " +
  11721. "<SuspenseList revealOrder=...> ... " +
  11722. "<SuspenseList revealOrder=...>{%s}</SuspenseList> ... " +
  11723. "</SuspenseList>",
  11724. type,
  11725. index,
  11726. type
  11727. );
  11728. return false;
  11729. }
  11730. }
  11731. return true;
  11732. }
  11733. function validateSuspenseListChildren(children, revealOrder) {
  11734. {
  11735. if (
  11736. (revealOrder === "forwards" || revealOrder === "backwards") &&
  11737. children !== undefined &&
  11738. children !== null &&
  11739. children !== false
  11740. ) {
  11741. if (Array.isArray(children)) {
  11742. for (var i = 0; i < children.length; i++) {
  11743. if (!validateSuspenseListNestedChild(children[i], i)) {
  11744. return;
  11745. }
  11746. }
  11747. } else {
  11748. var iteratorFn = getIteratorFn(children);
  11749. if (typeof iteratorFn === "function") {
  11750. var childrenIterator = iteratorFn.call(children);
  11751. if (childrenIterator) {
  11752. var step = childrenIterator.next();
  11753. var _i = 0;
  11754. for (; !step.done; step = childrenIterator.next()) {
  11755. if (!validateSuspenseListNestedChild(step.value, _i)) {
  11756. return;
  11757. }
  11758. _i++;
  11759. }
  11760. }
  11761. } else {
  11762. error(
  11763. 'A single row was passed to a <SuspenseList revealOrder="%s" />. ' +
  11764. "This is not useful since it needs multiple rows. " +
  11765. "Did you mean to pass multiple children or an array?",
  11766. revealOrder
  11767. );
  11768. }
  11769. }
  11770. }
  11771. }
  11772. }
  11773. function initSuspenseListRenderState(
  11774. workInProgress,
  11775. isBackwards,
  11776. tail,
  11777. lastContentRow,
  11778. tailMode,
  11779. lastEffectBeforeRendering
  11780. ) {
  11781. var renderState = workInProgress.memoizedState;
  11782. if (renderState === null) {
  11783. workInProgress.memoizedState = {
  11784. isBackwards: isBackwards,
  11785. rendering: null,
  11786. renderingStartTime: 0,
  11787. last: lastContentRow,
  11788. tail: tail,
  11789. tailExpiration: 0,
  11790. tailMode: tailMode,
  11791. lastEffect: lastEffectBeforeRendering
  11792. };
  11793. } else {
  11794. // We can reuse the existing object from previous renders.
  11795. renderState.isBackwards = isBackwards;
  11796. renderState.rendering = null;
  11797. renderState.renderingStartTime = 0;
  11798. renderState.last = lastContentRow;
  11799. renderState.tail = tail;
  11800. renderState.tailExpiration = 0;
  11801. renderState.tailMode = tailMode;
  11802. renderState.lastEffect = lastEffectBeforeRendering;
  11803. }
  11804. } // This can end up rendering this component multiple passes.
  11805. // The first pass splits the children fibers into two sets. A head and tail.
  11806. // We first render the head. If anything is in fallback state, we do another
  11807. // pass through beginWork to rerender all children (including the tail) with
  11808. // the force suspend context. If the first render didn't have anything in
  11809. // in fallback state. Then we render each row in the tail one-by-one.
  11810. // That happens in the completeWork phase without going back to beginWork.
  11811. function updateSuspenseListComponent(
  11812. current,
  11813. workInProgress,
  11814. renderExpirationTime
  11815. ) {
  11816. var nextProps = workInProgress.pendingProps;
  11817. var revealOrder = nextProps.revealOrder;
  11818. var tailMode = nextProps.tail;
  11819. var newChildren = nextProps.children;
  11820. validateRevealOrder(revealOrder);
  11821. validateTailOptions(tailMode, revealOrder);
  11822. validateSuspenseListChildren(newChildren, revealOrder);
  11823. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11824. var suspenseContext = suspenseStackCursor.current;
  11825. var shouldForceFallback = hasSuspenseContext(
  11826. suspenseContext,
  11827. ForceSuspenseFallback
  11828. );
  11829. if (shouldForceFallback) {
  11830. suspenseContext = setShallowSuspenseContext(
  11831. suspenseContext,
  11832. ForceSuspenseFallback
  11833. );
  11834. workInProgress.effectTag |= DidCapture;
  11835. } else {
  11836. var didSuspendBefore =
  11837. current !== null && (current.effectTag & DidCapture) !== NoEffect;
  11838. if (didSuspendBefore) {
  11839. // If we previously forced a fallback, we need to schedule work
  11840. // on any nested boundaries to let them know to try to render
  11841. // again. This is the same as context updating.
  11842. propagateSuspenseContextChange(
  11843. workInProgress,
  11844. workInProgress.child,
  11845. renderExpirationTime
  11846. );
  11847. }
  11848. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11849. }
  11850. pushSuspenseContext(workInProgress, suspenseContext);
  11851. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11852. // Outside of blocking mode, SuspenseList doesn't work so we just
  11853. // use make it a noop by treating it as the default revealOrder.
  11854. workInProgress.memoizedState = null;
  11855. } else {
  11856. switch (revealOrder) {
  11857. case "forwards": {
  11858. var lastContentRow = findLastContentRow(workInProgress.child);
  11859. var tail;
  11860. if (lastContentRow === null) {
  11861. // The whole list is part of the tail.
  11862. // TODO: We could fast path by just rendering the tail now.
  11863. tail = workInProgress.child;
  11864. workInProgress.child = null;
  11865. } else {
  11866. // Disconnect the tail rows after the content row.
  11867. // We're going to render them separately later.
  11868. tail = lastContentRow.sibling;
  11869. lastContentRow.sibling = null;
  11870. }
  11871. initSuspenseListRenderState(
  11872. workInProgress,
  11873. false, // isBackwards
  11874. tail,
  11875. lastContentRow,
  11876. tailMode,
  11877. workInProgress.lastEffect
  11878. );
  11879. break;
  11880. }
  11881. case "backwards": {
  11882. // We're going to find the first row that has existing content.
  11883. // At the same time we're going to reverse the list of everything
  11884. // we pass in the meantime. That's going to be our tail in reverse
  11885. // order.
  11886. var _tail = null;
  11887. var row = workInProgress.child;
  11888. workInProgress.child = null;
  11889. while (row !== null) {
  11890. var currentRow = row.alternate; // New rows can't be content rows.
  11891. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11892. // This is the beginning of the main content.
  11893. workInProgress.child = row;
  11894. break;
  11895. }
  11896. var nextRow = row.sibling;
  11897. row.sibling = _tail;
  11898. _tail = row;
  11899. row = nextRow;
  11900. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  11901. initSuspenseListRenderState(
  11902. workInProgress,
  11903. true, // isBackwards
  11904. _tail,
  11905. null, // last
  11906. tailMode,
  11907. workInProgress.lastEffect
  11908. );
  11909. break;
  11910. }
  11911. case "together": {
  11912. initSuspenseListRenderState(
  11913. workInProgress,
  11914. false, // isBackwards
  11915. null, // tail
  11916. null, // last
  11917. undefined,
  11918. workInProgress.lastEffect
  11919. );
  11920. break;
  11921. }
  11922. default: {
  11923. // The default reveal order is the same as not having
  11924. // a boundary.
  11925. workInProgress.memoizedState = null;
  11926. }
  11927. }
  11928. }
  11929. return workInProgress.child;
  11930. }
  11931. function updatePortalComponent(current, workInProgress, renderExpirationTime) {
  11932. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  11933. var nextChildren = workInProgress.pendingProps;
  11934. if (current === null) {
  11935. // Portals are special because we don't append the children during mount
  11936. // but at commit. Therefore we need to track insertions which the normal
  11937. // flow doesn't do during mount. This doesn't happen at the root because
  11938. // the root always starts with a "current" with a null child.
  11939. // TODO: Consider unifying this with how the root works.
  11940. workInProgress.child = reconcileChildFibers(
  11941. workInProgress,
  11942. null,
  11943. nextChildren,
  11944. renderExpirationTime
  11945. );
  11946. } else {
  11947. reconcileChildren(
  11948. current,
  11949. workInProgress,
  11950. nextChildren,
  11951. renderExpirationTime
  11952. );
  11953. }
  11954. return workInProgress.child;
  11955. }
  11956. function updateContextProvider(current, workInProgress, renderExpirationTime) {
  11957. var providerType = workInProgress.type;
  11958. var context = providerType._context;
  11959. var newProps = workInProgress.pendingProps;
  11960. var oldProps = workInProgress.memoizedProps;
  11961. var newValue = newProps.value;
  11962. {
  11963. var providerPropTypes = workInProgress.type.propTypes;
  11964. if (providerPropTypes) {
  11965. checkPropTypes(providerPropTypes, newProps, "prop", "Context.Provider");
  11966. }
  11967. }
  11968. pushProvider(workInProgress, newValue);
  11969. if (oldProps !== null) {
  11970. var oldValue = oldProps.value;
  11971. var changedBits = calculateChangedBits(context, newValue, oldValue);
  11972. if (changedBits === 0) {
  11973. // No change. Bailout early if children are the same.
  11974. if (oldProps.children === newProps.children && !hasContextChanged()) {
  11975. return bailoutOnAlreadyFinishedWork(
  11976. current,
  11977. workInProgress,
  11978. renderExpirationTime
  11979. );
  11980. }
  11981. } else {
  11982. // The context value changed. Search for matching consumers and schedule
  11983. // them to update.
  11984. propagateContextChange(
  11985. workInProgress,
  11986. context,
  11987. changedBits,
  11988. renderExpirationTime
  11989. );
  11990. }
  11991. }
  11992. var newChildren = newProps.children;
  11993. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11994. return workInProgress.child;
  11995. }
  11996. var hasWarnedAboutUsingContextAsConsumer = false;
  11997. function updateContextConsumer(current, workInProgress, renderExpirationTime) {
  11998. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  11999. // DEV mode, we create a separate object for Context.Consumer that acts
  12000. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  12001. // so we use the old behaviour (Context.Consumer references Context) to
  12002. // reduce size and overhead. The separate object references context via
  12003. // a property called "_context", which also gives us the ability to check
  12004. // in DEV mode if this property exists or not and warn if it does not.
  12005. {
  12006. if (context._context === undefined) {
  12007. // This may be because it's a Context (rather than a Consumer).
  12008. // Or it may be because it's older React where they're the same thing.
  12009. // We only want to warn if we're sure it's a new React.
  12010. if (context !== context.Consumer) {
  12011. if (!hasWarnedAboutUsingContextAsConsumer) {
  12012. hasWarnedAboutUsingContextAsConsumer = true;
  12013. error(
  12014. "Rendering <Context> directly is not supported and will be removed in " +
  12015. "a future major release. Did you mean to render <Context.Consumer> instead?"
  12016. );
  12017. }
  12018. }
  12019. } else {
  12020. context = context._context;
  12021. }
  12022. }
  12023. var newProps = workInProgress.pendingProps;
  12024. var render = newProps.children;
  12025. {
  12026. if (typeof render !== "function") {
  12027. error(
  12028. "A context consumer was rendered with multiple children, or a child " +
  12029. "that isn't a function. A context consumer expects a single child " +
  12030. "that is a function. If you did pass a function, make sure there " +
  12031. "is no trailing or leading whitespace around it."
  12032. );
  12033. }
  12034. }
  12035. prepareToReadContext(workInProgress, renderExpirationTime);
  12036. var newValue = readContext(context, newProps.unstable_observedBits);
  12037. var newChildren;
  12038. {
  12039. ReactCurrentOwner$1.current = workInProgress;
  12040. setIsRendering(true);
  12041. newChildren = render(newValue);
  12042. setIsRendering(false);
  12043. } // React DevTools reads this flag.
  12044. workInProgress.effectTag |= PerformedWork;
  12045. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  12046. return workInProgress.child;
  12047. }
  12048. function markWorkInProgressReceivedUpdate() {
  12049. didReceiveUpdate = true;
  12050. }
  12051. function bailoutOnAlreadyFinishedWork(
  12052. current,
  12053. workInProgress,
  12054. renderExpirationTime
  12055. ) {
  12056. cancelWorkTimer(workInProgress);
  12057. if (current !== null) {
  12058. // Reuse previous dependencies
  12059. workInProgress.dependencies = current.dependencies;
  12060. }
  12061. {
  12062. // Don't update "base" render times for bailouts.
  12063. stopProfilerTimerIfRunning();
  12064. }
  12065. var updateExpirationTime = workInProgress.expirationTime;
  12066. if (updateExpirationTime !== NoWork) {
  12067. markUnprocessedUpdateTime(updateExpirationTime);
  12068. } // Check if the children have any pending work.
  12069. var childExpirationTime = workInProgress.childExpirationTime;
  12070. if (childExpirationTime < renderExpirationTime) {
  12071. // The children don't have any work either. We can skip them.
  12072. // TODO: Once we add back resuming, we should check if the children are
  12073. // a work-in-progress set. If so, we need to transfer their effects.
  12074. return null;
  12075. } else {
  12076. // This fiber doesn't have work, but its subtree does. Clone the child
  12077. // fibers and continue.
  12078. cloneChildFibers(current, workInProgress);
  12079. return workInProgress.child;
  12080. }
  12081. }
  12082. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  12083. {
  12084. var returnFiber = oldWorkInProgress.return;
  12085. if (returnFiber === null) {
  12086. throw new Error("Cannot swap the root fiber.");
  12087. } // Disconnect from the old current.
  12088. // It will get deleted.
  12089. current.alternate = null;
  12090. oldWorkInProgress.alternate = null; // Connect to the new tree.
  12091. newWorkInProgress.index = oldWorkInProgress.index;
  12092. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  12093. newWorkInProgress.return = oldWorkInProgress.return;
  12094. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  12095. if (oldWorkInProgress === returnFiber.child) {
  12096. returnFiber.child = newWorkInProgress;
  12097. } else {
  12098. var prevSibling = returnFiber.child;
  12099. if (prevSibling === null) {
  12100. throw new Error("Expected parent to have a child.");
  12101. }
  12102. while (prevSibling.sibling !== oldWorkInProgress) {
  12103. prevSibling = prevSibling.sibling;
  12104. if (prevSibling === null) {
  12105. throw new Error("Expected to find the previous sibling.");
  12106. }
  12107. }
  12108. prevSibling.sibling = newWorkInProgress;
  12109. } // Delete the old fiber and place the new one.
  12110. // Since the old fiber is disconnected, we have to schedule it manually.
  12111. var last = returnFiber.lastEffect;
  12112. if (last !== null) {
  12113. last.nextEffect = current;
  12114. returnFiber.lastEffect = current;
  12115. } else {
  12116. returnFiber.firstEffect = returnFiber.lastEffect = current;
  12117. }
  12118. current.nextEffect = null;
  12119. current.effectTag = Deletion;
  12120. newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
  12121. return newWorkInProgress;
  12122. }
  12123. }
  12124. function beginWork(current, workInProgress, renderExpirationTime) {
  12125. var updateExpirationTime = workInProgress.expirationTime;
  12126. {
  12127. if (workInProgress._debugNeedsRemount && current !== null) {
  12128. // This will restart the begin phase with a new fiber.
  12129. return remountFiber(
  12130. current,
  12131. workInProgress,
  12132. createFiberFromTypeAndProps(
  12133. workInProgress.type,
  12134. workInProgress.key,
  12135. workInProgress.pendingProps,
  12136. workInProgress._debugOwner || null,
  12137. workInProgress.mode,
  12138. workInProgress.expirationTime
  12139. )
  12140. );
  12141. }
  12142. }
  12143. if (current !== null) {
  12144. var oldProps = current.memoizedProps;
  12145. var newProps = workInProgress.pendingProps;
  12146. if (
  12147. oldProps !== newProps ||
  12148. hasContextChanged() || // Force a re-render if the implementation changed due to hot reload:
  12149. workInProgress.type !== current.type
  12150. ) {
  12151. // If props or context changed, mark the fiber as having performed work.
  12152. // This may be unset if the props are determined to be equal later (memo).
  12153. didReceiveUpdate = true;
  12154. } else if (updateExpirationTime < renderExpirationTime) {
  12155. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  12156. // the begin phase. There's still some bookkeeping we that needs to be done
  12157. // in this optimized path, mostly pushing stuff onto the stack.
  12158. switch (workInProgress.tag) {
  12159. case HostRoot:
  12160. pushHostRootContext(workInProgress);
  12161. break;
  12162. case HostComponent:
  12163. pushHostContext(workInProgress);
  12164. if (
  12165. workInProgress.mode & ConcurrentMode &&
  12166. renderExpirationTime !== Never &&
  12167. shouldDeprioritizeSubtree(workInProgress.type)
  12168. ) {
  12169. {
  12170. markSpawnedWork(Never);
  12171. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  12172. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  12173. return null;
  12174. }
  12175. break;
  12176. case ClassComponent: {
  12177. var Component = workInProgress.type;
  12178. if (isContextProvider(Component)) {
  12179. pushContextProvider(workInProgress);
  12180. }
  12181. break;
  12182. }
  12183. case HostPortal:
  12184. pushHostContainer(
  12185. workInProgress,
  12186. workInProgress.stateNode.containerInfo
  12187. );
  12188. break;
  12189. case ContextProvider: {
  12190. var newValue = workInProgress.memoizedProps.value;
  12191. pushProvider(workInProgress, newValue);
  12192. break;
  12193. }
  12194. case Profiler:
  12195. {
  12196. // Profiler should only call onRender when one of its descendants actually rendered.
  12197. var hasChildWork =
  12198. workInProgress.childExpirationTime >= renderExpirationTime;
  12199. if (hasChildWork) {
  12200. workInProgress.effectTag |= Update;
  12201. } // Reset effect durations for the next eventual effect phase.
  12202. // These are reset during render to allow the DevTools commit hook a chance to read them,
  12203. var stateNode = workInProgress.stateNode;
  12204. stateNode.effectDuration = 0;
  12205. stateNode.passiveEffectDuration = 0;
  12206. }
  12207. break;
  12208. case SuspenseComponent: {
  12209. var state = workInProgress.memoizedState;
  12210. if (state !== null) {
  12211. // whether to retry the primary children, or to skip over it and
  12212. // go straight to the fallback. Check the priority of the primary
  12213. // child fragment.
  12214. var primaryChildFragment = workInProgress.child;
  12215. var primaryChildExpirationTime =
  12216. primaryChildFragment.childExpirationTime;
  12217. if (
  12218. primaryChildExpirationTime !== NoWork &&
  12219. primaryChildExpirationTime >= renderExpirationTime
  12220. ) {
  12221. // The primary children have pending work. Use the normal path
  12222. // to attempt to render the primary children again.
  12223. return updateSuspenseComponent(
  12224. current,
  12225. workInProgress,
  12226. renderExpirationTime
  12227. );
  12228. } else {
  12229. pushSuspenseContext(
  12230. workInProgress,
  12231. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  12232. ); // The primary children do not have pending work with sufficient
  12233. // priority. Bailout.
  12234. var child = bailoutOnAlreadyFinishedWork(
  12235. current,
  12236. workInProgress,
  12237. renderExpirationTime
  12238. );
  12239. if (child !== null) {
  12240. // The fallback children have pending work. Skip over the
  12241. // primary children and work on the fallback.
  12242. return child.sibling;
  12243. } else {
  12244. return null;
  12245. }
  12246. }
  12247. } else {
  12248. pushSuspenseContext(
  12249. workInProgress,
  12250. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  12251. );
  12252. }
  12253. break;
  12254. }
  12255. case SuspenseListComponent: {
  12256. var didSuspendBefore = (current.effectTag & DidCapture) !== NoEffect;
  12257. var _hasChildWork =
  12258. workInProgress.childExpirationTime >= renderExpirationTime;
  12259. if (didSuspendBefore) {
  12260. if (_hasChildWork) {
  12261. // If something was in fallback state last time, and we have all the
  12262. // same children then we're still in progressive loading state.
  12263. // Something might get unblocked by state updates or retries in the
  12264. // tree which will affect the tail. So we need to use the normal
  12265. // path to compute the correct tail.
  12266. return updateSuspenseListComponent(
  12267. current,
  12268. workInProgress,
  12269. renderExpirationTime
  12270. );
  12271. } // If none of the children had any work, that means that none of
  12272. // them got retried so they'll still be blocked in the same way
  12273. // as before. We can fast bail out.
  12274. workInProgress.effectTag |= DidCapture;
  12275. } // If nothing suspended before and we're rendering the same children,
  12276. // then the tail doesn't matter. Anything new that suspends will work
  12277. // in the "together" mode, so we can continue from the state we had.
  12278. var renderState = workInProgress.memoizedState;
  12279. if (renderState !== null) {
  12280. // Reset to the "together" mode in case we've started a different
  12281. // update in the past but didn't complete it.
  12282. renderState.rendering = null;
  12283. renderState.tail = null;
  12284. }
  12285. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  12286. if (_hasChildWork) {
  12287. break;
  12288. } else {
  12289. // If none of the children had any work, that means that none of
  12290. // them got retried so they'll still be blocked in the same way
  12291. // as before. We can fast bail out.
  12292. return null;
  12293. }
  12294. }
  12295. }
  12296. return bailoutOnAlreadyFinishedWork(
  12297. current,
  12298. workInProgress,
  12299. renderExpirationTime
  12300. );
  12301. } else {
  12302. // An update was scheduled on this fiber, but there are no new props
  12303. // nor legacy context. Set this to false. If an update queue or context
  12304. // consumer produces a changed value, it will set this to true. Otherwise,
  12305. // the component will assume the children have not changed and bail out.
  12306. didReceiveUpdate = false;
  12307. }
  12308. } else {
  12309. didReceiveUpdate = false;
  12310. } // Before entering the begin phase, clear pending update priority.
  12311. // TODO: This assumes that we're about to evaluate the component and process
  12312. // the update queue. However, there's an exception: SimpleMemoComponent
  12313. // sometimes bails out later in the begin phase. This indicates that we should
  12314. // move this assignment out of the common path and into each branch.
  12315. workInProgress.expirationTime = NoWork;
  12316. switch (workInProgress.tag) {
  12317. case IndeterminateComponent: {
  12318. return mountIndeterminateComponent(
  12319. current,
  12320. workInProgress,
  12321. workInProgress.type,
  12322. renderExpirationTime
  12323. );
  12324. }
  12325. case LazyComponent: {
  12326. var elementType = workInProgress.elementType;
  12327. return mountLazyComponent(
  12328. current,
  12329. workInProgress,
  12330. elementType,
  12331. updateExpirationTime,
  12332. renderExpirationTime
  12333. );
  12334. }
  12335. case FunctionComponent: {
  12336. var _Component = workInProgress.type;
  12337. var unresolvedProps = workInProgress.pendingProps;
  12338. var resolvedProps =
  12339. workInProgress.elementType === _Component
  12340. ? unresolvedProps
  12341. : resolveDefaultProps(_Component, unresolvedProps);
  12342. return updateFunctionComponent(
  12343. current,
  12344. workInProgress,
  12345. _Component,
  12346. resolvedProps,
  12347. renderExpirationTime
  12348. );
  12349. }
  12350. case ClassComponent: {
  12351. var _Component2 = workInProgress.type;
  12352. var _unresolvedProps = workInProgress.pendingProps;
  12353. var _resolvedProps =
  12354. workInProgress.elementType === _Component2
  12355. ? _unresolvedProps
  12356. : resolveDefaultProps(_Component2, _unresolvedProps);
  12357. return updateClassComponent(
  12358. current,
  12359. workInProgress,
  12360. _Component2,
  12361. _resolvedProps,
  12362. renderExpirationTime
  12363. );
  12364. }
  12365. case HostRoot:
  12366. return updateHostRoot(current, workInProgress, renderExpirationTime);
  12367. case HostComponent:
  12368. return updateHostComponent(current, workInProgress, renderExpirationTime);
  12369. case HostText:
  12370. return updateHostText();
  12371. case SuspenseComponent:
  12372. return updateSuspenseComponent(
  12373. current,
  12374. workInProgress,
  12375. renderExpirationTime
  12376. );
  12377. case HostPortal:
  12378. return updatePortalComponent(
  12379. current,
  12380. workInProgress,
  12381. renderExpirationTime
  12382. );
  12383. case ForwardRef: {
  12384. var type = workInProgress.type;
  12385. var _unresolvedProps2 = workInProgress.pendingProps;
  12386. var _resolvedProps2 =
  12387. workInProgress.elementType === type
  12388. ? _unresolvedProps2
  12389. : resolveDefaultProps(type, _unresolvedProps2);
  12390. return updateForwardRef(
  12391. current,
  12392. workInProgress,
  12393. type,
  12394. _resolvedProps2,
  12395. renderExpirationTime
  12396. );
  12397. }
  12398. case Fragment:
  12399. return updateFragment(current, workInProgress, renderExpirationTime);
  12400. case Mode:
  12401. return updateMode(current, workInProgress, renderExpirationTime);
  12402. case Profiler:
  12403. return updateProfiler(current, workInProgress, renderExpirationTime);
  12404. case ContextProvider:
  12405. return updateContextProvider(
  12406. current,
  12407. workInProgress,
  12408. renderExpirationTime
  12409. );
  12410. case ContextConsumer:
  12411. return updateContextConsumer(
  12412. current,
  12413. workInProgress,
  12414. renderExpirationTime
  12415. );
  12416. case MemoComponent: {
  12417. var _type2 = workInProgress.type;
  12418. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  12419. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  12420. {
  12421. if (workInProgress.type !== workInProgress.elementType) {
  12422. var outerPropTypes = _type2.propTypes;
  12423. if (outerPropTypes) {
  12424. checkPropTypes(
  12425. outerPropTypes,
  12426. _resolvedProps3, // Resolved for outer only
  12427. "prop",
  12428. getComponentName(_type2)
  12429. );
  12430. }
  12431. }
  12432. }
  12433. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  12434. return updateMemoComponent(
  12435. current,
  12436. workInProgress,
  12437. _type2,
  12438. _resolvedProps3,
  12439. updateExpirationTime,
  12440. renderExpirationTime
  12441. );
  12442. }
  12443. case SimpleMemoComponent: {
  12444. return updateSimpleMemoComponent(
  12445. current,
  12446. workInProgress,
  12447. workInProgress.type,
  12448. workInProgress.pendingProps,
  12449. updateExpirationTime,
  12450. renderExpirationTime
  12451. );
  12452. }
  12453. case IncompleteClassComponent: {
  12454. var _Component3 = workInProgress.type;
  12455. var _unresolvedProps4 = workInProgress.pendingProps;
  12456. var _resolvedProps4 =
  12457. workInProgress.elementType === _Component3
  12458. ? _unresolvedProps4
  12459. : resolveDefaultProps(_Component3, _unresolvedProps4);
  12460. return mountIncompleteClassComponent(
  12461. current,
  12462. workInProgress,
  12463. _Component3,
  12464. _resolvedProps4,
  12465. renderExpirationTime
  12466. );
  12467. }
  12468. case SuspenseListComponent: {
  12469. return updateSuspenseListComponent(
  12470. current,
  12471. workInProgress,
  12472. renderExpirationTime
  12473. );
  12474. }
  12475. }
  12476. {
  12477. throw Error(
  12478. "Unknown unit of work tag (" +
  12479. workInProgress.tag +
  12480. "). This error is likely caused by a bug in React. Please file an issue."
  12481. );
  12482. }
  12483. }
  12484. function markUpdate(workInProgress) {
  12485. // Tag the fiber with an update effect. This turns a Placement into
  12486. // a PlacementAndUpdate.
  12487. workInProgress.effectTag |= Update;
  12488. }
  12489. function markRef$1(workInProgress) {
  12490. workInProgress.effectTag |= Ref;
  12491. }
  12492. var appendAllChildren;
  12493. var updateHostContainer;
  12494. var updateHostComponent$1;
  12495. var updateHostText$1;
  12496. {
  12497. // Mutation mode
  12498. appendAllChildren = function(
  12499. parent,
  12500. workInProgress,
  12501. needsVisibilityToggle,
  12502. isHidden
  12503. ) {
  12504. // We only have the top Fiber that was created but we need recurse down its
  12505. // children to find all the terminal nodes.
  12506. var node = workInProgress.child;
  12507. while (node !== null) {
  12508. if (node.tag === HostComponent || node.tag === HostText) {
  12509. appendInitialChild(parent, node.stateNode);
  12510. } else if (node.tag === HostPortal);
  12511. else if (node.child !== null) {
  12512. node.child.return = node;
  12513. node = node.child;
  12514. continue;
  12515. }
  12516. if (node === workInProgress) {
  12517. return;
  12518. }
  12519. while (node.sibling === null) {
  12520. if (node.return === null || node.return === workInProgress) {
  12521. return;
  12522. }
  12523. node = node.return;
  12524. }
  12525. node.sibling.return = node.return;
  12526. node = node.sibling;
  12527. }
  12528. };
  12529. updateHostContainer = function(workInProgress) {
  12530. // Noop
  12531. };
  12532. updateHostComponent$1 = function(
  12533. current,
  12534. workInProgress,
  12535. type,
  12536. newProps,
  12537. rootContainerInstance
  12538. ) {
  12539. // If we have an alternate, that means this is an update and we need to
  12540. // schedule a side-effect to do the updates.
  12541. var oldProps = current.memoizedProps;
  12542. if (oldProps === newProps) {
  12543. // In mutation mode, this is sufficient for a bailout because
  12544. // we won't touch this node even if children changed.
  12545. return;
  12546. } // If we get updated because one of our children updated, we don't
  12547. // have newProps so we'll have to reuse them.
  12548. // TODO: Split the update API as separate for the props vs. children.
  12549. // Even better would be if children weren't special cased at all tho.
  12550. var instance = workInProgress.stateNode;
  12551. var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
  12552. // component is hitting the resume path. Figure out why. Possibly
  12553. // related to `hidden`.
  12554. var updatePayload = prepareUpdate(); // TODO: Type this specific to this type of component.
  12555. workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  12556. // is a new ref we mark this as an update. All the work is done in commitWork.
  12557. if (updatePayload) {
  12558. markUpdate(workInProgress);
  12559. }
  12560. };
  12561. updateHostText$1 = function(current, workInProgress, oldText, newText) {
  12562. // If the text differs, mark it as an update. All the work in done in commitWork.
  12563. if (oldText !== newText) {
  12564. markUpdate(workInProgress);
  12565. }
  12566. };
  12567. }
  12568. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  12569. switch (renderState.tailMode) {
  12570. case "hidden": {
  12571. // Any insertions at the end of the tail list after this point
  12572. // should be invisible. If there are already mounted boundaries
  12573. // anything before them are not considered for collapsing.
  12574. // Therefore we need to go through the whole tail to find if
  12575. // there are any.
  12576. var tailNode = renderState.tail;
  12577. var lastTailNode = null;
  12578. while (tailNode !== null) {
  12579. if (tailNode.alternate !== null) {
  12580. lastTailNode = tailNode;
  12581. }
  12582. tailNode = tailNode.sibling;
  12583. } // Next we're simply going to delete all insertions after the
  12584. // last rendered item.
  12585. if (lastTailNode === null) {
  12586. // All remaining items in the tail are insertions.
  12587. renderState.tail = null;
  12588. } else {
  12589. // Detach the insertion after the last node that was already
  12590. // inserted.
  12591. lastTailNode.sibling = null;
  12592. }
  12593. break;
  12594. }
  12595. case "collapsed": {
  12596. // Any insertions at the end of the tail list after this point
  12597. // should be invisible. If there are already mounted boundaries
  12598. // anything before them are not considered for collapsing.
  12599. // Therefore we need to go through the whole tail to find if
  12600. // there are any.
  12601. var _tailNode = renderState.tail;
  12602. var _lastTailNode = null;
  12603. while (_tailNode !== null) {
  12604. if (_tailNode.alternate !== null) {
  12605. _lastTailNode = _tailNode;
  12606. }
  12607. _tailNode = _tailNode.sibling;
  12608. } // Next we're simply going to delete all insertions after the
  12609. // last rendered item.
  12610. if (_lastTailNode === null) {
  12611. // All remaining items in the tail are insertions.
  12612. if (!hasRenderedATailFallback && renderState.tail !== null) {
  12613. // We suspended during the head. We want to show at least one
  12614. // row at the tail. So we'll keep on and cut off the rest.
  12615. renderState.tail.sibling = null;
  12616. } else {
  12617. renderState.tail = null;
  12618. }
  12619. } else {
  12620. // Detach the insertion after the last node that was already
  12621. // inserted.
  12622. _lastTailNode.sibling = null;
  12623. }
  12624. break;
  12625. }
  12626. }
  12627. }
  12628. function completeWork(current, workInProgress, renderExpirationTime) {
  12629. var newProps = workInProgress.pendingProps;
  12630. switch (workInProgress.tag) {
  12631. case IndeterminateComponent:
  12632. case LazyComponent:
  12633. case SimpleMemoComponent:
  12634. case FunctionComponent:
  12635. case ForwardRef:
  12636. case Fragment:
  12637. case Mode:
  12638. case Profiler:
  12639. case ContextConsumer:
  12640. case MemoComponent:
  12641. return null;
  12642. case ClassComponent: {
  12643. var Component = workInProgress.type;
  12644. if (isContextProvider(Component)) {
  12645. popContext(workInProgress);
  12646. }
  12647. return null;
  12648. }
  12649. case HostRoot: {
  12650. popHostContainer(workInProgress);
  12651. popTopLevelContextObject(workInProgress);
  12652. var fiberRoot = workInProgress.stateNode;
  12653. if (fiberRoot.pendingContext) {
  12654. fiberRoot.context = fiberRoot.pendingContext;
  12655. fiberRoot.pendingContext = null;
  12656. }
  12657. if (current === null || current.child === null) {
  12658. // If we hydrated, pop so that we can delete any remaining children
  12659. // that weren't hydrated.
  12660. var wasHydrated = popHydrationState();
  12661. if (wasHydrated) {
  12662. // If we hydrated, then we'll need to schedule an update for
  12663. // the commit side-effects on the root.
  12664. markUpdate(workInProgress);
  12665. }
  12666. }
  12667. updateHostContainer(workInProgress);
  12668. return null;
  12669. }
  12670. case HostComponent: {
  12671. popHostContext(workInProgress);
  12672. var rootContainerInstance = getRootHostContainer();
  12673. var type = workInProgress.type;
  12674. if (current !== null && workInProgress.stateNode != null) {
  12675. updateHostComponent$1(
  12676. current,
  12677. workInProgress,
  12678. type,
  12679. newProps,
  12680. rootContainerInstance
  12681. );
  12682. if (current.ref !== workInProgress.ref) {
  12683. markRef$1(workInProgress);
  12684. }
  12685. } else {
  12686. if (!newProps) {
  12687. if (!(workInProgress.stateNode !== null)) {
  12688. throw Error(
  12689. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12690. );
  12691. } // This can happen when we abort work.
  12692. return null;
  12693. }
  12694. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  12695. // "stack" as the parent. Then append children as we go in beginWork
  12696. // or completeWork depending on whether we want to add them top->down or
  12697. // bottom->up. Top->down is faster in IE11.
  12698. var _wasHydrated = popHydrationState();
  12699. if (_wasHydrated) {
  12700. // TODO: Move this and createInstance step into the beginPhase
  12701. // to consolidate.
  12702. if (prepareToHydrateHostInstance()) {
  12703. // If changes to the hydrated node need to be applied at the
  12704. // commit-phase we mark this as such.
  12705. markUpdate(workInProgress);
  12706. }
  12707. } else {
  12708. var instance = createInstance(
  12709. type,
  12710. newProps,
  12711. rootContainerInstance,
  12712. currentHostContext,
  12713. workInProgress
  12714. );
  12715. appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
  12716. workInProgress.stateNode = instance;
  12717. // (eg DOM renderer supports auto-focus for certain elements).
  12718. // Make sure such renderers get scheduled for later work.
  12719. if (finalizeInitialChildren(instance)) {
  12720. markUpdate(workInProgress);
  12721. }
  12722. }
  12723. if (workInProgress.ref !== null) {
  12724. // If there is a ref on a host node we need to schedule a callback
  12725. markRef$1(workInProgress);
  12726. }
  12727. }
  12728. return null;
  12729. }
  12730. case HostText: {
  12731. var newText = newProps;
  12732. if (current && workInProgress.stateNode != null) {
  12733. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  12734. // to schedule a side-effect to do the updates.
  12735. updateHostText$1(current, workInProgress, oldText, newText);
  12736. } else {
  12737. if (typeof newText !== "string") {
  12738. if (!(workInProgress.stateNode !== null)) {
  12739. throw Error(
  12740. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12741. );
  12742. } // This can happen when we abort work.
  12743. }
  12744. var _rootContainerInstance = getRootHostContainer();
  12745. var _currentHostContext = getHostContext();
  12746. var _wasHydrated2 = popHydrationState();
  12747. if (_wasHydrated2) {
  12748. if (prepareToHydrateHostTextInstance()) {
  12749. markUpdate(workInProgress);
  12750. }
  12751. } else {
  12752. workInProgress.stateNode = createTextInstance(
  12753. newText,
  12754. _rootContainerInstance,
  12755. _currentHostContext,
  12756. workInProgress
  12757. );
  12758. }
  12759. }
  12760. return null;
  12761. }
  12762. case SuspenseComponent: {
  12763. popSuspenseContext(workInProgress);
  12764. var nextState = workInProgress.memoizedState;
  12765. if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
  12766. // Something suspended. Re-render with the fallback children.
  12767. workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
  12768. return workInProgress;
  12769. }
  12770. var nextDidTimeout = nextState !== null;
  12771. var prevDidTimeout = false;
  12772. if (current === null) {
  12773. if (workInProgress.memoizedProps.fallback !== undefined);
  12774. } else {
  12775. var prevState = current.memoizedState;
  12776. prevDidTimeout = prevState !== null;
  12777. if (!nextDidTimeout && prevState !== null) {
  12778. // We just switched from the fallback to the normal children.
  12779. // Delete the fallback.
  12780. // TODO: Would it be better to store the fallback fragment on
  12781. // the stateNode during the begin phase?
  12782. var currentFallbackChild = current.child.sibling;
  12783. if (currentFallbackChild !== null) {
  12784. // Deletions go at the beginning of the return fiber's effect list
  12785. var first = workInProgress.firstEffect;
  12786. if (first !== null) {
  12787. workInProgress.firstEffect = currentFallbackChild;
  12788. currentFallbackChild.nextEffect = first;
  12789. } else {
  12790. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
  12791. currentFallbackChild.nextEffect = null;
  12792. }
  12793. currentFallbackChild.effectTag = Deletion;
  12794. }
  12795. }
  12796. }
  12797. if (nextDidTimeout && !prevDidTimeout) {
  12798. // If this subtreee is running in blocking mode we can suspend,
  12799. // otherwise we won't suspend.
  12800. // TODO: This will still suspend a synchronous tree if anything
  12801. // in the concurrent tree already suspended during this render.
  12802. // This is a known bug.
  12803. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  12804. // TODO: Move this back to throwException because this is too late
  12805. // if this is a large tree which is common for initial loads. We
  12806. // don't know if we should restart a render or not until we get
  12807. // this marker, and this is too late.
  12808. // If this render already had a ping or lower pri updates,
  12809. // and this is the first time we know we're going to suspend we
  12810. // should be able to immediately restart from within throwException.
  12811. var hasInvisibleChildContext =
  12812. current === null &&
  12813. workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  12814. if (
  12815. hasInvisibleChildContext ||
  12816. hasSuspenseContext(
  12817. suspenseStackCursor.current,
  12818. InvisibleParentSuspenseContext
  12819. )
  12820. ) {
  12821. // If this was in an invisible tree or a new render, then showing
  12822. // this boundary is ok.
  12823. renderDidSuspend();
  12824. } else {
  12825. // Otherwise, we're going to have to hide content so we should
  12826. // suspend for longer if possible.
  12827. renderDidSuspendDelayIfPossible();
  12828. }
  12829. }
  12830. }
  12831. {
  12832. // TODO: Only schedule updates if these values are non equal, i.e. it changed.
  12833. if (nextDidTimeout || prevDidTimeout) {
  12834. // If this boundary just timed out, schedule an effect to attach a
  12835. // retry listener to the promise. This flag is also used to hide the
  12836. // primary children. In mutation mode, we also need the flag to
  12837. // *unhide* children that were previously hidden, so check if this
  12838. // is currently timed out, too.
  12839. workInProgress.effectTag |= Update;
  12840. }
  12841. }
  12842. return null;
  12843. }
  12844. case HostPortal:
  12845. popHostContainer(workInProgress);
  12846. updateHostContainer(workInProgress);
  12847. return null;
  12848. case ContextProvider:
  12849. // Pop provider fiber
  12850. popProvider(workInProgress);
  12851. return null;
  12852. case IncompleteClassComponent: {
  12853. // Same as class component case. I put it down here so that the tags are
  12854. // sequential to ensure this switch is compiled to a jump table.
  12855. var _Component = workInProgress.type;
  12856. if (isContextProvider(_Component)) {
  12857. popContext(workInProgress);
  12858. }
  12859. return null;
  12860. }
  12861. case SuspenseListComponent: {
  12862. popSuspenseContext(workInProgress);
  12863. var renderState = workInProgress.memoizedState;
  12864. if (renderState === null) {
  12865. // We're running in the default, "independent" mode.
  12866. // We don't do anything in this mode.
  12867. return null;
  12868. }
  12869. var didSuspendAlready =
  12870. (workInProgress.effectTag & DidCapture) !== NoEffect;
  12871. var renderedTail = renderState.rendering;
  12872. if (renderedTail === null) {
  12873. // We just rendered the head.
  12874. if (!didSuspendAlready) {
  12875. // This is the first pass. We need to figure out if anything is still
  12876. // suspended in the rendered set.
  12877. // If new content unsuspended, but there's still some content that
  12878. // didn't. Then we need to do a second pass that forces everything
  12879. // to keep showing their fallbacks.
  12880. // We might be suspended if something in this render pass suspended, or
  12881. // something in the previous committed pass suspended. Otherwise,
  12882. // there's no chance so we can skip the expensive call to
  12883. // findFirstSuspended.
  12884. var cannotBeSuspended =
  12885. renderHasNotSuspendedYet() &&
  12886. (current === null || (current.effectTag & DidCapture) === NoEffect);
  12887. if (!cannotBeSuspended) {
  12888. var row = workInProgress.child;
  12889. while (row !== null) {
  12890. var suspended = findFirstSuspended(row);
  12891. if (suspended !== null) {
  12892. didSuspendAlready = true;
  12893. workInProgress.effectTag |= DidCapture;
  12894. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  12895. // part of the second pass. In that case nothing will subscribe to
  12896. // its thennables. Instead, we'll transfer its thennables to the
  12897. // SuspenseList so that it can retry if they resolve.
  12898. // There might be multiple of these in the list but since we're
  12899. // going to wait for all of them anyway, it doesn't really matter
  12900. // which ones gets to ping. In theory we could get clever and keep
  12901. // track of how many dependencies remain but it gets tricky because
  12902. // in the meantime, we can add/remove/change items and dependencies.
  12903. // We might bail out of the loop before finding any but that
  12904. // doesn't matter since that means that the other boundaries that
  12905. // we did find already has their listeners attached.
  12906. var newThennables = suspended.updateQueue;
  12907. if (newThennables !== null) {
  12908. workInProgress.updateQueue = newThennables;
  12909. workInProgress.effectTag |= Update;
  12910. } // Rerender the whole list, but this time, we'll force fallbacks
  12911. // to stay in place.
  12912. // Reset the effect list before doing the second pass since that's now invalid.
  12913. if (renderState.lastEffect === null) {
  12914. workInProgress.firstEffect = null;
  12915. }
  12916. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  12917. resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
  12918. // rerender the children.
  12919. pushSuspenseContext(
  12920. workInProgress,
  12921. setShallowSuspenseContext(
  12922. suspenseStackCursor.current,
  12923. ForceSuspenseFallback
  12924. )
  12925. );
  12926. return workInProgress.child;
  12927. }
  12928. row = row.sibling;
  12929. }
  12930. }
  12931. } else {
  12932. cutOffTailIfNeeded(renderState, false);
  12933. } // Next we're going to render the tail.
  12934. } else {
  12935. // Append the rendered row to the child list.
  12936. if (!didSuspendAlready) {
  12937. var _suspended = findFirstSuspended(renderedTail);
  12938. if (_suspended !== null) {
  12939. workInProgress.effectTag |= DidCapture;
  12940. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  12941. // get lost if this row ends up dropped during a second pass.
  12942. var _newThennables = _suspended.updateQueue;
  12943. if (_newThennables !== null) {
  12944. workInProgress.updateQueue = _newThennables;
  12945. workInProgress.effectTag |= Update;
  12946. }
  12947. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  12948. if (
  12949. renderState.tail === null &&
  12950. renderState.tailMode === "hidden" &&
  12951. !renderedTail.alternate
  12952. ) {
  12953. // We need to delete the row we just rendered.
  12954. // Reset the effect list to what it was before we rendered this
  12955. // child. The nested children have already appended themselves.
  12956. var lastEffect = (workInProgress.lastEffect =
  12957. renderState.lastEffect); // Remove any effects that were appended after this point.
  12958. if (lastEffect !== null) {
  12959. lastEffect.nextEffect = null;
  12960. } // We're done.
  12961. return null;
  12962. }
  12963. } else if (
  12964. // The time it took to render last row is greater than time until
  12965. // the expiration.
  12966. now() * 2 - renderState.renderingStartTime >
  12967. renderState.tailExpiration &&
  12968. renderExpirationTime > Never
  12969. ) {
  12970. // We have now passed our CPU deadline and we'll just give up further
  12971. // attempts to render the main content and only render fallbacks.
  12972. // The assumption is that this is usually faster.
  12973. workInProgress.effectTag |= DidCapture;
  12974. didSuspendAlready = true;
  12975. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  12976. // to get it started back up to attempt the next item. If we can show
  12977. // them, then they really have the same priority as this render.
  12978. // So we'll pick it back up the very next render pass once we've had
  12979. // an opportunity to yield for paint.
  12980. var nextPriority = renderExpirationTime - 1;
  12981. workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
  12982. {
  12983. markSpawnedWork(nextPriority);
  12984. }
  12985. }
  12986. }
  12987. if (renderState.isBackwards) {
  12988. // The effect list of the backwards tail will have been added
  12989. // to the end. This breaks the guarantee that life-cycles fire in
  12990. // sibling order but that isn't a strong guarantee promised by React.
  12991. // Especially since these might also just pop in during future commits.
  12992. // Append to the beginning of the list.
  12993. renderedTail.sibling = workInProgress.child;
  12994. workInProgress.child = renderedTail;
  12995. } else {
  12996. var previousSibling = renderState.last;
  12997. if (previousSibling !== null) {
  12998. previousSibling.sibling = renderedTail;
  12999. } else {
  13000. workInProgress.child = renderedTail;
  13001. }
  13002. renderState.last = renderedTail;
  13003. }
  13004. }
  13005. if (renderState.tail !== null) {
  13006. // We still have tail rows to render.
  13007. if (renderState.tailExpiration === 0) {
  13008. // Heuristic for how long we're willing to spend rendering rows
  13009. // until we just give up and show what we have so far.
  13010. var TAIL_EXPIRATION_TIMEOUT_MS = 500;
  13011. renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS; // TODO: This is meant to mimic the train model or JND but this
  13012. // is a per component value. It should really be since the start
  13013. // of the total render or last commit. Consider using something like
  13014. // globalMostRecentFallbackTime. That doesn't account for being
  13015. // suspended for part of the time or when it's a new render.
  13016. // It should probably use a global start time value instead.
  13017. } // Pop a row.
  13018. var next = renderState.tail;
  13019. renderState.rendering = next;
  13020. renderState.tail = next.sibling;
  13021. renderState.lastEffect = workInProgress.lastEffect;
  13022. renderState.renderingStartTime = now();
  13023. next.sibling = null; // Restore the context.
  13024. // TODO: We can probably just avoid popping it instead and only
  13025. // setting it the first time we go from not suspended to suspended.
  13026. var suspenseContext = suspenseStackCursor.current;
  13027. if (didSuspendAlready) {
  13028. suspenseContext = setShallowSuspenseContext(
  13029. suspenseContext,
  13030. ForceSuspenseFallback
  13031. );
  13032. } else {
  13033. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  13034. }
  13035. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  13036. return next;
  13037. }
  13038. return null;
  13039. }
  13040. }
  13041. {
  13042. throw Error(
  13043. "Unknown unit of work tag (" +
  13044. workInProgress.tag +
  13045. "). This error is likely caused by a bug in React. Please file an issue."
  13046. );
  13047. }
  13048. }
  13049. function unwindWork(workInProgress, renderExpirationTime) {
  13050. switch (workInProgress.tag) {
  13051. case ClassComponent: {
  13052. var Component = workInProgress.type;
  13053. if (isContextProvider(Component)) {
  13054. popContext(workInProgress);
  13055. }
  13056. var effectTag = workInProgress.effectTag;
  13057. if (effectTag & ShouldCapture) {
  13058. workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;
  13059. return workInProgress;
  13060. }
  13061. return null;
  13062. }
  13063. case HostRoot: {
  13064. popHostContainer(workInProgress);
  13065. popTopLevelContextObject(workInProgress);
  13066. var _effectTag = workInProgress.effectTag;
  13067. if (!((_effectTag & DidCapture) === NoEffect)) {
  13068. throw Error(
  13069. "The root failed to unmount after an error. This is likely a bug in React. Please file an issue."
  13070. );
  13071. }
  13072. workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture;
  13073. return workInProgress;
  13074. }
  13075. case HostComponent: {
  13076. // TODO: popHydrationState
  13077. popHostContext(workInProgress);
  13078. return null;
  13079. }
  13080. case SuspenseComponent: {
  13081. popSuspenseContext(workInProgress);
  13082. var _effectTag2 = workInProgress.effectTag;
  13083. if (_effectTag2 & ShouldCapture) {
  13084. workInProgress.effectTag = (_effectTag2 & ~ShouldCapture) | DidCapture; // Captured a suspense effect. Re-render the boundary.
  13085. return workInProgress;
  13086. }
  13087. return null;
  13088. }
  13089. case SuspenseListComponent: {
  13090. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  13091. // caught by a nested boundary. If not, it should bubble through.
  13092. return null;
  13093. }
  13094. case HostPortal:
  13095. popHostContainer(workInProgress);
  13096. return null;
  13097. case ContextProvider:
  13098. popProvider(workInProgress);
  13099. return null;
  13100. default:
  13101. return null;
  13102. }
  13103. }
  13104. function unwindInterruptedWork(interruptedWork) {
  13105. switch (interruptedWork.tag) {
  13106. case ClassComponent: {
  13107. var childContextTypes = interruptedWork.type.childContextTypes;
  13108. if (childContextTypes !== null && childContextTypes !== undefined) {
  13109. popContext(interruptedWork);
  13110. }
  13111. break;
  13112. }
  13113. case HostRoot: {
  13114. popHostContainer(interruptedWork);
  13115. popTopLevelContextObject(interruptedWork);
  13116. break;
  13117. }
  13118. case HostComponent: {
  13119. popHostContext(interruptedWork);
  13120. break;
  13121. }
  13122. case HostPortal:
  13123. popHostContainer(interruptedWork);
  13124. break;
  13125. case SuspenseComponent:
  13126. popSuspenseContext(interruptedWork);
  13127. break;
  13128. case SuspenseListComponent:
  13129. popSuspenseContext(interruptedWork);
  13130. break;
  13131. case ContextProvider:
  13132. popProvider(interruptedWork);
  13133. break;
  13134. }
  13135. }
  13136. function createCapturedValue(value, source) {
  13137. // If the value is an error, call this function immediately after it is thrown
  13138. // so the stack is accurate.
  13139. return {
  13140. value: value,
  13141. source: source,
  13142. stack: getStackByFiberInDevAndProd(source)
  13143. };
  13144. }
  13145. // Module provided by RN:
  13146. if (
  13147. !(
  13148. typeof ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog ===
  13149. "function"
  13150. )
  13151. ) {
  13152. throw Error(
  13153. "Expected ReactFiberErrorDialog.showErrorDialog to be a function."
  13154. );
  13155. }
  13156. function showErrorDialog(capturedError) {
  13157. return ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog(
  13158. capturedError
  13159. );
  13160. }
  13161. function logCapturedError(capturedError) {
  13162. var logError = showErrorDialog(capturedError); // Allow injected showErrorDialog() to prevent default console.error logging.
  13163. // This enables renderers like ReactNative to better manage redbox behavior.
  13164. if (logError === false) {
  13165. return;
  13166. }
  13167. var error = capturedError.error;
  13168. {
  13169. var componentName = capturedError.componentName,
  13170. componentStack = capturedError.componentStack,
  13171. errorBoundaryName = capturedError.errorBoundaryName,
  13172. errorBoundaryFound = capturedError.errorBoundaryFound,
  13173. willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
  13174. // `preventDefault()` in window `error` handler.
  13175. // We record this information as an expando on the error.
  13176. if (error != null && error._suppressLogging) {
  13177. if (errorBoundaryFound && willRetry) {
  13178. // The error is recoverable and was silenced.
  13179. // Ignore it and don't print the stack addendum.
  13180. // This is handy for testing error boundaries without noise.
  13181. return;
  13182. } // The error is fatal. Since the silencing might have
  13183. // been accidental, we'll surface it anyway.
  13184. // However, the browser would have silenced the original error
  13185. // so we'll print it first, and then print the stack addendum.
  13186. console["error"](error); // Don't transform to our wrapper
  13187. // For a more detailed description of this block, see:
  13188. // https://github.com/facebook/react/pull/13384
  13189. }
  13190. var componentNameMessage = componentName
  13191. ? "The above error occurred in the <" + componentName + "> component:"
  13192. : "The above error occurred in one of your React components:";
  13193. var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
  13194. if (errorBoundaryFound && errorBoundaryName) {
  13195. if (willRetry) {
  13196. errorBoundaryMessage =
  13197. "React will try to recreate this component tree from scratch " +
  13198. ("using the error boundary you provided, " + errorBoundaryName + ".");
  13199. } else {
  13200. errorBoundaryMessage =
  13201. "This error was initially handled by the error boundary " +
  13202. errorBoundaryName +
  13203. ".\n" +
  13204. "Recreating the tree from scratch failed so React will unmount the tree.";
  13205. }
  13206. } else {
  13207. errorBoundaryMessage =
  13208. "Consider adding an error boundary to your tree to customize error handling behavior.\n" +
  13209. "Visit https://fb.me/react-error-boundaries to learn more about error boundaries.";
  13210. }
  13211. var combinedMessage =
  13212. "" +
  13213. componentNameMessage +
  13214. componentStack +
  13215. "\n\n" +
  13216. ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  13217. // We don't include the original error message and JS stack because the browser
  13218. // has already printed it. Even if the application swallows the error, it is still
  13219. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  13220. console["error"](combinedMessage); // Don't transform to our wrapper
  13221. }
  13222. }
  13223. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  13224. {
  13225. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  13226. }
  13227. var PossiblyWeakSet = typeof WeakSet === "function" ? WeakSet : Set;
  13228. function logError(boundary, errorInfo) {
  13229. var source = errorInfo.source;
  13230. var stack = errorInfo.stack;
  13231. if (stack === null && source !== null) {
  13232. stack = getStackByFiberInDevAndProd(source);
  13233. }
  13234. var capturedError = {
  13235. componentName: source !== null ? getComponentName(source.type) : null,
  13236. componentStack: stack !== null ? stack : "",
  13237. error: errorInfo.value,
  13238. errorBoundary: null,
  13239. errorBoundaryName: null,
  13240. errorBoundaryFound: false,
  13241. willRetry: false
  13242. };
  13243. if (boundary !== null && boundary.tag === ClassComponent) {
  13244. capturedError.errorBoundary = boundary.stateNode;
  13245. capturedError.errorBoundaryName = getComponentName(boundary.type);
  13246. capturedError.errorBoundaryFound = true;
  13247. capturedError.willRetry = true;
  13248. }
  13249. try {
  13250. logCapturedError(capturedError);
  13251. } catch (e) {
  13252. // This method must not throw, or React internal state will get messed up.
  13253. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  13254. // we want to report this error outside of the normal stack as a last resort.
  13255. // https://github.com/facebook/react/issues/13188
  13256. setTimeout(function() {
  13257. throw e;
  13258. });
  13259. }
  13260. }
  13261. var callComponentWillUnmountWithTimer = function(current, instance) {
  13262. startPhaseTimer(current, "componentWillUnmount");
  13263. instance.props = current.memoizedProps;
  13264. instance.state = current.memoizedState;
  13265. {
  13266. instance.componentWillUnmount();
  13267. }
  13268. stopPhaseTimer();
  13269. }; // Capture errors so they don't interrupt unmounting.
  13270. function safelyCallComponentWillUnmount(current, instance) {
  13271. {
  13272. invokeGuardedCallback(
  13273. null,
  13274. callComponentWillUnmountWithTimer,
  13275. null,
  13276. current,
  13277. instance
  13278. );
  13279. if (hasCaughtError()) {
  13280. var unmountError = clearCaughtError();
  13281. captureCommitPhaseError(current, unmountError);
  13282. }
  13283. }
  13284. }
  13285. function safelyDetachRef(current) {
  13286. var ref = current.ref;
  13287. if (ref !== null) {
  13288. if (typeof ref === "function") {
  13289. {
  13290. invokeGuardedCallback(null, ref, null, null);
  13291. if (hasCaughtError()) {
  13292. var refError = clearCaughtError();
  13293. captureCommitPhaseError(current, refError);
  13294. }
  13295. }
  13296. } else {
  13297. ref.current = null;
  13298. }
  13299. }
  13300. }
  13301. function safelyCallDestroy(current, destroy) {
  13302. {
  13303. invokeGuardedCallback(null, destroy, null);
  13304. if (hasCaughtError()) {
  13305. var error = clearCaughtError();
  13306. captureCommitPhaseError(current, error);
  13307. }
  13308. }
  13309. }
  13310. function commitBeforeMutationLifeCycles(current, finishedWork) {
  13311. switch (finishedWork.tag) {
  13312. case FunctionComponent:
  13313. case ForwardRef:
  13314. case SimpleMemoComponent:
  13315. case Block: {
  13316. return;
  13317. }
  13318. case ClassComponent: {
  13319. if (finishedWork.effectTag & Snapshot) {
  13320. if (current !== null) {
  13321. var prevProps = current.memoizedProps;
  13322. var prevState = current.memoizedState;
  13323. startPhaseTimer(finishedWork, "getSnapshotBeforeUpdate");
  13324. var instance = finishedWork.stateNode; // We could update instance props and state here,
  13325. // but instead we rely on them being set during last render.
  13326. // TODO: revisit this when we implement resuming.
  13327. {
  13328. if (
  13329. finishedWork.type === finishedWork.elementType &&
  13330. !didWarnAboutReassigningProps
  13331. ) {
  13332. if (instance.props !== finishedWork.memoizedProps) {
  13333. error(
  13334. "Expected %s props to match memoized props before " +
  13335. "getSnapshotBeforeUpdate. " +
  13336. "This might either be because of a bug in React, or because " +
  13337. "a component reassigns its own `this.props`. " +
  13338. "Please file an issue.",
  13339. getComponentName(finishedWork.type) || "instance"
  13340. );
  13341. }
  13342. if (instance.state !== finishedWork.memoizedState) {
  13343. error(
  13344. "Expected %s state to match memoized state before " +
  13345. "getSnapshotBeforeUpdate. " +
  13346. "This might either be because of a bug in React, or because " +
  13347. "a component reassigns its own `this.state`. " +
  13348. "Please file an issue.",
  13349. getComponentName(finishedWork.type) || "instance"
  13350. );
  13351. }
  13352. }
  13353. }
  13354. var snapshot = instance.getSnapshotBeforeUpdate(
  13355. finishedWork.elementType === finishedWork.type
  13356. ? prevProps
  13357. : resolveDefaultProps(finishedWork.type, prevProps),
  13358. prevState
  13359. );
  13360. {
  13361. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  13362. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  13363. didWarnSet.add(finishedWork.type);
  13364. error(
  13365. "%s.getSnapshotBeforeUpdate(): A snapshot value (or null) " +
  13366. "must be returned. You have returned undefined.",
  13367. getComponentName(finishedWork.type)
  13368. );
  13369. }
  13370. }
  13371. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  13372. stopPhaseTimer();
  13373. }
  13374. }
  13375. return;
  13376. }
  13377. case HostRoot:
  13378. case HostComponent:
  13379. case HostText:
  13380. case HostPortal:
  13381. case IncompleteClassComponent:
  13382. // Nothing to do for these component types
  13383. return;
  13384. }
  13385. {
  13386. throw Error(
  13387. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13388. );
  13389. }
  13390. }
  13391. function commitHookEffectListUnmount(tag, finishedWork) {
  13392. var updateQueue = finishedWork.updateQueue;
  13393. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13394. if (lastEffect !== null) {
  13395. var firstEffect = lastEffect.next;
  13396. var effect = firstEffect;
  13397. do {
  13398. if ((effect.tag & tag) === tag) {
  13399. // Unmount
  13400. var destroy = effect.destroy;
  13401. effect.destroy = undefined;
  13402. if (destroy !== undefined) {
  13403. destroy();
  13404. }
  13405. }
  13406. effect = effect.next;
  13407. } while (effect !== firstEffect);
  13408. }
  13409. }
  13410. function commitHookEffectListMount(tag, finishedWork) {
  13411. var updateQueue = finishedWork.updateQueue;
  13412. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13413. if (lastEffect !== null) {
  13414. var firstEffect = lastEffect.next;
  13415. var effect = firstEffect;
  13416. do {
  13417. if ((effect.tag & tag) === tag) {
  13418. // Mount
  13419. var create = effect.create;
  13420. effect.destroy = create();
  13421. {
  13422. var destroy = effect.destroy;
  13423. if (destroy !== undefined && typeof destroy !== "function") {
  13424. var addendum = void 0;
  13425. if (destroy === null) {
  13426. addendum =
  13427. " You returned null. If your effect does not require clean " +
  13428. "up, return undefined (or nothing).";
  13429. } else if (typeof destroy.then === "function") {
  13430. addendum =
  13431. "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " +
  13432. "Instead, write the async function inside your effect " +
  13433. "and call it immediately:\n\n" +
  13434. "useEffect(() => {\n" +
  13435. " async function fetchData() {\n" +
  13436. " // You can await here\n" +
  13437. " const response = await MyAPI.getData(someId);\n" +
  13438. " // ...\n" +
  13439. " }\n" +
  13440. " fetchData();\n" +
  13441. "}, [someId]); // Or [] if effect doesn't need props or state\n\n" +
  13442. "Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching";
  13443. } else {
  13444. addendum = " You returned: " + destroy;
  13445. }
  13446. error(
  13447. "An effect function must not return anything besides a function, " +
  13448. "which is used for clean-up.%s%s",
  13449. addendum,
  13450. getStackByFiberInDevAndProd(finishedWork)
  13451. );
  13452. }
  13453. }
  13454. }
  13455. effect = effect.next;
  13456. } while (effect !== firstEffect);
  13457. }
  13458. }
  13459. function commitPassiveHookEffects(finishedWork) {
  13460. if ((finishedWork.effectTag & Passive) !== NoEffect) {
  13461. switch (finishedWork.tag) {
  13462. case FunctionComponent:
  13463. case ForwardRef:
  13464. case SimpleMemoComponent:
  13465. case Block: {
  13466. // TODO (#17945) We should call all passive destroy functions (for all fibers)
  13467. // before calling any create functions. The current approach only serializes
  13468. // these for a single fiber.
  13469. {
  13470. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
  13471. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  13472. }
  13473. break;
  13474. }
  13475. }
  13476. }
  13477. }
  13478. function commitLifeCycles(
  13479. finishedRoot,
  13480. current,
  13481. finishedWork,
  13482. committedExpirationTime
  13483. ) {
  13484. switch (finishedWork.tag) {
  13485. case FunctionComponent:
  13486. case ForwardRef:
  13487. case SimpleMemoComponent:
  13488. case Block: {
  13489. // At this point layout effects have already been destroyed (during mutation phase).
  13490. // This is done to prevent sibling component effects from interfering with each other,
  13491. // e.g. a destroy function in one component should never override a ref set
  13492. // by a create function in another component during the same commit.
  13493. {
  13494. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  13495. }
  13496. return;
  13497. }
  13498. case ClassComponent: {
  13499. var instance = finishedWork.stateNode;
  13500. if (finishedWork.effectTag & Update) {
  13501. if (current === null) {
  13502. startPhaseTimer(finishedWork, "componentDidMount"); // We could update instance props and state here,
  13503. // but instead we rely on them being set during last render.
  13504. // TODO: revisit this when we implement resuming.
  13505. {
  13506. if (
  13507. finishedWork.type === finishedWork.elementType &&
  13508. !didWarnAboutReassigningProps
  13509. ) {
  13510. if (instance.props !== finishedWork.memoizedProps) {
  13511. error(
  13512. "Expected %s props to match memoized props before " +
  13513. "componentDidMount. " +
  13514. "This might either be because of a bug in React, or because " +
  13515. "a component reassigns its own `this.props`. " +
  13516. "Please file an issue.",
  13517. getComponentName(finishedWork.type) || "instance"
  13518. );
  13519. }
  13520. if (instance.state !== finishedWork.memoizedState) {
  13521. error(
  13522. "Expected %s state to match memoized state before " +
  13523. "componentDidMount. " +
  13524. "This might either be because of a bug in React, or because " +
  13525. "a component reassigns its own `this.state`. " +
  13526. "Please file an issue.",
  13527. getComponentName(finishedWork.type) || "instance"
  13528. );
  13529. }
  13530. }
  13531. }
  13532. {
  13533. instance.componentDidMount();
  13534. }
  13535. stopPhaseTimer();
  13536. } else {
  13537. var prevProps =
  13538. finishedWork.elementType === finishedWork.type
  13539. ? current.memoizedProps
  13540. : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  13541. var prevState = current.memoizedState;
  13542. startPhaseTimer(finishedWork, "componentDidUpdate"); // We could update instance props and state here,
  13543. // but instead we rely on them being set during last render.
  13544. // TODO: revisit this when we implement resuming.
  13545. {
  13546. if (
  13547. finishedWork.type === finishedWork.elementType &&
  13548. !didWarnAboutReassigningProps
  13549. ) {
  13550. if (instance.props !== finishedWork.memoizedProps) {
  13551. error(
  13552. "Expected %s props to match memoized props before " +
  13553. "componentDidUpdate. " +
  13554. "This might either be because of a bug in React, or because " +
  13555. "a component reassigns its own `this.props`. " +
  13556. "Please file an issue.",
  13557. getComponentName(finishedWork.type) || "instance"
  13558. );
  13559. }
  13560. if (instance.state !== finishedWork.memoizedState) {
  13561. error(
  13562. "Expected %s state to match memoized state before " +
  13563. "componentDidUpdate. " +
  13564. "This might either be because of a bug in React, or because " +
  13565. "a component reassigns its own `this.state`. " +
  13566. "Please file an issue.",
  13567. getComponentName(finishedWork.type) || "instance"
  13568. );
  13569. }
  13570. }
  13571. }
  13572. {
  13573. instance.componentDidUpdate(
  13574. prevProps,
  13575. prevState,
  13576. instance.__reactInternalSnapshotBeforeUpdate
  13577. );
  13578. }
  13579. stopPhaseTimer();
  13580. }
  13581. }
  13582. var updateQueue = finishedWork.updateQueue;
  13583. if (updateQueue !== null) {
  13584. {
  13585. if (
  13586. finishedWork.type === finishedWork.elementType &&
  13587. !didWarnAboutReassigningProps
  13588. ) {
  13589. if (instance.props !== finishedWork.memoizedProps) {
  13590. error(
  13591. "Expected %s props to match memoized props before " +
  13592. "processing the update queue. " +
  13593. "This might either be because of a bug in React, or because " +
  13594. "a component reassigns its own `this.props`. " +
  13595. "Please file an issue.",
  13596. getComponentName(finishedWork.type) || "instance"
  13597. );
  13598. }
  13599. if (instance.state !== finishedWork.memoizedState) {
  13600. error(
  13601. "Expected %s state to match memoized state before " +
  13602. "processing the update queue. " +
  13603. "This might either be because of a bug in React, or because " +
  13604. "a component reassigns its own `this.state`. " +
  13605. "Please file an issue.",
  13606. getComponentName(finishedWork.type) || "instance"
  13607. );
  13608. }
  13609. }
  13610. } // We could update instance props and state here,
  13611. // but instead we rely on them being set during last render.
  13612. // TODO: revisit this when we implement resuming.
  13613. commitUpdateQueue(finishedWork, updateQueue, instance);
  13614. }
  13615. return;
  13616. }
  13617. case HostRoot: {
  13618. var _updateQueue = finishedWork.updateQueue;
  13619. if (_updateQueue !== null) {
  13620. var _instance = null;
  13621. if (finishedWork.child !== null) {
  13622. switch (finishedWork.child.tag) {
  13623. case HostComponent:
  13624. _instance = getPublicInstance(finishedWork.child.stateNode);
  13625. break;
  13626. case ClassComponent:
  13627. _instance = finishedWork.child.stateNode;
  13628. break;
  13629. }
  13630. }
  13631. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  13632. }
  13633. return;
  13634. }
  13635. case HostComponent: {
  13636. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  13637. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  13638. // These effects should only be committed when components are first mounted,
  13639. // aka when there is no current/alternate.
  13640. if (current === null && finishedWork.effectTag & Update) {
  13641. var type = finishedWork.type;
  13642. var props = finishedWork.memoizedProps;
  13643. }
  13644. return;
  13645. }
  13646. case HostText: {
  13647. // We have no life-cycles associated with text.
  13648. return;
  13649. }
  13650. case HostPortal: {
  13651. // We have no life-cycles associated with portals.
  13652. return;
  13653. }
  13654. case Profiler: {
  13655. {
  13656. var _finishedWork$memoize2 = finishedWork.memoizedProps,
  13657. onCommit = _finishedWork$memoize2.onCommit,
  13658. onRender = _finishedWork$memoize2.onRender;
  13659. var effectDuration = finishedWork.stateNode.effectDuration;
  13660. var commitTime = getCommitTime();
  13661. if (typeof onRender === "function") {
  13662. {
  13663. onRender(
  13664. finishedWork.memoizedProps.id,
  13665. current === null ? "mount" : "update",
  13666. finishedWork.actualDuration,
  13667. finishedWork.treeBaseDuration,
  13668. finishedWork.actualStartTime,
  13669. commitTime,
  13670. finishedRoot.memoizedInteractions
  13671. );
  13672. }
  13673. }
  13674. }
  13675. return;
  13676. }
  13677. case SuspenseComponent: {
  13678. return;
  13679. }
  13680. case SuspenseListComponent:
  13681. case IncompleteClassComponent:
  13682. case FundamentalComponent:
  13683. case ScopeComponent:
  13684. return;
  13685. }
  13686. {
  13687. throw Error(
  13688. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13689. );
  13690. }
  13691. }
  13692. function hideOrUnhideAllChildren(finishedWork, isHidden) {
  13693. {
  13694. // We only have the top Fiber that was inserted but we need to recurse down its
  13695. // children to find all the terminal nodes.
  13696. var node = finishedWork;
  13697. while (true) {
  13698. if (node.tag === HostComponent) {
  13699. var instance = node.stateNode;
  13700. if (isHidden) {
  13701. hideInstance(instance);
  13702. } else {
  13703. unhideInstance(node.stateNode, node.memoizedProps);
  13704. }
  13705. } else if (node.tag === HostText) {
  13706. var _instance3 = node.stateNode;
  13707. if (isHidden) {
  13708. hideTextInstance();
  13709. } else {
  13710. unhideTextInstance(_instance3, node.memoizedProps);
  13711. }
  13712. } else if (
  13713. node.tag === SuspenseComponent &&
  13714. node.memoizedState !== null &&
  13715. node.memoizedState.dehydrated === null
  13716. ) {
  13717. // Found a nested Suspense component that timed out. Skip over the
  13718. // primary child fragment, which should remain hidden.
  13719. var fallbackChildFragment = node.child.sibling;
  13720. fallbackChildFragment.return = node;
  13721. node = fallbackChildFragment;
  13722. continue;
  13723. } else if (node.child !== null) {
  13724. node.child.return = node;
  13725. node = node.child;
  13726. continue;
  13727. }
  13728. if (node === finishedWork) {
  13729. return;
  13730. }
  13731. while (node.sibling === null) {
  13732. if (node.return === null || node.return === finishedWork) {
  13733. return;
  13734. }
  13735. node = node.return;
  13736. }
  13737. node.sibling.return = node.return;
  13738. node = node.sibling;
  13739. }
  13740. }
  13741. }
  13742. function commitAttachRef(finishedWork) {
  13743. var ref = finishedWork.ref;
  13744. if (ref !== null) {
  13745. var instance = finishedWork.stateNode;
  13746. var instanceToUse;
  13747. switch (finishedWork.tag) {
  13748. case HostComponent:
  13749. instanceToUse = getPublicInstance(instance);
  13750. break;
  13751. default:
  13752. instanceToUse = instance;
  13753. } // Moved outside to ensure DCE works with this flag
  13754. if (typeof ref === "function") {
  13755. ref(instanceToUse);
  13756. } else {
  13757. {
  13758. if (!ref.hasOwnProperty("current")) {
  13759. error(
  13760. "Unexpected ref object provided for %s. " +
  13761. "Use either a ref-setter function or React.createRef().%s",
  13762. getComponentName(finishedWork.type),
  13763. getStackByFiberInDevAndProd(finishedWork)
  13764. );
  13765. }
  13766. }
  13767. ref.current = instanceToUse;
  13768. }
  13769. }
  13770. }
  13771. function commitDetachRef(current) {
  13772. var currentRef = current.ref;
  13773. if (currentRef !== null) {
  13774. if (typeof currentRef === "function") {
  13775. currentRef(null);
  13776. } else {
  13777. currentRef.current = null;
  13778. }
  13779. }
  13780. } // User-originating errors (lifecycles and refs) should not interrupt
  13781. // deletion, so don't let them throw. Host-originating errors should
  13782. // interrupt deletion, so it's okay
  13783. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  13784. onCommitUnmount(current);
  13785. switch (current.tag) {
  13786. case FunctionComponent:
  13787. case ForwardRef:
  13788. case MemoComponent:
  13789. case SimpleMemoComponent:
  13790. case Block: {
  13791. var updateQueue = current.updateQueue;
  13792. if (updateQueue !== null) {
  13793. var lastEffect = updateQueue.lastEffect;
  13794. if (lastEffect !== null) {
  13795. var firstEffect = lastEffect.next;
  13796. {
  13797. // When the owner fiber is deleted, the destroy function of a passive
  13798. // effect hook is called during the synchronous commit phase. This is
  13799. // a concession to implementation complexity. Calling it in the
  13800. // passive effect phase (like they usually are, when dependencies
  13801. // change during an update) would require either traversing the
  13802. // children of the deleted fiber again, or including unmount effects
  13803. // as part of the fiber effect list.
  13804. //
  13805. // Because this is during the sync commit phase, we need to change
  13806. // the priority.
  13807. //
  13808. // TODO: Reconsider this implementation trade off.
  13809. var priorityLevel =
  13810. renderPriorityLevel > NormalPriority
  13811. ? NormalPriority
  13812. : renderPriorityLevel;
  13813. runWithPriority(priorityLevel, function() {
  13814. var effect = firstEffect;
  13815. do {
  13816. var _effect3 = effect,
  13817. _destroy = _effect3.destroy,
  13818. _tag = _effect3.tag;
  13819. if (_destroy !== undefined) {
  13820. {
  13821. safelyCallDestroy(current, _destroy);
  13822. }
  13823. }
  13824. effect = effect.next;
  13825. } while (effect !== firstEffect);
  13826. });
  13827. }
  13828. }
  13829. }
  13830. return;
  13831. }
  13832. case ClassComponent: {
  13833. safelyDetachRef(current);
  13834. var instance = current.stateNode;
  13835. if (typeof instance.componentWillUnmount === "function") {
  13836. safelyCallComponentWillUnmount(current, instance);
  13837. }
  13838. return;
  13839. }
  13840. case HostComponent: {
  13841. safelyDetachRef(current);
  13842. return;
  13843. }
  13844. case HostPortal: {
  13845. // TODO: this is recursive.
  13846. // We are also not using this parent because
  13847. // the portal will get pushed immediately.
  13848. {
  13849. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  13850. }
  13851. return;
  13852. }
  13853. case FundamentalComponent: {
  13854. return;
  13855. }
  13856. case DehydratedFragment: {
  13857. return;
  13858. }
  13859. case ScopeComponent: {
  13860. return;
  13861. }
  13862. }
  13863. }
  13864. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  13865. // While we're inside a removed host node we don't want to call
  13866. // removeChild on the inner nodes because they're removed by the top
  13867. // call anyway. We also want to call componentWillUnmount on all
  13868. // composites before this host node is removed from the tree. Therefore
  13869. // we do an inner loop while we're still inside the host node.
  13870. var node = root;
  13871. while (true) {
  13872. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
  13873. // Skip portals because commitUnmount() currently visits them recursively.
  13874. if (
  13875. node.child !== null && // If we use mutation we drill down into portals using commitUnmount above.
  13876. // If we don't use mutation we drill down into portals here instead.
  13877. node.tag !== HostPortal
  13878. ) {
  13879. node.child.return = node;
  13880. node = node.child;
  13881. continue;
  13882. }
  13883. if (node === root) {
  13884. return;
  13885. }
  13886. while (node.sibling === null) {
  13887. if (node.return === null || node.return === root) {
  13888. return;
  13889. }
  13890. node = node.return;
  13891. }
  13892. node.sibling.return = node.return;
  13893. node = node.sibling;
  13894. }
  13895. }
  13896. function detachFiber(current) {
  13897. var alternate = current.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
  13898. // should clear the child pointer of the parent alternate to let this
  13899. // get GC:ed but we don't know which for sure which parent is the current
  13900. // one so we'll settle for GC:ing the subtree of this child. This child
  13901. // itself will be GC:ed when the parent updates the next time.
  13902. current.return = null;
  13903. current.child = null;
  13904. current.memoizedState = null;
  13905. current.updateQueue = null;
  13906. current.dependencies = null;
  13907. current.alternate = null;
  13908. current.firstEffect = null;
  13909. current.lastEffect = null;
  13910. current.pendingProps = null;
  13911. current.memoizedProps = null;
  13912. current.stateNode = null;
  13913. if (alternate !== null) {
  13914. detachFiber(alternate);
  13915. }
  13916. }
  13917. function getHostParentFiber(fiber) {
  13918. var parent = fiber.return;
  13919. while (parent !== null) {
  13920. if (isHostParent(parent)) {
  13921. return parent;
  13922. }
  13923. parent = parent.return;
  13924. }
  13925. {
  13926. throw Error(
  13927. "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue."
  13928. );
  13929. }
  13930. }
  13931. function isHostParent(fiber) {
  13932. return (
  13933. fiber.tag === HostComponent ||
  13934. fiber.tag === HostRoot ||
  13935. fiber.tag === HostPortal
  13936. );
  13937. }
  13938. function getHostSibling(fiber) {
  13939. // We're going to search forward into the tree until we find a sibling host
  13940. // node. Unfortunately, if multiple insertions are done in a row we have to
  13941. // search past them. This leads to exponential search for the next sibling.
  13942. // TODO: Find a more efficient way to do this.
  13943. var node = fiber;
  13944. siblings: while (true) {
  13945. // If we didn't find anything, let's try the next sibling.
  13946. while (node.sibling === null) {
  13947. if (node.return === null || isHostParent(node.return)) {
  13948. // If we pop out of the root or hit the parent the fiber we are the
  13949. // last sibling.
  13950. return null;
  13951. }
  13952. node = node.return;
  13953. }
  13954. node.sibling.return = node.return;
  13955. node = node.sibling;
  13956. while (
  13957. node.tag !== HostComponent &&
  13958. node.tag !== HostText &&
  13959. node.tag !== DehydratedFragment
  13960. ) {
  13961. // If it is not host node and, we might have a host node inside it.
  13962. // Try to search down until we find one.
  13963. if (node.effectTag & Placement) {
  13964. // If we don't have a child, try the siblings instead.
  13965. continue siblings;
  13966. } // If we don't have a child, try the siblings instead.
  13967. // We also skip portals because they are not part of this host tree.
  13968. if (node.child === null || node.tag === HostPortal) {
  13969. continue siblings;
  13970. } else {
  13971. node.child.return = node;
  13972. node = node.child;
  13973. }
  13974. } // Check if this host node is stable or about to be placed.
  13975. if (!(node.effectTag & Placement)) {
  13976. // Found it!
  13977. return node.stateNode;
  13978. }
  13979. }
  13980. }
  13981. function commitPlacement(finishedWork) {
  13982. var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
  13983. var parent;
  13984. var isContainer;
  13985. var parentStateNode = parentFiber.stateNode;
  13986. switch (parentFiber.tag) {
  13987. case HostComponent:
  13988. parent = parentStateNode;
  13989. isContainer = false;
  13990. break;
  13991. case HostRoot:
  13992. parent = parentStateNode.containerInfo;
  13993. isContainer = true;
  13994. break;
  13995. case HostPortal:
  13996. parent = parentStateNode.containerInfo;
  13997. isContainer = true;
  13998. break;
  13999. case FundamentalComponent:
  14000. // eslint-disable-next-line-no-fallthrough
  14001. default: {
  14002. throw Error(
  14003. "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue."
  14004. );
  14005. }
  14006. }
  14007. if (parentFiber.effectTag & ContentReset) {
  14008. parentFiber.effectTag &= ~ContentReset;
  14009. }
  14010. var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
  14011. // children to find all the terminal nodes.
  14012. if (isContainer) {
  14013. insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
  14014. } else {
  14015. insertOrAppendPlacementNode(finishedWork, before, parent);
  14016. }
  14017. }
  14018. function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
  14019. var tag = node.tag;
  14020. var isHost = tag === HostComponent || tag === HostText;
  14021. if (isHost || enableFundamentalAPI) {
  14022. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  14023. if (before) {
  14024. insertInContainerBefore(parent);
  14025. } else {
  14026. appendChildToContainer(parent, stateNode);
  14027. }
  14028. } else if (tag === HostPortal);
  14029. else {
  14030. var child = node.child;
  14031. if (child !== null) {
  14032. insertOrAppendPlacementNodeIntoContainer(child, before, parent);
  14033. var sibling = child.sibling;
  14034. while (sibling !== null) {
  14035. insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
  14036. sibling = sibling.sibling;
  14037. }
  14038. }
  14039. }
  14040. }
  14041. function insertOrAppendPlacementNode(node, before, parent) {
  14042. var tag = node.tag;
  14043. var isHost = tag === HostComponent || tag === HostText;
  14044. if (isHost || enableFundamentalAPI) {
  14045. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  14046. if (before) {
  14047. insertBefore(parent, stateNode, before);
  14048. } else {
  14049. appendChild(parent, stateNode);
  14050. }
  14051. } else if (tag === HostPortal);
  14052. else {
  14053. var child = node.child;
  14054. if (child !== null) {
  14055. insertOrAppendPlacementNode(child, before, parent);
  14056. var sibling = child.sibling;
  14057. while (sibling !== null) {
  14058. insertOrAppendPlacementNode(sibling, before, parent);
  14059. sibling = sibling.sibling;
  14060. }
  14061. }
  14062. }
  14063. }
  14064. function unmountHostComponents(finishedRoot, current, renderPriorityLevel) {
  14065. // We only have the top Fiber that was deleted but we need to recurse down its
  14066. // children to find all the terminal nodes.
  14067. var node = current; // Each iteration, currentParent is populated with node's host parent if not
  14068. // currentParentIsValid.
  14069. var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
  14070. var currentParent;
  14071. var currentParentIsContainer;
  14072. while (true) {
  14073. if (!currentParentIsValid) {
  14074. var parent = node.return;
  14075. findParent: while (true) {
  14076. if (!(parent !== null)) {
  14077. throw Error(
  14078. "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue."
  14079. );
  14080. }
  14081. var parentStateNode = parent.stateNode;
  14082. switch (parent.tag) {
  14083. case HostComponent:
  14084. currentParent = parentStateNode;
  14085. currentParentIsContainer = false;
  14086. break findParent;
  14087. case HostRoot:
  14088. currentParent = parentStateNode.containerInfo;
  14089. currentParentIsContainer = true;
  14090. break findParent;
  14091. case HostPortal:
  14092. currentParent = parentStateNode.containerInfo;
  14093. currentParentIsContainer = true;
  14094. break findParent;
  14095. }
  14096. parent = parent.return;
  14097. }
  14098. currentParentIsValid = true;
  14099. }
  14100. if (node.tag === HostComponent || node.tag === HostText) {
  14101. commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
  14102. // node from the tree.
  14103. if (currentParentIsContainer) {
  14104. removeChildFromContainer(currentParent, node.stateNode);
  14105. } else {
  14106. removeChild(currentParent, node.stateNode);
  14107. } // Don't visit children because we already visited them.
  14108. } else if (node.tag === HostPortal) {
  14109. if (node.child !== null) {
  14110. // When we go into a portal, it becomes the parent to remove from.
  14111. // We will reassign it back when we pop the portal on the way up.
  14112. currentParent = node.stateNode.containerInfo;
  14113. currentParentIsContainer = true; // Visit children because portals might contain host components.
  14114. node.child.return = node;
  14115. node = node.child;
  14116. continue;
  14117. }
  14118. } else {
  14119. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
  14120. if (node.child !== null) {
  14121. node.child.return = node;
  14122. node = node.child;
  14123. continue;
  14124. }
  14125. }
  14126. if (node === current) {
  14127. return;
  14128. }
  14129. while (node.sibling === null) {
  14130. if (node.return === null || node.return === current) {
  14131. return;
  14132. }
  14133. node = node.return;
  14134. if (node.tag === HostPortal) {
  14135. // When we go out of the portal, we need to restore the parent.
  14136. // Since we don't keep a stack of them, we will search for it.
  14137. currentParentIsValid = false;
  14138. }
  14139. }
  14140. node.sibling.return = node.return;
  14141. node = node.sibling;
  14142. }
  14143. }
  14144. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  14145. {
  14146. // Recursively delete all host nodes from the parent.
  14147. // Detach refs and call componentWillUnmount() on the whole subtree.
  14148. unmountHostComponents(finishedRoot, current, renderPriorityLevel);
  14149. }
  14150. detachFiber(current);
  14151. }
  14152. function commitWork(current, finishedWork) {
  14153. switch (finishedWork.tag) {
  14154. case FunctionComponent:
  14155. case ForwardRef:
  14156. case MemoComponent:
  14157. case SimpleMemoComponent:
  14158. case Block: {
  14159. // Layout effects are destroyed during the mutation phase so that all
  14160. // destroy functions for all fibers are called before any create functions.
  14161. // This prevents sibling component effects from interfering with each other,
  14162. // e.g. a destroy function in one component should never override a ref set
  14163. // by a create function in another component during the same commit.
  14164. {
  14165. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  14166. }
  14167. return;
  14168. }
  14169. case ClassComponent: {
  14170. return;
  14171. }
  14172. case HostComponent: {
  14173. var instance = finishedWork.stateNode;
  14174. if (instance != null) {
  14175. // Commit the work prepared earlier.
  14176. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  14177. // as the newProps. The updatePayload will contain the real change in
  14178. // this case.
  14179. var oldProps = current !== null ? current.memoizedProps : newProps;
  14180. var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
  14181. var updatePayload = finishedWork.updateQueue;
  14182. finishedWork.updateQueue = null;
  14183. if (updatePayload !== null) {
  14184. commitUpdate(instance, updatePayload, type, oldProps, newProps);
  14185. }
  14186. }
  14187. return;
  14188. }
  14189. case HostText: {
  14190. if (!(finishedWork.stateNode !== null)) {
  14191. throw Error(
  14192. "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue."
  14193. );
  14194. }
  14195. var textInstance = finishedWork.stateNode;
  14196. var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  14197. // as the newProps. The updatePayload will contain the real change in
  14198. // this case.
  14199. var oldText = current !== null ? current.memoizedProps : newText;
  14200. commitTextUpdate(textInstance, oldText, newText);
  14201. return;
  14202. }
  14203. case HostRoot: {
  14204. return;
  14205. }
  14206. case Profiler: {
  14207. return;
  14208. }
  14209. case SuspenseComponent: {
  14210. commitSuspenseComponent(finishedWork);
  14211. attachSuspenseRetryListeners(finishedWork);
  14212. return;
  14213. }
  14214. case SuspenseListComponent: {
  14215. attachSuspenseRetryListeners(finishedWork);
  14216. return;
  14217. }
  14218. case IncompleteClassComponent: {
  14219. return;
  14220. }
  14221. }
  14222. {
  14223. throw Error(
  14224. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  14225. );
  14226. }
  14227. }
  14228. function commitSuspenseComponent(finishedWork) {
  14229. var newState = finishedWork.memoizedState;
  14230. var newDidTimeout;
  14231. var primaryChildParent = finishedWork;
  14232. if (newState === null) {
  14233. newDidTimeout = false;
  14234. } else {
  14235. newDidTimeout = true;
  14236. primaryChildParent = finishedWork.child;
  14237. markCommitTimeOfFallback();
  14238. }
  14239. if (primaryChildParent !== null) {
  14240. hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
  14241. }
  14242. }
  14243. function attachSuspenseRetryListeners(finishedWork) {
  14244. // If this boundary just timed out, then it will have a set of thenables.
  14245. // For each thenable, attach a listener so that when it resolves, React
  14246. // attempts to re-render the boundary in the primary (pre-timeout) state.
  14247. var thenables = finishedWork.updateQueue;
  14248. if (thenables !== null) {
  14249. finishedWork.updateQueue = null;
  14250. var retryCache = finishedWork.stateNode;
  14251. if (retryCache === null) {
  14252. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  14253. }
  14254. thenables.forEach(function(thenable) {
  14255. // Memoize using the boundary fiber to prevent redundant listeners.
  14256. var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
  14257. if (!retryCache.has(thenable)) {
  14258. {
  14259. if (thenable.__reactDoNotTraceInteractions !== true) {
  14260. retry = tracing.unstable_wrap(retry);
  14261. }
  14262. }
  14263. retryCache.add(thenable);
  14264. thenable.then(retry, retry);
  14265. }
  14266. });
  14267. }
  14268. }
  14269. function commitResetTextContent(current) {
  14270. resetTextContent(current.stateNode);
  14271. }
  14272. var PossiblyWeakMap = typeof WeakMap === "function" ? WeakMap : Map;
  14273. function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
  14274. var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
  14275. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  14276. // being called "element".
  14277. update.payload = {
  14278. element: null
  14279. };
  14280. var error = errorInfo.value;
  14281. update.callback = function() {
  14282. onUncaughtError(error);
  14283. logError(fiber, errorInfo);
  14284. };
  14285. return update;
  14286. }
  14287. function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
  14288. var update = createUpdate(expirationTime, null);
  14289. update.tag = CaptureUpdate;
  14290. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  14291. if (typeof getDerivedStateFromError === "function") {
  14292. var error$1 = errorInfo.value;
  14293. update.payload = function() {
  14294. logError(fiber, errorInfo);
  14295. return getDerivedStateFromError(error$1);
  14296. };
  14297. }
  14298. var inst = fiber.stateNode;
  14299. if (inst !== null && typeof inst.componentDidCatch === "function") {
  14300. update.callback = function callback() {
  14301. {
  14302. markFailedErrorBoundaryForHotReloading(fiber);
  14303. }
  14304. if (typeof getDerivedStateFromError !== "function") {
  14305. // To preserve the preexisting retry behavior of error boundaries,
  14306. // we keep track of which ones already failed during this batch.
  14307. // This gets reset before we yield back to the browser.
  14308. // TODO: Warn in strict mode if getDerivedStateFromError is
  14309. // not defined.
  14310. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  14311. logError(fiber, errorInfo);
  14312. }
  14313. var error$1 = errorInfo.value;
  14314. var stack = errorInfo.stack;
  14315. this.componentDidCatch(error$1, {
  14316. componentStack: stack !== null ? stack : ""
  14317. });
  14318. {
  14319. if (typeof getDerivedStateFromError !== "function") {
  14320. // If componentDidCatch is the only error boundary method defined,
  14321. // then it needs to call setState to recover from errors.
  14322. // If no state update is scheduled then the boundary will swallow the error.
  14323. if (fiber.expirationTime !== Sync) {
  14324. error(
  14325. "%s: Error boundaries should implement getDerivedStateFromError(). " +
  14326. "In that method, return a state update to display an error message or fallback UI.",
  14327. getComponentName(fiber.type) || "Unknown"
  14328. );
  14329. }
  14330. }
  14331. }
  14332. };
  14333. } else {
  14334. update.callback = function() {
  14335. markFailedErrorBoundaryForHotReloading(fiber);
  14336. };
  14337. }
  14338. return update;
  14339. }
  14340. function attachPingListener(root, renderExpirationTime, thenable) {
  14341. // Attach a listener to the promise to "ping" the root and retry. But
  14342. // only if one does not already exist for the current render expiration
  14343. // time (which acts like a "thread ID" here).
  14344. var pingCache = root.pingCache;
  14345. var threadIDs;
  14346. if (pingCache === null) {
  14347. pingCache = root.pingCache = new PossiblyWeakMap();
  14348. threadIDs = new Set();
  14349. pingCache.set(thenable, threadIDs);
  14350. } else {
  14351. threadIDs = pingCache.get(thenable);
  14352. if (threadIDs === undefined) {
  14353. threadIDs = new Set();
  14354. pingCache.set(thenable, threadIDs);
  14355. }
  14356. }
  14357. if (!threadIDs.has(renderExpirationTime)) {
  14358. // Memoize using the thread ID to prevent redundant listeners.
  14359. threadIDs.add(renderExpirationTime);
  14360. var ping = pingSuspendedRoot.bind(
  14361. null,
  14362. root,
  14363. thenable,
  14364. renderExpirationTime
  14365. );
  14366. thenable.then(ping, ping);
  14367. }
  14368. }
  14369. function throwException(
  14370. root,
  14371. returnFiber,
  14372. sourceFiber,
  14373. value,
  14374. renderExpirationTime
  14375. ) {
  14376. // The source fiber did not complete.
  14377. sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
  14378. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  14379. if (
  14380. value !== null &&
  14381. typeof value === "object" &&
  14382. typeof value.then === "function"
  14383. ) {
  14384. // This is a thenable.
  14385. var thenable = value;
  14386. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  14387. // Reset the memoizedState to what it was before we attempted
  14388. // to render it.
  14389. var currentSource = sourceFiber.alternate;
  14390. if (currentSource) {
  14391. sourceFiber.updateQueue = currentSource.updateQueue;
  14392. sourceFiber.memoizedState = currentSource.memoizedState;
  14393. sourceFiber.expirationTime = currentSource.expirationTime;
  14394. } else {
  14395. sourceFiber.updateQueue = null;
  14396. sourceFiber.memoizedState = null;
  14397. }
  14398. }
  14399. var hasInvisibleParentBoundary = hasSuspenseContext(
  14400. suspenseStackCursor.current,
  14401. InvisibleParentSuspenseContext
  14402. ); // Schedule the nearest Suspense to re-render the timed out view.
  14403. var _workInProgress = returnFiber;
  14404. do {
  14405. if (
  14406. _workInProgress.tag === SuspenseComponent &&
  14407. shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)
  14408. ) {
  14409. // Found the nearest boundary.
  14410. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  14411. // attach another listener to flip the boundary back to its normal state.
  14412. var thenables = _workInProgress.updateQueue;
  14413. if (thenables === null) {
  14414. var updateQueue = new Set();
  14415. updateQueue.add(thenable);
  14416. _workInProgress.updateQueue = updateQueue;
  14417. } else {
  14418. thenables.add(thenable);
  14419. } // If the boundary is outside of blocking mode, we should *not*
  14420. // suspend the commit. Pretend as if the suspended component rendered
  14421. // null and keep rendering. In the commit phase, we'll schedule a
  14422. // subsequent synchronous update to re-render the Suspense.
  14423. //
  14424. // Note: It doesn't matter whether the component that suspended was
  14425. // inside a blocking mode tree. If the Suspense is outside of it, we
  14426. // should *not* suspend the commit.
  14427. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  14428. _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
  14429. // But we shouldn't call any lifecycle methods or callbacks. Remove
  14430. // all lifecycle effect tags.
  14431. sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
  14432. if (sourceFiber.tag === ClassComponent) {
  14433. var currentSourceFiber = sourceFiber.alternate;
  14434. if (currentSourceFiber === null) {
  14435. // This is a new mount. Change the tag so it's not mistaken for a
  14436. // completed class component. For example, we should not call
  14437. // componentWillUnmount if it is deleted.
  14438. sourceFiber.tag = IncompleteClassComponent;
  14439. } else {
  14440. // When we try rendering again, we should not reuse the current fiber,
  14441. // since it's known to be in an inconsistent state. Use a force update to
  14442. // prevent a bail out.
  14443. var update = createUpdate(Sync, null);
  14444. update.tag = ForceUpdate;
  14445. enqueueUpdate(sourceFiber, update);
  14446. }
  14447. } // The source fiber did not complete. Mark it with Sync priority to
  14448. // indicate that it still has pending work.
  14449. sourceFiber.expirationTime = Sync; // Exit without suspending.
  14450. return;
  14451. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  14452. // with the normal suspend path.
  14453. //
  14454. // After this we'll use a set of heuristics to determine whether this
  14455. // render pass will run to completion or restart or "suspend" the commit.
  14456. // The actual logic for this is spread out in different places.
  14457. //
  14458. // This first principle is that if we're going to suspend when we complete
  14459. // a root, then we should also restart if we get an update or ping that
  14460. // might unsuspend it, and vice versa. The only reason to suspend is
  14461. // because you think you might want to restart before committing. However,
  14462. // it doesn't make sense to restart only while in the period we're suspended.
  14463. //
  14464. // Restarting too aggressively is also not good because it starves out any
  14465. // intermediate loading state. So we use heuristics to determine when.
  14466. // Suspense Heuristics
  14467. //
  14468. // If nothing threw a Promise or all the same fallbacks are already showing,
  14469. // then don't suspend/restart.
  14470. //
  14471. // If this is an initial render of a new tree of Suspense boundaries and
  14472. // those trigger a fallback, then don't suspend/restart. We want to ensure
  14473. // that we can show the initial loading state as quickly as possible.
  14474. //
  14475. // If we hit a "Delayed" case, such as when we'd switch from content back into
  14476. // a fallback, then we should always suspend/restart. SuspenseConfig applies to
  14477. // this case. If none is defined, JND is used instead.
  14478. //
  14479. // If we're already showing a fallback and it gets "retried", allowing us to show
  14480. // another level, but there's still an inner boundary that would show a fallback,
  14481. // then we suspend/restart for 500ms since the last time we showed a fallback
  14482. // anywhere in the tree. This effectively throttles progressive loading into a
  14483. // consistent train of commits. This also gives us an opportunity to restart to
  14484. // get to the completed state slightly earlier.
  14485. //
  14486. // If there's ambiguity due to batching it's resolved in preference of:
  14487. // 1) "delayed", 2) "initial render", 3) "retry".
  14488. //
  14489. // We want to ensure that a "busy" state doesn't get force committed. We want to
  14490. // ensure that new initial loading states can commit as soon as possible.
  14491. attachPingListener(root, renderExpirationTime, thenable);
  14492. _workInProgress.effectTag |= ShouldCapture;
  14493. _workInProgress.expirationTime = renderExpirationTime;
  14494. return;
  14495. } // This boundary already captured during this render. Continue to the next
  14496. // boundary.
  14497. _workInProgress = _workInProgress.return;
  14498. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  14499. // TODO: Use invariant so the message is stripped in prod?
  14500. value = new Error(
  14501. (getComponentName(sourceFiber.type) || "A React component") +
  14502. " suspended while rendering, but no fallback UI was specified.\n" +
  14503. "\n" +
  14504. "Add a <Suspense fallback=...> component higher in the tree to " +
  14505. "provide a loading indicator or placeholder to display." +
  14506. getStackByFiberInDevAndProd(sourceFiber)
  14507. );
  14508. } // We didn't find a boundary that could handle this type of exception. Start
  14509. // over and traverse parent path again, this time treating the exception
  14510. // as an error.
  14511. renderDidError();
  14512. value = createCapturedValue(value, sourceFiber);
  14513. var workInProgress = returnFiber;
  14514. do {
  14515. switch (workInProgress.tag) {
  14516. case HostRoot: {
  14517. var _errorInfo = value;
  14518. workInProgress.effectTag |= ShouldCapture;
  14519. workInProgress.expirationTime = renderExpirationTime;
  14520. var _update = createRootErrorUpdate(
  14521. workInProgress,
  14522. _errorInfo,
  14523. renderExpirationTime
  14524. );
  14525. enqueueCapturedUpdate(workInProgress, _update);
  14526. return;
  14527. }
  14528. case ClassComponent:
  14529. // Capture and retry
  14530. var errorInfo = value;
  14531. var ctor = workInProgress.type;
  14532. var instance = workInProgress.stateNode;
  14533. if (
  14534. (workInProgress.effectTag & DidCapture) === NoEffect &&
  14535. (typeof ctor.getDerivedStateFromError === "function" ||
  14536. (instance !== null &&
  14537. typeof instance.componentDidCatch === "function" &&
  14538. !isAlreadyFailedLegacyErrorBoundary(instance)))
  14539. ) {
  14540. workInProgress.effectTag |= ShouldCapture;
  14541. workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
  14542. var _update2 = createClassErrorUpdate(
  14543. workInProgress,
  14544. errorInfo,
  14545. renderExpirationTime
  14546. );
  14547. enqueueCapturedUpdate(workInProgress, _update2);
  14548. return;
  14549. }
  14550. break;
  14551. }
  14552. workInProgress = workInProgress.return;
  14553. } while (workInProgress !== null);
  14554. }
  14555. var ceil = Math.ceil;
  14556. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  14557. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  14558. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  14559. var NoContext =
  14560. /* */
  14561. 0;
  14562. var BatchedContext =
  14563. /* */
  14564. 1;
  14565. var DiscreteEventContext =
  14566. /* */
  14567. 4;
  14568. var LegacyUnbatchedContext =
  14569. /* */
  14570. 8;
  14571. var RenderContext =
  14572. /* */
  14573. 16;
  14574. var CommitContext =
  14575. /* */
  14576. 32;
  14577. var RootIncomplete = 0;
  14578. var RootFatalErrored = 1;
  14579. var RootErrored = 2;
  14580. var RootSuspended = 3;
  14581. var RootSuspendedWithDelay = 4;
  14582. var RootCompleted = 5;
  14583. // Describes where we are in the React execution stack
  14584. var executionContext = NoContext; // The root we're working on
  14585. var workInProgressRoot = null; // The fiber we're working on
  14586. var workInProgress = null; // The expiration time we're rendering
  14587. var renderExpirationTime$1 = NoWork; // Whether to root completed, errored, suspended, etc.
  14588. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  14589. var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
  14590. // This is conceptually a time stamp but expressed in terms of an ExpirationTime
  14591. // because we deal mostly with expiration times in the hot path, so this avoids
  14592. // the conversion happening in the hot path.
  14593. var workInProgressRootLatestProcessedExpirationTime = Sync;
  14594. var workInProgressRootLatestSuspenseTimeout = Sync;
  14595. var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
  14596. // includes unprocessed updates, not work in bailed out children.
  14597. var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
  14598. // This flag determines if it might be worthwhile to restart if an opportunity
  14599. // happens latere.
  14600. var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
  14601. // model where we don't commit new loading states in too quick succession.
  14602. var globalMostRecentFallbackTime = 0;
  14603. var FALLBACK_THROTTLE_MS = 500;
  14604. var nextEffect = null;
  14605. var hasUncaughtError = false;
  14606. var firstUncaughtError = null;
  14607. var legacyErrorBoundariesThatAlreadyFailed = null;
  14608. var rootDoesHavePassiveEffects = false;
  14609. var rootWithPendingPassiveEffects = null;
  14610. var pendingPassiveEffectsRenderPriority = NoPriority;
  14611. var pendingPassiveEffectsExpirationTime = NoWork;
  14612. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  14613. var NESTED_UPDATE_LIMIT = 50;
  14614. var nestedUpdateCount = 0;
  14615. var rootWithNestedUpdates = null;
  14616. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  14617. var nestedPassiveUpdateCount = 0;
  14618. var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
  14619. // during the commit phase. This enables them to be traced across components
  14620. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  14621. // hydration or SuspenseList.
  14622. var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
  14623. // time). However, if two updates are scheduled within the same event, we
  14624. // should treat their start times as simultaneous, even if the actual clock
  14625. // time has advanced between the first and second call.
  14626. // In other words, because expiration times determine how updates are batched,
  14627. // we want all updates of like priority that occur within the same event to
  14628. // receive the same expiration time. Otherwise we get tearing.
  14629. var currentEventTime = NoWork;
  14630. function requestCurrentTimeForUpdate() {
  14631. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  14632. // We're inside React, so it's fine to read the actual time.
  14633. return msToExpirationTime(now());
  14634. } // We're not inside React, so we may be in the middle of a browser event.
  14635. if (currentEventTime !== NoWork) {
  14636. // Use the same start time for all updates until we enter React again.
  14637. return currentEventTime;
  14638. } // This is the first update since React yielded. Compute a new start time.
  14639. currentEventTime = msToExpirationTime(now());
  14640. return currentEventTime;
  14641. }
  14642. function getCurrentTime() {
  14643. return msToExpirationTime(now());
  14644. }
  14645. function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
  14646. var mode = fiber.mode;
  14647. if ((mode & BlockingMode) === NoMode) {
  14648. return Sync;
  14649. }
  14650. var priorityLevel = getCurrentPriorityLevel();
  14651. if ((mode & ConcurrentMode) === NoMode) {
  14652. return priorityLevel === ImmediatePriority ? Sync : Batched;
  14653. }
  14654. if ((executionContext & RenderContext) !== NoContext) {
  14655. // Use whatever time we're already rendering
  14656. // TODO: Should there be a way to opt out, like with `runWithPriority`?
  14657. return renderExpirationTime$1;
  14658. }
  14659. var expirationTime;
  14660. if (suspenseConfig !== null) {
  14661. // Compute an expiration time based on the Suspense timeout.
  14662. expirationTime = computeSuspenseExpiration(
  14663. currentTime,
  14664. suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION
  14665. );
  14666. } else {
  14667. // Compute an expiration time based on the Scheduler priority.
  14668. switch (priorityLevel) {
  14669. case ImmediatePriority:
  14670. expirationTime = Sync;
  14671. break;
  14672. case UserBlockingPriority:
  14673. // TODO: Rename this to computeUserBlockingExpiration
  14674. expirationTime = computeInteractiveExpiration(currentTime);
  14675. break;
  14676. case NormalPriority:
  14677. case LowPriority:
  14678. // TODO: Handle LowPriority
  14679. // TODO: Rename this to... something better.
  14680. expirationTime = computeAsyncExpiration(currentTime);
  14681. break;
  14682. case IdlePriority:
  14683. expirationTime = Idle;
  14684. break;
  14685. default: {
  14686. throw Error("Expected a valid priority level");
  14687. }
  14688. }
  14689. } // If we're in the middle of rendering a tree, do not update at the same
  14690. // expiration time that is already rendering.
  14691. // TODO: We shouldn't have to do this if the update is on a different root.
  14692. // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
  14693. // the root when we check for this condition.
  14694. if (
  14695. workInProgressRoot !== null &&
  14696. expirationTime === renderExpirationTime$1
  14697. ) {
  14698. // This is a trick to move this update into a separate batch
  14699. expirationTime -= 1;
  14700. }
  14701. return expirationTime;
  14702. }
  14703. function scheduleUpdateOnFiber(fiber, expirationTime) {
  14704. checkForNestedUpdates();
  14705. warnAboutRenderPhaseUpdatesInDEV(fiber);
  14706. var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
  14707. if (root === null) {
  14708. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  14709. return;
  14710. }
  14711. checkForInterruption(fiber, expirationTime);
  14712. recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
  14713. // priority as an argument to that function and this one.
  14714. var priorityLevel = getCurrentPriorityLevel();
  14715. if (expirationTime === Sync) {
  14716. if (
  14717. // Check if we're inside unbatchedUpdates
  14718. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  14719. (executionContext & (RenderContext | CommitContext)) === NoContext
  14720. ) {
  14721. // Register pending interactions on the root to avoid losing traced interaction data.
  14722. schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  14723. // root inside of batchedUpdates should be synchronous, but layout updates
  14724. // should be deferred until the end of the batch.
  14725. performSyncWorkOnRoot(root);
  14726. } else {
  14727. ensureRootIsScheduled(root);
  14728. schedulePendingInteractions(root, expirationTime);
  14729. if (executionContext === NoContext) {
  14730. // Flush the synchronous work now, unless we're already working or inside
  14731. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  14732. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  14733. // without immediately flushing it. We only do this for user-initiated
  14734. // updates, to preserve historical behavior of legacy mode.
  14735. flushSyncCallbackQueue();
  14736. }
  14737. }
  14738. } else {
  14739. ensureRootIsScheduled(root);
  14740. schedulePendingInteractions(root, expirationTime);
  14741. }
  14742. if (
  14743. (executionContext & DiscreteEventContext) !== NoContext && // Only updates at user-blocking priority or greater are considered
  14744. // discrete, even inside a discrete event.
  14745. (priorityLevel === UserBlockingPriority ||
  14746. priorityLevel === ImmediatePriority)
  14747. ) {
  14748. // This is the result of a discrete event. Track the lowest priority
  14749. // discrete update per root so we can flush them early, if needed.
  14750. if (rootsWithPendingDiscreteUpdates === null) {
  14751. rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
  14752. } else {
  14753. var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
  14754. if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
  14755. rootsWithPendingDiscreteUpdates.set(root, expirationTime);
  14756. }
  14757. }
  14758. }
  14759. }
  14760. var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
  14761. // work without treating it as a typical update that originates from an event;
  14762. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  14763. // on a fiber.
  14764. function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
  14765. // Update the source fiber's expiration time
  14766. if (fiber.expirationTime < expirationTime) {
  14767. fiber.expirationTime = expirationTime;
  14768. }
  14769. var alternate = fiber.alternate;
  14770. if (alternate !== null && alternate.expirationTime < expirationTime) {
  14771. alternate.expirationTime = expirationTime;
  14772. } // Walk the parent path to the root and update the child expiration time.
  14773. var node = fiber.return;
  14774. var root = null;
  14775. if (node === null && fiber.tag === HostRoot) {
  14776. root = fiber.stateNode;
  14777. } else {
  14778. while (node !== null) {
  14779. alternate = node.alternate;
  14780. if (node.childExpirationTime < expirationTime) {
  14781. node.childExpirationTime = expirationTime;
  14782. if (
  14783. alternate !== null &&
  14784. alternate.childExpirationTime < expirationTime
  14785. ) {
  14786. alternate.childExpirationTime = expirationTime;
  14787. }
  14788. } else if (
  14789. alternate !== null &&
  14790. alternate.childExpirationTime < expirationTime
  14791. ) {
  14792. alternate.childExpirationTime = expirationTime;
  14793. }
  14794. if (node.return === null && node.tag === HostRoot) {
  14795. root = node.stateNode;
  14796. break;
  14797. }
  14798. node = node.return;
  14799. }
  14800. }
  14801. if (root !== null) {
  14802. if (workInProgressRoot === root) {
  14803. // Received an update to a tree that's in the middle of rendering. Mark
  14804. // that's unprocessed work on this root.
  14805. markUnprocessedUpdateTime(expirationTime);
  14806. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  14807. // The root already suspended with a delay, which means this render
  14808. // definitely won't finish. Since we have a new update, let's mark it as
  14809. // suspended now, right before marking the incoming update. This has the
  14810. // effect of interrupting the current render and switching to the update.
  14811. // TODO: This happens to work when receiving an update during the render
  14812. // phase, because of the trick inside computeExpirationForFiber to
  14813. // subtract 1 from `renderExpirationTime` to move it into a
  14814. // separate bucket. But we should probably model it with an exception,
  14815. // using the same mechanism we use to force hydration of a subtree.
  14816. // TODO: This does not account for low pri updates that were already
  14817. // scheduled before the root started rendering. Need to track the next
  14818. // pending expiration time (perhaps by backtracking the return path) and
  14819. // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
  14820. markRootSuspendedAtTime(root, renderExpirationTime$1);
  14821. }
  14822. } // Mark that the root has a pending update.
  14823. markRootUpdatedAtTime(root, expirationTime);
  14824. }
  14825. return root;
  14826. }
  14827. function getNextRootExpirationTimeToWorkOn(root) {
  14828. // Determines the next expiration time that the root should render, taking
  14829. // into account levels that may be suspended, or levels that may have
  14830. // received a ping.
  14831. var lastExpiredTime = root.lastExpiredTime;
  14832. if (lastExpiredTime !== NoWork) {
  14833. return lastExpiredTime;
  14834. } // "Pending" refers to any update that hasn't committed yet, including if it
  14835. // suspended. The "suspended" range is therefore a subset.
  14836. var firstPendingTime = root.firstPendingTime;
  14837. if (!isRootSuspendedAtTime(root, firstPendingTime)) {
  14838. // The highest priority pending time is not suspended. Let's work on that.
  14839. return firstPendingTime;
  14840. } // If the first pending time is suspended, check if there's a lower priority
  14841. // pending level that we know about. Or check if we received a ping. Work
  14842. // on whichever is higher priority.
  14843. var lastPingedTime = root.lastPingedTime;
  14844. var nextKnownPendingLevel = root.nextKnownPendingLevel;
  14845. var nextLevel =
  14846. lastPingedTime > nextKnownPendingLevel
  14847. ? lastPingedTime
  14848. : nextKnownPendingLevel;
  14849. if (nextLevel <= Idle && firstPendingTime !== nextLevel) {
  14850. // Don't work on Idle/Never priority unless everything else is committed.
  14851. return NoWork;
  14852. }
  14853. return nextLevel;
  14854. } // Use this function to schedule a task for a root. There's only one task per
  14855. // root; if a task was already scheduled, we'll check to make sure the
  14856. // expiration time of the existing task is the same as the expiration time of
  14857. // the next level that the root has work on. This function is called on every
  14858. // update, and right before exiting a task.
  14859. function ensureRootIsScheduled(root) {
  14860. var lastExpiredTime = root.lastExpiredTime;
  14861. if (lastExpiredTime !== NoWork) {
  14862. // Special case: Expired work should flush synchronously.
  14863. root.callbackExpirationTime = Sync;
  14864. root.callbackPriority = ImmediatePriority;
  14865. root.callbackNode = scheduleSyncCallback(
  14866. performSyncWorkOnRoot.bind(null, root)
  14867. );
  14868. return;
  14869. }
  14870. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  14871. var existingCallbackNode = root.callbackNode;
  14872. if (expirationTime === NoWork) {
  14873. // There's nothing to work on.
  14874. if (existingCallbackNode !== null) {
  14875. root.callbackNode = null;
  14876. root.callbackExpirationTime = NoWork;
  14877. root.callbackPriority = NoPriority;
  14878. }
  14879. return;
  14880. } // TODO: If this is an update, we already read the current time. Pass the
  14881. // time as an argument.
  14882. var currentTime = requestCurrentTimeForUpdate();
  14883. var priorityLevel = inferPriorityFromExpirationTime(
  14884. currentTime,
  14885. expirationTime
  14886. ); // If there's an existing render task, confirm it has the correct priority and
  14887. // expiration time. Otherwise, we'll cancel it and schedule a new one.
  14888. if (existingCallbackNode !== null) {
  14889. var existingCallbackPriority = root.callbackPriority;
  14890. var existingCallbackExpirationTime = root.callbackExpirationTime;
  14891. if (
  14892. // Callback must have the exact same expiration time.
  14893. existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
  14894. existingCallbackPriority >= priorityLevel
  14895. ) {
  14896. // Existing callback is sufficient.
  14897. return;
  14898. } // Need to schedule a new task.
  14899. // TODO: Instead of scheduling a new task, we should be able to change the
  14900. // priority of the existing one.
  14901. cancelCallback(existingCallbackNode);
  14902. }
  14903. root.callbackExpirationTime = expirationTime;
  14904. root.callbackPriority = priorityLevel;
  14905. var callbackNode;
  14906. if (expirationTime === Sync) {
  14907. // Sync React callbacks are scheduled on a special internal queue
  14908. callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  14909. } else {
  14910. callbackNode = scheduleCallback(
  14911. priorityLevel,
  14912. performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
  14913. // ordering because tasks are processed in timeout order.
  14914. {
  14915. timeout: expirationTimeToMs(expirationTime) - now()
  14916. }
  14917. );
  14918. }
  14919. root.callbackNode = callbackNode;
  14920. } // This is the entry point for every concurrent task, i.e. anything that
  14921. // goes through Scheduler.
  14922. function performConcurrentWorkOnRoot(root, didTimeout) {
  14923. // Since we know we're in a React event, we can clear the current
  14924. // event time. The next update will compute a new event time.
  14925. currentEventTime = NoWork; // Check if the render expired.
  14926. if (didTimeout) {
  14927. // The render task took too long to complete. Mark the current time as
  14928. // expired to synchronously render all expired work in a single batch.
  14929. var currentTime = requestCurrentTimeForUpdate();
  14930. markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
  14931. ensureRootIsScheduled(root);
  14932. return null;
  14933. } // Determine the next expiration time to work on, using the fields stored
  14934. // on the root.
  14935. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  14936. if (expirationTime === NoWork) {
  14937. return null;
  14938. }
  14939. var originalCallbackNode = root.callbackNode;
  14940. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  14941. throw Error("Should not already be working.");
  14942. }
  14943. flushPassiveEffects();
  14944. var exitStatus = renderRootConcurrent(root, expirationTime);
  14945. if (exitStatus !== RootIncomplete) {
  14946. if (exitStatus === RootErrored) {
  14947. // If something threw an error, try rendering one more time. We'll
  14948. // render synchronously to block concurrent data mutations, and we'll
  14949. // render at Idle (or lower) so that all pending updates are included.
  14950. // If it still fails after the second attempt, we'll give up and commit
  14951. // the resulting tree.
  14952. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  14953. exitStatus = renderRootSync(root, expirationTime);
  14954. }
  14955. if (exitStatus === RootFatalErrored) {
  14956. var fatalError = workInProgressRootFatalError;
  14957. prepareFreshStack(root, expirationTime);
  14958. markRootSuspendedAtTime(root, expirationTime);
  14959. ensureRootIsScheduled(root);
  14960. throw fatalError;
  14961. } // We now have a consistent tree. The next step is either to commit it,
  14962. // or, if something suspended, wait to commit it after a timeout.
  14963. var finishedWork = (root.finishedWork = root.current.alternate);
  14964. root.finishedExpirationTime = expirationTime;
  14965. finishConcurrentRender(root, finishedWork, exitStatus, expirationTime);
  14966. }
  14967. ensureRootIsScheduled(root);
  14968. if (root.callbackNode === originalCallbackNode) {
  14969. // The task node scheduled for this root is the same one that's
  14970. // currently executed. Need to return a continuation.
  14971. return performConcurrentWorkOnRoot.bind(null, root);
  14972. }
  14973. return null;
  14974. }
  14975. function finishConcurrentRender(
  14976. root,
  14977. finishedWork,
  14978. exitStatus,
  14979. expirationTime
  14980. ) {
  14981. switch (exitStatus) {
  14982. case RootIncomplete:
  14983. case RootFatalErrored: {
  14984. {
  14985. throw Error("Root did not complete. This is a bug in React.");
  14986. }
  14987. }
  14988. // Flow knows about invariant, so it complains if I add a break
  14989. // statement, but eslint doesn't know about invariant, so it complains
  14990. // if I do. eslint-disable-next-line no-fallthrough
  14991. case RootErrored: {
  14992. // We should have already attempted to retry this tree. If we reached
  14993. // this point, it errored again. Commit it.
  14994. commitRoot(root);
  14995. break;
  14996. }
  14997. case RootSuspended: {
  14998. markRootSuspendedAtTime(root, expirationTime);
  14999. var lastSuspendedTime = root.lastSuspendedTime;
  15000. if (expirationTime === lastSuspendedTime) {
  15001. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  15002. } // We have an acceptable loading state. We need to figure out if we
  15003. // should immediately commit it or wait a bit.
  15004. // If we have processed new updates during this render, we may now
  15005. // have a new loading state ready. We want to ensure that we commit
  15006. // that as soon as possible.
  15007. var hasNotProcessedNewUpdates =
  15008. workInProgressRootLatestProcessedExpirationTime === Sync;
  15009. if (
  15010. hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
  15011. !IsThisRendererActing.current
  15012. ) {
  15013. // If we have not processed any new updates during this pass, then
  15014. // this is either a retry of an existing fallback state or a
  15015. // hidden tree. Hidden trees shouldn't be batched with other work
  15016. // and after that's fixed it can only be a retry. We're going to
  15017. // throttle committing retries so that we don't show too many
  15018. // loading states too quickly.
  15019. var msUntilTimeout =
  15020. globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  15021. if (msUntilTimeout > 10) {
  15022. if (workInProgressRootHasPendingPing) {
  15023. var lastPingedTime = root.lastPingedTime;
  15024. if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
  15025. // This render was pinged but we didn't get to restart
  15026. // earlier so try restarting now instead.
  15027. root.lastPingedTime = expirationTime;
  15028. prepareFreshStack(root, expirationTime);
  15029. break;
  15030. }
  15031. }
  15032. var nextTime = getNextRootExpirationTimeToWorkOn(root);
  15033. if (nextTime !== NoWork && nextTime !== expirationTime) {
  15034. // There's additional work on this root.
  15035. break;
  15036. }
  15037. if (
  15038. lastSuspendedTime !== NoWork &&
  15039. lastSuspendedTime !== expirationTime
  15040. ) {
  15041. // We should prefer to render the fallback of at the last
  15042. // suspended level. Ping the last suspended level to try
  15043. // rendering it again.
  15044. root.lastPingedTime = lastSuspendedTime;
  15045. break;
  15046. } // The render is suspended, it hasn't timed out, and there's no
  15047. // lower priority work to do. Instead of committing the fallback
  15048. // immediately, wait for more data to arrive.
  15049. root.timeoutHandle = scheduleTimeout(
  15050. commitRoot.bind(null, root),
  15051. msUntilTimeout
  15052. );
  15053. break;
  15054. }
  15055. } // The work expired. Commit immediately.
  15056. commitRoot(root);
  15057. break;
  15058. }
  15059. case RootSuspendedWithDelay: {
  15060. markRootSuspendedAtTime(root, expirationTime);
  15061. var _lastSuspendedTime = root.lastSuspendedTime;
  15062. if (expirationTime === _lastSuspendedTime) {
  15063. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  15064. }
  15065. {
  15066. // We're suspended in a state that should be avoided. We'll try to
  15067. // avoid committing it for as long as the timeouts let us.
  15068. if (workInProgressRootHasPendingPing) {
  15069. var _lastPingedTime = root.lastPingedTime;
  15070. if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
  15071. // This render was pinged but we didn't get to restart earlier
  15072. // so try restarting now instead.
  15073. root.lastPingedTime = expirationTime;
  15074. prepareFreshStack(root, expirationTime);
  15075. break;
  15076. }
  15077. }
  15078. var _nextTime = getNextRootExpirationTimeToWorkOn(root);
  15079. if (_nextTime !== NoWork && _nextTime !== expirationTime) {
  15080. // There's additional work on this root.
  15081. break;
  15082. }
  15083. if (
  15084. _lastSuspendedTime !== NoWork &&
  15085. _lastSuspendedTime !== expirationTime
  15086. ) {
  15087. // We should prefer to render the fallback of at the last
  15088. // suspended level. Ping the last suspended level to try
  15089. // rendering it again.
  15090. root.lastPingedTime = _lastSuspendedTime;
  15091. break;
  15092. }
  15093. var _msUntilTimeout;
  15094. if (workInProgressRootLatestSuspenseTimeout !== Sync) {
  15095. // We have processed a suspense config whose expiration time we
  15096. // can use as the timeout.
  15097. _msUntilTimeout =
  15098. expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
  15099. } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
  15100. // This should never normally happen because only new updates
  15101. // cause delayed states, so we should have processed something.
  15102. // However, this could also happen in an offscreen tree.
  15103. _msUntilTimeout = 0;
  15104. } else {
  15105. // If we don't have a suspense config, we're going to use a
  15106. // heuristic to determine how long we can suspend.
  15107. var eventTimeMs = inferTimeFromExpirationTime(
  15108. workInProgressRootLatestProcessedExpirationTime
  15109. );
  15110. var currentTimeMs = now();
  15111. var timeUntilExpirationMs =
  15112. expirationTimeToMs(expirationTime) - currentTimeMs;
  15113. var timeElapsed = currentTimeMs - eventTimeMs;
  15114. if (timeElapsed < 0) {
  15115. // We get this wrong some time since we estimate the time.
  15116. timeElapsed = 0;
  15117. }
  15118. _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
  15119. // event time is exact instead of inferred from expiration time
  15120. // we don't need this.
  15121. if (timeUntilExpirationMs < _msUntilTimeout) {
  15122. _msUntilTimeout = timeUntilExpirationMs;
  15123. }
  15124. } // Don't bother with a very short suspense time.
  15125. if (_msUntilTimeout > 10) {
  15126. // The render is suspended, it hasn't timed out, and there's no
  15127. // lower priority work to do. Instead of committing the fallback
  15128. // immediately, wait for more data to arrive.
  15129. root.timeoutHandle = scheduleTimeout(
  15130. commitRoot.bind(null, root),
  15131. _msUntilTimeout
  15132. );
  15133. break;
  15134. }
  15135. } // The work expired. Commit immediately.
  15136. commitRoot(root);
  15137. break;
  15138. }
  15139. case RootCompleted: {
  15140. // The work completed. Ready to commit.
  15141. if (
  15142. // do not delay if we're inside an act() scope
  15143. workInProgressRootLatestProcessedExpirationTime !== Sync &&
  15144. workInProgressRootCanSuspendUsingConfig !== null
  15145. ) {
  15146. // If we have exceeded the minimum loading delay, which probably
  15147. // means we have shown a spinner already, we might have to suspend
  15148. // a bit longer to ensure that the spinner is shown for
  15149. // enough time.
  15150. var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(
  15151. workInProgressRootLatestProcessedExpirationTime,
  15152. expirationTime,
  15153. workInProgressRootCanSuspendUsingConfig
  15154. );
  15155. if (_msUntilTimeout2 > 10) {
  15156. markRootSuspendedAtTime(root, expirationTime);
  15157. root.timeoutHandle = scheduleTimeout(
  15158. commitRoot.bind(null, root),
  15159. _msUntilTimeout2
  15160. );
  15161. break;
  15162. }
  15163. }
  15164. commitRoot(root);
  15165. break;
  15166. }
  15167. default: {
  15168. {
  15169. throw Error("Unknown root exit status.");
  15170. }
  15171. }
  15172. }
  15173. } // This is the entry point for synchronous tasks that don't go
  15174. // through Scheduler
  15175. function performSyncWorkOnRoot(root) {
  15176. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15177. throw Error("Should not already be working.");
  15178. }
  15179. flushPassiveEffects();
  15180. var lastExpiredTime = root.lastExpiredTime;
  15181. var expirationTime;
  15182. if (lastExpiredTime !== NoWork) {
  15183. // There's expired work on this root. Check if we have a partial tree
  15184. // that we can reuse.
  15185. if (
  15186. root === workInProgressRoot &&
  15187. renderExpirationTime$1 >= lastExpiredTime
  15188. ) {
  15189. // There's a partial tree with equal or greater than priority than the
  15190. // expired level. Finish rendering it before rendering the rest of the
  15191. // expired work.
  15192. expirationTime = renderExpirationTime$1;
  15193. } else {
  15194. // Start a fresh tree.
  15195. expirationTime = lastExpiredTime;
  15196. }
  15197. } else {
  15198. // There's no expired work. This must be a new, synchronous render.
  15199. expirationTime = Sync;
  15200. }
  15201. var exitStatus = renderRootSync(root, expirationTime);
  15202. if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
  15203. // If something threw an error, try rendering one more time. We'll
  15204. // render synchronously to block concurrent data mutations, and we'll
  15205. // render at Idle (or lower) so that all pending updates are included.
  15206. // If it still fails after the second attempt, we'll give up and commit
  15207. // the resulting tree.
  15208. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  15209. exitStatus = renderRootSync(root, expirationTime);
  15210. }
  15211. if (exitStatus === RootFatalErrored) {
  15212. var fatalError = workInProgressRootFatalError;
  15213. prepareFreshStack(root, expirationTime);
  15214. markRootSuspendedAtTime(root, expirationTime);
  15215. ensureRootIsScheduled(root);
  15216. throw fatalError;
  15217. } // We now have a consistent tree. Because this is a sync render, we
  15218. // will commit it even if something suspended.
  15219. root.finishedWork = root.current.alternate;
  15220. root.finishedExpirationTime = expirationTime;
  15221. commitRoot(root); // Before exiting, make sure there's a callback scheduled for the next
  15222. // pending level.
  15223. ensureRootIsScheduled(root);
  15224. return null;
  15225. }
  15226. function syncUpdates(fn, a, b, c) {
  15227. return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
  15228. }
  15229. function batchedUpdates$1(fn, a) {
  15230. var prevExecutionContext = executionContext;
  15231. executionContext |= BatchedContext;
  15232. try {
  15233. return fn(a);
  15234. } finally {
  15235. executionContext = prevExecutionContext;
  15236. if (executionContext === NoContext) {
  15237. // Flush the immediate callbacks that were scheduled during this batch
  15238. flushSyncCallbackQueue();
  15239. }
  15240. }
  15241. }
  15242. function flushSync(fn, a) {
  15243. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  15244. {
  15245. throw Error(
  15246. "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering."
  15247. );
  15248. }
  15249. }
  15250. var prevExecutionContext = executionContext;
  15251. executionContext |= BatchedContext;
  15252. try {
  15253. return runWithPriority(ImmediatePriority, fn.bind(null, a));
  15254. } finally {
  15255. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  15256. // Note that this will happen even if batchedUpdates is higher up
  15257. // the stack.
  15258. flushSyncCallbackQueue();
  15259. }
  15260. }
  15261. function prepareFreshStack(root, expirationTime) {
  15262. root.finishedWork = null;
  15263. root.finishedExpirationTime = NoWork;
  15264. var timeoutHandle = root.timeoutHandle;
  15265. if (timeoutHandle !== noTimeout) {
  15266. // The root previous suspended and scheduled a timeout to commit a fallback
  15267. // state. Now that we have additional work, cancel the timeout.
  15268. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  15269. cancelTimeout(timeoutHandle);
  15270. }
  15271. if (workInProgress !== null) {
  15272. var interruptedWork = workInProgress.return;
  15273. while (interruptedWork !== null) {
  15274. unwindInterruptedWork(interruptedWork);
  15275. interruptedWork = interruptedWork.return;
  15276. }
  15277. }
  15278. workInProgressRoot = root;
  15279. workInProgress = createWorkInProgress(root.current, null);
  15280. renderExpirationTime$1 = expirationTime;
  15281. workInProgressRootExitStatus = RootIncomplete;
  15282. workInProgressRootFatalError = null;
  15283. workInProgressRootLatestProcessedExpirationTime = Sync;
  15284. workInProgressRootLatestSuspenseTimeout = Sync;
  15285. workInProgressRootCanSuspendUsingConfig = null;
  15286. workInProgressRootNextUnprocessedUpdateTime = NoWork;
  15287. workInProgressRootHasPendingPing = false;
  15288. {
  15289. spawnedWorkDuringRender = null;
  15290. }
  15291. {
  15292. ReactStrictModeWarnings.discardPendingWarnings();
  15293. }
  15294. }
  15295. function handleError(root, thrownValue) {
  15296. do {
  15297. try {
  15298. // Reset module-level state that was set during the render phase.
  15299. resetContextDependencies();
  15300. resetHooksAfterThrow();
  15301. resetCurrentFiber();
  15302. if (workInProgress === null || workInProgress.return === null) {
  15303. // Expected to be working on a non-root fiber. This is a fatal error
  15304. // because there's no ancestor that can handle it; the root is
  15305. // supposed to capture all errors that weren't caught by an error
  15306. // boundary.
  15307. workInProgressRootExitStatus = RootFatalErrored;
  15308. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  15309. // sibling, or the parent if there are no siblings. But since the root
  15310. // has no siblings nor a parent, we set it to null. Usually this is
  15311. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  15312. // interntionally not calling those, we need set it here.
  15313. // TODO: Consider calling `unwindWork` to pop the contexts.
  15314. workInProgress = null;
  15315. return null;
  15316. }
  15317. if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
  15318. // Record the time spent rendering before an error was thrown. This
  15319. // avoids inaccurate Profiler durations in the case of a
  15320. // suspended render.
  15321. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
  15322. }
  15323. throwException(
  15324. root,
  15325. workInProgress.return,
  15326. workInProgress,
  15327. thrownValue,
  15328. renderExpirationTime$1
  15329. );
  15330. workInProgress = completeUnitOfWork(workInProgress);
  15331. } catch (yetAnotherThrownValue) {
  15332. // Something in the return path also threw.
  15333. thrownValue = yetAnotherThrownValue;
  15334. continue;
  15335. } // Return to the normal work loop.
  15336. return;
  15337. } while (true);
  15338. }
  15339. function pushDispatcher(root) {
  15340. var prevDispatcher = ReactCurrentDispatcher$1.current;
  15341. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  15342. if (prevDispatcher === null) {
  15343. // The React isomorphic package does not include a default dispatcher.
  15344. // Instead the first renderer will lazily attach one, in order to give
  15345. // nicer error messages.
  15346. return ContextOnlyDispatcher;
  15347. } else {
  15348. return prevDispatcher;
  15349. }
  15350. }
  15351. function popDispatcher(prevDispatcher) {
  15352. ReactCurrentDispatcher$1.current = prevDispatcher;
  15353. }
  15354. function pushInteractions(root) {
  15355. {
  15356. var prevInteractions = tracing.__interactionsRef.current;
  15357. tracing.__interactionsRef.current = root.memoizedInteractions;
  15358. return prevInteractions;
  15359. }
  15360. }
  15361. function popInteractions(prevInteractions) {
  15362. {
  15363. tracing.__interactionsRef.current = prevInteractions;
  15364. }
  15365. }
  15366. function markCommitTimeOfFallback() {
  15367. globalMostRecentFallbackTime = now();
  15368. }
  15369. function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
  15370. if (
  15371. expirationTime < workInProgressRootLatestProcessedExpirationTime &&
  15372. expirationTime > Idle
  15373. ) {
  15374. workInProgressRootLatestProcessedExpirationTime = expirationTime;
  15375. }
  15376. if (suspenseConfig !== null) {
  15377. if (
  15378. expirationTime < workInProgressRootLatestSuspenseTimeout &&
  15379. expirationTime > Idle
  15380. ) {
  15381. workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
  15382. workInProgressRootCanSuspendUsingConfig = suspenseConfig;
  15383. }
  15384. }
  15385. }
  15386. function markUnprocessedUpdateTime(expirationTime) {
  15387. if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
  15388. workInProgressRootNextUnprocessedUpdateTime = expirationTime;
  15389. }
  15390. }
  15391. function renderDidSuspend() {
  15392. if (workInProgressRootExitStatus === RootIncomplete) {
  15393. workInProgressRootExitStatus = RootSuspended;
  15394. }
  15395. }
  15396. function renderDidSuspendDelayIfPossible() {
  15397. if (
  15398. workInProgressRootExitStatus === RootIncomplete ||
  15399. workInProgressRootExitStatus === RootSuspended
  15400. ) {
  15401. workInProgressRootExitStatus = RootSuspendedWithDelay;
  15402. } // Check if there's a lower priority update somewhere else in the tree.
  15403. if (
  15404. workInProgressRootNextUnprocessedUpdateTime !== NoWork &&
  15405. workInProgressRoot !== null
  15406. ) {
  15407. // Mark the current render as suspended, and then mark that there's a
  15408. // pending update.
  15409. // TODO: This should immediately interrupt the current render, instead
  15410. // of waiting until the next time we yield.
  15411. markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime$1);
  15412. markRootUpdatedAtTime(
  15413. workInProgressRoot,
  15414. workInProgressRootNextUnprocessedUpdateTime
  15415. );
  15416. }
  15417. }
  15418. function renderDidError() {
  15419. if (workInProgressRootExitStatus !== RootCompleted) {
  15420. workInProgressRootExitStatus = RootErrored;
  15421. }
  15422. } // Called during render to determine if anything has suspended.
  15423. // Returns false if we're not sure.
  15424. function renderHasNotSuspendedYet() {
  15425. // If something errored or completed, we can't really be sure,
  15426. // so those are false.
  15427. return workInProgressRootExitStatus === RootIncomplete;
  15428. }
  15429. function inferTimeFromExpirationTime(expirationTime) {
  15430. // We don't know exactly when the update was scheduled, but we can infer an
  15431. // approximate start time from the expiration time.
  15432. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  15433. return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
  15434. }
  15435. function inferTimeFromExpirationTimeWithSuspenseConfig(
  15436. expirationTime,
  15437. suspenseConfig
  15438. ) {
  15439. // We don't know exactly when the update was scheduled, but we can infer an
  15440. // approximate start time from the expiration time by subtracting the timeout
  15441. // that was added to the event time.
  15442. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  15443. return (
  15444. earliestExpirationTimeMs -
  15445. (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION)
  15446. );
  15447. }
  15448. function renderRootSync(root, expirationTime) {
  15449. var prevExecutionContext = executionContext;
  15450. executionContext |= RenderContext;
  15451. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15452. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15453. if (
  15454. root !== workInProgressRoot ||
  15455. expirationTime !== renderExpirationTime$1
  15456. ) {
  15457. prepareFreshStack(root, expirationTime);
  15458. startWorkOnPendingInteractions(root, expirationTime);
  15459. }
  15460. var prevInteractions = pushInteractions(root);
  15461. startWorkLoopTimer(workInProgress);
  15462. do {
  15463. try {
  15464. workLoopSync();
  15465. break;
  15466. } catch (thrownValue) {
  15467. handleError(root, thrownValue);
  15468. }
  15469. } while (true);
  15470. resetContextDependencies();
  15471. {
  15472. popInteractions(prevInteractions);
  15473. }
  15474. executionContext = prevExecutionContext;
  15475. popDispatcher(prevDispatcher);
  15476. if (workInProgress !== null) {
  15477. // This is a sync render, so we should have finished the whole tree.
  15478. {
  15479. throw Error(
  15480. "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue."
  15481. );
  15482. }
  15483. }
  15484. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15485. workInProgressRoot = null;
  15486. return workInProgressRootExitStatus;
  15487. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  15488. /** @noinline */
  15489. function workLoopSync() {
  15490. // Already timed out, so perform work without checking if we need to yield.
  15491. while (workInProgress !== null) {
  15492. workInProgress = performUnitOfWork(workInProgress);
  15493. }
  15494. }
  15495. function renderRootConcurrent(root, expirationTime) {
  15496. var prevExecutionContext = executionContext;
  15497. executionContext |= RenderContext;
  15498. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15499. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15500. if (
  15501. root !== workInProgressRoot ||
  15502. expirationTime !== renderExpirationTime$1
  15503. ) {
  15504. prepareFreshStack(root, expirationTime);
  15505. startWorkOnPendingInteractions(root, expirationTime);
  15506. }
  15507. var prevInteractions = pushInteractions(root);
  15508. startWorkLoopTimer(workInProgress);
  15509. do {
  15510. try {
  15511. workLoopConcurrent();
  15512. break;
  15513. } catch (thrownValue) {
  15514. handleError(root, thrownValue);
  15515. }
  15516. } while (true);
  15517. resetContextDependencies();
  15518. {
  15519. popInteractions(prevInteractions);
  15520. }
  15521. popDispatcher(prevDispatcher);
  15522. executionContext = prevExecutionContext; // Check if the tree has completed.
  15523. if (workInProgress !== null) {
  15524. // Still work remaining.
  15525. stopInterruptedWorkLoopTimer();
  15526. return RootIncomplete;
  15527. } else {
  15528. // Completed the tree.
  15529. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15530. workInProgressRoot = null; // Return the final exit status.
  15531. return workInProgressRootExitStatus;
  15532. }
  15533. }
  15534. /** @noinline */
  15535. function workLoopConcurrent() {
  15536. // Perform work until Scheduler asks us to yield
  15537. while (workInProgress !== null && !shouldYield()) {
  15538. workInProgress = performUnitOfWork(workInProgress);
  15539. }
  15540. }
  15541. function performUnitOfWork(unitOfWork) {
  15542. // The current, flushed, state of this fiber is the alternate. Ideally
  15543. // nothing should rely on this, but relying on it here means that we don't
  15544. // need an additional field on the work in progress.
  15545. var current = unitOfWork.alternate;
  15546. startWorkTimer(unitOfWork);
  15547. setCurrentFiber(unitOfWork);
  15548. var next;
  15549. if ((unitOfWork.mode & ProfileMode) !== NoMode) {
  15550. startProfilerTimer(unitOfWork);
  15551. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15552. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  15553. } else {
  15554. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15555. }
  15556. resetCurrentFiber();
  15557. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  15558. if (next === null) {
  15559. // If this doesn't spawn new work, complete the current work.
  15560. next = completeUnitOfWork(unitOfWork);
  15561. }
  15562. ReactCurrentOwner$2.current = null;
  15563. return next;
  15564. }
  15565. function completeUnitOfWork(unitOfWork) {
  15566. // Attempt to complete the current unit of work, then move to the next
  15567. // sibling. If there are no more siblings, return to the parent fiber.
  15568. workInProgress = unitOfWork;
  15569. do {
  15570. // The current, flushed, state of this fiber is the alternate. Ideally
  15571. // nothing should rely on this, but relying on it here means that we don't
  15572. // need an additional field on the work in progress.
  15573. var current = workInProgress.alternate;
  15574. var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
  15575. if ((workInProgress.effectTag & Incomplete) === NoEffect) {
  15576. setCurrentFiber(workInProgress);
  15577. var next = void 0;
  15578. if ((workInProgress.mode & ProfileMode) === NoMode) {
  15579. next = completeWork(current, workInProgress, renderExpirationTime$1);
  15580. } else {
  15581. startProfilerTimer(workInProgress);
  15582. next = completeWork(current, workInProgress, renderExpirationTime$1); // Update render duration assuming we didn't error.
  15583. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
  15584. }
  15585. stopWorkTimer(workInProgress);
  15586. resetCurrentFiber();
  15587. resetChildExpirationTime(workInProgress);
  15588. if (next !== null) {
  15589. // Completing this fiber spawned new work. Work on that next.
  15590. return next;
  15591. }
  15592. if (
  15593. returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  15594. (returnFiber.effectTag & Incomplete) === NoEffect
  15595. ) {
  15596. // Append all the effects of the subtree and this fiber onto the effect
  15597. // list of the parent. The completion order of the children affects the
  15598. // side-effect order.
  15599. if (returnFiber.firstEffect === null) {
  15600. returnFiber.firstEffect = workInProgress.firstEffect;
  15601. }
  15602. if (workInProgress.lastEffect !== null) {
  15603. if (returnFiber.lastEffect !== null) {
  15604. returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
  15605. }
  15606. returnFiber.lastEffect = workInProgress.lastEffect;
  15607. } // If this fiber had side-effects, we append it AFTER the children's
  15608. // side-effects. We can perform certain side-effects earlier if needed,
  15609. // by doing multiple passes over the effect list. We don't want to
  15610. // schedule our own side-effect on our own list because if end up
  15611. // reusing children we'll schedule this effect onto itself since we're
  15612. // at the end.
  15613. var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
  15614. // list. PerformedWork effect is read by React DevTools but shouldn't be
  15615. // committed.
  15616. if (effectTag > PerformedWork) {
  15617. if (returnFiber.lastEffect !== null) {
  15618. returnFiber.lastEffect.nextEffect = workInProgress;
  15619. } else {
  15620. returnFiber.firstEffect = workInProgress;
  15621. }
  15622. returnFiber.lastEffect = workInProgress;
  15623. }
  15624. }
  15625. } else {
  15626. // This fiber did not complete because something threw. Pop values off
  15627. // the stack without entering the complete phase. If this is a boundary,
  15628. // capture values if possible.
  15629. var _next = unwindWork(workInProgress); // Because this fiber did not complete, don't reset its expiration time.
  15630. if ((workInProgress.mode & ProfileMode) !== NoMode) {
  15631. // Record the render duration for the fiber that errored.
  15632. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
  15633. var actualDuration = workInProgress.actualDuration;
  15634. var child = workInProgress.child;
  15635. while (child !== null) {
  15636. actualDuration += child.actualDuration;
  15637. child = child.sibling;
  15638. }
  15639. workInProgress.actualDuration = actualDuration;
  15640. }
  15641. if (_next !== null) {
  15642. // If completing this work spawned new work, do that next. We'll come
  15643. // back here again.
  15644. // Since we're restarting, remove anything that is not a host effect
  15645. // from the effect tag.
  15646. // TODO: The name stopFailedWorkTimer is misleading because Suspense
  15647. // also captures and restarts.
  15648. stopFailedWorkTimer(workInProgress);
  15649. _next.effectTag &= HostEffectMask;
  15650. return _next;
  15651. }
  15652. stopWorkTimer(workInProgress);
  15653. if (returnFiber !== null) {
  15654. // Mark the parent fiber as incomplete and clear its effect list.
  15655. returnFiber.firstEffect = returnFiber.lastEffect = null;
  15656. returnFiber.effectTag |= Incomplete;
  15657. }
  15658. }
  15659. var siblingFiber = workInProgress.sibling;
  15660. if (siblingFiber !== null) {
  15661. // If there is more work to do in this returnFiber, do that next.
  15662. return siblingFiber;
  15663. } // Otherwise, return to the parent
  15664. workInProgress = returnFiber;
  15665. } while (workInProgress !== null); // We've reached the root.
  15666. if (workInProgressRootExitStatus === RootIncomplete) {
  15667. workInProgressRootExitStatus = RootCompleted;
  15668. }
  15669. return null;
  15670. }
  15671. function getRemainingExpirationTime(fiber) {
  15672. var updateExpirationTime = fiber.expirationTime;
  15673. var childExpirationTime = fiber.childExpirationTime;
  15674. return updateExpirationTime > childExpirationTime
  15675. ? updateExpirationTime
  15676. : childExpirationTime;
  15677. }
  15678. function resetChildExpirationTime(completedWork) {
  15679. if (
  15680. renderExpirationTime$1 !== Never &&
  15681. completedWork.childExpirationTime === Never
  15682. ) {
  15683. // The children of this component are hidden. Don't bubble their
  15684. // expiration times.
  15685. return;
  15686. }
  15687. var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
  15688. if ((completedWork.mode & ProfileMode) !== NoMode) {
  15689. // In profiling mode, resetChildExpirationTime is also used to reset
  15690. // profiler durations.
  15691. var actualDuration = completedWork.actualDuration;
  15692. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  15693. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  15694. // When work is done, it should bubble to the parent's actualDuration. If
  15695. // the fiber has not been cloned though, (meaning no work was done), then
  15696. // this value will reflect the amount of time spent working on a previous
  15697. // render. In that case it should not bubble. We determine whether it was
  15698. // cloned by comparing the child pointer.
  15699. var shouldBubbleActualDurations =
  15700. completedWork.alternate === null ||
  15701. completedWork.child !== completedWork.alternate.child;
  15702. var child = completedWork.child;
  15703. while (child !== null) {
  15704. var childUpdateExpirationTime = child.expirationTime;
  15705. var childChildExpirationTime = child.childExpirationTime;
  15706. if (childUpdateExpirationTime > newChildExpirationTime) {
  15707. newChildExpirationTime = childUpdateExpirationTime;
  15708. }
  15709. if (childChildExpirationTime > newChildExpirationTime) {
  15710. newChildExpirationTime = childChildExpirationTime;
  15711. }
  15712. if (shouldBubbleActualDurations) {
  15713. actualDuration += child.actualDuration;
  15714. }
  15715. treeBaseDuration += child.treeBaseDuration;
  15716. child = child.sibling;
  15717. }
  15718. completedWork.actualDuration = actualDuration;
  15719. completedWork.treeBaseDuration = treeBaseDuration;
  15720. } else {
  15721. var _child = completedWork.child;
  15722. while (_child !== null) {
  15723. var _childUpdateExpirationTime = _child.expirationTime;
  15724. var _childChildExpirationTime = _child.childExpirationTime;
  15725. if (_childUpdateExpirationTime > newChildExpirationTime) {
  15726. newChildExpirationTime = _childUpdateExpirationTime;
  15727. }
  15728. if (_childChildExpirationTime > newChildExpirationTime) {
  15729. newChildExpirationTime = _childChildExpirationTime;
  15730. }
  15731. _child = _child.sibling;
  15732. }
  15733. }
  15734. completedWork.childExpirationTime = newChildExpirationTime;
  15735. }
  15736. function commitRoot(root) {
  15737. var renderPriorityLevel = getCurrentPriorityLevel();
  15738. runWithPriority(
  15739. ImmediatePriority,
  15740. commitRootImpl.bind(null, root, renderPriorityLevel)
  15741. );
  15742. return null;
  15743. }
  15744. function commitRootImpl(root, renderPriorityLevel) {
  15745. do {
  15746. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  15747. // means `flushPassiveEffects` will sometimes result in additional
  15748. // passive effects. So we need to keep flushing in a loop until there are
  15749. // no more pending effects.
  15750. // TODO: Might be better if `flushPassiveEffects` did not automatically
  15751. // flush synchronous work at the end, to avoid factoring hazards like this.
  15752. flushPassiveEffects();
  15753. } while (rootWithPendingPassiveEffects !== null);
  15754. flushRenderPhaseStrictModeWarningsInDEV();
  15755. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15756. throw Error("Should not already be working.");
  15757. }
  15758. var finishedWork = root.finishedWork;
  15759. var expirationTime = root.finishedExpirationTime;
  15760. if (finishedWork === null) {
  15761. return null;
  15762. }
  15763. root.finishedWork = null;
  15764. root.finishedExpirationTime = NoWork;
  15765. if (!(finishedWork !== root.current)) {
  15766. throw Error(
  15767. "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue."
  15768. );
  15769. } // commitRoot never returns a continuation; it always finishes synchronously.
  15770. // So we can clear these now to allow a new callback to be scheduled.
  15771. root.callbackNode = null;
  15772. root.callbackExpirationTime = NoWork;
  15773. root.callbackPriority = NoPriority;
  15774. root.nextKnownPendingLevel = NoWork;
  15775. startCommitTimer(); // Update the first and last pending times on this root. The new first
  15776. // pending time is whatever is left on the root fiber.
  15777. var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(
  15778. finishedWork
  15779. );
  15780. markRootFinishedAtTime(
  15781. root,
  15782. expirationTime,
  15783. remainingExpirationTimeBeforeCommit
  15784. );
  15785. if (root === workInProgressRoot) {
  15786. // We can reset these now that they are finished.
  15787. workInProgressRoot = null;
  15788. workInProgress = null;
  15789. renderExpirationTime$1 = NoWork;
  15790. } // This indicates that the last root we worked on is not the same one that
  15791. // we're committing now. This most commonly happens when a suspended root
  15792. // times out.
  15793. // Get the list of effects.
  15794. var firstEffect;
  15795. if (finishedWork.effectTag > PerformedWork) {
  15796. // A fiber's effect list consists only of its children, not itself. So if
  15797. // the root has an effect, we need to add it to the end of the list. The
  15798. // resulting list is the set that would belong to the root's parent, if it
  15799. // had one; that is, all the effects in the tree including the root.
  15800. if (finishedWork.lastEffect !== null) {
  15801. finishedWork.lastEffect.nextEffect = finishedWork;
  15802. firstEffect = finishedWork.firstEffect;
  15803. } else {
  15804. firstEffect = finishedWork;
  15805. }
  15806. } else {
  15807. // There is no effect on the root.
  15808. firstEffect = finishedWork.firstEffect;
  15809. }
  15810. if (firstEffect !== null) {
  15811. var prevExecutionContext = executionContext;
  15812. executionContext |= CommitContext;
  15813. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  15814. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  15815. // of the effect list for each phase: all mutation effects come before all
  15816. // layout effects, and so on.
  15817. // The first phase a "before mutation" phase. We use this phase to read the
  15818. // state of the host tree right before we mutate it. This is where
  15819. // getSnapshotBeforeUpdate is called.
  15820. startCommitSnapshotEffectsTimer();
  15821. prepareForCommit(root.containerInfo);
  15822. nextEffect = firstEffect;
  15823. do {
  15824. {
  15825. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  15826. if (hasCaughtError()) {
  15827. if (!(nextEffect !== null)) {
  15828. throw Error("Should be working on an effect.");
  15829. }
  15830. var error = clearCaughtError();
  15831. captureCommitPhaseError(nextEffect, error);
  15832. nextEffect = nextEffect.nextEffect;
  15833. }
  15834. }
  15835. } while (nextEffect !== null);
  15836. stopCommitSnapshotEffectsTimer();
  15837. {
  15838. // Mark the current commit time to be shared by all Profilers in this
  15839. // batch. This enables them to be grouped later.
  15840. recordCommitTime();
  15841. } // The next phase is the mutation phase, where we mutate the host tree.
  15842. startCommitHostEffectsTimer();
  15843. nextEffect = firstEffect;
  15844. do {
  15845. {
  15846. invokeGuardedCallback(
  15847. null,
  15848. commitMutationEffects,
  15849. null,
  15850. root,
  15851. renderPriorityLevel
  15852. );
  15853. if (hasCaughtError()) {
  15854. if (!(nextEffect !== null)) {
  15855. throw Error("Should be working on an effect.");
  15856. }
  15857. var _error = clearCaughtError();
  15858. captureCommitPhaseError(nextEffect, _error);
  15859. nextEffect = nextEffect.nextEffect;
  15860. }
  15861. }
  15862. } while (nextEffect !== null);
  15863. stopCommitHostEffectsTimer();
  15864. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  15865. // the mutation phase, so that the previous tree is still current during
  15866. // componentWillUnmount, but before the layout phase, so that the finished
  15867. // work is current during componentDidMount/Update.
  15868. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  15869. // the host tree after it's been mutated. The idiomatic use case for this is
  15870. // layout, but class component lifecycles also fire here for legacy reasons.
  15871. startCommitLifeCyclesTimer();
  15872. nextEffect = firstEffect;
  15873. do {
  15874. {
  15875. invokeGuardedCallback(
  15876. null,
  15877. commitLayoutEffects,
  15878. null,
  15879. root,
  15880. expirationTime
  15881. );
  15882. if (hasCaughtError()) {
  15883. if (!(nextEffect !== null)) {
  15884. throw Error("Should be working on an effect.");
  15885. }
  15886. var _error2 = clearCaughtError();
  15887. captureCommitPhaseError(nextEffect, _error2);
  15888. nextEffect = nextEffect.nextEffect;
  15889. }
  15890. }
  15891. } while (nextEffect !== null);
  15892. stopCommitLifeCyclesTimer();
  15893. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  15894. // opportunity to paint.
  15895. requestPaint();
  15896. {
  15897. popInteractions(prevInteractions);
  15898. }
  15899. executionContext = prevExecutionContext;
  15900. } else {
  15901. // No effects.
  15902. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  15903. // no effects.
  15904. // TODO: Maybe there's a better way to report this.
  15905. startCommitSnapshotEffectsTimer();
  15906. stopCommitSnapshotEffectsTimer();
  15907. {
  15908. recordCommitTime();
  15909. }
  15910. startCommitHostEffectsTimer();
  15911. stopCommitHostEffectsTimer();
  15912. startCommitLifeCyclesTimer();
  15913. stopCommitLifeCyclesTimer();
  15914. }
  15915. stopCommitTimer();
  15916. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  15917. if (rootDoesHavePassiveEffects) {
  15918. // This commit has passive effects. Stash a reference to them. But don't
  15919. // schedule a callback until after flushing layout work.
  15920. rootDoesHavePassiveEffects = false;
  15921. rootWithPendingPassiveEffects = root;
  15922. pendingPassiveEffectsExpirationTime = expirationTime;
  15923. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  15924. } else {
  15925. // We are done with the effect chain at this point so let's clear the
  15926. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  15927. // clear this in flushPassiveEffects.
  15928. nextEffect = firstEffect;
  15929. while (nextEffect !== null) {
  15930. var nextNextEffect = nextEffect.nextEffect;
  15931. nextEffect.nextEffect = null;
  15932. nextEffect = nextNextEffect;
  15933. }
  15934. } // Check if there's remaining work on this root
  15935. var remainingExpirationTime = root.firstPendingTime;
  15936. if (remainingExpirationTime !== NoWork) {
  15937. {
  15938. if (spawnedWorkDuringRender !== null) {
  15939. var expirationTimes = spawnedWorkDuringRender;
  15940. spawnedWorkDuringRender = null;
  15941. for (var i = 0; i < expirationTimes.length; i++) {
  15942. scheduleInteractions(
  15943. root,
  15944. expirationTimes[i],
  15945. root.memoizedInteractions
  15946. );
  15947. }
  15948. }
  15949. schedulePendingInteractions(root, remainingExpirationTime);
  15950. }
  15951. } else {
  15952. // If there's no remaining work, we can clear the set of already failed
  15953. // error boundaries.
  15954. legacyErrorBoundariesThatAlreadyFailed = null;
  15955. }
  15956. {
  15957. if (!rootDidHavePassiveEffects) {
  15958. // If there are no passive effects, then we can complete the pending interactions.
  15959. // Otherwise, we'll wait until after the passive effects are flushed.
  15960. // Wait to do this until after remaining work has been scheduled,
  15961. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  15962. finishPendingInteractions(root, expirationTime);
  15963. }
  15964. }
  15965. if (remainingExpirationTime === Sync) {
  15966. // Count the number of times the root synchronously re-renders without
  15967. // finishing. If there are too many, it indicates an infinite update loop.
  15968. if (root === rootWithNestedUpdates) {
  15969. nestedUpdateCount++;
  15970. } else {
  15971. nestedUpdateCount = 0;
  15972. rootWithNestedUpdates = root;
  15973. }
  15974. } else {
  15975. nestedUpdateCount = 0;
  15976. }
  15977. onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
  15978. // additional work on this root is scheduled.
  15979. ensureRootIsScheduled(root);
  15980. if (hasUncaughtError) {
  15981. hasUncaughtError = false;
  15982. var _error3 = firstUncaughtError;
  15983. firstUncaughtError = null;
  15984. throw _error3;
  15985. }
  15986. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  15987. // This is a legacy edge case. We just committed the initial mount of
  15988. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  15989. // synchronously, but layout updates should be deferred until the end
  15990. // of the batch.
  15991. return null;
  15992. } // If layout work was scheduled, flush it now.
  15993. flushSyncCallbackQueue();
  15994. return null;
  15995. }
  15996. function commitBeforeMutationEffects() {
  15997. while (nextEffect !== null) {
  15998. var effectTag = nextEffect.effectTag;
  15999. if ((effectTag & Snapshot) !== NoEffect) {
  16000. setCurrentFiber(nextEffect);
  16001. recordEffect();
  16002. var current = nextEffect.alternate;
  16003. commitBeforeMutationLifeCycles(current, nextEffect);
  16004. resetCurrentFiber();
  16005. }
  16006. if ((effectTag & Passive) !== NoEffect) {
  16007. // If there are passive effects, schedule a callback to flush at
  16008. // the earliest opportunity.
  16009. if (!rootDoesHavePassiveEffects) {
  16010. rootDoesHavePassiveEffects = true;
  16011. scheduleCallback(NormalPriority, function() {
  16012. flushPassiveEffects();
  16013. return null;
  16014. });
  16015. }
  16016. }
  16017. nextEffect = nextEffect.nextEffect;
  16018. }
  16019. }
  16020. function commitMutationEffects(root, renderPriorityLevel) {
  16021. // TODO: Should probably move the bulk of this function to commitWork.
  16022. while (nextEffect !== null) {
  16023. setCurrentFiber(nextEffect);
  16024. var effectTag = nextEffect.effectTag;
  16025. if (effectTag & ContentReset) {
  16026. commitResetTextContent(nextEffect);
  16027. }
  16028. if (effectTag & Ref) {
  16029. var current = nextEffect.alternate;
  16030. if (current !== null) {
  16031. commitDetachRef(current);
  16032. }
  16033. } // The following switch statement is only concerned about placement,
  16034. // updates, and deletions. To avoid needing to add a case for every possible
  16035. // bitmap value, we remove the secondary effects from the effect tag and
  16036. // switch on that value.
  16037. var primaryEffectTag =
  16038. effectTag & (Placement | Update | Deletion | Hydrating);
  16039. switch (primaryEffectTag) {
  16040. case Placement: {
  16041. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  16042. // inserted, before any life-cycles like componentDidMount gets called.
  16043. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  16044. // and isMounted is deprecated anyway so we should be able to kill this.
  16045. nextEffect.effectTag &= ~Placement;
  16046. break;
  16047. }
  16048. case PlacementAndUpdate: {
  16049. // Placement
  16050. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  16051. // inserted, before any life-cycles like componentDidMount gets called.
  16052. nextEffect.effectTag &= ~Placement; // Update
  16053. var _current = nextEffect.alternate;
  16054. commitWork(_current, nextEffect);
  16055. break;
  16056. }
  16057. case Hydrating: {
  16058. nextEffect.effectTag &= ~Hydrating;
  16059. break;
  16060. }
  16061. case HydratingAndUpdate: {
  16062. nextEffect.effectTag &= ~Hydrating; // Update
  16063. var _current2 = nextEffect.alternate;
  16064. commitWork(_current2, nextEffect);
  16065. break;
  16066. }
  16067. case Update: {
  16068. var _current3 = nextEffect.alternate;
  16069. commitWork(_current3, nextEffect);
  16070. break;
  16071. }
  16072. case Deletion: {
  16073. commitDeletion(root, nextEffect, renderPriorityLevel);
  16074. break;
  16075. }
  16076. } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
  16077. recordEffect();
  16078. resetCurrentFiber();
  16079. nextEffect = nextEffect.nextEffect;
  16080. }
  16081. }
  16082. function commitLayoutEffects(root, committedExpirationTime) {
  16083. // TODO: Should probably move the bulk of this function to commitWork.
  16084. while (nextEffect !== null) {
  16085. setCurrentFiber(nextEffect);
  16086. var effectTag = nextEffect.effectTag;
  16087. if (effectTag & (Update | Callback)) {
  16088. recordEffect();
  16089. var current = nextEffect.alternate;
  16090. commitLifeCycles(root, current, nextEffect);
  16091. }
  16092. if (effectTag & Ref) {
  16093. recordEffect();
  16094. commitAttachRef(nextEffect);
  16095. }
  16096. resetCurrentFiber();
  16097. nextEffect = nextEffect.nextEffect;
  16098. }
  16099. }
  16100. function flushPassiveEffects() {
  16101. if (pendingPassiveEffectsRenderPriority !== NoPriority) {
  16102. var priorityLevel =
  16103. pendingPassiveEffectsRenderPriority > NormalPriority
  16104. ? NormalPriority
  16105. : pendingPassiveEffectsRenderPriority;
  16106. pendingPassiveEffectsRenderPriority = NoPriority;
  16107. return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
  16108. }
  16109. }
  16110. function flushPassiveEffectsImpl() {
  16111. if (rootWithPendingPassiveEffects === null) {
  16112. return false;
  16113. }
  16114. var root = rootWithPendingPassiveEffects;
  16115. var expirationTime = pendingPassiveEffectsExpirationTime;
  16116. rootWithPendingPassiveEffects = null;
  16117. pendingPassiveEffectsExpirationTime = NoWork;
  16118. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  16119. throw Error("Cannot flush passive effects while already rendering.");
  16120. }
  16121. var prevExecutionContext = executionContext;
  16122. executionContext |= CommitContext;
  16123. var prevInteractions = pushInteractions(root);
  16124. {
  16125. // Note: This currently assumes there are no passive effects on the root fiber
  16126. // because the root is not part of its own effect list.
  16127. // This could change in the future.
  16128. var _effect2 = root.current.firstEffect;
  16129. while (_effect2 !== null) {
  16130. {
  16131. setCurrentFiber(_effect2);
  16132. invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
  16133. if (hasCaughtError()) {
  16134. if (!(_effect2 !== null)) {
  16135. throw Error("Should be working on an effect.");
  16136. }
  16137. var _error5 = clearCaughtError();
  16138. captureCommitPhaseError(_effect2, _error5);
  16139. }
  16140. resetCurrentFiber();
  16141. }
  16142. var nextNextEffect = _effect2.nextEffect; // Remove nextEffect pointer to assist GC
  16143. _effect2.nextEffect = null;
  16144. _effect2 = nextNextEffect;
  16145. }
  16146. }
  16147. {
  16148. popInteractions(prevInteractions);
  16149. finishPendingInteractions(root, expirationTime);
  16150. }
  16151. executionContext = prevExecutionContext;
  16152. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  16153. // exceeds the limit, we'll fire a warning.
  16154. nestedPassiveUpdateCount =
  16155. rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  16156. return true;
  16157. }
  16158. function isAlreadyFailedLegacyErrorBoundary(instance) {
  16159. return (
  16160. legacyErrorBoundariesThatAlreadyFailed !== null &&
  16161. legacyErrorBoundariesThatAlreadyFailed.has(instance)
  16162. );
  16163. }
  16164. function markLegacyErrorBoundaryAsFailed(instance) {
  16165. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  16166. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  16167. } else {
  16168. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  16169. }
  16170. }
  16171. function prepareToThrowUncaughtError(error) {
  16172. if (!hasUncaughtError) {
  16173. hasUncaughtError = true;
  16174. firstUncaughtError = error;
  16175. }
  16176. }
  16177. var onUncaughtError = prepareToThrowUncaughtError;
  16178. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  16179. var errorInfo = createCapturedValue(error, sourceFiber);
  16180. var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
  16181. enqueueUpdate(rootFiber, update);
  16182. var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
  16183. if (root !== null) {
  16184. ensureRootIsScheduled(root);
  16185. schedulePendingInteractions(root, Sync);
  16186. }
  16187. }
  16188. function captureCommitPhaseError(sourceFiber, error) {
  16189. if (sourceFiber.tag === HostRoot) {
  16190. // Error was thrown at the root. There is no parent, so the root
  16191. // itself should capture it.
  16192. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  16193. return;
  16194. }
  16195. var fiber = sourceFiber.return;
  16196. while (fiber !== null) {
  16197. if (fiber.tag === HostRoot) {
  16198. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  16199. return;
  16200. } else if (fiber.tag === ClassComponent) {
  16201. var ctor = fiber.type;
  16202. var instance = fiber.stateNode;
  16203. if (
  16204. typeof ctor.getDerivedStateFromError === "function" ||
  16205. (typeof instance.componentDidCatch === "function" &&
  16206. !isAlreadyFailedLegacyErrorBoundary(instance))
  16207. ) {
  16208. var errorInfo = createCapturedValue(error, sourceFiber);
  16209. var update = createClassErrorUpdate(
  16210. fiber,
  16211. errorInfo, // TODO: This is always sync
  16212. Sync
  16213. );
  16214. enqueueUpdate(fiber, update);
  16215. var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
  16216. if (root !== null) {
  16217. ensureRootIsScheduled(root);
  16218. schedulePendingInteractions(root, Sync);
  16219. }
  16220. return;
  16221. }
  16222. }
  16223. fiber = fiber.return;
  16224. }
  16225. }
  16226. function pingSuspendedRoot(root, thenable, suspendedTime) {
  16227. var pingCache = root.pingCache;
  16228. if (pingCache !== null) {
  16229. // The thenable resolved, so we no longer need to memoize, because it will
  16230. // never be thrown again.
  16231. pingCache.delete(thenable);
  16232. }
  16233. if (workInProgressRoot === root && renderExpirationTime$1 === suspendedTime) {
  16234. // Received a ping at the same priority level at which we're currently
  16235. // rendering. We might want to restart this render. This should mirror
  16236. // the logic of whether or not a root suspends once it completes.
  16237. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  16238. // we should probably never restart.
  16239. // If we're suspended with delay, we'll always suspend so we can always
  16240. // restart. If we're suspended without any updates, it might be a retry.
  16241. // If it's early in the retry we can restart. We can't know for sure
  16242. // whether we'll eventually process an update during this render pass,
  16243. // but it's somewhat unlikely that we get to a ping before that, since
  16244. // getting to the root most update is usually very fast.
  16245. if (
  16246. workInProgressRootExitStatus === RootSuspendedWithDelay ||
  16247. (workInProgressRootExitStatus === RootSuspended &&
  16248. workInProgressRootLatestProcessedExpirationTime === Sync &&
  16249. now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS)
  16250. ) {
  16251. // Restart from the root. Don't need to schedule a ping because
  16252. // we're already working on this tree.
  16253. prepareFreshStack(root, renderExpirationTime$1);
  16254. } else {
  16255. // Even though we can't restart right now, we might get an
  16256. // opportunity later. So we mark this render as having a ping.
  16257. workInProgressRootHasPendingPing = true;
  16258. }
  16259. return;
  16260. }
  16261. if (!isRootSuspendedAtTime(root, suspendedTime)) {
  16262. // The root is no longer suspended at this time.
  16263. return;
  16264. }
  16265. var lastPingedTime = root.lastPingedTime;
  16266. if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
  16267. // There's already a lower priority ping scheduled.
  16268. return;
  16269. } // Mark the time at which this ping was scheduled.
  16270. root.lastPingedTime = suspendedTime;
  16271. ensureRootIsScheduled(root);
  16272. schedulePendingInteractions(root, suspendedTime);
  16273. }
  16274. function retryTimedOutBoundary(boundaryFiber, retryTime) {
  16275. // The boundary fiber (a Suspense component or SuspenseList component)
  16276. // previously was rendered in its fallback state. One of the promises that
  16277. // suspended it has resolved, which means at least part of the tree was
  16278. // likely unblocked. Try rendering again, at a new expiration time.
  16279. if (retryTime === NoWork) {
  16280. var suspenseConfig = null; // Retries don't carry over the already committed update.
  16281. var currentTime = requestCurrentTimeForUpdate();
  16282. retryTime = computeExpirationForFiber(
  16283. currentTime,
  16284. boundaryFiber,
  16285. suspenseConfig
  16286. );
  16287. } // TODO: Special case idle priority?
  16288. var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
  16289. if (root !== null) {
  16290. ensureRootIsScheduled(root);
  16291. schedulePendingInteractions(root, retryTime);
  16292. }
  16293. }
  16294. function resolveRetryThenable(boundaryFiber, thenable) {
  16295. var retryTime = NoWork; // Default
  16296. var retryCache;
  16297. {
  16298. retryCache = boundaryFiber.stateNode;
  16299. }
  16300. if (retryCache !== null) {
  16301. // The thenable resolved, so we no longer need to memoize, because it will
  16302. // never be thrown again.
  16303. retryCache.delete(thenable);
  16304. }
  16305. retryTimedOutBoundary(boundaryFiber, retryTime);
  16306. } // Computes the next Just Noticeable Difference (JND) boundary.
  16307. // The theory is that a person can't tell the difference between small differences in time.
  16308. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  16309. // difference in the experience. However, waiting for longer might mean that we can avoid
  16310. // showing an intermediate loading state. The longer we have already waited, the harder it
  16311. // is to tell small differences in time. Therefore, the longer we've already waited,
  16312. // the longer we can wait additionally. At some point we have to give up though.
  16313. // We pick a train model where the next boundary commits at a consistent schedule.
  16314. // These particular numbers are vague estimates. We expect to adjust them based on research.
  16315. function jnd(timeElapsed) {
  16316. return timeElapsed < 120
  16317. ? 120
  16318. : timeElapsed < 480
  16319. ? 480
  16320. : timeElapsed < 1080
  16321. ? 1080
  16322. : timeElapsed < 1920
  16323. ? 1920
  16324. : timeElapsed < 3000
  16325. ? 3000
  16326. : timeElapsed < 4320
  16327. ? 4320
  16328. : ceil(timeElapsed / 1960) * 1960;
  16329. }
  16330. function computeMsUntilSuspenseLoadingDelay(
  16331. mostRecentEventTime,
  16332. committedExpirationTime,
  16333. suspenseConfig
  16334. ) {
  16335. var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
  16336. if (busyMinDurationMs <= 0) {
  16337. return 0;
  16338. }
  16339. var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
  16340. var currentTimeMs = now();
  16341. var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(
  16342. mostRecentEventTime,
  16343. suspenseConfig
  16344. );
  16345. var timeElapsed = currentTimeMs - eventTimeMs;
  16346. if (timeElapsed <= busyDelayMs) {
  16347. // If we haven't yet waited longer than the initial delay, we don't
  16348. // have to wait any additional time.
  16349. return 0;
  16350. }
  16351. var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
  16352. return msUntilTimeout;
  16353. }
  16354. function checkForNestedUpdates() {
  16355. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  16356. nestedUpdateCount = 0;
  16357. rootWithNestedUpdates = null;
  16358. {
  16359. throw Error(
  16360. "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."
  16361. );
  16362. }
  16363. }
  16364. {
  16365. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  16366. nestedPassiveUpdateCount = 0;
  16367. error(
  16368. "Maximum update depth exceeded. This can happen when a component " +
  16369. "calls setState inside useEffect, but useEffect either doesn't " +
  16370. "have a dependency array, or one of the dependencies changes on " +
  16371. "every render."
  16372. );
  16373. }
  16374. }
  16375. }
  16376. function flushRenderPhaseStrictModeWarningsInDEV() {
  16377. {
  16378. ReactStrictModeWarnings.flushLegacyContextWarning();
  16379. {
  16380. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  16381. }
  16382. }
  16383. }
  16384. function stopFinishedWorkLoopTimer() {
  16385. var didCompleteRoot = true;
  16386. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  16387. interruptedBy = null;
  16388. }
  16389. function stopInterruptedWorkLoopTimer() {
  16390. // TODO: Track which fiber caused the interruption.
  16391. var didCompleteRoot = false;
  16392. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  16393. interruptedBy = null;
  16394. }
  16395. function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
  16396. if (
  16397. workInProgressRoot !== null &&
  16398. updateExpirationTime > renderExpirationTime$1
  16399. ) {
  16400. interruptedBy = fiberThatReceivedUpdate;
  16401. }
  16402. }
  16403. var didWarnStateUpdateForUnmountedComponent = null;
  16404. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  16405. {
  16406. var tag = fiber.tag;
  16407. if (
  16408. tag !== HostRoot &&
  16409. tag !== ClassComponent &&
  16410. tag !== FunctionComponent &&
  16411. tag !== ForwardRef &&
  16412. tag !== MemoComponent &&
  16413. tag !== SimpleMemoComponent &&
  16414. tag !== Block
  16415. ) {
  16416. // Only warn for user-defined components, not internal ones like Suspense.
  16417. return;
  16418. }
  16419. // the problematic code almost always lies inside that component.
  16420. var componentName = getComponentName(fiber.type) || "ReactComponent";
  16421. if (didWarnStateUpdateForUnmountedComponent !== null) {
  16422. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  16423. return;
  16424. }
  16425. didWarnStateUpdateForUnmountedComponent.add(componentName);
  16426. } else {
  16427. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  16428. }
  16429. error(
  16430. "Can't perform a React state update on an unmounted component. This " +
  16431. "is a no-op, but it indicates a memory leak in your application. To " +
  16432. "fix, cancel all subscriptions and asynchronous tasks in %s.%s",
  16433. tag === ClassComponent
  16434. ? "the componentWillUnmount method"
  16435. : "a useEffect cleanup function",
  16436. getStackByFiberInDevAndProd(fiber)
  16437. );
  16438. }
  16439. }
  16440. var beginWork$1;
  16441. {
  16442. var dummyFiber = null;
  16443. beginWork$1 = function(current, unitOfWork, expirationTime) {
  16444. // If a component throws an error, we replay it again in a synchronously
  16445. // dispatched event, so that the debugger will treat it as an uncaught
  16446. // error See ReactErrorUtils for more information.
  16447. // Before entering the begin phase, copy the work-in-progress onto a dummy
  16448. // fiber. If beginWork throws, we'll use this to reset the state.
  16449. var originalWorkInProgressCopy = assignFiberPropertiesInDEV(
  16450. dummyFiber,
  16451. unitOfWork
  16452. );
  16453. try {
  16454. return beginWork(current, unitOfWork, expirationTime);
  16455. } catch (originalError) {
  16456. if (
  16457. originalError !== null &&
  16458. typeof originalError === "object" &&
  16459. typeof originalError.then === "function"
  16460. ) {
  16461. // Don't replay promises. Treat everything else like an error.
  16462. throw originalError;
  16463. } // Keep this code in sync with handleError; any changes here must have
  16464. // corresponding changes there.
  16465. resetContextDependencies();
  16466. resetHooksAfterThrow(); // Don't reset current debug fiber, since we're about to work on the
  16467. // same fiber again.
  16468. // Unwind the failed stack frame
  16469. unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
  16470. assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
  16471. if (unitOfWork.mode & ProfileMode) {
  16472. // Reset the profiler timer.
  16473. startProfilerTimer(unitOfWork);
  16474. } // Run beginWork again.
  16475. invokeGuardedCallback(
  16476. null,
  16477. beginWork,
  16478. null,
  16479. current,
  16480. unitOfWork,
  16481. expirationTime
  16482. );
  16483. if (hasCaughtError()) {
  16484. var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
  16485. // Rethrow this error instead of the original one.
  16486. throw replayError;
  16487. } else {
  16488. // This branch is reachable if the render phase is impure.
  16489. throw originalError;
  16490. }
  16491. }
  16492. };
  16493. }
  16494. var didWarnAboutUpdateInRender = false;
  16495. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  16496. {
  16497. if ((executionContext & RenderContext) !== NoContext) {
  16498. switch (fiber.tag) {
  16499. case FunctionComponent:
  16500. case ForwardRef:
  16501. case SimpleMemoComponent: {
  16502. error(
  16503. "Cannot update a component from inside the function body of a " +
  16504. "different component."
  16505. );
  16506. break;
  16507. }
  16508. case ClassComponent: {
  16509. if (isRendering && !didWarnAboutUpdateInRender) {
  16510. error(
  16511. "Cannot update during an existing state transition (such as " +
  16512. "within `render`). Render methods should be a pure " +
  16513. "function of props and state."
  16514. );
  16515. didWarnAboutUpdateInRender = true;
  16516. break;
  16517. }
  16518. }
  16519. }
  16520. }
  16521. }
  16522. } // a 'shared' variable that changes when act() opens/closes in tests.
  16523. var IsThisRendererActing = {
  16524. current: false
  16525. };
  16526. function warnIfNotScopedWithMatchingAct(fiber) {
  16527. {
  16528. if (
  16529. IsSomeRendererActing.current === true &&
  16530. IsThisRendererActing.current !== true
  16531. ) {
  16532. error(
  16533. "It looks like you're using the wrong act() around your test interactions.\n" +
  16534. "Be sure to use the matching version of act() corresponding to your renderer:\n\n" +
  16535. "// for react-dom:\n" + // Break up imports to avoid accidentally parsing them as dependencies.
  16536. "import {act} fr" +
  16537. "om 'react-dom/test-utils';\n" +
  16538. "// ...\n" +
  16539. "act(() => ...);\n\n" +
  16540. "// for react-test-renderer:\n" + // Break up imports to avoid accidentally parsing them as dependencies.
  16541. "import TestRenderer fr" +
  16542. "om react-test-renderer';\n" +
  16543. "const {act} = TestRenderer;\n" +
  16544. "// ...\n" +
  16545. "act(() => ...);" +
  16546. "%s",
  16547. getStackByFiberInDevAndProd(fiber)
  16548. );
  16549. }
  16550. }
  16551. }
  16552. function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
  16553. {
  16554. if (
  16555. (fiber.mode & StrictMode) !== NoMode &&
  16556. IsSomeRendererActing.current === false &&
  16557. IsThisRendererActing.current === false
  16558. ) {
  16559. error(
  16560. "An update to %s ran an effect, but was not wrapped in act(...).\n\n" +
  16561. "When testing, code that causes React state updates should be " +
  16562. "wrapped into act(...):\n\n" +
  16563. "act(() => {\n" +
  16564. " /* fire events that update state */\n" +
  16565. "});\n" +
  16566. "/* assert on the output */\n\n" +
  16567. "This ensures that you're testing the behavior the user would see " +
  16568. "in the browser." +
  16569. " Learn more at https://fb.me/react-wrap-tests-with-act" +
  16570. "%s",
  16571. getComponentName(fiber.type),
  16572. getStackByFiberInDevAndProd(fiber)
  16573. );
  16574. }
  16575. }
  16576. }
  16577. function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
  16578. {
  16579. if (
  16580. executionContext === NoContext &&
  16581. IsSomeRendererActing.current === false &&
  16582. IsThisRendererActing.current === false
  16583. ) {
  16584. error(
  16585. "An update to %s inside a test was not wrapped in act(...).\n\n" +
  16586. "When testing, code that causes React state updates should be " +
  16587. "wrapped into act(...):\n\n" +
  16588. "act(() => {\n" +
  16589. " /* fire events that update state */\n" +
  16590. "});\n" +
  16591. "/* assert on the output */\n\n" +
  16592. "This ensures that you're testing the behavior the user would see " +
  16593. "in the browser." +
  16594. " Learn more at https://fb.me/react-wrap-tests-with-act" +
  16595. "%s",
  16596. getComponentName(fiber.type),
  16597. getStackByFiberInDevAndProd(fiber)
  16598. );
  16599. }
  16600. }
  16601. }
  16602. var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
  16603. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  16604. // scheduler is the actual recommendation. The alternative could be a testing build,
  16605. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  16606. // to get their tests right.
  16607. function warnIfUnmockedScheduler(fiber) {
  16608. {
  16609. if (
  16610. didWarnAboutUnmockedScheduler === false &&
  16611. Scheduler.unstable_flushAllWithoutAsserting === undefined
  16612. ) {
  16613. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  16614. didWarnAboutUnmockedScheduler = true;
  16615. error(
  16616. 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
  16617. "to guarantee consistent behaviour across tests and browsers. " +
  16618. "For example, with jest: \n" + // Break up requires to avoid accidentally parsing them as dependencies.
  16619. "jest.mock('scheduler', () => require" +
  16620. "('scheduler/unstable_mock'));\n\n" +
  16621. "For more info, visit https://fb.me/react-mock-scheduler"
  16622. );
  16623. }
  16624. }
  16625. }
  16626. }
  16627. function computeThreadID(root, expirationTime) {
  16628. // Interaction threads are unique per root and expiration time.
  16629. return expirationTime * 1000 + root.interactionThreadID;
  16630. }
  16631. function markSpawnedWork(expirationTime) {
  16632. if (spawnedWorkDuringRender === null) {
  16633. spawnedWorkDuringRender = [expirationTime];
  16634. } else {
  16635. spawnedWorkDuringRender.push(expirationTime);
  16636. }
  16637. }
  16638. function scheduleInteractions(root, expirationTime, interactions) {
  16639. if (interactions.size > 0) {
  16640. var pendingInteractionMap = root.pendingInteractionMap;
  16641. var pendingInteractions = pendingInteractionMap.get(expirationTime);
  16642. if (pendingInteractions != null) {
  16643. interactions.forEach(function(interaction) {
  16644. if (!pendingInteractions.has(interaction)) {
  16645. // Update the pending async work count for previously unscheduled interaction.
  16646. interaction.__count++;
  16647. }
  16648. pendingInteractions.add(interaction);
  16649. });
  16650. } else {
  16651. pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
  16652. interactions.forEach(function(interaction) {
  16653. interaction.__count++;
  16654. });
  16655. }
  16656. var subscriber = tracing.__subscriberRef.current;
  16657. if (subscriber !== null) {
  16658. var threadID = computeThreadID(root, expirationTime);
  16659. subscriber.onWorkScheduled(interactions, threadID);
  16660. }
  16661. }
  16662. }
  16663. function schedulePendingInteractions(root, expirationTime) {
  16664. scheduleInteractions(root, expirationTime, tracing.__interactionsRef.current);
  16665. }
  16666. function startWorkOnPendingInteractions(root, expirationTime) {
  16667. // we can accurately attribute time spent working on it, And so that cascading
  16668. // work triggered during the render phase will be associated with it.
  16669. var interactions = new Set();
  16670. root.pendingInteractionMap.forEach(function(
  16671. scheduledInteractions,
  16672. scheduledExpirationTime
  16673. ) {
  16674. if (scheduledExpirationTime >= expirationTime) {
  16675. scheduledInteractions.forEach(function(interaction) {
  16676. return interactions.add(interaction);
  16677. });
  16678. }
  16679. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  16680. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  16681. // without having to recalculate it. We will also use it in commitWork() to
  16682. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  16683. // way to access it when the onCommitRoot() hook is called.
  16684. root.memoizedInteractions = interactions;
  16685. if (interactions.size > 0) {
  16686. var subscriber = tracing.__subscriberRef.current;
  16687. if (subscriber !== null) {
  16688. var threadID = computeThreadID(root, expirationTime);
  16689. try {
  16690. subscriber.onWorkStarted(interactions, threadID);
  16691. } catch (error) {
  16692. // If the subscriber throws, rethrow it in a separate task
  16693. scheduleCallback(ImmediatePriority, function() {
  16694. throw error;
  16695. });
  16696. }
  16697. }
  16698. }
  16699. }
  16700. function finishPendingInteractions(root, committedExpirationTime) {
  16701. var earliestRemainingTimeAfterCommit = root.firstPendingTime;
  16702. var subscriber;
  16703. try {
  16704. subscriber = tracing.__subscriberRef.current;
  16705. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  16706. var threadID = computeThreadID(root, committedExpirationTime);
  16707. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  16708. }
  16709. } catch (error) {
  16710. // If the subscriber throws, rethrow it in a separate task
  16711. scheduleCallback(ImmediatePriority, function() {
  16712. throw error;
  16713. });
  16714. } finally {
  16715. // Clear completed interactions from the pending Map.
  16716. // Unless the render was suspended or cascading work was scheduled,
  16717. // In which case– leave pending interactions until the subsequent render.
  16718. var pendingInteractionMap = root.pendingInteractionMap;
  16719. pendingInteractionMap.forEach(function(
  16720. scheduledInteractions,
  16721. scheduledExpirationTime
  16722. ) {
  16723. // Only decrement the pending interaction count if we're done.
  16724. // If there's still work at the current priority,
  16725. // That indicates that we are waiting for suspense data.
  16726. if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
  16727. pendingInteractionMap.delete(scheduledExpirationTime);
  16728. scheduledInteractions.forEach(function(interaction) {
  16729. interaction.__count--;
  16730. if (subscriber !== null && interaction.__count === 0) {
  16731. try {
  16732. subscriber.onInteractionScheduledWorkCompleted(interaction);
  16733. } catch (error) {
  16734. // If the subscriber throws, rethrow it in a separate task
  16735. scheduleCallback(ImmediatePriority, function() {
  16736. throw error;
  16737. });
  16738. }
  16739. }
  16740. });
  16741. }
  16742. });
  16743. }
  16744. }
  16745. var onScheduleFiberRoot = null;
  16746. var onCommitFiberRoot = null;
  16747. var onCommitFiberUnmount = null;
  16748. var hasLoggedError = false;
  16749. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined";
  16750. function injectInternals(internals) {
  16751. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") {
  16752. // No DevTools
  16753. return false;
  16754. }
  16755. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  16756. if (hook.isDisabled) {
  16757. // This isn't a real property on the hook, but it can be set to opt out
  16758. // of DevTools integration and associated warnings and logs.
  16759. // https://github.com/facebook/react/issues/3877
  16760. return true;
  16761. }
  16762. if (!hook.supportsFiber) {
  16763. {
  16764. error(
  16765. "The installed version of React DevTools is too old and will not work " +
  16766. "with the current version of React. Please update React DevTools. " +
  16767. "https://fb.me/react-devtools"
  16768. );
  16769. } // DevTools exists, even though it doesn't support Fiber.
  16770. return true;
  16771. }
  16772. try {
  16773. var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  16774. if (true) {
  16775. // Only used by Fast Refresh
  16776. if (typeof hook.onScheduleFiberRoot === "function") {
  16777. onScheduleFiberRoot = function(root, children) {
  16778. try {
  16779. hook.onScheduleFiberRoot(rendererID, root, children);
  16780. } catch (err) {
  16781. if (true && !hasLoggedError) {
  16782. hasLoggedError = true;
  16783. error("React instrumentation encountered an error: %s", err);
  16784. }
  16785. }
  16786. };
  16787. }
  16788. }
  16789. onCommitFiberRoot = function(root, expirationTime) {
  16790. try {
  16791. var didError = (root.current.effectTag & DidCapture) === DidCapture;
  16792. if (enableProfilerTimer) {
  16793. var currentTime = getCurrentTime();
  16794. var priorityLevel = inferPriorityFromExpirationTime(
  16795. currentTime,
  16796. expirationTime
  16797. );
  16798. hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  16799. } else {
  16800. hook.onCommitFiberRoot(rendererID, root, undefined, didError);
  16801. }
  16802. } catch (err) {
  16803. if (true) {
  16804. if (!hasLoggedError) {
  16805. hasLoggedError = true;
  16806. error("React instrumentation encountered an error: %s", err);
  16807. }
  16808. }
  16809. }
  16810. };
  16811. onCommitFiberUnmount = function(fiber) {
  16812. try {
  16813. hook.onCommitFiberUnmount(rendererID, fiber);
  16814. } catch (err) {
  16815. if (true) {
  16816. if (!hasLoggedError) {
  16817. hasLoggedError = true;
  16818. error("React instrumentation encountered an error: %s", err);
  16819. }
  16820. }
  16821. }
  16822. };
  16823. } catch (err) {
  16824. // Catch all errors because it is unsafe to throw during initialization.
  16825. {
  16826. error("React instrumentation encountered an error: %s.", err);
  16827. }
  16828. } // DevTools exists
  16829. return true;
  16830. }
  16831. function onScheduleRoot(root, children) {
  16832. if (typeof onScheduleFiberRoot === "function") {
  16833. onScheduleFiberRoot(root, children);
  16834. }
  16835. }
  16836. function onCommitRoot(root, expirationTime) {
  16837. if (typeof onCommitFiberRoot === "function") {
  16838. onCommitFiberRoot(root, expirationTime);
  16839. }
  16840. }
  16841. function onCommitUnmount(fiber) {
  16842. if (typeof onCommitFiberUnmount === "function") {
  16843. onCommitFiberUnmount(fiber);
  16844. }
  16845. }
  16846. var hasBadMapPolyfill;
  16847. {
  16848. hasBadMapPolyfill = false;
  16849. try {
  16850. var nonExtensibleObject = Object.preventExtensions({});
  16851. var testMap = new Map([[nonExtensibleObject, null]]);
  16852. var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
  16853. // https://github.com/rollup/rollup/issues/1771
  16854. // TODO: we can remove these if Rollup fixes the bug.
  16855. testMap.set(0, 0);
  16856. testSet.add(0);
  16857. } catch (e) {
  16858. // TODO: Consider warning about bad polyfills
  16859. hasBadMapPolyfill = true;
  16860. }
  16861. }
  16862. var debugCounter = 1;
  16863. function FiberNode(tag, pendingProps, key, mode) {
  16864. // Instance
  16865. this.tag = tag;
  16866. this.key = key;
  16867. this.elementType = null;
  16868. this.type = null;
  16869. this.stateNode = null; // Fiber
  16870. this.return = null;
  16871. this.child = null;
  16872. this.sibling = null;
  16873. this.index = 0;
  16874. this.ref = null;
  16875. this.pendingProps = pendingProps;
  16876. this.memoizedProps = null;
  16877. this.updateQueue = null;
  16878. this.memoizedState = null;
  16879. this.dependencies = null;
  16880. this.mode = mode; // Effects
  16881. this.effectTag = NoEffect;
  16882. this.nextEffect = null;
  16883. this.firstEffect = null;
  16884. this.lastEffect = null;
  16885. this.expirationTime = NoWork;
  16886. this.childExpirationTime = NoWork;
  16887. this.alternate = null;
  16888. {
  16889. // Note: The following is done to avoid a v8 performance cliff.
  16890. //
  16891. // Initializing the fields below to smis and later updating them with
  16892. // double values will cause Fibers to end up having separate shapes.
  16893. // This behavior/bug has something to do with Object.preventExtension().
  16894. // Fortunately this only impacts DEV builds.
  16895. // Unfortunately it makes React unusably slow for some applications.
  16896. // To work around this, initialize the fields below with doubles.
  16897. //
  16898. // Learn more about this here:
  16899. // https://github.com/facebook/react/issues/14365
  16900. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  16901. this.actualDuration = Number.NaN;
  16902. this.actualStartTime = Number.NaN;
  16903. this.selfBaseDuration = Number.NaN;
  16904. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  16905. // This won't trigger the performance cliff mentioned above,
  16906. // and it simplifies other profiler code (including DevTools).
  16907. this.actualDuration = 0;
  16908. this.actualStartTime = -1;
  16909. this.selfBaseDuration = 0;
  16910. this.treeBaseDuration = 0;
  16911. } // This is normally DEV-only except www when it adds listeners.
  16912. // TODO: remove the User Timing integration in favor of Root Events.
  16913. {
  16914. this._debugID = debugCounter++;
  16915. this._debugIsCurrentlyTiming = false;
  16916. }
  16917. {
  16918. this._debugSource = null;
  16919. this._debugOwner = null;
  16920. this._debugNeedsRemount = false;
  16921. this._debugHookTypes = null;
  16922. if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") {
  16923. Object.preventExtensions(this);
  16924. }
  16925. }
  16926. } // This is a constructor function, rather than a POJO constructor, still
  16927. // please ensure we do the following:
  16928. // 1) Nobody should add any instance methods on this. Instance methods can be
  16929. // more difficult to predict when they get optimized and they are almost
  16930. // never inlined properly in static compilers.
  16931. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  16932. // always know when it is a fiber.
  16933. // 3) We might want to experiment with using numeric keys since they are easier
  16934. // to optimize in a non-JIT environment.
  16935. // 4) We can easily go from a constructor to a createFiber object literal if that
  16936. // is faster.
  16937. // 5) It should be easy to port this to a C struct and keep a C implementation
  16938. // compatible.
  16939. var createFiber = function(tag, pendingProps, key, mode) {
  16940. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  16941. return new FiberNode(tag, pendingProps, key, mode);
  16942. };
  16943. function shouldConstruct(Component) {
  16944. var prototype = Component.prototype;
  16945. return !!(prototype && prototype.isReactComponent);
  16946. }
  16947. function isSimpleFunctionComponent(type) {
  16948. return (
  16949. typeof type === "function" &&
  16950. !shouldConstruct(type) &&
  16951. type.defaultProps === undefined
  16952. );
  16953. }
  16954. function resolveLazyComponentTag(Component) {
  16955. if (typeof Component === "function") {
  16956. return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
  16957. } else if (Component !== undefined && Component !== null) {
  16958. var $$typeof = Component.$$typeof;
  16959. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  16960. return ForwardRef;
  16961. }
  16962. if ($$typeof === REACT_MEMO_TYPE) {
  16963. return MemoComponent;
  16964. }
  16965. }
  16966. return IndeterminateComponent;
  16967. } // This is used to create an alternate fiber to do work on.
  16968. function createWorkInProgress(current, pendingProps) {
  16969. var workInProgress = current.alternate;
  16970. if (workInProgress === null) {
  16971. // We use a double buffering pooling technique because we know that we'll
  16972. // only ever need at most two versions of a tree. We pool the "other" unused
  16973. // node that we're free to reuse. This is lazily created to avoid allocating
  16974. // extra objects for things that are never updated. It also allow us to
  16975. // reclaim the extra memory if needed.
  16976. workInProgress = createFiber(
  16977. current.tag,
  16978. pendingProps,
  16979. current.key,
  16980. current.mode
  16981. );
  16982. workInProgress.elementType = current.elementType;
  16983. workInProgress.type = current.type;
  16984. workInProgress.stateNode = current.stateNode;
  16985. {
  16986. // DEV-only fields
  16987. {
  16988. workInProgress._debugID = current._debugID;
  16989. }
  16990. workInProgress._debugSource = current._debugSource;
  16991. workInProgress._debugOwner = current._debugOwner;
  16992. workInProgress._debugHookTypes = current._debugHookTypes;
  16993. }
  16994. workInProgress.alternate = current;
  16995. current.alternate = workInProgress;
  16996. } else {
  16997. workInProgress.pendingProps = pendingProps; // We already have an alternate.
  16998. // Reset the effect tag.
  16999. workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
  17000. workInProgress.nextEffect = null;
  17001. workInProgress.firstEffect = null;
  17002. workInProgress.lastEffect = null;
  17003. {
  17004. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  17005. // This prevents time from endlessly accumulating in new commits.
  17006. // This has the downside of resetting values for different priority renders,
  17007. // But works for yielding (the common case) and should support resuming.
  17008. workInProgress.actualDuration = 0;
  17009. workInProgress.actualStartTime = -1;
  17010. }
  17011. }
  17012. workInProgress.childExpirationTime = current.childExpirationTime;
  17013. workInProgress.expirationTime = current.expirationTime;
  17014. workInProgress.child = current.child;
  17015. workInProgress.memoizedProps = current.memoizedProps;
  17016. workInProgress.memoizedState = current.memoizedState;
  17017. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  17018. // it cannot be shared with the current fiber.
  17019. var currentDependencies = current.dependencies;
  17020. workInProgress.dependencies =
  17021. currentDependencies === null
  17022. ? null
  17023. : {
  17024. expirationTime: currentDependencies.expirationTime,
  17025. firstContext: currentDependencies.firstContext,
  17026. responders: currentDependencies.responders
  17027. }; // These will be overridden during the parent's reconciliation
  17028. workInProgress.sibling = current.sibling;
  17029. workInProgress.index = current.index;
  17030. workInProgress.ref = current.ref;
  17031. {
  17032. workInProgress.selfBaseDuration = current.selfBaseDuration;
  17033. workInProgress.treeBaseDuration = current.treeBaseDuration;
  17034. }
  17035. {
  17036. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  17037. switch (workInProgress.tag) {
  17038. case IndeterminateComponent:
  17039. case FunctionComponent:
  17040. case SimpleMemoComponent:
  17041. workInProgress.type = resolveFunctionForHotReloading(current.type);
  17042. break;
  17043. case ClassComponent:
  17044. workInProgress.type = resolveClassForHotReloading(current.type);
  17045. break;
  17046. case ForwardRef:
  17047. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  17048. break;
  17049. }
  17050. }
  17051. return workInProgress;
  17052. } // Used to reuse a Fiber for a second pass.
  17053. function resetWorkInProgress(workInProgress, renderExpirationTime) {
  17054. // This resets the Fiber to what createFiber or createWorkInProgress would
  17055. // have set the values to before during the first pass. Ideally this wouldn't
  17056. // be necessary but unfortunately many code paths reads from the workInProgress
  17057. // when they should be reading from current and writing to workInProgress.
  17058. // We assume pendingProps, index, key, ref, return are still untouched to
  17059. // avoid doing another reconciliation.
  17060. // Reset the effect tag but keep any Placement tags, since that's something
  17061. // that child fiber is setting, not the reconciliation.
  17062. workInProgress.effectTag &= Placement; // The effect list is no longer valid.
  17063. workInProgress.nextEffect = null;
  17064. workInProgress.firstEffect = null;
  17065. workInProgress.lastEffect = null;
  17066. var current = workInProgress.alternate;
  17067. if (current === null) {
  17068. // Reset to createFiber's initial values.
  17069. workInProgress.childExpirationTime = NoWork;
  17070. workInProgress.expirationTime = renderExpirationTime;
  17071. workInProgress.child = null;
  17072. workInProgress.memoizedProps = null;
  17073. workInProgress.memoizedState = null;
  17074. workInProgress.updateQueue = null;
  17075. workInProgress.dependencies = null;
  17076. {
  17077. // Note: We don't reset the actualTime counts. It's useful to accumulate
  17078. // actual time across multiple render passes.
  17079. workInProgress.selfBaseDuration = 0;
  17080. workInProgress.treeBaseDuration = 0;
  17081. }
  17082. } else {
  17083. // Reset to the cloned values that createWorkInProgress would've.
  17084. workInProgress.childExpirationTime = current.childExpirationTime;
  17085. workInProgress.expirationTime = current.expirationTime;
  17086. workInProgress.child = current.child;
  17087. workInProgress.memoizedProps = current.memoizedProps;
  17088. workInProgress.memoizedState = current.memoizedState;
  17089. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  17090. // it cannot be shared with the current fiber.
  17091. var currentDependencies = current.dependencies;
  17092. workInProgress.dependencies =
  17093. currentDependencies === null
  17094. ? null
  17095. : {
  17096. expirationTime: currentDependencies.expirationTime,
  17097. firstContext: currentDependencies.firstContext,
  17098. responders: currentDependencies.responders
  17099. };
  17100. {
  17101. // Note: We don't reset the actualTime counts. It's useful to accumulate
  17102. // actual time across multiple render passes.
  17103. workInProgress.selfBaseDuration = current.selfBaseDuration;
  17104. workInProgress.treeBaseDuration = current.treeBaseDuration;
  17105. }
  17106. }
  17107. return workInProgress;
  17108. }
  17109. function createHostRootFiber(tag) {
  17110. var mode;
  17111. if (tag === ConcurrentRoot) {
  17112. mode = ConcurrentMode | BlockingMode | StrictMode;
  17113. } else if (tag === BlockingRoot) {
  17114. mode = BlockingMode | StrictMode;
  17115. } else {
  17116. mode = NoMode;
  17117. }
  17118. if (isDevToolsPresent) {
  17119. // Always collect profile timings when DevTools are present.
  17120. // This enables DevTools to start capturing timing at any point–
  17121. // Without some nodes in the tree having empty base times.
  17122. mode |= ProfileMode;
  17123. }
  17124. return createFiber(HostRoot, null, null, mode);
  17125. }
  17126. function createFiberFromTypeAndProps(
  17127. type, // React$ElementType
  17128. key,
  17129. pendingProps,
  17130. owner,
  17131. mode,
  17132. expirationTime
  17133. ) {
  17134. var fiber;
  17135. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  17136. var resolvedType = type;
  17137. if (typeof type === "function") {
  17138. if (shouldConstruct(type)) {
  17139. fiberTag = ClassComponent;
  17140. {
  17141. resolvedType = resolveClassForHotReloading(resolvedType);
  17142. }
  17143. } else {
  17144. {
  17145. resolvedType = resolveFunctionForHotReloading(resolvedType);
  17146. }
  17147. }
  17148. } else if (typeof type === "string") {
  17149. fiberTag = HostComponent;
  17150. } else {
  17151. getTag: switch (type) {
  17152. case REACT_FRAGMENT_TYPE:
  17153. return createFiberFromFragment(
  17154. pendingProps.children,
  17155. mode,
  17156. expirationTime,
  17157. key
  17158. );
  17159. case REACT_CONCURRENT_MODE_TYPE:
  17160. fiberTag = Mode;
  17161. mode |= ConcurrentMode | BlockingMode | StrictMode;
  17162. break;
  17163. case REACT_STRICT_MODE_TYPE:
  17164. fiberTag = Mode;
  17165. mode |= StrictMode;
  17166. break;
  17167. case REACT_PROFILER_TYPE:
  17168. return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
  17169. case REACT_SUSPENSE_TYPE:
  17170. return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
  17171. case REACT_SUSPENSE_LIST_TYPE:
  17172. return createFiberFromSuspenseList(
  17173. pendingProps,
  17174. mode,
  17175. expirationTime,
  17176. key
  17177. );
  17178. default: {
  17179. if (typeof type === "object" && type !== null) {
  17180. switch (type.$$typeof) {
  17181. case REACT_PROVIDER_TYPE:
  17182. fiberTag = ContextProvider;
  17183. break getTag;
  17184. case REACT_CONTEXT_TYPE:
  17185. // This is a consumer
  17186. fiberTag = ContextConsumer;
  17187. break getTag;
  17188. case REACT_FORWARD_REF_TYPE:
  17189. fiberTag = ForwardRef;
  17190. {
  17191. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  17192. }
  17193. break getTag;
  17194. case REACT_MEMO_TYPE:
  17195. fiberTag = MemoComponent;
  17196. break getTag;
  17197. case REACT_LAZY_TYPE:
  17198. fiberTag = LazyComponent;
  17199. resolvedType = null;
  17200. break getTag;
  17201. case REACT_BLOCK_TYPE:
  17202. fiberTag = Block;
  17203. break getTag;
  17204. }
  17205. }
  17206. var info = "";
  17207. {
  17208. if (
  17209. type === undefined ||
  17210. (typeof type === "object" &&
  17211. type !== null &&
  17212. Object.keys(type).length === 0)
  17213. ) {
  17214. info +=
  17215. " You likely forgot to export your component from the file " +
  17216. "it's defined in, or you might have mixed up default and " +
  17217. "named imports.";
  17218. }
  17219. var ownerName = owner ? getComponentName(owner.type) : null;
  17220. if (ownerName) {
  17221. info += "\n\nCheck the render method of `" + ownerName + "`.";
  17222. }
  17223. }
  17224. {
  17225. throw Error(
  17226. "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: " +
  17227. (type == null ? type : typeof type) +
  17228. "." +
  17229. info
  17230. );
  17231. }
  17232. }
  17233. }
  17234. }
  17235. fiber = createFiber(fiberTag, pendingProps, key, mode);
  17236. fiber.elementType = type;
  17237. fiber.type = resolvedType;
  17238. fiber.expirationTime = expirationTime;
  17239. return fiber;
  17240. }
  17241. function createFiberFromElement(element, mode, expirationTime) {
  17242. var owner = null;
  17243. {
  17244. owner = element._owner;
  17245. }
  17246. var type = element.type;
  17247. var key = element.key;
  17248. var pendingProps = element.props;
  17249. var fiber = createFiberFromTypeAndProps(
  17250. type,
  17251. key,
  17252. pendingProps,
  17253. owner,
  17254. mode,
  17255. expirationTime
  17256. );
  17257. {
  17258. fiber._debugSource = element._source;
  17259. fiber._debugOwner = element._owner;
  17260. }
  17261. return fiber;
  17262. }
  17263. function createFiberFromFragment(elements, mode, expirationTime, key) {
  17264. var fiber = createFiber(Fragment, elements, key, mode);
  17265. fiber.expirationTime = expirationTime;
  17266. return fiber;
  17267. }
  17268. function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
  17269. {
  17270. if (typeof pendingProps.id !== "string") {
  17271. error('Profiler must specify an "id" as a prop');
  17272. }
  17273. }
  17274. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  17275. fiber.elementType = REACT_PROFILER_TYPE;
  17276. fiber.type = REACT_PROFILER_TYPE;
  17277. fiber.expirationTime = expirationTime;
  17278. {
  17279. fiber.stateNode = {
  17280. effectDuration: 0,
  17281. passiveEffectDuration: 0
  17282. };
  17283. }
  17284. return fiber;
  17285. }
  17286. function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
  17287. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  17288. // This needs to be fixed in getComponentName so that it relies on the tag
  17289. // instead.
  17290. fiber.type = REACT_SUSPENSE_TYPE;
  17291. fiber.elementType = REACT_SUSPENSE_TYPE;
  17292. fiber.expirationTime = expirationTime;
  17293. return fiber;
  17294. }
  17295. function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
  17296. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  17297. {
  17298. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  17299. // This needs to be fixed in getComponentName so that it relies on the tag
  17300. // instead.
  17301. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  17302. }
  17303. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  17304. fiber.expirationTime = expirationTime;
  17305. return fiber;
  17306. }
  17307. function createFiberFromText(content, mode, expirationTime) {
  17308. var fiber = createFiber(HostText, content, null, mode);
  17309. fiber.expirationTime = expirationTime;
  17310. return fiber;
  17311. }
  17312. function createFiberFromPortal(portal, mode, expirationTime) {
  17313. var pendingProps = portal.children !== null ? portal.children : [];
  17314. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  17315. fiber.expirationTime = expirationTime;
  17316. fiber.stateNode = {
  17317. containerInfo: portal.containerInfo,
  17318. pendingChildren: null,
  17319. // Used by persistent updates
  17320. implementation: portal.implementation
  17321. };
  17322. return fiber;
  17323. } // Used for stashing WIP properties to replay failed work in DEV.
  17324. function assignFiberPropertiesInDEV(target, source) {
  17325. if (target === null) {
  17326. // This Fiber's initial properties will always be overwritten.
  17327. // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
  17328. target = createFiber(IndeterminateComponent, null, null, NoMode);
  17329. } // This is intentionally written as a list of all properties.
  17330. // We tried to use Object.assign() instead but this is called in
  17331. // the hottest path, and Object.assign() was too slow:
  17332. // https://github.com/facebook/react/issues/12502
  17333. // This code is DEV-only so size is not a concern.
  17334. target.tag = source.tag;
  17335. target.key = source.key;
  17336. target.elementType = source.elementType;
  17337. target.type = source.type;
  17338. target.stateNode = source.stateNode;
  17339. target.return = source.return;
  17340. target.child = source.child;
  17341. target.sibling = source.sibling;
  17342. target.index = source.index;
  17343. target.ref = source.ref;
  17344. target.pendingProps = source.pendingProps;
  17345. target.memoizedProps = source.memoizedProps;
  17346. target.updateQueue = source.updateQueue;
  17347. target.memoizedState = source.memoizedState;
  17348. target.dependencies = source.dependencies;
  17349. target.mode = source.mode;
  17350. target.effectTag = source.effectTag;
  17351. target.nextEffect = source.nextEffect;
  17352. target.firstEffect = source.firstEffect;
  17353. target.lastEffect = source.lastEffect;
  17354. target.expirationTime = source.expirationTime;
  17355. target.childExpirationTime = source.childExpirationTime;
  17356. target.alternate = source.alternate;
  17357. {
  17358. target.actualDuration = source.actualDuration;
  17359. target.actualStartTime = source.actualStartTime;
  17360. target.selfBaseDuration = source.selfBaseDuration;
  17361. target.treeBaseDuration = source.treeBaseDuration;
  17362. }
  17363. {
  17364. target._debugID = source._debugID;
  17365. target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
  17366. }
  17367. target._debugSource = source._debugSource;
  17368. target._debugOwner = source._debugOwner;
  17369. target._debugNeedsRemount = source._debugNeedsRemount;
  17370. target._debugHookTypes = source._debugHookTypes;
  17371. return target;
  17372. }
  17373. function FiberRootNode(containerInfo, tag, hydrate) {
  17374. this.tag = tag;
  17375. this.current = null;
  17376. this.containerInfo = containerInfo;
  17377. this.pendingChildren = null;
  17378. this.pingCache = null;
  17379. this.finishedExpirationTime = NoWork;
  17380. this.finishedWork = null;
  17381. this.timeoutHandle = noTimeout;
  17382. this.context = null;
  17383. this.pendingContext = null;
  17384. this.hydrate = hydrate;
  17385. this.callbackNode = null;
  17386. this.callbackPriority = NoPriority;
  17387. this.firstPendingTime = NoWork;
  17388. this.firstSuspendedTime = NoWork;
  17389. this.lastSuspendedTime = NoWork;
  17390. this.nextKnownPendingLevel = NoWork;
  17391. this.lastPingedTime = NoWork;
  17392. this.lastExpiredTime = NoWork;
  17393. {
  17394. this.interactionThreadID = tracing.unstable_getThreadID();
  17395. this.memoizedInteractions = new Set();
  17396. this.pendingInteractionMap = new Map();
  17397. }
  17398. }
  17399. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  17400. var root = new FiberRootNode(containerInfo, tag, hydrate);
  17401. // stateNode is any.
  17402. var uninitializedFiber = createHostRootFiber(tag);
  17403. root.current = uninitializedFiber;
  17404. uninitializedFiber.stateNode = root;
  17405. initializeUpdateQueue(uninitializedFiber);
  17406. return root;
  17407. }
  17408. function isRootSuspendedAtTime(root, expirationTime) {
  17409. var firstSuspendedTime = root.firstSuspendedTime;
  17410. var lastSuspendedTime = root.lastSuspendedTime;
  17411. return (
  17412. firstSuspendedTime !== NoWork &&
  17413. firstSuspendedTime >= expirationTime &&
  17414. lastSuspendedTime <= expirationTime
  17415. );
  17416. }
  17417. function markRootSuspendedAtTime(root, expirationTime) {
  17418. var firstSuspendedTime = root.firstSuspendedTime;
  17419. var lastSuspendedTime = root.lastSuspendedTime;
  17420. if (firstSuspendedTime < expirationTime) {
  17421. root.firstSuspendedTime = expirationTime;
  17422. }
  17423. if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
  17424. root.lastSuspendedTime = expirationTime;
  17425. }
  17426. if (expirationTime <= root.lastPingedTime) {
  17427. root.lastPingedTime = NoWork;
  17428. }
  17429. if (expirationTime <= root.lastExpiredTime) {
  17430. root.lastExpiredTime = NoWork;
  17431. }
  17432. }
  17433. function markRootUpdatedAtTime(root, expirationTime) {
  17434. // Update the range of pending times
  17435. var firstPendingTime = root.firstPendingTime;
  17436. if (expirationTime > firstPendingTime) {
  17437. root.firstPendingTime = expirationTime;
  17438. } // Update the range of suspended times. Treat everything lower priority or
  17439. // equal to this update as unsuspended.
  17440. var firstSuspendedTime = root.firstSuspendedTime;
  17441. if (firstSuspendedTime !== NoWork) {
  17442. if (expirationTime >= firstSuspendedTime) {
  17443. // The entire suspended range is now unsuspended.
  17444. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  17445. } else if (expirationTime >= root.lastSuspendedTime) {
  17446. root.lastSuspendedTime = expirationTime + 1;
  17447. } // This is a pending level. Check if it's higher priority than the next
  17448. // known pending level.
  17449. if (expirationTime > root.nextKnownPendingLevel) {
  17450. root.nextKnownPendingLevel = expirationTime;
  17451. }
  17452. }
  17453. }
  17454. function markRootFinishedAtTime(
  17455. root,
  17456. finishedExpirationTime,
  17457. remainingExpirationTime
  17458. ) {
  17459. // Update the range of pending times
  17460. root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
  17461. // equal to this update as unsuspended.
  17462. if (finishedExpirationTime <= root.lastSuspendedTime) {
  17463. // The entire suspended range is now unsuspended.
  17464. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  17465. } else if (finishedExpirationTime <= root.firstSuspendedTime) {
  17466. // Part of the suspended range is now unsuspended. Narrow the range to
  17467. // include everything between the unsuspended time (non-inclusive) and the
  17468. // last suspended time.
  17469. root.firstSuspendedTime = finishedExpirationTime - 1;
  17470. }
  17471. if (finishedExpirationTime <= root.lastPingedTime) {
  17472. // Clear the pinged time
  17473. root.lastPingedTime = NoWork;
  17474. }
  17475. if (finishedExpirationTime <= root.lastExpiredTime) {
  17476. // Clear the expired time
  17477. root.lastExpiredTime = NoWork;
  17478. }
  17479. }
  17480. function markRootExpiredAtTime(root, expirationTime) {
  17481. var lastExpiredTime = root.lastExpiredTime;
  17482. if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
  17483. root.lastExpiredTime = expirationTime;
  17484. }
  17485. }
  17486. var didWarnAboutNestedUpdates;
  17487. var didWarnAboutFindNodeInStrictMode;
  17488. {
  17489. didWarnAboutNestedUpdates = false;
  17490. didWarnAboutFindNodeInStrictMode = {};
  17491. }
  17492. function getContextForSubtree(parentComponent) {
  17493. if (!parentComponent) {
  17494. return emptyContextObject;
  17495. }
  17496. var fiber = get(parentComponent);
  17497. var parentContext = findCurrentUnmaskedContext(fiber);
  17498. if (fiber.tag === ClassComponent) {
  17499. var Component = fiber.type;
  17500. if (isContextProvider(Component)) {
  17501. return processChildContext(fiber, Component, parentContext);
  17502. }
  17503. }
  17504. return parentContext;
  17505. }
  17506. function findHostInstanceWithWarning(component, methodName) {
  17507. {
  17508. var fiber = get(component);
  17509. if (fiber === undefined) {
  17510. if (typeof component.render === "function") {
  17511. {
  17512. throw Error("Unable to find node on an unmounted component.");
  17513. }
  17514. } else {
  17515. {
  17516. throw Error(
  17517. "Argument appears to not be a ReactComponent. Keys: " +
  17518. Object.keys(component)
  17519. );
  17520. }
  17521. }
  17522. }
  17523. var hostFiber = findCurrentHostFiber(fiber);
  17524. if (hostFiber === null) {
  17525. return null;
  17526. }
  17527. if (hostFiber.mode & StrictMode) {
  17528. var componentName = getComponentName(fiber.type) || "Component";
  17529. if (!didWarnAboutFindNodeInStrictMode[componentName]) {
  17530. didWarnAboutFindNodeInStrictMode[componentName] = true;
  17531. if (fiber.mode & StrictMode) {
  17532. error(
  17533. "%s is deprecated in StrictMode. " +
  17534. "%s was passed an instance of %s which is inside StrictMode. " +
  17535. "Instead, add a ref directly to the element you want to reference. " +
  17536. "Learn more about using refs safely here: " +
  17537. "https://fb.me/react-strict-mode-find-node%s",
  17538. methodName,
  17539. methodName,
  17540. componentName,
  17541. getStackByFiberInDevAndProd(hostFiber)
  17542. );
  17543. } else {
  17544. error(
  17545. "%s is deprecated in StrictMode. " +
  17546. "%s was passed an instance of %s which renders StrictMode children. " +
  17547. "Instead, add a ref directly to the element you want to reference. " +
  17548. "Learn more about using refs safely here: " +
  17549. "https://fb.me/react-strict-mode-find-node%s",
  17550. methodName,
  17551. methodName,
  17552. componentName,
  17553. getStackByFiberInDevAndProd(hostFiber)
  17554. );
  17555. }
  17556. }
  17557. }
  17558. return hostFiber.stateNode;
  17559. }
  17560. }
  17561. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  17562. return createFiberRoot(containerInfo, tag, hydrate);
  17563. }
  17564. function updateContainer(element, container, parentComponent, callback) {
  17565. {
  17566. onScheduleRoot(container, element);
  17567. }
  17568. var current$1 = container.current;
  17569. var currentTime = requestCurrentTimeForUpdate();
  17570. {
  17571. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  17572. if ("undefined" !== typeof jest) {
  17573. warnIfUnmockedScheduler(current$1);
  17574. warnIfNotScopedWithMatchingAct(current$1);
  17575. }
  17576. }
  17577. var suspenseConfig = requestCurrentSuspenseConfig();
  17578. var expirationTime = computeExpirationForFiber(
  17579. currentTime,
  17580. current$1,
  17581. suspenseConfig
  17582. );
  17583. var context = getContextForSubtree(parentComponent);
  17584. if (container.context === null) {
  17585. container.context = context;
  17586. } else {
  17587. container.pendingContext = context;
  17588. }
  17589. {
  17590. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  17591. didWarnAboutNestedUpdates = true;
  17592. error(
  17593. "Render methods should be a pure function of props and state; " +
  17594. "triggering nested component updates from render is not allowed. " +
  17595. "If necessary, trigger nested updates in componentDidUpdate.\n\n" +
  17596. "Check the render method of %s.",
  17597. getComponentName(current.type) || "Unknown"
  17598. );
  17599. }
  17600. }
  17601. var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
  17602. // being called "element".
  17603. update.payload = {
  17604. element: element
  17605. };
  17606. callback = callback === undefined ? null : callback;
  17607. if (callback !== null) {
  17608. {
  17609. if (typeof callback !== "function") {
  17610. error(
  17611. "render(...): Expected the last optional `callback` argument to be a " +
  17612. "function. Instead received: %s.",
  17613. callback
  17614. );
  17615. }
  17616. }
  17617. update.callback = callback;
  17618. }
  17619. enqueueUpdate(current$1, update);
  17620. scheduleWork(current$1, expirationTime);
  17621. return expirationTime;
  17622. }
  17623. function getPublicRootInstance(container) {
  17624. var containerFiber = container.current;
  17625. if (!containerFiber.child) {
  17626. return null;
  17627. }
  17628. switch (containerFiber.child.tag) {
  17629. case HostComponent:
  17630. return getPublicInstance(containerFiber.child.stateNode);
  17631. default:
  17632. return containerFiber.child.stateNode;
  17633. }
  17634. }
  17635. var shouldSuspendImpl = function(fiber) {
  17636. return false;
  17637. };
  17638. function shouldSuspend(fiber) {
  17639. return shouldSuspendImpl(fiber);
  17640. }
  17641. var overrideHookState = null;
  17642. var overrideProps = null;
  17643. var scheduleUpdate = null;
  17644. var setSuspenseHandler = null;
  17645. {
  17646. var copyWithSetImpl = function(obj, path, idx, value) {
  17647. if (idx >= path.length) {
  17648. return value;
  17649. }
  17650. var key = path[idx];
  17651. var updated = Array.isArray(obj) ? obj.slice() : Object.assign({}, obj); // $FlowFixMe number or string is fine here
  17652. updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
  17653. return updated;
  17654. };
  17655. var copyWithSet = function(obj, path, value) {
  17656. return copyWithSetImpl(obj, path, 0, value);
  17657. }; // Support DevTools editable values for useState and useReducer.
  17658. overrideHookState = function(fiber, id, path, value) {
  17659. // For now, the "id" of stateful hooks is just the stateful hook index.
  17660. // This may change in the future with e.g. nested hooks.
  17661. var currentHook = fiber.memoizedState;
  17662. while (currentHook !== null && id > 0) {
  17663. currentHook = currentHook.next;
  17664. id--;
  17665. }
  17666. if (currentHook !== null) {
  17667. var newState = copyWithSet(currentHook.memoizedState, path, value);
  17668. currentHook.memoizedState = newState;
  17669. currentHook.baseState = newState; // We aren't actually adding an update to the queue,
  17670. // because there is no update we can add for useReducer hooks that won't trigger an error.
  17671. // (There's no appropriate action type for DevTools overrides.)
  17672. // As a result though, React will see the scheduled update as a noop and bailout.
  17673. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  17674. fiber.memoizedProps = Object.assign({}, fiber.memoizedProps);
  17675. scheduleWork(fiber, Sync);
  17676. }
  17677. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  17678. overrideProps = function(fiber, path, value) {
  17679. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  17680. if (fiber.alternate) {
  17681. fiber.alternate.pendingProps = fiber.pendingProps;
  17682. }
  17683. scheduleWork(fiber, Sync);
  17684. };
  17685. scheduleUpdate = function(fiber) {
  17686. scheduleWork(fiber, Sync);
  17687. };
  17688. setSuspenseHandler = function(newShouldSuspendImpl) {
  17689. shouldSuspendImpl = newShouldSuspendImpl;
  17690. };
  17691. }
  17692. function injectIntoDevTools(devToolsConfig) {
  17693. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  17694. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  17695. return injectInternals({
  17696. bundleType: devToolsConfig.bundleType,
  17697. version: devToolsConfig.version,
  17698. rendererPackageName: devToolsConfig.rendererPackageName,
  17699. rendererConfig: devToolsConfig.rendererConfig,
  17700. overrideHookState: overrideHookState,
  17701. overrideProps: overrideProps,
  17702. setSuspenseHandler: setSuspenseHandler,
  17703. scheduleUpdate: scheduleUpdate,
  17704. currentDispatcherRef: ReactCurrentDispatcher,
  17705. findHostInstanceByFiber: function(fiber) {
  17706. var hostFiber = findCurrentHostFiber(fiber);
  17707. if (hostFiber === null) {
  17708. return null;
  17709. }
  17710. return hostFiber.stateNode;
  17711. },
  17712. findFiberByHostInstance: function(instance) {
  17713. if (!findFiberByHostInstance) {
  17714. // Might not be implemented by the renderer.
  17715. return null;
  17716. }
  17717. return findFiberByHostInstance(instance);
  17718. },
  17719. // React Refresh
  17720. findHostInstancesForRefresh: findHostInstancesForRefresh,
  17721. scheduleRefresh: scheduleRefresh,
  17722. scheduleRoot: scheduleRoot,
  17723. setRefreshHandler: setRefreshHandler,
  17724. // Enables DevTools to append owner stacks to error messages in DEV mode.
  17725. getCurrentFiber: function() {
  17726. return current;
  17727. }
  17728. });
  17729. }
  17730. var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing;
  17731. function createPortal(
  17732. children,
  17733. containerInfo, // TODO: figure out the API for cross-renderer implementation.
  17734. implementation
  17735. ) {
  17736. var key =
  17737. arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  17738. return {
  17739. // This tag allow us to uniquely identify this as a React Portal
  17740. $$typeof: REACT_PORTAL_TYPE,
  17741. key: key == null ? null : "" + key,
  17742. children: children,
  17743. containerInfo: containerInfo,
  17744. implementation: implementation
  17745. };
  17746. }
  17747. // TODO: this is special because it gets imported during build.
  17748. var ReactVersion = "16.13.0";
  17749. var emptyObject$1 = {};
  17750. {
  17751. Object.freeze(emptyObject$1);
  17752. }
  17753. var getInspectorDataForViewTag;
  17754. var getInspectorDataForViewAtPoint;
  17755. {
  17756. var traverseOwnerTreeUp = function(hierarchy, instance) {
  17757. if (instance) {
  17758. hierarchy.unshift(instance);
  17759. traverseOwnerTreeUp(hierarchy, instance._debugOwner);
  17760. }
  17761. };
  17762. var getOwnerHierarchy = function(instance) {
  17763. var hierarchy = [];
  17764. traverseOwnerTreeUp(hierarchy, instance);
  17765. return hierarchy;
  17766. };
  17767. var lastNonHostInstance = function(hierarchy) {
  17768. for (var i = hierarchy.length - 1; i > 1; i--) {
  17769. var instance = hierarchy[i];
  17770. if (instance.tag !== HostComponent) {
  17771. return instance;
  17772. }
  17773. }
  17774. return hierarchy[0];
  17775. };
  17776. var getHostProps = function(fiber) {
  17777. var host = findCurrentHostFiber(fiber);
  17778. if (host) {
  17779. return host.memoizedProps || emptyObject$1;
  17780. }
  17781. return emptyObject$1;
  17782. };
  17783. var getHostNode = function(fiber, findNodeHandle) {
  17784. var hostNode; // look for children first for the hostNode
  17785. // as composite fibers do not have a hostNode
  17786. while (fiber) {
  17787. if (fiber.stateNode !== null && fiber.tag === HostComponent) {
  17788. hostNode = findNodeHandle(fiber.stateNode);
  17789. }
  17790. if (hostNode) {
  17791. return hostNode;
  17792. }
  17793. fiber = fiber.child;
  17794. }
  17795. return null;
  17796. };
  17797. var createHierarchy = function(fiberHierarchy) {
  17798. return fiberHierarchy.map(function(fiber) {
  17799. return {
  17800. name: getComponentName(fiber.type),
  17801. getInspectorData: function(findNodeHandle) {
  17802. return {
  17803. props: getHostProps(fiber),
  17804. source: fiber._debugSource,
  17805. measure: function(callback) {
  17806. // If this is Fabric, we'll find a ShadowNode and use that to measure.
  17807. var hostFiber = findCurrentHostFiber(fiber);
  17808. var shadowNode =
  17809. hostFiber != null &&
  17810. hostFiber.stateNode !== null &&
  17811. hostFiber.stateNode.node;
  17812. if (shadowNode) {
  17813. nativeFabricUIManager.measure(shadowNode, callback);
  17814. } else {
  17815. return ReactNativePrivateInterface.UIManager.measure(
  17816. getHostNode(fiber, findNodeHandle),
  17817. callback
  17818. );
  17819. }
  17820. }
  17821. };
  17822. }
  17823. };
  17824. });
  17825. };
  17826. var getInspectorDataForInstance = function(closestInstance) {
  17827. // Handle case where user clicks outside of ReactNative
  17828. if (!closestInstance) {
  17829. return {
  17830. hierarchy: [],
  17831. props: emptyObject$1,
  17832. selectedIndex: null,
  17833. source: null
  17834. };
  17835. }
  17836. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17837. var fiberHierarchy = getOwnerHierarchy(fiber);
  17838. var instance = lastNonHostInstance(fiberHierarchy);
  17839. var hierarchy = createHierarchy(fiberHierarchy);
  17840. var props = getHostProps(instance);
  17841. var source = instance._debugSource;
  17842. var selectedIndex = fiberHierarchy.indexOf(instance);
  17843. return {
  17844. hierarchy: hierarchy,
  17845. props: props,
  17846. selectedIndex: selectedIndex,
  17847. source: source
  17848. };
  17849. };
  17850. getInspectorDataForViewTag = function(viewTag) {
  17851. var closestInstance = getInstanceFromTag(viewTag); // Handle case where user clicks outside of ReactNative
  17852. if (!closestInstance) {
  17853. return {
  17854. hierarchy: [],
  17855. props: emptyObject$1,
  17856. selectedIndex: null,
  17857. source: null
  17858. };
  17859. }
  17860. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17861. var fiberHierarchy = getOwnerHierarchy(fiber);
  17862. var instance = lastNonHostInstance(fiberHierarchy);
  17863. var hierarchy = createHierarchy(fiberHierarchy);
  17864. var props = getHostProps(instance);
  17865. var source = instance._debugSource;
  17866. var selectedIndex = fiberHierarchy.indexOf(instance);
  17867. return {
  17868. hierarchy: hierarchy,
  17869. props: props,
  17870. selectedIndex: selectedIndex,
  17871. source: source
  17872. };
  17873. };
  17874. getInspectorDataForViewAtPoint = function(
  17875. findNodeHandle,
  17876. inspectedView,
  17877. locationX,
  17878. locationY,
  17879. callback
  17880. ) {
  17881. var closestInstance = null;
  17882. if (inspectedView._internalInstanceHandle != null) {
  17883. // For Fabric we can look up the instance handle directly and measure it.
  17884. nativeFabricUIManager.findNodeAtPoint(
  17885. inspectedView._internalInstanceHandle.stateNode.node,
  17886. locationX,
  17887. locationY,
  17888. function(internalInstanceHandle) {
  17889. if (internalInstanceHandle == null) {
  17890. callback(
  17891. Object.assign(
  17892. {
  17893. pointerY: locationY,
  17894. frame: {
  17895. left: 0,
  17896. top: 0,
  17897. width: 0,
  17898. height: 0
  17899. }
  17900. },
  17901. getInspectorDataForInstance(closestInstance)
  17902. )
  17903. );
  17904. }
  17905. closestInstance =
  17906. internalInstanceHandle.stateNode.canonical._internalInstanceHandle;
  17907. nativeFabricUIManager.measure(
  17908. internalInstanceHandle.stateNode.node,
  17909. function(x, y, width, height, pageX, pageY) {
  17910. callback(
  17911. Object.assign(
  17912. {
  17913. pointerY: locationY,
  17914. frame: {
  17915. left: pageX,
  17916. top: pageY,
  17917. width: width,
  17918. height: height
  17919. }
  17920. },
  17921. getInspectorDataForInstance(closestInstance)
  17922. )
  17923. );
  17924. }
  17925. );
  17926. }
  17927. );
  17928. } else if (inspectedView._internalFiberInstanceHandleDEV != null) {
  17929. // For Paper we fall back to the old strategy using the React tag.
  17930. ReactNativePrivateInterface.UIManager.findSubviewIn(
  17931. findNodeHandle(inspectedView),
  17932. [locationX, locationY],
  17933. function(nativeViewTag, left, top, width, height) {
  17934. var inspectorData = getInspectorDataForInstance(
  17935. getInstanceFromTag(nativeViewTag)
  17936. );
  17937. callback(
  17938. Object.assign({}, inspectorData, {
  17939. pointerY: locationY,
  17940. frame: {
  17941. left: left,
  17942. top: top,
  17943. width: width,
  17944. height: height
  17945. },
  17946. touchedViewTag: nativeViewTag
  17947. })
  17948. );
  17949. }
  17950. );
  17951. } else {
  17952. error(
  17953. "getInspectorDataForViewAtPoint expects to receieve a host component"
  17954. );
  17955. return;
  17956. }
  17957. };
  17958. }
  17959. var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
  17960. function findHostInstance_DEPRECATED(componentOrHandle) {
  17961. {
  17962. var owner = ReactCurrentOwner$3.current;
  17963. if (owner !== null && owner.stateNode !== null) {
  17964. if (!owner.stateNode._warnedAboutRefsInRender) {
  17965. error(
  17966. "%s is accessing findNodeHandle inside its render(). " +
  17967. "render() should be a pure function of props and state. It should " +
  17968. "never access something that requires stale data from the previous " +
  17969. "render, such as refs. Move this logic to componentDidMount and " +
  17970. "componentDidUpdate instead.",
  17971. getComponentName(owner.type) || "A component"
  17972. );
  17973. }
  17974. owner.stateNode._warnedAboutRefsInRender = true;
  17975. }
  17976. }
  17977. if (componentOrHandle == null) {
  17978. return null;
  17979. }
  17980. if (componentOrHandle._nativeTag) {
  17981. return componentOrHandle;
  17982. }
  17983. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  17984. return componentOrHandle.canonical;
  17985. }
  17986. var hostInstance;
  17987. {
  17988. hostInstance = findHostInstanceWithWarning(
  17989. componentOrHandle,
  17990. "findHostInstance_DEPRECATED"
  17991. );
  17992. }
  17993. if (hostInstance == null) {
  17994. return hostInstance;
  17995. }
  17996. if (hostInstance.canonical) {
  17997. // Fabric
  17998. return hostInstance.canonical;
  17999. }
  18000. return hostInstance;
  18001. }
  18002. function findNodeHandle(componentOrHandle) {
  18003. {
  18004. var owner = ReactCurrentOwner$3.current;
  18005. if (owner !== null && owner.stateNode !== null) {
  18006. if (!owner.stateNode._warnedAboutRefsInRender) {
  18007. error(
  18008. "%s is accessing findNodeHandle inside its render(). " +
  18009. "render() should be a pure function of props and state. It should " +
  18010. "never access something that requires stale data from the previous " +
  18011. "render, such as refs. Move this logic to componentDidMount and " +
  18012. "componentDidUpdate instead.",
  18013. getComponentName(owner.type) || "A component"
  18014. );
  18015. }
  18016. owner.stateNode._warnedAboutRefsInRender = true;
  18017. }
  18018. }
  18019. if (componentOrHandle == null) {
  18020. return null;
  18021. }
  18022. if (typeof componentOrHandle === "number") {
  18023. // Already a node handle
  18024. return componentOrHandle;
  18025. }
  18026. if (componentOrHandle._nativeTag) {
  18027. return componentOrHandle._nativeTag;
  18028. }
  18029. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  18030. return componentOrHandle.canonical._nativeTag;
  18031. }
  18032. var hostInstance;
  18033. {
  18034. hostInstance = findHostInstanceWithWarning(
  18035. componentOrHandle,
  18036. "findNodeHandle"
  18037. );
  18038. }
  18039. if (hostInstance == null) {
  18040. return hostInstance;
  18041. }
  18042. if (hostInstance.canonical) {
  18043. // Fabric
  18044. return hostInstance.canonical._nativeTag;
  18045. }
  18046. return hostInstance._nativeTag;
  18047. }
  18048. function dispatchCommand(handle, command, args) {
  18049. if (handle._nativeTag == null) {
  18050. {
  18051. error(
  18052. "dispatchCommand was called with a ref that isn't a " +
  18053. "native component. Use React.forwardRef to get access to the underlying native component"
  18054. );
  18055. }
  18056. return;
  18057. }
  18058. if (handle._internalInstanceHandle) {
  18059. nativeFabricUIManager.dispatchCommand(
  18060. handle._internalInstanceHandle.stateNode.node,
  18061. command,
  18062. args
  18063. );
  18064. } else {
  18065. ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
  18066. handle._nativeTag,
  18067. command,
  18068. args
  18069. );
  18070. }
  18071. }
  18072. function render(element, containerTag, callback) {
  18073. var root = roots.get(containerTag);
  18074. if (!root) {
  18075. // TODO (bvaughn): If we decide to keep the wrapper component,
  18076. // We could create a wrapper for containerTag as well to reduce special casing.
  18077. root = createContainer(containerTag, LegacyRoot, false);
  18078. roots.set(containerTag, root);
  18079. }
  18080. updateContainer(element, root, null, callback);
  18081. return getPublicRootInstance(root);
  18082. }
  18083. function unmountComponentAtNode(containerTag) {
  18084. var root = roots.get(containerTag);
  18085. if (root) {
  18086. // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
  18087. updateContainer(null, root, null, function() {
  18088. roots.delete(containerTag);
  18089. });
  18090. }
  18091. }
  18092. function unmountComponentAtNodeAndRemoveContainer(containerTag) {
  18093. unmountComponentAtNode(containerTag); // Call back into native to remove all of the subviews from this container
  18094. ReactNativePrivateInterface.UIManager.removeRootView(containerTag);
  18095. }
  18096. function createPortal$1(children, containerTag) {
  18097. var key =
  18098. arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  18099. return createPortal(children, containerTag, null, key);
  18100. }
  18101. setBatchingImplementation(batchedUpdates$1);
  18102. function computeComponentStackForErrorReporting(reactTag) {
  18103. var fiber = getInstanceFromTag(reactTag);
  18104. if (!fiber) {
  18105. return "";
  18106. }
  18107. return getStackByFiberInDevAndProd(fiber);
  18108. }
  18109. var roots = new Map();
  18110. var Internals = {
  18111. computeComponentStackForErrorReporting: computeComponentStackForErrorReporting
  18112. };
  18113. injectIntoDevTools({
  18114. findFiberByHostInstance: getInstanceFromTag,
  18115. bundleType: 1,
  18116. version: ReactVersion,
  18117. rendererPackageName: "react-native-renderer",
  18118. rendererConfig: {
  18119. getInspectorDataForViewTag: getInspectorDataForViewTag,
  18120. getInspectorDataForViewAtPoint: getInspectorDataForViewAtPoint.bind(
  18121. null,
  18122. findNodeHandle
  18123. )
  18124. }
  18125. });
  18126. exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = Internals;
  18127. exports.createPortal = createPortal$1;
  18128. exports.dispatchCommand = dispatchCommand;
  18129. exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
  18130. exports.findNodeHandle = findNodeHandle;
  18131. exports.render = render;
  18132. exports.unmountComponentAtNode = unmountComponentAtNode;
  18133. exports.unmountComponentAtNodeAndRemoveContainer = unmountComponentAtNodeAndRemoveContainer;
  18134. exports.unstable_batchedUpdates = batchedUpdates;
  18135. })();
  18136. }